Skip to content

Commit

Permalink
Update to pyqt6
Browse files Browse the repository at this point in the history
  • Loading branch information
foarsitter committed Dec 19, 2023
1 parent 6016a6c commit d164e3a
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- { os: macos-latest, python-version: '3.11' }
env:
DISPLAY: ':99.0'
PYTEST_QT_API: 'pyqt5'
PYTEST_QT_API: 'PyQt6'
steps:
- uses: actions/checkout@v4
- name: Install Poetry
Expand Down
43 changes: 23 additions & 20 deletions decide/qt/inputwindow/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import sys

import requests
from PyQt5 import QtWidgets, QtGui
from PyQt6 import QtWidgets, QtGui
from PyQt6.QtGui import QAction
from PyQt6.QtWidgets import QMainWindow, QHBoxLayout, QVBoxLayout, QTabWidget, QWidget, QMenuBar, QFileDialog, \
QErrorMessage, QMessageBox, QApplication

from decide import log_filename, input_folder
from decide.data.reader import InputDataFile
Expand All @@ -21,7 +24,7 @@
from decide.qt.utils import show_user_error


class InputWindow(QtWidgets.QMainWindow):
class InputWindow(QMainWindow):
def __init__(self, main_window: DecideMainWindow = None, *args, **kwargs):
super(InputWindow, self).__init__(*args, **kwargs)

Expand All @@ -31,10 +34,10 @@ def __init__(self, main_window: DecideMainWindow = None, *args, **kwargs):
# refresh the main windows after editing
self.main_window = main_window

self.main = QtWidgets.QHBoxLayout()
self.left = QtWidgets.QVBoxLayout()
self.main = QHBoxLayout()
self.left = QVBoxLayout()

self.tabs = QtWidgets.QTabWidget()
self.tabs = QTabWidget()

self.actor_widget = ActorWidget()
self.issue_widget = IssueWidget()
Expand All @@ -53,10 +56,10 @@ def __init__(self, main_window: DecideMainWindow = None, *args, **kwargs):
self.main.addLayout(self.left)
self.main.addWidget(self.tabs)

q = QtWidgets.QWidget()
q = QWidget()
q.setLayout(self.main)

self.menubar = QtWidgets.QMenuBar(self)
self.menubar = QMenuBar(self)

self.init_menu()
self.setCentralWidget(q)
Expand All @@ -77,16 +80,16 @@ def init_menu(self):
file_menu = self.menubar.addMenu("File")
example_menu = self.menubar.addMenu("Examples")

load_kopenhagen = QtWidgets.QAction("&load Kopenhagen", self.menubar)
load_kopenhagen = QAction("&load Kopenhagen", self.menubar)
load_kopenhagen.triggered.connect(self.load_copenhagen)

load_cop = QtWidgets.QAction("&load Parijs", self.menubar)
load_cop = QAction("&load Parijs", self.menubar)
load_cop.triggered.connect(self.load_cop21)

open_action = QtWidgets.QAction("Open", self.menubar)
open_action = QAction("Open", self.menubar)
open_action.triggered.connect(self.open_dialog)

save_action = QtWidgets.QAction("Save", self.menubar)
save_action = QAction("Save", self.menubar)
save_action.triggered.connect(self.save_location)

example_menu.addAction(load_kopenhagen)
Expand Down Expand Up @@ -131,13 +134,13 @@ def load_input_file(self, file_path):

def open_dialog(self):

file_name, _ = QtWidgets.QFileDialog.getOpenFileName(self, "Select input data")
file_name, _ = QFileDialog.getOpenFileName(self, "Select input data")

if file_name:
try:
self.load(file_name)
except Exception as ex:
error_dialog = QtWidgets.QErrorMessage(self)
error_dialog = QErrorMessage(self)
error_dialog.showMessage(str(ex))

raise ex
Expand All @@ -146,22 +149,22 @@ def save_location(self):

if self.input_filename:

