Skip to content

Commit

Permalink
Remove unecessary LaserToolbar class architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
mmouchous-ledger committed Aug 21, 2024
1 parent 6d2b452 commit a793a76
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 51 deletions.
2 changes: 1 addition & 1 deletion laserstudio/instruments/laserdriver.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions laserstudio/laserstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions laserstudio/widgets/toolbars/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,7 +16,6 @@
"CameraToolbar",
"CameraNITToolBar",
"PictureToolbar",
"LaserToolbar",
"LaserDriverToolbar",
"PDMToolbar",
]
29 changes: 14 additions & 15 deletions laserstudio/widgets/toolbars/laserdrivertoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 0 additions & 16 deletions laserstudio/widgets/toolbars/lasertoolbar.py

This file was deleted.

27 changes: 12 additions & 15 deletions laserstudio/widgets/toolbars/pdmtoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a793a76

Please sign in to comment.