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

Switch to PySide6 to make MaD GUI usabel on M1/M2 architecture #26

Draft
wants to merge 9 commits into
base: arne-dataset-plugin
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions .github/workflows/test_and_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test and Lint

on:
push:
branches: [ main ]
branches: '**'
pull_request:
branches: [ main ]

Expand All @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.8]
python-version: [3.10.15]

steps:
- uses: actions/checkout@v2
Expand Down
10 changes: 5 additions & 5 deletions docs/troubleshooting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ If you get an error like this, see the next section.
TypeError: cannot unpack non-iterable NoneType object


PySide2-uic not found
PySide6-uic not found
*********************

.. note::
Expand All @@ -73,16 +73,16 @@ PySide2-uic not found
.. code-block:: console

"...mad_gui/components/dialogs/....py", line .., in <module>
FileNotFoundError: Probably python did not find pyside2-uic
FileNotFoundError: Probably python did not find pyside6-uic

Apparently python can't find pyside2-uic, this can be solved like this.
Apparently python can't find pyside6-uic, this can be solved like this.

- In your terminal / command line interface activate the environment you want to use (e.g. `conda activate mad_gui`)
- Find out, where the python installation is by using `where python` (Windows) or `which python` (Unix)
- That folder should also keep a folder `Scripts`, go there and copy `pyside2-uic` from there to the parent folder, where also python is
- That folder should also keep a folder `Scripts`, go there and copy `pyside6-uic` from there to the parent folder, where also python is
- Try again

