From aef29e38094fa40951d9b81c65d084de4678cdb2 Mon Sep 17 00:00:00 2001 From: Benedikt Burger <67148916+BenediktBurger@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:22:36 +0100 Subject: [PATCH] Add ui file path to base main window --- .../data_logger/data/data_logger_listener.py | 8 ++++++-- .../gui/data_logger/data_logger_base.py | 5 ++++- .../gui/data_logger/data_logger_viewer.py | 2 +- pyleco_extras/gui_utils/base_main_window.py | 18 ++++++++++++++---- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/pyleco_extras/gui/data_logger/data/data_logger_listener.py b/pyleco_extras/gui/data_logger/data/data_logger_listener.py index 806aa26..3632783 100644 --- a/pyleco_extras/gui/data_logger/data/data_logger_listener.py +++ b/pyleco_extras/gui/data_logger/data/data_logger_listener.py @@ -12,10 +12,14 @@ from pyleco.utils.pipe_handler import PipeHandler from pyleco.utils.events import Event from pyleco.utils.listener import Listener -from pyleco.utils.qt_listener import QtListener +try: + from pyleco.utils.qt_listener import ListenerSignals +except ImportError: + from pyleco.utils.qt_listener import QtListener + ListenerSignals = QtListener.ListenerSignals # type: ignore -class Signals(QtListener.ListenerSignals): +class Signals(ListenerSignals): """Signals for the DataLogger message handler.""" started = Signal() configuration_changed = Signal(dict) diff --git a/pyleco_extras/gui/data_logger/data_logger_base.py b/pyleco_extras/gui/data_logger/data_logger_base.py index 1732f39..9c4e1bf 100644 --- a/pyleco_extras/gui/data_logger/data_logger_base.py +++ b/pyleco_extras/gui/data_logger/data_logger_base.py @@ -5,6 +5,7 @@ # Standard packages. import logging +from pathlib import Path import time from typing import Any, Iterable, Optional @@ -57,7 +58,9 @@ class DataLoggerBase(LECOBaseMainWindowDesigner): def __init__(self, name: str, **kwargs) -> None: # Use initialization of parent class QMainWindow. - super().__init__(name=name, ui_file_name="DataLogger", **kwargs) + super().__init__(name=name, ui_file_name="DataLogger", + ui_file_path=Path(__file__).parent / "data", + **kwargs) # Load the user interface file, and configure the dock area and show it. self.dockArea = DockArea() diff --git a/pyleco_extras/gui/data_logger/data_logger_viewer.py b/pyleco_extras/gui/data_logger/data_logger_viewer.py index 5e4b10b..8541dbd 100644 --- a/pyleco_extras/gui/data_logger/data_logger_viewer.py +++ b/pyleco_extras/gui/data_logger/data_logger_viewer.py @@ -1,5 +1,5 @@ """ -Remotely control a DataLogger +View data files of a DataLogger Created on Thu Apr 1 15:14:39 2021 by Benedikt Burger """ diff --git a/pyleco_extras/gui_utils/base_main_window.py b/pyleco_extras/gui_utils/base_main_window.py index 69cc4b0..c7c99a8 100644 --- a/pyleco_extras/gui_utils/base_main_window.py +++ b/pyleco_extras/gui_utils/base_main_window.py @@ -1,6 +1,7 @@ import logging -from typing import Optional +from pathlib import Path +from typing import Optional, Union from qtpy import QtCore, QtGui, QtWidgets, uic from qtpy.QtCore import Slot # type: ignore @@ -117,18 +118,27 @@ def show_namespace_information(self, full_name: str): class LECOBaseMainWindowDesigner(_LECOBaseMainWindow): - """Base MainWindow subclass with a LECO listener, UI defined via designer ui file.""" + """Base MainWindow subclass with a LECO listener, UI defined via designer ui file. + + :param name: Leco name + :param ui_file_name: Name of the ui_file (without ".ui" termination) + :param ui_file_path: Path to the ui file. Relative "data" or absolute, e.g. + `pathlib.Path(__file__).parent / "data"`. + """ def __init__(self, name: str, ui_file_name: str, + ui_file_path: Union[Path, str] = "data", settings_dialog_class: type[QtWidgets.QDialog] | None = None, host: str = "localhost", port: int = COORDINATOR_PORT, logger: logging.Logger = log, data_port: int = PROXY_SENDING_PORT, **kwargs) -> None: - self._ui_file_name = ui_file_name + if isinstance(ui_file_path, str): + ui_file_path = Path(ui_file_path) + self._file_path = ui_file_path / f"{ui_file_name}.ui" super().__init__(name=name, settings_dialog_class=settings_dialog_class, host=host, @@ -138,7 +148,7 @@ def __init__(self, **kwargs) def _setup_ui(self): - uic.load_ui.loadUi(f"data/{self._ui_file_name}.ui", self) + uic.load_ui.loadUi(self._file_path, self) class LECOBaseMainWindowNoDesigner(_LECOBaseMainWindow):