Houdini 18.5 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.

Methods

Examples

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 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():
            menu.popup(event.globalPos())

XML file:

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

    <toggleItem>
        <label>Parm Locked</label>
        <enableExpression><![CDATA[
return kwargs['parm'] is not None
]]></enableExpression>
        <valueExpression><![CDATA[
return kwargs['parm'].isLocked()
]]></valueExpression>
        <scriptCode><![CDATA[
kwargs['parm'].lock(not kwargs['parm'].isLocked())
]]></scriptCode>
    </toggleItem>

    <actionItem id="lock_parm">
        <context><expression><![CDATA[
if kwargs['parm'] is not None and kwargs['parm'].isLocked():
return False
return True
]]></expression></context>
    </actionItem>
    <actionItem id="unlock_parm">
        <context><expression><![CDATA[
if kwargs['parm'] is not None and kwargs['parm'].isLocked():
return True
return False
]]></expression></context>
    </actionItem>
    <separatorItem/>
    <subMenu>
        <label>Expressions</label>
        <actionItem id="toggle_expr"/>
        <actionItem id="edit_expression"/>
        <actionItem id="expand_values"/>
        <actionItem id="use_python"/>
        <actionItem id="use_old_language"/>
    </subMenu>
</menu>
</menuDocument>

hou.qt