Skip to content

Commit

Permalink
IPython console: Unify all its menus under a single enum
Browse files Browse the repository at this point in the history
- That enum is IPythonConsoleWidgetMenus.
- That's because several menus are placed in different places, not only
in the console options menu.
  • Loading branch information
ccordoba12 committed Nov 13, 2023
1 parent c9599af commit 8c6e4bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
9 changes: 3 additions & 6 deletions spyder/plugins/ipythonconsole/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,19 @@ class IPythonConsoleWidgetActions:
QuickReference = 'quick reference'


class IPythonConsoleWidgetOptionsMenus:
class IPythonConsoleWidgetMenus:
SpecialConsoles = 'special_consoles_submenu'
Documentation = 'documentation_submenu'
EnvironmentConsoles = 'environment_consoles_submenu'
ClientContextMenu = 'client_context_menu'
TabsContextMenu = 'tabs_context_menu'


class IPythonConsoleWidgetOptionsMenuSections:
Edit = 'edit_section'
View = 'view_section'


class IPythonConsoleWidgetMenus:
ClientContextMenu = 'client_context_menu'
TabsContextMenu = 'tabs_context_menu'


class IPythonConsoleWidgetTabsContextMenuSections:
Consoles = 'tabs_consoles_section'
Edit = 'tabs_edit_section'
Expand Down
10 changes: 7 additions & 3 deletions spyder/plugins/ipythonconsole/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
from spyder.api.plugin_registration.decorators import (
on_plugin_available, on_plugin_teardown)
from spyder.api.translations import _
from spyder.plugins.ipythonconsole.api import IPythonConsolePyConfiguration
from spyder.plugins.ipythonconsole.api import (
IPythonConsolePyConfiguration,
IPythonConsoleWidgetMenus
)
from spyder.plugins.ipythonconsole.confpage import IPythonConsoleConfigPage
from spyder.plugins.ipythonconsole.widgets.config import IPythonConfigOptions
from spyder.plugins.ipythonconsole.widgets.main_widget import (
IPythonConsoleWidget, IPythonConsoleWidgetOptionsMenus)
IPythonConsoleWidget
)
from spyder.plugins.mainmenu.api import (
ApplicationMenus, ConsolesMenuSections, HelpMenuSections)
from spyder.plugins.run.api import (
Expand Down Expand Up @@ -424,7 +428,7 @@ def on_main_menu_teardown(self):

# IPython documentation menu
mainmenu.remove_item_from_application_menu(
IPythonConsoleWidgetOptionsMenus.Documentation,
IPythonConsoleWidgetMenus.Documentation,
menu_id=ApplicationMenus.Help
)

Expand Down
15 changes: 9 additions & 6 deletions spyder/plugins/ipythonconsole/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@
from spyder.api.widgets.main_widget import PluginMainWidget
from spyder.config.base import get_home_dir, running_under_pytest
from spyder.plugins.ipythonconsole.api import (
IPythonConsoleWidgetActions, IPythonConsoleWidgetMenus,
IPythonConsoleWidgetOptionsMenus, IPythonConsoleWidgetOptionsMenuSections,
IPythonConsoleWidgetTabsContextMenuSections, ClientContextMenuActions)
ClientContextMenuActions,
IPythonConsoleWidgetActions,
IPythonConsoleWidgetMenus,
IPythonConsoleWidgetOptionsMenuSections,
IPythonConsoleWidgetTabsContextMenuSections
)
from spyder.plugins.ipythonconsole.utils.kernel_handler import KernelHandler
from spyder.plugins.ipythonconsole.utils.kernelspec import SpyderKernelSpec
from spyder.plugins.ipythonconsole.utils.style import create_qss_style
Expand Down Expand Up @@ -543,15 +546,15 @@ def setup(self):
options_menu = self.get_options_menu()

self.console_environment_menu = self.create_menu(
IPythonConsoleWidgetOptionsMenus.EnvironmentConsoles,
IPythonConsoleWidgetMenus.EnvironmentConsoles,
_('New console in environment')
)
stylesheet = qstylizer.style.StyleSheet()
stylesheet["QMenu"]["menu-scrollable"].setValue("1")
self.console_environment_menu.setStyleSheet(stylesheet.toString())

self.special_console_menu = self.create_menu(
IPythonConsoleWidgetOptionsMenus.SpecialConsoles,
IPythonConsoleWidgetMenus.SpecialConsoles,
_('New special console'))

for item in [
Expand Down Expand Up @@ -658,7 +661,7 @@ def setup(self):

# --- Create IPython documentation menu
self.ipython_menu = self.create_menu(
menu_id=IPythonConsoleWidgetOptionsMenus.Documentation,
menu_id=IPythonConsoleWidgetMenus.Documentation,
title=_("IPython documentation"))
intro_action = self.create_action(
IPythonConsoleWidgetActions.IPythonDocumentation,
Expand Down

0 comments on commit 8c6e4bd

Please sign in to comment.