button_reply = QtWidgets.QMessageBox.question(
button_reply = QMessageBox.question(
self,
"Save",
"Overwrite existing file {}".format(
self.input_filename
),
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.No,
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
QMessageBox.StandardButton.No,
)
else:
button_reply = QtWidgets.QMessageBox.No
button_reply = QMessageBox.StandardButton.No

if button_reply == QtWidgets.QMessageBox.Yes:
if button_reply == QMessageBox.StandardButton.Yes:
file_name = self.input_filename
else:
file_name, _ = QtWidgets.QFileDialog.getSaveFileName(self, "Select input data")
file_name, _ = QFileDialog.getSaveFileName(self, "Select input data")

if file_name:
self.save(file_name)
Expand Down Expand Up @@ -352,7 +355,7 @@ def register_app(ex):

# sys.excepthook = exception_hook

app = QtWidgets.QApplication(sys.argv)
app = QApplication(sys.argv)
app.setQuitOnLastWindowClosed(True)

input_window = InputWindow()
Expand Down
9 changes: 5 additions & 4 deletions decide/qt/inputwindow/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import uuid
from decimal import Decimal

from PyQt5 import QtWidgets
from PyQt6 import QtWidgets
from PyQt6.QtWidgets import QLabel
from typesystem.base import ValidationResult

from decide.data import types
Expand Down Expand Up @@ -199,10 +200,10 @@ def __init__(self, actor: ActorInputModel, issue: IssueInputModel):
self.actor = actor
self.issue = issue

self.actor_input = QtWidgets.QLabel(actor.name)
self.issue_input = QtWidgets.QLabel(issue.name)
self.actor_input = QLabel(actor.name)
self.issue_input = QLabel(issue.name)

self.power_input = QtWidgets.QLabel(str(actor.power))
self.power_input = QLabel(str(actor.power))

self.position_input = DoubleInput()
self.position_input.valueChanged.connect(self.set_position)
Expand Down
4 changes: 2 additions & 2 deletions decide/qt/inputwindow/tests/test_comment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from PyQt5 import QtCore
from PyQt6 import QtCore

from decide.qt.inputwindow.gui import InputWindow, register_app

Expand All @@ -10,6 +10,6 @@ def test_actor_widget_add_button(qtbot):
assert x.actor_widget._row_pointer == 1, 'Only the heading is shown'
assert x.actor_widget.grid_layout.rowCount() == 1

qtbot.mouseClick(x.actor_widget.add_button, QtCore.Qt.LeftButton)
qtbot.mouseClick(x.actor_widget.add_button, QtCore.Qt.MouseButton.LeftButton)

assert x.actor_widget.grid_layout.rowCount() == 2, 'The heading and an empty row is shown'
10 changes: 5 additions & 5 deletions decide/qt/inputwindow/widgets.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from collections import defaultdict
from decimal import Decimal

from PyQt5 import QtWidgets, QtCore
from PyQt5.QtWidgets import QListWidgetItem
from PyQt6 import QtWidgets, QtCore
from PyQt6.QtWidgets import QListWidgetItem

from decide.data.types import ActorIssue
from decide.qt.inputwindow import signals
Expand All @@ -25,7 +25,7 @@ def __init__(self, title, btn=True):
self.scroll_area.setWidget(self.scroll_area_widget)

self.grid_layout = QtWidgets.QGridLayout(self.scroll_area_widget)
self.grid_layout.setAlignment(QtCore.Qt.AlignTop)
self.grid_layout.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop)

self.layout_container = QtWidgets.QVBoxLayout()
self.layout_container.addWidget(self.scroll_area)
Expand Down Expand Up @@ -367,7 +367,7 @@ def __init__(self, actor_issue_box: ActorIssueWidget, *args, **kwargs):

self.choices_list_widget = QtWidgets.QListWidget(self)
self.choices_list_widget.setMaximumHeight(100)
self.choices_list_widget.setSelectionMode(QtWidgets.QListWidget.MultiSelection)
self.choices_list_widget.setSelectionMode(QtWidgets.QListWidget.SelectionMode.MultiSelection)
self.choices_list_widget.itemSelectionChanged.connect(self.redraw)

self.choices_list_widget_items = {}
Expand All @@ -382,7 +382,7 @@ def __init__(self, actor_issue_box: ActorIssueWidget, *args, **kwargs):
self.scroll_area.setWidget(self.scroll_area_widget)

