Skip to content

Commit 547dfdc

Browse files
committed
Copy tooltip coords as TR str on label click
1 parent 7587cd6 commit 547dfdc

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

coperniFUS/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,15 @@ def descriptive_line_edit(default_text, description_text):
571571
return descr_line_edit
572572

573573

574+
class ClickableLabel(pyqtw.QLabel):
575+
clicked = pyqtc.pyqtSignal()
576+
577+
def mousePressEvent(self, event):
578+
if event.button() == pyqtc.Qt.MouseButton.LeftButton:
579+
self.clicked.emit()
580+
super().mousePressEvent(event)
581+
582+
574583
class AcceptRejectDialog(pyqtw.QDialog):
575584
def __init__(self, parent=None, title='Title', msg='Msg'):
576585
super().__init__(parent)

coperniFUS/modules/tooltip.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ def delete_rendered_object(self):
9797

9898
# --- Module specific attributes ---
9999

100+
def copy_tooltip_coords_as_strtr_to_clipboard(self):
101+
coords = self.tooltip_coordinates
102+
if coords is not None:
103+
tooltip_str_transform = ' '.join([
104+
f'T{ax}' + si_format(cc, format_str='{value}{prefix}m')
105+
for ax, cc in zip(['x', 'y', 'z'], coords)
106+
])
107+
108+
clipboard = self.parent_viewer.app.clipboard()
109+
clipboard.setText(tooltip_str_transform)
110+
100111
def _on_editor_parsed(self, param_name, edited_value):
101112
self.set_user_param(param_name, edited_value)
102113
self.parent_viewer.update_rendered_view()
@@ -118,13 +129,21 @@ def _init_status_bar_widget(self):
118129

119130
# Tooltip global coordinates widget
120131
space_conv = self.parent_viewer.ATLAS_SPACE_CONVENTION
121-
self.statusbar_label = pyqtw.QLabel(' Tooltip global coords: ')
122-
self.statusbar_x_coord_label = pyqtw.QLabel(f"{space_conv[0][:4]}. (x): 0 m")
132+
self.statusbar_label = ClickableLabel(' Tooltip global coords: ')
133+
self.statusbar_x_coord_label = ClickableLabel(f"{space_conv[0][:4]}. (x): 0 m")
123134
self.statusbar_x_coord_label.setStyleSheet(f'border: 0; color: {self.parent_viewer.x_RED};')
124-
self.statusbar_y_coord_label = pyqtw.QLabel(f"{space_conv[1][:4]}. (y): 0 m")
135+
self.statusbar_y_coord_label = ClickableLabel(f"{space_conv[1][:4]}. (y): 0 m")
125136
self.statusbar_y_coord_label.setStyleSheet(f'border: 0; color: {self.parent_viewer.y_GREEN};')
126-
self.statusbar_z_coord_label = pyqtw.QLabel(f"{space_conv[2][:4]}. (z): 0 m")
137+
self.statusbar_z_coord_label = ClickableLabel(f"{space_conv[2][:4]}. (z): 0 m")
127138
self.statusbar_z_coord_label.setStyleSheet(f'border: 0; color: {self.parent_viewer.z_BLUE};')
139+
140+
# Connect mouse click events
141+
self.statusbar_label.clicked.connect(self.copy_tooltip_coords_as_strtr_to_clipboard)
142+
self.statusbar_x_coord_label.clicked.connect(self.copy_tooltip_coords_as_strtr_to_clipboard)
143+
self.statusbar_y_coord_label.clicked.connect(self.copy_tooltip_coords_as_strtr_to_clipboard)
144+
self.statusbar_z_coord_label.clicked.connect(self.copy_tooltip_coords_as_strtr_to_clipboard)
145+
146+
# Add widgets to toolbar
128147
self.parent_viewer.statusBar().addPermanentWidget(self.statusbar_label)
129148
self.parent_viewer.statusBar().addPermanentWidget(self.statusbar_x_coord_label)
130149
self.parent_viewer.statusBar().addPermanentWidget(self.statusbar_y_coord_label)

0 commit comments

Comments
 (0)