SpriteAction (hwx.gui)#
- class SpriteAction(parent=None, name='', **kwds)#
Bases:
Action
A SpriteAction is a palette of PushButtons with icons.
SpriteActions MUST be children of the SpriteActionGroup. The SpriteActionGroup can then be placed into the Unity RibbonPage.
Example
from hwx import gui from hwx.gui.demo import getDemoFilePath # Add icons to resource path resourceFolder = getDemoFilePath('resources') gui.addResourcePath(resourceFolder) # Define a dialog to be toggled by a SpriteAction class Dialog(gui.ActionDialog): def createContents(self): self.addChildren("A dialog toggled by a SpriteAction in the Ribbon'") def buildContextMenu(menu, action): for child in action.parent.children: menu.insertItem(f"Simulate click on {child.tooltip}", command=child.toggle) # A pallet with a couple of SpriteActions group = gui.SpriteActionGroup(text="Fasteners", onContextMenu=buildContextMenu) gui.SpriteAction(group, tooltip="Say Hello", icon=("ribbonFastenersStrip-80.png", (0, 5)), command=lambda: gui.tellUser("Hello World")) gui.SpriteAction(group, tooltip="List Bolts/Pins", icon=("ribbonSatelliteListStrip-80.png", (3, 5)), dialog=Dialog, ) # If the group has only one action, you can use a shortcut command = gui.SpriteCommand(text="Open", icon="ribbonFilesOpenBottomStrip-80.png", command=lambda: gui.tellUser("Open Dialog Goes Here"), # enabled = False, # visible = False, ) # We can also change label to be displayed at the bottom of the group group.text = "Fastener1" frame = gui.HFrame(group, 10, command) show(frame)