Skip to content

Commit

Permalink
Replace most usages of QMenu by SpyderMenu
Browse files Browse the repository at this point in the history
- That allows to use our customizations for menus all over the
application.
- I only left the editor menus untouched because that's going to be
addressed when it's migrated to the new API.
  • Loading branch information
ccordoba12 committed Nov 21, 2023
1 parent cae75b3 commit 5581408
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 33 deletions.
1 change: 0 additions & 1 deletion spyder/api/widgets/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"""

# Standard library imports
import os
import sys
from typing import Optional, Union, TypeVar

Expand Down
5 changes: 2 additions & 3 deletions spyder/plugins/application/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@

# Third party imports
from qtpy.QtCore import Slot
from qtpy.QtWidgets import QMenu

# Local imports
from spyder.api.plugins import Plugins, SpyderPluginV2
from spyder.api.translations import _
from spyder.api.plugin_registration.decorators import (
on_plugin_available, on_plugin_teardown)
from spyder.api.widgets.menus import MENU_SEPARATOR
from spyder.api.widgets.menus import SpyderMenu, MENU_SEPARATOR
from spyder.config.base import (DEV, get_module_path, get_debug_level,
running_under_pytest)
from spyder.plugins.application.confpage import ApplicationConfigPage
Expand Down Expand Up @@ -305,7 +304,7 @@ def get_application_context_menu(self, parent=None):

help_plugin = self.get_plugin(Plugins.Help)
shortcuts = self.get_plugin(Plugins.Shortcuts)
menu = QMenu(parent=parent)
menu = SpyderMenu(parent=parent)
actions = [self.documentation_action]
# Help actions
if help_plugin:
Expand Down
5 changes: 3 additions & 2 deletions spyder/plugins/application/widgets/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

# Third party imports
from qtpy.QtCore import QPoint, Qt, Signal, Slot
from qtpy.QtWidgets import QMenu, QLabel
from qtpy.QtWidgets import QLabel

# Local imports
from spyder.api.translations import _
from spyder.api.widgets.menus import SpyderMenu
from spyder.api.widgets.status import StatusBarWidget
from spyder.config.base import is_conda_based_app
from spyder.plugins.application.widgets.install import (
Expand Down Expand Up @@ -62,7 +63,7 @@ def __init__(self, parent):
self.installer = UpdateInstallerDialog(self)

# Check for updates action menu
self.menu = QMenu(self)
self.menu = SpyderMenu(self)

# Set aligment attributes for custom widget to match default label
# values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

# Third party imports
from qtpy.QtCore import QPoint, Slot
from qtpy.QtWidgets import QMenu

# Local imports
from spyder.api.widgets.menus import SpyderMenu
from spyder.api.widgets.status import StatusBarWidget
from spyder.config.base import _
from spyder.utils.qthelpers import add_actions, create_action
Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(self, parent, provider):

self.provider = provider
self.current_language = None
self.menu = QMenu(self)
self.menu = SpyderMenu(self)

# Setup
self.set_status(status=ClientStatus.STARTING)
Expand Down
4 changes: 2 additions & 2 deletions spyder/plugins/completion/widgets/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

# Third party imports
from qtpy.QtCore import QPoint, Signal
from qtpy.QtWidgets import QMenu

# Local imports
from spyder.api.widgets.menus import SpyderMenu
from spyder.api.translations import _
from spyder.api.widgets.status import StatusBarWidget
from spyder.utils.qthelpers import add_actions, create_action
Expand All @@ -36,7 +36,7 @@ def __init__(self, parent, icon=None):
self.main = parent
self.value = ''

self.menu = QMenu(self)
self.menu = SpyderMenu(self)
self.sig_clicked.connect(self.show_menu)

def update_status(self, value, tool_tip):
Expand Down
5 changes: 3 additions & 2 deletions spyder/plugins/console/widgets/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
from qtpy.compat import getsavefilename
from qtpy.QtCore import Property, Qt, QTimer, Signal, Slot
from qtpy.QtGui import QKeySequence, QTextCharFormat, QTextCursor
from qtpy.QtWidgets import QApplication, QMenu
from qtpy.QtWidgets import QApplication

# Local import
from spyder.api.widgets.menus import SpyderMenu
from spyder.config.base import _, get_conf_path, get_debug_level, STDERR
from spyder.config.manager import CONF
from spyder.py3compat import is_string, is_text_string, to_text_string
Expand Down Expand Up @@ -123,7 +124,7 @@ def set_font(self, font):
#------ Context menu
def setup_context_menu(self):
"""Setup shell context menu"""
self.menu = QMenu(self)
self.menu = SpyderMenu(self)
self.cut_action = create_action(self, _("Cut"),
shortcut=keybinding('Cut'),
icon=ima.icon('editcut'),
Expand Down
4 changes: 4 additions & 0 deletions spyder/plugins/editor/widgets/codeeditor/codeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3356,6 +3356,8 @@ def setup_context_menu(self):
self.format_action.setEnabled(False)

# Build menu
# TODO: Change to SpyderMenu when the editor is migrated to the new
# API
self.menu = QMenu(self)
actions_1 = [self.gotodef_action, self.inspect_current_object_action,
None, self.undo_action, self.redo_action, None,
Expand All @@ -3374,6 +3376,8 @@ def setup_context_menu(self):
add_actions(self.menu, actions)

# Read-only context-menu
# TODO: Change to SpyderMenu when the editor is migrated to the new
# API
self.readonly_menu = QMenu(self)
add_actions(self.readonly_menu,
(self.copy_action, None, selectall_action,
Expand Down
5 changes: 3 additions & 2 deletions spyder/plugins/tours/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
QPixmap, QRegion)
from qtpy.QtWidgets import (QAction, QApplication, QComboBox, QDialog,
QGraphicsOpacityEffect, QHBoxLayout, QLabel,
QLayout, QMainWindow, QMenu, QMessageBox,
QLayout, QMainWindow, QMessageBox,
QPushButton, QSpacerItem, QToolButton, QVBoxLayout,
QWidget)

# Local imports
from spyder.api.widgets.menus import SpyderMenu
from spyder.api.translations import _
from spyder.plugins.layout.layouts import DefaultLayouts
from spyder.py3compat import to_binary_string
Expand Down Expand Up @@ -577,7 +578,7 @@ def focusOutEvent(self, event):

def context_menu_requested(self, event):
pos = QPoint(event.x(), event.y())
menu = QMenu(self)
menu = SpyderMenu(self)

actions = []
action_title = create_action(self, _('Go to step: '), icon=QIcon())
Expand Down
5 changes: 3 additions & 2 deletions spyder/plugins/variableexplorer/widgets/arrayeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
from qtpy.QtGui import QColor, QCursor, QDoubleValidator, QKeySequence
from qtpy.QtWidgets import (
QAbstractItemDelegate, QApplication, QComboBox, QDialog, QGridLayout,
QHBoxLayout, QInputDialog, QItemDelegate, QLabel, QLineEdit, QMenu,
QHBoxLayout, QInputDialog, QItemDelegate, QLabel, QLineEdit,
QMessageBox, QPushButton, QSpinBox, QStackedWidget, QTableView,
QVBoxLayout, QWidget)
from spyder_kernels.utils.nsview import value_to_display
from spyder_kernels.utils.lazymodules import numpy as np

# Local imports
from spyder.api.config.fonts import SpyderFontsMixin, SpyderFontType
from spyder.api.widgets.menus import SpyderMenu
from spyder.api.widgets.mixins import SpyderWidgetMixin
from spyder.api.widgets.toolbars import SpyderToolbar
from spyder.config.base import _
Expand Down Expand Up @@ -541,7 +542,7 @@ def setup_menu(self):
icon=ima.icon('editcopy'),
triggered=self.copy,
context=Qt.WidgetShortcut)
menu = QMenu(self)
menu = SpyderMenu(self)
add_actions(menu, [self.copy_action, ])
return menu

Expand Down
11 changes: 6 additions & 5 deletions spyder/plugins/variableexplorer/widgets/dataframeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@
from qtpy.QtGui import QColor, QCursor
from qtpy.QtWidgets import (
QApplication, QCheckBox, QGridLayout, QHBoxLayout, QInputDialog, QLineEdit,
QMenu, QMessageBox, QPushButton, QTableView, QScrollBar, QTableWidget,
QMessageBox, QPushButton, QTableView, QScrollBar, QTableWidget,
QFrame, QItemDelegate, QVBoxLayout, QLabel, QDialog)
from spyder_kernels.utils.lazymodules import numpy as np, pandas as pd

# Local imports
from spyder.api.config.fonts import SpyderFontsMixin, SpyderFontType
from spyder.api.config.mixins import SpyderConfigurationAccessor
from spyder.api.widgets.menus import SpyderMenu
from spyder.api.widgets.toolbars import SpyderToolbar
from spyder.config.base import _
from spyder.py3compat import (is_text_string, is_type_text_string,
Expand Down Expand Up @@ -684,7 +685,7 @@ def setup_menu_header(self):
triggered=self.edit_header_item
)
header_menu = [edit_header_action]
menu = QMenu(self)
menu = SpyderMenu(self)
add_actions(menu, header_menu)
return menu

Expand Down Expand Up @@ -808,7 +809,7 @@ def setup_menu(self):
(_("Float"), float),
(_("Str"), to_text_string)
)
convert_to_menu = QMenu(self)
convert_to_menu = SpyderMenu(self)
self.convert_to_action.setMenu(convert_to_menu)
self.convert_to_actions = []
for name, func in functions:
Expand All @@ -823,7 +824,7 @@ def slot():
)
]

menu = QMenu(self)
menu = SpyderMenu(self)
add_actions(convert_to_menu, self.convert_to_actions)
add_actions(menu, menu_actions)

Expand Down Expand Up @@ -1753,7 +1754,7 @@ def setup_menu_header(self, header):
triggered=lambda: self.edit_header_item(header=header)
)
header_menu = [edit_header_action]
menu = QMenu(self)
menu = SpyderMenu(self)
add_actions(menu, header_menu)
return menu

Expand Down
12 changes: 7 additions & 5 deletions spyder/plugins/variableexplorer/widgets/importwizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
from qtpy.compat import to_qvariant
from qtpy.QtCore import QAbstractTableModel, QModelIndex, Qt, Signal, Slot
from qtpy.QtGui import QColor, QIntValidator
from qtpy.QtWidgets import (QCheckBox, QDialog, QFrame, QGridLayout, QGroupBox,
from qtpy.QtWidgets import (QCheckBox, QFrame, QGridLayout, QGroupBox,
QHBoxLayout, QLabel, QLineEdit,
QPushButton, QMenu, QMessageBox, QRadioButton,
QPushButton, QMessageBox, QRadioButton,
QSizePolicy, QSpacerItem, QTableView, QTabWidget,
QTextEdit, QVBoxLayout, QWidget)
from spyder_kernels.utils.lazymodules import (
FakeObject, numpy as np, pandas as pd)

# Local import
from spyder.api.widgets.menus import SpyderMenu
from spyder.config.base import _
from spyder.py3compat import INT_TYPES, TEXT_TYPES, to_text_string
from spyder.utils import programs
Expand Down Expand Up @@ -335,6 +336,7 @@ def reset(self):
self.beginResetModel()
self.endResetModel()


class PreviewTable(QTableView):
"""Import wizard preview widget"""
def __init__(self, parent):
Expand All @@ -358,15 +360,15 @@ def __init__(self, parent):
triggered=ft_partial(self.parse_to_type, atype="float"))

# Setting up menus
self.date_menu = QMenu()
self.date_menu = SpyderMenu(self)
self.date_menu.setTitle("Date")
add_actions( self.date_menu, (self.date_dayfirst_action,
self.date_monthfirst_action))
self.parse_menu = QMenu(self)
self.parse_menu = SpyderMenu(self)
self.parse_menu.addMenu(self.date_menu)
add_actions( self.parse_menu, (self.perc_action, self.acc_action))
self.parse_menu.setTitle("String to")
self.opt_menu = QMenu(self)
self.opt_menu = SpyderMenu(self)
self.opt_menu.addMenu(self.parse_menu)
add_actions( self.opt_menu, (self.str_action, self.int_action,
self.float_action))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# Local imports
from spyder.api.config.fonts import SpyderFontsMixin, SpyderFontType
from spyder.api.config.mixins import SpyderConfigurationAccessor
from spyder.api.widgets.menus import SpyderMenu
from spyder.config.base import _
from spyder.config.manager import CONF
from spyder.plugins.variableexplorer.widgets.basedialog import BaseDialog
Expand Down Expand Up @@ -204,7 +205,7 @@ def _setup_menu(self, show_callable_attributes=False,
self.options_button.setStyleSheet(str(PANES_TOOLBAR_STYLESHEET))
self.options_button.setPopupMode(QToolButton.InstantPopup)

self.show_cols_submenu = QMenu(self)
self.show_cols_submenu = SpyderMenu(self)
self.options_button.setMenu(self.show_cols_submenu)
self.show_cols_submenu.setStyleSheet(str(PANES_TOOLBAR_STYLESHEET))
self.tools_layout.addWidget(self.options_button)
Expand Down
7 changes: 4 additions & 3 deletions spyder/widgets/collectionseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
QAbstractTableModel, QItemSelectionModel, QModelIndex, Qt, Signal, Slot)
from qtpy.QtGui import QColor, QKeySequence
from qtpy.QtWidgets import (
QApplication, QHBoxLayout, QHeaderView, QInputDialog, QLineEdit, QMenu,
QApplication, QHBoxLayout, QHeaderView, QInputDialog, QLineEdit,
QMessageBox, QPushButton, QTableView, QVBoxLayout, QWidget)
from spyder_kernels.utils.lazymodules import (
FakeObject, numpy as np, pandas as pd, PIL)
Expand All @@ -45,6 +45,7 @@
# Local imports
from spyder.api.config.fonts import SpyderFontsMixin, SpyderFontType
from spyder.api.config.mixins import SpyderConfigurationAccessor
from spyder.api.widgets.menus import SpyderMenu
from spyder.api.widgets.toolbars import SpyderToolbar
from spyder.config.base import _, running_under_pytest
from spyder.py3compat import (is_binary_string, to_text_string,
Expand Down Expand Up @@ -709,7 +710,7 @@ def setup_menu(self):
icon=ima.icon('outline_explorer'),
triggered=self.view_item)

menu = QMenu(self)
menu = SpyderMenu(self)
self.menu_actions = [
self.edit_action,
self.copy_action,
Expand All @@ -733,7 +734,7 @@ def setup_menu(self):
]
add_actions(menu, self.menu_actions)

self.empty_ws_menu = QMenu(self)
self.empty_ws_menu = SpyderMenu(self)
add_actions(
self.empty_ws_menu,
[self.insert_action, self.paste_action]
Expand Down
7 changes: 4 additions & 3 deletions spyder/widgets/tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
from qtpy.QtCore import QEvent, QPoint, Qt, Signal, Slot, QSize
from qtpy.QtGui import QFontMetrics
from qtpy.QtWidgets import (
QHBoxLayout, QLineEdit, QMenu, QTabBar, QTabWidget, QToolButton, QWidget)
QHBoxLayout, QLineEdit, QTabBar, QTabWidget, QToolButton, QWidget)

# Local imports
from spyder.api.widgets.menus import SpyderMenu
from spyder.config.base import _
from spyder.config.gui import is_dark_interface
from spyder.config.manager import CONF
Expand Down Expand Up @@ -433,7 +434,7 @@ def __init__(self, parent, actions=None, menu=None,
self.menu_use_tooltips = menu_use_tooltips

if menu is None:
self.menu = QMenu(self)
self.menu = SpyderMenu(self)
if actions:
add_actions(self.menu, actions)
else:
Expand All @@ -451,7 +452,7 @@ def __init__(self, parent, actions=None, menu=None,
self, icon=ima.icon('browse_tab'), tip=_("Browse tabs"))
self.browse_button.setStyleSheet(str(PANES_TABBAR_STYLESHEET))

self.browse_tabs_menu = QMenu(self)
self.browse_tabs_menu = SpyderMenu(self)
self.browse_button.setMenu(self.browse_tabs_menu)
self.browse_button.setPopupMode(self.browse_button.InstantPopup)
self.browse_tabs_menu.aboutToShow.connect(self.update_browse_tabs_menu)
Expand Down

0 comments on commit 5581408

Please sign in to comment.