|
from mylib.traitsui_helper.import_10_qt import * # mylib: https://github.com/mo-han/mo-han-toolbox/tree/master/mylib |
|
|
|
i = ImageResource(r'scpi_shell\icon.png') |
|
|
|
TestAction = Action( |
|
name="&Test", action="test_clicked", tooltip="Click to test", image=i, height=-1280 |
|
) |
|
|
|
|
|
class DialogWithToolbar(HasTraits): |
|
"""Test dialog with toolbar and menu.""" |
|
|
|
action_successful = Bool(False) |
|
|
|
def test_clicked(self): |
|
self.action_successful = True |
|
|
|
menus = MenuBar( |
|
Menu( |
|
ActionGroup(TestAction), |
|
name="Test" |
|
) |
|
) |
|
|
|
bt1 = Button(image=i) |
|
bt2 = Button(button_editor=ButtonEditor(image=i)) |
|
bt3 = ToolbarButton(image=i) |
|
|
|
toolbar = ToolBar(ActionGroup(TestAction)) |
|
|
|
traits_view = View( |
|
Item( |
|
label="Click the button on the toolbar or the menu item.\n" |
|
"The 'Action successful' element should turn to True." |
|
), |
|
Item("action_successful", style="readonly", label='clicked'), |
|
Item(oa(bt1), style='custom', height=-200, width=-200), # `oa` is a wrapper of `varname.nameof`, oa(x.y.z) == str('x.y.z') |
|
Item(oa(bt2), style='custom', height=-200, width=-200), |
|
Item(oa(bt3), style='custom', height=-200, width=-200), |
|
menubar=menus, |
|
toolbar=toolbar, |
|
buttons=[TestAction, "OK", ], |
|
) |
|
|
|
def _bt_fired(self): |
|
self.action_successful = not self.action_successful |
|
|
|
|
|
if __name__ == "__main__": |
|
# Execute from command line for manual testing |
|
vw = DialogWithToolbar() |
|
vw.configure_traits() |
Success with
SVGButton
inenable