From 8cbb12aeb643d7f898c9ab1b75e42662a5c8bcca Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 24 May 2015 17:24:10 +0200 Subject: [PATCH] Workaround for wxCocoa bug causing wxSpinCtrl values to be reset when losing focus after changing them from the text field. #2612 --- lib/Slic3r/GUI/OptionsGroup/Field.pm | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Slic3r/GUI/OptionsGroup/Field.pm b/lib/Slic3r/GUI/OptionsGroup/Field.pm index 2eab6053c..bc8e6a02d 100644 --- a/lib/Slic3r/GUI/OptionsGroup/Field.pm +++ b/lib/Slic3r/GUI/OptionsGroup/Field.pm @@ -7,7 +7,6 @@ has 'parent' => (is => 'ro', required => 1); has 'option' => (is => 'ro', required => 1); # Slic3r::GUI::OptionsGroup::Option has 'on_change' => (is => 'rw', default => sub { sub {} }); has 'on_kill_focus' => (is => 'rw', default => sub { sub {} }); -has 'wxSsizer' => (is => 'rw'); # alternatively, wxSizer object has 'disable_change_event' => (is => 'rw', default => sub { 0 }); # This method should not fire the on_change event @@ -128,6 +127,8 @@ extends 'Slic3r::GUI::OptionsGroup::Field::wxWindow'; use Wx qw(:misc); use Wx::Event qw(EVT_SPINCTRL EVT_TEXT EVT_KILL_FOCUS); +has 'tmp_value' => (is => 'rw'); + sub BUILD { my ($self) = @_; @@ -139,13 +140,27 @@ sub BUILD { $self->_on_change($self->option->opt_id); }); EVT_TEXT($self->parent, $field, sub { + my ($s, $event) = @_; + + # On OSX/Cocoa, wxSpinCtrl::GetValue() doesn't return the new value + # when it was changed from the text control, so the on_change callback + # gets the old one, and on_kill_focus resets the control to the old value. + # As a workaround, we get the new value from $event->GetString and store + # here temporarily so that we can return it from $self->get_value + $self->tmp_value($event->GetString); $self->_on_change($self->option->opt_id); + $self->tmp_value(undef); }); EVT_KILL_FOCUS($field, sub { $self->_on_kill_focus($self->option->opt_id, @_); }); } +sub get_value { + my ($self) = @_; + return $self->tmp_value // $self->wxWindow->GetValue; +} + package Slic3r::GUI::OptionsGroup::Field::TextCtrl; use Moo;