Skip to content

Commit

Permalink
Remove unecessary LaserToolbar class architecture (#15)
Browse files Browse the repository at this point in the history
Remove unecessary LaserToolbar class architecture
  • Loading branch information
mmouchous-ledger authored Aug 26, 2024
1 parent 71ef9d9 commit 7fa3a7a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 40 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 @@ -108,9 +108,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 @@ -19,7 +18,6 @@
"CameraToolbar",
"CameraNITToolBar",
"PictureToolbar",
"LaserToolbar",
"LaserDriverToolbar",
"PDMToolbar",
"MarkersToolbar",
Expand Down
27 changes: 16 additions & 11 deletions laserstudio/widgets/toolbars/laserdrivertoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +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(QToolBar):
def __init__(self, laser: LaserDriverInstrument, laser_num: int):
"""
:param laser: Laser Driver instrument.
:param laser_num: Laser equipment index.
"""
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

class LaserDriverToolbar(LaserToolbar):
def __init__(self, laser_studio: "LaserStudio", laser_num: int):
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)", "donjon", laser_num)
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
11 changes: 0 additions & 11 deletions laserstudio/widgets/toolbars/lasertoolbar.py

This file was deleted.

29 changes: 16 additions & 13 deletions laserstudio/widgets/toolbars/pdmtoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +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


class PDMToolbar(QToolBar):
def __init__(self, laser: PDMInstrument, laser_num: int):
"""
:param laser: Alphanov PDM instrument.
:param laser_num: Laser equipment index.
"""
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

if TYPE_CHECKING:
from ...laserstudio import LaserStudio


class PDMToolbar(LaserToolbar):
def __init__(self, laser_studio: "LaserStudio", laser_num: int):
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)", "pdm", laser_num)
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 7fa3a7a

Please sign in to comment.