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: Fixes to make the app work with PySide6 #23732

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 20 additions & 4 deletions spyder/api/config/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
from typing import Any, Callable, Optional, Union
import warnings

# Third-party imports
from qtpy import PYSIDE6

# Local imports
from spyder.config.manager import CONF
from spyder.config.types import ConfigurationKey
Expand Down Expand Up @@ -239,10 +242,13 @@ def __init__(self):
section = self.CONF_SECTION if section is None else section
observed_options = self._configuration_listeners[section]
for option in observed_options:
logger.debug(
f'{self} is observing option "{option}" in section '
f'"{section}"'
)
# Avoid a crash at startup due to MRO
if not PYSIDE6:
logger.debug(
f'{self} is observing option "{option}" in section '
f'"{section}"'
)

CONF.observe_configuration(self, section, option)

def __del__(self):
Expand All @@ -252,6 +258,16 @@ def __del__(self):
def _gather_observers(self):
"""Gather all the methods decorated with `on_conf_change`."""
for method_name in dir(self):
# Avoid crash at startup due to MRO
if PYSIDE6 and method_name in {
# PySide seems to require that the class is instantiated to
# access this method
"painters",
# Method is debounced
"restart_kernel",
}:
continue

method = getattr(self, method_name, None)
if hasattr(method, '_conf_listen'):
info = method._conf_listen
Expand Down
19 changes: 6 additions & 13 deletions spyder/api/widgets/comboboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

