Preferences.pm 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 $optgroup;
  11. $optgroup = Slic3r::GUI::OptionsGroup->new(
  12. parent => $self,
  13. title => 'General',
  14. on_change => sub {
  15. my ($opt_id) = @_;
  16. $self->{values}{$opt_id} = $optgroup->get_value($opt_id);
  17. },
  18. label_width => 200,
  19. );
  20. # $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  21. # opt_id => 'version_check',
  22. # type => 'bool',
  23. # label => 'Check for updates',
  24. # tooltip => 'If this is enabled, Slic3r will check for updates daily and display a reminder if a newer version is available.',
  25. # default => $Slic3r::GUI::Settings->{_}{version_check} // 1,
  26. # readonly => !wxTheApp->have_version_check,
  27. # ));
  28. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  29. opt_id => 'remember_output_path',
  30. type => 'bool',
  31. label => 'Remember output directory',
  32. tooltip => 'If this is enabled, Slic3r will prompt the last output directory instead of the one containing the input files.',
  33. default => $Slic3r::GUI::Settings->{_}{remember_output_path},
  34. ));
  35. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  36. opt_id => 'autocenter',
  37. type => 'bool',
  38. label => 'Auto-center parts',
  39. tooltip => 'If this is enabled, Slic3r will auto-center objects around the print bed center.',
  40. default => $Slic3r::GUI::Settings->{_}{autocenter},
  41. ));
  42. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  43. opt_id => 'background_processing',
  44. type => 'bool',
  45. label => 'Background processing',
  46. 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.',
  47. default => $Slic3r::GUI::Settings->{_}{background_processing},
  48. readonly => !$Slic3r::have_threads,
  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 => $Slic3r::GUI::Settings->{_}{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 => $Slic3r::GUI::Settings->{_}{no_defaults},
  63. ));
  64. my $sizer = Wx::BoxSizer->new(wxVERTICAL);
  65. $sizer->Add($optgroup->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
  66. my $buttons = $self->CreateStdDialogButtonSizer(wxOK | wxCANCEL);
  67. EVT_BUTTON($self, wxID_OK, sub { $self->_accept });
  68. $sizer->Add($buttons, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
  69. $self->SetSizer($sizer);
  70. $sizer->SetSizeHints($self);
  71. return $self;
  72. }
  73. sub _accept {
  74. my $self = shift;
  75. if (defined($self->{values}{no_controller})) {
  76. Slic3r::GUI::warning_catcher($self)->("You need to restart Slic3r to make the changes effective.");
  77. }
  78. $Slic3r::GUI::Settings->{_}{$_} = $self->{values}{$_} for keys %{$self->{values}};
  79. wxTheApp->save_settings;
  80. $self->EndModal(wxID_OK);
  81. $self->Close; # needed on Linux
  82. # Nothify the UI to update itself from the ini file.
  83. wxTheApp->update_ui_from_settings;
  84. }
  85. 1;