From 0dadf7de97dcc6400185ad767ed7774b25a6be54 Mon Sep 17 00:00:00 2001 From: miruka Date: Sat, 16 Jan 2021 08:15:49 -0400 Subject: [PATCH] Have split python_(remote_)debugger keybinds python_debugger (shift+F1) will now always start pdb, and python_remote_debugger will always start remote_pdb. Since the new autoreload.py script doesn't break stdin like entr with live-reload.sh did, we can now use pdb if the app is connected to a terminal. --- src/backend/qml_bridge.py | 20 ++++++-------------- src/config/settings.py | 11 ++++++++--- src/gui/UI.qml | 5 +++++ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/backend/qml_bridge.py b/src/backend/qml_bridge.py index 0ec9d3f9..fc249025 100644 --- a/src/backend/qml_bridge.py +++ b/src/backend/qml_bridge.py @@ -133,10 +133,10 @@ class QMLBridge: self._cancelled_early.add(uuid) - def pdb(self, additional_data: Sequence = ()) -> None: + def pdb(self, extra_data: Sequence = (), remote: bool = False) -> None: """Call the RemotePdb debugger; define some conveniance variables.""" - ad = additional_data # noqa + ad = extra_data # noqa ba = self.backend # noqa mo = self.backend.models # noqa cl = self.backend.clients @@ -151,21 +151,13 @@ class QMLBridge: except ModuleNotFoundError: pass - try: + if remote: + # Run `socat readline tcp:127.0.0.1:4444` in a terminal to connect import remote_pdb - except ModuleNotFoundError: - log.warning( - "\nThe remote_pdb python package is not installed, falling " - "back to pdb.", - ) + remote_pdb.RemotePdb("127.0.0.1", 4444).set_trace() + else: import pdb pdb.set_trace() - else: - log.info( - "\n=> Run `socat readline tcp:127.0.0.1:4444` in a terminal " - "to connect to the debugger.", - ) - remote_pdb.RemotePdb("127.0.0.1", 4444).set_trace() def exit(self) -> None: diff --git a/src/config/settings.py b/src/config/settings.py index b6698b7d..6517d05d 100644 --- a/src/config/settings.py +++ b/src/config/settings.py @@ -219,13 +219,18 @@ class Keys: # Switch to the last opened page/chat, similar to Alt+Tab on most desktops. last_page = ["Ctrl+Tab"] - # Toggle the QML developer console. Type ". help" in it for more info. + # Toggle the QML developer console. Type ". help" inside it for more info. qml_console = ["F1"] - # Start the Python backend debugger. Unless the "remote-pdb" pip package is - # installed, Mirage must be started from a terminal for this to work. + # Start the Python backend debugger. + # Mirage must be connected to a terminal for this to work. python_debugger = ["Shift+F1"] + # Start the Python backend debugger in remote access mode. + # The remote-pdb Python package must be installed. + # From any terminal, run `socat readline tcp:127.0.0.1:4444` to connect. + python_remote_debugger = ["Alt+F1"] + class Scrolling: # Pages and chat timeline scrolling up = ["Alt+Up", "Alt+K"] diff --git a/src/gui/UI.qml b/src/gui/UI.qml index 7e5a2fa6..8632ffb5 100644 --- a/src/gui/UI.qml +++ b/src/gui/UI.qml @@ -39,6 +39,11 @@ Item { onActivated: py.call("BRIDGE.pdb") } + HShortcut { + sequences: window.settings.Keys.python_remote_debugger + onActivated: py.call("BRIDGE.pdb", [[], true]) + } + HShortcut { sequences: window.settings.Keys.zoom_in onActivated: {