Skip to content

Commit

Permalink
Upgrade to Qt6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
raimund-schluessler committed Mar 15, 2022
1 parent fe839e6 commit 1120bfe
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 51 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ jobs:
- name: Setup xvfb (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get install -y xvfb libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xinput0 libxcb-xfixes0
sudo apt-get update
sudo apt-get install -y xvfb libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xinput0 libxcb-xfixes0 libegl1-mesa
# start xvfb in the background
sudo /usr/bin/Xvfb $DISPLAY -screen 0 1280x1024x24 &
- name: Install dependencies
Expand Down
12 changes: 6 additions & 6 deletions impose/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ def main(splash=True):
import sys
# import time

from PyQt5.QtWidgets import QApplication
from PyQt6.QtWidgets import QApplication

app = QApplication(sys.argv)
# imdir = pkg_resources.resource_filename("impose", "img")

# if splash:
# from PyQt5.QtWidgets import QSplashScreen
# from PyQt5.QtGui import QPixmap
# from PyQt6.QtWidgets import QSplashScreen
# from PyQt6.QtGui import QPixmap
# splash_path = os.path.join(imdir, "splash.png")
# splash_pix = QPixmap(splash_path)
# splash = QSplashScreen(splash_pix)
Expand All @@ -21,23 +21,23 @@ def main(splash=True):
# time.sleep(.07)
# app.processEvents()

from PyQt5 import QtCore # , QtGui
from PyQt6 import QtCore # , QtGui
from .gui.main import Impose

# # Set Application Icon
# icon_path = os.path.join(imdir, "icon.png")
# app.setWindowIcon(QtGui.QIcon(icon_path))

# Use dots as decimal separators
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.C))
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.Language.C))

window = Impose() # noqa: F841

# window = Impose()
# if splash:
# splash.finish(window)

sys.exit(app.exec_())
sys.exit(app.exec())


if __name__ == "__main__":
Expand Down
14 changes: 7 additions & 7 deletions impose/gui/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pkg_resources

import numpy as np
from PyQt5 import uic, QtCore, QtWidgets
from PyQt6 import uic, QtCore, QtWidgets
from skimage.color import hsv2rgb

from .. import formats
Expand Down Expand Up @@ -40,8 +40,8 @@ def __init__(self, *args, **kwargs):
# set horizontal stretch for path list
header = self.tableWidget_paths.horizontalHeader()
header.setSectionResizeMode(
0, QtWidgets.QHeaderView.ResizeToContents)
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
0, QtWidgets.QHeaderView.ResizeMode.ResizeToContents)
header.setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeMode.Stretch)

# signal for user wants to add new dataset(s)
self.toolButton_add_data.clicked.connect(self.on_add_data)
Expand Down Expand Up @@ -192,8 +192,8 @@ def update_shape_list(self):
# Finally add a stretch spacer in case there are not enough
# items.
spacer_item = QtWidgets.QSpacerItem(20, 0,
QtWidgets.QSizePolicy.Minimum,
QtWidgets.QSizePolicy.Expanding)
QtWidgets.QSizePolicy.Policy.Minimum,
QtWidgets.QSizePolicy.Policy.Expanding)
self.verticalLayout_structures.addItem(spacer_item)
self.widget_structures.setUpdatesEnabled(True)

Expand All @@ -209,11 +209,11 @@ def update_table_paths(self):
item = QtWidgets.QLabel()
self.tableWidget_paths.setCellWidget(row, jj, item)
QtWidgets.QApplication.processEvents(
QtCore.QEventLoop.AllEvents, 500)
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 500)
f_metrics = item.fontMetrics()
s = item.size().width() - 5
ellabel = f_metrics.elidedText(
label, QtCore.Qt.ElideLeft, s)
label, QtCore.Qt.TextElideMode.ElideLeft, s)
item.setText(ellabel)

def update_ui_from_scheme(self):
Expand Down
2 changes: 1 addition & 1 deletion impose/gui/collect_pgrois.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from PyQt5 import QtCore
from PyQt6 import QtCore
import pyqtgraph as pg

from ..geometry import pg_roi_to_impose_shape
Expand Down
2 changes: 1 addition & 1 deletion impose/gui/collect_shape_controls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pkg_resources

from PyQt5 import uic, QtCore, QtWidgets
from PyQt6 import uic, QtCore, QtWidgets

from . import dlg_edit_shape

Expand Down
10 changes: 5 additions & 5 deletions impose/gui/colocalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pkg_resources

import numpy as np
from PyQt5 import uic, QtCore, QtWidgets
from PyQt6 import uic, QtCore, QtWidgets

from .. import formats

