Last active
February 5, 2021 04:54
-
-
Save mo-han/af1d5b5eafd4f069e74814368d5cbb0a to your computer and use it in GitHub Desktop.
traitsui large icon button test
Author
mo-han
commented
Feb 5, 2021
Success with SVGButton
in enable
from mylib.traitsui_helper.import_10_qt import * # mylib: https://github.com/mo-han/mo-han-toolbox/tree/master/mylib
svg = r'scpi_shell\icon.svg'
ir = ImageResource(svg)
TestAction = Action(
name="&Test", action="test_clicked", tooltip="Click to test", image=ir, 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=ir)
bt2 = SVGButton(filename=svg, height=128, width=128)
bt3 = ToolbarButton(image=ir)
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=-128, width=-128), # `oa` is a wrapper of `varname.nameof`, oa(x.y.z) == str('x.y.z')
Item(oa(bt2)),
Item(oa(bt3), style='custom', height=-128, width=-128),
menubar=menus,
toolbar=toolbar,
buttons=[TestAction, "OK", ],
)
def _bt2_fired(self):
self.action_successful = not self.action_successful
if __name__ == "__main__":
# Execute from command line for manual testing
vw = DialogWithToolbar()
vw.configure_traits()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment