git.lucas.co / hou-control
git clone https://git.lucas.co/hou-control.git

python3.11libs/hc/hcpane.py (4.1K)

  1 import hou
  2 from .hctab import HCTab
  3 from .hcpathtab import HCPathTab
  4 from .hcparametertab import HCParameterTab
  5 from .hcsceneviewer import HCSceneViewer
  6 from .hcnetworkeditor import HCNetworkEditor
  7 
  8 class HCPane:
  9     def __init__(self, hou_pane):
 10         self.hou_pane = hou_pane
 11 
 12     def initialize(self):
 13         """Per-pane setup hook. Called by factory callers (HCLayout.launchFloating)
 14         after a pane is created so per-pane defaults can apply."""
 15         self.showTabs(False)
 16 
 17     """ Adjust size """
 18 
 19     def setIsMaximized(self, bool):
 20         self.hou_pane.setIsMaximized(bool)
 21 
 22     def setIsSplitMaximized(self, bool):
 23         self.hou_pane.setIsSplitMaximized(bool)
 24 
 25     def setSplitFraction(self, fraction):
 26         self.hou_pane.setSplitFraction(fraction)
 27 
 28     def splitHorizontal(self):
 29         self.hou_pane.splitHorizontally()
 30 
 31     def splitRotate(self):
 32         self.hou_pane.splitRotate()
 33 
 34     def splitSwap(self):
 35         self.hou_pane.splitSwap()
 36 
 37     def splitVertical(self):
 38         self.hou_pane.splitVertically()
 39 
 40     def contract(self):
 41         fraction = round(self.splitFraction(), 3) + 0.1
 42         self.setSplitFraction(fraction)
 43         hou.ui.setStatusMessage("Pane fraction: " + str(fraction))
 44 
 45     def expand(self):
 46         fraction = round(self.splitFraction(), 3) - 0.1
 47         self.setSplitFraction(fraction)
 48         hou.ui.setStatusMessage("Pane fraction: " + str(fraction))
 49 
 50     def setRatioHalf(self):
 51         self.setSplitFraction(0.5)
 52 
 53     def setRatioQuarter(self):
 54         self.setSplitFraction(0.25)
 55 
 56     def setRatioThird(self):
 57         self.setSplitFraction(0.333)
 58 
 59     def toggleSplitMaximized(self):
 60         self.setIsSplitMaximized(not self.isSplitMaximized())
 61 
 62     def toggleMaximize(self):
 63         self.hou_pane.setIsMaximized(not self.isMaximized())
 64 
 65 
 66     """ Size info """
 67 
 68     def isMaximized(self):
 69         return self.hou_pane.isMaximized()
 70 
 71     def qtScreenGeometry(self):
 72         return self.hou_pane.qtScreenGeometry()
 73 
 74     def isSplitMaximized(self):
 75         return self.hou_pane.isSplitMaximized()
 76 
 77     def splitFraction(self):
 78         return self.hou_pane.getSplitFraction()
 79 
 80 
 81     """ Tabs """
 82 
 83     def close(self):
 84         for tab in self.tabs():
 85             tab.close()
 86 
 87     def convertTab(self, hou_tab):
 88         hou_tab_type = hou_tab.type()
 89         if hou_tab_type == hou.paneTabType.SceneViewer:
 90             return HCSceneViewer(hou_tab)
 91         elif hou_tab_type == hou.paneTabType.NetworkEditor:
 92             return HCNetworkEditor(hou_tab)
 93         elif hou_tab_type == hou.paneTabType.DetailsView:
 94             return HCPathTab(hou_tab)
 95         elif hou_tab_type == hou.paneTabType.Parm:
 96             return HCParameterTab(hou_tab)
 97         else:
 98             return HCTab(hou_tab)
 99 
100     def currentTab(self):
101         hou_tab = self.hou_pane.currentTab()
102         return self.convertTab(hou_tab)
103 
104     def isShowingTabs(self):
105         return self.hou_pane.isShowingPaneTabs()
106 
107     def newTab(self, tab_type, python_panel_interface=None):
108         return self.hou_pane.createTab(tab_type, python_panel_interface)
109 
110     def nextTab(self):
111         tabs = self.tabs()
112         tab_names = self.tabNames()
113         current_tab_name = self.currentTab().name()
114         current_tab_index = tab_names.index(current_tab_name)
115         new_tab_index = (current_tab_index + 1) % len(tabs)
116         tabs[new_tab_index].setCurrent()
117 
118     def prevTab(self):
119         tabs = self.tabs()
120         tab_names = self.tabNames()
121         current_tab_name = self.currentTab().name()
122         current_tab_index = tab_names.index(current_tab_name)
123         new_tab_index = (current_tab_index - 1) % len(tabs)
124         tabs[new_tab_index].setCurrent()
125 
126     def showTabs(self, value):
127         self.hou_pane.showPaneTabs(value)
128         self.hou_pane.showPaneTabsStow(value)
129 
130     def tabs(self):
131         tabs = []
132         for hou_tab in self.hou_pane.tabs():
133             tabs.append(HCTab(hou_tab))
134         return tabs
135 
136     def tabNames(self):
137         tab_names = []
138         for tab in self.tabs():
139             tab_names.append(tab.name())
140         return tab_names
141 
142     def toggleTabs(self):
143         self.showTabs(not self.isShowingTabs())