RibbonPageGroup (hwx.gui)#

class RibbonPageGroup(parent=None, text='', children=None, menus=None, name='')#

Bases: object

Logical grouping of SpriteActionGroups in a RibbonPage.

Attribute Table#

Name

Type

visible

property

Method Table#

Name

Description

add (self, action, after=None, index=None)

Adds the SpriteAction/SpriteActionGroup.

get (name)

Gets the RibbonPageGroup with the specified name.

hide (self)

Hides the RibbonPageGroup.

isShown (self)

Returns True if it shown, False otherwise.

remove (self, action)

Removes the sprite action group from RibbonPageGroup.

show (self)

Shows the RibbonPageGroup.

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
    )
  ])
])
add(action, after=None, index=None)#

Adds the SpriteAction/SpriteActionGroup.

Parameters:
remove(action)#

Removes the sprite action group from RibbonPageGroup.

Parameters:

action (SpriteActionGroup) – The action to be removed.

property visible#

The visibility of the RibbonPageGroup.

show()#

Shows the RibbonPageGroup.

hide()#

Hides the RibbonPageGroup.

isShown()#

Returns True if it shown, False otherwise.