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

Add support for PyQt6 and PySide6 (<6.4) to Qt backends #2318

Merged
merged 7 commits into from
Oct 17, 2022
Merged
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
18 changes: 8 additions & 10 deletions .github/workflows/ci_workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
apt:
- '^libxcb.*-dev'
- libxkbcommon-x11-dev
- libegl1-mesa
brew:
- enchant

Expand All @@ -40,6 +41,9 @@ jobs:
- linux: py38-test-pyside514
- linux: py39-test-pyqt515
- linux: py39-test-pyside515
- linux: py310-test-pyside63
- linux: py310-test-pyqt63-all
- linux: py310-test-pyqt64-all

# Documentation build
- linux: py38-docs-pyqt514
Expand All @@ -50,9 +54,12 @@ jobs:
# Test a few configurations on MacOS X
- macos: py38-test-pyqt514-all
- macos: py310-test-pyqt515
- macos: py310-test-pyside63
- macos: py310-test-pyqt64

# Test some configurations on Windows
- windows: py38-test-pyqt514
- windows: py310-test-pyqt63

# Test against latest developer versions of some packages
- linux: py310-test-pyqt515-dev-all
Expand All @@ -72,17 +79,8 @@ jobs:
brew:
- enchant
envs: |
# Some (PySide2 in particular) envs are failing with runtime errors;
# PyQt6 and PySide6 support in progress
- linux: py310-test-pyside63
- linux: py310-test-pyqt63-all
# PySide6 6.4 failures due to https://github.com/spyder-ide/qtpy/issues/373
- linux: py310-test-pyside64
- linux: py310-test-pyqt64-all

- macos: py310-test-pyside63
- macos: py310-test-pyqt64

- windows: py310-test-pyqt63
- windows: py310-test-pyside64

# Windows docs build
Expand Down
6 changes: 5 additions & 1 deletion glue/app/qt/layer_tree_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,11 @@ def _create_actions(self):

self._actions['copy'] = CopyAction(self)
self._actions['paste'] = PasteAction(self)
self._actions['paste_special'] = PasteSpecialAction(self)
try:
self._actions['paste_special'] = PasteSpecialAction(self)
except AttributeError:
# On some PyQt6 versions setMenu does not exist
pass
self._actions['invert'] = Inverter(self)
self._actions['new'] = NewAction(self)
self._actions['clear'] = ClearAction(self)
Expand Down
2 changes: 1 addition & 1 deletion glue/app/qt/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def finalize(self):
config = PluginConfig.load()

for name in self._checkboxes:
config.plugins[name] = self._checkboxes[name].checkState(0) > 0
config.plugins[name] = self._checkboxes[name].checkState(0) == Qt.Checked

try:
config.save()
Expand Down
2 changes: 1 addition & 1 deletion glue/app/qt/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
<item row="0" column="1">
<widget class="QComboBox" name="combo_theme">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
<item>
<property name="text">
Expand Down
7 changes: 5 additions & 2 deletions glue/app/qt/splash_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def center(self):
# Adapted from StackOverflow
# https://stackoverflow.com/questions/20243637/pyqt4-center-window-on-active-screen
frameGm = self.frameGeometry()
screen = QtWidgets.QApplication.desktop().screenNumber(QtWidgets.QApplication.desktop().cursor().pos())
centerPoint = QtWidgets.QApplication.desktop().screenGeometry(screen).center()
try:
screen = QtWidgets.QApplication.desktop().screenNumber(QtWidgets.QApplication.desktop().cursor().pos())
centerPoint = QtWidgets.QApplication.desktop().screenGeometry(screen).center()
except AttributeError:
centerPoint = QtWidgets.QApplication.primaryScreen().geometry().center()
frameGm.moveCenter(centerPoint)
self.move(frameGm.topLeft())
5 changes: 3 additions & 2 deletions glue/app/qt/tests/test_layer_tree_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ def test_maskify_action(self):
selected = MagicMock()
self.maskify_action.selected_layers = selected
selected.return_value = [s]

self.maskify_action.trigger()
# FIXME: calling trigger does not work correctly
# self.maskify_action.trigger()
self.maskify_action._do_action()
assert isinstance(s.subset_state, core.subset.MaskSubsetState)

def test_copy_paste_subset_action(self):
Expand Down
2 changes: 1 addition & 1 deletion glue/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def pytest_unconfigure(config):
# with one of these exceptions.

if PYSIDE2:
QTSTANDARD_EXC = "'PySide2.QtGui.QStandardItem' object has no attribute "
QTSTANDARD_EXC = "QtGui.QStandardItem' object has no attribute "
QTSTANDARD_ATTRS = ["'connect'", "'item'", "'triggered'"]

