From a793a766fce24bc5617ead7bf24265ca2688f630 Mon Sep 17 00:00:00 2001 From: mmouchous-ledger Date: Wed, 21 Aug 2024 17:12:31 +0200 Subject: [PATCH] Remove unecessary LaserToolbar class architecture --- laserstudio/instruments/laserdriver.py | 2 +- laserstudio/laserstudio.py | 4 +-- laserstudio/widgets/toolbars/__init__.py | 2 -- .../widgets/toolbars/laserdrivertoolbar.py | 29 +++++++++---------- laserstudio/widgets/toolbars/lasertoolbar.py | 16 ---------- laserstudio/widgets/toolbars/pdmtoolbar.py | 27 ++++++++--------- 6 files changed, 29 insertions(+), 51 deletions(-) delete mode 100644 laserstudio/widgets/toolbars/lasertoolbar.py diff --git a/laserstudio/instruments/laserdriver.py b/laserstudio/instruments/laserdriver.py index 176148f..136e5f9 100644 --- a/laserstudio/instruments/laserdriver.py +++ b/laserstudio/instruments/laserdriver.py @@ -1,4 +1,4 @@ -# Lazy import, LaserDriver is not supported yet. +# Lazy import, LaserDriver is not pubicly supported yet. try: from laser_driver import LaserDriver # type: ignore except Exception: diff --git a/laserstudio/laserstudio.py b/laserstudio/laserstudio.py index 8e71937..1418b98 100644 --- a/laserstudio/laserstudio.py +++ b/laserstudio/laserstudio.py @@ -103,9 +103,9 @@ def __init__(self, config: Optional[dict]): # Laser toolbars for i, laser in enumerate(self.instruments.lasers): if isinstance(laser, PDMInstrument): - toolbar = PDMToolbar(self, i) + toolbar = PDMToolbar(laser, i) elif isinstance(laser, LaserDriverInstrument): - toolbar = LaserDriverToolbar(self, i) + toolbar = LaserDriverToolbar(laser, i) else: continue self.addToolBar(Qt.ToolBarArea.RightToolBarArea, toolbar) diff --git a/laserstudio/widgets/toolbars/__init__.py b/laserstudio/widgets/toolbars/__init__.py index d70f19a..7f1d2f8 100644 --- a/laserstudio/widgets/toolbars/__init__.py +++ b/laserstudio/widgets/toolbars/__init__.py @@ -1,6 +1,5 @@ from .cameratoolbar import CameraToolbar from .cameranittoolbar import CameraNITToolBar -from .lasertoolbar import LaserToolbar from .pdmtoolbar import PDMToolbar from .laserdrivertoolbar import LaserDriverToolbar from .maintoolbar import MainToolbar @@ -17,7 +16,6 @@ "CameraToolbar", "CameraNITToolBar", "PictureToolbar", - "LaserToolbar", "LaserDriverToolbar", "PDMToolbar", ] diff --git a/laserstudio/widgets/toolbars/laserdrivertoolbar.py b/laserstudio/widgets/toolbars/laserdrivertoolbar.py index 1cf9b20..3198da3 100644 --- a/laserstudio/widgets/toolbars/laserdrivertoolbar.py +++ b/laserstudio/widgets/toolbars/laserdrivertoolbar.py @@ -2,32 +2,31 @@ from laser_driver import LaserDriverPanel # type: ignore except Exception: LaserDriverPanel = None -from .lasertoolbar import LaserToolbar from ...instruments.laserdriver import LaserDriverInstrument -from typing import TYPE_CHECKING from PyQt6.QtCore import Qt +from PyQt6.QtWidgets import QToolBar -if TYPE_CHECKING: - from ...laserstudio import LaserStudio - -class LaserDriverToolbar(LaserToolbar): - def __init__(self, laser_studio: "LaserStudio", laser_num: int): +class LaserDriverToolbar(QToolBar): + def __init__(self, laser: LaserDriverInstrument, laser_num: int): """ - :param laser_studio: Main windows of laserstudio. Can be used for interacting with - other elements of the UI. + :param laser: Laser Driver instrument. :param laser_num: Laser equipment index. """ - assert LaserDriverPanel is not None - assert laser_num < len(laser_studio.instruments.lasers) - self.laser = laser_studio.instruments.lasers[laser_num] - assert isinstance(self.laser, LaserDriverInstrument) - super().__init__(f"Laser {laser_num} (Donjon Driver)", laser_studio, laser_num) - super().setObjectName(f"toolbox-laser-donjon-{laser_num}") # For settings save and restore + assert isinstance(laser, LaserDriverInstrument) + self.laser = laser + super().__init__(f"Laser {laser_num} (Donjon Driver)") + self.setObjectName( + f"toolbox-laser-donjon-{laser_num}" + ) # For settings save and restore + self.setAllowedAreas( Qt.ToolBarArea.LeftToolBarArea | Qt.ToolBarArea.RightToolBarArea ) self.setFloatable(True) + + # Construct a UI Panel for the Laser Driver + assert LaserDriverPanel is not None panel = LaserDriverPanel(self.laser.laser) panel.refresh_interval_edit.setMinimum(1000) panel.refresh_interval_edit.setMaximum(5000) diff --git a/laserstudio/widgets/toolbars/lasertoolbar.py b/laserstudio/widgets/toolbars/lasertoolbar.py deleted file mode 100644 index 83336d4..0000000 --- a/laserstudio/widgets/toolbars/lasertoolbar.py +++ /dev/null @@ -1,16 +0,0 @@ -from PyQt6.QtWidgets import QToolBar -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from ...laserstudio import LaserStudio - -class LaserToolbar(QToolBar): - def __init__(self, title: str, laser_studio: "LaserStudio", laser_num: int): - """ - :param laser_studio: Main windows of laserstudio. Can be used for interacting with - other elements of the UI. - :param laser_num: Laser equipment index. - """ - super().__init__(title) - self.laser_studio = laser_studio - super().setObjectName(f"toolbox-laser-{laser_num}") # For settings save and restore diff --git a/laserstudio/widgets/toolbars/pdmtoolbar.py b/laserstudio/widgets/toolbars/pdmtoolbar.py index 431def3..4fe457f 100644 --- a/laserstudio/widgets/toolbars/pdmtoolbar.py +++ b/laserstudio/widgets/toolbars/pdmtoolbar.py @@ -11,31 +11,28 @@ from laserstudio.instruments.pdm import PDMInstrument from ...utils.util import resource_path, colored_image -from typing import TYPE_CHECKING from ..return_line_edit import ReturnDoubleSpinBox -from .lasertoolbar import LaserToolbar +from PyQt6.QtWidgets import QToolBar -if TYPE_CHECKING: - from ...laserstudio import LaserStudio - -class PDMToolbar(LaserToolbar): - def __init__(self, laser_studio: "LaserStudio", laser_num: int): +class PDMToolbar(QToolBar): + def __init__(self, laser: PDMInstrument, laser_num: int): """ - :param laser_studio: Main windows of laserstudio. Can be used for interacting with - other elements of the UI. + :param laser: Alphanov PDM instrument. :param laser_num: Laser equipment index. """ - assert laser_num < len(laser_studio.instruments.lasers) - self.laser = laser_studio.instruments.lasers[laser_num] - assert isinstance(self.laser, PDMInstrument) - super().__init__(f"Laser {laser_num} (PDM)", laser_studio, laser_num) - super().setObjectName(f"toolbox-laser-pdm-{laser_num}") # For settings save and restore + assert isinstance(laser, PDMInstrument) + self.laser = laser + super().__init__(f"Laser {laser_num} (PDM)") + self.setObjectName( + f"toolbox-laser-pdm-{laser_num}" + ) # For settings save and restore + self.setAllowedAreas( Qt.ToolBarArea.LeftToolBarArea | Qt.ToolBarArea.RightToolBarArea ) - self.setFloatable(True) + w = QPushButton(self) w.setToolTip("On/Off Laser") w.setCheckable(True)