Skip to content

Commit

Permalink
Merge from 3.x: PR #7694
Browse files Browse the repository at this point in the history
Fixes #7561
  • Loading branch information
ccordoba12 committed Aug 17, 2018
2 parents 943ad5b + a44635a commit 51891f0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
3 changes: 2 additions & 1 deletion spyder/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
{
Expand Down
18 changes: 16 additions & 2 deletions spyder/plugins/ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"))
Expand Down Expand Up @@ -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:
Expand All @@ -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"""
Expand Down Expand Up @@ -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(),
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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)
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 @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -477,15 +479,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

0 comments on commit 51891f0

Please sign in to comment.