SecondaryRibbon (hwx.gui)#
- class SecondaryRibbon(*childrenArgs, children=None, persistSelected=True, allowAllOff=False, **kwds)#
Bases:
Widget
A sub Ribbon containing a list of SpriteActionGroups that appears under a SpriteActionGroup in the Ribbon.
# Name
Type
property
property
property
# Name
Description
add
(self, action, index=None)Adds the SpriteAction/SpriteActionGroup to Secondary Ribbon.
remove
(self, action)Removes the SpriteAction/SpriteActionGroup from Secondary Ribbon.
Example
from hwx.inspire import gui from hwx.gui.Ribbon import SecondaryRibbon map = {} # Mapping of Sprite Action Group with Secondary Ribbon # To create the Secondary Ribbon. def getRibbon(): secondaryRibbon = SecondaryRibbon(allowAllOff=False, children=[ gui.SpriteActionGroup(text='Add', children=[ gui.SpriteAction( icon='ribbonAddStrip-80.png', tooltip='Add Operation', dialog=ToolsDialog, visible=True, )] ) ]) return secondaryRibbon # Dialog for Secondary Ribbon. class ToolsDialog(gui.ActionDialog): def __init__(self): super().__init__(children=[ gui.GridFrame([ [couplers(), spring()] ], margin=1) ]) self.SetCaption('Tools') self.SetGeomMgrPriority(9900) # Context Menu option for Sprite Action Group for secondary ribbon. def buildContextMenu2(menu, action): if action: def removeSAG(): for key, val in map.items(): if key.GetUiAction().IsAnyOn(): val.remove(action.parent) break ui = action.parent.GetUiAction() if not ui.IsAnyOn(): menu.insertItem('Delete', icon='glyphDeleteStrip-16.png', command=removeSAG) # Secondary Ribbon tool. def couplers(): def command(): sag = gui.SpriteActionGroup( text='Couplers', children=[ gui.SpriteAction( icon='ribbonCouplersStrip-80.png', tooltip='Couplers', command=lambda: print("Couplers clicked"), ) ], onContextMenu=buildContextMenu2 ) for key, val in map.items(): if key.GetUiAction().IsAnyOn(): val.add(sag, index=-1) break return gui.SpriteCommand( text='Couplers', icon='ribbonCouplersStrip-80.png', command=command ) # Secondary Ribbon tool. def spring(): def command(): sag = gui.SpriteActionGroup( text='Spring', children=[ gui.SpriteAction( icon='ribbonSpringTorsionStrip-80.png', tooltip='Spring', command=lambda: print("Spring clicked") ) ], onContextMenu=buildContextMenu2 ) for key, val in map.items(): if key.GetUiAction().IsAnyOn(): val.add(sag, index=-1) break return gui.SpriteCommand( text='Spring', icon='ribbonSpringTorsionStrip-80.png', command=command ) # Context Menu option for Sprite Action Group. def buildContextMenu(menu, action): if action: def removeSAG(): operationGroup.remove(action.parent) global map del map[action.parent] ui = action.parent.GetUiAction() if not ui.IsAnyOn(): menu.insertItem('Delete', icon='glyphDeleteStrip-16.png', command=removeSAG) # Main Ribbon tool. def actuator(): def command(): secondaryRibbon = getRibbon() sag = gui.SpriteActionGroup( text='Actuator', children=[ gui.SpriteAction( icon='ribbonActuatorStrip-80.png', tooltip='Configure Toolset', ribbon=secondaryRibbon ) ], onContextMenu=buildContextMenu ) operationGroup.add(sag, index=-1) global map map[sag] = secondaryRibbon return gui.SpriteCommand( text='Actuator', icon='ribbonActuatorStrip-80.png', command=command ) # Main Ribbon tool. def motor(): def command(): secondaryRibbon = getRibbon() sag = gui.SpriteActionGroup( text='Motor', children=[ gui.SpriteAction( icon='ribbonMotorStrip-80.png', tooltip='Configure Toolset', ribbon=secondaryRibbon ) ], onContextMenu=buildContextMenu ) operationGroup.add(sag, index=-1) global map map[sag] = secondaryRibbon return gui.SpriteCommand( text='Motor', icon='ribbonMotorStrip-80.png', command=command ) # Dialog for Main Ribbon. class OperationsDialog(gui.ActionDialog): def __init__(self): super().__init__(children=[ gui.GridFrame([ [actuator(), motor()] ], margin=1) ]) self.SetCaption('Operations') for i in range(100): try: tryoutPage = gui.RibbonPage(f"Tryout {i}") print( f"Tryout {i} Ribbon page has been created. Please open the same to explore " "different functionality of SpriteAction.") break except: pass operationGroup = gui.RibbonPageGroup(tryoutPage, "Operation", children=[ gui.SpriteActionGroup(text='Add', children=[ gui.SpriteAction( icon='ribbonAddStrip-80.png', tooltip='Add Operation', dialog=OperationsDialog, visible=True ) ]) ])
- property action#
The SpriteAction the ribbon is shown under.
- property allowAllOff: bool#
(bool) Use False to auto hide when all actions are toggled off.
- property persistSelected: bool#
(bool) Use True to toggle on the last active action when shown.
- add(action, index=None)#
Adds the SpriteAction/SpriteActionGroup to Secondary Ribbon.
- Parameters:
action (str | SpriteActionGroup) – The action to be added.
index (int) – Index at which to insert the action.
- remove(action)#
Removes the SpriteAction/SpriteActionGroup from Secondary Ribbon.
- Parameters:
action (SpriteActionGroup) – The action to be removed.