# Third-party imports
import qstylizer.style
from qtpy import PYQT5, PYQT6
from qtpy.QtCore import QSize, Qt, Signal
from qtpy.QtGui import QColor, QPainter, QFontMetrics
from qtpy.QtWidgets import (
Expand Down Expand Up @@ -256,7 +255,7 @@ def _generate_stylesheet(self):
return css


class SpyderComboBox(QComboBox, _SpyderComboBoxMixin):
class SpyderComboBox(_SpyderComboBoxMixin, QComboBox):
"""Default combobox widget for Spyder."""

def __init__(self, parent=None, items_elide_mode=None):
Expand All @@ -270,11 +269,8 @@ def __init__(self, parent=None, items_elide_mode=None):
items_elide_mode: Qt.TextElideMode, optional
Elide mode for the combobox items.
"""
if PYQT5 or PYQT6:
super().__init__(parent)
else:
QComboBox.__init__(self, parent)
_SpyderComboBoxMixin.__init__(self)
QComboBox.__init__(self, parent)
_SpyderComboBoxMixin.__init__(self)

self.is_editable = None
self._is_shown = False
Expand Down Expand Up @@ -375,14 +371,11 @@ def __init__(self, parent=None, items_elide_mode=None):
self.setStyleSheet(self._css.toString())


class SpyderFontComboBox(QFontComboBox, _SpyderComboBoxMixin):
class SpyderFontComboBox(_SpyderComboBoxMixin, QFontComboBox):

def __init__(self, parent=None):
if PYQT5 or PYQT6:
super().__init__(parent)
else:
QFontComboBox.__init__(self, parent)
_SpyderComboBoxMixin.__init__(self)
QFontComboBox.__init__(self, parent)
_SpyderComboBoxMixin.__init__(self)

# Avoid font name eliding because it confuses users.
# Fixes spyder-ide/spyder#22683
Expand Down
4 changes: 2 additions & 2 deletions spyder/api/widgets/main_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
status bar widgets or toolbars.
"""

from qtpy import PYQT5, PYQT6
from qtpy import PYSIDE2
from qtpy.QtCore import Signal
from qtpy.QtWidgets import QWidget

Expand Down Expand Up @@ -113,7 +113,7 @@ class PluginMainContainer(QWidget, SpyderWidgetMixin):
"""

def __init__(self, name, plugin, parent=None):
if PYQT5 or PYQT6:
if not PYSIDE2:
super().__init__(parent=parent, class_parent=plugin)
else:
QWidget.__init__(self, parent)
Expand Down
4 changes: 2 additions & 2 deletions spyder/api/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from typing import Optional

# Third party imports
from qtpy import PYQT5, PYQT6
from qtpy import PYSIDE2
from qtpy.QtCore import QByteArray, QSize, Qt, Signal, Slot
from qtpy.QtGui import QFocusEvent, QIcon
from qtpy.QtWidgets import (QApplication, QHBoxLayout, QSizePolicy,
Expand Down Expand Up @@ -206,7 +206,7 @@ class PluginMainWidget(QWidget, SpyderWidgetMixin):
"""

def __init__(self, name, plugin, parent=None):
if PYQT5 or PYQT6:
if not PYSIDE2:
super().__init__(parent=parent, class_parent=plugin)
else:
QWidget.__init__(self, parent)
Expand Down
2 changes: 1 addition & 1 deletion spyder/api/widgets/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ class SpyderWidgetMixin(
# Context name used to store actions, toolbars, toolbuttons and menus
CONTEXT_NAME = None

def __init__(self, class_parent=None):
def __init__(self, class_parent=None, parent=None):
for attr in ['CONF_SECTION', 'PLUGIN_NAME']:
if getattr(self, attr, None) is None:
if hasattr(class_parent, attr):
Expand Down
4 changes: 2 additions & 2 deletions spyder/api/widgets/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# Third party imports
import qstylizer.parser
from qtpy import PYQT5, PYQT6
from qtpy import PYSIDE2
from qtpy.QtCore import Qt, QSize, QTimer, Signal
from qtpy.QtGui import QIcon
from qtpy.QtWidgets import QHBoxLayout, QLabel, QWidget
Expand Down Expand Up @@ -82,7 +82,7 @@ def __init__(self, parent=None, show_icon=True, show_label=True,
1. To use an icon, you need to redefine the ``get_icon`` method.
2. To use a label, you need to call ``set_value``.
"""
if PYQT5 or PYQT6:
if not PYSIDE2:
super().__init__(parent, class_parent=parent)
else:
QWidget.__init__(self, parent)
Expand Down
2 changes: 1 addition & 1 deletion spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5383,7 +5383,7 @@ def test_goto_find(main_window, qtbot, tmpdir):
for i in range(5):
item = file_item.child(i)
findinfiles.result_browser.setCurrentItem(item)
findinfiles.result_browser.activated(item)
findinfiles.result_browser.on_item_activated(item)
cursor = code_editor.textCursor()
position = (cursor.selectionStart(), cursor.selectionEnd())
assert position == match_positions[i]
Expand Down
8 changes: 8 additions & 0 deletions spyder/plugins/completion/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from typing import Any, Optional, Tuple, Union

# Third party imports
from qtpy import PYSIDE6
from qtpy.QtCore import Signal, QObject, Slot, Qt

# Local imports
Expand Down Expand Up @@ -675,6 +676,13 @@ class CompletionConfigurationObserver(SpyderConfigurationObserver):
def _gather_observers(self):
"""Gather all the methods decorated with `on_conf_change`."""
for method_name in dir(self):
# Avoid crash at startup due to MRO
if PYSIDE6 and method_name in {
# Method is debounced
"interpreter_changed"
}:
continue

method = getattr(self, method_name, None)
if hasattr(method, '_conf_listen'):
info = method._conf_listen
Expand Down
4 changes: 2 additions & 2 deletions spyder/plugins/debugger/widgets/breakpoint_table_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# Third party imports
import qstylizer.style
from qtpy import PYQT5, PYQT6
from qtpy import PYSIDE2
from qtpy.compat import to_qvariant
from qtpy.QtCore import QAbstractTableModel, QModelIndex, Qt, Signal
from qtpy.QtWidgets import QAbstractItemView, QTableView
Expand Down Expand Up @@ -175,7 +175,7 @@ class BreakpointTableView(QTableView, SpyderWidgetMixin):
sig_conditional_breakpoint_requested = Signal()

def __init__(self, parent, data):
if PYQT5 or PYQT6:
if not PYSIDE2:
super().__init__(parent, class_parent=parent)
else:
QTableView.__init__(self, parent)
Expand Down
6 changes: 3 additions & 3 deletions spyder/plugins/debugger/widgets/framesbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,13 @@ def __init__(self, parent):

# Signals
self.header().sectionClicked.connect(self.sort_section)
self.itemActivated.connect(self.activated)
self.itemClicked.connect(self.activated)
self.itemActivated.connect(self.on_item_activated)
self.itemClicked.connect(self.on_item_activated)

def set_title(self, title):
self.setHeaderLabels([title])

def activated(self, item):
def on_item_activated(self, item):
"""Double-click event."""
itemdata = self.data.get(id(self.currentItem()))
if itemdata is not None:
Expand Down
4 changes: 2 additions & 2 deletions spyder/plugins/editor/widgets/editorstack/editorstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

# Third party imports
import qstylizer.style
from qtpy import PYQT5, PYQT6
from qtpy import PYSIDE2
from qtpy.compat import getsavefilename
from qtpy.QtCore import QFileInfo, Qt, QTimer, Signal, Slot
from qtpy.QtGui import QTextCursor
Expand Down Expand Up @@ -207,7 +207,7 @@ class EditorStack(QWidget, SpyderWidgetMixin):
"""

def __init__(self, parent, actions, use_switcher=True):
if PYQT5 or PYQT6:
if not PYSIDE2:
super().__init__(parent, class_parent=parent)
else:
QWidget.__init__(self, parent)
Expand Down
4 changes: 2 additions & 2 deletions spyder/plugins/editor/widgets/splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# Third party imports
import qstylizer.style
from qtpy import PYQT5, PYQT6
from qtpy import PYSIDE2
from qtpy.QtCore import QByteArray, Qt, Slot
from qtpy.QtWidgets import QSplitter

Expand Down Expand Up @@ -57,7 +57,7 @@ def __init__(self, parent, main_widget, menu_actions, first=False,
Defaults to main_widget.unregister_editorstack() to
unregister the EditorStack with the EditorMainWidget.
"""
if PYQT5 or PYQT6:
if not PYSIDE2:
super().__init__(parent, class_parent=main_widget)
else:
QSplitter.__init__(self, parent)
Expand Down
4 changes: 2 additions & 2 deletions spyder/plugins/explorer/widgets/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import sys

# Third party imports
from qtpy import PYQT5, PYQT6
from qtpy import PYSIDE2
from qtpy.compat import getexistingdirectory, getsavefilename
from qtpy.QtCore import (
QDir,
Expand Down Expand Up @@ -334,7 +334,7 @@ def __init__(self, parent=None):
parent: QWidget
Parent QWidget of the widget.
"""
if PYQT5 or PYQT6:
if not PYSIDE2:
super().__init__(parent=parent, class_parent=parent)
else:
QTreeView.__init__(self, parent)
Expand Down
4 changes: 2 additions & 2 deletions spyder/plugins/findinfiles/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import re

# Third party imports
from qtpy import PYQT5, PYQT6
from qtpy import PYSIDE2
from qtpy.QtCore import Signal
from qtpy.QtGui import QFontMetricsF
from qtpy.QtWidgets import QInputDialog, QLabel, QStackedWidget, QVBoxLayout
Expand Down Expand Up @@ -128,7 +128,7 @@ class FindInFilesWidget(PluginMainWidget):
"""

def __init__(self, name=None, plugin=None, parent=None):
if PYQT5 or PYQT6:
if not PYSIDE2:
super().__init__(name, plugin, parent=parent)
else:
PluginMainWidget.__init__(self, name, plugin, parent=parent)
Expand Down
6 changes: 3 additions & 3 deletions spyder/plugins/findinfiles/widgets/results_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def __init__(self, parent, text_color, max_results=1000):
# Signals
self.header().sectionClicked.connect(self.sort_section)

def activated(self, item):
def on_item_activated(self, item):
"""Double-click event."""
itemdata = self.data.get(id(self.currentItem()))
if itemdata is not None:
Expand All @@ -240,15 +240,15 @@ def set_sorting(self, flag):
def sort_section(self, idx):
self.setSortingEnabled(True)

def clicked(self, item):
def on_item_clicked(self, item):
"""Click event."""
if isinstance(item, FileMatchItem):
if item.isExpanded():
self.collapseItem(item)
else:
self.expandItem(item)
else:
self.activated(item)
self.on_item_activated(item)

def clear_title(self, search_text):
self.font = self.get_font(SpyderFontType.MonospaceInterface)
Expand Down
4 changes: 2 additions & 2 deletions spyder/plugins/help/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import sys

# Third party imports
from qtpy import PYQT5, PYQT6
from qtpy import PYSIDE2
from qtpy.QtCore import Qt, QUrl, Signal, Slot, QPoint
from qtpy.QtGui import QColor
from qtpy.QtWidgets import (QActionGroup, QLabel, QLineEdit,
Expand Down Expand Up @@ -156,7 +156,7 @@ class RichText(QWidget, SpyderWidgetMixin):
sig_link_clicked = Signal(QUrl)

def __init__(self, parent):
if PYQT5 or PYQT6:
if not PYSIDE2:
super().__init__(parent, class_parent=parent)
else:
QWidget.__init__(self, parent)
Expand Down
6 changes: 3 additions & 3 deletions spyder/plugins/outlineexplorer/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ def get_visible_items(self):
iterator += 1
return items

def activated(self, item):
def on_item_activated(self, item):
"""Double-click event"""
editor_root = self.editor_items.get(
self.editor_ids.get(self.current_editor))
Expand Down Expand Up @@ -800,11 +800,11 @@ def activated(self, item):
break
break

def clicked(self, item):
def on_item_clicked(self, item):
"""Click event"""
if isinstance(item, FileRootItem):
self.root_item_selected(item)
self.activated(item)
self.on_item_activated(item)

def selection_switched(self, current_item, previous_item):
if current_item is not None:
Expand Down
6 changes: 3 additions & 3 deletions spyder/plugins/plots/widgets/figurebrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

# Third library imports
from qtconsole.svg import svg_to_clipboard, svg_to_image
from qtpy import PYQT5, PYQT6
from qtpy import PYSIDE2
from qtpy.compat import getexistingdirectory, getsavefilename
from qtpy.QtCore import (
QEvent,
Expand Down Expand Up @@ -147,7 +147,7 @@ class FigureBrowser(QWidget, SpyderWidgetMixin):
"""

def __init__(self, parent=None, background_color=None):
if PYQT5 or PYQT6:
if not PYSIDE2:
super().__init__(parent=parent, class_parent=parent)
else:
QWidget.__init__(self, parent)
Expand Down Expand Up @@ -367,7 +367,7 @@ class FigureViewer(QScrollArea, SpyderWidgetMixin):
"""This signal is emitted when a new figure is loaded."""

def __init__(self, parent=None, background_color=None):
if PYQT5 or PYQT6:
if not PYSIDE2:
super().__init__(parent, class_parent=parent)
else:
QScrollArea.__init__(self, parent)
Expand Down
Loading
Loading