diff --git a/spyder/config/main.py b/spyder/config/main.py index 939249a245d..3558d266595 100755 --- a/spyder/config/main.py +++ b/spyder/config/main.py @@ -169,7 +169,8 @@ 'symbolic_math': False, 'in_prompt': '', 'out_prompt': '', - 'show_elapsed_time': False + 'show_elapsed_time': False, + 'ask_before_restart': True }), ('variable_explorer', { diff --git a/spyder/plugins/ipythonconsole.py b/spyder/plugins/ipythonconsole.py index 0b85c5bce14..2a3d1a0d1b4 100644 --- a/spyder/plugins/ipythonconsole.py +++ b/spyder/plugins/ipythonconsole.py @@ -310,6 +310,11 @@ def setup_page(self): tip=_("This option lets you hide the warning message shown\n" "when resetting the namespace from Spyder.")) show_time_box = newcb(_("Show elapsed time"), 'show_elapsed_time') + ask_restart_box = newcb( + _("Ask for confirmation before restarting"), + 'ask_before_restart', + tip=_("This option lets you hide the warning message shown\n" + "when restarting the kernel.")) interface_layout = QVBoxLayout() interface_layout.addWidget(banner_box) @@ -318,6 +323,7 @@ def setup_page(self): interface_layout.addWidget(ask_box) interface_layout.addWidget(reset_namespace_box) interface_layout.addWidget(show_time_box) + interface_layout.addWidget(ask_restart_box) interface_group.setLayout(interface_layout) comp_group = QGroupBox(_("Completion Type")) @@ -739,6 +745,8 @@ def apply_plugin_settings(self, options): show_time_o = self.get_option(show_time_n) reset_namespace_n = 'show_reset_namespace_warning' 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) for client in self.clients: control = client.get_control() if font_n in options: @@ -752,6 +760,8 @@ def apply_plugin_settings(self, options): client.set_elapsed_time_visible(show_time_o) if reset_namespace_n in options: client.reset_warning = reset_namespace_o + if ask_before_restart_n in options: + client.ask_before_restart = ask_before_restart_o def toggle_view(self, checked): """Toggle view""" @@ -1079,6 +1089,7 @@ def create_new_client(self, give_focus=True, filename='', is_cython=False, cf = self._new_connection_file() show_elapsed_time = self.get_option('show_elapsed_time') reset_warning = self.get_option('show_reset_namespace_warning') + ask_before_restart = self.get_option('ask_before_restart') client = ClientWidget(self, id_=client_id, history_filename=get_conf_path('history.py'), config_options=self.config_options(), @@ -1091,7 +1102,8 @@ def create_new_client(self, give_focus=True, filename='', is_cython=False, options_button=self.options_button, show_elapsed_time=show_elapsed_time, reset_warning=reset_warning, - given_name=given_name) + given_name=given_name, + ask_before_restart=ask_before_restart) if self.testing: client.stderr_dir = self.test_dir self.add_tab(client, name=client.get_name(), filename=filename) @@ -1822,6 +1834,7 @@ def _create_client_for_kernel(self, connection_file, hostname, sshkey, # Creating the client show_elapsed_time = self.get_option('show_elapsed_time') reset_warning = self.get_option('show_reset_namespace_warning') + ask_before_restart = self.get_option('ask_before_restart') client = ClientWidget(self, id_=client_id, given_name=given_name, @@ -1835,7 +1848,8 @@ def _create_client_for_kernel(self, connection_file, hostname, sshkey, external_kernel=external_kernel, slave=True, show_elapsed_time=show_elapsed_time, - reset_warning=reset_warning) + reset_warning=reset_warning, + ask_before_restart=ask_before_restart) # Create kernel client kernel_client = QtKernelClient(connection_file=connection_file) diff --git a/spyder/widgets/ipythonconsole/client.py b/spyder/widgets/ipythonconsole/client.py index 0fea9f46f70..7fdd2ff53a7 100644 --- a/spyder/widgets/ipythonconsole/client.py +++ b/spyder/widgets/ipythonconsole/client.py @@ -103,7 +103,8 @@ def __init__(self, plugin, id_, external_kernel=False, given_name=None, options_button=None, show_elapsed_time=False, - reset_warning=True): + reset_warning=True, + ask_before_restart=True): super(ClientWidget, self).__init__(plugin) SaveHistoryMixin.__init__(self, history_filename) @@ -117,6 +118,7 @@ def __init__(self, plugin, id_, self.given_name = given_name self.show_elapsed_time = show_elapsed_time self.reset_warning = reset_warning + self.ask_before_restart = ask_before_restart # --- Other attrs self.options_button = options_button @@ -477,7 +479,7 @@ def restart_kernel(self): """ sw = self.shellwidget - if not running_under_pytest(): + if not running_under_pytest() and self.ask_before_restart: message = _('Are you sure you want to restart the kernel?') buttons = QMessageBox.Yes | QMessageBox.No result = QMessageBox.question(self, _('Restart kernel?'), @@ -485,7 +487,9 @@ def restart_kernel(self): else: result = None - if result == QMessageBox.Yes or running_under_pytest(): + if (result == QMessageBox.Yes or + running_under_pytest() or + not self.ask_before_restart): if sw.kernel_manager: if self.infowidget.isVisible(): self.infowidget.hide()