2011-10-03 09:55:32 +00:00
|
|
|
package Slic3r::GUI;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2012-03-11 18:59:09 +00:00
|
|
|
use utf8;
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2014-03-25 13:04:01 +00:00
|
|
|
use File::Basename qw(basename);
|
2012-04-07 18:45:02 +00:00
|
|
|
use FindBin;
|
2015-12-07 11:17:06 +00:00
|
|
|
use List::Util qw(first);
|
2015-11-02 19:16:37 +00:00
|
|
|
use Slic3r::GUI::2DBed;
|
2012-07-13 21:46:39 +00:00
|
|
|
use Slic3r::GUI::AboutDialog;
|
2018-02-16 16:20:34 +00:00
|
|
|
use Slic3r::GUI::BedShapeDialog;
|
2014-12-28 17:49:13 +00:00
|
|
|
use Slic3r::GUI::BonjourBrowser;
|
2012-06-26 15:42:29 +00:00
|
|
|
use Slic3r::GUI::ConfigWizard;
|
2015-01-04 22:18:23 +00:00
|
|
|
use Slic3r::GUI::Controller;
|
2015-11-02 19:16:37 +00:00
|
|
|
use Slic3r::GUI::Controller::ManualControlDialog;
|
2014-12-31 18:10:46 +00:00
|
|
|
use Slic3r::GUI::Controller::PrinterPanel;
|
2014-06-14 17:11:04 +00:00
|
|
|
use Slic3r::GUI::MainFrame;
|
2014-06-14 17:54:18 +00:00
|
|
|
use Slic3r::GUI::Notifier;
|
2012-05-04 08:15:33 +00:00
|
|
|
use Slic3r::GUI::Plater;
|
2014-05-28 10:29:43 +00:00
|
|
|
use Slic3r::GUI::Plater::2D;
|
2014-07-03 07:24:19 +00:00
|
|
|
use Slic3r::GUI::Plater::2DToolpaths;
|
2014-07-13 10:10:34 +00:00
|
|
|
use Slic3r::GUI::Plater::3D;
|
2015-01-18 18:36:47 +00:00
|
|
|
use Slic3r::GUI::Plater::3DPreview;
|
2014-01-08 18:36:41 +00:00
|
|
|
use Slic3r::GUI::Plater::ObjectPartsPanel;
|
2014-04-25 12:54:08 +00:00
|
|
|
use Slic3r::GUI::Plater::ObjectCutDialog;
|
2013-08-25 16:01:59 +00:00
|
|
|
use Slic3r::GUI::Plater::ObjectSettingsDialog;
|
2016-11-27 22:05:28 +00:00
|
|
|
use Slic3r::GUI::Plater::LambdaObjectDialog;
|
2014-02-14 21:24:30 +00:00
|
|
|
use Slic3r::GUI::Plater::OverrideSettingsPanel;
|
2014-06-14 17:54:18 +00:00
|
|
|
use Slic3r::GUI::ProgressStatusBar;
|
2011-10-03 09:55:32 +00:00
|
|
|
use Slic3r::GUI::OptionsGroup;
|
2014-07-01 14:40:56 +00:00
|
|
|
use Slic3r::GUI::OptionsGroup::Field;
|
2017-02-19 15:04:57 +00:00
|
|
|
use Slic3r::GUI::SystemInfo;
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2018-02-28 14:39:20 +00:00
|
|
|
use Wx::Locale gettext => 'L';
|
|
|
|
|
2015-01-09 00:30:04 +00:00
|
|
|
our $have_OpenGL = eval "use Slic3r::GUI::3DScene; 1";
|
2014-12-28 00:30:05 +00:00
|
|
|
our $have_LWP = eval "use LWP::UserAgent; 1";
|
2013-05-17 12:14:33 +00:00
|
|
|
|
2017-08-04 14:28:01 +00:00
|
|
|
use Wx 0.9901 qw(:bitmap :dialog :icon :id :misc :systemsettings :toplevelwindow :filedialog :font);
|
|
|
|
use Wx::Event qw(EVT_IDLE EVT_COMMAND EVT_MENU);
|
2011-10-03 09:55:32 +00:00
|
|
|
use base 'Wx::App';
|
|
|
|
|
2014-06-14 17:54:18 +00:00
|
|
|
use constant FILE_WILDCARDS => {
|
2018-02-19 14:33:01 +00:00
|
|
|
known => 'Known files (*.stl, *.obj, *.amf, *.xml, *.3mf, *.prusa)|*.stl;*.STL;*.obj;*.OBJ;*.zip.amf;*.amf;*.AMF;*.xml;*.XML;*.3mf;*.3MF;*.prusa;*.PRUSA',
|
2014-06-14 17:54:18 +00:00
|
|
|
stl => 'STL files (*.stl)|*.stl;*.STL',
|
|
|
|
obj => 'OBJ files (*.obj)|*.obj;*.OBJ',
|
2018-02-19 14:33:01 +00:00
|
|
|
amf => 'AMF files (*.amf)|*.zip.amf;*.amf;*.AMF;*.xml;*.XML',
|
2018-01-30 08:27:10 +00:00
|
|
|
threemf => '3MF files (*.3mf)|*.3mf;*.3MF',
|
2017-04-05 12:45:43 +00:00
|
|
|
prusa => 'Prusa Control files (*.prusa)|*.prusa;*.PRUSA',
|
2014-06-14 17:54:18 +00:00
|
|
|
ini => 'INI files *.ini|*.ini;*.INI',
|
|
|
|
gcode => 'G-code files (*.gcode, *.gco, *.g, *.ngc)|*.gcode;*.GCODE;*.gco;*.GCO;*.g;*.G;*.ngc;*.NGC',
|
|
|
|
svg => 'SVG files *.svg|*.svg;*.SVG',
|
|
|
|
};
|
2018-01-30 08:27:10 +00:00
|
|
|
use constant MODEL_WILDCARD => join '|', @{&FILE_WILDCARDS}{qw(known stl obj amf threemf prusa)};
|
2014-06-14 17:54:18 +00:00
|
|
|
|
2017-11-30 09:22:39 +00:00
|
|
|
# Datadir provided on the command line.
|
|
|
|
our $datadir;
|
2016-05-16 21:40:24 +00:00
|
|
|
# If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden.
|
2013-03-09 15:43:09 +00:00
|
|
|
our $no_plater;
|
2013-08-25 12:37:50 +00:00
|
|
|
our @cb;
|
2013-03-09 15:43:09 +00:00
|
|
|
|
2012-07-01 17:24:06 +00:00
|
|
|
our $small_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
2017-05-02 17:04:04 +00:00
|
|
|
$small_font->SetPointSize(11) if &Wx::wxMAC;
|
2015-11-02 00:18:05 +00:00
|
|
|
our $small_bold_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
2017-05-02 17:04:04 +00:00
|
|
|
$small_bold_font->SetPointSize(11) if &Wx::wxMAC;
|
2015-11-02 00:18:05 +00:00
|
|
|
$small_bold_font->SetWeight(wxFONTWEIGHT_BOLD);
|
2012-07-01 17:24:06 +00:00
|
|
|
our $medium_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
2012-06-19 15:23:10 +00:00
|
|
|
$medium_font->SetPointSize(12);
|
2015-01-04 17:17:15 +00:00
|
|
|
our $grey = Wx::Colour->new(200,200,200);
|
2012-06-19 15:23:10 +00:00
|
|
|
|
2018-02-09 10:04:34 +00:00
|
|
|
# Events to be sent from a C++ menu implementation:
|
|
|
|
# 1) To inform about a change of the application language.
|
2018-02-22 10:12:29 +00:00
|
|
|
our $LANGUAGE_CHANGE_EVENT = Wx::NewEventType;
|
|
|
|
# 2) To inform about a change of Preferences.
|
|
|
|
our $PREFERENCES_EVENT = Wx::NewEventType;
|
2018-02-09 10:04:34 +00:00
|
|
|
|
2011-10-03 09:55:32 +00:00
|
|
|
sub OnInit {
|
2014-06-14 17:54:18 +00:00
|
|
|
my ($self) = @_;
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2017-12-10 12:19:44 +00:00
|
|
|
$self->SetAppName('Slic3rPE');
|
2017-08-03 15:47:18 +00:00
|
|
|
$self->SetAppDisplayName('Slic3r Prusa Edition');
|
2012-08-04 20:19:42 +00:00
|
|
|
Slic3r::debugf "wxWidgets version %s, Wx version %s\n", &Wx::wxVERSION_STRING, $Wx::VERSION;
|
2017-11-30 09:22:39 +00:00
|
|
|
|
|
|
|
# Set the Slic3r data directory at the Slic3r XS module.
|
|
|
|
# Unix: ~/.Slic3r
|
|
|
|
# Windows: "C:\Users\username\AppData\Roaming\Slic3r" or "C:\Documents and Settings\username\Application Data\Slic3r"
|
|
|
|
# Mac: "~/Library/Application Support/Slic3r"
|
|
|
|
Slic3r::set_data_dir($datadir || Wx::StandardPaths::Get->GetUserDataDir);
|
2017-12-04 09:48:40 +00:00
|
|
|
Slic3r::GUI::set_wxapp($self);
|
2018-02-20 07:58:46 +00:00
|
|
|
|
2012-07-16 20:37:31 +00:00
|
|
|
$self->{notifier} = Slic3r::GUI::Notifier->new;
|
2017-11-02 15:21:34 +00:00
|
|
|
$self->{app_config} = Slic3r::GUI::AppConfig->new;
|
2017-09-19 11:55:48 +00:00
|
|
|
$self->{preset_bundle} = Slic3r::GUI::PresetBundle->new;
|
2018-02-20 07:58:46 +00:00
|
|
|
|
2017-10-25 10:53:31 +00:00
|
|
|
# just checking for existence of Slic3r::data_dir is not enough: it may be an empty directory
|
2014-03-25 13:07:03 +00:00
|
|
|
# supplied as argument to --datadir; in that case we should still run the wizard
|
2017-11-02 15:21:34 +00:00
|
|
|
eval { $self->{preset_bundle}->setup_directories() };
|
|
|
|
if ($@) {
|
|
|
|
warn $@ . "\n";
|
|
|
|
fatal_error(undef, $@);
|
2012-06-18 20:27:57 +00:00
|
|
|
}
|
2017-11-02 15:21:34 +00:00
|
|
|
my $run_wizard = ! $self->{app_config}->exists;
|
2012-06-19 16:11:51 +00:00
|
|
|
# load settings
|
2017-11-02 15:21:34 +00:00
|
|
|
$self->{app_config}->load if ! $run_wizard;
|
|
|
|
$self->{app_config}->set('version', $Slic3r::VERSION);
|
|
|
|
$self->{app_config}->save;
|
2017-10-25 10:53:31 +00:00
|
|
|
|
2018-02-20 07:58:46 +00:00
|
|
|
Slic3r::GUI::set_app_config($self->{app_config});
|
|
|
|
Slic3r::GUI::load_language();
|
|
|
|
|
2017-10-26 15:17:39 +00:00
|
|
|
# Suppress the '- default -' presets.
|
2017-11-02 15:21:34 +00:00
|
|
|
$self->{preset_bundle}->set_default_suppressed($self->{app_config}->get('no_defaults') ? 1 : 0);
|
2017-12-10 21:11:00 +00:00
|
|
|
eval { $self->{preset_bundle}->load_presets };
|
2017-11-28 09:08:01 +00:00
|
|
|
if ($@) {
|
|
|
|
warn $@ . "\n";
|
|
|
|
show_error(undef, $@);
|
|
|
|
}
|
2017-12-10 21:11:00 +00:00
|
|
|
eval { $self->{preset_bundle}->load_selections($self->{app_config}) };
|
2017-11-28 09:08:01 +00:00
|
|
|
$run_wizard = 1 if $self->{preset_bundle}->has_defauls_only;
|
2012-06-19 16:11:51 +00:00
|
|
|
|
2012-06-18 20:27:57 +00:00
|
|
|
# application frame
|
2017-11-30 19:25:59 +00:00
|
|
|
Wx::Image::FindHandlerType(wxBITMAP_TYPE_PNG) || Wx::Image::AddHandler(Wx::PNGHandler->new);
|
2014-06-14 17:54:18 +00:00
|
|
|
$self->{mainframe} = my $frame = Slic3r::GUI::MainFrame->new(
|
2016-05-16 21:40:24 +00:00
|
|
|
# If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden.
|
2017-11-02 15:21:34 +00:00
|
|
|
no_controller => $self->{app_config}->get('no_controller'),
|
2016-05-16 21:40:24 +00:00
|
|
|
no_plater => $no_plater,
|
2018-02-09 10:04:34 +00:00
|
|
|
lang_ch_event => $LANGUAGE_CHANGE_EVENT,
|
2018-02-22 10:12:29 +00:00
|
|
|
preferences_event => $PREFERENCES_EVENT,
|
2013-03-09 15:43:09 +00:00
|
|
|
);
|
2012-06-28 21:20:10 +00:00
|
|
|
$self->SetTopWindow($frame);
|
2017-10-26 15:17:39 +00:00
|
|
|
|
2018-02-09 10:04:34 +00:00
|
|
|
#EVT_IDLE($frame, sub {
|
|
|
|
EVT_IDLE($self->{mainframe}, sub {
|
2013-08-25 12:37:50 +00:00
|
|
|
while (my $cb = shift @cb) {
|
|
|
|
$cb->();
|
|
|
|
}
|
2017-11-02 15:21:34 +00:00
|
|
|
$self->{app_config}->save if $self->{app_config}->dirty;
|
2013-08-25 12:37:50 +00:00
|
|
|
});
|
2017-12-14 16:35:06 +00:00
|
|
|
|
|
|
|
if ($run_wizard) {
|
|
|
|
# On OSX the UI was not initialized correctly if the wizard was called
|
|
|
|
# before the UI was up and running.
|
|
|
|
$self->CallAfter(sub {
|
2017-12-19 18:51:22 +00:00
|
|
|
# Run the config wizard, don't offer the "reset user profile" checkbox.
|
|
|
|
$self->{mainframe}->config_wizard(1);
|
2017-12-14 16:35:06 +00:00
|
|
|
});
|
|
|
|
}
|
2018-02-09 10:04:34 +00:00
|
|
|
|
|
|
|
# The following event is emited by the C++ menu implementation of application language change.
|
|
|
|
EVT_COMMAND($self, -1, $LANGUAGE_CHANGE_EVENT, sub{
|
|
|
|
$self->recreate_GUI;
|
|
|
|
});
|
2018-02-22 10:12:29 +00:00
|
|
|
|
|
|
|
# The following event is emited by the C++ menu implementation of preferences change.
|
|
|
|
EVT_COMMAND($self, -1, $PREFERENCES_EVENT, sub{
|
|
|
|
$self->update_ui_from_settings;
|
|
|
|
});
|
2013-08-25 12:37:50 +00:00
|
|
|
|
2011-10-03 11:08:43 +00:00
|
|
|
return 1;
|
2011-10-03 09:55:32 +00:00
|
|
|
}
|
|
|
|
|
2018-02-09 10:04:34 +00:00
|
|
|
sub recreate_GUI{
|
|
|
|
my ($self) = @_;
|
|
|
|
my $topwindow = $self->GetTopWindow();
|
|
|
|
$self->{mainframe} = my $frame = Slic3r::GUI::MainFrame->new(
|
|
|
|
# If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden.
|
|
|
|
no_controller => $self->{app_config}->get('no_controller'),
|
|
|
|
no_plater => $no_plater,
|
|
|
|
lang_ch_event => $LANGUAGE_CHANGE_EVENT,
|
2018-02-22 10:12:29 +00:00
|
|
|
preferences_event => $PREFERENCES_EVENT,
|
2018-02-09 10:04:34 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if($topwindow)
|
|
|
|
{
|
|
|
|
$self->SetTopWindow($frame);
|
|
|
|
$topwindow->Destroy;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $run_wizard = 1 if $self->{preset_bundle}->has_defauls_only;
|
|
|
|
if ($run_wizard) {
|
|
|
|
# On OSX the UI was not initialized correctly if the wizard was called
|
|
|
|
# before the UI was up and running.
|
|
|
|
$self->CallAfter(sub {
|
|
|
|
# Run the config wizard, don't offer the "reset user profile" checkbox.
|
|
|
|
$self->{mainframe}->config_wizard(1);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-24 10:09:48 +00:00
|
|
|
sub about {
|
2014-06-14 17:54:18 +00:00
|
|
|
my ($self) = @_;
|
|
|
|
my $about = Slic3r::GUI::AboutDialog->new(undef);
|
2012-07-13 21:46:39 +00:00
|
|
|
$about->ShowModal;
|
|
|
|
$about->Destroy;
|
2011-10-03 09:55:32 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 15:04:57 +00:00
|
|
|
sub system_info {
|
|
|
|
my ($self) = @_;
|
|
|
|
my $slic3r_info = Slic3r::slic3r_info(format => 'html');
|
|
|
|
my $copyright_info = Slic3r::copyright_info(format => 'html');
|
|
|
|
my $system_info = Slic3r::system_info(format => 'html');
|
|
|
|
my $opengl_info;
|
|
|
|
my $opengl_info_txt = '';
|
|
|
|
if (defined($self->{mainframe}) && defined($self->{mainframe}->{plater}) &&
|
|
|
|
defined($self->{mainframe}->{plater}->{canvas3D})) {
|
|
|
|
$opengl_info = $self->{mainframe}->{plater}->{canvas3D}->opengl_info(format => 'html');
|
|
|
|
$opengl_info_txt = $self->{mainframe}->{plater}->{canvas3D}->opengl_info;
|
|
|
|
}
|
|
|
|
my $about = Slic3r::GUI::SystemInfo->new(
|
|
|
|
parent => undef,
|
|
|
|
slic3r_info => $slic3r_info,
|
|
|
|
# copyright_info => $copyright_info,
|
|
|
|
system_info => $system_info,
|
|
|
|
opengl_info => $opengl_info,
|
|
|
|
text_info => Slic3r::slic3r_info . Slic3r::system_info . $opengl_info_txt,
|
|
|
|
);
|
|
|
|
$about->ShowModal;
|
|
|
|
$about->Destroy;
|
|
|
|
}
|
|
|
|
|
2014-06-14 17:54:18 +00:00
|
|
|
# static method accepting a wxWindow object as first parameter
|
2012-04-30 12:56:01 +00:00
|
|
|
sub catch_error {
|
2012-05-05 19:08:15 +00:00
|
|
|
my ($self, $cb, $message_dialog) = @_;
|
2012-04-30 12:56:01 +00:00
|
|
|
if (my $err = $@) {
|
|
|
|
$cb->() if $cb;
|
2012-05-05 19:08:15 +00:00
|
|
|
$message_dialog
|
2014-06-13 12:27:55 +00:00
|
|
|
? $message_dialog->($err, 'Error', wxOK | wxICON_ERROR)
|
|
|
|
: Slic3r::GUI::show_error($self, $err);
|
2012-04-30 12:56:01 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-14 17:54:18 +00:00
|
|
|
# static method accepting a wxWindow object as first parameter
|
2012-06-18 20:27:57 +00:00
|
|
|
sub show_error {
|
2015-01-09 13:50:42 +00:00
|
|
|
my ($parent, $message) = @_;
|
|
|
|
Wx::MessageDialog->new($parent, $message, 'Error', wxOK | wxICON_ERROR)->ShowModal;
|
2012-06-18 20:27:57 +00:00
|
|
|
}
|
|
|
|
|
2014-06-14 17:54:18 +00:00
|
|
|
# static method accepting a wxWindow object as first parameter
|
2013-04-27 18:55:43 +00:00
|
|
|
sub show_info {
|
2015-01-09 13:50:42 +00:00
|
|
|
my ($parent, $message, $title) = @_;
|
|
|
|
Wx::MessageDialog->new($parent, $message, $title || 'Notice', wxOK | wxICON_INFORMATION)->ShowModal;
|
2013-04-27 18:55:43 +00:00
|
|
|
}
|
|
|
|
|
2014-06-14 17:54:18 +00:00
|
|
|
# static method accepting a wxWindow object as first parameter
|
2012-06-18 20:27:57 +00:00
|
|
|
sub fatal_error {
|
2015-01-09 13:50:42 +00:00
|
|
|
show_error(@_);
|
2012-06-18 20:27:57 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
2014-06-14 17:54:18 +00:00
|
|
|
# static method accepting a wxWindow object as first parameter
|
2012-04-30 12:56:01 +00:00
|
|
|
sub warning_catcher {
|
2012-05-05 19:08:15 +00:00
|
|
|
my ($self, $message_dialog) = @_;
|
2012-04-30 12:56:01 +00:00
|
|
|
return sub {
|
|
|
|
my $message = shift;
|
2013-06-07 11:54:40 +00:00
|
|
|
return if $message =~ /GLUquadricObjPtr|Attempt to free unreferenced scalar/;
|
2012-07-01 17:24:06 +00:00
|
|
|
my @params = ($message, 'Warning', wxOK | wxICON_WARNING);
|
2012-05-05 19:08:15 +00:00
|
|
|
$message_dialog
|
|
|
|
? $message_dialog->(@params)
|
|
|
|
: Wx::MessageDialog->new($self, @params)->ShowModal;
|
2012-04-30 12:56:01 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-06-14 11:49:50 +00:00
|
|
|
sub notify {
|
2014-06-14 17:54:18 +00:00
|
|
|
my ($self, $message) = @_;
|
2012-06-14 11:49:50 +00:00
|
|
|
|
2012-07-15 21:57:31 +00:00
|
|
|
my $frame = $self->GetTopWindow;
|
2012-08-01 11:59:43 +00:00
|
|
|
# try harder to attract user attention on OS X
|
|
|
|
$frame->RequestUserAttention(&Wx::wxMAC ? wxUSER_ATTENTION_ERROR : wxUSER_ATTENTION_INFO)
|
|
|
|
unless ($frame->IsActive);
|
2012-07-15 21:57:31 +00:00
|
|
|
|
2012-07-16 20:37:31 +00:00
|
|
|
$self->{notifier}->notify($message);
|
2012-06-14 11:49:50 +00:00
|
|
|
}
|
|
|
|
|
2016-10-25 11:24:42 +00:00
|
|
|
# Called after the Preferences dialog is closed and the program settings are saved.
|
|
|
|
# Update the UI based on the current preferences.
|
|
|
|
sub update_ui_from_settings {
|
|
|
|
my ($self) = @_;
|
|
|
|
$self->{mainframe}->update_ui_from_settings;
|
|
|
|
}
|
|
|
|
|
2014-01-18 17:43:55 +00:00
|
|
|
sub open_model {
|
2014-06-14 17:54:18 +00:00
|
|
|
my ($self, $window) = @_;
|
2018-02-28 14:39:20 +00:00
|
|
|
|
|
|
|
my $dlg_title = L('Choose one or more files (STL/OBJ/AMF/3MF/PRUSA):');
|
|
|
|
my $dialog = Wx::FileDialog->new($window // $self->GetTopWindow, $dlg_title,
|
2017-11-02 15:21:34 +00:00
|
|
|
$self->{app_config}->get_last_dir, "",
|
2014-06-14 17:54:18 +00:00
|
|
|
MODEL_WILDCARD, wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST);
|
2014-01-18 17:43:55 +00:00
|
|
|
if ($dialog->ShowModal != wxID_OK) {
|
|
|
|
$dialog->Destroy;
|
|
|
|
return;
|
|
|
|
}
|
2017-08-03 15:31:31 +00:00
|
|
|
my @input_files = $dialog->GetPaths;
|
2014-01-18 17:43:55 +00:00
|
|
|
$dialog->Destroy;
|
|
|
|
return @input_files;
|
|
|
|
}
|
|
|
|
|
2013-08-25 12:37:50 +00:00
|
|
|
sub CallAfter {
|
2014-06-14 17:54:18 +00:00
|
|
|
my ($self, $cb) = @_;
|
2013-08-25 12:37:50 +00:00
|
|
|
push @cb, $cb;
|
|
|
|
}
|
|
|
|
|
2017-08-04 14:28:01 +00:00
|
|
|
sub append_menu_item {
|
|
|
|
my ($self, $menu, $string, $description, $cb, $id, $icon, $kind) = @_;
|
|
|
|
|
|
|
|
$id //= &Wx::NewId();
|
|
|
|
my $item = Wx::MenuItem->new($menu, $id, $string, $description // '', $kind // 0);
|
|
|
|
$self->set_menu_item_icon($item, $icon);
|
|
|
|
$menu->Append($item);
|
|
|
|
|
|
|
|
EVT_MENU($self, $id, $cb);
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub append_submenu {
|
|
|
|
my ($self, $menu, $string, $description, $submenu, $id, $icon) = @_;
|
|
|
|
|
|
|
|
$id //= &Wx::NewId();
|
|
|
|
my $item = Wx::MenuItem->new($menu, $id, $string, $description // '');
|
|
|
|
$self->set_menu_item_icon($item, $icon);
|
|
|
|
$item->SetSubMenu($submenu);
|
|
|
|
$menu->Append($item);
|
|
|
|
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub set_menu_item_icon {
|
|
|
|
my ($self, $menuItem, $icon) = @_;
|
|
|
|
|
|
|
|
# SetBitmap was not available on OS X before Wx 0.9927
|
|
|
|
if ($icon && $menuItem->can('SetBitmap')) {
|
2017-10-25 10:53:31 +00:00
|
|
|
$menuItem->SetBitmap(Wx::Bitmap->new(Slic3r::var($icon), wxBITMAP_TYPE_PNG));
|
2017-08-04 14:28:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-04 13:54:12 +00:00
|
|
|
sub save_window_pos {
|
|
|
|
my ($self, $window, $name) = @_;
|
|
|
|
|
2017-11-02 15:21:34 +00:00
|
|
|
$self->{app_config}->set("${name}_pos", join ',', $window->GetScreenPositionXY);
|
|
|
|
$self->{app_config}->set("${name}_size", join ',', $window->GetSizeWH);
|
|
|
|
$self->{app_config}->set("${name}_maximized", $window->IsMaximized);
|
|
|
|
$self->{app_config}->save;
|
2017-08-04 13:54:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub restore_window_pos {
|
|
|
|
my ($self, $window, $name) = @_;
|
2017-11-02 15:21:34 +00:00
|
|
|
if ($self->{app_config}->has("${name}_pos")) {
|
|
|
|
my $size = [ split ',', $self->{app_config}->get("${name}_size"), 2 ];
|
2017-08-04 13:54:12 +00:00
|
|
|
$window->SetSize($size);
|
|
|
|
|
|
|
|
my $display = Wx::Display->new->GetClientArea();
|
2017-11-02 15:21:34 +00:00
|
|
|
my $pos = [ split ',', $self->{app_config}->get("${name}_pos"), 2 ];
|
2017-08-04 13:54:12 +00:00
|
|
|
if (($pos->[0] + $size->[0]/2) < $display->GetRight && ($pos->[1] + $size->[1]/2) < $display->GetBottom) {
|
|
|
|
$window->Move($pos);
|
|
|
|
}
|
2017-11-02 15:21:34 +00:00
|
|
|
$window->Maximize(1) if $self->{app_config}->get("${name}_maximized");
|
2017-08-04 13:54:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-03 09:55:32 +00:00
|
|
|
1;
|