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: Make "Are you sure you want to restart the kernel?" warning optional #7694

Merged
merged 2 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion spyder/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@
'symbolic_math': False,
'in_prompt': '',
'out_prompt': '',
'show_elapsed_time': False
'show_elapsed_time': False,
'ask_before_restart': True
}),
('variable_explorer',
{
Expand Down
18 changes: 16 additions & 2 deletions spyder/plugins/ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,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)
Expand All @@ -319,6 +324,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"))
Expand Down Expand Up @@ -741,6 +747,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:
Expand All @@ -754,6 +762,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"""
Expand Down Expand Up @@ -1053,6 +1063,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(),
Expand All @@ -1061,7 +1072,8 @@ def create_new_client(self, give_focus=True, filename='', is_cython=False):
connection_file=cf,
menu_actions=self.menu_actions,
show_elapsed_time=show_elapsed_time,
reset_warning=reset_warning)
reset_warning=reset_warning,
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)
Expand Down Expand Up @@ -1761,6 +1773,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,
Expand All @@ -1774,7 +1787,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)
Expand Down
10 changes: 7 additions & 3 deletions spyder/widgets/ipythonconsole/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def __init__(self, plugin, id_,
menu_actions=None, slave=False,
external_kernel=False, given_name=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)

Expand All @@ -116,6 +117,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 = None
Expand Down Expand Up @@ -473,15 +475,17 @@ 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?'),
message, buttons)
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()
Expand Down