self.grid_layout = QtWidgets.QGridLayout(self.scroll_area_widget)
self.grid_layout.setAlignment(QtCore.Qt.AlignTop)
self.grid_layout.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop)

self.container.addWidget(self.scroll_area)

Expand Down
10 changes: 5 additions & 5 deletions decide/qt/mainwindow/errordialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import sys

import requests
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QMessageBox, QDialog
from PyQt6 import QtWidgets
from PyQt6.QtWidgets import QMessageBox, QDialog

from decide import log_filename
from decide.qt.mainwindow.settings import ProgramSettings
Expand Down Expand Up @@ -89,14 +89,14 @@ def send_error_report(self):
self,
"Confirm sending",
"Are you sure you want to send the message with the attachments?",
QMessageBox.Yes | QMessageBox.No,
QMessageBox.No,
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
QMessageBox.StandardButton.No,
)

settings = None
input_data = None

if confirm == QMessageBox.Yes:
if confirm == QMessageBox.StandardButton.Yes:

files = {}

Expand Down
4 changes: 2 additions & 2 deletions decide/qt/mainwindow/errorgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import sys
from typing import List

from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QDialog
from PyQt6 import QtWidgets
from PyQt6.QtWidgets import QDialog
from decide import log_filename, input_folder
from decide.data.reader import InputDataFile
from decide.qt.utils import exception_hook
Expand Down
22 changes: 11 additions & 11 deletions decide/qt/mainwindow/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import xml.etree.cElementTree as ET
from shutil import copyfile

from PyQt5 import QtCore
from PyQt5 import QtWidgets
from PyQt6 import QtCore
from PyQt6 import QtWidgets
from decide import log_filename
from decide.cli import init_output_directory
from decide.data.modelfactory import ModelFactory
Expand Down Expand Up @@ -237,13 +237,13 @@ def init_ui(self):

overview_box = QtWidgets.QGroupBox("Overview")
overview_box.setLayout(self.overview_widget)
self.overview_widget.setAlignment(QtCore.Qt.AlignTop)
self.overview_widget.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop)

right = QtWidgets.QVBoxLayout()
right.addWidget(settings_box, 1)
right.addWidget(overview_box, 1)
right.addWidget(self.start, 1)
right.setAlignment(QtCore.Qt.AlignTop)
right.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop)

main.addLayout(left, 1)
main.addLayout(right, 1)
Expand Down Expand Up @@ -418,11 +418,11 @@ def finished(self, output_directory):
self,
"Done",
"Done running the calculations. Open the result directory?",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.StandardButton.Yes | QtWidgets.QMessageBox.StandardButton.No,
QtWidgets.QMessageBox.StandardButton.No,
)

if button_reply == QtWidgets.QMessageBox.Yes:
if button_reply == QtWidgets.QMessageBox.StandardButton.Yes:
utils.open_file_natively(output_directory)

def _clean_progress_dialog(self):
Expand All @@ -443,11 +443,11 @@ def run(self):
self,
"Output directory already exists",
"The given directory {} already exists. Proceed?".format(output_dir),
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.StandardButton.Yes | QtWidgets.QMessageBox.StandardButton.No,
QtWidgets.QMessageBox.StandardButton.No,
)

if button_reply == QtWidgets.QMessageBox.No:
if button_reply == QtWidgets.QMessageBox.StandardButton.No:
return

self.setWindowTitle("Decide Exchange Model")
Expand Down Expand Up @@ -516,7 +516,7 @@ def main():

sys.excepthook = utils.exception_hook

qtapp.exec_()
qtapp.exec()


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion decide/qt/mainwindow/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from decimal import Decimal

from PyQt5 import QtWidgets
from PyQt6 import QtWidgets


def clear_layout(layout):
Expand Down
4 changes: 2 additions & 2 deletions decide/qt/mainwindow/settings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import xml.etree.cElementTree as ET

from PyQt5 import QtCore
from PyQt5 import QtWidgets
from PyQt6 import QtCore
from PyQt6 import QtWidgets
from decide import decide_base_path
from decide.cli import float_range

Expand Down
Loading

0 comments on commit d164e3a

Please sign in to comment.