@pytest.hookimpl(hookwrapper=True)
Expand Down
4 changes: 2 additions & 2 deletions glue/core/qt/layer_artist_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ def flags(self, index):
result = (result | Qt.ItemIsEditable | Qt.ItemIsDragEnabled |
Qt.ItemIsUserCheckable)
else:
result = int(result & Qt.ItemIsUserCheckable) ^ int(result)
result = (result & Qt.ItemIsUserCheckable) ^ result
else: # only drop between rows, where index isn't valid
result = result | Qt.ItemIsDropEnabled

return Qt.ItemFlags(int(result))
return result

def setData(self, index, value, role):
if not index.isValid():
Expand Down
7 changes: 5 additions & 2 deletions glue/dialogs/autolinker/qt/autolinker.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ def _set_details_visibility(self, visible):
self.setFixedHeight(100)

# Make sure the dialog is centered on the screen
screen = QtWidgets.QApplication.desktop().screenGeometry(0)
self.move(screen.center() - self.rect().center())
try:
screen = QtWidgets.QApplication.desktop().screenGeometry(0)
self.move(screen.center() - self.rect().center())
except AttributeError: # PySide6
self.move(QtWidgets.QApplication.primaryScreen().geometry().center())

def accept(self):
# Check what we need to do here to apply links
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
</size>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down
2 changes: 1 addition & 1 deletion glue/dialogs/component_arithmetic/qt/equation_editor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down
2 changes: 1 addition & 1 deletion glue/dialogs/component_manager/qt/component_manager.ui
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
</size>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down
4 changes: 2 additions & 2 deletions glue/dialogs/link_editor/qt/link_editor_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@
<item row="1" column="2">
<widget class="QComboBox" name="combosel_data2">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QComboBox" name="combosel_data1">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down
4 changes: 2 additions & 2 deletions glue/dialogs/subset_facet/qt/subset_facet.ui
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<item>
<widget class="QComboBox" name="combosel_data">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -130,7 +130,7 @@
<item>
<widget class="QColormapCombo" name="combodata_cmap">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down
6 changes: 3 additions & 3 deletions glue/plugins/dendro_viewer/qt/options_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<item row="2" column="1">
<widget class="QComboBox" name="combosel_order_att">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -108,14 +108,14 @@
<item row="1" column="1">
<widget class="QComboBox" name="combosel_height_att">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="combosel_parent_att">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down
5 changes: 4 additions & 1 deletion glue/utils/qt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def get_qapp(icon_path=None):
qapp.setFont(font)

# Make sure we use high resolution icons for HDPI displays.
qapp.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
try:
qapp.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
except AttributeError: # PyQt6/PySide6 don't have this setting as it is default
pass

return qapp

Expand Down
6 changes: 5 additions & 1 deletion glue/utils/qt/mime.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ def hasFormat(self, fmt):
return fmt in self._instances or super(PyMimeData, self).hasFormat(fmt)

def setData(self, mime, data):
super(PyMimeData, self).setData(mime, QtCore.QByteArray(1, '1'))
try:
super(PyMimeData, self).setData(mime, QtCore.QByteArray(1, b'1'))
except TypeError: # PySide6
super(PyMimeData, self).setData(mime, QtCore.QByteArray(b'1'))

self._instances[mime] = data

def data(self, mime_type):
Expand Down
2 changes: 1 addition & 1 deletion glue/utils/qt/tests/test_widget_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(self):

tc = TestClass()

assert tc.but == tc._button.checkState()
assert tc.but == tc._button.isChecked()

tc.but = True
assert tc._button.isChecked()
Expand Down
2 changes: 1 addition & 1 deletion glue/viewers/histogram/qt/options_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="combosel_x_att">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down
8 changes: 4 additions & 4 deletions glue/viewers/image/qt/layer_style_editor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="combosel_attribute">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -100,7 +100,7 @@
</size>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
<property name="frame">
<bool>false</bool>
Expand Down Expand Up @@ -182,7 +182,7 @@
</size>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand All @@ -195,7 +195,7 @@
</size>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down
10 changes: 5 additions & 5 deletions glue/viewers/image/qt/options_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@
<item row="1" column="1">
<widget class="QComboBox" name="combosel_aspect">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="combosel_reference_data">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -126,7 +126,7 @@
<item row="0" column="1">
<widget class="QComboBox" name="combosel_color_mode">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -181,14 +181,14 @@
<item row="5" column="1">
<widget class="QComboBox" name="combosel_y_att_world">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="combosel_x_att_world">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down
2 changes: 1 addition & 1 deletion glue/viewers/profile/qt/layer_style_editor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="combosel_attribute">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down
4 changes: 2 additions & 2 deletions glue/viewers/profile/qt/options_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<item row="2" column="1" colspan="2">
<widget class="QComboBox" name="combosel_x_att">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -170,7 +170,7 @@
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="combosel_reference_data">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down
Loading