SideFX Houdini customization package
git clone https://git.lucas.co/hou-control.git
python3.13libs/hc/hcparametertab.py (2.3K)
1 import hou
2 from . import hcstate
3 from .hcpathtab import HCPathTab
4
5 # Which parameter this pane last moved focus to.
6 _focused_parm = hcstate.Store("focused_parm", hcstate.PANE)
7
8
9 def _deferredEcho(label):
10 """Set status message on next event loop tick, then self-remove."""
11 def _cb():
12 hou.ui.setStatusMessage(label, hou.severityType.Message)
13 hou.ui.removeEventLoopCallback(_cb)
14 hou.ui.addEventLoopCallback(_cb)
15
16
17 class HCParameterTab(HCPathTab):
18 def __init__(self, hou_tab):
19 self.hou_tab = hou_tab
20
21 def type(self):
22 return "HCParameterTab"
23
24 def initialize(self):
25 self.showNetworkControls(False)
26
27 def _focusableParms(self):
28 """Return list of (parm_tuple, first_parm) for focusable parameters."""
29 result = []
30 for parm_tuple in self.hou_tab.visibleParms():
31 try:
32 if len(parm_tuple) > 0:
33 result.append((parm_tuple, parm_tuple[0]))
34 except TypeError:
35 pass
36 return result
37
38 def _currentFocusIndex(self, entries):
39 parm_path = _focused_parm.get(self.hou_tab)
40 if parm_path is None:
41 return None
42 for index, (_, parm) in enumerate(entries):
43 if parm.path() == parm_path:
44 return index
45 return None
46
47 def focusNextParameter(self):
48 entries = self._focusableParms()
49 if not entries:
50 return
51
52 current_index = self._currentFocusIndex(entries)
53 next_index = 0 if current_index is None else (current_index + 1) % len(entries)
54 parm_tuple, parm = entries[next_index]
55 self.hou_tab.moveFocusTo(parm)
56 _focused_parm.set(self.hou_tab, parm.path())
57 label = parm_tuple.parmTemplate().label()
58 _deferredEcho(label)
59
60 def focusPreviousParameter(self):
61 entries = self._focusableParms()
62 if not entries:
63 return
64
65 current_index = self._currentFocusIndex(entries)
66 prev_index = len(entries) - 1 if current_index is None else (current_index - 1) % len(entries)
67 parm_tuple, parm = entries[prev_index]
68 self.hou_tab.moveFocusTo(parm)
69 _focused_parm.set(self.hou_tab, parm.path())
70 label = parm_tuple.parmTemplate().label()
71 _deferredEcho(label)