Skip to content

Commit

Permalink
Merge from 4.x: PR #12134
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Oct 24, 2020
2 parents 5ad4244 + 6554746 commit c15d347
Show file tree
Hide file tree
Showing 9 changed files with 506 additions and 328 deletions.
288 changes: 170 additions & 118 deletions spyder/app/tests/test_mainwindow.py

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions spyder/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@
# This is True because there are libraries like Pyomo
# that generate a lot of Command Prompts while running,
# and that's extremely annoying for Windows users.
'hide_cmd_windows': True
}),
('run',
{
'hide_cmd_windows': True,
'pdb_prevent_closing': True,
'pdb_ignore_lib': False,
'pdb_execute_events': True
}),
'pdb_execute_events': True,
'pdb_use_exclamation_mark': True,
'pdb_stop_first_line': True,
}),
('variable_explorer',
{
'check_all': CHECK_ALL,
Expand Down Expand Up @@ -640,4 +640,4 @@
# or if you want to *rename* options, then you need to do a MAJOR update in
# version, e.g. from 3.0.0 to 4.0.0
# 3. You don't need to touch this value if you're just adding a new option
CONF_VERSION = '59.0.0'
CONF_VERSION = '60.0.0'
32 changes: 3 additions & 29 deletions spyder/plugins/editor/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,18 +567,6 @@ def get_plugin_actions(self):
_('Clear breakpoints in all files'),
triggered=self.clear_all_breakpoints)

pdb_ignore_lib_action = create_action(
self, _("Ignore Python libraries while debugging"),
toggled=self.toggle_pdb_ignore_lib)
pdb_ignore_lib_action.setChecked(
CONF.get('run', 'pdb_ignore_lib'))

pdb_execute_events_action = create_action(
self, _("Process execute events while debugging"),
toggled=self.toggle_pdb_execute_events)
pdb_execute_events_action.setChecked(
CONF.get('run', 'pdb_execute_events'))

self.winpdb_action = create_action(self, _("Debug with winpdb"),
triggered=self.run_winpdb)
self.winpdb_action.setEnabled(WINPDB_PATH is not None and PY2)
Expand Down Expand Up @@ -1037,8 +1025,6 @@ def get_plugin_actions(self):
self.debug_continue_action,
self.debug_exit_action,
MENU_SEPARATOR,
pdb_ignore_lib_action,
pdb_execute_events_action,
set_clear_breakpoint_action,
set_cond_breakpoint_action,
clear_all_breakpoints_action,
Expand Down Expand Up @@ -1147,18 +1133,6 @@ def get_plugin_actions(self):

return self.file_dependent_actions

def toggle_pdb_ignore_lib(self, checked):
""""Set pdb_ignore_lib"""
CONF.set('run', 'pdb_ignore_lib', checked)
if self.main.ipyconsole is not None:
self.main.ipyconsole.set_pdb_ignore_lib()

def toggle_pdb_execute_events(self, checked):
""""Set pdb_execute_events"""
CONF.set('run', 'pdb_execute_events', checked)
if self.main.ipyconsole is not None:
self.main.ipyconsole.set_pdb_execute_events()

def update_pdb_state(self, state, last_step):
"""Enable/disable debugging actions and handle pdb state change."""
# Enable/disable actions taking into account debugging state:
Expand Down Expand Up @@ -2164,6 +2138,8 @@ def can_close_file(self, filename=None):
"""
Check if a file can be closed taking into account debugging state.
"""
if not CONF.get('ipython_console', 'pdb_prevent_closing'):
return True
debugging = self.main.ipyconsole.get_pdb_state()
last_pdb_step = self.main.ipyconsole.get_pdb_last_step()
can_close = True
Expand Down Expand Up @@ -2603,9 +2579,7 @@ def stop_debugging(self):
def debug_command(self, command):
"""Debug actions"""
self.switch_to_plugin()
self.main.ipyconsole.pdb_execute(
command, hidden=False, echo_stack_entry=False,
add_history=False)
self.main.ipyconsole.pdb_execute_command(command)
focus_widget = self.main.ipyconsole.get_focus_widget()
if focus_widget:
focus_widget.setFocus()
Expand Down
82 changes: 63 additions & 19 deletions spyder/plugins/ipythonconsole/confpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,23 +220,6 @@ def setup_page(self):
run_lines_layout.addWidget(run_lines_edit)
run_lines_group.setLayout(run_lines_layout)

# Pdb run lines Group
pdb_run_lines_group = QGroupBox(_("Run code while debugging"))
pdb_run_lines_label = QLabel(_(
"You can run several lines of code on each "
"new prompt while debugging. Please "
"introduce each one separated by semicolons "
"and a space, for example:<br>"
"<i>import matplotlib.pyplot as plt</i>"))
pdb_run_lines_label.setWordWrap(True)
pdb_run_lines_edit = self.create_lineedit(
_("Lines:"), 'startup/pdb_run_lines', '', alignment=Qt.Horizontal)

pdb_run_lines_layout = QVBoxLayout()
pdb_run_lines_layout.addWidget(pdb_run_lines_label)
pdb_run_lines_layout.addWidget(pdb_run_lines_edit)
pdb_run_lines_group.setLayout(pdb_run_lines_layout)

# Run file Group
run_file_group = QGroupBox(_("Run a file"))
run_file_label = QLabel(_("You can also run a whole file at startup "
Expand All @@ -255,6 +238,66 @@ def setup_page(self):
run_file_layout.addWidget(run_file_browser)
run_file_group.setLayout(run_file_layout)

# ---- Debug ----
# Pdb run lines Group
pdb_run_lines_group = QGroupBox(_("Run code while debugging"))
pdb_run_lines_label = QLabel(_(
"You can run several lines of code on each "
"new prompt while debugging. Please "
"introduce each one separated by semicolons "
"and a space, for example:<br>"
"<i>import matplotlib.pyplot as plt</i>"))
pdb_run_lines_label.setWordWrap(True)
pdb_run_lines_edit = self.create_lineedit(
_("Lines:"), 'startup/pdb_run_lines', '', alignment=Qt.Horizontal)

pdb_run_lines_layout = QVBoxLayout()
pdb_run_lines_layout.addWidget(pdb_run_lines_label)
pdb_run_lines_layout.addWidget(pdb_run_lines_edit)
pdb_run_lines_group.setLayout(pdb_run_lines_layout)

# Debug Group
debug_group = QGroupBox(_("Debug"))
debug_layout = QVBoxLayout()

prevent_closing_box = newcb(
_("Prevent editor from closing files while debugging"),
'pdb_prevent_closing',
tip=_("This option prevents the user from closing a file while"
" it is debugged."))
debug_layout.addWidget(prevent_closing_box)

continue_box = newcb(
_("Stop debugging on first line of files without breakpoints"),
'pdb_stop_first_line',
tip=_("This option lets you decide if the debugger should"
" stop on the first line while debugging if no breakpoints"
" are present."))
debug_layout.addWidget(continue_box)

libraries_box = newcb(
_("Ignore Python libraries while debugging"), 'pdb_ignore_lib',
tip=_("This option lets you decide if the debugger should "
"ignore the system libraries while debugging."))
debug_layout.addWidget(libraries_box)

execute_events_box = newcb(
_("Process execute events while debugging"), 'pdb_execute_events',
tip=_("This option lets you decide if the debugger should "
"process the 'execute events' after each prompt, such as "
"matplotlib 'show' command."))
debug_layout.addWidget(execute_events_box)

exclamation_mark_box = newcb(
_("Use exclamation mark prefix for Pdb commands"),
'pdb_use_exclamation_mark',
tip=_("This option lets you decide if the Pdb commands should "
"be prefixed by an exclamation mark. This helps in "
"separating Pdb commands from Python code."))
debug_layout.addWidget(exclamation_mark_box)

debug_group.setLayout(debug_layout)

# ---- Advanced settings ----
# Enable Jedi completion
jedi_group = QGroupBox(_("Jedi completion"))
Expand Down Expand Up @@ -391,9 +434,10 @@ def setup_page(self):
source_code_group), _("Display"))
tabs.addTab(self.create_tab(pylab_group, backend_group, inline_group),
_("Graphics"))
tabs.addTab(self.create_tab(run_lines_group, pdb_run_lines_group,
run_file_group),
tabs.addTab(self.create_tab(run_lines_group, run_file_group),
_("Startup"))
tabs.addTab(self.create_tab(debug_group, pdb_run_lines_group),
_("Debugger"))
tabs.addTab(self.create_tab(jedi_group, greedy_group, autocall_group,
sympy_group, prompts_group,
windows_group),
Expand Down
52 changes: 21 additions & 31 deletions spyder/plugins/ipythonconsole/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ def apply_plugin_settings(self, options):
reset_namespace_o = self.get_option(reset_namespace_n)
ask_before_restart_n = 'ask_before_restart'
ask_before_restart_o = self.get_option(ask_before_restart_n)
pdb_ignore_lib_n = 'pdb_ignore_lib'
pdb_ignore_lib_o = self.get_option(pdb_ignore_lib_n)
pdb_execute_events_n = 'pdb_execute_events'
pdb_execute_events_o = self.get_option(pdb_execute_events_n)
pdb_use_exclamation_mark_n = 'pdb_use_exclamation_mark'
pdb_use_exclamation_mark_o = self.get_option(
pdb_use_exclamation_mark_n)

for client in self.clients:
control = client.get_control()
if font_n in options:
Expand All @@ -276,6 +284,15 @@ def apply_plugin_settings(self, options):
client.reset_warning = reset_namespace_o
if ask_before_restart_n in options:
client.ask_before_restart = ask_before_restart_o
if pdb_ignore_lib_n in options:
client.shellwidget.set_pdb_ignore_lib(
pdb_ignore_lib_o)
if pdb_execute_events_n in options:
client.shellwidget.set_pdb_execute_events(
pdb_execute_events_o)
if pdb_use_exclamation_mark_n in options:
client.shellwidget.set_pdb_use_exclamation_mark(
pdb_use_exclamation_mark_o)

def toggle_view(self, checked):
"""Toggle view"""
Expand Down Expand Up @@ -665,32 +682,17 @@ def execute_code(self, lines, current_client=True, clear_variables=False):
self.activateWindow()
self.get_current_client().get_control().setFocus()

def pdb_execute(self, line, hidden=False, echo_stack_entry=False,
add_history=False):
def pdb_execute_command(self, command):
"""
Send line to the pdb kernel if possible.
Parameters
----------
line: str
the line to execute
hidden: bool
If the line should be hidden
echo_stack_entry: bool
If not hidden, if the stack entry should be printed
add_history: bool
If not hidden, wether the line should be added to history
Send command to the pdb kernel if possible.
"""

sw = self.get_current_shellwidget()
if sw is not None:
# Needed to handle an error when kernel_client is None.
# See spyder-ide/spyder#7578.
try:
sw.pdb_execute(line, hidden, echo_stack_entry, add_history)
sw.pdb_execute_command(command)
except AttributeError:
pass

Expand All @@ -701,9 +703,7 @@ def stop_debugging(self):
if not sw.is_waiting_pdb_input():
sw.interrupt_kernel()
try:
sw.pdb_execute(
"exit",
hidden=False, echo_stack_entry=False, add_history=False)
sw.pdb_execute_command("exit")
except AttributeError:
pass

Expand Down Expand Up @@ -1195,16 +1195,6 @@ def set_spyder_breakpoints(self):
for cl in self.clients:
cl.shellwidget.set_spyder_breakpoints()

def set_pdb_ignore_lib(self):
"""Set pdb_ignore_lib into all clients"""
for cl in self.clients:
cl.shellwidget.set_pdb_ignore_lib()

def set_pdb_execute_events(self):
"""Set pdb_execute_events into all clients"""
for cl in self.clients:
cl.shellwidget.set_pdb_execute_events()

@Slot(str)
def create_client_from_path(self, path):
"""Create a client with its cwd pointing to path."""
Expand Down

0 comments on commit c15d347

Please sign in to comment.