From 5ff00e5b1340c687c5ebdcdce5b47ef140e251fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20H=C3=A9riveaux?= Date: Thu, 25 Jul 2024 14:50:38 +0200 Subject: [PATCH 1/4] Added menu to clear markers --- laserstudio/laserstudio.py | 2 +- laserstudio/widgets/toolbars/maintoolbar.py | 12 ++++++++---- laserstudio/widgets/viewer.py | 6 ++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/laserstudio/laserstudio.py b/laserstudio/laserstudio.py index 8e71937..bdeebd2 100644 --- a/laserstudio/laserstudio.py +++ b/laserstudio/laserstudio.py @@ -70,7 +70,7 @@ def __init__(self, config: Optional[dict]): self.viewer.mode_changed.connect(self.update_buttons_mode) # Toolbar: Main - toolbar = MainToolbar(self) + toolbar = MainToolbar(self, self.viewer) self.addToolBar(Qt.ToolBarArea.LeftToolBarArea, toolbar) # Toolbar: Background picture diff --git a/laserstudio/widgets/toolbars/maintoolbar.py b/laserstudio/widgets/toolbars/maintoolbar.py index 90ea0bb..bb6dd53 100644 --- a/laserstudio/widgets/toolbars/maintoolbar.py +++ b/laserstudio/widgets/toolbars/maintoolbar.py @@ -4,19 +4,21 @@ from PyQt6.QtWidgets import QToolBar, QPushButton, QLabel, QMenu from ...utils.util import resource_path, colored_image from ..coloredbutton import ColoredPushButton +from ..viewer import Viewer if TYPE_CHECKING: from ...laserstudio import LaserStudio class MainToolbar(QToolBar): - def __init__(self, laser_studio: "LaserStudio"): + def __init__(self, laser_studio: "LaserStudio", viewer: Viewer): + """ + :param viewer: Required for the menu to remove markers. + """ 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 - ) + self.setAllowedAreas(Qt.ToolBarArea.AllToolBarAreas) self.setFloatable(True) # Icon Logo @@ -48,5 +50,7 @@ def __init__(self, laser_studio: "LaserStudio"): settings_menu = QMenu("Settings", self) settings_menu.addAction("Save settings", laser_studio.save_settings) settings_menu.addAction("Load settings", laser_studio.reload_settings) + settings_menu.addSeparator() + settings_menu.addAction("Clear markers", viewer.clear_markers) w.setMenu(settings_menu) self.addWidget(w) diff --git a/laserstudio/widgets/viewer.py b/laserstudio/widgets/viewer.py index c758574..8a47c7e 100644 --- a/laserstudio/widgets/viewer.py +++ b/laserstudio/widgets/viewer.py @@ -612,6 +612,12 @@ def add_marker( marker.update_tooltip() return marker + def clear_markers(self): + """Removes all markers.""" + for marker in self.__markers: + self.__scene.removeItem(marker) + self.__markers.clear() + @property def yaml(self) -> dict: """Export settings to a dict for yaml serialization.""" From ae04f1fb6df3bc3fdb4b944fd863e9daf5497807 Mon Sep 17 00:00:00 2001 From: mmouchous-ledger Date: Fri, 26 Jul 2024 10:09:05 +0200 Subject: [PATCH 2/4] Markers Toolbar --- .../fontawesome-free/location-pin-solid.svg | 36 ++++++++++++++ laserstudio/icons/location-pin-clear.svg | 36 ++++++++++++++ laserstudio/icons/location-pin-plus.svg | 36 ++++++++++++++ laserstudio/laserstudio.py | 7 ++- laserstudio/widgets/toolbars/__init__.py | 3 ++ laserstudio/widgets/toolbars/maintoolbar.py | 5 +- .../widgets/toolbars/markerstoolbar.py | 48 +++++++++++++++++++ laserstudio/widgets/toolbars/zoomtoolbar.py | 15 ------ 8 files changed, 166 insertions(+), 20 deletions(-) create mode 100644 laserstudio/icons/fontawesome-free/location-pin-solid.svg create mode 100644 laserstudio/icons/location-pin-clear.svg create mode 100644 laserstudio/icons/location-pin-plus.svg create mode 100644 laserstudio/widgets/toolbars/markerstoolbar.py diff --git a/laserstudio/icons/fontawesome-free/location-pin-solid.svg b/laserstudio/icons/fontawesome-free/location-pin-solid.svg new file mode 100644 index 0000000..f00c2d3 --- /dev/null +++ b/laserstudio/icons/fontawesome-free/location-pin-solid.svg @@ -0,0 +1,36 @@ + + + + + + + diff --git a/laserstudio/icons/location-pin-clear.svg b/laserstudio/icons/location-pin-clear.svg new file mode 100644 index 0000000..2e75b5e --- /dev/null +++ b/laserstudio/icons/location-pin-clear.svg @@ -0,0 +1,36 @@ + + + + + + + diff --git a/laserstudio/icons/location-pin-plus.svg b/laserstudio/icons/location-pin-plus.svg new file mode 100644 index 0000000..4b49251 --- /dev/null +++ b/laserstudio/icons/location-pin-plus.svg @@ -0,0 +1,36 @@ + + + + + + + diff --git a/laserstudio/laserstudio.py b/laserstudio/laserstudio.py index bdeebd2..75d0ec3 100644 --- a/laserstudio/laserstudio.py +++ b/laserstudio/laserstudio.py @@ -22,6 +22,7 @@ StageToolbar, CameraToolbar, MainToolbar, + MarkersToolbar, PDMToolbar, LaserDriverToolbar, CameraNITToolBar, @@ -70,7 +71,7 @@ def __init__(self, config: Optional[dict]): self.viewer.mode_changed.connect(self.update_buttons_mode) # Toolbar: Main - toolbar = MainToolbar(self, self.viewer) + toolbar = MainToolbar(self) self.addToolBar(Qt.ToolBarArea.LeftToolBarArea, toolbar) # Toolbar: Background picture @@ -81,6 +82,10 @@ def __init__(self, config: Optional[dict]): toolbar = ZoomToolbar(self) self.addToolBar(Qt.ToolBarArea.TopToolBarArea, toolbar) + # Toolbar: Markers + toolbar = MarkersToolbar(self, self.viewer) + self.addToolBar(Qt.ToolBarArea.TopToolBarArea, toolbar) + # Toolbar: Stage positioning if self.instruments.stage is not None: toolbar = StageToolbar(self) diff --git a/laserstudio/widgets/toolbars/__init__.py b/laserstudio/widgets/toolbars/__init__.py index d70f19a..38165f3 100644 --- a/laserstudio/widgets/toolbars/__init__.py +++ b/laserstudio/widgets/toolbars/__init__.py @@ -4,11 +4,13 @@ from .pdmtoolbar import PDMToolbar from .laserdrivertoolbar import LaserDriverToolbar from .maintoolbar import MainToolbar +from .markerstoolbar import MarkersToolbar from .scantoolbar import ScanToolbar from .picturetoolbar import PictureToolbar from .stagetoolbar import StageToolbar from .zoomtoolbar import ZoomToolbar + __all__ = [ "MainToolbar", "ScanToolbar", @@ -20,4 +22,5 @@ "LaserToolbar", "LaserDriverToolbar", "PDMToolbar", + "MarkersToolbar", ] diff --git a/laserstudio/widgets/toolbars/maintoolbar.py b/laserstudio/widgets/toolbars/maintoolbar.py index bb6dd53..512316a 100644 --- a/laserstudio/widgets/toolbars/maintoolbar.py +++ b/laserstudio/widgets/toolbars/maintoolbar.py @@ -4,14 +4,13 @@ from PyQt6.QtWidgets import QToolBar, QPushButton, QLabel, QMenu from ...utils.util import resource_path, colored_image from ..coloredbutton import ColoredPushButton -from ..viewer import Viewer if TYPE_CHECKING: from ...laserstudio import LaserStudio class MainToolbar(QToolBar): - def __init__(self, laser_studio: "LaserStudio", viewer: Viewer): + def __init__(self, laser_studio: "LaserStudio"): """ :param viewer: Required for the menu to remove markers. """ @@ -50,7 +49,5 @@ def __init__(self, laser_studio: "LaserStudio", viewer: Viewer): settings_menu = QMenu("Settings", self) settings_menu.addAction("Save settings", laser_studio.save_settings) settings_menu.addAction("Load settings", laser_studio.reload_settings) - settings_menu.addSeparator() - settings_menu.addAction("Clear markers", viewer.clear_markers) w.setMenu(settings_menu) self.addWidget(w) diff --git a/laserstudio/widgets/toolbars/markerstoolbar.py b/laserstudio/widgets/toolbars/markerstoolbar.py new file mode 100644 index 0000000..89a4c39 --- /dev/null +++ b/laserstudio/widgets/toolbars/markerstoolbar.py @@ -0,0 +1,48 @@ +from typing import TYPE_CHECKING +from PyQt6.QtCore import Qt, QSize +from PyQt6.QtGui import QIcon +from PyQt6.QtWidgets import QToolBar, QPushButton +from ..return_line_edit import ReturnSpinBox +from ...utils.util import colored_image +from ..viewer import Viewer + +if TYPE_CHECKING: + from ...laserstudio import LaserStudio + + +class MarkersToolbar(QToolBar): + def __init__(self, laser_studio: "LaserStudio", viewer: Viewer): + super().__init__("Markers", laser_studio) + self.setObjectName("toolbar-markers") # For settings save and restore + self.setAllowedAreas(Qt.ToolBarArea.TopToolBarArea) + self.setFloatable(True) + + # Add a marker + w = QPushButton(self) + w.setIcon(QIcon(colored_image(":/icons/location-pin-plus.svg"))) + w.setIconSize(QSize(24, 24)) + w.setToolTip("Add markers") + w.clicked.connect(lambda: viewer.add_marker()) + self.addWidget(w) + + # Clear all markers + w = QPushButton(self) + w.setIcon(QIcon(colored_image(":/icons/location-pin-clear.svg"))) + w.setIconSize(QSize(24, 24)) + w.setToolTip("Clear all markers") + w.clicked.connect(viewer.clear_markers) + self.addWidget(w) + + # Markers' size + self.marker_size_sp = w = ReturnSpinBox() + self.marker_size_sp.setSuffix(" µm") + self.marker_size_sp.setToolTip("Markers' size") + self.marker_size_sp.setMinimum(1) + self.marker_size_sp.setSingleStep(10) + self.marker_size_sp.setMaximum(2000) + self.marker_size_sp.setValue(int(laser_studio.viewer.default_marker_size)) + self.marker_size_sp.reset() + w.returnPressed.connect( + lambda: laser_studio.viewer.marker_size(float(self.marker_size_sp.value())) + ) + self.addWidget(self.marker_size_sp) diff --git a/laserstudio/widgets/toolbars/zoomtoolbar.py b/laserstudio/widgets/toolbars/zoomtoolbar.py index baa4116..03e0ff2 100644 --- a/laserstudio/widgets/toolbars/zoomtoolbar.py +++ b/laserstudio/widgets/toolbars/zoomtoolbar.py @@ -4,7 +4,6 @@ from PyQt6.QtWidgets import QToolBar, QPushButton from ...utils.util import colored_image from ..coloredbutton import ColoredPushButton -from ..return_line_edit import ReturnSpinBox if TYPE_CHECKING: from ...laserstudio import LaserStudio @@ -91,20 +90,6 @@ def __init__(self, laser_studio: "LaserStudio"): self.addWidget(self.position) self.position.setChecked(True) - # Markers' size - self.marker_size_sp = w = ReturnSpinBox() - self.marker_size_sp.setSuffix(" µm") - self.marker_size_sp.setToolTip("Markers' size") - self.marker_size_sp.setMinimum(1) - self.marker_size_sp.setSingleStep(10) - self.marker_size_sp.setMaximum(2000) - self.marker_size_sp.setValue(int(laser_studio.viewer.default_marker_size)) - self.marker_size_sp.reset() - w.returnPressed.connect( - lambda: laser_studio.viewer.marker_size(float(self.marker_size_sp.value())) - ) - self.addWidget(self.marker_size_sp) - def activate_mouse_tracking(self, activate: bool): if not activate: self.position.setText("Cursor Position") From b370935425332a489ff4f2badb7fd8d891be7e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20H=C3=A9riveaux?= Date: Fri, 26 Jul 2024 11:40:11 +0200 Subject: [PATCH 3/4] Removed laserstudio widget circular reference --- laserstudio/laserstudio.py | 2 +- laserstudio/widgets/toolbars/markerstoolbar.py | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/laserstudio/laserstudio.py b/laserstudio/laserstudio.py index 75d0ec3..899cfd5 100644 --- a/laserstudio/laserstudio.py +++ b/laserstudio/laserstudio.py @@ -83,7 +83,7 @@ def __init__(self, config: Optional[dict]): self.addToolBar(Qt.ToolBarArea.TopToolBarArea, toolbar) # Toolbar: Markers - toolbar = MarkersToolbar(self, self.viewer) + toolbar = MarkersToolbar(self.viewer) self.addToolBar(Qt.ToolBarArea.TopToolBarArea, toolbar) # Toolbar: Stage positioning diff --git a/laserstudio/widgets/toolbars/markerstoolbar.py b/laserstudio/widgets/toolbars/markerstoolbar.py index 89a4c39..6ad39e2 100644 --- a/laserstudio/widgets/toolbars/markerstoolbar.py +++ b/laserstudio/widgets/toolbars/markerstoolbar.py @@ -6,13 +6,10 @@ from ...utils.util import colored_image from ..viewer import Viewer -if TYPE_CHECKING: - from ...laserstudio import LaserStudio - class MarkersToolbar(QToolBar): - def __init__(self, laser_studio: "LaserStudio", viewer: Viewer): - super().__init__("Markers", laser_studio) + def __init__(self, viewer: Viewer): + super().__init__("Markers") self.setObjectName("toolbar-markers") # For settings save and restore self.setAllowedAreas(Qt.ToolBarArea.TopToolBarArea) self.setFloatable(True) @@ -22,7 +19,7 @@ def __init__(self, laser_studio: "LaserStudio", viewer: Viewer): w.setIcon(QIcon(colored_image(":/icons/location-pin-plus.svg"))) w.setIconSize(QSize(24, 24)) w.setToolTip("Add markers") - w.clicked.connect(lambda: viewer.add_marker()) + w.clicked.connect(viewer.add_marker) self.addWidget(w) # Clear all markers @@ -40,9 +37,9 @@ def __init__(self, laser_studio: "LaserStudio", viewer: Viewer): self.marker_size_sp.setMinimum(1) self.marker_size_sp.setSingleStep(10) self.marker_size_sp.setMaximum(2000) - self.marker_size_sp.setValue(int(laser_studio.viewer.default_marker_size)) + self.marker_size_sp.setValue(int(viewer.default_marker_size)) self.marker_size_sp.reset() w.returnPressed.connect( - lambda: laser_studio.viewer.marker_size(float(self.marker_size_sp.value())) + lambda: viewer.marker_size(float(self.marker_size_sp.value())) ) self.addWidget(self.marker_size_sp) From 11e923e66da3d5db886e665f395cf1a13a3fc764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20H=C3=A9riveaux?= Date: Fri, 26 Jul 2024 11:43:50 +0200 Subject: [PATCH 4/4] Fix --- laserstudio/widgets/toolbars/markerstoolbar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/laserstudio/widgets/toolbars/markerstoolbar.py b/laserstudio/widgets/toolbars/markerstoolbar.py index 6ad39e2..fb3fc36 100644 --- a/laserstudio/widgets/toolbars/markerstoolbar.py +++ b/laserstudio/widgets/toolbars/markerstoolbar.py @@ -19,7 +19,7 @@ def __init__(self, viewer: Viewer): w.setIcon(QIcon(colored_image(":/icons/location-pin-plus.svg"))) w.setIconSize(QSize(24, 24)) w.setToolTip("Add markers") - w.clicked.connect(viewer.add_marker) + w.clicked.connect(lambda: viewer.add_marker()) self.addWidget(w) # Clear all markers