Skip to content

Commit

Permalink
IPython console: Fix resetting variables after clicking on the reset …
Browse files Browse the repository at this point in the history
…button
  • Loading branch information
ccordoba12 committed Jul 14, 2021
1 parent 210a37a commit a8a6d9b
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions spyder/plugins/ipythonconsole/widgets/shell.py
Expand Up @@ -453,23 +453,14 @@ def _reset_namespace(self):

def reset_namespace(self, warning=False, message=False):
"""Reset the namespace by removing all names defined by the user."""
reset_str = _("Remove all variables")
warn_str = _("All user-defined variables will be removed. "
"Are you sure you want to proceed?")

# Don't show the warning when running our tests.
if running_under_pytest():
warning = False

# This is necessary to make resetting variables work in external
# kernels.
# See spyder-ide/spyder#9505.
try:
kernel_env = self.kernel_manager._kernel_spec.env
except AttributeError:
kernel_env = {}

if warning:
reset_str = _("Remove all variables")
warn_str = _("All user-defined variables will be removed. "
"Are you sure you want to proceed?")
box = MessageCheckBox(icon=QMessageBox.Warning, parent=self)
box.setWindowTitle(reset_str)
box.set_checkbox_text(_("Don't show again."))
Expand All @@ -479,16 +470,40 @@ def reset_namespace(self, warning=False, message=False):
box.set_checked(False)
box.set_check_visible(True)
box.setText(warn_str)
box.accepted.connect(lambda: self._perform_reset(message, box))
box.show()
else:
self._perform_reset(message)

answer = box.show()
def _perform_reset(self, message, message_box=None):
"""
Perform the reset namespace operation.
# Update checkbox based on user interaction
Parameters
----------
message: bool
Whether to show a message in the console telling users the
namespace was reset.
message_box: MessageCheckBox
Instance of the message box shown to the user telling them
that a reset is going to take place.
"""
# Update options and variables based on user interaction in the
# warning message box, if it was shown to the user.
if message_box is not None:
self.set_conf(
'show_reset_namespace_warning', not box.is_checked())
self.ipyclient.reset_warning = not box.is_checked()
'show_reset_namespace_warning',
not message_box.is_checked()
)
self.ipyclient.reset_warning = not message_box.is_checked()

if answer != QMessageBox.Yes:
return
# This is necessary to make resetting variables work in external
# kernels.
# See spyder-ide/spyder#9505.
try:
kernel_env = self.kernel_manager._kernel_spec.env
except AttributeError:
kernel_env = {}

try:
if self.is_waiting_pdb_input():
Expand Down

0 comments on commit a8a6d9b

Please sign in to comment.