Added a cancel button, and rewrote initial option code to reuse OptionGroup.
This commit is contained in:
parent
3109a9bc1f
commit
a0548898f3
@ -25,7 +25,10 @@ sub new {
|
|||||||
|
|
||||||
$self->{sizer} = Wx::BoxSizer->new(wxVERTICAL);
|
$self->{sizer} = Wx::BoxSizer->new(wxVERTICAL);
|
||||||
my $button_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
my $button_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
||||||
my $buttons = $self->CreateStdDialogButtonSizer(wxOK);
|
my $button_ok = $self->CreateStdDialogButtonSizer(wxOK);
|
||||||
|
my $button_cancel = $self->CreateStdDialogButtonSizer(wxCANCEL);
|
||||||
|
$button_sizer->Add($button_ok);
|
||||||
|
$button_sizer->Add($button_cancel);
|
||||||
EVT_BUTTON($self, wxID_OK, sub {
|
EVT_BUTTON($self, wxID_OK, sub {
|
||||||
# validate user input
|
# validate user input
|
||||||
return if !$self->CanClose;
|
return if !$self->CanClose;
|
||||||
@ -33,66 +36,67 @@ sub new {
|
|||||||
$self->EndModal(wxID_OK);
|
$self->EndModal(wxID_OK);
|
||||||
$self->Destroy;
|
$self->Destroy;
|
||||||
});
|
});
|
||||||
$button_sizer->Add($buttons, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
|
EVT_BUTTON($self, wxID_CANCEL, sub {
|
||||||
|
# validate user input
|
||||||
|
return if !$self->CanClose;
|
||||||
|
|
||||||
|
$self->EndModal(wxID_CANCEL);
|
||||||
|
$self->Destroy;
|
||||||
|
});
|
||||||
|
|
||||||
|
my $optgroup;
|
||||||
|
$optgroup = $self->{optgroup} = Slic3r::GUI::OptionsGroup->new(
|
||||||
|
parent => $self,
|
||||||
|
title => 'Add Generic...',
|
||||||
|
on_change => sub {
|
||||||
|
# Do validation
|
||||||
|
my ($opt_id) = @_;
|
||||||
|
if ($opt_id == 0 || $opt_id == 1 || $opt_id == 2) {
|
||||||
|
if (!looks_like_number($optgroup->get_value($opt_id))) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$self->{object_parameters}->{dim}[$opt_id] = $optgroup->get_value($opt_id);
|
||||||
|
},
|
||||||
|
label_width => 100,
|
||||||
|
);
|
||||||
my @options = ("box");
|
my @options = ("box");
|
||||||
$self->{type} = Wx::ComboBox->new($self, 1, "box", wxDefaultPosition, wxDefaultSize, \@options, wxCB_READONLY);
|
$self->{type} = Wx::ComboBox->new($self, 1, "box", wxDefaultPosition, wxDefaultSize, \@options, wxCB_READONLY);
|
||||||
|
#my @types = ("box");
|
||||||
my $sbox = Wx::StaticBox->new($self, -1, '', wxDefaultPosition, wxDefaultSize, 0, 'sbox');
|
#$optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
|
||||||
my $cube_dim_sizer = Wx::StaticBoxSizer->new($sbox, wxVERTICAL);
|
# opt_id => 'type',
|
||||||
{
|
# label => 'Type',
|
||||||
my $opt_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
# type => 'select',
|
||||||
{
|
# values => \@types,
|
||||||
my $lbl = Wx::StaticText->new($self, 2, "X", wxDefaultPosition, Wx::Size->new(10,-1));
|
# default => 'box',
|
||||||
$self->{dim_x} = Wx::TextCtrl->new($self, 2, "1", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_TAB);
|
#));
|
||||||
$opt_sizer->Add($lbl, 1, wxRIGHT , 8);
|
$optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
|
||||||
$opt_sizer->Add($self->{dim_x});
|
opt_id => 0,
|
||||||
|
label => 'L',
|
||||||
}
|
type => 'f',
|
||||||
$cube_dim_sizer->Add($opt_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10);
|
default => '1',
|
||||||
$opt_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
));
|
||||||
{
|
$optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
|
||||||
my $lbl = Wx::StaticText->new($self, -1, "Y", wxDefaultPosition, Wx::Size->new(10,-1));
|
opt_id => 1,
|
||||||
$self->{dim_y} = Wx::TextCtrl->new($self, 2, "1", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_TAB);
|
label => 'W',
|
||||||
$opt_sizer->Add($lbl, 1, wxRIGHT , 8);
|
type => 'f',
|
||||||
$opt_sizer->Add($self->{dim_y});
|
default => '1',
|
||||||
}
|
));
|
||||||
$cube_dim_sizer->Add($opt_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10);
|
$optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
|
||||||
$opt_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
opt_id => 2,
|
||||||
{
|
label => 'H',
|
||||||
my $lbl = Wx::StaticText->new($self, -1, "Z", wxDefaultPosition, Wx::Size->new(10,-1));
|
type => 'f',
|
||||||
$self->{dim_z} = Wx::TextCtrl->new($self, 2, "1", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_TAB);
|
default => '1',
|
||||||
$opt_sizer->Add($lbl, 1, wxRIGHT , 8);
|
));
|
||||||
$opt_sizer->Add($self->{dim_z});
|
|
||||||
}
|
|
||||||
$cube_dim_sizer->Add($opt_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10);
|
|
||||||
EVT_TEXT($self, 2, sub {
|
|
||||||
if (!looks_like_number($self->{dim_x}->GetValue)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (!looks_like_number($self->{dim_y}->GetValue)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (!looks_like_number($self->{dim_z}->GetValue)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if ($self->{dim_x}->GetValue() > 0) {
|
|
||||||
$self->{object_parameters}->{dim}[0] = $self->{dim_x}->GetValue;
|
|
||||||
}
|
|
||||||
if ($self->{dim_y}->GetValue() > 0) {
|
|
||||||
$self->{object_parameters}->{dim}[1] = $self->{dim_y}->GetValue;
|
|
||||||
}
|
|
||||||
if ($self->{dim_z}->GetValue() > 0) {
|
|
||||||
$self->{object_parameters}->{dim}[2] = $self->{dim_z}->GetValue;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
EVT_COMBOBOX($self, 1, sub{
|
EVT_COMBOBOX($self, 1, sub{
|
||||||
$self->{object_parameters}->{type} = $self->{type}->GetValue();
|
$self->{object_parameters}->{type} = $self->{type}->GetValue();
|
||||||
});
|
});
|
||||||
$self->{sizer}->Add($self->{type}, 0, wxEXPAND, 3);
|
|
||||||
$self->{sizer}->Add($cube_dim_sizer, 0, wxEXPAND, 10);
|
|
||||||
$self->{sizer}->Add($button_sizer);
|
$optgroup->sizer->Add($self->{type}, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
|
||||||
|
$self->{sizer}->Add($optgroup->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
|
||||||
|
$self->{sizer}->Add($button_sizer,0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
|
||||||
|
|
||||||
$self->SetSizer($self->{sizer});
|
$self->SetSizer($self->{sizer});
|
||||||
$self->{sizer}->Fit($self);
|
$self->{sizer}->Fit($self);
|
||||||
$self->{sizer}->SetSizeHints($self);
|
$self->{sizer}->SetSizeHints($self);
|
||||||
|
@ -7,7 +7,7 @@ use warnings;
|
|||||||
use utf8;
|
use utf8;
|
||||||
|
|
||||||
use File::Basename qw(basename);
|
use File::Basename qw(basename);
|
||||||
use Wx qw(:misc :sizer :treectrl :button wxTAB_TRAVERSAL wxSUNKEN_BORDER wxBITMAP_TYPE_PNG
|
use Wx qw(:misc :sizer :treectrl :button wxTAB_TRAVERSAL wxSUNKEN_BORDER wxBITMAP_TYPE_PNG wxID_CANCEL
|
||||||
wxTheApp);
|
wxTheApp);
|
||||||
use Wx::Event qw(EVT_BUTTON EVT_TREE_ITEM_COLLAPSING EVT_TREE_SEL_CHANGED);
|
use Wx::Event qw(EVT_BUTTON EVT_TREE_ITEM_COLLAPSING EVT_TREE_SEL_CHANGED);
|
||||||
use base 'Wx::Panel';
|
use base 'Wx::Panel';
|
||||||
@ -337,7 +337,9 @@ sub on_btn_lambda {
|
|||||||
my ($self, $is_modifier) = @_;
|
my ($self, $is_modifier) = @_;
|
||||||
|
|
||||||
my $dlg = Slic3r::GUI::Plater::LambdaObjectDialog->new($self);
|
my $dlg = Slic3r::GUI::Plater::LambdaObjectDialog->new($self);
|
||||||
$dlg->ShowModal();
|
if ($dlg->ShowModal() == wxID_CANCEL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
my $params = $dlg->ObjectParameter;
|
my $params = $dlg->ObjectParameter;
|
||||||
my $name = "lambda-".$params->{"type"};
|
my $name = "lambda-".$params->{"type"};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user