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,315 @@
|
|
1
|
+
"""Right panel with file explorer and segment management."""
|
2
|
+
|
3
|
+
from PyQt6.QtWidgets import (
|
4
|
+
QWidget,
|
5
|
+
QVBoxLayout,
|
6
|
+
QPushButton,
|
7
|
+
QLabel,
|
8
|
+
QHBoxLayout,
|
9
|
+
QTableWidget,
|
10
|
+
QTreeView,
|
11
|
+
QComboBox,
|
12
|
+
QSplitter,
|
13
|
+
QSpacerItem,
|
14
|
+
QHeaderView,
|
15
|
+
)
|
16
|
+
from PyQt6.QtCore import Qt, pyqtSignal
|
17
|
+
from PyQt6.QtGui import QBrush, QColor
|
18
|
+
|
19
|
+
from .reorderable_class_table import ReorderableClassTable
|
20
|
+
from .numeric_table_widget_item import NumericTableWidgetItem
|
21
|
+
|
22
|
+
|
23
|
+
class RightPanel(QWidget):
|
24
|
+
"""Right panel with file explorer and segment management."""
|
25
|
+
|
26
|
+
# Signals
|
27
|
+
open_folder_requested = pyqtSignal()
|
28
|
+
image_selected = pyqtSignal("QModelIndex")
|
29
|
+
merge_selection_requested = pyqtSignal()
|
30
|
+
delete_selection_requested = pyqtSignal()
|
31
|
+
segments_selection_changed = pyqtSignal()
|
32
|
+
class_alias_changed = pyqtSignal(int, str) # class_id, alias
|
33
|
+
reassign_classes_requested = pyqtSignal()
|
34
|
+
class_filter_changed = pyqtSignal()
|
35
|
+
class_toggled = pyqtSignal(int) # class_id
|
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 = 350 # 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
|
+
self.v_layout = QVBoxLayout(self)
|
48
|
+
|
49
|
+
# Top button row
|
50
|
+
toggle_layout = QHBoxLayout()
|
51
|
+
|
52
|
+
self.btn_popout = QPushButton("⋯")
|
53
|
+
self.btn_popout.setToolTip("Pop out panel to separate window")
|
54
|
+
self.btn_popout.setMaximumWidth(30)
|
55
|
+
toggle_layout.addWidget(self.btn_popout)
|
56
|
+
|
57
|
+
toggle_layout.addStretch()
|
58
|
+
|
59
|
+
self.v_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
|
+
# Vertical splitter for sections
|
67
|
+
v_splitter = QSplitter(Qt.Orientation.Vertical)
|
68
|
+
|
69
|
+
# File explorer section
|
70
|
+
self._setup_file_explorer(v_splitter)
|
71
|
+
|
72
|
+
# Segment management section
|
73
|
+
self._setup_segment_management(v_splitter)
|
74
|
+
|
75
|
+
# Class management section
|
76
|
+
self._setup_class_management(v_splitter)
|
77
|
+
|
78
|
+
main_layout.addWidget(v_splitter)
|
79
|
+
|
80
|
+
# Status label
|
81
|
+
self.status_label = QLabel("")
|
82
|
+
self.status_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
83
|
+
main_layout.addWidget(self.status_label)
|
84
|
+
|
85
|
+
self.v_layout.addWidget(self.main_controls_widget)
|
86
|
+
|
87
|
+
def _setup_file_explorer(self, splitter):
|
88
|
+
"""Setup file explorer section."""
|
89
|
+
file_explorer_widget = QWidget()
|
90
|
+
layout = QVBoxLayout(file_explorer_widget)
|
91
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
92
|
+
|
93
|
+
self.btn_open_folder = QPushButton("Open Image Folder")
|
94
|
+
self.btn_open_folder.setToolTip("Open a directory of images")
|
95
|
+
layout.addWidget(self.btn_open_folder)
|
96
|
+
|
97
|
+
self.file_tree = QTreeView()
|
98
|
+
layout.addWidget(self.file_tree)
|
99
|
+
|
100
|
+
splitter.addWidget(file_explorer_widget)
|
101
|
+
|
102
|
+
def _setup_segment_management(self, splitter):
|
103
|
+
"""Setup segment management section."""
|
104
|
+
segment_widget = QWidget()
|
105
|
+
layout = QVBoxLayout(segment_widget)
|
106
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
107
|
+
|
108
|
+
# Class filter
|
109
|
+
filter_layout = QHBoxLayout()
|
110
|
+
filter_layout.addWidget(QLabel("Filter Class:"))
|
111
|
+
self.class_filter_combo = QComboBox()
|
112
|
+
self.class_filter_combo.setToolTip("Filter segments list by class")
|
113
|
+
filter_layout.addWidget(self.class_filter_combo)
|
114
|
+
layout.addLayout(filter_layout)
|
115
|
+
|
116
|
+
# Segment table
|
117
|
+
self.segment_table = QTableWidget()
|
118
|
+
self.segment_table.setColumnCount(3)
|
119
|
+
self.segment_table.setHorizontalHeaderLabels(
|
120
|
+
["Segment ID", "Class ID", "Alias"]
|
121
|
+
)
|
122
|
+
self.segment_table.horizontalHeader().setSectionResizeMode(
|
123
|
+
QHeaderView.ResizeMode.Stretch
|
124
|
+
)
|
125
|
+
self.segment_table.setSelectionBehavior(
|
126
|
+
QTableWidget.SelectionBehavior.SelectRows
|
127
|
+
)
|
128
|
+
self.segment_table.setSortingEnabled(True)
|
129
|
+
self.segment_table.setEditTriggers(QTableWidget.EditTrigger.NoEditTriggers)
|
130
|
+
layout.addWidget(self.segment_table)
|
131
|
+
|
132
|
+
# Action buttons
|
133
|
+
action_layout = QHBoxLayout()
|
134
|
+
self.btn_merge_selection = QPushButton("Merge to Class")
|
135
|
+
self.btn_merge_selection.setToolTip(
|
136
|
+
"Merge selected segments into a single class (M)"
|
137
|
+
)
|
138
|
+
self.btn_delete_selection = QPushButton("Delete")
|
139
|
+
self.btn_delete_selection.setToolTip(
|
140
|
+
"Delete selected segments (Delete/Backspace)"
|
141
|
+
)
|
142
|
+
action_layout.addWidget(self.btn_merge_selection)
|
143
|
+
action_layout.addWidget(self.btn_delete_selection)
|
144
|
+
layout.addLayout(action_layout)
|
145
|
+
|
146
|
+
splitter.addWidget(segment_widget)
|
147
|
+
|
148
|
+
def _setup_class_management(self, splitter):
|
149
|
+
"""Setup class management section."""
|
150
|
+
class_widget = QWidget()
|
151
|
+
layout = QVBoxLayout(class_widget)
|
152
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
153
|
+
|
154
|
+
layout.addWidget(QLabel("Class Order:"))
|
155
|
+
|
156
|
+
self.class_table = ReorderableClassTable()
|
157
|
+
self.class_table.setToolTip(
|
158
|
+
"Double-click to set class aliases and drag to reorder channels for saving.\nClick once to toggle as active class for new segments."
|
159
|
+
)
|
160
|
+
self.class_table.setColumnCount(2)
|
161
|
+
self.class_table.setHorizontalHeaderLabels(["Alias", "Class ID"])
|
162
|
+
self.class_table.horizontalHeader().setSectionResizeMode(
|
163
|
+
0, QHeaderView.ResizeMode.Stretch
|
164
|
+
)
|
165
|
+
self.class_table.horizontalHeader().setSectionResizeMode(
|
166
|
+
1, QHeaderView.ResizeMode.ResizeToContents
|
167
|
+
)
|
168
|
+
self.class_table.setEditTriggers(QTableWidget.EditTrigger.DoubleClicked)
|
169
|
+
layout.addWidget(self.class_table)
|
170
|
+
|
171
|
+
self.btn_reassign_classes = QPushButton("Reassign Class IDs")
|
172
|
+
self.btn_reassign_classes.setToolTip(
|
173
|
+
"Re-index class channels based on the current order in this table"
|
174
|
+
)
|
175
|
+
layout.addWidget(self.btn_reassign_classes)
|
176
|
+
|
177
|
+
splitter.addWidget(class_widget)
|
178
|
+
|
179
|
+
def _connect_signals(self):
|
180
|
+
"""Connect internal signals."""
|
181
|
+
self.btn_open_folder.clicked.connect(self.open_folder_requested)
|
182
|
+
self.file_tree.doubleClicked.connect(self.image_selected)
|
183
|
+
self.btn_merge_selection.clicked.connect(self.merge_selection_requested)
|
184
|
+
self.btn_delete_selection.clicked.connect(self.delete_selection_requested)
|
185
|
+
self.segment_table.itemSelectionChanged.connect(self.segments_selection_changed)
|
186
|
+
self.class_table.itemChanged.connect(self._handle_class_alias_change)
|
187
|
+
self.class_table.cellClicked.connect(self._handle_class_toggle)
|
188
|
+
self.btn_reassign_classes.clicked.connect(self.reassign_classes_requested)
|
189
|
+
self.class_filter_combo.currentIndexChanged.connect(self.class_filter_changed)
|
190
|
+
self.btn_popout.clicked.connect(self.pop_out_requested)
|
191
|
+
|
192
|
+
def mouseDoubleClickEvent(self, event):
|
193
|
+
"""Handle double-click to expand collapsed panel."""
|
194
|
+
if self.width() < 50: # If panel is collapsed
|
195
|
+
# Request expansion by calling parent method
|
196
|
+
if self.parent() and hasattr(self.parent(), "_expand_right_panel"):
|
197
|
+
self.parent()._expand_right_panel()
|
198
|
+
super().mouseDoubleClickEvent(event)
|
199
|
+
|
200
|
+
def _handle_class_alias_change(self, item):
|
201
|
+
"""Handle class alias change in table."""
|
202
|
+
if item.column() != 0: # Only handle alias column
|
203
|
+
return
|
204
|
+
|
205
|
+
class_table = self.class_table
|
206
|
+
id_item = class_table.item(item.row(), 1)
|
207
|
+
if id_item:
|
208
|
+
try:
|
209
|
+
class_id = int(id_item.text())
|
210
|
+
self.class_alias_changed.emit(class_id, item.text())
|
211
|
+
except (ValueError, AttributeError):
|
212
|
+
pass
|
213
|
+
|
214
|
+
def _handle_class_toggle(self, row, column):
|
215
|
+
"""Handle class table cell click for toggling active class."""
|
216
|
+
# Get the class ID from the clicked row
|
217
|
+
id_item = self.class_table.item(row, 1)
|
218
|
+
if id_item:
|
219
|
+
try:
|
220
|
+
class_id = int(id_item.text())
|
221
|
+
self.class_toggled.emit(class_id)
|
222
|
+
except (ValueError, AttributeError):
|
223
|
+
pass
|
224
|
+
|
225
|
+
def update_active_class_display(self, active_class_id):
|
226
|
+
"""Update the visual display to show which class is active."""
|
227
|
+
# Block signals to prevent triggering change events during update
|
228
|
+
self.class_table.blockSignals(True)
|
229
|
+
|
230
|
+
for row in range(self.class_table.rowCount()):
|
231
|
+
id_item = self.class_table.item(row, 1)
|
232
|
+
alias_item = self.class_table.item(row, 0)
|
233
|
+
if id_item and alias_item:
|
234
|
+
try:
|
235
|
+
class_id = int(id_item.text())
|
236
|
+
if class_id == active_class_id:
|
237
|
+
# Make active class bold and add indicator
|
238
|
+
font = alias_item.font()
|
239
|
+
font.setBold(True)
|
240
|
+
alias_item.setFont(font)
|
241
|
+
id_item.setFont(font)
|
242
|
+
# Add visual indicator
|
243
|
+
if not alias_item.text().startswith("🔸 "):
|
244
|
+
alias_item.setText(f"🔸 {alias_item.text()}")
|
245
|
+
else:
|
246
|
+
# Make inactive classes normal
|
247
|
+
font = alias_item.font()
|
248
|
+
font.setBold(False)
|
249
|
+
alias_item.setFont(font)
|
250
|
+
id_item.setFont(font)
|
251
|
+
# Remove visual indicator
|
252
|
+
if alias_item.text().startswith("🔸 "):
|
253
|
+
alias_item.setText(alias_item.text()[2:])
|
254
|
+
except (ValueError, AttributeError):
|
255
|
+
pass
|
256
|
+
|
257
|
+
# Re-enable signals
|
258
|
+
self.class_table.blockSignals(False)
|
259
|
+
|
260
|
+
def setup_file_model(self, file_model):
|
261
|
+
"""Setup the file model for the tree view."""
|
262
|
+
self.file_tree.setModel(file_model)
|
263
|
+
self.file_tree.setColumnWidth(0, 200)
|
264
|
+
|
265
|
+
def set_folder(self, folder_path, file_model):
|
266
|
+
"""Set the folder for file browsing."""
|
267
|
+
self.file_tree.setRootIndex(file_model.setRootPath(folder_path))
|
268
|
+
|
269
|
+
def get_selected_segment_indices(self):
|
270
|
+
"""Get indices of selected segments."""
|
271
|
+
selected_items = self.segment_table.selectedItems()
|
272
|
+
selected_rows = sorted(list({item.row() for item in selected_items}))
|
273
|
+
return [
|
274
|
+
self.segment_table.item(row, 0).data(Qt.ItemDataRole.UserRole)
|
275
|
+
for row in selected_rows
|
276
|
+
if self.segment_table.item(row, 0)
|
277
|
+
]
|
278
|
+
|
279
|
+
def get_class_order(self):
|
280
|
+
"""Get the current class order from the class table."""
|
281
|
+
ordered_ids = []
|
282
|
+
for row in range(self.class_table.rowCount()):
|
283
|
+
id_item = self.class_table.item(row, 1)
|
284
|
+
if id_item and id_item.text():
|
285
|
+
try:
|
286
|
+
ordered_ids.append(int(id_item.text()))
|
287
|
+
except ValueError:
|
288
|
+
continue
|
289
|
+
return ordered_ids
|
290
|
+
|
291
|
+
def clear_selections(self):
|
292
|
+
"""Clear all selections."""
|
293
|
+
self.segment_table.clearSelection()
|
294
|
+
self.class_table.clearSelection()
|
295
|
+
|
296
|
+
def select_all_segments(self):
|
297
|
+
"""Select all segments."""
|
298
|
+
self.segment_table.selectAll()
|
299
|
+
|
300
|
+
def set_status(self, message):
|
301
|
+
"""Set status message."""
|
302
|
+
self.status_label.setText(message)
|
303
|
+
|
304
|
+
def clear_status(self):
|
305
|
+
"""Clear status message."""
|
306
|
+
self.status_label.clear()
|
307
|
+
|
308
|
+
def set_popout_mode(self, is_popped_out: bool):
|
309
|
+
"""Update the pop-out button based on panel state."""
|
310
|
+
if is_popped_out:
|
311
|
+
self.btn_popout.setText("⇤")
|
312
|
+
self.btn_popout.setToolTip("Return panel to main window")
|
313
|
+
else:
|
314
|
+
self.btn_popout.setText("⋯")
|
315
|
+
self.btn_popout.setToolTip("Pop out panel to separate window")
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"""UI widgets for LazyLabel."""
|
2
|
+
|
3
|
+
from .model_selection_widget import ModelSelectionWidget
|
4
|
+
from .settings_widget import SettingsWidget
|
5
|
+
from .adjustments_widget import AdjustmentsWidget
|
6
|
+
from .status_bar import StatusBar
|
7
|
+
|
8
|
+
__all__ = ["ModelSelectionWidget", "SettingsWidget", "AdjustmentsWidget", "StatusBar"]
|
@@ -0,0 +1,107 @@
|
|
1
|
+
"""Adjustments widget for sliders and controls."""
|
2
|
+
|
3
|
+
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QLabel, QSlider, QGroupBox
|
4
|
+
from PyQt6.QtCore import Qt, pyqtSignal
|
5
|
+
|
6
|
+
|
7
|
+
class AdjustmentsWidget(QWidget):
|
8
|
+
"""Widget for adjustment controls."""
|
9
|
+
|
10
|
+
annotation_size_changed = pyqtSignal(int)
|
11
|
+
pan_speed_changed = pyqtSignal(int)
|
12
|
+
join_threshold_changed = pyqtSignal(int)
|
13
|
+
|
14
|
+
def __init__(self, parent=None):
|
15
|
+
super().__init__(parent)
|
16
|
+
self._setup_ui()
|
17
|
+
self._connect_signals()
|
18
|
+
|
19
|
+
def _setup_ui(self):
|
20
|
+
"""Setup the UI layout."""
|
21
|
+
group = QGroupBox("Adjustments")
|
22
|
+
layout = QVBoxLayout(group)
|
23
|
+
|
24
|
+
# Annotation size
|
25
|
+
self.size_label = QLabel("Annotation Size: 1.0x")
|
26
|
+
self.size_slider = QSlider(Qt.Orientation.Horizontal)
|
27
|
+
self.size_slider.setRange(1, 50)
|
28
|
+
self.size_slider.setValue(10)
|
29
|
+
self.size_slider.setToolTip("Adjusts the size of points and lines (Ctrl +/-)")
|
30
|
+
layout.addWidget(self.size_label)
|
31
|
+
layout.addWidget(self.size_slider)
|
32
|
+
|
33
|
+
layout.addSpacing(10)
|
34
|
+
|
35
|
+
# Pan speed
|
36
|
+
self.pan_label = QLabel("Pan Speed: 1.0x")
|
37
|
+
self.pan_slider = QSlider(Qt.Orientation.Horizontal)
|
38
|
+
self.pan_slider.setRange(1, 100)
|
39
|
+
self.pan_slider.setValue(10)
|
40
|
+
self.pan_slider.setToolTip(
|
41
|
+
"Adjusts the speed of WASD panning. Hold Shift for 5x boost."
|
42
|
+
)
|
43
|
+
layout.addWidget(self.pan_label)
|
44
|
+
layout.addWidget(self.pan_slider)
|
45
|
+
|
46
|
+
layout.addSpacing(10)
|
47
|
+
|
48
|
+
# Polygon join threshold
|
49
|
+
self.join_label = QLabel("Polygon Join Distance: 2px")
|
50
|
+
self.join_slider = QSlider(Qt.Orientation.Horizontal)
|
51
|
+
self.join_slider.setRange(1, 10)
|
52
|
+
self.join_slider.setValue(2)
|
53
|
+
self.join_slider.setToolTip("The pixel distance to 'snap' a polygon closed.")
|
54
|
+
layout.addWidget(self.join_label)
|
55
|
+
layout.addWidget(self.join_slider)
|
56
|
+
|
57
|
+
# Main layout
|
58
|
+
main_layout = QVBoxLayout(self)
|
59
|
+
main_layout.setContentsMargins(0, 0, 0, 0)
|
60
|
+
main_layout.addWidget(group)
|
61
|
+
|
62
|
+
def _connect_signals(self):
|
63
|
+
"""Connect internal signals."""
|
64
|
+
self.size_slider.valueChanged.connect(self._on_size_changed)
|
65
|
+
self.pan_slider.valueChanged.connect(self._on_pan_changed)
|
66
|
+
self.join_slider.valueChanged.connect(self._on_join_changed)
|
67
|
+
|
68
|
+
def _on_size_changed(self, value):
|
69
|
+
"""Handle annotation size change."""
|
70
|
+
multiplier = value / 10.0
|
71
|
+
self.size_label.setText(f"Annotation Size: {multiplier:.1f}x")
|
72
|
+
self.annotation_size_changed.emit(value)
|
73
|
+
|
74
|
+
def _on_pan_changed(self, value):
|
75
|
+
"""Handle pan speed change."""
|
76
|
+
multiplier = value / 10.0
|
77
|
+
self.pan_label.setText(f"Pan Speed: {multiplier:.1f}x")
|
78
|
+
self.pan_speed_changed.emit(value)
|
79
|
+
|
80
|
+
def _on_join_changed(self, value):
|
81
|
+
"""Handle join threshold change."""
|
82
|
+
self.join_label.setText(f"Polygon Join Distance: {value}px")
|
83
|
+
self.join_threshold_changed.emit(value)
|
84
|
+
|
85
|
+
def get_annotation_size(self):
|
86
|
+
"""Get current annotation size value."""
|
87
|
+
return self.size_slider.value()
|
88
|
+
|
89
|
+
def set_annotation_size(self, value):
|
90
|
+
"""Set annotation size value."""
|
91
|
+
self.size_slider.setValue(value)
|
92
|
+
|
93
|
+
def get_pan_speed(self):
|
94
|
+
"""Get current pan speed value."""
|
95
|
+
return self.pan_slider.value()
|
96
|
+
|
97
|
+
def set_pan_speed(self, value):
|
98
|
+
"""Set pan speed value."""
|
99
|
+
self.pan_slider.setValue(value)
|
100
|
+
|
101
|
+
def get_join_threshold(self):
|
102
|
+
"""Get current join threshold value."""
|
103
|
+
return self.join_slider.value()
|
104
|
+
|
105
|
+
def set_join_threshold(self, value):
|
106
|
+
"""Set join threshold value."""
|
107
|
+
self.join_slider.setValue(value)
|
@@ -0,0 +1,94 @@
|
|
1
|
+
"""Model selection widget."""
|
2
|
+
|
3
|
+
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel, QComboBox, QGroupBox
|
4
|
+
from PyQt6.QtCore import pyqtSignal
|
5
|
+
from typing import List, Tuple
|
6
|
+
|
7
|
+
|
8
|
+
class ModelSelectionWidget(QWidget):
|
9
|
+
"""Widget for model selection and management."""
|
10
|
+
|
11
|
+
browse_requested = pyqtSignal()
|
12
|
+
refresh_requested = pyqtSignal()
|
13
|
+
model_selected = pyqtSignal(str)
|
14
|
+
|
15
|
+
def __init__(self, parent=None):
|
16
|
+
super().__init__(parent)
|
17
|
+
self._setup_ui()
|
18
|
+
self._connect_signals()
|
19
|
+
|
20
|
+
def _setup_ui(self):
|
21
|
+
"""Setup the UI layout."""
|
22
|
+
group = QGroupBox("Model Selection")
|
23
|
+
layout = QVBoxLayout(group)
|
24
|
+
|
25
|
+
# Buttons
|
26
|
+
button_layout = QHBoxLayout()
|
27
|
+
self.btn_browse = QPushButton("Browse Models")
|
28
|
+
self.btn_browse.setToolTip("Browse for a folder containing .pth model files")
|
29
|
+
self.btn_refresh = QPushButton("Refresh")
|
30
|
+
self.btn_refresh.setToolTip("Refresh the list of available models")
|
31
|
+
|
32
|
+
button_layout.addWidget(self.btn_browse)
|
33
|
+
button_layout.addWidget(self.btn_refresh)
|
34
|
+
layout.addLayout(button_layout)
|
35
|
+
|
36
|
+
# Model combo
|
37
|
+
layout.addWidget(QLabel("Available Models:"))
|
38
|
+
self.model_combo = QComboBox()
|
39
|
+
self.model_combo.setToolTip("Select a .pth model file to use")
|
40
|
+
self.model_combo.addItem("Default (vit_h)")
|
41
|
+
layout.addWidget(self.model_combo)
|
42
|
+
|
43
|
+
# Current model label
|
44
|
+
self.current_model_label = QLabel("Current: Default SAM Model")
|
45
|
+
self.current_model_label.setWordWrap(True)
|
46
|
+
self.current_model_label.setStyleSheet("color: #90EE90; font-style: italic;")
|
47
|
+
layout.addWidget(self.current_model_label)
|
48
|
+
|
49
|
+
# Main layout
|
50
|
+
main_layout = QVBoxLayout(self)
|
51
|
+
main_layout.setContentsMargins(0, 0, 0, 0)
|
52
|
+
main_layout.addWidget(group)
|
53
|
+
|
54
|
+
def _connect_signals(self):
|
55
|
+
"""Connect internal signals."""
|
56
|
+
self.btn_browse.clicked.connect(self.browse_requested)
|
57
|
+
self.btn_refresh.clicked.connect(self.refresh_requested)
|
58
|
+
self.model_combo.currentTextChanged.connect(self.model_selected)
|
59
|
+
|
60
|
+
def populate_models(self, models: List[Tuple[str, str]]):
|
61
|
+
"""Populate the models combo box.
|
62
|
+
|
63
|
+
Args:
|
64
|
+
models: List of (display_name, full_path) tuples
|
65
|
+
"""
|
66
|
+
self.model_combo.blockSignals(True)
|
67
|
+
self.model_combo.clear()
|
68
|
+
|
69
|
+
# Add default option
|
70
|
+
self.model_combo.addItem("Default (vit_h)")
|
71
|
+
|
72
|
+
# Add custom models
|
73
|
+
for display_name, full_path in models:
|
74
|
+
self.model_combo.addItem(display_name, full_path)
|
75
|
+
|
76
|
+
self.model_combo.blockSignals(False)
|
77
|
+
|
78
|
+
def set_current_model(self, model_name: str):
|
79
|
+
"""Set the current model display."""
|
80
|
+
self.current_model_label.setText(model_name)
|
81
|
+
|
82
|
+
def get_selected_model_path(self) -> str:
|
83
|
+
"""Get the path of the currently selected model."""
|
84
|
+
current_index = self.model_combo.currentIndex()
|
85
|
+
if current_index <= 0: # Default option
|
86
|
+
return ""
|
87
|
+
return self.model_combo.itemData(current_index) or ""
|
88
|
+
|
89
|
+
def reset_to_default(self):
|
90
|
+
"""Reset selection to default model."""
|
91
|
+
self.model_combo.blockSignals(True)
|
92
|
+
self.model_combo.setCurrentIndex(0)
|
93
|
+
self.model_combo.blockSignals(False)
|
94
|
+
self.set_current_model("Current: Default SAM Model")
|
@@ -0,0 +1,106 @@
|
|
1
|
+
"""Settings widget for save options."""
|
2
|
+
|
3
|
+
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QCheckBox, QGroupBox
|
4
|
+
from PyQt6.QtCore import pyqtSignal
|
5
|
+
|
6
|
+
|
7
|
+
class SettingsWidget(QWidget):
|
8
|
+
"""Widget for application settings."""
|
9
|
+
|
10
|
+
settings_changed = pyqtSignal()
|
11
|
+
|
12
|
+
def __init__(self, parent=None):
|
13
|
+
super().__init__(parent)
|
14
|
+
self._setup_ui()
|
15
|
+
self._connect_signals()
|
16
|
+
|
17
|
+
def _setup_ui(self):
|
18
|
+
"""Setup the UI layout."""
|
19
|
+
group = QGroupBox("Settings")
|
20
|
+
layout = QVBoxLayout(group)
|
21
|
+
|
22
|
+
# Auto-save
|
23
|
+
self.chk_auto_save = QCheckBox("Auto-Save on Navigate")
|
24
|
+
self.chk_auto_save.setToolTip(
|
25
|
+
"Automatically save work when using arrow keys to change images."
|
26
|
+
)
|
27
|
+
self.chk_auto_save.setChecked(True)
|
28
|
+
layout.addWidget(self.chk_auto_save)
|
29
|
+
|
30
|
+
# Save NPZ
|
31
|
+
self.chk_save_npz = QCheckBox("Save .npz")
|
32
|
+
self.chk_save_npz.setChecked(True)
|
33
|
+
self.chk_save_npz.setToolTip(
|
34
|
+
"Save the final mask as a compressed NumPy NPZ file."
|
35
|
+
)
|
36
|
+
layout.addWidget(self.chk_save_npz)
|
37
|
+
|
38
|
+
# Save TXT
|
39
|
+
self.chk_save_txt = QCheckBox("Save .txt")
|
40
|
+
self.chk_save_txt.setChecked(True)
|
41
|
+
self.chk_save_txt.setToolTip(
|
42
|
+
"Save bounding box annotations in YOLO TXT format."
|
43
|
+
)
|
44
|
+
layout.addWidget(self.chk_save_txt)
|
45
|
+
|
46
|
+
# YOLO with aliases
|
47
|
+
self.chk_yolo_use_alias = QCheckBox("Save YOLO with Class Aliases")
|
48
|
+
self.chk_yolo_use_alias.setToolTip(
|
49
|
+
"If checked, saves YOLO .txt files using class alias names instead of numeric IDs.\n"
|
50
|
+
"This is useful when a separate .yaml or .names file defines the classes."
|
51
|
+
)
|
52
|
+
self.chk_yolo_use_alias.setChecked(True)
|
53
|
+
layout.addWidget(self.chk_yolo_use_alias)
|
54
|
+
|
55
|
+
# Save class aliases
|
56
|
+
self.chk_save_class_aliases = QCheckBox("Save Class Aliases (.json)")
|
57
|
+
self.chk_save_class_aliases.setToolTip(
|
58
|
+
"Save class aliases to a companion JSON file."
|
59
|
+
)
|
60
|
+
self.chk_save_class_aliases.setChecked(False)
|
61
|
+
layout.addWidget(self.chk_save_class_aliases)
|
62
|
+
|
63
|
+
# Main layout
|
64
|
+
main_layout = QVBoxLayout(self)
|
65
|
+
main_layout.setContentsMargins(0, 0, 0, 0)
|
66
|
+
main_layout.addWidget(group)
|
67
|
+
|
68
|
+
def _connect_signals(self):
|
69
|
+
"""Connect internal signals."""
|
70
|
+
self.chk_save_npz.stateChanged.connect(self._handle_save_checkbox_change)
|
71
|
+
self.chk_save_txt.stateChanged.connect(self._handle_save_checkbox_change)
|
72
|
+
|
73
|
+
# Connect all checkboxes to settings changed signal
|
74
|
+
for checkbox in [self.chk_auto_save, self.chk_save_npz, self.chk_save_txt,
|
75
|
+
self.chk_yolo_use_alias, self.chk_save_class_aliases]:
|
76
|
+
checkbox.stateChanged.connect(self.settings_changed)
|
77
|
+
|
78
|
+
def _handle_save_checkbox_change(self):
|
79
|
+
"""Ensure at least one save format is selected."""
|
80
|
+
is_npz_checked = self.chk_save_npz.isChecked()
|
81
|
+
is_txt_checked = self.chk_save_txt.isChecked()
|
82
|
+
|
83
|
+
if not is_npz_checked and not is_txt_checked:
|
84
|
+
sender = self.sender()
|
85
|
+
if sender == self.chk_save_npz:
|
86
|
+
self.chk_save_txt.setChecked(True)
|
87
|
+
else:
|
88
|
+
self.chk_save_npz.setChecked(True)
|
89
|
+
|
90
|
+
def get_settings(self):
|
91
|
+
"""Get current settings as dictionary."""
|
92
|
+
return {
|
93
|
+
'auto_save': self.chk_auto_save.isChecked(),
|
94
|
+
'save_npz': self.chk_save_npz.isChecked(),
|
95
|
+
'save_txt': self.chk_save_txt.isChecked(),
|
96
|
+
'yolo_use_alias': self.chk_yolo_use_alias.isChecked(),
|
97
|
+
'save_class_aliases': self.chk_save_class_aliases.isChecked(),
|
98
|
+
}
|
99
|
+
|
100
|
+
def set_settings(self, settings):
|
101
|
+
"""Set settings from dictionary."""
|
102
|
+
self.chk_auto_save.setChecked(settings.get('auto_save', True))
|
103
|
+
self.chk_save_npz.setChecked(settings.get('save_npz', True))
|
104
|
+
self.chk_save_txt.setChecked(settings.get('save_txt', True))
|
105
|
+
self.chk_yolo_use_alias.setChecked(settings.get('yolo_use_alias', True))
|
106
|
+
self.chk_save_class_aliases.setChecked(settings.get('save_class_aliases', False))
|