From 8f0636ecac2f13f02e55072467d38b5800d0c0d6 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sat, 4 Sep 2021 16:23:44 -0500 Subject: [PATCH 1/8] Icon manager: Remove unused imports and repeated entry --- spyder/utils/icon_manager.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spyder/utils/icon_manager.py b/spyder/utils/icon_manager.py index 8f9aa2cb225..19be9dc3f37 100644 --- a/spyder/utils/icon_manager.py +++ b/spyder/utils/icon_manager.py @@ -11,13 +11,12 @@ import sys # Third party imports -from qtpy.QtCore import QBuffer, QByteArray, Qt -from qtpy.QtGui import QIcon, QImage, QPixmap +from qtpy.QtCore import QBuffer, QByteArray +from qtpy.QtGui import QIcon, QImage from qtpy.QtWidgets import QStyle, QWidget # Local imports from spyder.config.manager import CONF -from spyder.config.gui import is_dark_interface from spyder.utils.image_path_manager import get_image_path from spyder.utils.encoding import is_text_file from spyder.utils.palette import QStylePalette, SpyderPalette @@ -292,7 +291,6 @@ def __init__(self): 'array': [('mdi.alpha-a-box',), {'color': SpyderPalette.GROUP_9, 'scale_factor': self.BIG_ATTR_FACTOR}], 'object': [('mdi.alpha-o-box',), {'color': SpyderPalette.ICON_5, 'scale_factor': self.BIG_ATTR_FACTOR}], 'key': [('mdi.alpha-k-box',), {'color': SpyderPalette.ICON_5, 'scale_factor': self.BIG_ATTR_FACTOR}], - 'class': [('mdi.alpha-c-box',), {'color': SpyderPalette.ICON_2, 'scale_factor': self.BIG_ATTR_FACTOR}], 'null': [('mdi.alpha-n-box',), {'color': SpyderPalette.GROUP_12, 'scale_factor': self.BIG_ATTR_FACTOR}], 'enum_member': [('mdi.alpha-e-box',), {'color': SpyderPalette.COLOR_ERROR_3, 'scale_factor': self.BIG_ATTR_FACTOR}], 'struct': [('mdi.alpha-s-box',), {'color': SpyderPalette.ICON_2, 'scale_factor': self.BIG_ATTR_FACTOR}], From 29d3516d6dfc117d4f9f8c39d5461fdafb5fa015 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sat, 4 Sep 2021 17:43:30 -0500 Subject: [PATCH 2/8] API: Set icon for toolbars extension button --- spyder/api/widgets/toolbars.py | 6 ++++++ spyder/utils/icon_manager.py | 1 + 2 files changed, 7 insertions(+) diff --git a/spyder/api/widgets/toolbars.py b/spyder/api/widgets/toolbars.py index 204cf824358..80e496a88a8 100644 --- a/spyder/api/widgets/toolbars.py +++ b/spyder/api/widgets/toolbars.py @@ -19,6 +19,7 @@ # Local imports from spyder.api.exceptions import SpyderAPIError +from spyder.utils.icon_manager import ima from spyder.utils.qthelpers import SpyderAction from spyder.utils.stylesheet import ( APP_TOOLBAR_STYLESHEET, PANES_TOOLBAR_STYLESHEET) @@ -72,6 +73,11 @@ def __init__(self, parent, title): self.setWindowTitle(title) + # Set icon for extension button. + # From https://stackoverflow.com/a/55412455/438386 + ext_button = self.findChild(QToolButton, "qt_toolbar_ext_button") + ext_button.setIcon(ima.icon('toolbar_ext_button')) + def add_item(self, action_or_widget: ToolbarItem, section: Optional[str] = None, before: Optional[str] = None, before_section: Optional[str] = None, omit_id: bool = False): diff --git a/spyder/utils/icon_manager.py b/spyder/utils/icon_manager.py index 19be9dc3f37..7e078c9f075 100644 --- a/spyder/utils/icon_manager.py +++ b/spyder/utils/icon_manager.py @@ -265,6 +265,7 @@ def __init__(self): '1downarrow': [('mdi.chevron-down',), {'color': self.MAIN_FG_COLOR}], 'undock': [('mdi.open-in-new',), {'color': self.MAIN_FG_COLOR}], 'close_pane': [('mdi.window-close',), {'color': self.MAIN_FG_COLOR}], + 'toolbar_ext_button': [('mdi.dots-vertical',), {'color': self.MAIN_FG_COLOR}], # --- Autocompletion/document symbol type icons -------------- 'keyword': [('mdi.alpha-k-box',), {'color': SpyderPalette.GROUP_9, 'scale_factor': self.BIG_ATTR_FACTOR}], 'color': [('mdi.alpha-c-box',), {'color': SpyderPalette.ICON_5, 'scale_factor': self.BIG_ATTR_FACTOR}], From f336e8732bc41f7b4e40ae10c368db28c4339203 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sat, 4 Sep 2021 17:52:22 -0500 Subject: [PATCH 3/8] API: Set size of toolbars extension button --- spyder/api/widgets/toolbars.py | 50 ++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/spyder/api/widgets/toolbars.py b/spyder/api/widgets/toolbars.py index 80e496a88a8..cf245dea02d 100644 --- a/spyder/api/widgets/toolbars.py +++ b/spyder/api/widgets/toolbars.py @@ -15,7 +15,8 @@ # Third part imports from qtpy.QtCore import QEvent, QObject, QSize, Qt -from qtpy.QtWidgets import QAction, QToolBar, QToolButton, QWidget +from qtpy.QtWidgets import ( + QAction, QProxyStyle, QStyle, QToolBar, QToolButton, QWidget) # Local imports from spyder.api.exceptions import SpyderAPIError @@ -30,14 +31,14 @@ ToolbarItemEntry = Tuple[ToolbarItem, Optional[str], Optional[str], Optional[str]] -# --- Constants +# ---- Constants # ---------------------------------------------------------------------------- class ToolbarLocation: Top = Qt.TopToolBarArea Bottom = Qt.BottomToolBarArea -# --- Event filters +# ---- Event filters # ---------------------------------------------------------------------------- class ToolTipFilter(QObject): """ @@ -54,7 +55,30 @@ def eventFilter(self, obj, event): return QObject.eventFilter(self, obj, event) -# --- Widgets +# ---- Styles +# ---------------------------------------------------------------------------- +class ToolbarStyle(QProxyStyle): + + # The toolbar type. This can be 'Application' or 'MainWidget' + TYPE = None + + def pixelMetric(self, pm, option, widget): + """ + Adjust size of toolbar extension button (in pixels). + + From https://stackoverflow.com/a/27042352/438386 + """ + if pm == QStyle.PM_ToolBarExtensionExtent: + if self.TYPE == 'Application': + return 30 + elif self.TYPE == 'MainWidget': + return 20 + else: + print("Unknown toolbar style type") + return super().pixelMetric(pm, option, widget) + + +# ---- Toolbars # ---------------------------------------------------------------------------- class SpyderToolbar(QToolBar): """ @@ -217,6 +241,11 @@ class ApplicationToolbar(SpyderToolbar): def __init__(self, parent, title): super().__init__(parent=parent, title=title) + + self._style = ToolbarStyle(None) + self._style.TYPE = 'Application' + self.setStyle(self._style) + self.setStyleSheet(str(APP_TOOLBAR_STYLESHEET)) @@ -245,7 +274,12 @@ def __init__(self, parent=None, title=None): self.setContextMenuPolicy(Qt.PreventContextMenu) self.setIconSize(self._icon_size) - self._setup_style() + self._style = ToolbarStyle(None) + self._style.TYPE = 'MainWidget' + self.setStyle(self._style) + + self.setStyleSheet(str(PANES_TOOLBAR_STYLESHEET)) + self._filter = ToolTipFilter() def set_icon_size(self, icon_size): @@ -288,9 +322,3 @@ def _render(self): if item.isCheckable(): widget.setCheckable(True) - - def _setup_style(self): - """ - Set the style of this toolbar with a stylesheet. - """ - self.setStyleSheet(str(PANES_TOOLBAR_STYLESHEET)) From feca275702bebac82c9b6c3537d5c93fe9405bd3 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sat, 4 Sep 2021 17:58:12 -0500 Subject: [PATCH 4/8] API: Add tooltip to toolbars extension button --- spyder/api/widgets/toolbars.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spyder/api/widgets/toolbars.py b/spyder/api/widgets/toolbars.py index cf245dea02d..a82581fb62e 100644 --- a/spyder/api/widgets/toolbars.py +++ b/spyder/api/widgets/toolbars.py @@ -20,12 +20,16 @@ # Local imports from spyder.api.exceptions import SpyderAPIError +from spyder.api.translations import get_translation from spyder.utils.icon_manager import ima from spyder.utils.qthelpers import SpyderAction from spyder.utils.stylesheet import ( APP_TOOLBAR_STYLESHEET, PANES_TOOLBAR_STYLESHEET) +# Translations +_ = get_translation('spyder') + # Generic type annotations ToolbarItem = Union[SpyderAction, QWidget] ToolbarItemEntry = Tuple[ToolbarItem, Optional[str], Optional[str], @@ -101,6 +105,7 @@ def __init__(self, parent, title): # From https://stackoverflow.com/a/55412455/438386 ext_button = self.findChild(QToolButton, "qt_toolbar_ext_button") ext_button.setIcon(ima.icon('toolbar_ext_button')) + ext_button.setToolTip(_("More")) def add_item(self, action_or_widget: ToolbarItem, section: Optional[str] = None, before: Optional[str] = None, From a547939639ad00e2b82aa1ab6e97e56f32621462 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sun, 12 Sep 2021 11:33:46 -0500 Subject: [PATCH 5/8] Add comment to skip print from tests --- spyder/api/widgets/toolbars.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyder/api/widgets/toolbars.py b/spyder/api/widgets/toolbars.py index a82581fb62e..c0bcddb9072 100644 --- a/spyder/api/widgets/toolbars.py +++ b/spyder/api/widgets/toolbars.py @@ -78,7 +78,7 @@ def pixelMetric(self, pm, option, widget): elif self.TYPE == 'MainWidget': return 20 else: - print("Unknown toolbar style type") + print("Unknown toolbar style type") # spyder: test-skip return super().pixelMetric(pm, option, widget) From 6c0a002891f9010050a228739dfdb9101dbc7e7f Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sun, 12 Sep 2021 11:51:17 -0500 Subject: [PATCH 6/8] API: Adjust toolbar extension button size to match the others --- spyder/api/widgets/toolbars.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spyder/api/widgets/toolbars.py b/spyder/api/widgets/toolbars.py index c0bcddb9072..e120b00eac5 100644 --- a/spyder/api/widgets/toolbars.py +++ b/spyder/api/widgets/toolbars.py @@ -72,11 +72,14 @@ def pixelMetric(self, pm, option, widget): From https://stackoverflow.com/a/27042352/438386 """ + # Important: These values need to be updated in case we change the size + # of our toolbar buttons in utils/stylesheet.py. That's because Qt only + # allow to set them in pixels here, not em's. if pm == QStyle.PM_ToolBarExtensionExtent: if self.TYPE == 'Application': - return 30 + return 57 elif self.TYPE == 'MainWidget': - return 20 + return 44 else: print("Unknown toolbar style type") # spyder: test-skip return super().pixelMetric(pm, option, widget) From 0227bc35d166d72c4ed4092ea441efa6b31e99bb Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sun, 12 Sep 2021 11:52:45 -0500 Subject: [PATCH 7/8] Use mdi.dots-horizontal for toolbar extension button This was suggested in review. --- spyder/utils/icon_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyder/utils/icon_manager.py b/spyder/utils/icon_manager.py index 7e078c9f075..49f543ea927 100644 --- a/spyder/utils/icon_manager.py +++ b/spyder/utils/icon_manager.py @@ -265,7 +265,7 @@ def __init__(self): '1downarrow': [('mdi.chevron-down',), {'color': self.MAIN_FG_COLOR}], 'undock': [('mdi.open-in-new',), {'color': self.MAIN_FG_COLOR}], 'close_pane': [('mdi.window-close',), {'color': self.MAIN_FG_COLOR}], - 'toolbar_ext_button': [('mdi.dots-vertical',), {'color': self.MAIN_FG_COLOR}], + 'toolbar_ext_button': [('mdi.dots-horizontal',), {'color': self.MAIN_FG_COLOR}], # --- Autocompletion/document symbol type icons -------------- 'keyword': [('mdi.alpha-k-box',), {'color': SpyderPalette.GROUP_9, 'scale_factor': self.BIG_ATTR_FACTOR}], 'color': [('mdi.alpha-c-box',), {'color': SpyderPalette.ICON_5, 'scale_factor': self.BIG_ATTR_FACTOR}], From 0cdee7f07c0f8c14e8f54d43820e6f7b02ef5968 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Tue, 14 Sep 2021 19:03:13 -0500 Subject: [PATCH 8/8] API: Adjust width of toolbar extension button according to OS --- spyder/api/widgets/toolbars.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/spyder/api/widgets/toolbars.py b/spyder/api/widgets/toolbars.py index e120b00eac5..8a87cf15727 100644 --- a/spyder/api/widgets/toolbars.py +++ b/spyder/api/widgets/toolbars.py @@ -9,9 +9,11 @@ """ # Standard library imports -import uuid from collections import OrderedDict +import os +import sys from typing import Union, Optional, Tuple, List, Dict +import uuid # Third part imports from qtpy.QtCore import QEvent, QObject, QSize, Qt @@ -77,9 +79,19 @@ def pixelMetric(self, pm, option, widget): # allow to set them in pixels here, not em's. if pm == QStyle.PM_ToolBarExtensionExtent: if self.TYPE == 'Application': - return 57 + if os.name == 'nt': + return 40 + elif sys.platform == 'darwin': + return 54 + else: + return 57 elif self.TYPE == 'MainWidget': - return 44 + if os.name == 'nt': + return 36 + elif sys.platform == 'darwin': + return 42 + else: + return 44 else: print("Unknown toolbar style type") # spyder: test-skip return super().pixelMetric(pm, option, widget)