Preferences.pm 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 => 'mode',
  22. type => 'select',
  23. label => 'Mode',
  24. tooltip => 'Choose between a simpler, basic mode and an expert mode with more options and more complicated interface.',
  25. labels => ['Simple','Expert'],
  26. values => ['simple','expert'],
  27. default => $Slic3r::GUI::Settings->{_}{mode},
  28. width => 100,
  29. ));
  30. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  31. opt_id => 'version_check',
  32. type => 'bool',
  33. label => 'Check for updates',
  34. tooltip => 'If this is enabled, Slic3r will check for updates daily and display a reminder if a newer version is available.',
  35. default => $Slic3r::GUI::Settings->{_}{version_check} // 1,
  36. readonly => !wxTheApp->have_version_check,
  37. ));
  38. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  39. opt_id => 'remember_output_path',
  40. type => 'bool',
  41. label => 'Remember output directory',
  42. tooltip => 'If this is enabled, Slic3r will prompt the last output directory instead of the one containing the input files.',
  43. default => $Slic3r::GUI::Settings->{_}{remember_output_path},
  44. ));
  45. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  46. opt_id => 'autocenter',
  47. type => 'bool',
  48. label => 'Auto-center parts',
  49. tooltip => 'If this is enabled, Slic3r will auto-center objects around the print bed center.',
  50. default => $Slic3r::GUI::Settings->{_}{autocenter},
  51. ));
  52. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  53. opt_id => 'background_processing',
  54. type => 'bool',
  55. label => 'Background processing',
  56. 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.',
  57. default => $Slic3r::GUI::Settings->{_}{background_processing},
  58. readonly => !$Slic3r::have_threads,
  59. ));
  60. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  61. opt_id => 'no_controller',
  62. type => 'bool',
  63. label => 'Disable USB/serial connection',
  64. 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.',
  65. default => $Slic3r::GUI::Settings->{_}{no_controller},
  66. ));
  67. $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  68. opt_id => 'no_defaults',
  69. type => 'bool',
  70. label => 'Suppress "- default -" presets',
  71. tooltip => 'Suppress "- default -" presets in the Print / Filament / Printer selections once there are any other valid presets available.',
  72. default => $Slic3r::GUI::Settings->{_}{no_defaults},
  73. ));
  74. my $sizer = Wx::BoxSizer->new(wxVERTICAL);
  75. $sizer->Add($optgroup->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
  76. my $buttons = $self->CreateStdDialogButtonSizer(wxOK | wxCANCEL);
  77. EVT_BUTTON($self, wxID_OK, sub { $self->_accept });
  78. $sizer->Add($buttons, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
  79. $self->SetSizer($sizer);
  80. $sizer->SetSizeHints($self);
  81. return $self;
  82. }
  83. sub _accept {
  84. my $self = shift;
  85. if ($self->{values}{mode} || defined($self->{values}{no_controller})) {
  86. Slic3r::GUI::warning_catcher($self)->("You need to restart Slic3r to make the changes effective.");
  87. }
  88. $Slic3r::GUI::Settings->{_}{$_} = $self->{values}{$_} for keys %{$self->{values}};
  89. wxTheApp->save_settings;
  90. $self->EndModal(wxID_OK);
  91. $self->Close; # needed on Linux
  92. }
  93. 1;