Skip to content

features overview

hannes edited this page Feb 14, 2023 · 36 revisions

every menu item can have several attributes. The core attributes are label and command

Attributes

attribute description
command the action to run when clicking the item
label the label displayed in the menu for this item. (Don't confuse label with name)
name the name used in the code or by the app for this item. Often required to be unique so be carefull !
icon name of the icon, or path to the icon, an icon next to the menu entry TODO do we support QIcons?
separator if set to a non False value, this item will be treated as a separator. Some apps support labeled separators
items = children the child nodes of a menu or submenu.
parent_path Only set in config for the root node. Controls where & how your menu is parented too. Behaviour can differ between apps, depending on implementation!

App feature overview

  • ❌ Not easily supported ( with current UniMenu implementation )
  • ✅ Implemented
  • 🛠️ To implement
  • Not investigated yet
App Icon Separator Labeled separator callback command ¹ tooltip teardown native UI
Maya 🛠️ 🛠️ PySide2 & native menu
Max ² 🛠️ 🛠️ PySide2 & native menu
Substance Painter PySide2
Krita 🛠️ PyQt5
Qt any Qt
Marmoset UIWindow
Blender GHOST Menu Operator
Unreal 🛠️ 🛠️ 🛠️ Slate ToolMenuEntry

¹ some apps only support string commands, some support passing functions & callbacks.

² ⚠️ Max maintains it's created menu on restart, inconsistent with other apps. ¹²³⁴⁵⁶⁷⁸⁹⁰

other features TODO

  • checkbox, e.g. Krita
  • shortcuts - Krita
  • option button, e.g. maya

Config

This sample shows of all attributes in use. Checkout the samples in the UniMenu repo for more configs.

parent_path: MainWindow
label: UniMenu
items:
  - label: Item 1
    command: print('Item 1')
    icon: QUESTION.png
    tooltip: you can read this when you hover over me
  - separator: 1
    label: labeled separator

MenuNode

The attributes can also be accessed on the MenuNode, if we load the above config in unimenu.

node = unimenu.load(config)
node.parent_path # "MainWindow"
node.label       # "UniMenu"

nodes = node.children
node1 = nodes[0]
node2 = nodes[1]

node1.label      # "Item 1"
node1.tooltip    # "you can read this when you hover over me"
node1.command    # "print('Item 1')"
node1.icon       # "QUESTION.png"


node2.separator  # 1, could also be set to True, or "--"
node2.label      # "labeled separator"

# =========== Helper functions ===========
# run the command
node1.run()
# find out if a node is a separator
node2.is_separator()
# get a node's parent. When you ask the parent of a non-root-menuNode, 
# it'll return the parent MenuNode. 
# This attribute isn't explicitly saved back to the config.
node2.parent
Clone this wiki locally