Compatibility with --load and new GUI
This commit is contained in:
parent
e228b834e2
commit
9210c708fc
5 changed files with 90 additions and 77 deletions
|
@ -722,7 +722,7 @@ sub read_ini {
|
|||
|
||||
my $ini = { _ => {} };
|
||||
my $category = '_';
|
||||
while (<$fh>) {
|
||||
while (my $_ = <$fh>) {
|
||||
s/\R+$//;
|
||||
next if /^\s+/;
|
||||
next if /^$/;
|
||||
|
|
|
@ -56,7 +56,7 @@ sub OnInit {
|
|||
Wx::Image::AddHandler(Wx::PNGHandler->new);
|
||||
my $frame = Wx::Frame->new(undef, -1, 'Slic3r', wxDefaultPosition, [760,520], wxDEFAULT_FRAME_STYLE);
|
||||
$frame->SetIcon(Wx::Icon->new("$Slic3r::var/Slic3r_128px.png", wxBITMAP_TYPE_PNG) );
|
||||
$frame->{skeinpanel} = Slic3r::GUI::SkeinPanel->new($frame);
|
||||
$self->{skeinpanel} = Slic3r::GUI::SkeinPanel->new($frame);
|
||||
$self->SetTopWindow($frame);
|
||||
|
||||
# status bar
|
||||
|
@ -76,12 +76,12 @@ sub OnInit {
|
|||
$fileMenu->Append(6, "Slice to SVG…");
|
||||
$fileMenu->AppendSeparator();
|
||||
$fileMenu->Append(wxID_EXIT, "&Quit");
|
||||
EVT_MENU($frame, 1, sub { $frame->{skeinpanel}->load_config });
|
||||
EVT_MENU($frame, 2, sub { $frame->{skeinpanel}->save_config });
|
||||
EVT_MENU($frame, 3, sub { $frame->{skeinpanel}->do_slice });
|
||||
EVT_MENU($frame, 4, sub { $frame->{skeinpanel}->do_slice(reslice => 1) });
|
||||
EVT_MENU($frame, 5, sub { $frame->{skeinpanel}->do_slice(save_as => 1) });
|
||||
EVT_MENU($frame, 6, sub { $frame->{skeinpanel}->do_slice(save_as => 1, export_svg => 1) });
|
||||
EVT_MENU($frame, 1, sub { $self->{skeinpanel}->load_config });
|
||||
EVT_MENU($frame, 2, sub { $self->{skeinpanel}->save_config });
|
||||
EVT_MENU($frame, 3, sub { $self->{skeinpanel}->do_slice });
|
||||
EVT_MENU($frame, 4, sub { $self->{skeinpanel}->do_slice(reslice => 1) });
|
||||
EVT_MENU($frame, 5, sub { $self->{skeinpanel}->do_slice(save_as => 1) });
|
||||
EVT_MENU($frame, 6, sub { $self->{skeinpanel}->do_slice(save_as => 1, export_svg => 1) });
|
||||
EVT_MENU($frame, wxID_EXIT, sub {$_[0]->Close(0)});
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ sub OnInit {
|
|||
$helpMenu->Append(7, "Configuration Wizard…");
|
||||
$helpMenu->Append(8, "Slic3r Website");
|
||||
$helpMenu->Append(wxID_ABOUT, "&About Slic3r");
|
||||
EVT_MENU($frame, 7, sub { $frame->{skeinpanel}->config_wizard });
|
||||
EVT_MENU($frame, 7, sub { $self->{skeinpanel}->config_wizard });
|
||||
EVT_MENU($frame, 8, sub { Wx::LaunchDefaultBrowser('http://slic3r.org/') });
|
||||
EVT_MENU($frame, wxID_ABOUT, \&about);
|
||||
}
|
||||
|
@ -106,13 +106,20 @@ sub OnInit {
|
|||
$frame->SetMenuBar($menubar);
|
||||
}
|
||||
|
||||
EVT_CLOSE($frame, \&on_close);
|
||||
|
||||
EVT_CLOSE($frame, sub {
|
||||
my (undef, $event) = @_;
|
||||
if ($event->CanVeto && !$self->{skeinpanel}->check_unsaved_changes) {
|
||||
$event->Veto;
|
||||
return;
|
||||
}
|
||||
$event->Skip;
|
||||
});
|
||||
|
||||
$frame->SetMinSize($frame->GetSize);
|
||||
$frame->Show;
|
||||
$frame->Layout;
|
||||
|
||||
$frame->{skeinpanel}->config_wizard if $run_wizard;
|
||||
$self->{skeinpanel}->config_wizard if $run_wizard;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -125,11 +132,6 @@ sub about {
|
|||
$about->Destroy;
|
||||
}
|
||||
|
||||
sub on_close {
|
||||
my ($frame, $event) = @_;
|
||||
$event->CanVeto ? $event->Skip($frame->{skeinpanel}->check_unsaved_changes) : $event->Skip(1);
|
||||
}
|
||||
|
||||
sub catch_error {
|
||||
my ($self, $cb, $message_dialog) = @_;
|
||||
if (my $err = $@) {
|
||||
|
|
|
@ -197,23 +197,19 @@ sub save_config {
|
|||
|
||||
sub load_config {
|
||||
my $self = shift;
|
||||
my ($file) = @_;
|
||||
|
||||
my $dir = $last_config ? dirname($last_config) : $last_config_dir || $last_skein_dir || "";
|
||||
my $dlg = Wx::FileDialog->new($self, 'Select configuration to load:', $dir, "config.ini",
|
||||
$ini_wildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
||||
if ($dlg->ShowModal == wxID_OK) {
|
||||
my ($file) = $dlg->GetPaths;
|
||||
$last_config_dir = dirname($file);
|
||||
$last_config = $file;
|
||||
eval {
|
||||
local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self);
|
||||
Slic3r::Config->load($file);
|
||||
};
|
||||
Slic3r::GUI::catch_error($self);
|
||||
$_->() for values %Slic3r::GUI::OptionsGroup::reload_callbacks;
|
||||
$_->external_config_loaded($file) for values %{$self->{options_tabs}};
|
||||
if (!$file) {
|
||||
my $dir = $last_config ? dirname($last_config) : $last_config_dir || $last_skein_dir || "";
|
||||
my $dlg = Wx::FileDialog->new($self, 'Select configuration to load:', $dir, "config.ini",
|
||||
$ini_wildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
||||
return unless $dlg->ShowModal == wxID_OK;
|
||||
($file) = $dlg->GetPaths;
|
||||
$dlg->Destroy;
|
||||
}
|
||||
$dlg->Destroy;
|
||||
$last_config_dir = dirname($file);
|
||||
$last_config = $file;
|
||||
$_->external_config_loaded($file) for values %{$self->{options_tabs}};
|
||||
}
|
||||
|
||||
sub config_wizard {
|
||||
|
@ -228,19 +224,15 @@ sub config_wizard {
|
|||
|
||||
sub check_unsaved_changes {
|
||||
my $self = shift;
|
||||
|
||||
my @dirty;
|
||||
foreach (values %{$self->{options_tabs}}) {
|
||||
push (@dirty, $_->title) if $_->is_dirty;
|
||||
}
|
||||
|
||||
|
||||
my @dirty = map $_->title, grep $_->is_dirty, values %{$self->{options_tabs}};
|
||||
if (@dirty) {
|
||||
my $titles = join ', ', @dirty;
|
||||
my $confirm = Wx::MessageDialog->new($self, "You have unsaved changes ($titles). Discard changes and continue anyway?",
|
||||
'Unsaved Presets', wxICON_QUESTION | wxOK | wxCANCEL);
|
||||
return ($confirm->ShowModal == wxID_OK);
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -83,14 +83,13 @@ sub new {
|
|||
});
|
||||
|
||||
EVT_BUTTON($self, $self->{btn_save_preset}, sub {
|
||||
my $i = $self->{presets_choice}->GetSelection;
|
||||
my $default = $i == 0 ? 'Untitled' : basename($self->{presets}[$i-1]);
|
||||
$default =~ s/\.ini$//i;
|
||||
my $preset = $self->current_preset;
|
||||
my $default_name = $preset->{default} ? 'Untitled' : basename($preset->{name});
|
||||
|
||||
my $dlg = Slic3r::GUI::SavePresetWindow->new($self,
|
||||
title => lc($title),
|
||||
default => $default,
|
||||
values => [ map { my $filename = basename($_); $filename =~ /^(.*?)\.ini$/i; $1 } @{$self->{presets}} ],
|
||||
title => lc($title),
|
||||
default => $default_name,
|
||||
values => [ map { my $filename = basename($_->{file}); $filename =~ /^(.*?)\.ini$/i; $1 } @{$self->{presets}} ],
|
||||
);
|
||||
return unless $dlg->ShowModal == wxID_OK;
|
||||
|
||||
|
@ -98,7 +97,7 @@ sub new {
|
|||
Slic3r::Config->save($file, $self->{presets_group});
|
||||
$self->set_dirty(0);
|
||||
$self->load_presets;
|
||||
$self->{presets_choice}->SetSelection(1 + first { basename($self->{presets}[$_]) eq $dlg->get_name . ".ini" } 0 .. $#{$self->{presets}});
|
||||
$self->{presets_choice}->SetSelection(first { basename($self->{presets}[$_]{file}) eq $dlg->get_name . ".ini" } 0 .. $#{$self->{presets}});
|
||||
$self->on_select_preset;
|
||||
$self->sync_presets;
|
||||
});
|
||||
|
@ -108,8 +107,8 @@ sub new {
|
|||
return if $i == 0; # this shouldn't happen but let's trap it anyway
|
||||
my $res = Wx::MessageDialog->new($self, "Are you sure you want to delete the selected preset?", 'Delete Preset', wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION)->ShowModal;
|
||||
return unless $res == wxID_YES;
|
||||
if (-e $self->{presets}[$i-1]) {
|
||||
unlink $self->{presets}[$i-1];
|
||||
if (-e $self->{presets}[$i-1]{file}) {
|
||||
unlink $self->{presets}[$i-1]{file};
|
||||
}
|
||||
splice @{$self->{presets}}, $i-1, 1;
|
||||
$self->{presets_choice}->Delete($i);
|
||||
|
@ -121,6 +120,11 @@ sub new {
|
|||
return $self;
|
||||
}
|
||||
|
||||
sub current_preset {
|
||||
my $self = shift;
|
||||
return $self->{presets}[ $self->{presets_choice}->GetSelection ];
|
||||
}
|
||||
|
||||
sub on_select_preset {
|
||||
my $self = shift;
|
||||
|
||||
|
@ -129,23 +133,28 @@ sub on_select_preset {
|
|||
$self->set_dirty(0);
|
||||
}
|
||||
|
||||
my $i = $self->{presets_choice}->GetSelection;
|
||||
my $file;
|
||||
if ($i == 0) {
|
||||
my $preset = $self->current_preset;
|
||||
if ($preset->{default}) {
|
||||
# default settings: disable the delete button
|
||||
Slic3r::Config->load_hash($Slic3r::Defaults, $self->{presets_group}, 1);
|
||||
$self->{btn_delete_preset}->Disable;
|
||||
} else {
|
||||
$file = $self->{presets}[$i-1];
|
||||
if (!-e $file) {
|
||||
Slic3r::GUI::show_error($self, "The selected preset does not exist anymore ($file).");
|
||||
if (!-e $preset->{file}) {
|
||||
Slic3r::GUI::show_error($self, "The selected preset does not exist anymore ($preset->{file}).");
|
||||
return;
|
||||
}
|
||||
Slic3r::Config->load($file, $self->{presets_group});
|
||||
$self->{btn_delete_preset}->Enable;
|
||||
eval {
|
||||
local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self);
|
||||
Slic3r::Config->load($preset->{file}, $self->{presets_group});
|
||||
};
|
||||
Slic3r::GUI::catch_error($self);
|
||||
$preset->{external}
|
||||
? $self->{btn_delete_preset}->Disable
|
||||
: $self->{btn_delete_preset}->Enable;
|
||||
}
|
||||
$_->() for @Slic3r::GUI::OptionsGroup::reload_callbacks{@{$Slic3r::Config::Groups{$self->{presets_group}}}};
|
||||
$self->set_dirty(0);
|
||||
$Slic3r::Settings->{presets}{$self->{presets_group}} = $file ? basename($file) : '';
|
||||
$Slic3r::Settings->{presets}{$self->{presets_group}} = $preset->{file} ? basename($preset->{file}) : '';
|
||||
Slic3r::Config->save_settings("$Slic3r::GUI::datadir/slic3r.ini");
|
||||
}
|
||||
|
||||
|
@ -179,7 +188,7 @@ sub set_dirty {
|
|||
|
||||
my $i = $self->{dirty} // $self->{presets_choice}->GetSelection; #/
|
||||
my $text = $self->{presets_choice}->GetString($i);
|
||||
|
||||
|
||||
if ($dirty) {
|
||||
$self->{dirty} = $i;
|
||||
if ($text !~ / \(modified\)$/) {
|
||||
|
@ -202,7 +211,7 @@ sub is_dirty {
|
|||
|
||||
sub title {
|
||||
my $self = shift;
|
||||
return $self->{title}
|
||||
return $self->{title};
|
||||
}
|
||||
|
||||
sub load_presets {
|
||||
|
@ -210,22 +219,28 @@ sub load_presets {
|
|||
my ($group) = @_;
|
||||
|
||||
$self->{presets_group} ||= $group;
|
||||
$self->{presets} = [];
|
||||
$self->{presets} = [{
|
||||
default => 1,
|
||||
name => '- default -',
|
||||
}];
|
||||
|
||||
opendir my $dh, "$Slic3r::GUI::datadir/$self->{presets_group}" or die "Failed to read directory $Slic3r::GUI::datadir/$self->{presets_group} (errno: $!)\n";
|
||||
my @presets = sort grep /\.ini$/i, readdir $dh;
|
||||
foreach my $file (sort grep /\.ini$/i, readdir $dh) {
|
||||
my $name = basename($file);
|
||||
$name =~ s/\.ini$//;
|
||||
push @{$self->{presets}}, {
|
||||
file => "$Slic3r::GUI::datadir/$self->{presets_group}/$file",
|
||||
name => $name,
|
||||
};
|
||||
}
|
||||
closedir $dh;
|
||||
|
||||
$self->{presets_choice}->Clear;
|
||||
$self->{presets_choice}->Append("- default -");
|
||||
foreach my $preset (@presets) {
|
||||
push @{$self->{presets}}, "$Slic3r::GUI::datadir/$self->{presets_group}/$preset";
|
||||
$preset =~ s/\.ini$//i;
|
||||
$self->{presets_choice}->Append($preset);
|
||||
}
|
||||
$self->{presets_choice}->Append($_->{name}) for @{$self->{presets}};
|
||||
{
|
||||
my $i = first { basename($self->{presets}[$_]) eq ($Slic3r::Settings->{presets}{$self->{presets_group}} || '') } 0 .. $#{$self->{presets}};
|
||||
$self->{presets_choice}->SetSelection(defined $i ? $i + 1 : 0);
|
||||
# load last used preset
|
||||
my $i = first { basename($self->{presets}[$_]{file}) eq ($Slic3r::Settings->{presets}{$self->{presets_group}} || '') } 1 .. $#{$self->{presets}};
|
||||
$self->{presets_choice}->SetSelection($i || 0);
|
||||
$self->on_select_preset;
|
||||
}
|
||||
$self->sync_presets;
|
||||
|
@ -236,16 +251,19 @@ sub external_config_loaded {
|
|||
my ($file) = @_;
|
||||
|
||||
# look for the loaded config among the existing menu items
|
||||
my $i = first { $self->{presets}[$_] eq $file } 0..$#{$self->{presets}};
|
||||
my $i = first { $self->{presets}[$_]{file} eq $file && $self->{presets}[$_]{external} } 1..$#{$self->{presets}};
|
||||
if (!$i) {
|
||||
push @{$self->{presets}}, $file;
|
||||
my $preset_name = basename($file); # leave the .ini suffix
|
||||
my $preset_name = basename($file); # keep the .ini suffix
|
||||
push @{$self->{presets}}, {
|
||||
file => $file,
|
||||
name => $preset_name,
|
||||
external => 1,
|
||||
};
|
||||
$self->{presets_choice}->Append($preset_name);
|
||||
$i = $#{$self->{presets}};
|
||||
}
|
||||
$self->{presets_choice}->SetSelection(1 + $i);
|
||||
$self->set_dirty(0);
|
||||
$self->{btn_delete_preset}->Disable;
|
||||
$self->{presets_choice}->SetSelection($i);
|
||||
$self->on_select_preset;
|
||||
$self->sync_presets;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,8 +72,9 @@ Slic3r::Config->save($opt{save}) if $opt{save};
|
|||
# start GUI
|
||||
if (!@ARGV && !$opt{save} && eval "require Slic3r::GUI; 1") {
|
||||
no warnings 'once';
|
||||
$Slic3r::GUI::SkeinPanel::last_config = $opt{load} ? $opt{load}[0] : undef;
|
||||
Slic3r::GUI->new->MainLoop;
|
||||
my $gui = Slic3r::GUI->new;
|
||||
$gui->{skeinpanel}->load_config($opt{load}[0]) if $opt{load};
|
||||
$gui->MainLoop;
|
||||
exit;
|
||||
}
|
||||
die $@ if $@ && $opt{gui};
|
||||
|
|
Loading…
Reference in a new issue