lazylabel-gui 1.0.9__py3-none-any.whl → 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lazylabel/__init__.py +9 -0
- lazylabel/config/__init__.py +7 -0
- lazylabel/config/hotkeys.py +169 -0
- lazylabel/config/paths.py +41 -0
- lazylabel/config/settings.py +66 -0
- lazylabel/core/__init__.py +7 -0
- lazylabel/core/file_manager.py +106 -0
- lazylabel/core/model_manager.py +97 -0
- lazylabel/core/segment_manager.py +171 -0
- lazylabel/main.py +20 -1262
- lazylabel/models/__init__.py +5 -0
- lazylabel/models/sam_model.py +195 -0
- lazylabel/ui/__init__.py +8 -0
- lazylabel/ui/control_panel.py +237 -0
- lazylabel/{editable_vertex.py → ui/editable_vertex.py} +25 -3
- lazylabel/ui/hotkey_dialog.py +384 -0
- lazylabel/{hoverable_polygon_item.py → ui/hoverable_polygon_item.py} +17 -1
- lazylabel/ui/main_window.py +1546 -0
- lazylabel/ui/right_panel.py +315 -0
- lazylabel/ui/widgets/__init__.py +8 -0
- lazylabel/ui/widgets/adjustments_widget.py +107 -0
- lazylabel/ui/widgets/model_selection_widget.py +94 -0
- lazylabel/ui/widgets/settings_widget.py +106 -0
- lazylabel/ui/widgets/status_bar.py +109 -0
- lazylabel/utils/__init__.py +6 -0
- lazylabel/{custom_file_system_model.py → utils/custom_file_system_model.py} +9 -3
- {lazylabel_gui-1.0.9.dist-info → lazylabel_gui-1.1.1.dist-info}/METADATA +61 -11
- lazylabel_gui-1.1.1.dist-info/RECORD +37 -0
- lazylabel/controls.py +0 -265
- lazylabel/sam_model.py +0 -70
- lazylabel_gui-1.0.9.dist-info/RECORD +0 -17
- /lazylabel/{hoverable_pixelmap_item.py → ui/hoverable_pixelmap_item.py} +0 -0
- /lazylabel/{numeric_table_widget_item.py → ui/numeric_table_widget_item.py} +0 -0
- /lazylabel/{photo_viewer.py → ui/photo_viewer.py} +0 -0
- /lazylabel/{reorderable_class_table.py → ui/reorderable_class_table.py} +0 -0
- /lazylabel/{utils.py → utils/utils.py} +0 -0
- {lazylabel_gui-1.0.9.dist-info → lazylabel_gui-1.1.1.dist-info}/WHEEL +0 -0
- {lazylabel_gui-1.0.9.dist-info → lazylabel_gui-1.1.1.dist-info}/entry_points.txt +0 -0
- {lazylabel_gui-1.0.9.dist-info → lazylabel_gui-1.1.1.dist-info}/licenses/LICENSE +0 -0
- {lazylabel_gui-1.0.9.dist-info → lazylabel_gui-1.1.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,195 @@
|
|
1
|
+
import os
|
2
|
+
import cv2
|
3
|
+
import numpy as np
|
4
|
+
import torch
|
5
|
+
import requests
|
6
|
+
from tqdm import tqdm
|
7
|
+
from segment_anything import sam_model_registry, SamPredictor
|
8
|
+
|
9
|
+
|
10
|
+
def download_model(url, download_path):
|
11
|
+
"""Downloads file with a progress bar."""
|
12
|
+
print(f"[10/20] SAM model not found. Downloading from Meta's repository...")
|
13
|
+
print(f" Downloading to: {download_path}")
|
14
|
+
try:
|
15
|
+
print(f"[10/20] Connecting to download server...")
|
16
|
+
response = requests.get(url, stream=True, timeout=30)
|
17
|
+
response.raise_for_status()
|
18
|
+
total_size_in_bytes = int(response.headers.get("content-length", 0))
|
19
|
+
block_size = 1024 # 1 Kibibyte
|
20
|
+
|
21
|
+
print(
|
22
|
+
f"[10/20] Starting download ({total_size_in_bytes / (1024*1024*1024):.1f} GB)..."
|
23
|
+
)
|
24
|
+
progress_bar = tqdm(total=total_size_in_bytes, unit="iB", unit_scale=True)
|
25
|
+
with open(download_path, "wb") as file:
|
26
|
+
for data in response.iter_content(block_size):
|
27
|
+
progress_bar.update(len(data))
|
28
|
+
file.write(data)
|
29
|
+
progress_bar.close()
|
30
|
+
|
31
|
+
if total_size_in_bytes != 0 and progress_bar.n != total_size_in_bytes:
|
32
|
+
raise RuntimeError("Download incomplete - file size mismatch")
|
33
|
+
|
34
|
+
print("[10/20] Model download completed successfully.")
|
35
|
+
|
36
|
+
except requests.exceptions.ConnectionError as e:
|
37
|
+
raise RuntimeError(
|
38
|
+
f"[10/20] Network connection failed: Check your internet connection"
|
39
|
+
)
|
40
|
+
except requests.exceptions.Timeout as e:
|
41
|
+
raise RuntimeError(f"[10/20] Download timeout: Server took too long to respond")
|
42
|
+
except requests.exceptions.HTTPError as e:
|
43
|
+
raise RuntimeError(
|
44
|
+
f"[10/20] HTTP error {e.response.status_code}: Server rejected request"
|
45
|
+
)
|
46
|
+
except requests.exceptions.RequestException as e:
|
47
|
+
raise RuntimeError(f"[10/20] Network error during download: {e}")
|
48
|
+
except PermissionError as e:
|
49
|
+
raise RuntimeError(
|
50
|
+
f"[10/20] Permission denied: Cannot write to {download_path}"
|
51
|
+
)
|
52
|
+
except OSError as e:
|
53
|
+
raise RuntimeError(f"[10/20] Disk error: {e} (check available disk space)")
|
54
|
+
except Exception as e:
|
55
|
+
# Clean up partial download
|
56
|
+
if os.path.exists(download_path):
|
57
|
+
try:
|
58
|
+
os.remove(download_path)
|
59
|
+
except:
|
60
|
+
pass
|
61
|
+
raise RuntimeError(f"[10/20] Download failed: {e}")
|
62
|
+
|
63
|
+
|
64
|
+
class SamModel:
|
65
|
+
def __init__(
|
66
|
+
self,
|
67
|
+
model_type="vit_h",
|
68
|
+
model_filename="sam_vit_h_4b8939.pth",
|
69
|
+
custom_model_path=None,
|
70
|
+
):
|
71
|
+
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
72
|
+
print(f"[9/20] Detected device: {str(self.device).upper()}")
|
73
|
+
|
74
|
+
self.current_model_type = model_type
|
75
|
+
self.current_model_path = custom_model_path
|
76
|
+
self.model = None
|
77
|
+
self.predictor = None
|
78
|
+
self.image = None
|
79
|
+
self.is_loaded = False
|
80
|
+
|
81
|
+
try:
|
82
|
+
if custom_model_path and os.path.exists(custom_model_path):
|
83
|
+
# Use custom model path
|
84
|
+
model_path = custom_model_path
|
85
|
+
print(f"[10/20] Loading custom SAM model from {model_path}...")
|
86
|
+
else:
|
87
|
+
# Use default model with download if needed - store in models folder
|
88
|
+
model_url = (
|
89
|
+
f"https://dl.fbaipublicfiles.com/segment_anything/{model_filename}"
|
90
|
+
)
|
91
|
+
|
92
|
+
# Use models folder instead of cache folder
|
93
|
+
models_dir = os.path.dirname(__file__) # Already in models directory
|
94
|
+
os.makedirs(models_dir, exist_ok=True)
|
95
|
+
model_path = os.path.join(models_dir, model_filename)
|
96
|
+
|
97
|
+
# Also check the old cache location and move it if it exists
|
98
|
+
old_cache_dir = os.path.join(
|
99
|
+
os.path.expanduser("~"), ".cache", "lazylabel"
|
100
|
+
)
|
101
|
+
old_model_path = os.path.join(old_cache_dir, model_filename)
|
102
|
+
|
103
|
+
if os.path.exists(old_model_path) and not os.path.exists(model_path):
|
104
|
+
print(
|
105
|
+
f"[10/20] Moving existing model from cache to models folder..."
|
106
|
+
)
|
107
|
+
import shutil
|
108
|
+
|
109
|
+
shutil.move(old_model_path, model_path)
|
110
|
+
elif not os.path.exists(model_path):
|
111
|
+
# Download the model if it doesn't exist
|
112
|
+
download_model(model_url, model_path)
|
113
|
+
|
114
|
+
print(f"[10/20] Loading default SAM model from {model_path}...")
|
115
|
+
|
116
|
+
print(f"[11/20] Initializing {model_type.upper()} model architecture...")
|
117
|
+
self.model = sam_model_registry[model_type](checkpoint=model_path).to(
|
118
|
+
self.device
|
119
|
+
)
|
120
|
+
|
121
|
+
print(f"[12/20] Setting up predictor...")
|
122
|
+
self.predictor = SamPredictor(self.model)
|
123
|
+
self.is_loaded = True
|
124
|
+
print("[13/20] SAM model loaded successfully.")
|
125
|
+
|
126
|
+
except Exception as e:
|
127
|
+
print(f"[8/20] Failed to load SAM model: {e}")
|
128
|
+
print(f"[8/20] SAM point functionality will be disabled.")
|
129
|
+
self.is_loaded = False
|
130
|
+
|
131
|
+
def load_custom_model(self, model_path, model_type="vit_h"):
|
132
|
+
"""Load a custom model from the specified path."""
|
133
|
+
if not os.path.exists(model_path):
|
134
|
+
print(f"Model file not found: {model_path}")
|
135
|
+
return False
|
136
|
+
|
137
|
+
print(f"Loading custom SAM model from {model_path}...")
|
138
|
+
try:
|
139
|
+
# Clear existing model from memory
|
140
|
+
if hasattr(self, "model") and self.model is not None:
|
141
|
+
del self.model
|
142
|
+
del self.predictor
|
143
|
+
torch.cuda.empty_cache() if torch.cuda.is_available() else None
|
144
|
+
|
145
|
+
# Load new model
|
146
|
+
self.model = sam_model_registry[model_type](checkpoint=model_path).to(
|
147
|
+
self.device
|
148
|
+
)
|
149
|
+
self.predictor = SamPredictor(self.model)
|
150
|
+
self.current_model_type = model_type
|
151
|
+
self.current_model_path = model_path
|
152
|
+
self.is_loaded = True
|
153
|
+
|
154
|
+
# Re-set image if one was previously loaded
|
155
|
+
if self.image is not None:
|
156
|
+
self.predictor.set_image(self.image)
|
157
|
+
|
158
|
+
print("Custom SAM model loaded successfully.")
|
159
|
+
return True
|
160
|
+
except Exception as e:
|
161
|
+
print(f"Error loading custom model: {e}")
|
162
|
+
self.is_loaded = False
|
163
|
+
self.model = None
|
164
|
+
self.predictor = None
|
165
|
+
return False
|
166
|
+
|
167
|
+
def set_image(self, image_path):
|
168
|
+
if not self.is_loaded:
|
169
|
+
return False
|
170
|
+
try:
|
171
|
+
self.image = cv2.imread(image_path)
|
172
|
+
self.image = cv2.cvtColor(self.image, cv2.COLOR_BGR2RGB)
|
173
|
+
self.predictor.set_image(self.image)
|
174
|
+
return True
|
175
|
+
except Exception as e:
|
176
|
+
print(f"Error setting image: {e}")
|
177
|
+
return False
|
178
|
+
|
179
|
+
def predict(self, positive_points, negative_points):
|
180
|
+
if not self.is_loaded or not positive_points:
|
181
|
+
return None
|
182
|
+
|
183
|
+
try:
|
184
|
+
points = np.array(positive_points + negative_points)
|
185
|
+
labels = np.array([1] * len(positive_points) + [0] * len(negative_points))
|
186
|
+
|
187
|
+
masks, _, _ = self.predictor.predict(
|
188
|
+
point_coords=points,
|
189
|
+
point_labels=labels,
|
190
|
+
multimask_output=False,
|
191
|
+
)
|
192
|
+
return masks[0]
|
193
|
+
except Exception as e:
|
194
|
+
print(f"Error during prediction: {e}")
|
195
|
+
return None
|
lazylabel/ui/__init__.py
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
"""UI components for LazyLabel."""
|
2
|
+
|
3
|
+
from .main_window import MainWindow
|
4
|
+
from .control_panel import ControlPanel
|
5
|
+
from .right_panel import RightPanel
|
6
|
+
from .hotkey_dialog import HotkeyDialog
|
7
|
+
|
8
|
+
__all__ = ['MainWindow', 'ControlPanel', 'RightPanel', 'HotkeyDialog']
|
@@ -0,0 +1,237 @@
|
|
1
|
+
"""Left control panel with mode controls and settings."""
|
2
|
+
|
3
|
+
from PyQt6.QtWidgets import (
|
4
|
+
QWidget,
|
5
|
+
QVBoxLayout,
|
6
|
+
QPushButton,
|
7
|
+
QLabel,
|
8
|
+
QFrame,
|
9
|
+
QHBoxLayout,
|
10
|
+
QCheckBox,
|
11
|
+
QSlider,
|
12
|
+
QGroupBox,
|
13
|
+
QComboBox,
|
14
|
+
)
|
15
|
+
from PyQt6.QtCore import Qt, pyqtSignal
|
16
|
+
|
17
|
+
from .widgets import ModelSelectionWidget, SettingsWidget, AdjustmentsWidget
|
18
|
+
|
19
|
+
|
20
|
+
class ControlPanel(QWidget):
|
21
|
+
"""Left control panel with mode controls and settings."""
|
22
|
+
|
23
|
+
# Signals
|
24
|
+
sam_mode_requested = pyqtSignal()
|
25
|
+
polygon_mode_requested = pyqtSignal()
|
26
|
+
selection_mode_requested = pyqtSignal()
|
27
|
+
clear_points_requested = pyqtSignal()
|
28
|
+
fit_view_requested = pyqtSignal()
|
29
|
+
browse_models_requested = pyqtSignal()
|
30
|
+
refresh_models_requested = pyqtSignal()
|
31
|
+
model_selected = pyqtSignal(str)
|
32
|
+
annotation_size_changed = pyqtSignal(int)
|
33
|
+
pan_speed_changed = pyqtSignal(int)
|
34
|
+
join_threshold_changed = pyqtSignal(int)
|
35
|
+
hotkeys_requested = pyqtSignal()
|
36
|
+
pop_out_requested = pyqtSignal()
|
37
|
+
|
38
|
+
def __init__(self, parent=None):
|
39
|
+
super().__init__(parent)
|
40
|
+
self.setMinimumWidth(50) # Allow collapsing but maintain minimum
|
41
|
+
self.preferred_width = 250 # Store preferred width for expansion
|
42
|
+
self._setup_ui()
|
43
|
+
self._connect_signals()
|
44
|
+
|
45
|
+
def _setup_ui(self):
|
46
|
+
"""Setup the UI layout."""
|
47
|
+
layout = QVBoxLayout(self)
|
48
|
+
layout.setAlignment(Qt.AlignmentFlag.AlignTop)
|
49
|
+
|
50
|
+
# Top button row
|
51
|
+
toggle_layout = QHBoxLayout()
|
52
|
+
toggle_layout.addStretch()
|
53
|
+
|
54
|
+
self.btn_popout = QPushButton("⋯")
|
55
|
+
self.btn_popout.setToolTip("Pop out panel to separate window")
|
56
|
+
self.btn_popout.setMaximumWidth(30)
|
57
|
+
toggle_layout.addWidget(self.btn_popout)
|
58
|
+
|
59
|
+
layout.addLayout(toggle_layout)
|
60
|
+
|
61
|
+
# Main controls widget
|
62
|
+
self.main_controls_widget = QWidget()
|
63
|
+
main_layout = QVBoxLayout(self.main_controls_widget)
|
64
|
+
main_layout.setContentsMargins(0, 0, 0, 0)
|
65
|
+
|
66
|
+
# Mode label
|
67
|
+
self.mode_label = QLabel("Mode: Points")
|
68
|
+
font = self.mode_label.font()
|
69
|
+
font.setPointSize(14)
|
70
|
+
font.setBold(True)
|
71
|
+
self.mode_label.setFont(font)
|
72
|
+
main_layout.addWidget(self.mode_label)
|
73
|
+
|
74
|
+
# Mode buttons
|
75
|
+
self._add_mode_buttons(main_layout)
|
76
|
+
|
77
|
+
# Separator
|
78
|
+
main_layout.addSpacing(20)
|
79
|
+
main_layout.addWidget(self._create_separator())
|
80
|
+
main_layout.addSpacing(10)
|
81
|
+
|
82
|
+
# Model selection
|
83
|
+
self.model_widget = ModelSelectionWidget()
|
84
|
+
main_layout.addWidget(self.model_widget)
|
85
|
+
|
86
|
+
# Separator
|
87
|
+
main_layout.addSpacing(10)
|
88
|
+
main_layout.addWidget(self._create_separator())
|
89
|
+
main_layout.addSpacing(10)
|
90
|
+
|
91
|
+
# Action buttons
|
92
|
+
self._add_action_buttons(main_layout)
|
93
|
+
main_layout.addSpacing(10)
|
94
|
+
|
95
|
+
# Settings
|
96
|
+
self.settings_widget = SettingsWidget()
|
97
|
+
main_layout.addWidget(self.settings_widget)
|
98
|
+
|
99
|
+
# Adjustments
|
100
|
+
self.adjustments_widget = AdjustmentsWidget()
|
101
|
+
main_layout.addWidget(self.adjustments_widget)
|
102
|
+
|
103
|
+
main_layout.addStretch()
|
104
|
+
|
105
|
+
# Status labels
|
106
|
+
self.notification_label = QLabel("")
|
107
|
+
font = self.notification_label.font()
|
108
|
+
font.setItalic(True)
|
109
|
+
self.notification_label.setFont(font)
|
110
|
+
self.notification_label.setStyleSheet("color: #ffa500;")
|
111
|
+
self.notification_label.setWordWrap(True)
|
112
|
+
main_layout.addWidget(self.notification_label)
|
113
|
+
|
114
|
+
layout.addWidget(self.main_controls_widget)
|
115
|
+
|
116
|
+
def _add_mode_buttons(self, layout):
|
117
|
+
"""Add mode control buttons."""
|
118
|
+
self.btn_sam_mode = QPushButton("Point Mode (1)")
|
119
|
+
self.btn_sam_mode.setToolTip("Switch to Point Mode for AI segmentation (1)")
|
120
|
+
|
121
|
+
self.btn_polygon_mode = QPushButton("Polygon Mode (2)")
|
122
|
+
self.btn_polygon_mode.setToolTip("Switch to Polygon Drawing Mode (2)")
|
123
|
+
|
124
|
+
self.btn_selection_mode = QPushButton("Selection Mode (E)")
|
125
|
+
self.btn_selection_mode.setToolTip("Toggle segment selection (E)")
|
126
|
+
|
127
|
+
layout.addWidget(self.btn_sam_mode)
|
128
|
+
layout.addWidget(self.btn_polygon_mode)
|
129
|
+
layout.addWidget(self.btn_selection_mode)
|
130
|
+
|
131
|
+
def _add_action_buttons(self, layout):
|
132
|
+
"""Add action buttons."""
|
133
|
+
self.btn_fit_view = QPushButton("Fit View (.)")
|
134
|
+
self.btn_fit_view.setToolTip("Reset image zoom and pan to fit the view (.)")
|
135
|
+
|
136
|
+
self.btn_clear_points = QPushButton("Clear Clicks (C)")
|
137
|
+
self.btn_clear_points.setToolTip("Clear current temporary points/vertices (C)")
|
138
|
+
|
139
|
+
self.btn_hotkeys = QPushButton("Hotkeys")
|
140
|
+
self.btn_hotkeys.setToolTip("Configure keyboard shortcuts")
|
141
|
+
|
142
|
+
layout.addWidget(self.btn_fit_view)
|
143
|
+
layout.addWidget(self.btn_clear_points)
|
144
|
+
layout.addWidget(self.btn_hotkeys)
|
145
|
+
|
146
|
+
def _create_separator(self):
|
147
|
+
"""Create a horizontal separator line."""
|
148
|
+
line = QFrame()
|
149
|
+
line.setFrameShape(QFrame.Shape.HLine)
|
150
|
+
return line
|
151
|
+
|
152
|
+
def _connect_signals(self):
|
153
|
+
"""Connect internal signals."""
|
154
|
+
self.btn_sam_mode.clicked.connect(self.sam_mode_requested)
|
155
|
+
self.btn_polygon_mode.clicked.connect(self.polygon_mode_requested)
|
156
|
+
self.btn_selection_mode.clicked.connect(self.selection_mode_requested)
|
157
|
+
self.btn_clear_points.clicked.connect(self.clear_points_requested)
|
158
|
+
self.btn_fit_view.clicked.connect(self.fit_view_requested)
|
159
|
+
self.btn_hotkeys.clicked.connect(self.hotkeys_requested)
|
160
|
+
self.btn_popout.clicked.connect(self.pop_out_requested)
|
161
|
+
|
162
|
+
def mouseDoubleClickEvent(self, event):
|
163
|
+
"""Handle double-click to expand collapsed panel."""
|
164
|
+
if self.width() < 50: # If panel is collapsed
|
165
|
+
# Request expansion by calling parent method
|
166
|
+
if self.parent() and hasattr(self.parent(), "_expand_left_panel"):
|
167
|
+
self.parent()._expand_left_panel()
|
168
|
+
super().mouseDoubleClickEvent(event)
|
169
|
+
|
170
|
+
# Model widget signals
|
171
|
+
self.model_widget.browse_requested.connect(self.browse_models_requested)
|
172
|
+
self.model_widget.refresh_requested.connect(self.refresh_models_requested)
|
173
|
+
self.model_widget.model_selected.connect(self.model_selected)
|
174
|
+
|
175
|
+
# Settings widget signals
|
176
|
+
self.adjustments_widget.annotation_size_changed.connect(
|
177
|
+
self.annotation_size_changed
|
178
|
+
)
|
179
|
+
self.adjustments_widget.pan_speed_changed.connect(self.pan_speed_changed)
|
180
|
+
self.adjustments_widget.join_threshold_changed.connect(
|
181
|
+
self.join_threshold_changed
|
182
|
+
)
|
183
|
+
|
184
|
+
def show_notification(self, message: str, duration: int = 3000):
|
185
|
+
"""Show a notification message."""
|
186
|
+
self.notification_label.setText(message)
|
187
|
+
# Note: Timer should be handled by the caller
|
188
|
+
|
189
|
+
def clear_notification(self):
|
190
|
+
"""Clear the notification message."""
|
191
|
+
self.notification_label.clear()
|
192
|
+
|
193
|
+
def set_mode_text(self, mode: str):
|
194
|
+
"""Set the mode label text."""
|
195
|
+
self.mode_label.setText(f"Mode: {mode.replace('_', ' ').title()}")
|
196
|
+
|
197
|
+
# Delegate methods for sub-widgets
|
198
|
+
def populate_models(self, models):
|
199
|
+
"""Populate the models combo box."""
|
200
|
+
self.model_widget.populate_models(models)
|
201
|
+
|
202
|
+
def set_current_model(self, model_name):
|
203
|
+
"""Set the current model display."""
|
204
|
+
self.model_widget.set_current_model(model_name)
|
205
|
+
|
206
|
+
def get_settings(self):
|
207
|
+
"""Get current settings from the settings widget."""
|
208
|
+
return self.settings_widget.get_settings()
|
209
|
+
|
210
|
+
def set_settings(self, settings):
|
211
|
+
"""Set settings in the settings widget."""
|
212
|
+
self.settings_widget.set_settings(settings)
|
213
|
+
|
214
|
+
def get_annotation_size(self):
|
215
|
+
"""Get current annotation size."""
|
216
|
+
return self.adjustments_widget.get_annotation_size()
|
217
|
+
|
218
|
+
def set_annotation_size(self, value):
|
219
|
+
"""Set annotation size."""
|
220
|
+
self.adjustments_widget.set_annotation_size(value)
|
221
|
+
|
222
|
+
def set_sam_mode_enabled(self, enabled: bool):
|
223
|
+
"""Enable or disable the SAM mode button."""
|
224
|
+
self.btn_sam_mode.setEnabled(enabled)
|
225
|
+
if not enabled:
|
226
|
+
self.btn_sam_mode.setToolTip("Point Mode (SAM model not available)")
|
227
|
+
else:
|
228
|
+
self.btn_sam_mode.setToolTip("Switch to Point Mode for AI segmentation (1)")
|
229
|
+
|
230
|
+
def set_popout_mode(self, is_popped_out: bool):
|
231
|
+
"""Update the pop-out button based on panel state."""
|
232
|
+
if is_popped_out:
|
233
|
+
self.btn_popout.setText("⇤")
|
234
|
+
self.btn_popout.setToolTip("Return panel to main window")
|
235
|
+
else:
|
236
|
+
self.btn_popout.setText("⋯")
|
237
|
+
self.btn_popout.setToolTip("Pop out panel to separate window")
|
@@ -17,13 +17,35 @@ class EditableVertexItem(QGraphicsEllipseItem):
|
|
17
17
|
self.setBrush(QBrush(color))
|
18
18
|
|
19
19
|
self.setPen(QPen(Qt.GlobalColor.transparent))
|
20
|
+
|
21
|
+
# Set flags for dragging - use the original working approach
|
20
22
|
self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsMovable)
|
21
23
|
self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemSendsGeometryChanges)
|
24
|
+
self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsSelectable)
|
25
|
+
|
26
|
+
# Accept mouse events
|
27
|
+
self.setAcceptHoverEvents(True)
|
22
28
|
|
23
29
|
def itemChange(self, change, value):
|
24
30
|
if change == QGraphicsItem.GraphicsItemChange.ItemPositionHasChanged:
|
25
31
|
new_pos = value
|
26
|
-
self.main_window
|
27
|
-
self.
|
28
|
-
|
32
|
+
if hasattr(self.main_window, "update_vertex_pos"):
|
33
|
+
self.main_window.update_vertex_pos(
|
34
|
+
self.segment_index, self.vertex_index, new_pos
|
35
|
+
)
|
29
36
|
return super().itemChange(change, value)
|
37
|
+
|
38
|
+
def mousePressEvent(self, event):
|
39
|
+
"""Handle mouse press events."""
|
40
|
+
super().mousePressEvent(event)
|
41
|
+
event.accept()
|
42
|
+
|
43
|
+
def mouseMoveEvent(self, event):
|
44
|
+
"""Handle mouse move events."""
|
45
|
+
super().mouseMoveEvent(event)
|
46
|
+
event.accept()
|
47
|
+
|
48
|
+
def mouseReleaseEvent(self, event):
|
49
|
+
"""Handle mouse release events."""
|
50
|
+
super().mouseReleaseEvent(event)
|
51
|
+
event.accept()
|