Expand Down Expand Up @@ -42,8 +42,8 @@ def __init__(self, *args, **kwargs):
for tab in [self.tableWidget_paths, self.tableWidget_structures]:
header = tab.horizontalHeader()
header.setSectionResizeMode(
0, QtWidgets.QHeaderView.ResizeToContents)
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
0, QtWidgets.QHeaderView.ResizeMode.ResizeToContents)
header.setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeMode.Stretch)

# Tool Button Add Menu
# options button
Expand Down Expand Up @@ -316,11 +316,11 @@ def update_table_paths(self):
item = QtWidgets.QLabel()
self.tableWidget_paths.setCellWidget(row, jj, item)
QtWidgets.QApplication.processEvents(
QtCore.QEventLoop.AllEvents, 500)
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 500)
f_metrics = item.fontMetrics()
s = item.size().width() - 5
ellabel = f_metrics.elidedText(
label, QtCore.Qt.ElideLeft, s)
label, QtCore.Qt.TextElideMode.ElideLeft, s)
item.setText(ellabel)

def update_ui_from_scheme(self):
Expand Down
8 changes: 4 additions & 4 deletions impose/gui/colocalize_pgrois.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from PyQt5 import QtCore
from PyQt6 import QtCore
import pyqtgraph as pg
from pyqtgraph import functions as fn

Expand Down Expand Up @@ -48,7 +48,7 @@ def append(self, roi):
roi.sigRegionChangeStarted.connect(self.on_change_started)
roi.sigRegionChangeFinished.connect(self.on_change_finished)
roi.sigRegionChanged.connect(self.on_change_finished)
roi.setAcceptedMouseButtons(QtCore.Qt.LeftButton) # allow clicking
roi.setAcceptedMouseButtons(QtCore.Qt.MouseButton.LeftButton) # allow clicking
roi.sigClicked.connect(self.update_structure_geometry)
self.rois.append(roi)
self._initial_states.append(roi.saveState())
Expand Down Expand Up @@ -256,10 +256,10 @@ def hide_handles(self):
if hh["type"] == "t":
# Hide polygon drag handles
hh["item"].hide()
hh["item"].setAcceptedMouseButtons(QtCore.Qt.NoButton)
hh["item"].setAcceptedMouseButtons(QtCore.Qt.MouseButton.NoButton)

for seg in self.segments:
seg.setAcceptedMouseButtons(QtCore.Qt.NoButton)
seg.setAcceptedMouseButtons(QtCore.Qt.MouseButton.NoButton)
seg.setZValue(self.zValue() - 1000)

def segmentClicked(self, segment, ev=None, pos=None):
Expand Down
4 changes: 2 additions & 2 deletions impose/gui/dlg_edit_shape.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pkg_resources

import numpy as np
from PyQt5 import uic, QtWidgets
from PyQt6 import uic, QtWidgets


class EditDialog(QtWidgets.QDialog):
Expand All @@ -13,7 +13,7 @@ def __init__(self, ui_name, shape, *args, **kwargs):
self.point_um = shape.point_um

# Dialog box buttons
btn_apply = self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok)
btn_apply = self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok)
btn_apply.clicked.connect(self.on_ok)


Expand Down
12 changes: 6 additions & 6 deletions impose/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import traceback

from PyQt5 import uic, QtCore, QtWidgets
from PyQt6 import uic, QtCore, QtWidgets
import pyqtgraph as pg

from .widgets import ShowWaitCursor
Expand All @@ -28,7 +28,7 @@ def __init__(self):
QtCore.QCoreApplication.setOrganizationDomain(
"impose.readthedocs.io")
QtCore.QCoreApplication.setApplicationName("impose")
QtCore.QSettings.setDefaultFormat(QtCore.QSettings.IniFormat)
QtCore.QSettings.setDefaultFormat(QtCore.QSettings.Format.IniFormat)
# Some promoted widgets may need the above constants set in order
# to access the settings upon initialization.
super(Impose, self).__init__()
Expand Down Expand Up @@ -146,14 +146,14 @@ def excepthook(etype, value, trace):

errorbox = QtWidgets.QMessageBox()
errorbox.addButton(QtWidgets.QPushButton('Close'),
QtWidgets.QMessageBox.YesRole)
QtWidgets.QMessageBox.ButtonRole.YesRole)
errorbox.addButton(QtWidgets.QPushButton(
'Copy text && Close'), QtWidgets.QMessageBox.NoRole)
'Copy text && Close'), QtWidgets.QMessageBox.ButtonRole.NoRole)
errorbox.setText(exception)
ret = errorbox.exec_()
ret = errorbox.exec()
if ret == 1:
cb = QtWidgets.QApplication.clipboard()
cb.clear(mode=cb.Clipboard)
cb.clear(mode=cb.Mode.Clipboard)
cb.setText(exception)


