git clone https://git.lucas.co/hou-control.git
python3.11libs/hc/hcstatus.py (3.5K)
1 import hou
2 from PySide6.QtCore import Qt, QTimer
3 from PySide6.QtGui import QCursor
4 from PySide6.QtWidgets import QDialog, QLabel, QVBoxLayout
5
6
7 class HCStatus(QDialog):
8 OBJECT_NAME = "hc_status_dialog"
9
10 def __init__(self):
11 super().__init__(hou.qt.mainWindow())
12 self.setObjectName(self.OBJECT_NAME)
13 self.setWindowTitle("HC Status")
14 self.setWindowFlags(Qt.Tool | Qt.WindowStaysOnTopHint)
15 self.resize(440, 240)
16
17 self.desktop_label = QLabel()
18 self.pane_label = QLabel()
19 self.tab_type_label = QLabel()
20 self.tab_name_label = QLabel()
21 self.context_label = QLabel()
22 self.path_label = QLabel()
23 self.cursor_screen_label = QLabel()
24 self.cursor_main_label = QLabel()
25 self.hip_label = QLabel()
26
27 layout = QVBoxLayout(self)
28 for w in (
29 self.desktop_label,
30 self.hip_label,
31 self.pane_label,
32 self.tab_type_label,
33 self.tab_name_label,
34 self.context_label,
35 self.path_label,
36 self.cursor_screen_label,
37 self.cursor_main_label,
38 ):
39 layout.addWidget(w)
40 layout.addStretch()
41
42 self.timer = QTimer(self)
43 self.timer.timeout.connect(self.refresh)
44 self.refresh()
45
46 def showEvent(self, event):
47 self.timer.start(100)
48 self.refresh()
49 super().showEvent(event)
50
51 def hideEvent(self, event):
52 self.timer.stop()
53 super().hideEvent(event)
54
55 def refresh(self):
56 self.desktop_label.setText(f"Desktop: {hou.ui.curDesktop().name()}")
57 self.hip_label.setText(f"Hip: {hou.hipFile.path()}")
58
59 pane = hou.ui.paneUnderCursor()
60 if pane is None:
61 self.pane_label.setText("Pane: —")
62 self.tab_type_label.setText("Tab Type: —")
63 self.tab_name_label.setText("Tab Name: —")
64 self.context_label.setText("Context: —")
65 self.path_label.setText("Path: —")
66 else:
67 self.pane_label.setText(f"Pane: #{pane.id()}")
68 tab = pane.currentTab()
69 if tab is None:
70 self.tab_type_label.setText("Tab Type: —")
71 self.tab_name_label.setText("Tab Name: —")
72 self.context_label.setText("Context: —")
73 self.path_label.setText("Path: —")
74 else:
75 tab_type = tab.type()
76 self.tab_type_label.setText(f"Tab Type: {tab_type.name()}")
77 self.tab_name_label.setText(f"Tab Name: {tab.name()}")
78 pwd = getattr(tab, "pwd", None)
79 if callable(pwd):
80 try:
81 node = pwd()
82 self.path_label.setText(f"Path: {node.path()}")
83 self.context_label.setText(f"Context: {node.childTypeCategory().name()}")
84 except Exception as e:
85 self.path_label.setText(f"Path: {e!r}")
86 self.context_label.setText("Context: —")
87 else:
88 self.path_label.setText("Path: —")
89 self.context_label.setText("Context: —")
90
91 screen = QCursor.pos()
92 self.cursor_screen_label.setText(f"Cursor (screen): ({screen.x()}, {screen.y()})")
93 rel = hou.qt.mainWindow().mapFromGlobal(screen)
94 self.cursor_main_label.setText(f"Cursor (main): ({rel.x()}, {rel.y()})")