Skip to content

Commit

Permalink
Merge pull request #5 from Ledger-Donjon/window-settings
Browse files Browse the repository at this point in the history
Window and toolbars settings save and restore
  • Loading branch information
mmouchous-ledger authored Jul 24, 2024
2 parents 920f223 + 2762d6b commit 44b8cf2
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 5 deletions.
19 changes: 18 additions & 1 deletion laserstudio/laserstudio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python3
from PyQt6.QtCore import Qt, QKeyCombination
from PyQt6.QtCore import Qt, QKeyCombination, QSettings
from PyQt6.QtGui import QColor, QShortcut, QKeySequence
from PyQt6.QtWidgets import (
QMainWindow,
Expand Down Expand Up @@ -43,6 +43,9 @@ def __init__(self, config: Optional[dict]):
if config is None:
config = {}

# User settings
self.settings = QSettings("ledger", "laserstudio")

# Instantiate all instruments
self.instruments = Instruments(config)

Expand Down Expand Up @@ -169,6 +172,20 @@ def __init__(self, config: Optional[dict]):
)
shortcut.activated.connect(self.handle_go_next)

# Restore docks are previous session
geometry = self.settings.value("geometry")
if geometry is not None:
self.restoreGeometry(geometry)
window_state = self.settings.value("window-state")
if window_state is not None:
self.restoreState(window_state)

def closeEvent(self, event):
"""Saves user settings before closing the application."""
self.settings.setValue("geometry", self.saveGeometry())
self.settings.setValue("window-state", self.saveState())
super().closeEvent(event)

def handle_go_next(self) -> dict:
"""Go Next operation.
Triggers the instruments to perform changes to go to next step of scan.
Expand Down
1 change: 1 addition & 0 deletions laserstudio/widgets/toolbars/cameranittoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self, laser_studio: "LaserStudio"):
self.laser_studio = laser_studio

super().__init__("NIT Camera parameters", laser_studio)
self.setObjectName("toolbar-camera-nit") # For settings save and restore
self.setAllowedAreas(
Qt.ToolBarArea.LeftToolBarArea
| Qt.ToolBarArea.RightToolBarArea
Expand Down
1 change: 1 addition & 0 deletions laserstudio/widgets/toolbars/cameratoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, laser_studio: "LaserStudio"):
assert laser_studio.instruments.camera is not None
self.camera = laser_studio.instruments.camera
super().__init__("Camera parameters", laser_studio)
self.setObjectName("toolbar-camera") # For settings save and restore
self.setAllowedAreas(
Qt.ToolBarArea.LeftToolBarArea
| Qt.ToolBarArea.RightToolBarArea
Expand Down
2 changes: 1 addition & 1 deletion laserstudio/widgets/toolbars/laserdrivertoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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, LaserDriverInstrument)
super().__init__(f"Laser {laser_num} (Donjon Driver)", laser_studio)
super().__init__(f"Laser {laser_num} (Donjon Driver)", "donjon", laser_num)
self.setAllowedAreas(
Qt.ToolBarArea.LeftToolBarArea | Qt.ToolBarArea.RightToolBarArea
)
Expand Down
8 changes: 7 additions & 1 deletion laserstudio/widgets/toolbars/lasertoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@


class LaserToolbar(QToolBar):
pass
def __init__(self, title: str, laser_model: str, laser_num: int):
"""
:param laser_model: Equipment model, such as "pdm". Used for settings save and restore.
:param laser_num: Laser equipment index.
"""
super().__init__(title)
super().setObjectName(f"toolbox-laser-{laser_model}-{laser_num}") # For settings save and restore
1 change: 1 addition & 0 deletions laserstudio/widgets/toolbars/maintoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class MainToolbar(QToolBar):
def __init__(self, laser_studio: "LaserStudio"):
super().__init__("Main", laser_studio)
self.setObjectName("toolbar-main") # For settings save and restore
group = laser_studio.viewer_buttons_group
self.setAllowedAreas(
Qt.ToolBarArea.LeftToolBarArea | Qt.ToolBarArea.RightToolBarArea
Expand Down
3 changes: 1 addition & 2 deletions laserstudio/widgets/toolbars/pdmtoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ 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)", laser_studio)
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")
Expand Down
1 change: 1 addition & 0 deletions laserstudio/widgets/toolbars/picturetoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class PictureToolbar(QToolBar):
def __init__(self, laser_studio: "LaserStudio"):
super().__init__("Background picture", laser_studio)
self.setObjectName("toolbar-background-picture") # For settings save and restore
group = laser_studio.viewer_buttons_group
self.setAllowedAreas(Qt.ToolBarArea.TopToolBarArea)
self.setFloatable(True)
Expand Down
1 change: 1 addition & 0 deletions laserstudio/widgets/toolbars/scantoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class ScanToolbar(QToolBar):
def __init__(self, laser_studio: "LaserStudio"):
super().__init__("Scanning Zones", laser_studio)
self.setObjectName("toolbar-scanning") # For settings save and restore
group = laser_studio.viewer_buttons_group
self.setAllowedAreas(Qt.ToolBarArea.TopToolBarArea)
self.setFloatable(True)
Expand Down
1 change: 1 addition & 0 deletions laserstudio/widgets/toolbars/stagetoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, laser_studio: "LaserStudio"):
assert laser_studio.instruments.stage is not None
self.stage = laser_studio.instruments.stage
super().__init__("Stage control", laser_studio)
self.setObjectName("toolbar-stage") # For settings save and restore
group = laser_studio.viewer_buttons_group
self.setAllowedAreas(
Qt.ToolBarArea.LeftToolBarArea
Expand Down
1 change: 1 addition & 0 deletions laserstudio/widgets/toolbars/zoomtoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class ZoomToolbar(QToolBar):
def __init__(self, laser_studio: "LaserStudio"):
super().__init__("Zoom control", laser_studio)
self.setObjectName("toolbar-zoom") # For settings save and restore
self.setAllowedAreas(Qt.ToolBarArea.TopToolBarArea)
self.setFloatable(True)

Expand Down

0 comments on commit 44b8cf2

Please sign in to comment.