From d20320f31a992c0b0a40b3474778c151f8e74f33 Mon Sep 17 00:00:00 2001 From: mmouchous-ledger Date: Wed, 27 Nov 2024 16:06:30 +0100 Subject: [PATCH] Do not assume that the type of parameter is inferred by the source of selection (button or shortcut) --- laserstudio/laserstudio.py | 2 +- laserstudio/widgets/viewer.py | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/laserstudio/laserstudio.py b/laserstudio/laserstudio.py index 04d6240..a29008b 100644 --- a/laserstudio/laserstudio.py +++ b/laserstudio/laserstudio.py @@ -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 diff --git a/laserstudio/widgets/viewer.py b/laserstudio/widgets/viewer.py index 83e16ee..a68fcab 100644 --- a/laserstudio/widgets/viewer.py +++ b/laserstudio/widgets/viewer.py @@ -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