Inheritance |
|
This class provides the essential methods for supporting compositing shelf tools, COP states and handles. It doesn’t currently offer programmatic control over most UI-available functions. For that purpose, the functions within the cop2toolutils
module are more suitable.
Methods ¶
currentState()
→ str
Returns the name of the tool currently in use in the view. This is an internal, undocumented designation but usually corresponds to the name of a node. You can change to a different tool using setCurrentState.
enterViewState(wait_for_exit=False)
Switch to the view tool.
setCurrentState(state, wait_for_exit=False)
Sets the currently active tool in the view. state
is a string containing an internal, undocumented designation. See currentState().
runStateCommand(name, args=None)
Executes a command implemented by the active python state. A state command can be invoked by specifying a name identifier along with arguments.
An exception is thrown if the state is not a Python state type or the state is not running.
name
The command name identifier.
args
The command arguments. args
can be any Python type, including built-in types, containers, sets, or dictionaries. A dictionary is commonly used to pass arguments to a
command, as it simplifies the command’s implementation and allows output values to be returned by the command. args
defaults to None is omitted.
An implementation example of a COP state command.
import hou import viewerstate.utils as su class State(object): def __init__(self, state_name, viewer): self.state_name = state_name self.scene_viewer = viewer def onCommand( self, kwargs ): name = kwargs['command'] args = kwargs['command_args'] if name == "myCOPCommand"': self.log(f"{name}({args})") def createViewerStateTemplate(): """ Mandatory entry point to create and return the viewer state template to register. """ state_typename = "mycopstate" state_label = "My COP State" state_cat = hou.copNodeTypeCategory() template = hou.ViewerStateTemplate(state_typename, state_label, state_cat) template.bindFactory(State) template.bindIcon("MISC_python") return template
Here’s how to invoke the command.
import viewerstate.utils as ut v = ut.findCompositorViewer() v.runStateCommand("myCOPCommand", {"arg0":0, "arg1":[1,2,3]})
curViewport()
→ hou.Viewport2D
Returns this viewer’s current viewport. The current viewport is the one containing the mouse cursor.
showHandle(name, value)
Shows or hides a display handle linked to the current tool state. This API is typically used with Python states and can be
called from any python state callbacks. Avoid calling showHandle
from the python state constructor, because this leads to a runtime error.
See also hou.Handle.show.
name
The name of the handle as specified with hou.ViewerStateTemplate.bindHandle or the name or a built-in Houdini handle.
value
Bool
value, True
to show the handle, False
to hide it.
bindViewerHandle(handle_type, name, settings=None, cache_previous_parms=False, handle_parms=None)
Binds a dynamic viewer handle to the current viewer state similarly to hou.ViewerStateTemplate.bindHandle. Unlike bindHandle
though, this method creates and
initializes the handle in a dynamic fashion so there is no need to register in advance the handle with the viewer state. You can call bindViewerHandle
from almost anywhere in Houdini (from the viewer state handlers, from a python script, etc…), but it can only be called while the viewer state is running.
To remove the viewer handles added with bindViewerHandle
, use hou.SceneViewer.unbindViewerHandle. Houdini will take care of removing automatically all viewer
handles added with bindViewerHandle
when the state exits.
This method works only with python states, an exception is raised if the state is not a python state.
handle_type
A string naming the type of handle. See State handle types for a list of handle types to choose from.
name
A string to use to identify the handle. Each binding’s name must be unique within this state. Trying to bind the same name more than once will raise an exception.
settings
A string containing specific settings of the handle. Multiple settings must be space separated.
cache_previous_parms
If True, the handle retains a record of previous values. This can be useful if you want your code to calculate deltas as the user moves the handle, for example to know how fast the user is dragging the handle.
handle_parms
An array of handle parm names to specify the parms to enable, only the parms contained in the array will be available to the python state callbacks.
All handle parms are enabled when handle_parms
is empty (default).
bindViewerHandleStatic(handle_type, name, bindings, settings=None)
Binds a static viewer handle to the current viewer state similarly to hou.ViewerStateTemplate.bindHandleStatic. Unlike bindHandleStatic
though, this method creates and
initializes the handle in a dynamic fashion so there is no need to register in advance the handle with the viewer state. You can call bindViewerHandleStatic
from almost anywhere in Houdini (from the viewer state handlers, from a python script, etc…), but it can only be called while the viewer state is running.
To remove the viewer handles added with bindViewerHandleStatic
, use hou.SceneViewer.unbindViewerHandle. Houdini will take care of removing automatically all viewer
handles added with bindViewerHandleStatic
when the state exits.
This method works only with python states, an exception is raised if the state is not a python state.
handle_type
A string naming the type of handle.
name
A unique string to use to identify the handle. Each binding’s name must be unique within this state. Trying to bind the same name more than once will raise an exception.
bindings
A list of ("node_parm_name", "handle_parm_name")
tuples. This binds the parts of the handle to individual parameters on the node.
settings
A string containing specific settings of a handle. Multiple settings must be space separated.
unbindViewerHandle(name)
Removes a viewer handle from the current python state. unbindViewerHandle
can only unbind the viewer handles that were dynamically added with hou.SceneViewer.bindViewerHandle or
hou.SceneViewer.bindViewerHandleStatic. An exception is raised if the viewer handle to unbind is a state registered viewer handle.
This method works only with python states, an exception is raised if the state is not a python state.
name
The viewer handle name to unbind. This is the name used when binding the handle with bindViewerHandle
or bindViewerHandleStatic
.
hudInfo(show=-1, state=None, template=None, values=None, panel=hou.hudPanel.ToolInfo, terminate=False, update_hotkey_bindings=False)
Not implemented.
clearPromptMessage()
Not implemented.
setPromptMessage(msg, msg_type = None)
Not implemented.
selectDrawableGeometry(drawable_selection, selection_modifier=None)
Not implemented.
beginStateUndo(label)
Not implemented.
endStateUndo()
Not implemented.
Color Correction ¶
These functions set or query the OpenColorIO settings for the viewer (see OpenColorIO Support).
usingOCIO()
→ bool
Query if OpenColorIO is being used for color correction in the viewer.
setUsingOCIO(enable)
Enable or disable OpenColorIO for color correction in the viewer.
setOCIODisplayView(display="", view="")
Set the OpenColorIO display name, view name, or both. The display and view together define the output colorspace for the viewer, and any number of color transforms (Looks) to be performed on the linear viewport image.
getOCIODisplay()
→ str
Return the current OpenColorIO display used for color correction.
getOCIOView()
→ str
Return the current OpenColorIO view used for color correction.
Methods from hou.PaneTab ¶
name()
→ str
Return the name of this tab.
setName(name)
Set the name of this pane tab. A pane tab name may contain spaces.
Note that this name is the internal name of the tab, and is different from the label displayed in the interface.
type()
→ hou.paneTabType enum value
Return the type of this tab (i.e. whether it is a scene viewer, parameter editor, network editor, etc.).
setType(type)
→ hou.PaneTab
Create a new pane tab of the given type, replace this tab with it, and return the new pane tab. Use the returned pane tab afterward; references to this tab become invalid.
close()
Close the pane tab.
pane()
→ hou.Pane or None
Return the pane in the desktop that contains this pane tab. Note that pane tabs in regular floating panels are always in a pane, since regular floating panels contain one or more panes.
However, some floating panels have their content stripped down to only contain one particular pane tab type, and do not display the user interface to add more pane tabs, split the pane, etc. This method returns None for these stripped down floating panels.
floatingPanel()
→ hou.FloatingPanel or None
Return the floating panel that contains this pane tab or None if the pane tab is not in a floating panel.
isCurrentTab()
→ bool
Return whether this tab is the selected tab in the containing pane.
setIsCurrentTab()
Set this tab as the selected tab in the containing pane.
isFloating()
→ bool
Return whether this pane tab is in a floating panel.
This method can be approximately implemented as follows:
def isFloating(self): return self.pane() is None or self.pane().floatingPanel() is not None
clone()
→ hou.PaneTab
Create a floating copy of the pane tab and return the cloned pane tab. The new pane tab is in a new floating panel.
linkGroup()
→ hou.paneLinkType enum value
Return the link group that this pane tab belongs to.
See also hou.PaneTab.isPin.
setLinkGroup(group)
Set the link group membership of this pane tab.
isPin()
→ bool
Return whether this pane tab is pinned. This method is equivalent to
(self.linkGroup() == hou.paneLinkType.Pinned)
See also hou.PaneTab.linkGroup.
setPin(pin)
If pin is True
, set the link group membership to hou.paneLinkType.Pinned.
Otherwise, set it to hou.paneLinkType.FollowSelection. This method can be
implemented using hou.PaneTab.setLinkGroup as follows:
def setPin(self, pin): if pin: self.setLinkGroup(hou.paneLinkType.Pinned) else: self.setLinkGroup(hou.paneLinkType.FollowSelection)
See also hou.PaneTab.setLinkGroup.
size()
→ tuple
of int
Return a 2-tuple containing the pane tab’s width and height.
The width and height include the content area, network navigation control area (if any) and borders.
The width and height do not include the pane tab’s tab area.
contentSize()
→ tuple
of int
Return a 2-tuple containing the pane tab’s content area width and height.
The width and height do not include the network navigation control area (if any), pane tab borders or tab area.
hasNetworkControls()
→ bool
Return True if this pane tab type supports network controls.
isShowingNetworkControls()
→ bool
Return whether this pane tab is showing its network control bar. Return False if the pane tab doesn’t have network controls. See also hou.PaneTab.hasNetworkControls.
setShowNetworkControls(pin)
Show or Hide the network control bar. Has no effect if the pane tab doesn’t have network controls. See also hou.PaneTab.hasNetworkControls.
This method is deprecated in favor of showNetworkControls
.
showNetworkControls(pin)
Show or Hide the network control bar. Has no effect if the pane tab doesn’t have network controls. See also hou.PaneTab.hasNetworkControls.
displayRadialMenu(menu)
Launch the specified radial menu in the pane tab.
qtParentWindow()
→ QWidget
Return a PySide6.QtWidgets.QWidget
instance that represents the window
containing the pane tab.
qtScreenGeometry()
→ QRect
Return the geometry of the pane as a PySide6.QtCore.QRect
object. The x
and y
properties of the returned QRect
object
point to the top-left corner of the pane in screen coordinates.
Methods from hou.PathBasedPaneTab ¶
cd(path)
currentNode()
→ Node
pwd()
→ Node
setCurrentNode(node, pick_node = True)
setPwd(node)