Skip to content

Commit 18e709c

Browse files
committed
Disable action to create new console in an environment that is installing spyder-kernels.
Note that setIconVisibleInMenu(False) at SpyderAction instantiation results in the environment menu item not reflecting its enabled state in the menubar. Removing this, or setting it to True (QAction defaults to True), produces the correct behavior. Also note that menubar items still do not show the icon for macOS (as desired) because setIconVisibleInMenu is called in set_menu_icons.
1 parent 573016c commit 18e709c

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

spyder/plugins/ipythonconsole/utils/kernelspec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ def argv(self):
121121
if self.path_to_custom_interpreter:
122122
pyexec = self.path_to_custom_interpreter
123123

124-
has_spyder_kernels(pyexec)
125-
126124
if not is_python_interpreter(pyexec):
127125
pyexec = get_python_executable()
128126
self.set_conf('executable', '', section='main_interpreter')
129127
self.set_conf('default', True, section='main_interpreter')
130128
self.set_conf('custom', False, section='main_interpreter')
131129

130+
has_spyder_kernels(pyexec)
131+
132132
# Command used to start kernels
133133
kernel_cmd = []
134134

spyder/plugins/ipythonconsole/widgets/client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def __init__(
180180
self.kernel_loading_page = self._create_loading_page()
181181
self.env_loading_page = self._create_loading_page(kind="env")
182182
self.spyk_installing_page = self._create_loading_page(kind="install")
183+
self._pyexec = None
183184

184185
if self.is_remote():
185186
# Keep a reference
@@ -404,7 +405,8 @@ def _set_initial_cwd_in_kernel(self):
404405

405406
@Slot()
406407
def _install_spyder_kernels(self, pyexec):
407-
# TODO: Disable create new client with same environment
408+
self._pyexec = pyexec
409+
self.container.environment_menu_item_state(pyexec, enable=False)
408410

409411
# Store existing error page for reuse later, if necessary
410412
self.installwidget.info_page = self.info_page
@@ -562,7 +564,10 @@ def stop_button_click_handler(self):
562564
self.shellwidget.pdb_execute_command('exit')
563565

564566
def process_kernel_install(self, exit_code, exit_status, output=None):
565-
# TODO: Re-enable create new client with same environment
567+
if self._pyexec:
568+
self.container.environment_menu_item_state(
569+
self._pyexec, enable=True
570+
)
566571

567572
if exit_code == 0 and exit_status == 0:
568573
# Success!

spyder/plugins/ipythonconsole/widgets/main_widget.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def __init__(self, name=None, plugin=None, parent=None):
304304
self.interrupt_action = None
305305
self.registered_spyder_kernel_handlers = {}
306306
self.envs = {}
307+
self._envs_disabled = set()
307308

308309
# Attributes needed for the restart dialog
309310
self._restart_dialog = ConsoleRestartDialog(self)
@@ -1314,6 +1315,9 @@ def _update_environment_menu(self):
13141315
tip=text,
13151316
)
13161317

1318+
# Disable action for environments while installing spyder-kernels
1319+
action.setEnabled(path_to_interpreter not in self._envs_disabled)
1320+
13171321
# Add default env as the first entry in the menu
13181322
if text.startswith(_("Default")):
13191323
self.add_item_to_menu(
@@ -1578,6 +1582,19 @@ def infowidget(self):
15781582
except AttributeError:
15791583
return None
15801584

1585+
def environment_menu_item_state(self, pyexec, enable=False):
1586+
if enable and pyexec in self._envs_disabled:
1587+
self._envs_disabled.remove(pyexec)
1588+
elif not enable:
1589+
self._envs_disabled.add(pyexec)
1590+
1591+
default_interpreter = self.get_conf(
1592+
"executable", section="main_interpreter"
1593+
)
1594+
self.create_client_action.setEnabled(
1595+
default_interpreter not in self._envs_disabled
1596+
)
1597+
15811598
# ---- General
15821599
# -------------------------------------------------------------------------
15831600
def update_edit_menu(self) -> None:

spyder/utils/qthelpers.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,6 @@ def __init__(self, *args, action_id=None, **kwargs):
612612
"""Spyder QAction class wrapper to handle cross platform patches."""
613613
super().__init__(*args, **kwargs)
614614
self.action_id = action_id
615-
if sys.platform == "darwin":
616-
self.setIconVisibleInMenu(False)
617615

618616
def __str__(self):
619617
return "SpyderAction('{0}')".format(self.text())

0 commit comments

Comments
 (0)