You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you have an Action with the toggle style and an associated image, then you should theoretically be able to share that action between a menu item and a toolbar item. In fact it used to work, until wxWidgets disallowed it, and indeed it still works with the Qt4 backend.
Here's a sample program that reproduces the failure:
fromtraits.apiimportHasTraitsfromtraitsui.apiimportAction, Menu, MenuBar, ToolBar, ViewclassWindow(HasTraits):
action=Action(name='Action', style='toggle',
image='/usr/share/icons/hicolor/16x16/actions/package-new.png') # replace with some icon on your systemview=View(menubar=MenuBar(Menu(action, name='File')),
toolbar=ToolBar(action),
resizable=True)
w=Window()
w.configure_traits()
And here's the stack trace it produces:
File "actions.py", line 12, in <module>
w.configure_traits()
File "/usr/lib/python2.7/dist-packages/traits/has_traits.py", line 2386, in configure_traits
kind, handler, id, scrollable, args )
File "/usr/lib/python2.7/dist-packages/traitsui/wx/toolkit.py", line 219, in view_application
id, scrollable, args )
File "/usr/lib/python2.7/dist-packages/traitsui/wx/view_application.py", line 93, in view_application
scrollable, args ).ui.result
File "/usr/lib/python2.7/dist-packages/traitsui/wx/view_application.py", line 141, in __init__
super( ViewApplication, self ).__init__(0)
File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/_core.py", line 8628, in __init__
self._BootstrapApp()
File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/_core.py", line 8196, in _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/traitsui/wx/view_application.py", line 158, in OnInit
args = self.args )
File "/usr/lib/python2.7/dist-packages/traitsui/view.py", line 433, in ui
ui.ui( parent, kind )
File "/usr/lib/python2.7/dist-packages/traitsui/ui.py", line 221, in ui
self.rebuild( self, parent )
File "/usr/lib/python2.7/dist-packages/traitsui/wx/toolkit.py", line 140, in ui_live
ui_live.ui_live( ui, parent )
File "/usr/lib/python2.7/dist-packages/traitsui/wx/ui_live.py", line 68, in ui_live
ui_dialog( ui, parent, NONMODAL )
File "/usr/lib/python2.7/dist-packages/traitsui/wx/ui_live.py", line 99, in ui_dialog
ui.owner.init( ui, parent, style )
File "/usr/lib/python2.7/dist-packages/traitsui/wx/ui_live.py", line 299, in init
self.add_menubar()
File "/usr/lib/python2.7/dist-packages/traitsui/wx/ui_base.py", line 199, in add_menubar
menubar.create_menu_bar( self.control, self ) )
File "/usr/lib/python2.7/dist-packages/pyface/ui/wx/action/menu_bar_manager.py", line 49, in create_menu_bar
menu = item.create_menu(parent, controller)
File "/usr/lib/python2.7/dist-packages/pyface/ui/wx/action/menu_manager.py", line 58, in create_menu
return _Menu(self, parent, controller)
File "/usr/lib/python2.7/dist-packages/pyface/ui/wx/action/menu_manager.py", line 110, in __init__
self.refresh()
File "/usr/lib/python2.7/dist-packages/pyface/ui/wx/action/menu_manager.py", line 153, in refresh
parent, group, previous_non_empty_group
File "/usr/lib/python2.7/dist-packages/pyface/ui/wx/action/menu_manager.py", line 208, in _add_group
item.add_to_menu(parent, self, self._controller)
File "/usr/lib/python2.7/dist-packages/pyface/action/action_item.py", line 103, in add_to_menu
wrapper = _MenuItem(parent, menu, self, controller)
File "/usr/lib/python2.7/dist-packages/pyface/ui/wx/action/action_item.py", line 93, in __init__
self.control.SetBitmap(action.image.create_bitmap())
File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/_core.py", line 12543, in SetBitmap
return _core_.MenuItem_SetBitmap(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "Assert failure" failed at ../src/gtk/menu.cpp(724) in SetBitmap(): only normal menu items can have bitmaps
I've opened a wxWidgets bug, since I think an assertion is quite rude to application developers in this case, but they have said this is by design and are not going to change it. Therefore, probably TraitsUI should avoid setting the bitmap on the menu item so that the above sample code can continue to work with the wxWidgets backend.
The text was updated successfully, but these errors were encountered:
If you have an Action with the
toggle
style and an associated image, then you should theoretically be able to share that action between a menu item and a toolbar item. In fact it used to work, until wxWidgets disallowed it, and indeed it still works with the Qt4 backend.Here's a sample program that reproduces the failure:
And here's the stack trace it produces:
I've opened a wxWidgets bug, since I think an assertion is quite rude to application developers in this case, but they have said this is by design and are not going to change it. Therefore, probably TraitsUI should avoid setting the bitmap on the menu item so that the above sample code can continue to work with the wxWidgets backend.
The text was updated successfully, but these errors were encountered: