Houdini 20.0 Python scripting hou hou.qt

hou.qt.XMLMenuParser class

Object for dealing with XML menus.

On this page

This object will build QMenus based on an XML menu definition and will also simplify keyboard shortcut handling for activating items in the menu that have shortcuts assigned to them.

Script items like expressions and script code are passed kwargs that will contain (if defined) the id and label of the corresponding menu item.



This example shows how you would use this object to preparse the XML file. Then on-demand generate a /hom/hou/qt/hou.qt.Menu.html which can be invoked within an event handler.

    self._mymenuparser = XmlMenuParser(context = "h.pane.parms", xmlfile = "c:/temp/menu.xml")
    def contextMenuEvent(self, event):
        # custom kwargs passed to any expression or code in menu.xml when evaluating
        menukwargs["parm"] = menucontextparm
        menukwargs["parmname"] = menucontextparm.name()
        menu = self._mymenuparser.generateMenu(kwargs = menukwargs, hotkeyaction = self._processHotKeyAction)
        if not menu.isEmpty():

XML file:

<?xml version="1.0" encoding="UTF-8"?>
    <actionItem id="set_keyframe">
        <label>Set a Keyframe</label>
    <actionItem id="rem_keyframe">
        <labelExpression>return kwargs["label"] + " - " + kwargs["parmname"]</labelExpression>
    <actionItem id="revert_defs">

        <label>Parm Locked</label>
return kwargs['parm'] is not None
return kwargs['parm'].isLocked()
kwargs['parm'].lock(not kwargs['parm'].isLocked())

    <actionItem id="lock_parm">
if kwargs['parm'] is not None and kwargs['parm'].isLocked():
return False
return True
    <actionItem id="unlock_parm">
if kwargs['parm'] is not None and kwargs['parm'].isLocked():
return True
return False
        <actionItem id="toggle_expr"/>
        <actionItem id="edit_expression"/>
        <actionItem id="expand_values"/>
        <actionItem id="use_python"/>
        <actionItem id="use_old_language"/>