I’m constructing a preferences dialog, in which there’s an Apply button, initially disabled. Whenever a setting changes, I want to enable the Apply button. Whenever the Apply button is pressed, it should be disabled again (until another setting changes).
Sample code attached: a simple app with 3 radio buttons and an Apply button only.
I get strange behavior though, with wxPython 2.9.4.0 under Python 2.7.3 on Windows XP SP3. Run the attached sample code:
> python interaction_test.py
2.9.4.0 msw (classic)
interaction_test.py:35: wxPyDeprecationWarning: Using deprecated class PySimpleApp.
app = wx.PySimpleApp()
(Where’s the Python-specific documentation for 2.9? http://www.wxpython.org/docs/api/ is for 2.8)
Choose radio B:
in on_radio for B
entering enable_apply_button(True)
selection at start: B
selection at end: B
leaving enable_apply_button(True)
Apply is enabled. So far so good. Now press Apply:
entering on_apply_button
entering enable_apply_button(False)
selection at start: B
in on_radio for A
What the…!? Radio A is being activated automatically here, undesired behavior. Why?
entering enable_apply_button(True)
selection at start: A
selection at end: A
leaving enable_apply_button(True)
selection at end: A
leaving enable_apply_button(False)
leaving on_apply_button
Choose radio B:
in on_radio for C
entering enable_apply_button(True)
selection at start: C
selection at end: C
leaving enable_apply_button(True)
The Apply button is not enabled. It seems to be permanently disabled. Huh?
This caused me many hours of frustration, thinking I had done a Bind call wrong or my widget hierarchy was wonky. But in wxPython 2.8, there is no problem. After editing the attached sample app to switch versions:
> python interaction_test.py
2.8.12.1 (msw-unicode)
Choose radio B:
in on_radio for B
entering enable_apply_button(True)
selection at start: B
selection at end: B
leaving enable_apply_button(True)
Apply is enabled. Now press Apply:
entering on_apply_button
entering enable_apply_button(False)
selection at start: B
selection at end: B
leaving enable_apply_button(False)
leaving on_apply_button
Works fine. Apply is disabled, the radio B selection doesn’t change. Choose radio C:
in on_radio for C
entering enable_apply_button(True)
selection at start: C
selection at end: C
leaving enable_apply_button(True)
Apply is enabled again. All is well.
I would like to stick to wxPython 2.9, since I’m using ToolBar.InsertStretchableSpace(0) and ToolBar.AddStretchableSpace(), not available in 2.8.
Any workaround to the bug above?
If this is novel, I’ll happily add it to the bug tracker.
Thanks!
interaction_test.py (1.52 KB)
···
–
David Goodger <http://python.net/~goodger>