mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-25 07:34:03 -06:00
Use a popup menu for part settings
This commit is contained in:
parent
21e6de0e59
commit
bf8c388568
1 changed files with 17 additions and 17 deletions
|
@ -5,7 +5,7 @@ use utf8;
|
||||||
|
|
||||||
use File::Basename qw(basename);
|
use File::Basename qw(basename);
|
||||||
use Wx qw(:misc :sizer :button wxTAB_TRAVERSAL wxSUNKEN_BORDER wxBITMAP_TYPE_PNG);
|
use Wx qw(:misc :sizer :button wxTAB_TRAVERSAL wxSUNKEN_BORDER wxBITMAP_TYPE_PNG);
|
||||||
use Wx::Event qw(EVT_BUTTON);
|
use Wx::Event qw(EVT_BUTTON EVT_LEFT_DOWN EVT_MENU);
|
||||||
use base 'Wx::ScrolledWindow';
|
use base 'Wx::ScrolledWindow';
|
||||||
|
|
||||||
use constant ICON_MATERIAL => 0;
|
use constant ICON_MATERIAL => 0;
|
||||||
|
@ -22,20 +22,23 @@ sub new {
|
||||||
|
|
||||||
# option selector
|
# option selector
|
||||||
{
|
{
|
||||||
my $choice = $self->{choice} = Wx::Choice->new($self, -1, wxDefaultPosition, [150, -1], []);
|
|
||||||
|
|
||||||
# create the button
|
# create the button
|
||||||
my $btn = $self->{btn_add} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/add.png", wxBITMAP_TYPE_PNG));
|
my $btn = $self->{btn_add} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/add.png", wxBITMAP_TYPE_PNG));
|
||||||
EVT_BUTTON($self, $btn, sub {
|
EVT_LEFT_DOWN($btn, sub {
|
||||||
my $idx = $choice->GetSelection;
|
my $menu = Wx::Menu->new;
|
||||||
return if $idx == -1; # lack of selected item, can happen on Windows
|
foreach my $opt_key (@{$self->{options}}) {
|
||||||
my $opt_key = $self->{options}[$idx];
|
my $id = &Wx::NewId();
|
||||||
$self->{config}->apply(Slic3r::Config->new_from_defaults($opt_key));
|
$menu->Append($id, $self->{option_labels}{$opt_key});
|
||||||
$self->update_optgroup;
|
EVT_MENU($menu, $id, sub {
|
||||||
|
$self->{config}->apply(Slic3r::Config->new_from_defaults($opt_key));
|
||||||
|
$self->update_optgroup;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$self->PopupMenu($menu, $btn->GetPosition);
|
||||||
|
$menu->Destroy;
|
||||||
});
|
});
|
||||||
|
|
||||||
my $h_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
my $h_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
||||||
$h_sizer->Add($choice, 1, wxEXPAND | wxALL, 0);
|
|
||||||
$h_sizer->Add($btn, 0, wxEXPAND | wxLEFT, 10);
|
$h_sizer->Add($btn, 0, wxEXPAND | wxLEFT, 10);
|
||||||
$self->{sizer}->Add($h_sizer, 0, wxEXPAND | wxBOTTOM, 10);
|
$self->{sizer}->Add($h_sizer, 0, wxEXPAND | wxBOTTOM, 10);
|
||||||
}
|
}
|
||||||
|
@ -56,11 +59,10 @@ sub set_opt_keys {
|
||||||
my ($self, $opt_keys) = @_;
|
my ($self, $opt_keys) = @_;
|
||||||
|
|
||||||
# sort options by category+label
|
# sort options by category+label
|
||||||
my %settings = map { $_ => sprintf('%s > %s', $Slic3r::Config::Options->{$_}{category}, $Slic3r::Config::Options->{$_}{full_label} // $Slic3r::Config::Options->{$_}{label}) } @$opt_keys;
|
$self->{option_labels} = {
|
||||||
$self->{options} = [ sort { $settings{$a} cmp $settings{$b} } keys %settings ];
|
map { $_ => sprintf('%s > %s', $Slic3r::Config::Options->{$_}{category}, $Slic3r::Config::Options->{$_}{full_label} // $Slic3r::Config::Options->{$_}{label}) } @$opt_keys
|
||||||
|
};
|
||||||
$self->{choice}->Clear;
|
$self->{options} = [ sort { $self->{option_labels}{$a} cmp $self->{option_labels}{$b} } @$opt_keys ];
|
||||||
$self->{choice}->Append($_) for map $settings{$_}, @{$self->{options}};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub set_config {
|
sub set_config {
|
||||||
|
@ -108,7 +110,6 @@ sub update_optgroup {
|
||||||
sub enable {
|
sub enable {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
$self->{choice}->Enable;
|
|
||||||
$self->{btn_add}->Enable;
|
$self->{btn_add}->Enable;
|
||||||
$self->Enable;
|
$self->Enable;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +117,6 @@ sub enable {
|
||||||
sub disable {
|
sub disable {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
$self->{choice}->Disable;
|
|
||||||
$self->{btn_add}->Disable;
|
$self->{btn_add}->Disable;
|
||||||
$self->Disable;
|
$self->Disable;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue