Sim: Update tuner dialog values when focus is lost

Fixes https://gitlab.com/kicad/code/kicad/issues/7841
This commit is contained in:
Mikolaj Wielgus 2021-10-21 01:33:30 +02:00 committed by Jeff Young
parent 6c0110ecd3
commit 28d7a2d7c9
5 changed files with 98 additions and 36 deletions

View File

@ -131,6 +131,52 @@ void TUNER_SLIDER::updateValueText()
} }
void TUNER_SLIDER::updateMax()
{
try
{
SPICE_VALUE newMax( m_maxText->GetValue() );
SetMax( newMax );
}
catch( const KI_PARAM_ERROR& )
{
// Restore the previous value
m_maxText->SetValue( m_max.ToOrigString() );
}
}
void TUNER_SLIDER::updateValue()
{
try
{
SPICE_VALUE newCur( m_valueText->GetValue() );
SetValue( newCur );
m_changed = true;
}
catch( const KI_PARAM_ERROR& )
{
// Restore the previous value
m_valueText->SetValue( m_value.ToOrigString() );
}
}
void TUNER_SLIDER::updateMin()
{
try
{
SPICE_VALUE newMin( m_minText->GetValue() );
SetMin( newMin );
}
catch( const KI_PARAM_ERROR& )
{
// Restore the previous value
m_minText->SetValue( m_min.ToOrigString() );
}
}
void TUNER_SLIDER::onClose( wxCommandEvent& event ) void TUNER_SLIDER::onClose( wxCommandEvent& event )
{ {
m_frame->RemoveTuner( this ); m_frame->RemoveTuner( this );
@ -153,49 +199,39 @@ void TUNER_SLIDER::onSliderChanged( wxScrollEvent& event )
} }
void TUNER_SLIDER::onMaxKillFocus( wxFocusEvent& event )
{
updateMax();
}
void TUNER_SLIDER::onValueKillFocus( wxFocusEvent& event )
{
updateValue();
}
void TUNER_SLIDER::onMinKillFocus( wxFocusEvent& event )
{
updateMin();
}
void TUNER_SLIDER::onMaxTextEnter( wxCommandEvent& event ) void TUNER_SLIDER::onMaxTextEnter( wxCommandEvent& event )
{ {
try updateMax();
{
SPICE_VALUE newMax( m_maxText->GetValue() );
SetMax( newMax );
}
catch( const KI_PARAM_ERROR& )
{
// Restore the previous value
m_maxText->SetValue( m_max.ToOrigString() );
}
} }
void TUNER_SLIDER::onValueTextEnter( wxCommandEvent& event ) void TUNER_SLIDER::onValueTextEnter( wxCommandEvent& event )
{ {
try updateValue();
{
SPICE_VALUE newCur( m_valueText->GetValue() );
SetValue( newCur );
m_changed = true;
}
catch( const KI_PARAM_ERROR& )
{
// Restore the previous value
m_valueText->SetValue( m_value.ToOrigString() );
}
} }
void TUNER_SLIDER::onMinTextEnter( wxCommandEvent& event ) void TUNER_SLIDER::onMinTextEnter( wxCommandEvent& event )
{ {
try updateMin();
{
SPICE_VALUE newMin( m_minText->GetValue() );
SetMin( newMin );
}
catch( const KI_PARAM_ERROR& )
{
// Restore the previous value
m_minText->SetValue( m_min.ToOrigString() );
}
} }

View File

