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

Use PySide6 #9586

Open
wants to merge 2 commits into
base: main
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
5 changes: 2 additions & 3 deletions .github/actions/install_dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ name: install_dependencies
description: Installs dependencies for the pip build

inputs:
os:
required: true

os:
required: true

runs:
using: "composite"
Expand Down
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 @@ -155,6 +155,10 @@ jobs:
with:
os: ${{ matrix.os }}

- 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 @@ -31,6 +31,10 @@ jobs:
with:
fetch-depth: 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 @@ -25,6 +25,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_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 @@ -25,6 +25,10 @@ jobs:
with:
fetch-depth: 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 @@ -28,6 +28,10 @@ jobs:
with:
fetch-depth: 0

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

- name: Set up Python
uses: actions/setup-python@v5
with:
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ dependencies = [
"python-dateutil",
"python-multipart", # extra dependency for fastapi
"pyyaml",
"qtpy",
"PySide6",
"requests",
"resfo",
"scipy >= 1.10.1",
Expand Down Expand Up @@ -126,6 +126,7 @@ style = [
]
types = [
"mypy",
"pyside6-stubs",
"types-lxml",
"types-requests",
"types-PyYAML",
Expand Down Expand Up @@ -248,7 +249,7 @@ typeCheckingMode = "standard"
pythonVersion = "3.11"

[tool.pyright.defineConstant]
PYSIDE6 = false
PYQT5 = true
PYSIDE6 = true
PYQT5 = false
PYSIDE2 = false
PYQT6 = false
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 PySide6.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 PySide6.QtCore import QSize, Qt
from PySide6.QtGui import QFont
from PySide6.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
2 changes: 1 addition & 1 deletion src/ert/gui/ertnotifier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from qtpy.QtCore import QObject, Signal, Slot
from PySide6.QtCore import QObject, Signal, 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 PySide6.QtCore import Qt
from PySide6.QtGui import QCursor
from PySide6.QtWidgets import QApplication
from typing import Any
from collections.abc import Callable

Expand Down
6 changes: 3 additions & 3 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 PySide6.QtCore import QMargins, Qt
from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QHBoxLayout, QToolButton, QWidget

from ert.gui.ertwidgets import ClosableDialog
from ert.gui.ertwidgets.analysismodulevariablespanel import AnalysisModuleVariablesPanel
Expand Down
31 changes: 19 additions & 12 deletions src/ert/gui/ertwidgets/analysismodulevariablespanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
from typing import cast, get_args

from annotated_types import Ge, Gt, Le
from qtpy.QtCore import Qt
from qtpy.QtWidgets import (
from PySide6.QtCore import Qt
from PySide6.QtWidgets import (
QCheckBox,
QComboBox,
QDoubleSpinBox,
QFormLayout,
QFrame,
QHBoxLayout,
QLabel,
QLayout,
QWidget,
)

Expand Down Expand Up @@ -52,7 +51,7 @@ def __init__(self, analysis_module: AnalysisModule, ensemble_size: int):
):
metadata = analysis_module.model_fields[variable_name]
layout.addRow(
metadata.title,
metadata.title if metadata.title else "",
self.createDoubleSpinBox(
variable_name,
analysis_module.__getattribute__(variable_name),
Expand Down Expand Up @@ -105,7 +104,8 @@ def __init__(self, analysis_module: AnalysisModule, ensemble_size: int):

localization_frame = QFrame()
localization_frame.setLayout(QHBoxLayout())
lf_layout = cast(QLayout, localization_frame.layout())
lf_layout = localization_frame.layout()
assert lf_layout is not None
lf_layout.setContentsMargins(0, 0, 0, 0)

metadata = analysis_module.model_fields[
Expand All @@ -115,7 +115,7 @@ 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 @@ -154,8 +154,8 @@ def update_inversion_algorithm(
@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 Down Expand Up @@ -189,14 +189,21 @@ def valueChanged(
variable_name: str,
variable_type: type[bool] | type[float],
variable_control: QWidget,
value: float,
) -> None:
value: bool | float | None = None
if value is not None:
self.analysis_module.__setattr__(variable_name, value) # noqa: PLC2801

def valueChangedCheckBox(
self,
variable_name: str,
variable_type: type[bool] | type[float],
variable_control: QWidget,
) -> None:
value = 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
10 changes: 5 additions & 5 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 PySide6.QtCore import QPoint, QSize, Qt
from PySide6.QtGui import QIcon
from PySide6.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,7 +162,7 @@ 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()
Expand Down
35 changes: 16 additions & 19 deletions src/ert/gui/ertwidgets/closabledialog.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from collections.abc import Callable
from typing import TYPE_CHECKING, cast

from qtpy.QtCore import Qt
from qtpy.QtWidgets import QDialog, QHBoxLayout, QPushButton, QVBoxLayout, QWidget
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QDialog, QHBoxLayout, QPushButton, QVBoxLayout, QWidget

if TYPE_CHECKING:
from qtpy.QtGui import QKeyEvent
from qtpy.QtWidgets import QT_SLOT
from PySide6.QtGui import QKeyEvent


class ClosableDialog(QDialog):
def __init__(
self, title: str | None, widget: QWidget, parent: QWidget | None = None
) -> None:
QDialog.__init__(self, parent)
self.setWindowTitle(title)
self.setWindowTitle(title if title else "")
self.setModal(True)
self.setWindowFlags(self.windowFlags() | Qt.WindowType.CustomizeWindowHint)
self.setWindowFlags(
self.windowFlags()
& ~Qt.WindowFlags(Qt.WindowType.WindowContextHelpButtonHint)
)
self.setWindowFlags(
self.windowFlags() & ~Qt.WindowFlags(Qt.WindowType.WindowCloseButtonHint)
)
self.setWindowFlag(Qt.WindowType.CustomizeWindowHint, True)
self.setWindowFlag(Qt.WindowType.WindowContextHelpButtonHint, False)
self.setWindowFlag(Qt.WindowType.WindowCloseButtonHint, False)

layout = QVBoxLayout()
layout.addWidget(widget, stretch=1)
Expand All @@ -47,18 +42,20 @@ def disableCloseButton(self) -> None:
def enableCloseButton(self) -> None:
self.close_button.setEnabled(True)

def keyPressEvent(self, a0: QKeyEvent | None) -> None:
if self.close_button.isEnabled() or a0 is None or a0.key() != Qt.Key.Key_Escape:
QDialog.keyPressEvent(self, a0)
def keyPressEvent(self, arg__1: QKeyEvent) -> None:
if self.close_button.isEnabled() or arg__1.key() != Qt.Key.Key_Escape:
QDialog.keyPressEvent(self, arg__1)

def addButton(self, caption: str, listener: QT_SLOT) -> QPushButton:
def addButton(self, caption: str, listener: Callable[..., None]) -> QPushButton:
button = QPushButton(caption)
button.setObjectName(str(caption).capitalize())
self.__button_layout.insertWidget(1, button)
button.clicked.connect(listener)
return button

def toggleButton(self, caption: str, enabled: bool) -> None:
button = self.findChild(QPushButton, str(caption).capitalize())
button = cast(
QPushButton, self.findChild(QPushButton, str(caption).capitalize())
)
if button is not None:
button.setEnabled(enabled)
Loading
Loading