diff --git a/spyder/plugins/ipythonconsole/widgets/main_widget.py b/spyder/plugins/ipythonconsole/widgets/main_widget.py index 483ca4c1d1c..2deb32e9dad 100644 --- a/spyder/plugins/ipythonconsole/widgets/main_widget.py +++ b/spyder/plugins/ipythonconsole/widgets/main_widget.py @@ -315,7 +315,8 @@ def __init__(self, name=None, plugin=None, parent=None, # a crash when the console is detached from the main window # Fixes spyder-ide/spyder#561. self.tabwidget.setDocumentMode(True) - self.tabwidget.currentChanged.connect(self.refresh_container) + self.tabwidget.currentChanged.connect( + lambda idx: self.refresh_container(give_focus=True)) self.tabwidget.tabBar().tabMoved.connect(self.move_tab) self.tabwidget.tabBar().sig_name_changed.connect( self.rename_tabs_after_change) @@ -772,11 +773,16 @@ def change_clients_pdb_use_exclamation_mark(self, value): value) @on_conf_change(option=[ + 'symbolic_math', 'hide_cmd_windows', 'startup/run_lines', 'startup/use_run_file', 'startup/run_file', - 'pylab', 'pylab/backend', 'symbolic_math', 'hide_cmd_windows']) + 'pylab', 'pylab/backend']) def change_possible_restart_conf(self, option, value): """Apply options that possibly require a kernel restart.""" - if not self.get_current_client(): + # Check that we are not triggering validations in the initial + # notification sent when Spyder is starting or when another option + # already required a restart and the restart dialog was shown + if option in self.initial_conf_options: + self.initial_conf_options.remove(option) return restart_needed = False @@ -797,31 +803,25 @@ def change_possible_restart_conf(self, option, value): restart_options += [run_lines_n, use_run_file_n, run_file_n, symbolic_math_n, hide_cmd_windows_n] + restart_needed = option in restart_options inline_backend = 0 pylab_restart = False client_backend_not_inline = [False] * len(self.clients) - if pylab_o and pylab_backend_n == option: + current_client = self.get_current_client() + current_client_backend_not_inline = False + if pylab_o and pylab_backend_n == option and current_client: pylab_backend_o = self.get_conf(pylab_backend_n) client_backend_not_inline = [ client.shellwidget.get_matplotlib_backend() != inline_backend for client in self.clients] current_client_backend_not_inline = ( - self.get_current_client().shellwidget.get_matplotlib_backend() + current_client.shellwidget.get_matplotlib_backend() != inline_backend) pylab_restart = ( any(client_backend_not_inline) and pylab_backend_o != inline_backend) - # Check that we are not triggering validations in the initial - # notification sent when Spyder is starting or when another option - # already required a restart and the restart dialog was shown - if option in self.initial_conf_options: - self.initial_conf_options.remove(option) - restart_needed = False - else: - restart_needed = option in restart_options - if (restart_needed or pylab_restart) and not running_under_pytest(): self.initial_conf_options = self.get_conf_options() self.initial_conf_options.remove(option) @@ -858,8 +858,7 @@ def change_client_mpl_conf(o=options, c=client): client.ask_before_restart = current_ask_before_restart if (((pylab_restart and current_client_backend_not_inline) - or restart_needed) and restart_current): - current_client = self.get_current_client() + or restart_needed) and restart_current and current_client): current_client_ask_before_restart = ( current_client.ask_before_restart) current_client.ask_before_restart = False @@ -1164,7 +1163,7 @@ def update_font(self, font, rich_font): for client in self.clients: client.set_font(font) - def refresh_container(self): + def refresh_container(self, give_focus=False): """ Refresh interface depending on the current widget client available. @@ -1192,9 +1191,11 @@ def refresh_container(self): self.infowidget.hide() client.shellwidget.show() - # Give focus to the control widget of the selected tab + # Get reference for the control widget of the selected tab + # and give focus if needed control = client.get_control() - control.setFocus() + if give_focus: + control.setFocus() if isinstance(control, PageControlWidget): self.pager_label.show()