Preferences.pm 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package Slic3r::GUI::Preferences;
  2. use Wx qw(:dialog :id :misc :sizer :systemsettings wxTheApp);
  3. use Wx::Event qw(EVT_BUTTON EVT_TEXT_ENTER);
  4. use base 'Wx::Dialog';
  5. sub new {
  6. my ($class, $parent) = @_;
  7. my $self = $class->SUPER::new($parent, -1, "Preferences", wxDefaultPosition, wxDefaultSize);
  8. $self->{values} = {};
  9. my $optgroup;
  10. $optgroup = Slic3r::GUI::OptionsGroup->new(
  11. parent => $self,
  12. title => 'General',
  13. on_change => sub {
  14. my ($opt_id) = @_;
  15. $self->{values}{$opt_id} = $optgroup->get_value($opt_id);
  16. },
  17. label_width => 200,
  18. );
  19. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  20. opt_id => 'mode',
  21. type => 'select',
  22. label => 'Mode',
  23. tooltip => 'Choose between a simpler, basic mode and an expert mode with more options and more complicated interface.',
  24. labels => ['Simple','Expert'],
  25. values => ['simple','expert'],
  26. default => $Slic3r::GUI::Settings->{_}{mode},
  27. width => 100,
  28. ));
  29. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  30. opt_id => 'version_check',
  31. type => 'bool',
  32. label => 'Check for updates',
  33. tooltip => 'If this is enabled, Slic3r will check for updates daily and display a reminder if a newer version is available.',
  34. default => $Slic3r::GUI::Settings->{_}{version_check} // 1,
  35. readonly => !wxTheApp->have_version_check,
  36. ));
  37. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  38. opt_id => 'remember_output_path',
  39. type => 'bool',
  40. label => 'Remember output directory',
  41. tooltip => 'If this is enabled, Slic3r will prompt the last output directory instead of the one containing the input files.',
  42. default => $Slic3r::GUI::Settings->{_}{remember_output_path},
  43. ));
  44. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  45. opt_id => 'autocenter',
  46. type => 'bool',
  47. label => 'Auto-center parts',
  48. tooltip => 'If this is enabled, Slic3r will auto-center objects around the print bed center.',
  49. default => $Slic3r::GUI::Settings->{_}{autocenter},
  50. ));
  51. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  52. opt_id => 'background_processing',
  53. type => 'bool',
  54. label => 'Background processing',
  55. 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.',
  56. default => $Slic3r::GUI::Settings->{_}{background_processing},
  57. readonly => !$Slic3r::have_threads,
  58. ));
  59. my $sizer = Wx::BoxSizer->new(wxVERTICAL);
  60. $sizer->Add($optgroup->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
  61. my $buttons = $self->CreateStdDialogButtonSizer(wxOK | wxCANCEL);
  62. EVT_BUTTON($self, wxID_OK, sub { $self->_accept });
  63. $sizer->Add($buttons, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
  64. $self->SetSizer($sizer);
  65. $sizer->SetSizeHints($self);
  66. return $self;
  67. }
  68. sub _accept {
  69. my $self = shift;
  70. if ($self->{values}{mode}) {
  71. Slic3r::GUI::warning_catcher($self)->("You need to restart Slic3r to make the changes effective.");
  72. }
  73. $Slic3r::GUI::Settings->{_}{$_} = $self->{values}{$_} for keys %{$self->{values}};
  74. wxTheApp->save_settings;
  75. $self->EndModal(wxID_OK);
  76. $self->Close; # needed on Linux
  77. }
  78. 1;