Expand Down
8 changes: 4 additions & 4 deletions impose/gui/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pkg_resources

import numpy as np
from PyQt5 import uic, QtCore, QtWidgets
from PyQt6 import uic, QtCore, QtWidgets


class Visualize(QtWidgets.QWidget):
Expand Down Expand Up @@ -103,11 +103,11 @@ def __setstate__(self, state):
# add channels
for name in state["channels"]:
qwi = QtWidgets.QListWidgetItem(name)
qwi.setFlags(qwi.flags() | QtCore.Qt.ItemIsUserCheckable)
qwi.setFlags(qwi.flags() | QtCore.Qt.ItemFlag.ItemIsUserCheckable)
if name in state["blend"]["channels"]:
qwi.setCheckState(QtCore.Qt.Checked)
qwi.setCheckState(QtCore.Qt.CheckState.Checked)
else:
qwi.setCheckState(QtCore.Qt.Unchecked)
qwi.setCheckState(QtCore.Qt.CheckState.Unchecked)
self.listWidget_chan.addItem(qwi)
self.listWidget_chan.setCurrentRow(0)
self.listWidget_chan.blockSignals(False)
Expand Down
4 changes: 2 additions & 2 deletions impose/gui/widgets/simple_image_view.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt6 import QtCore, QtGui, QtWidgets
import pyqtgraph as pg

from .simple_plot_widget import SimpleViewBox
Expand Down Expand Up @@ -32,7 +32,7 @@ def on_export(self, suffix):
height, width, _ = self.image.shape

qImg = QtGui.QImage(img, width, height, width *
3, QtGui.QImage.Format_RGB888)
3, QtGui.QImage.Format.Format_RGB888)
qImg.save(path)


Expand Down
2 changes: 1 addition & 1 deletion impose/gui/widgets/simple_plot_widget.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from PyQt5 import QtCore, QtWidgets
from PyQt6 import QtCore, QtWidgets
import pyqtgraph as pg
from pyqtgraph import exporters

Expand Down
10 changes: 5 additions & 5 deletions impose/gui/widgets/wait_cursor.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import functools

from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import QCursor
from PyQt5.QtCore import Qt, QEventLoop
from PyQt6.QtWidgets import QApplication
from PyQt6.QtGui import QCursor
from PyQt6.QtCore import Qt, QEventLoop


class ShowWaitCursor(object):
def __enter__(self):
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
# This overloaded function call makes sure that all events,
# even those triggered during the function call, are processed.
QApplication.processEvents(QEventLoop.AllEvents, 50)
QApplication.processEvents(QEventLoop.ProcessEventsFlag.AllEvents, 50)
return self

def __exit__(self, type, value, traceback):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"bmlab>=0.1.1",
"h5py>=2.10.0",
"numpy>=1.17.0",
"pyqt5>=5.15.0",
"pyqt6>=6.2.0",
"pyqtgraph==0.12.3",
"scikit-image>=0.17.2",
"scipy>=0.12.0", # compute size of polygon shape
Expand Down
8 changes: 4 additions & 4 deletions tests/test_gui_collect.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pathlib

import numpy as np
from PyQt5 import QtCore, QtWidgets
from PyQt6 import QtCore, QtWidgets

from impose.gui.main import Impose

Expand All @@ -22,8 +22,8 @@ def test_load_dataset(qtbot, monkeypatch):
example_data = data_dir / "brillouin.h5"
monkeypatch.setattr(QtWidgets.QFileDialog, "getOpenFileNames",
lambda *args: ([str(example_data)], None))
qtbot.mouseClick(mw.tab_collect.toolButton_add_data, QtCore.Qt.LeftButton)
QtWidgets.QApplication.processEvents(QtCore.QEventLoop.AllEvents, 300)
qtbot.mouseClick(mw.tab_collect.toolButton_add_data, QtCore.Qt.MouseButton.LeftButton)
QtWidgets.QApplication.processEvents(QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 300)

# make sure the data is loaded correctly
assert len(mw.tab_collect.session_scheme.paths) == 1
Expand All @@ -43,7 +43,7 @@ def test_load_session(qtbot, monkeypatch):
# select the first entry in the datasets list
assert not mw.tab_collect.widget_struct.isEnabled()
qtbot.mouseClick(mw.tab_collect.tableWidget_paths.cellWidget(0, 0),
QtCore.Qt.LeftButton)
QtCore.Qt.MouseButton.LeftButton)
assert mw.tab_collect.widget_struct.isEnabled()

# test a label
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gui_colocalize.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pathlib

from PyQt5 import QtWidgets
from PyQt6 import QtWidgets

from impose.gui.main import Impose

Expand Down

0 comments on commit 1120bfe

Please sign in to comment.