Nicer configuration fields for USB/Serial connection
This commit is contained in:
parent
16939b80e6
commit
cbc0e270b7
5 changed files with 93 additions and 19 deletions
lib/Slic3r/GUI/OptionsGroup
|
@ -194,13 +194,15 @@ extends 'Slic3r::GUI::OptionsGroup::Field::wxWindow';
|
|||
|
||||
use List::Util qw(first);
|
||||
use Wx qw(:misc :combobox);
|
||||
use Wx::Event qw(EVT_COMBOBOX);
|
||||
use Wx::Event qw(EVT_COMBOBOX EVT_TEXT);
|
||||
|
||||
sub BUILD {
|
||||
my ($self) = @_;
|
||||
|
||||
my $style = 0;
|
||||
$style |= wxCB_READONLY if $self->option->gui_type ne 'select_open';
|
||||
my $field = Wx::ComboBox->new($self->parent, -1, "", wxDefaultPosition, $self->_default_size,
|
||||
$self->option->labels || $self->option->values, wxCB_READONLY);
|
||||
$self->option->labels || $self->option->values || [], $style);
|
||||
$self->wxWindow($field);
|
||||
|
||||
$self->set_value($self->option->default);
|
||||
|
@ -208,24 +210,49 @@ sub BUILD {
|
|||
EVT_COMBOBOX($self->parent, $field, sub {
|
||||
$self->_on_change($self->option->opt_id);
|
||||
});
|
||||
EVT_TEXT($self->parent, $field, sub {
|
||||
$self->_on_change($self->option->opt_id);
|
||||
});
|
||||
}
|
||||
|
||||
sub set_value {
|
||||
my ($self, $value) = @_;
|
||||
|
||||
my $idx = first { $self->option->values->[$_] eq $value } 0..$#{$self->option->values};
|
||||
$self->disable_change_event(1);
|
||||
|
||||
if ($self->option->values) {
|
||||
my $idx = first { $self->option->values->[$_] eq $value } 0..$#{$self->option->values};
|
||||
$self->wxWindow->SetSelection($idx);
|
||||
} else {
|
||||
$self->wxWindow->SetValue($value);
|
||||
}
|
||||
|
||||
$self->disable_change_event(0);
|
||||
}
|
||||
|
||||
sub set_values {
|
||||
my ($self, $values) = @_;
|
||||
|
||||
$self->disable_change_event(1);
|
||||
$self->wxWindow->SetSelection($idx);
|
||||
|
||||
$self->wxWindow->Clear;
|
||||
$self->wxWindow->Append($_) for @$values;
|
||||
|
||||
$self->disable_change_event(0);
|
||||
}
|
||||
|
||||
sub get_value {
|
||||
my ($self) = @_;
|
||||
return $self->option->values->[$self->wxWindow->GetSelection];
|
||||
|
||||
if ($self->option->values) {
|
||||
my $idx = $self->wxWindow->GetSelection;
|
||||
if ($idx != &Wx::wxNOT_FOUND) {
|
||||
return $self->option->values->[$idx];
|
||||
}
|
||||
}
|
||||
return $self->wxWindow->GetValue;
|
||||
}
|
||||
|
||||
|
||||
package Slic3r::GUI::OptionsGroup::Field::NumericChoice;
|
||||
use Moo;
|
||||
extends 'Slic3r::GUI::OptionsGroup::Field::wxWindow';
|
||||
|
@ -311,12 +338,14 @@ sub get_value {
|
|||
my ($self) = @_;
|
||||
|
||||
my $label = $self->wxWindow->GetValue;
|
||||
my $value_idx = first { $self->option->labels->[$_] eq $label } 0..$#{$self->option->labels};
|
||||
if (defined $value_idx) {
|
||||
if ($self->option->values) {
|
||||
return $self->option->values->[$value_idx];
|
||||
if ($self->option->labels) {
|
||||
my $value_idx = first { $self->option->labels->[$_] eq $label } 0..$#{$self->option->labels};
|
||||
if (defined $value_idx) {
|
||||
if ($self->option->values) {
|
||||
return $self->option->values->[$value_idx];
|
||||
}
|
||||
return $value_idx;
|
||||
}
|
||||
return $value_idx;
|
||||
}
|
||||
return $label;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue