Preferences.pm 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # Preferences dialog, opens from Menu: File->Preferences
  2. package Slic3r::GUI::Preferences;
  3. use Wx qw(:dialog :id :misc :sizer :systemsettings wxTheApp);
  4. use Wx::Event qw(EVT_BUTTON EVT_TEXT_ENTER);
  5. use base 'Wx::Dialog';
  6. sub new {
  7. my ($class, $parent) = @_;
  8. my $self = $class->SUPER::new($parent, -1, "Preferences", wxDefaultPosition, wxDefaultSize);
  9. $self->{values} = {};
  10. my $app_config = wxTheApp->{app_config};
  11. my $optgroup;
  12. $optgroup = Slic3r::GUI::OptionsGroup->new(
  13. parent => $self,
  14. title => 'General',
  15. on_change => sub {
  16. my ($opt_id) = @_;
  17. $self->{values}{$opt_id} = $optgroup->get_value($opt_id);
  18. },
  19. label_width => 200,
  20. );
  21. # $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  22. # opt_id => 'version_check',
  23. # type => 'bool',
  24. # label => 'Check for updates',
  25. # tooltip => 'If this is enabled, Slic3r will check for updates daily and display a reminder if a newer version is available.',
  26. # default => $app_config->get("version_check") // 1,
  27. # readonly => !wxTheApp->have_version_check,
  28. # ));
  29. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  30. opt_id => 'remember_output_path',
  31. type => 'bool',
  32. label => 'Remember output directory',
  33. tooltip => 'If this is enabled, Slic3r will prompt the last output directory instead of the one containing the input files.',
  34. default => $app_config->get("remember_output_path"),
  35. ));
  36. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  37. opt_id => 'autocenter',
  38. type => 'bool',
  39. label => 'Auto-center parts',
  40. tooltip => 'If this is enabled, Slic3r will auto-center objects around the print bed center.',
  41. default => $app_config->get("autocenter"),
  42. ));
  43. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  44. opt_id => 'background_processing',
  45. type => 'bool',
  46. label => 'Background processing',
  47. tooltip => 'If this is enabled, Slic3r will pre-process objects as soon as they\'re loaded in order to save time when exporting G-code.',
  48. default => $app_config->get("background_processing"),
  49. ));
  50. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  51. opt_id => 'no_controller',
  52. type => 'bool',
  53. label => 'Disable USB/serial connection',
  54. tooltip => 'Disable communication with the printer over a serial / USB cable. This simplifies the user interface in case the printer is never attached to the computer.',
  55. default => $app_config->get("no_controller"),
  56. ));
  57. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  58. opt_id => 'no_defaults',
  59. type => 'bool',
  60. label => 'Suppress "- default -" presets',
  61. tooltip => 'Suppress "- default -" presets in the Print / Filament / Printer selections once there are any other valid presets available.',
  62. default => $app_config->get("no_defaults"),
  63. ));
  64. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  65. opt_id => 'show_incompatible_presets',
  66. type => 'bool',
  67. label => 'Show incompatible print and filament presets',
  68. tooltip => 'When checked, the print and filament presets are shown in the preset editor even ' .
  69. 'if they are marked as incompatible with the active printer',
  70. default => $app_config->get("show_incompatible_presets"),
  71. ));
  72. my $sizer = Wx::BoxSizer->new(wxVERTICAL);
  73. $sizer->Add($optgroup->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
  74. my $buttons = $self->CreateStdDialogButtonSizer(wxOK | wxCANCEL);
  75. EVT_BUTTON($self, wxID_OK, sub { $self->_accept });
  76. $sizer->Add($buttons, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
  77. $self->SetSizer($sizer);
  78. $sizer->SetSizeHints($self);
  79. return $self;
  80. }
  81. sub _accept {
  82. my ($self) = @_;
  83. if (defined($self->{values}{no_controller}) ||
  84. defined($self->{values}{no_defaults})) {
  85. Slic3r::GUI::warning_catcher($self)->("You need to restart Slic3r to make the changes effective.");
  86. }
  87. my $app_config = wxTheApp->{app_config};
  88. $app_config->set($_, $self->{values}{$_}) for keys %{$self->{values}};
  89. $self->EndModal(wxID_OK);
  90. $self->Close; # needed on Linux
  91. # Nothify the UI to update itself from the ini file.
  92. wxTheApp->update_ui_from_settings;
  93. }
  94. 1;