Skip to content

Commit

Permalink
The Viewer's mode is deselected when the button is clicked again.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmouchous-ledger committed Nov 27, 2024
1 parent 6088802 commit 4f17d07
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
22 changes: 6 additions & 16 deletions laserstudio/laserstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
QMainWindow,
QButtonGroup,
)
from typing import Optional, Any
from typing import Optional, Any, Union

from .widgets.viewer import Viewer
from .instruments.instruments import (
Expand Down Expand Up @@ -65,9 +65,7 @@ def __init__(self, config: Optional[dict]):

# Create group of buttons for Viewer mode selection
self.viewer_buttons_group = group = QButtonGroup(self)
group.idClicked.connect(
lambda _id: self.viewer.__setattr__("mode", Viewer.Mode(_id))
)
group.idClicked.connect(self.viewer.select_mode)
self.viewer.mode_changed.connect(self.update_buttons_mode)

# Toolbar: Main
Expand Down Expand Up @@ -120,23 +118,15 @@ def __init__(self, config: Optional[dict]):

# Create shortcuts
shortcut = QShortcut(Qt.Key.Key_Escape, self)
shortcut.activated.connect(
lambda: self.viewer.__setattr__("mode", Viewer.Mode.NONE)
)
shortcut.activated.connect(lambda: self.viewer.select_mode(Viewer.Mode.NONE))
shortcut = QShortcut(Qt.Key.Key_R, self)
shortcut.activated.connect(
lambda: self.viewer.__setattr__("mode", Viewer.Mode.ZONE)
)
shortcut.activated.connect(lambda: self.viewer.select_mode(Viewer.Mode.ZONE))
# shortcut = QShortcut(Qt.Key_T, self)
# shortcut.activated.connect(self.zone_rot_mode)
shortcut = QShortcut(Qt.Key.Key_M, self)
shortcut.activated.connect(
lambda: self.viewer.__setattr__("mode", Viewer.Mode.STAGE)
)
shortcut.activated.connect(lambda: self.viewer.select_mode(Viewer.Mode.STAGE))
shortcut = QShortcut(Qt.Key.Key_P, self)
shortcut.activated.connect(
lambda: self.viewer.__setattr__("mode", Viewer.Mode.PIN)
)
shortcut.activated.connect(lambda: self.viewer.select_mode(Viewer.Mode.PIN))
if (stage := self.instruments.stage) is not None:
shortcut = QShortcut(Qt.Key.Key_PageUp, self)
shortcut.activated.connect(
Expand Down
13 changes: 13 additions & 0 deletions laserstudio/widgets/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,19 @@ def mode(self, new_mode: Mode):
logging.getLogger("laserstudio").debug(f"Viewer mode selection: {new_mode}")
self.mode_changed.emit(int(new_mode))

def select_mode(self, mode: Union[Mode, int]):
"""Selects the Viewer's mode. In the case of a button click,
the mode is the button's id, in the case of a shortcut, the mode
is directly an instance of Mode.
"""
if isinstance(mode, int):
new_mode = Viewer.Mode(mode)
# If it has been requested to select the same mode, we deselect it.
if self.mode == new_mode:
new_mode = Viewer.Mode.NONE

self.mode = Viewer.Mode.NONE

def go_next(self):
"""Actions to perform when Laser Studio receive a Go Next command.
Retrieve the next point position from Scan Geometry
Expand Down

0 comments on commit 4f17d07

Please sign in to comment.