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: Unify UI of editors in Variable Explorer and simplify code #21666

Merged
merged 21 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9f65183
Change SpyderWidgetMixin.create_toolbar() to create a SpyderToolbar
jitseniesen Dec 9, 2023
7d76a88
Add `register` parameter to SpyderWidgetMixin.create_xxx()
jitseniesen Dec 9, 2023
0f8ad73
Make SpyderWidgetMixin inherit from SpyderToolbarMixin
jitseniesen Dec 9, 2023
c2e437c
Use SpyderWidgetMixin.create_menu in Variable Explorer editors
jitseniesen Dec 10, 2023
ed9989a
Use SpyderWidgetMixin.create_toolbar in Variable Explorer editors
jitseniesen Dec 9, 2023
4472b0b
Use SpyderWidgetMixin.create_action in Variable Explorer editors
jitseniesen Dec 18, 2023
7424676
Simplify implementation of "Show xxx attributes" in object explorer
jitseniesen Dec 23, 2023
687ee11
Change layout of editor windows in Variable Explorer
jitseniesen Dec 24, 2023
d0be94a
Explicitly pass actions from editors to toolbar
jitseniesen Dec 26, 2023
e9412a7
Move Refresh and Resize to front of toolbars
jitseniesen Dec 26, 2023
8b16c69
Remove Refresh and Resize actions from context menus
jitseniesen Dec 26, 2023
c831f81
Move refresh_action from dataframe view to editor widget
jitseniesen Dec 26, 2023
4130a68
Rename "Save array" as "Save" and remove from toolbar
jitseniesen Dec 26, 2023
3822061
Remove Edit, Copy, Paste, Rename from toolbars
jitseniesen Dec 26, 2023
8f9f199
Reorder items in context menus and toolbars
jitseniesen Dec 26, 2023
54686b7
Remove buttons in lower left of dataframe editor window
jitseniesen Dec 26, 2023
65944e4
Change default value of new parameter in create_toolbutton()
jitseniesen Jan 3, 2024
c0a1cd1
Eliminate warnings in array editor
jitseniesen Jan 3, 2024
2d765ee
Move toolbar buttons in Variable Explorer and its editors
jitseniesen Jan 28, 2024
2a61b45
Move buttons in Variable Explorer and its editors again
jitseniesen Feb 8, 2024
b2cb5c4
Use SpyderWidgetMixin API to build toolbars and menus
jitseniesen Feb 11, 2024
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
2 changes: 1 addition & 1 deletion spyder/api/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def __init__(self, name, plugin, parent=None):
parent=self,
title=_("Main widget corner toolbar"),
)
self._corner_toolbar.ID = 'corner_toolbar',
self._corner_toolbar.ID = 'corner_toolbar'

TOOLBAR_REGISTRY.register_reference(
self._corner_toolbar, self._corner_toolbar.ID,
Expand Down
68 changes: 42 additions & 26 deletions spyder/api/widgets/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
)
from spyder.api.exceptions import SpyderAPIError
from spyder.api.widgets.menus import SpyderMenu
from spyder.api.widgets.toolbars import SpyderToolbar
from spyder.config.manager import CONF
from spyder.utils.icon_manager import ima
from spyder.utils.image_path_manager import get_image_path
from spyder.utils.qthelpers import create_action, create_toolbutton
from spyder.utils.registries import (
ACTION_REGISTRY, MENU_REGISTRY, TOOLBAR_REGISTRY, TOOLBUTTON_REGISTRY)
from spyder.utils.stylesheet import PANES_TOOLBAR_STYLESHEET


class SpyderToolButtonMixin:
Expand All @@ -46,7 +48,7 @@ class SpyderToolButtonMixin:
def create_toolbutton(self, name, text=None, icon=None,
tip=None, toggled=None, triggered=None,
autoraise=True, text_beside_icon=False,
section=None, option=None):
section=None, option=None, register=True):
"""
Create a Spyder toolbutton.
"""
Expand All @@ -72,7 +74,7 @@ def create_toolbutton(self, name, text=None, icon=None,
id_=name,
plugin=self.PLUGIN_NAME,
context_name=self.CONTEXT_NAME,
register_toolbutton=True
register_toolbutton=register
)
toolbutton.name = name