@ -78,10 +78,18 @@ private:
void updateSlider(); void updateSlider();
void updateValueText(); void updateValueText();
void updateMax();
void updateValue();
void updateMin();
void onClose( wxCommandEvent& event ) override; void onClose( wxCommandEvent& event ) override;
void onSave( wxCommandEvent& event ) override; void onSave( wxCommandEvent& event ) override;
void onSliderChanged( wxScrollEvent& event ) override; void onSliderChanged( wxScrollEvent& event ) override;
void onMaxKillFocus( wxFocusEvent& event ) override;
void onValueKillFocus( wxFocusEvent& event ) override;
void onMinKillFocus( wxFocusEvent& event ) override;
void onMaxTextEnter( wxCommandEvent& event ) override; void onMaxTextEnter( wxCommandEvent& event ) override;
void onValueTextEnter( wxCommandEvent& event ) override; void onValueTextEnter( wxCommandEvent& event ) override;
void onMinTextEnter( wxCommandEvent& event ) override; void onMinTextEnter( wxCommandEvent& event ) override;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Oct 26 2018) // C++ code generated with wxFormBuilder (version 3.10.0)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO *NOT* EDIT THIS FILE! // PLEASE DO *NOT* EDIT THIS FILE!
@ -81,8 +81,11 @@ TUNER_SLIDER_BASE::TUNER_SLIDER_BASE( wxWindow* parent, wxWindowID id, const wxP
m_slider->Connect( wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this ); m_slider->Connect( wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this );
m_slider->Connect( wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this ); m_slider->Connect( wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this );
m_slider->Connect( wxEVT_SCROLL_CHANGED, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this ); m_slider->Connect( wxEVT_SCROLL_CHANGED, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this );
m_maxText->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( TUNER_SLIDER_BASE::onMaxKillFocus ), NULL, this );
m_maxText->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onMaxTextEnter ), NULL, this ); m_maxText->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onMaxTextEnter ), NULL, this );
m_valueText->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( TUNER_SLIDER_BASE::onValueKillFocus ), NULL, this );
m_valueText->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onValueTextEnter ), NULL, this ); m_valueText->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onValueTextEnter ), NULL, this );
m_minText->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( TUNER_SLIDER_BASE::onMinKillFocus ), NULL, this );
m_minText->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onMinTextEnter ), NULL, this ); m_minText->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onMinTextEnter ), NULL, this );
m_saveBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( TUNER_SLIDER_BASE::onSave ), NULL, this ); m_saveBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( TUNER_SLIDER_BASE::onSave ), NULL, this );
} }
@ -100,8 +103,11 @@ TUNER_SLIDER_BASE::~TUNER_SLIDER_BASE()
m_slider->Disconnect( wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this ); m_slider->Disconnect( wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this );
m_slider->Disconnect( wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this ); m_slider->Disconnect( wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this );
m_slider->Disconnect( wxEVT_SCROLL_CHANGED, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this ); m_slider->Disconnect( wxEVT_SCROLL_CHANGED, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this );
m_maxText->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( TUNER_SLIDER_BASE::onMaxKillFocus ), NULL, this );
m_maxText->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onMaxTextEnter ), NULL, this ); m_maxText->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onMaxTextEnter ), NULL, this );
m_valueText->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( TUNER_SLIDER_BASE::onValueKillFocus ), NULL, this );
m_valueText->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onValueTextEnter ), NULL, this ); m_valueText->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onValueTextEnter ), NULL, this );
m_minText->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( TUNER_SLIDER_BASE::onMinKillFocus ), NULL, this );
m_minText->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onMinTextEnter ), NULL, this ); m_minText->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onMinTextEnter ), NULL, this );
m_saveBtn->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( TUNER_SLIDER_BASE::onSave ), NULL, this ); m_saveBtn->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( TUNER_SLIDER_BASE::onSave ), NULL, this );

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<wxFormBuilder_Project> <wxFormBuilder_Project>
<FileVersion major="1" minor="15" /> <FileVersion major="1" minor="16" />
<object class="Project" expanded="1"> <object class="Project" expanded="1">
<property name="class_decoration"></property> <property name="class_decoration"></property>
<property name="code_generation">C++</property> <property name="code_generation">C++</property>
@ -14,6 +14,7 @@
<property name="file">tuner_slider_base</property> <property name="file">tuner_slider_base</property>
<property name="first_id">1000</property> <property name="first_id">1000</property>
<property name="help_provider">none</property> <property name="help_provider">none</property>
<property name="image_path_wrapper_function_name"></property>
<property name="indent_with_spaces"></property> <property name="indent_with_spaces"></property>
<property name="internationalize">1</property> <property name="internationalize">1</property>
<property name="name">TUNER_SLIDER_BASE</property> <property name="name">TUNER_SLIDER_BASE</property>
@ -25,6 +26,7 @@
<property name="skip_php_events">1</property> <property name="skip_php_events">1</property>
<property name="skip_python_events">1</property> <property name="skip_python_events">1</property>
<property name="ui_table">UI</property> <property name="ui_table">UI</property>
<property name="use_array_enum">0</property>
<property name="use_enum">0</property> <property name="use_enum">0</property>
<property name="use_microsoft_bom">0</property> <property name="use_microsoft_bom">0</property>
<object class="Panel" expanded="1"> <object class="Panel" expanded="1">
@ -46,6 +48,7 @@
<property name="size">126,283</property> <property name="size">126,283</property>
<property name="subclass"></property> <property name="subclass"></property>
<property name="tooltip"></property> <property name="tooltip"></property>
<property name="two_step_creation">0</property>
<property name="window_extra_style"></property> <property name="window_extra_style"></property>
<property name="window_name"></property> <property name="window_name"></property>
<property name="window_style">wxTAB_TRAVERSAL</property> <property name="window_style">wxTAB_TRAVERSAL</property>
@ -137,6 +140,7 @@
<property name="aui_name"></property> <property name="aui_name"></property>
<property name="aui_position"></property> <property name="aui_position"></property>
<property name="aui_row"></property> <property name="aui_row"></property>
<property name="auth_needed">0</property>
<property name="best_size"></property> <property name="best_size"></property>
<property name="bg"></property> <property name="bg"></property>
<property name="bitmap"></property> <property name="bitmap"></property>
@ -359,6 +363,7 @@
<property name="window_extra_style"></property> <property name="window_extra_style"></property>
<property name="window_name"></property> <property name="window_name"></property>
<property name="window_style"></property> <property name="window_style"></property>
<event name="OnKillFocus">onMaxKillFocus</event>
<event name="OnTextEnter">onMaxTextEnter</event> <event name="OnTextEnter">onMaxTextEnter</event>
</object> </object>
</object> </object>
@ -424,6 +429,7 @@
<property name="window_extra_style"></property> <property name="window_extra_style"></property>
<property name="window_name"></property> <property name="window_name"></property>
<property name="window_style"></property> <property name="window_style"></property>
<event name="OnKillFocus">onValueKillFocus</event>
<event name="OnTextEnter">onValueTextEnter</event> <event name="OnTextEnter">onValueTextEnter</event>
</object> </object>
</object> </object>
@ -489,6 +495,7 @@
<property name="window_extra_style"></property> <property name="window_extra_style"></property>
<property name="window_name"></property> <property name="window_name"></property>
<property name="window_style"></property> <property name="window_style"></property>
<event name="OnKillFocus">onMinKillFocus</event>
<event name="OnTextEnter">onMinTextEnter</event> <event name="OnTextEnter">onMinTextEnter</event>
</object> </object>
</object> </object>
@ -509,6 +516,7 @@
<property name="aui_name"></property> <property name="aui_name"></property>
<property name="aui_position"></property> <property name="aui_position"></property>
<property name="aui_row"></property> <property name="aui_row"></property>
<property name="auth_needed">0</property>
<property name="best_size"></property> <property name="best_size"></property>
<property name="bg"></property> <property name="bg"></property>
<property name="bitmap"></property> <property name="bitmap"></property>

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Oct 26 2018) // C++ code generated with wxFormBuilder (version 3.10.0)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO *NOT* EDIT THIS FILE! // PLEASE DO *NOT* EDIT THIS FILE!
@ -16,10 +16,10 @@
#include <wx/font.h> #include <wx/font.h>
#include <wx/colour.h> #include <wx/colour.h>
#include <wx/settings.h> #include <wx/settings.h>
#include <wx/button.h>
#include <wx/bitmap.h> #include <wx/bitmap.h>
#include <wx/image.h> #include <wx/image.h>
#include <wx/icon.h> #include <wx/icon.h>
#include <wx/button.h>
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/slider.h> #include <wx/slider.h>
#include <wx/textctrl.h> #include <wx/textctrl.h>
@ -44,11 +44,14 @@ class TUNER_SLIDER_BASE : public wxPanel
wxTextCtrl* m_minText; wxTextCtrl* m_minText;
wxButton* m_saveBtn; wxButton* m_saveBtn;
// Virtual event handlers, overide them in your derived class // Virtual event handlers, override them in your derived class
virtual void onClose( wxCommandEvent& event ) { event.Skip(); } virtual void onClose( wxCommandEvent& event ) { event.Skip(); }
virtual void onSliderChanged( wxScrollEvent& event ) { event.Skip(); } virtual void onSliderChanged( wxScrollEvent& event ) { event.Skip(); }
virtual void onMaxKillFocus( wxFocusEvent& event ) { event.Skip(); }
virtual void onMaxTextEnter( wxCommandEvent& event ) { event.Skip(); } virtual void onMaxTextEnter( wxCommandEvent& event ) { event.Skip(); }
virtual void onValueKillFocus( wxFocusEvent& event ) { event.Skip(); }
virtual void onValueTextEnter( wxCommandEvent& event ) { event.Skip(); } virtual void onValueTextEnter( wxCommandEvent& event ) { event.Skip(); }
virtual void onMinKillFocus( wxFocusEvent& event ) { event.Skip(); }
virtual void onMinTextEnter( wxCommandEvent& event ) { event.Skip(); } virtual void onMinTextEnter( wxCommandEvent& event ) { event.Skip(); }
virtual void onSave( wxCommandEvent& event ) { event.Skip(); } virtual void onSave( wxCommandEvent& event ) { event.Skip(); }
@ -56,6 +59,7 @@ class TUNER_SLIDER_BASE : public wxPanel
public: public:
TUNER_SLIDER_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 126,283 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); TUNER_SLIDER_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 126,283 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
~TUNER_SLIDER_BASE(); ~TUNER_SLIDER_BASE();
}; };