Skip to content

Commit

Permalink
Debugger: Show/hide buttons that control it in the main toolbar
Browse files Browse the repository at this point in the history
Those buttons will be visible only if there's a debugging session active
in the current console.
  • Loading branch information
ccordoba12 committed Oct 25, 2024
1 parent 25642ed commit 15f1a15
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions spyder/plugins/debugger/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ def on_toolbar_available(self):
toolbar_id=ApplicationToolbars.Debug,
)

debug_toolbar = toolbar.get_application_toolbar(
ApplicationToolbars.Debug
)
debug_toolbar.sig_is_rendered.connect(
self.get_widget().on_debug_toolbar_rendered
)

@on_plugin_teardown(plugin=Plugins.Toolbar)
def on_toolbar_teardown(self):
toolbar = self.get_plugin(Plugins.Toolbar)
Expand Down
44 changes: 44 additions & 0 deletions spyder/plugins/debugger/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
import qstylizer.style
from spyder.api.config.decorators import on_conf_change
from spyder.api.shellconnect.main_widget import ShellConnectMainWidget
from spyder.api.plugins import Plugins
from spyder.api.translations import _
from spyder.plugins.debugger.widgets.framesbrowser import (
FramesBrowser, FramesBrowserState)
from spyder.plugins.debugger.widgets.breakpoint_table_view import (
BreakpointTableView, BreakpointTableViewActions)
from spyder.plugins.toolbar.api import ApplicationToolbars
from spyder.utils.palette import SpyderPalette
from spyder.utils.stylesheet import APP_TOOLBAR_STYLESHEET


# =============================================================================
Expand Down Expand Up @@ -171,6 +174,12 @@ def __init__(self, name=None, plugin=None, parent=None):
f"border-radius: {SpyderPalette.SIZE_BORDER_RADIUS}"
)

# To manipulate the control debugger buttons in the Debug toolbar
self._control_debugger_toolbar_widgets = []
self._app_toolbar_button_width = (
int(APP_TOOLBAR_STYLESHEET.BUTTON_WIDTH.split("px")[0])
)

# Layout
# Create the layout.
layout = QHBoxLayout()
Expand Down Expand Up @@ -429,6 +438,8 @@ def update_actions(self):
action = self.get_action(action_name)
action.setEnabled(pdb_prompt)

self._set_visible_control_debugger_buttons(pdb_prompt)

rows = self.breakpoints_table.selectionModel().selectedRows()
initial_row = rows[0] if rows else None

Expand Down Expand Up @@ -722,6 +733,31 @@ def update_splitter_widths(self, base_width):
if base_width - table_width > 0:
self.splitter.setSizes([base_width - table_width, table_width])

def on_debug_toolbar_rendered(self):
"""Actions to take when the Debug toolbar is rendered."""
debug_toolbar = self.get_toolbar(
ApplicationToolbars.Debug, plugin=Plugins.Toolbar
)

# Get widgets corresponding to control debugger actions in the Debug
# toolbar
for action_id in [
DebuggerWidgetActions.Next,
DebuggerWidgetActions.Step,
DebuggerWidgetActions.Return,
DebuggerWidgetActions.Continue,
DebuggerWidgetActions.Stop,
]:
action = self.get_action(action_id)
widget = debug_toolbar.widgetForAction(action)

# Hide widgets by default because no debugging session is
# active at startup
widget.setFixedWidth(0)

# Save widgets in this list to manipulate them later
self._control_debugger_toolbar_widgets.append(widget)

# ---- Private API
# ------------------------------------------------------------------------
def _update_stylesheet(self, is_table_shown=False):
Expand All @@ -739,3 +775,11 @@ def _update_stylesheet(self, is_table_shown=False):
borderBottomRightRadius=f'{border_radius}',
)
self._stack.setStyleSheet(css.toString())

def _set_visible_control_debugger_buttons(self, visible: bool):
"""Show/hide control debugger buttons in the Debug toolbar."""
for widget in self._control_debugger_toolbar_widgets:
if visible:
widget.setFixedWidth(self._app_toolbar_button_width)
else:
widget.setFixedWidth(0)

0 comments on commit 15f1a15

Please sign in to comment.