Houdini 20.5 Examples Python panel examples

Qt designer

How to load user interface layout from a Qt Designer file.

Example
<?xml version="1.0" encoding="UTF-8"?>
<pythonPanelDocument>
  <!-- This file contains definitions of Python interfaces and the
 interfaces menu.  It should not be hand-edited when it is being
 used by the application.  Note, that two definitions of the
 same interface or of the interfaces menu are not allowed
 in a single file. -->
  <interface name="QtDesigner" label="Qt Designer Example" icon="MISC_python">
    <script><![CDATA[import os
import sys

from hutil.Qt import QtCore, QtUiTools, QtWidgets

panel_path = "%s/houdini/help/examples/python_panels/" % os.environ["HFS"]
sys.path.append(panel_path)

from examplehelp import ExampleHelpWidget

theMainWidget = None
theHelpWidget =None
theDisplayLabel = None

def displayDialog():
    """Displays a dialog containing the information entered in the form field."""
    global theMainWidget
    global theDisplayLabel

    text = """
        Information received!

        Name: %s
        Address: %s
        City: %s
        Country: %s
    """  % (
        theMainWidget.findChild(QtWidgets.QLineEdit, "name_field").text(),
        theMainWidget.findChild(QtWidgets.QLineEdit, "address_field").text(),
        theMainWidget.findChild(QtWidgets.QLineEdit, "city_field").text(),
        theMainWidget.findChild(QtWidgets.QLineEdit, "country_field").text(),
    )

    # Create a new dialog to show the information.
    if theDisplayLabel is None:
        theDisplayLabel = QtWidgets.QLabel()
        theDisplayLabel.resize(200, 100)
    theDisplayLabel.setText(text)
    theDisplayLabel.show()
    theDisplayLabel.activateWindow()


def onCreateInterface():
    global theMainWidget

    # Load the interface layout from the .ui file.
    ui_file_path = "%s/houdini/help/examples/python_panels/qtdesignerform.ui" % os.environ["HFS"]
    loader = QtUiTools.QUiLoader()
    ui_file = QtCore.QFile(ui_file_path)
    ui_file.open(QtCore.QFile.ReadOnly)
    theMainWidget = loader.load(ui_file)

    full_string = """The layout for this example was created using Qt Designer: 
                      http://qt-project.org/doc/qt-4.8/designer-manual.html<br><br>
                      The source .ui file is located at $HFS/houdini/help/examples/
                      python_panels/qtdesignerform.ui.<br><br>

                      Qt Designer is part of the Qt 4.8 package.
                      You can install Qt using your system's package management software, or you can 
                      download the Qt source package from here: https://download.qt.io/archive/qt/4.8/4.8.5/<br>
                      <br>
                      And then build Qt by following these instructions:<br>
                       * <b>Linux</b> - http://qt-project.org/doc/qt-4.8/install-x11.html<br>
                       * <b>Mac OSX</b> - http://qt-project.org/doc/qt-4.8/install-x11.html<br>
                       * <b>Windows</b> - http://qt-project.org/doc/qt-4.8/install-win.html"""

    small_string = """The layout for this example was created using Qt Designer:
                      http://qt-project.org/doc/qt-4.8/designer-manual.html<br><br>
                      The source .ui file is located at $HFS/houdini/help/examples/
                      python_panels/qtdesignerform.ui."""

    # Add the help section
    theHelpWidget = ExampleHelpWidget(small_string, full_string, True)
    theHelpWidget.setContentsMargins(0,0,0,6)

    layout = theMainWidget.layout()
    layout.insertWidget(0, theHelpWidget, 1, QtCore.Qt.AlignTop)

    # Connect push buttons to event handlers.
    submit_btn = theMainWidget.findChild(QtWidgets.QPushButton, "submit_button")
    submit_btn.clicked.connect(displayDialog)


    return theMainWidget

]]></script>
  </interface>
</pythonPanelDocument>

Python panel examples

  • Custom Graphics

    Custom OpenGL drawing in a Python Panel.

  • Drag and Drop

    How to implement drag and drop functionality in a Python Panel.

  • Linked parameters

    How to link PySide parameter widgets (i.e. text fields and sliders) to Houdini node parameters and vice versa.

  • Node path

    How to listen for changes to the current node path.

  • Qt designer

    How to load user interface layout from a Qt Designer file.

  • Qt events

    How Python Panels can listen to Qt events.

  • Viewport color editor

    A PySide interface for editing viewport colors.