fix: direct setStyleSheet (no unpolish/polish), removed modal debug popup — was crashing window after popup dismiss
This commit is contained in:
+21
-21
@@ -30,7 +30,20 @@ def save_config(cfg):
|
|||||||
def bridge_is_open(port):
|
def bridge_is_open(port):
|
||||||
return f"Port {port} is open" in hou.hscript("openport")[0]
|
return f"Port {port} is open" in hou.hscript("openport")[0]
|
||||||
|
|
||||||
# ── Window (QWidget, not QDialog — per SideFX HOM cookbook) ─
|
# ── Styles ──────────────────────────────────────────
|
||||||
|
STYLE_CONNECTED = (
|
||||||
|
"QPushButton {"
|
||||||
|
" background: #5c1a1a; color: #ff7777;"
|
||||||
|
" border: 1px solid #a44; border-radius: 4px;"
|
||||||
|
" padding: 12px; font-size: 15px; font-weight: bold; }"
|
||||||
|
)
|
||||||
|
STYLE_DISCONNECTED = (
|
||||||
|
"QPushButton {"
|
||||||
|
" background: #1a4a1a; color: #77cc77;"
|
||||||
|
" border: 1px solid #4a4; border-radius: 4px;"
|
||||||
|
" padding: 12px; font-size: 15px; font-weight: bold; }"
|
||||||
|
)
|
||||||
|
|
||||||
class HermesBridgeWindow(QtWidgets.QWidget):
|
class HermesBridgeWindow(QtWidgets.QWidget):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
@@ -39,7 +52,7 @@ class HermesBridgeWindow(QtWidgets.QWidget):
|
|||||||
self.hostname = socket.gethostname()
|
self.hostname = socket.gethostname()
|
||||||
self._build_ui()
|
self._build_ui()
|
||||||
self._refresh()
|
self._refresh()
|
||||||
# Connect AFTER refresh — avoids signal-loss from style changes
|
# Connect after refresh — style changes don't kill the signal
|
||||||
self.btn_toggle.released.connect(self._toggle)
|
self.btn_toggle.released.connect(self._toggle)
|
||||||
|
|
||||||
def _build_ui(self):
|
def _build_ui(self):
|
||||||
@@ -49,14 +62,8 @@ class HermesBridgeWindow(QtWidgets.QWidget):
|
|||||||
self.setStyleSheet("""
|
self.setStyleSheet("""
|
||||||
QWidget { background: #1e1e1e; color: #e0e0e0; font-size: 13px; }
|
QWidget { background: #1e1e1e; color: #e0e0e0; font-size: 13px; }
|
||||||
QLabel#title { font-size: 16px; font-weight: bold; color: #fff; }
|
QLabel#title { font-size: 16px; font-weight: bold; color: #fff; }
|
||||||
QPushButton { border: none; border-radius: 4px; padding: 8px 16px;
|
QPushButton#btnCopy { background: #1565c0; color: #fff;
|
||||||
font-weight: bold; }
|
border: none; border-radius: 4px; padding: 8px 16px; font-weight: bold; }
|
||||||
QPushButton#btnToggle { padding: 12px; font-size: 15px; }
|
|
||||||
QPushButton#btnToggle[active="true"] {
|
|
||||||
background: #5c1a1a; color: #ff7777; border: 1px solid #a44; }
|
|
||||||
QPushButton#btnToggle[active="false"] {
|
|
||||||
background: #1a4a1a; color: #77cc77; border: 1px solid #4a4; }
|
|
||||||
QPushButton#btnCopy { background: #1565c0; color: #fff; }
|
|
||||||
QPushButton#btnCopy:hover { background: #1976d2; }
|
QPushButton#btnCopy:hover { background: #1976d2; }
|
||||||
QSpinBox { background: #2d2d2d; border: 1px solid #555; color: #e0e0e0;
|
QSpinBox { background: #2d2d2d; border: 1px solid #555; color: #e0e0e0;
|
||||||
padding: 5px 8px; border-radius: 3px; }
|
padding: 5px 8px; border-radius: 3px; }
|
||||||
@@ -86,7 +93,7 @@ class HermesBridgeWindow(QtWidgets.QWidget):
|
|||||||
port_row.addStretch()
|
port_row.addStretch()
|
||||||
layout.addLayout(port_row)
|
layout.addLayout(port_row)
|
||||||
|
|
||||||
self.btn_toggle = QtWidgets.QPushButton("Open Bridge")
|
self.btn_toggle = QtWidgets.QPushButton()
|
||||||
self.btn_toggle.setObjectName("btnToggle")
|
self.btn_toggle.setObjectName("btnToggle")
|
||||||
layout.addWidget(self.btn_toggle)
|
layout.addWidget(self.btn_toggle)
|
||||||
|
|
||||||
@@ -100,7 +107,6 @@ class HermesBridgeWindow(QtWidgets.QWidget):
|
|||||||
self.btn_copy.clicked.connect(self._copy)
|
self.btn_copy.clicked.connect(self._copy)
|
||||||
prompt_row.addWidget(self.btn_copy)
|
prompt_row.addWidget(self.btn_copy)
|
||||||
layout.addLayout(prompt_row)
|
layout.addLayout(prompt_row)
|
||||||
|
|
||||||
layout.addStretch()
|
layout.addStretch()
|
||||||
|
|
||||||
def _refresh(self):
|
def _refresh(self):
|
||||||
@@ -111,24 +117,18 @@ class HermesBridgeWindow(QtWidgets.QWidget):
|
|||||||
self.status_label.setStyleSheet(
|
self.status_label.setStyleSheet(
|
||||||
"color: #4caf50; font-size: 14px; font-weight: bold;")
|
"color: #4caf50; font-size: 14px; font-weight: bold;")
|
||||||
self.btn_toggle.setText("Close Bridge")
|
self.btn_toggle.setText("Close Bridge")
|
||||||
self.btn_toggle.setProperty("active", "true")
|
self.btn_toggle.setStyleSheet(STYLE_CONNECTED)
|
||||||
else:
|
else:
|
||||||
self.status_label.setText("\u25cf Not connected")
|
self.status_label.setText("\u25cf Not connected")
|
||||||
self.status_label.setStyleSheet(
|
self.status_label.setStyleSheet(
|
||||||
"color: #ff5555; font-size: 14px; font-weight: bold;")
|
"color: #ff5555; font-size: 14px; font-weight: bold;")
|
||||||
self.btn_toggle.setText("Open Bridge")
|
self.btn_toggle.setText("Open Bridge")
|
||||||
self.btn_toggle.setProperty("active", "false")
|
self.btn_toggle.setStyleSheet(STYLE_DISCONNECTED)
|
||||||
self.btn_toggle.style().unpolish(self.btn_toggle)
|
|
||||||
self.btn_toggle.style().polish(self.btn_toggle)
|
|
||||||
self.prompt_field.setText(
|
self.prompt_field.setText(
|
||||||
f"Hey Hermes, I have a Houdini session running "
|
f"Hey Hermes, I have a Houdini session running "
|
||||||
f"on {self.hostname} (port {self.port}).")
|
f"on {self.hostname} (port {self.port}).")
|
||||||
|
|
||||||
def _toggle(self):
|
def _toggle(self):
|
||||||
hou.ui.displayMessage(
|
|
||||||
"TOGGLE FIRED! (signal works)",
|
|
||||||
severity=hou.severityType.ImportantMessage,
|
|
||||||
title="Hermes Bridge")
|
|
||||||
try:
|
try:
|
||||||
if bridge_is_open(self.port):
|
if bridge_is_open(self.port):
|
||||||
hou.hscript(f"closeport {self.port}")
|
hou.hscript(f"closeport {self.port}")
|
||||||
@@ -160,7 +160,7 @@ class HermesBridgeWindow(QtWidgets.QWidget):
|
|||||||
QtCore.QTimer.singleShot(2000,
|
QtCore.QTimer.singleShot(2000,
|
||||||
lambda: self.btn_copy.setText("Copy"))
|
lambda: self.btn_copy.setText("Copy"))
|
||||||
|
|
||||||
# ── Store on hou.session to prevent GC (per SideFX docs) ──
|
# ── Keep alive via hou.session ──
|
||||||
win = HermesBridgeWindow()
|
win = HermesBridgeWindow()
|
||||||
hou.session.hermes_bridge_win = win
|
hou.session.hermes_bridge_win = win
|
||||||
win.show()
|
win.show()
|
||||||
|
|||||||
Reference in New Issue
Block a user