Then copy pyside2-uic from the folder `Scripts` to the location where also your python executable is (should be the
Then copy pyside6-uic from the folder `Scripts` to the location where also your python executable is (should be the
parent directory).


Expand Down
12 changes: 6 additions & 6 deletions dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ def get_dst_path():
return Path(venv_path) / "Lib/site-packages/mad_gui/qt_designer/build/"
if arch in ["Linux", "Darwin"]:
python_dirs = os.listdir(Path(venv_path) / "lib/")
warnings.warn(
f"dodo.py: Assuming your python installation is in {Path(venv_path)}/lib/{python_dirs[0]}"
)
warnings.warn(f"dodo.py: Assuming your python installation is in {Path(venv_path)}/lib/{python_dirs[0]}")
return Path(venv_path) / "lib" / python_dirs[0] / "site-packages/mad_gui/qt_designer/build/"
raise ValueError("What operating system is this?!")

Expand All @@ -77,15 +75,17 @@ def convert_ui_to_py():
print("\n")
for file in ui_files:
if platform.system() == "Darwin":
pyside_path = f"{venv_path}/bin/pyside2-uic"
pyside_path = f"{venv_path}/bin/pyside6-uic"
else:
pyside_path = "pyside2-uic"
pyside_path = "pyside6-uic"

result = os.popen(f"{pyside_path} -h")
print(f"Result: {result}")
print(f"Converting from: {dst_path.parent}{os.sep}{file}")
print(f"To: {dst_path}{os.sep}{file.split('.')[0]}.py")
result = os.popen(f"{pyside_path} -o {dst_path}{os.sep}{file.split('.')[0]}.py {dst_path.parent}{os.sep}{file}")
result = os.popen(
f"{pyside_path} -o {dst_path}{os.sep}{file.split('.')[0]}.py {dst_path.parent}{os.sep}{file}"
)

print(
"Info: These conversions should have taken place in the virtual environment you are going to use with "
Expand Down
4 changes: 2 additions & 2 deletions mad_gui/components/dialogs/data_selector.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Select which kind of data should be loaded/saved."""

from PySide2.QtCore import Qt
from PySide2.QtWidgets import QCheckBox, QDialog, QDialogButtonBox, QVBoxLayout
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QCheckBox, QDialog, QDialogButtonBox, QVBoxLayout

from mad_gui.state_keeper import StateKeeper

Expand Down
4 changes: 2 additions & 2 deletions mad_gui/components/dialogs/label_annotation_dialog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from functools import reduce

from PySide2.QtCore import QEvent, Qt
from PySide2.QtWidgets import QButtonGroup, QDialog, QDialogButtonBox, QGroupBox, QHBoxLayout, QRadioButton, QVBoxLayout
from PySide6.QtCore import QEvent, Qt
from PySide6.QtWidgets import QButtonGroup, QDialog, QDialogButtonBox, QGroupBox, QHBoxLayout, QRadioButton, QVBoxLayout

from typing import Any, Dict, List, Tuple, Union

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from pathlib import Path

import pandas as pd
from PySide2 import QtCore
from PySide2.QtGui import Qt
from PySide2.QtWidgets import QDialog, QLabel, QLineEdit, QPushButton
from PySide6 import QtCore
from PySide6.QtGui import Qt
from PySide6.QtWidgets import QDialog, QLabel, QLineEdit, QPushButton

from mad_gui import BaseFileImporter
from mad_gui.components.dialogs.user_information import UserInformation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List, Union

from PySide2 import QtCore
from PySide2.QtWidgets import QDialog
from PySide6 import QtCore
from PySide6.QtWidgets import QDialog

from mad_gui.components.dialogs.user_information import UserInformation
from mad_gui.components.helper import set_cursor
Expand Down
12 changes: 6 additions & 6 deletions mad_gui/components/dialogs/user_information.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A window to display a message for the user and potentially getting a yes/no answer."""
from PySide2.QtCore import Qt
from PySide2.QtWidgets import QDialog, QMessageBox
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QDialog, QMessageBox

from typing import Optional

Expand Down Expand Up @@ -68,7 +68,7 @@ def inform(cls, text: str, help_link: Optional[str] = None) -> bool:
Note: If you want to execute the following example without having a MaD GUI instance running (i.e. you did
not use :meth:`mad_gui.start_gui`, you need to:

>>> from PySide2.QtWidgets import QApplication
>>> from PySide6.QtWidgets import QApplication
>>> app = QApplication()

You do not need the above code snippet, if you want to implement the lines below into your plugin.
Expand Down Expand Up @@ -97,20 +97,20 @@ def confirm(cls, text: str, help_link: Optional[str] = None) -> bool:
Returns
-------
answer
Either `Yes` or `No` of the class :py:class:`PySide2.QtWidgets.QMessageBox`.
Either `Yes` or `No` of the class :py:class:`PySide6.QtWidgets.QMessageBox`.
:py:

Examples
--------
Note: If you want to execute the following example without having a MaD GUI instance running (i.e. you did
not use :meth:`mad_gui.start_gui`, you need to:

>>> from PySide2.QtWidgets import QApplication
>>> from PySide6.QtWidgets import QApplication
>>> app = QApplication()

You do not need the above code snippet, if you want to implement the lines below into your plugin.

>>> from PySide2.QtWidgets import QMessageBox
>>> from PySide6.QtWidgets import QMessageBox
>>> from mad_gui.components.dialogs import UserInformation
>>> answer = UserInformation.confirm("Do you want to perform X?")
>>> if answer == QMessageBox.Yes:
Expand Down
4 changes: 2 additions & 2 deletions mad_gui/components/helper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path

from PySide2.QtCore import QCoreApplication
from PySide2.QtWidgets import QFileDialog
from PySide6.QtCore import QCoreApplication
from PySide6.QtWidgets import QFileDialog

from typing import Optional

Expand Down
4 changes: 2 additions & 2 deletions mad_gui/components/key_event_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from PySide2.QtCore import QObject, Qt, Slot
from PySide2.QtGui import QKeyEvent
from PySide6.QtCore import QObject, Qt, Slot
from PySide6.QtGui import QKeyEvent

from mad_gui.models.ui_state import PlotState
from typing import Optional, Tuple
Expand Down
2 changes: 1 addition & 1 deletion mad_gui/components/sidebar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from PySide2.QtCore import QObject, QPropertyAnimation, Signal
from PySide6.QtCore import QObject, QPropertyAnimation, Signal

from mad_gui.config import Config

Expand Down
2 changes: 1 addition & 1 deletion mad_gui/config/theme.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from PySide2.QtGui import QColor
from PySide6.QtGui import QColor


class BaseTheme:
Expand Down
2 changes: 1 addition & 1 deletion mad_gui/plot_tools/labels/base_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pandas as pd
import pyqtgraph as pg
from pyqtgraph import mkPen
from PySide2.QtGui import QColor, QHoverEvent, QMouseEvent, Qt
from PySide6.QtGui import QColor, QHoverEvent, QMouseEvent, Qt

from mad_gui.components.dialogs import UserInformation
from mad_gui.components.dialogs.label_annotation_dialog import NestedLabelSelectDialog
Expand Down
4 changes: 2 additions & 2 deletions mad_gui/plot_tools/labels/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import numpy as np
import pandas as pd
import pyqtgraph as pg
from PySide2.QtGui import QBrush, QColor, QLinearGradient, Qt
from PySide2.QtWidgets import QWidget
from PySide6.QtGui import QBrush, QColor, QLinearGradient, Qt
from PySide6.QtWidgets import QWidget

from mad_gui.config import Config
from mad_gui.plot_tools.labels.base_label import BaseRegionLabel, InvalidStartEnd, edit_label_description
Expand Down
4 changes: 2 additions & 2 deletions mad_gui/plot_tools/plots/base_mode_handler.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import TYPE_CHECKING

import pyqtgraph as pg
from PySide2.QtGui import QCursor
from PySide2.QtWidgets import QApplication
from PySide6.QtGui import QCursor
from PySide6.QtWidgets import QApplication

if TYPE_CHECKING:
from mad_gui.plot_tools.plots import SensorPlot
Expand Down
18 changes: 10 additions & 8 deletions mad_gui/plot_tools/plots/base_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pandas as pd
import pyqtgraph as pg
from pyqtgraph.GraphicsScene.mouseEvents import MouseClickEvent
from PySide2.QtCore import Slot
from PySide2.QtGui import QColor, QCursor, QMouseEvent, QPalette
from PySide6.QtCore import Slot
from PySide6.QtGui import QColor, QCursor, QMouseEvent, QPalette

from mad_gui.config import Config
from mad_gui.models.local import AnnotationData, PlotData
Expand Down Expand Up @@ -47,14 +47,12 @@ def __init__(
self._initialize_events(event_classes)

def _initialize_events(self, event_classes: List):
# if not hasattr(self.plot_data.annotations, "events"):
# return
# df = self.plot_data.annotations["events"].data
# for _, event in df.iterrows():
# pos = self.snap_to_sample(event.pos / self.plot_data.sampling_rate_hz)
# self.addItem(BaseEventLabel(pos=pos, span=(event.min_height, event.max_height), parent=self))
if event_classes is None:
return
# if event_classes is None:
# return
event_ranges = []
for event_class in event_classes:
if event_class.name not in self.plot_data.annotations.keys():
Expand All @@ -74,7 +72,7 @@ def _initialize_labels(self, labels: List):

for label_class in labels:
if hasattr(self.plot_data, "annotations"):
self._ensure_annotations_available(label_class)
self._ensure_label_available(label_class)
self.set_labels(label_class, self.plot_data.annotations[label_class.name].data)

label_range = pd.DataFrame(
Expand All @@ -85,10 +83,14 @@ def _initialize_labels(self, labels: List):
label_ranges.append(label_range)
self.label_ranges = pd.concat(label_ranges)

def _ensure_annotations_available(self, label_class: Union[BaseRegionLabel, BaseEventLabel]):
def _ensure_label_available(self, label_class: BaseRegionLabel):
if label_class.name not in self.plot_data.annotations.keys():
self.plot_data.annotations[label_class.name] = AnnotationData()

def _ensure_event_available(self, event_class: BaseEventLabel):
if event_class.name not in self.plot_data.annotations["events"].keys():
self.plot_data.annotations["events"][event_class.name] = AnnotationData()

@Slot(BaseEventLabel, pd.DataFrame)
def set_events(self, label_class: Type[BaseEventLabel], df: pd.DataFrame):
if df is None or df.empty:
Expand Down
13 changes: 7 additions & 6 deletions mad_gui/plot_tools/plots/sensor_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import numpy as np
import pandas as pd
import pyqtgraph as pg
from PySide2.QtCore import QObject, Qt, QTime, Slot
from PySide2.QtUiTools import loadUiType
from PySide2.QtWidgets import (
from PySide6.QtCore import QObject, Qt, QTime, Slot
from PySide6.QtUiTools import loadUiType
from PySide6.QtWidgets import (
QButtonGroup,
QCheckBox,
QDialog,
Expand Down Expand Up @@ -53,8 +53,8 @@
ChannelSelector, _ = loadUiType(ui_path)
except TypeError as e:
raise FileNotFoundError(
"Probably python did not find `pyside2-uic`. See "
'"https://mad-gui.readthedocs.io/en/latest/troubleshooting.html#pyside2-uic-not-found" for more '
"Probably python did not find `PySide6-uic`. See "
'"https://mad-gui.readthedocs.io/en/latest/troubleshooting.html#PySide6-uic-not-found" for more '
"information"
) from e

Expand Down Expand Up @@ -204,7 +204,8 @@ def _add_channel_selection_menu(self):
self.channels_selection_button_group.buttonToggled.connect(self._update_plotted_channels)

# add to plotwidget
self.getPlotItem().vb.menu.axes.append(submenu)
# self.getPlotItem().vb.menu.axes.append(submenu)

self.getPlotItem().vb.menu.ctrl.append(ui)
self.getPlotItem().vb.menu.widgetGroups.append(submenu)
self.getPlotItem().vb.menu.addMenu(submenu)
Expand Down
4 changes: 2 additions & 2 deletions mad_gui/plot_tools/plots/sensor_plot_mode_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from typing import Optional

from PySide2.QtCore import QEvent, Qt
from PySide2.QtGui import QMouseEvent
from PySide6.QtCore import QEvent, Qt
from PySide6.QtGui import QMouseEvent
from pyqtgraph import InfiniteLine, mkPen

from mad_gui.components.dialogs.user_information import UserInformation
Expand Down
2 changes: 1 addition & 1 deletion mad_gui/plugins/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np
import pandas as pd
from PySide2.QtWidgets import QFileDialog
from PySide6.QtWidgets import QFileDialog

from mad_gui.components.dialogs import UserInformation
from mad_gui.models import GlobalData
Expand Down
9 changes: 4 additions & 5 deletions mad_gui/qt_designer/ui_video.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from PySide2.QtCore import QSize, Qt
from PySide2.QtMultimedia import QMediaPlayer, QMediaPlaylist
from PySide2.QtMultimediaWidgets import QVideoWidget
from PySide2.QtWidgets import QHBoxLayout, QPushButton, QSizePolicy, QSlider, QVBoxLayout, QWidget
from PySide6.QtCore import QSize, Qt
from PySide6.QtMultimedia import QMediaPlayer
from PySide6.QtMultimediaWidgets import QVideoWidget
from PySide6.QtWidgets import QHBoxLayout, QPushButton, QSizePolicy, QSlider, QVBoxLayout, QWidget


class UiVideoWindow(QWidget):
Expand All @@ -28,7 +28,6 @@ def __init__(self):
self.verticalLayout.addWidget(self.view_video)

self.player = QMediaPlayer()
self.playlist = QMediaPlaylist()

self.horizontalLayout = QHBoxLayout()

Expand Down
2 changes: 1 addition & 1 deletion mad_gui/qt_designer/window_buttons_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Created by: The Resource Compiler for Qt version 5.15.1
# WARNING! All changes made in this file will be lost!

from PySide2 import QtCore
from PySide6 import QtCore

qt_resource_data = b"\
\x00\x00I\x01\
Expand Down
4 changes: 2 additions & 2 deletions mad_gui/start_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path

import pyqtgraph
from PySide2.QtWidgets import QApplication
from PySide6.QtWidgets import QApplication

from mad_gui.config import BaseSettings, BaseTheme
from mad_gui.plot_tools.labels import BaseEventLabel, BaseRegionLabel
Expand Down Expand Up @@ -74,7 +74,7 @@ def start_gui(
)
form.show()

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


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion mad_gui/state_keeper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Keeps the state of the GUI and related signals / slots."""

from PySide2.QtCore import QObject, Signal, Slot
from PySide6.QtCore import QObject, Signal, Slot


class _StateKeeper(QObject):
Expand Down
Loading
Loading