I have an app which basically looks like this:
The event handlers for the tools (and menu items) have all the same structure. In the EVT_UPDATE_UI I check if the current control (which has the focus) can perform the required action:
def update_copy(self, event): widget = self.FindFocus() if widget and hasattr(widget, "CanCopy"): event.Enable(widget.CanCopy()) else: event.Enable(False)
In the main event handler I simply call the required method, like this:
def on_copy(self, event): self.FindFocus().Copy()
This works well on Windows:
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)]
‘4.1.0 msw (phoenix) wxWidgets 3.1.4’
But it failed on Mac with the following exception:
Traceback (most recent call last): File "/Volumes/ ... /auiToolbarTest/auiToolbarTest.py", line 8, in on_copy self.FindFocus().Copy() AttributeError: 'AuiToolBar' object has no attribute 'Copy'
Mac OS 10.14.6 Mojave
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31)
4.1.0 osx-cocoa (phoenix) wxWidgets 3.1.4
I suspect on Mac the AUI toolbar receives the focus before the event handler of the tool is called, which does not happen on Windows.
Calling the event handler via menu item selection or the respective shortcut works on Mac as well.
Do you have any tips on how I can get this to work on Mac as well as on Windows?
Or is this simply a bug.
Sample application is attached
auiToolbarTest.zip (3.9 KB)
All the best