Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Improve UI/UX of the Debugger pane #22163

Merged
merged 7 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Debugger: Add new action specific to post mortem debugging
- That allows us to represent it with a different icon which will make
more sense to users.
- Also, group actions that interact with the console in a new toolbar
section.
  • Loading branch information
ccordoba12 committed Jun 12, 2024
commit 3e45f74afad6cb719be946c144aa3e2d769e352e
4 changes: 4 additions & 0 deletions spyder/images/dark/postmortem_debug.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions spyder/images/light/postmortem_debug.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 47 additions & 18 deletions spyder/plugins/debugger/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class DebuggerWidgetActions:
Search = 'search'
Inspect = 'inspect'
EnterDebug = 'enter_debug'
InterrupAndDebug = "interrupt_and_debug"
Next = "next"
Continue = "continue"
Step = "step"
Expand All @@ -61,6 +62,7 @@ class DebuggerWidgetOptionsMenuSections:

class DebuggerWidgetMainToolBarSections:
Control = 'control_section'
InteractWithConsole = "interact_with_console_section"
Extras = "extras_section"


Expand Down Expand Up @@ -233,9 +235,17 @@ def setup(self):

enter_debug_action = self.create_action(
DebuggerWidgetActions.EnterDebug,
text=_("Interrupt execution and enter debugger"),
text=_("Start debugging after last error"),
icon=self.create_icon("postmortem_debug"),
triggered=self.enter_debugger_after_exception,
register_shortcut=True,
)

interrupt_and_debug_action = self.create_action(
DebuggerWidgetActions.InterrupAndDebug,
text=_("Interrupt execution and start the debugger"),
icon=self.create_icon("interrupt_and_debug"),
triggered=self.enter_debug,
triggered=self.interrupt_and_debug,
register_shortcut=True,
)

Expand Down Expand Up @@ -354,13 +364,22 @@ def setup(self):
section=DebuggerWidgetMainToolBarSections.Control,
)

for item in [
enter_debug_action,
interrupt_and_debug_action,
inspect_action,
]:
self.add_item_to_toolbar(
item,
toolbar=main_toolbar,
section=DebuggerWidgetMainToolBarSections.InteractWithConsole,
)

stretcher = self.create_stretcher(
DebuggerWidgetToolbarItems.ToolbarStretcher
)
for item in [
goto_cursor_action,
enter_debug_action,
inspect_action,
search_action,
stretcher,
toggle_breakpoints_action,
Expand All @@ -376,14 +395,19 @@ def update_actions(self):
try:
search_action = self.get_action(DebuggerWidgetActions.Search)
enter_debug_action = self.get_action(
DebuggerWidgetActions.EnterDebug)
DebuggerWidgetActions.EnterDebug
)
interrupt_and_debug_action = self.get_action(
DebuggerWidgetActions.InterrupAndDebug
)
inspect_action = self.get_action(
DebuggerWidgetActions.Inspect)
DebuggerWidgetActions.Inspect
)

widget = self.current_widget()
if self.is_current_widget_empty() or widget is None:
search_action.setEnabled(False)
show_enter_debugger = False
post_mortem = False
executing = False
pdb_prompt = False
else:
Expand All @@ -392,10 +416,10 @@ def update_actions(self):
post_mortem = widget.state == FramesBrowserState.Error
sw = widget.shellwidget
executing = sw._executing
show_enter_debugger = post_mortem or executing
pdb_prompt = sw.is_waiting_pdb_input()

enter_debug_action.setEnabled(show_enter_debugger)
enter_debug_action.setEnabled(post_mortem and not executing)
interrupt_and_debug_action.setEnabled(executing)
inspect_action.setEnabled(executing)

for action_name in [
Expand Down Expand Up @@ -578,12 +602,22 @@ def hide_finder(self):
action = self.get_action(DebuggerWidgetActions.Search)
action.setChecked(False)

def enter_debug(self):
"""
Enter the debugger.
def enter_debugger_after_exception(self):
"""Enter the debugger after an exception."""
widget = self.current_widget()
if widget is None:
return

# Enter the debugger
sw = widget.shellwidget
if widget.state == FramesBrowserState.Error:
# Debug the last exception
sw.execute("%debug")
return

def interrupt_and_debug(self):
"""
If the shell is executing, interrupt execution and enter debugger.
If an exception took place, run post mortem.
"""
widget = self.current_widget()
if widget is None:
Expand All @@ -601,11 +635,6 @@ def enter_debug(self):
sw.call_kernel(interrupt=True).request_pdb_stop()
return

if widget.state == FramesBrowserState.Error:
# Debug the last exception
sw.execute("%debug")
return

def capture_frames(self):
"""Refresh frames table"""
widget = self.current_widget()
Expand Down