From d8a64f038657844e023ff04a428a13a552674911 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 18 Jun 2012 11:52:45 +0200 Subject: [PATCH] Use spin controls for integer values --- lib/Slic3r/Config.pm | 26 ++++++++++++++++++++++---- lib/Slic3r/GUI/OptionsGroup.pm | 15 ++++++++++----- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index c9a4647b2..4e116df58 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -26,6 +26,8 @@ our $Options = { sidetext => '(more speed but more memory usage)', cli => 'threads|j=i', type => 'i', + min => 1, + max => 16, }, # output options @@ -110,18 +112,21 @@ our $Options = { sidetext => '°C', cli => 'first-layer-temperature=i', type => 'i', + max => 300, }, 'first_layer_bed_temperature' => { label => 'First layer bed temperature', sidetext => '°C', cli => 'first-layer-bed-temperature=i', type => 'i', + max => 300, }, 'temperature' => { label => 'Temperature', sidetext => '°C', cli => 'temperature=i', type => 'i', + max => 300, important => 1, }, 'bed_temperature' => { @@ -129,6 +134,7 @@ our $Options = { sidetext => '°C', cli => 'bed-temperature=i', type => 'i', + max => 300, }, # speed options @@ -227,6 +233,7 @@ our $Options = { sidetext => 'layers', cli => 'infill-every-layers=i', type => 'i', + min => 1, }, # flow options @@ -296,6 +303,7 @@ our $Options = { sidetext => '°', cli => 'fill-angle=i', type => 'i', + max => 359, }, 'randomize_start' => { label => 'Randomize starting points', @@ -367,6 +375,7 @@ our $Options = { sidetext => 'mm/s', cli => 'retract-speed=f', type => 'i', + max => 1000, }, 'retract_restart_extra' => { label => 'Extra length on restart', @@ -398,24 +407,28 @@ our $Options = { sidetext => '%', cli => 'min-fan-speed=i', type => 'i', + max => 1000, }, 'max_fan_speed' => { label => 'Max fan speed', sidetext => '%', cli => 'max-fan-speed=i', type => 'i', + max => 1000, }, 'bridge_fan_speed' => { label => 'Bridge fan speed', sidetext => '%', cli => 'bridge-fan-speed=i', type => 'i', + max => 1000, }, 'fan_below_layer_time' => { label => 'Enable fan if layer print time is below', sidetext => 'approximate seconds', cli => 'fan-below-layer-time=i', type => 'i', + max => 1000, width => 60, }, 'slowdown_below_layer_time' => { @@ -423,6 +436,7 @@ our $Options = { sidetext => 'approximate seconds', cli => 'slowdown-below-layer-time=i', type => 'i', + max => 1000, width => 60, }, 'min_print_speed' => { @@ -430,12 +444,14 @@ our $Options = { sidetext => 'mm/s', cli => 'min-print-speed=f', type => 'i', + max => 1000, }, 'disable_fan_first_layers' => { label => 'Disable fan for the first', sidetext => 'layers', cli => 'disable-fan-first-layers=i', type => 'i', + max => 1000, }, 'fan_always_on' => { label => 'Keep fan always on', @@ -453,7 +469,7 @@ our $Options = { label => 'Distance from object', sidetext => 'mm', cli => 'skirt-distance=f', - type => 'i', + type => 'f', }, 'skirt_height' => { label => 'Skirt height', @@ -473,6 +489,7 @@ our $Options = { sidetext => '°', cli => 'rotate=i', type => 'i', + max => 359, }, 'duplicate_mode' => { label => 'Duplicate', @@ -485,6 +502,7 @@ our $Options = { label => 'Copies (autoarrange)', cli => 'duplicate=i', type => 'i', + min => 1, }, 'bed_size' => { label => 'Bed size', @@ -505,7 +523,7 @@ our $Options = { label => 'Distance between copies', sidetext => 'mm', cli => 'duplicate-distance=f', - type => 'i', + type => 'f', aliases => [qw(multiply_distance)], }, @@ -519,13 +537,13 @@ our $Options = { label => 'Extruder clearance radius', sidetext => 'mm', cli => 'extruder-clearance-radius=f', - type => 'i', + type => 'f', }, 'extruder_clearance_height' => { label => 'Extruder clearance height', sidetext => 'mm', cli => 'extruder-clearance-height=f', - type => 'i', + type => 'f', }, }; diff --git a/lib/Slic3r/GUI/OptionsGroup.pm b/lib/Slic3r/GUI/OptionsGroup.pm index caf9956a0..dd36a6ad2 100644 --- a/lib/Slic3r/GUI/OptionsGroup.pm +++ b/lib/Slic3r/GUI/OptionsGroup.pm @@ -3,7 +3,7 @@ use strict; use warnings; use Wx qw(:sizer wxSYS_DEFAULT_GUI_FONT); -use Wx::Event qw(EVT_TEXT EVT_CHECKBOX EVT_CHOICE); +use Wx::Event qw(EVT_TEXT EVT_SPINCTRL EVT_CHECKBOX EVT_CHOICE); use base 'Wx::StaticBoxSizer'; @@ -49,9 +49,14 @@ sub new { my ($get, $set) = $opt->{type} eq 's@' ? qw(serialize deserialize) : qw(get set); - $field = Wx::TextCtrl->new($parent, -1, Slic3r::Config->$get($opt_key), - Wx::wxDefaultPosition, $size, $style); - EVT_TEXT($parent, $field, sub { Slic3r::Config->$set($opt_key, $field->GetValue) }); + if ($opt->{type} eq 'i') { + my $value = Slic3r::Config->$get($opt_key); + $field = Wx::SpinCtrl->new($parent, -1, $value, Wx::wxDefaultPosition, $size, $style, $opt->{min} || 0, $opt->{max} || 100, $value); + EVT_SPINCTRL($parent, $field, sub { Slic3r::Config->$set($opt_key, $field->GetValue) }); + } else { + $field = Wx::TextCtrl->new($parent, -1, Slic3r::Config->$get($opt_key), Wx::wxDefaultPosition, $size, $style); + EVT_TEXT($parent, $field, sub { Slic3r::Config->$set($opt_key, $field->GetValue) }); + } push @reload_callbacks, sub { $field->SetValue(Slic3r::Config->$get($opt_key)) }; } elsif ($opt->{type} eq 'bool') { $field = Wx::CheckBox->new($parent, -1, ""); @@ -100,7 +105,7 @@ sub new { $sizer->Add($field); my $sidetext = Wx::StaticText->new($parent, -1, $opt->{sidetext}, Wx::wxDefaultPosition, [-1, -1]); $sidetext->SetFont($sidetext_font); - $sizer->Add($sidetext, 0, &Wx::wxLEFT, 4); + $sizer->Add($sidetext, 0, &Wx::wxLEFT | &Wx::wxALIGN_CENTER_VERTICAL , 4); $grid_sizer->Add($sizer); } else { $grid_sizer->Add($field, 0, $opt->{full_width} ? &Wx::wxEXPAND : 0);