Skip to content

Commit 6997f4a

Browse files
committed
Make Remote Desktop tab optional when webrtc extra is missing
PyBreeze (and similar embedders) imports 'from je_auto_control.gui.main_widget import AutoControlGUIWidget' directly, which previously cascaded through RemoteDesktopTab → webrtc_panel → webrtc_transport and required the optional 'webrtc' extra (aiortc + PyAV). Wrap the eager import in a try/except and substitute a placeholder tab with install instructions when the extra is unavailable, so embedders can mount the GUI on a base install and still run the rest of the suite.
1 parent a76d9b9 commit 6997f4a

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

je_auto_control/gui/main_widget.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@
2828
from je_auto_control.gui.recording_editor_tab import RecordingEditorTab
2929
from je_auto_control.gui.usb_browser_tab import UsbBrowserTab
3030
from je_auto_control.gui.usb_devices_tab import UsbDevicesTab
31-
from je_auto_control.gui.remote_desktop_tab import RemoteDesktopTab
31+
# Remote desktop relies on the optional `webrtc` extra (aiortc + PyAV).
32+
# Importing it eagerly would break embedders (e.g. PyBreeze) that install
33+
# je_auto_control without the extra; fall back to a placeholder tab that
34+
# tells the user how to enable it.
35+
try:
36+
from je_auto_control.gui.remote_desktop_tab import RemoteDesktopTab
37+
_REMOTE_DESKTOP_IMPORT_ERROR: ImportError = None
38+
except ImportError as _remote_desktop_error:
39+
RemoteDesktopTab = None # type: ignore[assignment]
40+
_REMOTE_DESKTOP_IMPORT_ERROR = _remote_desktop_error
3241
from je_auto_control.gui.rest_api_tab import RestApiTab
3342
from je_auto_control.gui.run_history_tab import RunHistoryTab
3443
from je_auto_control.gui.scheduler_tab import SchedulerTab
@@ -142,8 +151,11 @@ def __init__(self, parent=None):
142151
category="system")
143152
self._add_tab("plugins", "tab_plugins", PluginsTab(),
144153
category="system")
145-
self._add_tab("remote_desktop", "tab_remote_desktop", RemoteDesktopTab(),
146-
category="system", default_visible=True)
154+
self._add_tab(
155+
"remote_desktop", "tab_remote_desktop",
156+
self._build_remote_desktop_tab(),
157+
category="system", default_visible=True,
158+
)
147159
self._add_tab("rest_api", "tab_rest_api", RestApiTab(),
148160
category="system")
149161
self._add_tab("admin_console", "tab_admin_console", AdminConsoleTab(),
@@ -169,6 +181,26 @@ def __init__(self, parent=None):
169181
self.repeat_max = 0
170182
self._record_data = []
171183

184+
@staticmethod
185+
def _build_remote_desktop_tab() -> QWidget:
186+
"""Return the real remote-desktop tab, or a placeholder if the
187+
``webrtc`` extra is not installed."""
188+
if RemoteDesktopTab is not None:
189+
return RemoteDesktopTab()
190+
placeholder = QWidget()
191+
layout = QVBoxLayout(placeholder)
192+
message = QLabel(
193+
"Remote Desktop is unavailable: the optional 'webrtc' extra "
194+
"(aiortc + PyAV) is not installed.\n\n"
195+
"Install with:\n pip install je_auto_control[webrtc]\n\n"
196+
f"Underlying error: {_REMOTE_DESKTOP_IMPORT_ERROR!r}",
197+
)
198+
message.setWordWrap(True)
199+
message.setTextInteractionFlags(Qt.TextSelectableByMouse)
200+
layout.addWidget(message)
201+
layout.addStretch()
202+
return placeholder
203+
172204
# --- tab registry API ----------------------------------------------------
173205

174206
def _add_tab(

0 commit comments

Comments
 (0)