Skip to content

Commit

Permalink
Do not assume that the type of parameter is inferred by the source of…
Browse files Browse the repository at this point in the history
… selection (button or shortcut)
  • Loading branch information
mmouchous-ledger committed Nov 27, 2024
1 parent c384201 commit d20320f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion laserstudio/laserstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +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(self.viewer.select_mode)
group.idClicked.connect(lambda mode: self.viewer.select_mode(mode, True))
self.viewer.mode_changed.connect(self.update_buttons_mode)

# Toolbar: Main
Expand Down
15 changes: 7 additions & 8 deletions laserstudio/widgets/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,15 @@ 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.
"""
def select_mode(self, mode: Union[Mode, int], toggle: bool = False):
"""Selects the Viewer's mode. If toogle is set to true,
the function behaves as 'toggling',
meaning that the mode is reset to NONE if it is reselected."""
if isinstance(mode, int):
mode = Viewer.Mode(mode)
# If it has been requested to select the same mode, we deselect it.
if self.mode == mode:
mode = Viewer.Mode.NONE

if toggle and self.mode == mode:
mode = Viewer.Mode.NONE

self.mode = mode

Expand Down

0 comments on commit d20320f

Please sign in to comment.