Skip to content

Commit

Permalink
Merge pull request #7 from Ledger-Donjon/marker-clear-button
Browse files Browse the repository at this point in the history
Added menu to clear markers
  • Loading branch information
mmouchous-ledger authored Jul 26, 2024
2 parents 34c3d3b + 11e923e commit a7c05b6
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 18 deletions.
36 changes: 36 additions & 0 deletions laserstudio/icons/fontawesome-free/location-pin-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions laserstudio/icons/location-pin-clear.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions laserstudio/icons/location-pin-plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions laserstudio/laserstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
StageToolbar,
CameraToolbar,
MainToolbar,
MarkersToolbar,
PDMToolbar,
LaserDriverToolbar,
CameraNITToolBar,
Expand Down Expand Up @@ -81,6 +82,10 @@ def __init__(self, config: Optional[dict]):
toolbar = ZoomToolbar(self)
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, toolbar)

# Toolbar: Markers
toolbar = MarkersToolbar(self.viewer)
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, toolbar)

# Toolbar: Stage positioning
if self.instruments.stage is not None:
toolbar = StageToolbar(self)
Expand Down
3 changes: 3 additions & 0 deletions laserstudio/widgets/toolbars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -20,4 +22,5 @@
"LaserToolbar",
"LaserDriverToolbar",
"PDMToolbar",
"MarkersToolbar",
]
7 changes: 4 additions & 3 deletions laserstudio/widgets/toolbars/maintoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

class MainToolbar(QToolBar):
def __init__(self, laser_studio: "LaserStudio"):
"""
: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
Expand Down
45 changes: 45 additions & 0 deletions laserstudio/widgets/toolbars/markerstoolbar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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


class MarkersToolbar(QToolBar):
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)

# 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(viewer.default_marker_size))
self.marker_size_sp.reset()
w.returnPressed.connect(
lambda: viewer.marker_size(float(self.marker_size_sp.value()))
)
self.addWidget(self.marker_size_sp)
15 changes: 0 additions & 15 deletions laserstudio/widgets/toolbars/zoomtoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions laserstudio/widgets/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,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."""
Expand Down

0 comments on commit a7c05b6

Please sign in to comment.