fix: QDialog → QWidget per SideFX HOM cookbook (QDialog blocks events when shown non-modally)
This commit is contained in:
@@ -30,8 +30,8 @@ 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]
|
||||||
|
|
||||||
# ── Dialog ──────────────────────────────────────────
|
# ── Window (QWidget, not QDialog — per SideFX HOM cookbook) ─
|
||||||
class HermesBridgeDialog(QtWidgets.QDialog):
|
class HermesBridgeWindow(QtWidgets.QWidget):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.cfg = load_config()
|
self.cfg = load_config()
|
||||||
@@ -43,22 +43,17 @@ class HermesBridgeDialog(QtWidgets.QDialog):
|
|||||||
def _build_ui(self):
|
def _build_ui(self):
|
||||||
self.setWindowTitle("Hermes Bridge")
|
self.setWindowTitle("Hermes Bridge")
|
||||||
self.setMinimumWidth(420)
|
self.setMinimumWidth(420)
|
||||||
self.setAttribute(QtCore.Qt.WA_DeleteOnClose, False)
|
|
||||||
|
|
||||||
# Dark theme
|
|
||||||
self.setStyleSheet("""
|
self.setStyleSheet("""
|
||||||
QDialog { background: #1e1e1e; color: #e0e0e0; }
|
QWidget { background: #1e1e1e; color: #e0e0e0; font-size: 13px; }
|
||||||
QLabel { color: #ccc; }
|
|
||||||
QLabel#title { font-size: 16px; font-weight: bold; color: #fff; }
|
QLabel#title { font-size: 16px; font-weight: bold; color: #fff; }
|
||||||
QLabel#status { font-size: 14px; font-weight: bold; }
|
|
||||||
QPushButton { border: none; border-radius: 4px; padding: 8px 16px;
|
QPushButton { border: none; border-radius: 4px; padding: 8px 16px;
|
||||||
font-weight: bold; font-size: 13px; }
|
font-weight: bold; }
|
||||||
QPushButton#btnToggle { padding: 12px; font-size: 15px; }
|
QPushButton#btnToggle { padding: 12px; font-size: 15px; }
|
||||||
QPushButton#btnToggle[active="true"] {
|
QPushButton#btnToggle[active="true"] {
|
||||||
background: #5c1a1a; color: #ff7777; border: 1px solid #a44; }
|
background: #5c1a1a; color: #ff7777; border: 1px solid #a44; }
|
||||||
QPushButton#btnToggle[active="false"] {
|
QPushButton#btnToggle[active="false"] {
|
||||||
background: #1a4a1a; color: #77cc77; border: 1px solid #4a4; }
|
background: #1a4a1a; color: #77cc77; border: 1px solid #4a4; }
|
||||||
QPushButton#btnToggle:hover { opacity: 0.9; }
|
|
||||||
QPushButton#btnCopy { background: #1565c0; color: #fff; }
|
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;
|
||||||
@@ -71,17 +66,13 @@ class HermesBridgeDialog(QtWidgets.QDialog):
|
|||||||
layout.setSpacing(12)
|
layout.setSpacing(12)
|
||||||
layout.setContentsMargins(20, 20, 20, 20)
|
layout.setContentsMargins(20, 20, 20, 20)
|
||||||
|
|
||||||
# Title
|
|
||||||
title = QtWidgets.QLabel("\U0001f916 Hermes Bridge")
|
title = QtWidgets.QLabel("\U0001f916 Hermes Bridge")
|
||||||
title.setObjectName("title")
|
title.setObjectName("title")
|
||||||
layout.addWidget(title)
|
layout.addWidget(title)
|
||||||
|
|
||||||
# Status
|
|
||||||
self.status_label = QtWidgets.QLabel()
|
self.status_label = QtWidgets.QLabel()
|
||||||
self.status_label.setObjectName("status")
|
|
||||||
layout.addWidget(self.status_label)
|
layout.addWidget(self.status_label)
|
||||||
|
|
||||||
# Port
|
|
||||||
port_row = QtWidgets.QHBoxLayout()
|
port_row = QtWidgets.QHBoxLayout()
|
||||||
port_row.addWidget(QtWidgets.QLabel("Port:"))
|
port_row.addWidget(QtWidgets.QLabel("Port:"))
|
||||||
self.port_spin = QtWidgets.QSpinBox()
|
self.port_spin = QtWidgets.QSpinBox()
|
||||||
@@ -93,13 +84,11 @@ class HermesBridgeDialog(QtWidgets.QDialog):
|
|||||||
port_row.addStretch()
|
port_row.addStretch()
|
||||||
layout.addLayout(port_row)
|
layout.addLayout(port_row)
|
||||||
|
|
||||||
# Toggle button
|
|
||||||
self.btn_toggle = QtWidgets.QPushButton()
|
self.btn_toggle = QtWidgets.QPushButton()
|
||||||
self.btn_toggle.setObjectName("btnToggle")
|
self.btn_toggle.setObjectName("btnToggle")
|
||||||
self.btn_toggle.clicked.connect(self._toggle)
|
self.btn_toggle.clicked.connect(self._toggle)
|
||||||
layout.addWidget(self.btn_toggle)
|
layout.addWidget(self.btn_toggle)
|
||||||
|
|
||||||
# Prompt text
|
|
||||||
layout.addWidget(QtWidgets.QLabel("Tell Hermes:"))
|
layout.addWidget(QtWidgets.QLabel("Tell Hermes:"))
|
||||||
prompt_row = QtWidgets.QHBoxLayout()
|
prompt_row = QtWidgets.QHBoxLayout()
|
||||||
self.prompt_field = QtWidgets.QLineEdit()
|
self.prompt_field = QtWidgets.QLineEdit()
|
||||||
@@ -128,7 +117,6 @@ class HermesBridgeDialog(QtWidgets.QDialog):
|
|||||||
"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.setProperty("active", "false")
|
||||||
# Force style refresh
|
|
||||||
self.btn_toggle.style().unpolish(self.btn_toggle)
|
self.btn_toggle.style().unpolish(self.btn_toggle)
|
||||||
self.btn_toggle.style().polish(self.btn_toggle)
|
self.btn_toggle.style().polish(self.btn_toggle)
|
||||||
self.prompt_field.setText(
|
self.prompt_field.setText(
|
||||||
@@ -151,7 +139,6 @@ class HermesBridgeDialog(QtWidgets.QDialog):
|
|||||||
self.cfg["port"] = value
|
self.cfg["port"] = value
|
||||||
save_config(self.cfg)
|
save_config(self.cfg)
|
||||||
if was_open:
|
if was_open:
|
||||||
hou.hscript(f"closeport {self.port}")
|
|
||||||
hou.hscript(f"openport {self.port} 0.0.0.0")
|
hou.hscript(f"openport {self.port} 0.0.0.0")
|
||||||
self._refresh()
|
self._refresh()
|
||||||
|
|
||||||
@@ -162,13 +149,6 @@ class HermesBridgeDialog(QtWidgets.QDialog):
|
|||||||
QtCore.QTimer.singleShot(2000,
|
QtCore.QTimer.singleShot(2000,
|
||||||
lambda: self.btn_copy.setText("Copy"))
|
lambda: self.btn_copy.setText("Copy"))
|
||||||
|
|
||||||
# ── Show dialog (persist in hou.session per SideFX docs) ──
|
# ── Per SideFX docs: parent to main window to keep alive ──
|
||||||
if not hasattr(hou.session, "hermes_bridge_dialog") or hou.session.hermes_bridge_dialog is None:
|
win = HermesBridgeWindow(hou.ui.mainQtWindow())
|
||||||
hou.session.hermes_bridge_dialog = HermesBridgeDialog(hou.ui.mainQtWindow())
|
win.show()
|
||||||
dialog = hou.session.hermes_bridge_dialog
|
|
||||||
dialog.show()
|
|
||||||
dialog.raise_()
|
|
||||||
dialog.activateWindow()
|
|
||||||
]]></script>
|
|
||||||
</tool>
|
|
||||||
</shelfDocument>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user