Skip to content

Commit

Permalink
Upgrade to PyQt6
Browse files Browse the repository at this point in the history
Upgrade from qtpy with pyqt5 to PyQt6.
Using PyQt6 directly should give us better typing.
PySide6 was tested, but was unstable.
  • Loading branch information
JHolba committed Jan 24, 2025
1 parent 02df6ee commit fa0dce3
Show file tree
Hide file tree
Showing 133 changed files with 927 additions and 820 deletions.
16 changes: 16 additions & 0 deletions .github/actions/install_dependencies_qt/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: install_dependencies_qt
description: Installs dependencies for qt

inputs:
os:
required: true

runs:
using: "composite"
steps:
- name: Install Ubuntu dependencies
if: inputs.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install libegl1
shell: bash
4 changes: 4 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ jobs:
fetch-depth: 0
filter: tree:0

- uses: ./.github/actions/install_dependencies_qt
with:
os: ${{ matrix.os }}

- name: Install pandoc
run: |
sudo apt install pandoc
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_dependencies_qt
with:
os: ubuntu-latest
- uses: actions/setup-python@v5
with:
python-version: '3.12'
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/run_ert_test_data_setups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jobs:
fetch-depth: 0
filter: tree:0

- uses: ./.github/actions/install_dependencies_qt
with:
os: ${{ matrix.os }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test_ert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ jobs:
submodules: true
lfs: true

- uses: ./.github/actions/install_dependencies_qt
with:
os: ${{ inputs.os }}

- uses: actions/setup-python@v5
id: setup_python
with:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test_ert_with_flow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/install_dependencies_qt
with:
os: ${{ inputs.os }}

- uses: actions/setup-python@v5
id: setup_python
with:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test_ert_with_slurm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/install_dependencies_qt
with:
os: ${{ inputs.os }}

- uses: actions/setup-python@v5
id: setup_python
with:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test_everest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ jobs:
fetch-depth: 0
filter: tree:0

- uses: ./.github/actions/install_dependencies_qt
with:
os: ${{ inputs.os }}

- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v5
with:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test_semeio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ jobs:
fetch-depth: 0
filter: tree:0

- uses: ./.github/actions/install_dependencies_qt
with:
os: ubuntu-latest

- name: Set up Python
uses: actions/setup-python@v5
with:
Expand Down
38 changes: 14 additions & 24 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
[build-system]
requires = [
"setuptools",
"setuptools_scm>=8.1",
]
requires = ["setuptools", "setuptools_scm>=8.1"]
build-backend = "setuptools.build_meta"

[project]
name = "ert"
authors = [
{ name = "Equinor ASA", email = "[email protected]" },
]
authors = [{ name = "Equinor ASA", email = "[email protected]" }]
description = "Ensemble based Reservoir Tool (ERT)"
requires-python = ">=3.11"
readme = "README.md"
Expand Down Expand Up @@ -42,7 +37,7 @@ dependencies = [
"matplotlib",
"netCDF4",
"numpy<2",
"openpyxl", # extra dependency for pandas (excel)
"openpyxl", # extra dependency for pandas (excel)
"opentelemetry-api",
"opentelemetry-sdk",
"opentelemetry-instrumentation-fastapi",
Expand All @@ -54,19 +49,18 @@ dependencies = [
"pluggy>=1.3.0",
"polars>=1",
"psutil",
"pyarrow", # extra dependency for pandas (parquet)
"pyarrow", # extra dependency for pandas (parquet)
"pydantic > 2",
"PyQt5",
"python-dateutil",
"python-multipart", # extra dependency for fastapi
"python-multipart", # extra dependency for fastapi
"pyyaml",
"pyzmq",
"qtpy",
"pyqt6",
"requests",
"resfo",
"scipy >= 1.10.1, < 1.15",
"seaborn",
"tables", # extra dependency for pandas (hdf5)
"tables", # extra dependency for pandas (hdf5)
"tabulate",
"tqdm>=4.62.0",
"typing_extensions>=4.5",
Expand Down Expand Up @@ -122,11 +116,9 @@ dev = [
"sphinx-autoapi",
"sphinx-copybutton",
"sphinxcontrib.datatemplates",
"json-schema-for-humans"
]
style = [
"pre-commit",
"json-schema-for-humans",
]
style = ["pre-commit"]
types = [
"mypy",
"types-lxml",
Expand All @@ -137,7 +129,7 @@ types = [
"types-docutils",
"types-tqdm",
"types-psutil",
"types-setuptools"
"types-setuptools",
]
everest = [
"progressbar2",
Expand All @@ -152,7 +144,7 @@ everest = [
]

[tool.setuptools]
package-dir = {"" = "src"}
package-dir = { "" = "src" }
platforms = ["all"]

[tool.setuptools.package-data]
Expand Down Expand Up @@ -239,9 +231,7 @@ allow-dunder-method-names = [
]

[tool.ruff.lint.flake8-bugbear]
extend-immutable-calls = [
"fastapi.Depends",
]
extend-immutable-calls = ["fastapi.Depends"]

[tool.pyright]
include = ["src"]
Expand All @@ -252,6 +242,6 @@ pythonVersion = "3.11"

[tool.pyright.defineConstant]
PYSIDE6 = false
PYQT5 = true
PYQT5 = false
PYSIDE2 = false
PYQT6 = false
PYQT6 = true
2 changes: 1 addition & 1 deletion src/ert/ensemble_evaluator/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from datetime import datetime
from typing import Any, TypeVar, cast, get_args

from qtpy.QtGui import QColor
from PyQt6.QtGui import QColor
from typing_extensions import TypedDict

from _ert.events import (
Expand Down
15 changes: 5 additions & 10 deletions src/ert/gui/about_dialog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from qtpy.QtCore import QSize, Qt
from qtpy.QtGui import QFont
from qtpy.QtWidgets import (
from PyQt6.QtCore import QSize, Qt
from PyQt6.QtGui import QFont
from PyQt6.QtWidgets import (
QDialog,
QHBoxLayout,
QLabel,
Expand All @@ -19,13 +19,8 @@ def __init__(self, parent: QWidget | None) -> None:
self.setWindowTitle("About")
self.setModal(True)
self.setFixedSize(QSize(600, 480))
self.setWindowFlags(
self.windowFlags()
& ~Qt.WindowFlags(Qt.WindowType.WindowContextHelpButtonHint)
)
self.setWindowFlags(
self.windowFlags() & ~Qt.WindowFlags(Qt.WindowType.WindowCloseButtonHint)
)
self.setWindowFlag(Qt.WindowType.WindowContextHelpButtonHint, False)
self.setWindowFlag(Qt.WindowType.WindowCloseButtonHint, False)

main_layout = QVBoxLayout()

Expand Down
4 changes: 3 additions & 1 deletion src/ert/gui/ertnotifier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from qtpy.QtCore import QObject, Signal, Slot
from PyQt6.QtCore import QObject
from PyQt6.QtCore import pyqtSignal as Signal
from PyQt6.QtCore import pyqtSlot as Slot

from ert.storage import Ensemble, Storage

Expand Down
6 changes: 3 additions & 3 deletions src/ert/gui/ertwidgets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# isort: skip_file
from qtpy.QtCore import Qt
from qtpy.QtGui import QCursor
from qtpy.QtWidgets import QApplication
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QCursor
from PyQt6.QtWidgets import QApplication
from typing import Any
from collections.abc import Callable

Expand Down
8 changes: 4 additions & 4 deletions src/ert/gui/ertwidgets/analysismoduleedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from typing import TYPE_CHECKING

from qtpy.QtCore import QMargins, Qt
from qtpy.QtGui import QIcon
from qtpy.QtWidgets import QHBoxLayout, QToolButton, QWidget
from PyQt6.QtCore import QMargins, Qt
from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import QHBoxLayout, QToolButton, QWidget

from ert.gui.ertwidgets import ClosableDialog
from ert.gui.ertwidgets.analysismodulevariablespanel import AnalysisModuleVariablesPanel
Expand Down Expand Up @@ -45,4 +45,4 @@ def showVariablesPopup(self) -> None:
variable_dialog,
self.parent(), # type: ignore
)
dialog.exec_()
dialog.exec()
36 changes: 11 additions & 25 deletions src/ert/gui/ertwidgets/analysismodulevariablespanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from typing import cast, get_args

from annotated_types import Ge, Gt, Le
from qtpy.QtCore import Qt
from qtpy.QtWidgets import (
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import (
QCheckBox,
QComboBox,
QDoubleSpinBox,
Expand Down Expand Up @@ -75,9 +75,8 @@ def __init__(self, analysis_module: AnalysisModule, ensemble_size: int):
local_checkbox.setObjectName("localization")
local_checkbox.clicked.connect(
partial(
self.valueChanged,
self.valueChangedCheckBox,
"localization",
bool,
local_checkbox,
)
)
Expand Down Expand Up @@ -112,8 +111,8 @@ def update_inversion_algorithm(self, text: InversionTypeES) -> None:
@staticmethod
def create_horizontal_line() -> QFrame:
hline = QFrame()
hline.setFrameShape(QFrame.HLine)
hline.setFrameShadow(QFrame.Sunken)
hline.setFrameShape(QFrame.Shape.HLine)
hline.setFrameShadow(QFrame.Shadow.Sunken)
hline.setFixedHeight(20)
return hline

Expand All @@ -137,24 +136,11 @@ def createDoubleSpinBox(

spinner.setSingleStep(step_length)
spinner.setValue(variable_value)
spinner.valueChanged.connect(
partial(self.valueChanged, variable_name, float, spinner)
)
spinner.valueChanged.connect(partial(self.valueChangedSpinner, variable_name))
return spinner

def valueChanged(
self,
variable_name: str,
variable_type: type[bool] | type[float],
variable_control: QWidget,
) -> None:
value: bool | float | None = None
if variable_type == bool:
assert isinstance(variable_control, QCheckBox)
value = variable_control.isChecked()
elif variable_type == float:
assert isinstance(variable_control, QDoubleSpinBox)
value = variable_control.value()

if value is not None:
self.analysis_module.__setattr__(variable_name, value) # noqa: PLC2801
def valueChangedSpinner(self, name: str, value: float) -> None:
setattr(self.analysis_module, name, value)

def valueChangedCheckBox(self, name: str, control: QCheckBox) -> None:
setattr(self.analysis_module, name, control.isChecked())
12 changes: 6 additions & 6 deletions src/ert/gui/ertwidgets/checklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from typing import TYPE_CHECKING

from qtpy.QtCore import QPoint, QSize, Qt
from qtpy.QtGui import QIcon
from qtpy.QtWidgets import (
from PyQt6.QtCore import QPoint, QSize, Qt
from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import (
QAbstractItemView,
QHBoxLayout,
QLabel,
Expand Down Expand Up @@ -44,7 +44,7 @@ def __init__(

self._list = QListWidget()
self._list.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
self._list.setSelectionMode(QAbstractItemView.ExtendedSelection)
self._list.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection)

self._search_box = SearchBox()

Expand Down Expand Up @@ -162,13 +162,13 @@ def uncheckSelected(self) -> None:

def showContextMenu(self, point: QPoint) -> None:
p = self._list.mapToGlobal(point)
menu = QMenu()
menu = QMenu(self)
check_selected = menu.addAction("Check selected")
uncheck_selected = menu.addAction("Uncheck selected")
menu.addSeparator()
clear_selection = menu.addAction("Clear selection")

selected_item = menu.exec_(p)
selected_item = menu.exec(p)

if selected_item == check_selected:
self.checkSelected()
Expand Down
Loading

0 comments on commit fa0dce3

Please sign in to comment.