diff --git a/spyder/api/widgets/menus.py b/spyder/api/widgets/menus.py index 227c878f752..e50cc4f9422 100644 --- a/spyder/api/widgets/menus.py +++ b/spyder/api/widgets/menus.py @@ -9,7 +9,6 @@ """ # Standard library imports -import os import sys from typing import Optional, Union, TypeVar diff --git a/spyder/plugins/application/plugin.py b/spyder/plugins/application/plugin.py index 6f0589a2f80..11c968f195a 100644 --- a/spyder/plugins/application/plugin.py +++ b/spyder/plugins/application/plugin.py @@ -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 @@ -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: diff --git a/spyder/plugins/application/widgets/status.py b/spyder/plugins/application/widgets/status.py index 420cbf3d2f3..051ed90b4c5 100644 --- a/spyder/plugins/application/widgets/status.py +++ b/spyder/plugins/application/widgets/status.py @@ -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 ( @@ -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 diff --git a/spyder/plugins/completion/providers/languageserver/widgets/status.py b/spyder/plugins/completion/providers/languageserver/widgets/status.py index c103900af70..f7a6c643ee2 100644 --- a/spyder/plugins/completion/providers/languageserver/widgets/status.py +++ b/spyder/plugins/completion/providers/languageserver/widgets/status.py @@ -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 @@ -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) diff --git a/spyder/plugins/completion/widgets/status.py b/spyder/plugins/completion/widgets/status.py index e17eef3fa84..49cd36cf33d 100644 --- a/spyder/plugins/completion/widgets/status.py +++ b/spyder/plugins/completion/widgets/status.py @@ -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 @@ -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): diff --git a/spyder/plugins/console/widgets/shell.py b/spyder/plugins/console/widgets/shell.py index 3419291ee53..f2cd3d837a8 100644 --- a/spyder/plugins/console/widgets/shell.py +++ b/spyder/plugins/console/widgets/shell.py @@ -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 @@ -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'), diff --git a/spyder/plugins/editor/widgets/codeeditor/codeeditor.py b/spyder/plugins/editor/widgets/codeeditor/codeeditor.py index bf350325348..c54a264e785 100644 --- a/spyder/plugins/editor/widgets/codeeditor/codeeditor.py +++ b/spyder/plugins/editor/widgets/codeeditor/codeeditor.py @@ -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, @@ -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, diff --git a/spyder/plugins/tours/widgets.py b/spyder/plugins/tours/widgets.py index 7b07d40a774..94dfa44c301 100644 --- a/spyder/plugins/tours/widgets.py +++ b/spyder/plugins/tours/widgets.py @@ -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 @@ -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()) diff --git a/spyder/plugins/variableexplorer/widgets/arrayeditor.py b/spyder/plugins/variableexplorer/widgets/arrayeditor.py index 311e2c00cc1..b6e8b520efc 100644 --- a/spyder/plugins/variableexplorer/widgets/arrayeditor.py +++ b/spyder/plugins/variableexplorer/widgets/arrayeditor.py @@ -23,7 +23,7 @@ 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 @@ -31,6 +31,7 @@ # 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 _ @@ -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 diff --git a/spyder/plugins/variableexplorer/widgets/dataframeeditor.py b/spyder/plugins/variableexplorer/widgets/dataframeeditor.py index cc4a2c8a59e..8fd3b827319 100644 --- a/spyder/plugins/variableexplorer/widgets/dataframeeditor.py +++ b/spyder/plugins/variableexplorer/widgets/dataframeeditor.py @@ -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, @@ -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 @@ -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: @@ -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) @@ -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 diff --git a/spyder/plugins/variableexplorer/widgets/importwizard.py b/spyder/plugins/variableexplorer/widgets/importwizard.py index a54dd5262ac..b680fe1de6c 100644 --- a/spyder/plugins/variableexplorer/widgets/importwizard.py +++ b/spyder/plugins/variableexplorer/widgets/importwizard.py @@ -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 @@ -335,6 +336,7 @@ def reset(self): self.beginResetModel() self.endResetModel() + class PreviewTable(QTableView): """Import wizard preview widget""" def __init__(self, parent): @@ -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)) diff --git a/spyder/plugins/variableexplorer/widgets/objectexplorer/objectexplorer.py b/spyder/plugins/variableexplorer/widgets/objectexplorer/objectexplorer.py index d3843e882d0..95141f02652 100644 --- a/spyder/plugins/variableexplorer/widgets/objectexplorer/objectexplorer.py +++ b/spyder/plugins/variableexplorer/widgets/objectexplorer/objectexplorer.py @@ -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 @@ -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) diff --git a/spyder/widgets/collectionseditor.py b/spyder/widgets/collectionseditor.py index 9abc86d9bfe..e0b76279131 100644 --- a/spyder/widgets/collectionseditor.py +++ b/spyder/widgets/collectionseditor.py @@ -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) @@ -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, @@ -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, @@ -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] diff --git a/spyder/widgets/tabs.py b/spyder/widgets/tabs.py index 5a446dcee18..3fc3bba2c85 100644 --- a/spyder/widgets/tabs.py +++ b/spyder/widgets/tabs.py @@ -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 @@ -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: @@ -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)