Expand Down Expand Up @@ -166,13 +168,23 @@ def create_stretcher(self, id_=None):
stretcher.ID = id_
return stretcher

def create_toolbar(self, name: str) -> QToolBar:
def create_toolbar(self, name: str,
register: bool = True) -> SpyderToolbar:
ccordoba12 marked this conversation as resolved.
Show resolved Hide resolved
"""
Create a Spyder toolbar.
"""
toolbar = QToolBar(self)
TOOLBAR_REGISTRY.register_reference(
toolbar, name, self.PLUGIN_NAME, self.CONTEXT_NAME)

Parameters
----------
name: str
Name of the toolbar to create.
register: bool
Whether to register the toolbar in the global registry.
"""
toolbar = SpyderToolbar(self, name)
toolbar.setStyleSheet(str(PANES_TOOLBAR_STYLESHEET))
if register:
TOOLBAR_REGISTRY.register_reference(
toolbar, name, self.PLUGIN_NAME, self.CONTEXT_NAME)
ccordoba12 marked this conversation as resolved.
Show resolved Hide resolved
return toolbar

def get_toolbar(self, name: str, context: Optional[str] = None,
Expand Down Expand Up @@ -255,6 +267,7 @@ def _create_menu(
title: Optional[str] = None,
icon: Optional[QIcon] = None,
reposition: Optional[bool] = True,
register: bool = True,
MenuClass=SpyderMenu
) -> SpyderMenu:
"""
Expand All @@ -266,14 +279,15 @@ def _create_menu(
subclass of SpyderMenu.
* Refer to the documentation for `create_menu` to learn about its args.
"""
menus = getattr(self, '_menus', None)
if menus is None:
self._menus = OrderedDict()
if register:
menus = getattr(self, '_menus', None)
if menus is None:
self._menus = OrderedDict()

if menu_id in self._menus:
raise SpyderAPIError(
'Menu name "{}" already in use!'.format(menu_id)
)
if menu_id in self._menus:
raise SpyderAPIError(
'Menu name "{}" already in use!'.format(menu_id)
)

menu = MenuClass(
parent=self,
Expand All @@ -286,11 +300,12 @@ def _create_menu(
menu.menuAction().setIconVisibleInMenu(True)
menu.setIcon(icon)

MENU_REGISTRY.register_reference(
menu, menu_id, self.PLUGIN_NAME, self.CONTEXT_NAME
)
if register:
MENU_REGISTRY.register_reference(
menu, menu_id, self.PLUGIN_NAME, self.CONTEXT_NAME
)
self._menus[menu_id] = menu

self._menus[menu_id] = menu
return menu

def create_menu(
Expand All @@ -299,6 +314,7 @@ def create_menu(
title: Optional[str] = None,
icon: Optional[QIcon] = None,
reposition: Optional[bool] = True,
register: bool = True
) -> SpyderMenu:
"""
Create a menu for Spyder.
Expand All @@ -312,7 +328,9 @@ def create_menu(
icon: QIcon or None
Icon to use for the menu.
reposition: bool, optional (default True)
Whether to vertically reposition the menu due to it's padding.
Whether to vertically reposition the menu due to its padding.
register: bool
Whether to register the menu in the global registry.

Returns
-------
Expand All @@ -323,7 +341,8 @@ def create_menu(
menu_id=menu_id,
title=title,
icon=icon,
reposition=reposition
reposition=reposition,
register=register
)

def get_menu(
Expand Down Expand Up @@ -620,15 +639,12 @@ def update_actions(self, options):
raise NotImplementedError('')


class SpyderWidgetMixin(SpyderActionMixin, SpyderMenuMixin,
SpyderConfigurationObserver, SpyderToolButtonMixin):
class SpyderWidgetMixin(SpyderActionMixin, SpyderConfigurationObserver,
SpyderMenuMixin, SpyderToolbarMixin,
SpyderToolButtonMixin):
"""
Basic functionality for all Spyder widgets and Qt items.

This mixin does not include toolbar handling as that is limited to the
application with the coreui plugin or the PluginMainWidget for dockable
plugins.

This provides a simple management of widget options, as well as Qt helpers
for defining the actions a widget provides.
"""
Expand Down
Loading
Loading