From 3c4683cc5df7ca72f44b6b9e25f5bb6f75418872 Mon Sep 17 00:00:00 2001 From: Ondrej Lexa Date: Fri, 24 Jan 2025 14:51:37 +0100 Subject: [PATCH] both pyqt5 and pyqt6 supported --- CHANGELOG.md | 7 ++++++- README.md | 28 +++++++++++----------------- pyproject.toml | 11 +++++------ pypsbuilder/__init__.py | 2 +- pypsbuilder/psbuilders.py | 25 +++++++++++-------------- pypsbuilder/ui/compile_ui.sh | 1 + pypsbuilder/ui_addinv.py | 2 +- pypsbuilder/ui_adduni.py | 2 +- pypsbuilder/ui_ptbuilder.py | 2 +- pypsbuilder/ui_pxbuilder.py | 2 +- pypsbuilder/ui_txbuilder.py | 2 +- pypsbuilder/ui_uniguess.py | 2 +- 12 files changed, 41 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb3e844..ea1d71f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,16 @@ # Changelog All notable pypsbuilder changes. +## [2.6.1] - master +### Added + - Both PyQt5 and PyQt6 are supported and need to be specified as + extra option during installation + ## [2.6.0] - 2025-01-23 Initial PyQt6 release ## [2.5.3] - 2024-12-18 -Latest version using PyQt5 +Latest version using PyQt5 only ## [2.5.0] - 2024-12-13 ### Fixed diff --git a/README.md b/README.md index 27aa083..a68e602 100644 --- a/README.md +++ b/README.md @@ -28,11 +28,11 @@ for Windows use PowerShell: and install **pypsbuilder** using pip within the environment: - pip install pypsbuilder + pip install pypsbuilder[pyqt6] -Jupyter Lab could be also installed providing extra option: +Providing jupyter option, JupyterLab will be also installed: - pip install pypsbuilder[extra] + pip install pypsbuilder[pyqt6,jupyter] ## I'm using conda or mamba to manage environments @@ -53,21 +53,15 @@ or mamba activate pyps and install with pip. Note that PyQt6 is not yet available in conda repositories, -so we need to use the 2.5.3 version: +so we need to use the pyqt5 version: - pip install pypsbuilder==2.5.3 + pip install pypsbuilder[pyqt5] -#### Note for macOS - -If you have environment created with conda/mamba install the pypsbuilder with: - - pip install pypsbuilder==2.5.3 --no-deps - -#### Install master version - -You can install latest version from master branch on GitHub: - - pip install https://github.com/ondrolexa/pypsbuilder/archive/master.zip +> [!NOTE] +> If you encounter errors during install, try to install without upgrading dependencies: +> ``` +> pip install --no-deps pypsbuilder[pyqt5] +> ``` #### Upgrade existing installation @@ -75,7 +69,7 @@ To upgrade an already installed **pypsbuilder** to the latest release: pip install --upgrade pypsbuilder -or to latest master version: +or to the latest master version: pip install --upgrade https://github.com/ondrolexa/pypsbuilder/archive/master.zip diff --git a/pyproject.toml b/pyproject.toml index 8dd2774..46fb2d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ classifiers = [ dependencies = [ "numpy", "matplotlib>=3.8", - "pyqt6", + "qtpy", "scipy", "scikit-image", "networkx", @@ -34,13 +34,12 @@ dependencies = [ ] [project.optional-dependencies] -extra = ["jupyterlab"] +pyqt5 = ["pyqt5"] +pyqt6 = ["pyqt6"] +jupyter = ["jupyterlab"] tests = ["pytest", "pytest-cov"] docs = ["sphinx", "sphinx_mdinclude", "sphinx_rtd_theme"] -dev = [ - "pypsbuilder[extra,tests,docs]", - "black", -] +dev = ["pypsbuilder[pyqt6,jupyter,tests,docs]", "black"] [project.urls] Homepage = "https://github.com/ondrolexa/pypsbuilder" diff --git a/pypsbuilder/__init__.py b/pypsbuilder/__init__.py index 7436c0b..0c422d5 100644 --- a/pypsbuilder/__init__.py +++ b/pypsbuilder/__init__.py @@ -22,7 +22,7 @@ "get_tcapi", ) -__version__ = "2.6.0" +__version__ = "2.6.1" __author__ = "Ondrej Lexa" __copyright__ = "© Ondrej Lexa 2016-2025" __email__ = "lexa.ondrej@gmail.com" diff --git a/pypsbuilder/psbuilders.py b/pypsbuilder/psbuilders.py index 1f3e7a7..d3a035d 100755 --- a/pypsbuilder/psbuilders.py +++ b/pypsbuilder/psbuilders.py @@ -15,9 +15,10 @@ import warnings import importlib.resources as ires -from PyQt6 import QtCore, QtGui, QtWidgets -from PyQt6.QtCore import QT_VERSION_STR -from PyQt6.QtCore import PYQT_VERSION_STR +from qtpy import QtCore, QtGui, QtWidgets +from qtpy import QT_VERSION +from qtpy import API as QTPY_API + import numpy as np import matplotlib @@ -1347,7 +1348,7 @@ def add_userdefined(self, checked=True): self.unimodel.appendRow(id_uni, uni) self.uni_connect(id_uni, candidates) self.changed = True - # self.unisel.select(idx, QtCore.QItemSelectionModel.ClearAndSelect | QtCore.QItemSelectionModel.Rows) + # self.unisel.select(idx, QtCore.QItemSelectionModel.SelectionFlag.ClearAndSelect | QtCore.QItemSelectionModel.SelectionFlag.Rows) idx = self.unimodel.getIndexID(id_uni) self.uniview.selectRow(idx.row()) self.uniview.scrollToBottom() @@ -1950,8 +1951,7 @@ def builder_ui_settings(self): def app_settings(self, write=False): # Applicatiom settings - qtver = QtCore.PYQT_VERSION_STR.split(".")[0] - builder_settings = QtCore.QSettings("LX", f"ptbuilder pyqt{qtver}") + builder_settings = QtCore.QSettings("LX", f"ptbuilder {QTPY_API}{QT_VERSION.split(".")[0]}") if write: builder_settings.setValue("steps", self.spinSteps.value()) builder_settings.setValue("precision", self.spinPrec.value()) @@ -2713,7 +2713,7 @@ def do_calc(self, calcT, phases={}, out={}, run_tc=True): self.unimodel.appendRow(id_uni, uni) self.uniview.resizeColumnsToContents() self.changed = True - # self.unisel.select(idx, QtCore.QItemSelectionModel.ClearAndSelect | QtCore.QItemSelectionModel.Rows) + # self.unisel.select(idx, QtCore.QItemSelectionModel.SelectionFlag.ClearAndSelect | QtCore.QItemSelectionModel.SelectionFlag.Rows) idx = self.unimodel.getIndexID(id_uni) self.uniview.selectRow(idx.row()) self.uniview.scrollToBottom() @@ -3686,7 +3686,7 @@ def do_calc(self, calcT, phases={}, out={}, run_tc=True): self.unimodel.appendRow(id_uni, uni) self.uniview.resizeColumnsToContents() self.changed = True - # self.unisel.select(idx, QtCore.QItemSelectionModel.ClearAndSelect | QtCore.QItemSelectionModel.Rows) + # self.unisel.select(idx, QtCore.QItemSelectionModel.SelectionFlag.ClearAndSelect | QtCore.QItemSelectionModel.SelectionFlag.Rows) idx = self.unimodel.getIndexID(id_uni) self.uniview.selectRow(idx.row()) self.uniview.scrollToBottom() @@ -4682,7 +4682,7 @@ def do_calc(self, calcT, phases={}, out={}, run_tc=True): self.unimodel.appendRow(id_uni, uni) self.uniview.resizeColumnsToContents() self.changed = True - # self.unisel.select(idx, QtCore.QItemSelectionModel.ClearAndSelect | QtCore.QItemSelectionModel.Rows) + # self.unisel.select(idx, QtCore.QItemSelectionModel.SelectionFlag.ClearAndSelect | QtCore.QItemSelectionModel.SelectionFlag.Rows) idx = self.unimodel.getIndexID(id_uni) self.uniview.selectRow(idx.row()) self.uniview.scrollToBottom() @@ -4895,7 +4895,7 @@ def data(self, index, role=QtCore.Qt.ItemDataRole.DisplayRole): return None inv = self.ps.invpoints[self.invlist[index.row()]] # highlight not finished invpoints - move to plot ??? - # if role == QtCore.Qt.ForegroundRole: + # if role == QtCore.Qt.ItemDataRole.ForegroundRole: # all_uni = inv.all_unilines() # isnew1, id = self.ps.getiduni(UniLine(phases=all_uni[0][0], out=all_uni[0][1])) # isnew2, id = self.ps.getiduni(UniLine(phases=all_uni[1][0], out=all_uni[1][1])) @@ -5244,10 +5244,7 @@ def __init__(self, builder, version, copyright, parent=None): author.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter) swinfo = QtWidgets.QLabel( - "Python:{} Qt:{} PyQt:{}".format( - sys.version.split()[0], QT_VERSION_STR, PYQT_VERSION_STR - ) - ) + f"Python:{sys.version.split()[0]} {QTPY_API} {QT_VERSION}") swinfo.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter) github = QtWidgets.QLabel( diff --git a/pypsbuilder/ui/compile_ui.sh b/pypsbuilder/ui/compile_ui.sh index ce16b67..b0c2f77 100755 --- a/pypsbuilder/ui/compile_ui.sh +++ b/pypsbuilder/ui/compile_ui.sh @@ -7,3 +7,4 @@ pyuic6 adduni.ui > ../ui_adduni.py pyuic6 addinv.ui > ../ui_addinv.py pyuic6 uniguess.ui > ../ui_uniguess.py +# do not forget to replace PyQt6 with qtpy in all generated .py files diff --git a/pypsbuilder/ui_addinv.py b/pypsbuilder/ui_addinv.py index 82faa5a..bf6430e 100644 --- a/pypsbuilder/ui_addinv.py +++ b/pypsbuilder/ui_addinv.py @@ -6,7 +6,7 @@ # run again. Do not edit this file unless you know what you are doing. -from PyQt6 import QtCore, QtGui, QtWidgets +from qtpy import QtCore, QtGui, QtWidgets class Ui_AddInv(object): diff --git a/pypsbuilder/ui_adduni.py b/pypsbuilder/ui_adduni.py index 110ef15..7b28d45 100644 --- a/pypsbuilder/ui_adduni.py +++ b/pypsbuilder/ui_adduni.py @@ -6,7 +6,7 @@ # run again. Do not edit this file unless you know what you are doing. -from PyQt6 import QtCore, QtGui, QtWidgets +from qtpy import QtCore, QtGui, QtWidgets class Ui_AddUni(object): diff --git a/pypsbuilder/ui_ptbuilder.py b/pypsbuilder/ui_ptbuilder.py index 05633ff..3d2d0ef 100644 --- a/pypsbuilder/ui_ptbuilder.py +++ b/pypsbuilder/ui_ptbuilder.py @@ -6,7 +6,7 @@ # run again. Do not edit this file unless you know what you are doing. -from PyQt6 import QtCore, QtGui, QtWidgets +from qtpy import QtCore, QtGui, QtWidgets class Ui_PTBuilder(object): diff --git a/pypsbuilder/ui_pxbuilder.py b/pypsbuilder/ui_pxbuilder.py index 1e6768a..a836aca 100644 --- a/pypsbuilder/ui_pxbuilder.py +++ b/pypsbuilder/ui_pxbuilder.py @@ -6,7 +6,7 @@ # run again. Do not edit this file unless you know what you are doing. -from PyQt6 import QtCore, QtGui, QtWidgets +from qtpy import QtCore, QtGui, QtWidgets class Ui_PXBuilder(object): diff --git a/pypsbuilder/ui_txbuilder.py b/pypsbuilder/ui_txbuilder.py index 691455c..a177d4e 100644 --- a/pypsbuilder/ui_txbuilder.py +++ b/pypsbuilder/ui_txbuilder.py @@ -6,7 +6,7 @@ # run again. Do not edit this file unless you know what you are doing. -from PyQt6 import QtCore, QtGui, QtWidgets +from qtpy import QtCore, QtGui, QtWidgets class Ui_TXBuilder(object): diff --git a/pypsbuilder/ui_uniguess.py b/pypsbuilder/ui_uniguess.py index 77f768f..22ba059 100644 --- a/pypsbuilder/ui_uniguess.py +++ b/pypsbuilder/ui_uniguess.py @@ -6,7 +6,7 @@ # run again. Do not edit this file unless you know what you are doing. -from PyQt6 import QtCore, QtGui, QtWidgets +from qtpy import QtCore, QtGui, QtWidgets class Ui_UniGuess(object):