lazylabel-gui 1.1.8__py3-none-any.whl → 1.1.9__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.
@@ -1,861 +1,885 @@
1
- """Left control panel with mode controls and settings."""
2
-
3
- from PyQt6.QtCore import Qt, pyqtSignal
4
- from PyQt6.QtWidgets import (
5
- QFrame,
6
- QHBoxLayout,
7
- QLabel,
8
- QPushButton,
9
- QScrollArea,
10
- QTabWidget,
11
- QVBoxLayout,
12
- QWidget,
13
- )
14
-
15
- from .widgets import (
16
- AdjustmentsWidget,
17
- BorderCropWidget,
18
- ChannelThresholdWidget,
19
- FragmentThresholdWidget,
20
- ModelSelectionWidget,
21
- SettingsWidget,
22
- )
23
-
24
-
25
- class SimpleCollapsible(QWidget):
26
- """A simple collapsible widget for use within tabs."""
27
-
28
- def __init__(self, title: str, content_widget: QWidget, parent=None):
29
- super().__init__(parent)
30
- self.content_widget = content_widget
31
- self.is_collapsed = False
32
-
33
- layout = QVBoxLayout(self)
34
- layout.setContentsMargins(0, 0, 0, 0)
35
- layout.setSpacing(2)
36
-
37
- # Header with toggle button
38
- header_layout = QHBoxLayout()
39
- header_layout.setContentsMargins(2, 2, 2, 2)
40
-
41
- self.toggle_button = QPushButton("▼")
42
- self.toggle_button.setMaximumWidth(16)
43
- self.toggle_button.setMaximumHeight(16)
44
- self.toggle_button.setStyleSheet(
45
- """
46
- QPushButton {
47
- border: 1px solid rgba(120, 120, 120, 0.5);
48
- background: rgba(70, 70, 70, 0.6);
49
- color: #E0E0E0;
50
- font-size: 10px;
51
- font-weight: bold;
52
- border-radius: 2px;
53
- }
54
- QPushButton:hover {
55
- background: rgba(90, 90, 90, 0.8);
56
- border: 1px solid rgba(140, 140, 140, 0.8);
57
- color: #FFF;
58
- }
59
- QPushButton:pressed {
60
- background: rgba(50, 50, 50, 0.8);
61
- border: 1px solid rgba(100, 100, 100, 0.6);
62
- }
63
- """
64
- )
65
- self.toggle_button.clicked.connect(self.toggle_collapse)
66
-
67
- title_label = QLabel(title)
68
- title_label.setStyleSheet(
69
- """
70
- QLabel {
71
- color: #E0E0E0;
72
- font-weight: bold;
73
- font-size: 11px;
74
- background: transparent;
75
- border: none;
76
- padding: 2px;
77
- }
78
- """
79
- )
80
-
81
- header_layout.addWidget(self.toggle_button)
82
- header_layout.addWidget(title_label)
83
- header_layout.addStretch()
84
-
85
- self.header_widget = QWidget()
86
- self.header_widget.setLayout(header_layout)
87
- self.header_widget.setStyleSheet(
88
- """
89
- QWidget {
90
- background-color: rgba(60, 60, 60, 0.3);
91
- border-radius: 3px;
92
- border: 1px solid rgba(80, 80, 80, 0.4);
93
- }
94
- """
95
- )
96
- self.header_widget.setFixedHeight(20)
97
-
98
- layout.addWidget(self.header_widget)
99
- layout.addWidget(content_widget)
100
-
101
- # Add some spacing below content
102
- layout.addSpacing(4)
103
-
104
- def toggle_collapse(self):
105
- """Toggle the collapsed state."""
106
- self.is_collapsed = not self.is_collapsed
107
- self.content_widget.setVisible(not self.is_collapsed)
108
- self.toggle_button.setText("▶" if self.is_collapsed else "▼")
109
-
110
-
111
- class ProfessionalCard(QFrame):
112
- """A professional-looking card widget for containing controls."""
113
-
114
- def __init__(self, title: str = "", parent=None):
115
- super().__init__(parent)
116
- self.setFrameStyle(QFrame.Shape.Box)
117
- self.setStyleSheet(
118
- """
119
- QFrame {
120
- background-color: rgba(40, 40, 40, 0.8);
121
- border: 1px solid rgba(80, 80, 80, 0.6);
122
- border-radius: 8px;
123
- margin: 2px;
124
- }
125
- """
126
- )
127
-
128
- layout = QVBoxLayout(self)
129
- layout.setContentsMargins(8, 8, 8, 8)
130
- layout.setSpacing(6)
131
-
132
- if title:
133
- title_label = QLabel(title)
134
- title_label.setStyleSheet(
135
- """
136
- QLabel {
137
- color: #E0E0E0;
138
- font-weight: bold;
139
- font-size: 11px;
140
- border: none;
141
- background: transparent;
142
- padding: 0px;
143
- margin-bottom: 4px;
144
- }
145
- """
146
- )
147
- layout.addWidget(title_label)
148
-
149
- self.content_layout = layout
150
-
151
- def addWidget(self, widget):
152
- """Add a widget to the card."""
153
- self.content_layout.addWidget(widget)
154
-
155
- def addLayout(self, layout):
156
- """Add a layout to the card."""
157
- self.content_layout.addLayout(layout)
158
-
159
-
160
- class ControlPanel(QWidget):
161
- """Left control panel with mode controls and settings."""
162
-
163
- # Signals
164
- sam_mode_requested = pyqtSignal()
165
- polygon_mode_requested = pyqtSignal()
166
- bbox_mode_requested = pyqtSignal()
167
- selection_mode_requested = pyqtSignal()
168
- edit_mode_requested = pyqtSignal()
169
- clear_points_requested = pyqtSignal()
170
- fit_view_requested = pyqtSignal()
171
- browse_models_requested = pyqtSignal()
172
- refresh_models_requested = pyqtSignal()
173
- model_selected = pyqtSignal(str)
174
- annotation_size_changed = pyqtSignal(int)
175
- pan_speed_changed = pyqtSignal(int)
176
- join_threshold_changed = pyqtSignal(int)
177
- fragment_threshold_changed = pyqtSignal(int)
178
- brightness_changed = pyqtSignal(int)
179
- contrast_changed = pyqtSignal(int)
180
- gamma_changed = pyqtSignal(int)
181
- reset_adjustments_requested = pyqtSignal()
182
- image_adjustment_changed = pyqtSignal()
183
- hotkeys_requested = pyqtSignal()
184
- pop_out_requested = pyqtSignal()
185
- settings_changed = pyqtSignal()
186
- # Border crop signals
187
- crop_draw_requested = pyqtSignal()
188
- crop_clear_requested = pyqtSignal()
189
- crop_applied = pyqtSignal(int, int, int, int) # x1, y1, x2, y2
190
- # Channel threshold signals
191
- channel_threshold_changed = pyqtSignal()
192
-
193
- def __init__(self, parent=None):
194
- super().__init__(parent)
195
- self.setMinimumWidth(260) # Slightly wider for better layout
196
- self.preferred_width = 280
197
- self._setup_ui()
198
- self._connect_signals()
199
-
200
- def _setup_ui(self):
201
- """Setup the professional UI layout."""
202
- layout = QVBoxLayout(self)
203
- layout.setContentsMargins(8, 8, 8, 8)
204
- layout.setSpacing(8)
205
-
206
- # Create widgets first
207
- self.model_widget = ModelSelectionWidget()
208
- self.crop_widget = BorderCropWidget()
209
- self.channel_threshold_widget = ChannelThresholdWidget()
210
- self.settings_widget = SettingsWidget()
211
- self.adjustments_widget = AdjustmentsWidget()
212
- self.fragment_widget = FragmentThresholdWidget()
213
-
214
- # Top header with pop-out button
215
- header_layout = QHBoxLayout()
216
- header_layout.addStretch()
217
-
218
- self.btn_popout = QPushButton("⋯")
219
- self.btn_popout.setToolTip("Pop out panel to separate window")
220
- self.btn_popout.setMaximumWidth(30)
221
- self.btn_popout.setMaximumHeight(25)
222
- self.btn_popout.setStyleSheet(
223
- """
224
- QPushButton {
225
- background-color: rgba(60, 60, 60, 0.8);
226
- border: 1px solid rgba(80, 80, 80, 0.6);
227
- border-radius: 4px;
228
- color: #E0E0E0;
229
- }
230
- QPushButton:hover {
231
- background-color: rgba(80, 80, 80, 0.9);
232
- }
233
- QPushButton:pressed {
234
- background-color: rgba(40, 40, 40, 0.9);
235
- }
236
- """
237
- )
238
- header_layout.addWidget(self.btn_popout)
239
- layout.addLayout(header_layout)
240
-
241
- # Fixed Mode Controls Section (Always Visible)
242
- mode_card = self._create_mode_card()
243
- layout.addWidget(mode_card)
244
-
245
- # Tabbed Interface for Everything Else
246
- self.tab_widget = QTabWidget()
247
- self.tab_widget.setStyleSheet(
248
- """
249
- QTabWidget::pane {
250
- border: 1px solid rgba(80, 80, 80, 0.6);
251
- border-radius: 6px;
252
- background-color: rgba(35, 35, 35, 0.9);
253
- margin-top: 2px;
254
- }
255
- QTabWidget::tab-bar {
256
- alignment: center;
257
- }
258
- QTabBar::tab {
259
- background-color: rgba(50, 50, 50, 0.8);
260
- border: 1px solid rgba(70, 70, 70, 0.6);
261
- border-bottom: none;
262
- border-radius: 4px 4px 0 0;
263
- padding: 4px 8px;
264
- margin-right: 1px;
265
- color: #B0B0B0;
266
- font-size: 9px;
267
- min-width: 45px;
268
- max-width: 80px;
269
- }
270
- QTabBar::tab:selected {
271
- background-color: rgba(70, 70, 70, 0.9);
272
- color: #E0E0E0;
273
- font-weight: bold;
274
- }
275
- QTabBar::tab:hover:!selected {
276
- background-color: rgba(60, 60, 60, 0.8);
277
- color: #D0D0D0;
278
- }
279
- """
280
- )
281
-
282
- # AI & Settings Tab
283
- ai_tab = self._create_ai_tab()
284
- self.tab_widget.addTab(ai_tab, "🤖 AI")
285
-
286
- # Processing & Adjustments Tab
287
- processing_tab = self._create_processing_tab()
288
- self.tab_widget.addTab(processing_tab, "🛠️ Tools")
289
-
290
- layout.addWidget(self.tab_widget, 1)
291
-
292
- # Status label at bottom
293
- self.notification_label = QLabel("")
294
- self.notification_label.setStyleSheet(
295
- """
296
- QLabel {
297
- color: #FFA500;
298
- font-style: italic;
299
- font-size: 9px;
300
- background: transparent;
301
- border: none;
302
- padding: 4px;
303
- }
304
- """
305
- )
306
- self.notification_label.setWordWrap(True)
307
- layout.addWidget(self.notification_label)
308
-
309
- def _create_mode_card(self):
310
- """Create the fixed mode controls card."""
311
- mode_card = ProfessionalCard("Mode Controls")
312
-
313
- # Mode buttons in a clean grid
314
- buttons_layout = QVBoxLayout()
315
- buttons_layout.setSpacing(4)
316
-
317
- # First row: AI and Polygon
318
- row1_layout = QHBoxLayout()
319
- row1_layout.setSpacing(4)
320
-
321
- self.btn_sam_mode = self._create_mode_button(
322
- "AI", "1", "Switch to AI Mode for AI segmentation"
323
- )
324
- self.btn_sam_mode.setCheckable(True)
325
- self.btn_sam_mode.setChecked(True) # Default mode
326
-
327
- self.btn_polygon_mode = self._create_mode_button(
328
- "Poly", "2", "Switch to Polygon Drawing Mode"
329
- )
330
- self.btn_polygon_mode.setCheckable(True)
331
-
332
- row1_layout.addWidget(self.btn_sam_mode)
333
- row1_layout.addWidget(self.btn_polygon_mode)
334
- buttons_layout.addLayout(row1_layout)
335
-
336
- # Second row: BBox and Selection
337
- row2_layout = QHBoxLayout()
338
- row2_layout.setSpacing(4)
339
-
340
- self.btn_bbox_mode = self._create_mode_button(
341
- "Box", "3", "Switch to Bounding Box Drawing Mode"
342
- )
343
- self.btn_bbox_mode.setCheckable(True)
344
-
345
- self.btn_selection_mode = self._create_mode_button(
346
- "Select", "E", "Toggle segment selection"
347
- )
348
- self.btn_selection_mode.setCheckable(True)
349
-
350
- row2_layout.addWidget(self.btn_bbox_mode)
351
- row2_layout.addWidget(self.btn_selection_mode)
352
- buttons_layout.addLayout(row2_layout)
353
-
354
- mode_card.addLayout(buttons_layout)
355
-
356
- # Bottom utility row: Edit and Hotkeys
357
- utility_layout = QHBoxLayout()
358
- utility_layout.setSpacing(4)
359
-
360
- self.btn_edit_mode = self._create_utility_button(
361
- "Edit", "R", "Edit segments and polygons"
362
- )
363
- self.btn_edit_mode.setCheckable(True) # Make edit button checkable
364
-
365
- self.btn_hotkeys = self._create_utility_button(
366
- "⌨️ Hotkeys", "", "Configure keyboard shortcuts"
367
- )
368
-
369
- utility_layout.addWidget(self.btn_edit_mode)
370
- utility_layout.addWidget(self.btn_hotkeys)
371
-
372
- mode_card.addLayout(utility_layout)
373
-
374
- return mode_card
375
-
376
- def _create_mode_button(self, text, key, tooltip):
377
- """Create a professional mode button."""
378
- button = QPushButton(f"{text} ({key})")
379
- button.setToolTip(f"{tooltip} ({key})")
380
- button.setFixedHeight(28)
381
- button.setFixedWidth(75) # Fixed width for consistency
382
- button.setStyleSheet(
383
- """
384
- QPushButton {
385
- background-color: rgba(60, 90, 120, 0.8);
386
- border: 1px solid rgba(80, 110, 140, 0.8);
387
- border-radius: 6px;
388
- color: #E0E0E0;
389
- font-weight: bold;
390
- font-size: 10px;
391
- padding: 4px 8px;
392
- }
393
- QPushButton:hover {
394
- background-color: rgba(80, 110, 140, 0.9);
395
- border-color: rgba(100, 130, 160, 0.9);
396
- }
397
- QPushButton:pressed {
398
- background-color: rgba(40, 70, 100, 0.9);
399
- }
400
- QPushButton:checked {
401
- background-color: rgba(120, 170, 220, 1.0);
402
- border: 2px solid rgba(150, 200, 250, 1.0);
403
- color: #FFFFFF;
404
- font-weight: bold;
405
- }
406
- QPushButton:checked:hover {
407
- background-color: rgba(140, 190, 240, 1.0);
408
- border: 2px solid rgba(170, 220, 255, 1.0);
409
- }
410
- """
411
- )
412
- return button
413
-
414
- def _create_utility_button(self, text, key, tooltip):
415
- """Create a utility button with consistent styling."""
416
- if key:
417
- button_text = f"{text} ({key})"
418
- tooltip_text = f"{tooltip} ({key})"
419
- else:
420
- button_text = text
421
- tooltip_text = tooltip
422
-
423
- button = QPushButton(button_text)
424
- button.setToolTip(tooltip_text)
425
- button.setFixedHeight(28)
426
- button.setFixedWidth(75) # Fixed width for consistency
427
- button.setStyleSheet(
428
- """
429
- QPushButton {
430
- background-color: rgba(70, 100, 130, 0.8);
431
- border: 1px solid rgba(90, 120, 150, 0.8);
432
- border-radius: 6px;
433
- color: #E0E0E0;
434
- font-weight: bold;
435
- font-size: 10px;
436
- padding: 4px 8px;
437
- }
438
- QPushButton:hover {
439
- background-color: rgba(90, 120, 150, 0.9);
440
- border-color: rgba(110, 140, 170, 0.9);
441
- }
442
- QPushButton:pressed {
443
- background-color: rgba(50, 80, 110, 0.9);
444
- }
445
- QPushButton:checked {
446
- background-color: rgba(120, 170, 220, 1.0);
447
- border: 2px solid rgba(150, 200, 250, 1.0);
448
- color: #FFFFFF;
449
- font-weight: bold;
450
- }
451
- QPushButton:checked:hover {
452
- background-color: rgba(140, 190, 240, 1.0);
453
- border: 2px solid rgba(170, 220, 255, 1.0);
454
- }
455
- """
456
- )
457
- return button
458
-
459
- def _get_mode_sized_button_style(self):
460
- """Get styling for utility buttons that matches mode button size."""
461
- return """
462
- QPushButton {
463
- background-color: rgba(80, 80, 80, 0.8);
464
- border: 1px solid rgba(100, 100, 100, 0.6);
465
- border-radius: 6px;
466
- color: #E0E0E0;
467
- font-weight: bold;
468
- font-size: 10px;
469
- padding: 4px 8px;
470
- min-height: 22px;
471
- }
472
- QPushButton:hover {
473
- background-color: rgba(100, 100, 100, 0.9);
474
- border-color: rgba(120, 120, 120, 0.8);
475
- }
476
- QPushButton:pressed {
477
- background-color: rgba(60, 60, 60, 0.9);
478
- }
479
- """
480
-
481
- def _get_utility_button_style(self):
482
- """Get styling for utility buttons."""
483
- return """
484
- QPushButton {
485
- background-color: rgba(80, 80, 80, 0.8);
486
- border: 1px solid rgba(100, 100, 100, 0.6);
487
- border-radius: 5px;
488
- color: #E0E0E0;
489
- font-size: 10px;
490
- padding: 4px 8px;
491
- min-height: 22px;
492
- }
493
- QPushButton:hover {
494
- background-color: rgba(100, 100, 100, 0.9);
495
- }
496
- QPushButton:pressed {
497
- background-color: rgba(60, 60, 60, 0.9);
498
- }
499
- """
500
-
501
- def _create_ai_tab(self):
502
- """Create the AI & Settings tab."""
503
- tab_widget = QWidget()
504
-
505
- # Create scroll area for AI and settings
506
- scroll = QScrollArea()
507
- scroll.setWidgetResizable(True)
508
- scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
509
- scroll.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
510
- scroll.setStyleSheet(
511
- """
512
- QScrollArea {
513
- border: none;
514
- background: transparent;
515
- }
516
- QScrollBar:vertical {
517
- background-color: rgba(60, 60, 60, 0.5);
518
- width: 8px;
519
- border-radius: 4px;
520
- }
521
- QScrollBar::handle:vertical {
522
- background-color: rgba(120, 120, 120, 0.7);
523
- border-radius: 4px;
524
- min-height: 20px;
525
- }
526
- QScrollBar::handle:vertical:hover {
527
- background-color: rgba(140, 140, 140, 0.8);
528
- }
529
- """
530
- )
531
-
532
- scroll_content = QWidget()
533
- layout = QVBoxLayout(scroll_content)
534
- layout.setContentsMargins(6, 6, 6, 6)
535
- layout.setSpacing(8)
536
-
537
- # AI Model Selection - collapsible
538
- model_collapsible = SimpleCollapsible("AI Model Selection", self.model_widget)
539
- layout.addWidget(model_collapsible)
540
-
541
- # AI Fragment Filter - collapsible
542
- fragment_collapsible = SimpleCollapsible(
543
- "AI Fragment Filter", self.fragment_widget
544
- )
545
- layout.addWidget(fragment_collapsible)
546
-
547
- # Application Settings - collapsible
548
- settings_collapsible = SimpleCollapsible(
549
- "Application Settings", self.settings_widget
550
- )
551
- layout.addWidget(settings_collapsible)
552
-
553
- layout.addStretch()
554
-
555
- scroll.setWidget(scroll_content)
556
-
557
- tab_layout = QVBoxLayout(tab_widget)
558
- tab_layout.setContentsMargins(0, 0, 0, 0)
559
- tab_layout.addWidget(scroll)
560
-
561
- return tab_widget
562
-
563
- def _create_processing_tab(self):
564
- """Create the Processing & Tools tab."""
565
- tab_widget = QWidget()
566
-
567
- # Create scroll area for processing controls
568
- scroll = QScrollArea()
569
- scroll.setWidgetResizable(True)
570
- scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
571
- scroll.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
572
- scroll.setStyleSheet(
573
- """
574
- QScrollArea {
575
- border: none;
576
- background: transparent;
577
- }
578
- QScrollBar:vertical {
579
- background-color: rgba(60, 60, 60, 0.5);
580
- width: 8px;
581
- border-radius: 4px;
582
- }
583
- QScrollBar::handle:vertical {
584
- background-color: rgba(120, 120, 120, 0.7);
585
- border-radius: 4px;
586
- min-height: 20px;
587
- }
588
- QScrollBar::handle:vertical:hover {
589
- background-color: rgba(140, 140, 140, 0.8);
590
- }
591
- """
592
- )
593
-
594
- scroll_content = QWidget()
595
- layout = QVBoxLayout(scroll_content)
596
- layout.setContentsMargins(6, 6, 6, 6)
597
- layout.setSpacing(8)
598
-
599
- # Border Crop - collapsible
600
- crop_collapsible = SimpleCollapsible("Border Crop", self.crop_widget)
601
- layout.addWidget(crop_collapsible)
602
-
603
- # Channel Threshold - collapsible
604
- threshold_collapsible = SimpleCollapsible(
605
- "Channel Threshold", self.channel_threshold_widget
606
- )
607
- layout.addWidget(threshold_collapsible)
608
-
609
- # Image Adjustments - collapsible
610
- adjustments_collapsible = SimpleCollapsible(
611
- "Image Adjustments", self.adjustments_widget
612
- )
613
- layout.addWidget(adjustments_collapsible)
614
-
615
- layout.addStretch()
616
-
617
- scroll.setWidget(scroll_content)
618
-
619
- tab_layout = QVBoxLayout(tab_widget)
620
- tab_layout.setContentsMargins(0, 0, 0, 0)
621
- tab_layout.addWidget(scroll)
622
-
623
- return tab_widget
624
-
625
- def _connect_signals(self):
626
- """Connect internal signals."""
627
- self.btn_sam_mode.clicked.connect(self._on_sam_mode_clicked)
628
- self.btn_polygon_mode.clicked.connect(self._on_polygon_mode_clicked)
629
- self.btn_bbox_mode.clicked.connect(self._on_bbox_mode_clicked)
630
- self.btn_selection_mode.clicked.connect(self._on_selection_mode_clicked)
631
- self.btn_edit_mode.clicked.connect(self._on_edit_mode_clicked)
632
- self.btn_hotkeys.clicked.connect(self.hotkeys_requested)
633
- self.btn_popout.clicked.connect(self.pop_out_requested)
634
-
635
- # Model widget signals
636
- self.model_widget.browse_requested.connect(self.browse_models_requested)
637
- self.model_widget.refresh_requested.connect(self.refresh_models_requested)
638
- self.model_widget.model_selected.connect(self.model_selected)
639
-
640
- # Settings widget signals
641
- self.settings_widget.settings_changed.connect(self.settings_changed)
642
-
643
- # Adjustments widget signals
644
- self.adjustments_widget.annotation_size_changed.connect(
645
- self.annotation_size_changed
646
- )
647
- self.adjustments_widget.pan_speed_changed.connect(self.pan_speed_changed)
648
- self.adjustments_widget.join_threshold_changed.connect(
649
- self.join_threshold_changed
650
- )
651
- self.adjustments_widget.brightness_changed.connect(self.brightness_changed)
652
- self.adjustments_widget.contrast_changed.connect(self.contrast_changed)
653
- self.adjustments_widget.gamma_changed.connect(self.gamma_changed)
654
- self.adjustments_widget.reset_requested.connect(
655
- self.reset_adjustments_requested
656
- )
657
- self.adjustments_widget.image_adjustment_changed.connect(
658
- self.image_adjustment_changed
659
- )
660
-
661
- # Fragment threshold widget signals
662
- self.fragment_widget.fragment_threshold_changed.connect(
663
- self.fragment_threshold_changed
664
- )
665
-
666
- # Border crop signals
667
- self.crop_widget.crop_draw_requested.connect(self.crop_draw_requested)
668
- self.crop_widget.crop_clear_requested.connect(self.crop_clear_requested)
669
- self.crop_widget.crop_applied.connect(self.crop_applied)
670
-
671
- # Channel threshold signals
672
- self.channel_threshold_widget.thresholdChanged.connect(
673
- self.channel_threshold_changed
674
- )
675
-
676
- def _on_sam_mode_clicked(self):
677
- """Handle AI mode button click."""
678
- self._set_active_mode_button(self.btn_sam_mode)
679
- self.sam_mode_requested.emit()
680
-
681
- def _on_polygon_mode_clicked(self):
682
- """Handle polygon mode button click."""
683
- self._set_active_mode_button(self.btn_polygon_mode)
684
- self.polygon_mode_requested.emit()
685
-
686
- def _on_bbox_mode_clicked(self):
687
- """Handle bbox mode button click."""
688
- self._set_active_mode_button(self.btn_bbox_mode)
689
- self.bbox_mode_requested.emit()
690
-
691
- def _on_selection_mode_clicked(self):
692
- """Handle selection mode button click."""
693
- self._set_active_mode_button(self.btn_selection_mode)
694
- self.selection_mode_requested.emit()
695
-
696
- def _on_edit_mode_clicked(self):
697
- """Handle edit mode button click."""
698
- # For now, emit the signal - the main window will handle polygon checking
699
- self.edit_mode_requested.emit()
700
-
701
- def _set_active_mode_button(self, active_button):
702
- """Set the active mode button and deactivate others."""
703
- mode_buttons = [
704
- self.btn_sam_mode,
705
- self.btn_polygon_mode,
706
- self.btn_bbox_mode,
707
- self.btn_selection_mode,
708
- ]
709
-
710
- # Clear all mode buttons
711
- for button in mode_buttons:
712
- button.setChecked(button == active_button if active_button else False)
713
-
714
- # Clear edit button when setting mode buttons
715
- if active_button and active_button != self.btn_edit_mode:
716
- self.btn_edit_mode.setChecked(False)
717
-
718
- def mouseDoubleClickEvent(self, event):
719
- """Handle double-click to expand collapsed panel."""
720
- if (
721
- self.width() < 50
722
- and self.parent()
723
- and hasattr(self.parent(), "_expand_left_panel")
724
- ):
725
- self.parent()._expand_left_panel()
726
- super().mouseDoubleClickEvent(event)
727
-
728
- def show_notification(self, message: str, duration: int = 3000):
729
- """Show a notification message."""
730
- self.notification_label.setText(message)
731
- # Note: Timer should be handled by the caller
732
-
733
- def clear_notification(self):
734
- """Clear the notification message."""
735
- self.notification_label.clear()
736
-
737
- def set_mode_text(self, mode: str):
738
- """Set the active mode by highlighting the corresponding button."""
739
- # Map internal mode names to buttons
740
- mode_buttons = {
741
- "sam_points": self.btn_sam_mode,
742
- "polygon": self.btn_polygon_mode,
743
- "bbox": self.btn_bbox_mode,
744
- "selection": self.btn_selection_mode,
745
- "edit": self.btn_edit_mode,
746
- }
747
-
748
- active_button = mode_buttons.get(mode)
749
- if active_button:
750
- # Clear all mode buttons first
751
- self._set_active_mode_button(None)
752
- # Set edit button separately if it's edit mode
753
- if mode == "edit":
754
- self.btn_edit_mode.setChecked(True)
755
- else:
756
- self._set_active_mode_button(active_button)
757
-
758
- def set_edit_mode_active(self, active: bool):
759
- """Set edit mode button as active or inactive."""
760
- if active:
761
- # Clear all mode buttons and set edit as active
762
- self._set_active_mode_button(None)
763
- self.btn_edit_mode.setChecked(True)
764
- else:
765
- self.btn_edit_mode.setChecked(False)
766
-
767
- # Delegate methods for sub-widgets
768
- def populate_models(self, models):
769
- """Populate the models combo box."""
770
- self.model_widget.populate_models(models)
771
-
772
- def set_current_model(self, model_name):
773
- """Set the current model display."""
774
- self.model_widget.set_current_model(model_name)
775
-
776
- def get_settings(self):
777
- """Get current settings from the settings widget."""
778
- return self.settings_widget.get_settings()
779
-
780
- def set_settings(self, settings):
781
- """Set settings in the settings widget."""
782
- self.settings_widget.set_settings(settings)
783
-
784
- def get_annotation_size(self):
785
- """Get current annotation size."""
786
- return self.adjustments_widget.get_annotation_size()
787
-
788
- def set_annotation_size(self, value):
789
- """Set annotation size."""
790
- self.adjustments_widget.set_annotation_size(value)
791
-
792
- def set_pan_speed(self, value):
793
- """Set pan speed."""
794
- self.adjustments_widget.set_pan_speed(value)
795
-
796
- def set_join_threshold(self, value):
797
- """Set join threshold."""
798
- self.adjustments_widget.set_join_threshold(value)
799
-
800
- def set_fragment_threshold(self, value):
801
- """Set fragment threshold."""
802
- self.fragment_widget.set_fragment_threshold(value)
803
-
804
- def set_brightness(self, value):
805
- """Set brightness."""
806
- self.adjustments_widget.set_brightness(value)
807
-
808
- def set_contrast(self, value):
809
- """Set contrast."""
810
- self.adjustments_widget.set_contrast(value)
811
-
812
- def set_gamma(self, value):
813
- """Set gamma."""
814
- self.adjustments_widget.set_gamma(value)
815
-
816
- def set_sam_mode_enabled(self, enabled: bool):
817
- """Enable or disable the SAM mode button."""
818
- self.btn_sam_mode.setEnabled(enabled)
819
- if not enabled:
820
- self.btn_sam_mode.setToolTip("AI Mode (SAM model not available)")
821
- else:
822
- self.btn_sam_mode.setToolTip("Switch to AI Mode for AI segmentation (1)")
823
-
824
- def set_popout_mode(self, is_popped_out: bool):
825
- """Update the pop-out button based on panel state."""
826
- if is_popped_out:
827
- self.btn_popout.setText("⇤")
828
- self.btn_popout.setToolTip("Return panel to main window")
829
- else:
830
- self.btn_popout.setText("⋯")
831
- self.btn_popout.setToolTip("Pop out panel to separate window")
832
-
833
- # Border crop delegate methods
834
- def set_crop_coordinates(self, x1, y1, x2, y2):
835
- """Set crop coordinates in the crop widget."""
836
- self.crop_widget.set_crop_coordinates(x1, y1, x2, y2)
837
-
838
- def clear_crop_coordinates(self):
839
- """Clear crop coordinates."""
840
- self.crop_widget.clear_crop_coordinates()
841
-
842
- def get_crop_coordinates(self):
843
- """Get current crop coordinates."""
844
- return self.crop_widget.get_crop_coordinates()
845
-
846
- def has_crop(self):
847
- """Check if crop coordinates are set."""
848
- return self.crop_widget.has_crop()
849
-
850
- def set_crop_status(self, message):
851
- """Set crop status message."""
852
- self.crop_widget.set_status(message)
853
-
854
- # Channel threshold delegate methods
855
- def update_channel_threshold_for_image(self, image_array):
856
- """Update channel threshold widget for new image."""
857
- self.channel_threshold_widget.update_for_image(image_array)
858
-
859
- def get_channel_threshold_widget(self):
860
- """Get the channel threshold widget."""
861
- return self.channel_threshold_widget
1
+ """Left control panel with mode controls and settings."""
2
+
3
+ from PyQt6.QtCore import Qt, pyqtSignal
4
+ from PyQt6.QtWidgets import (
5
+ QFrame,
6
+ QHBoxLayout,
7
+ QLabel,
8
+ QPushButton,
9
+ QScrollArea,
10
+ QTabWidget,
11
+ QVBoxLayout,
12
+ QWidget,
13
+ )
14
+
15
+ from .widgets import (
16
+ AdjustmentsWidget,
17
+ BorderCropWidget,
18
+ ChannelThresholdWidget,
19
+ FFTThresholdWidget,
20
+ FragmentThresholdWidget,
21
+ ModelSelectionWidget,
22
+ SettingsWidget,
23
+ )
24
+
25
+
26
+ class SimpleCollapsible(QWidget):
27
+ """A simple collapsible widget for use within tabs."""
28
+
29
+ def __init__(self, title: str, content_widget: QWidget, parent=None):
30
+ super().__init__(parent)
31
+ self.content_widget = content_widget
32
+ self.is_collapsed = False
33
+
34
+ layout = QVBoxLayout(self)
35
+ layout.setContentsMargins(0, 0, 0, 0)
36
+ layout.setSpacing(2)
37
+
38
+ # Header with toggle button
39
+ header_layout = QHBoxLayout()
40
+ header_layout.setContentsMargins(2, 2, 2, 2)
41
+
42
+ self.toggle_button = QPushButton("▼")
43
+ self.toggle_button.setMaximumWidth(16)
44
+ self.toggle_button.setMaximumHeight(16)
45
+ self.toggle_button.setStyleSheet(
46
+ """
47
+ QPushButton {
48
+ border: 1px solid rgba(120, 120, 120, 0.5);
49
+ background: rgba(70, 70, 70, 0.6);
50
+ color: #E0E0E0;
51
+ font-size: 10px;
52
+ font-weight: bold;
53
+ border-radius: 2px;
54
+ }
55
+ QPushButton:hover {
56
+ background: rgba(90, 90, 90, 0.8);
57
+ border: 1px solid rgba(140, 140, 140, 0.8);
58
+ color: #FFF;
59
+ }
60
+ QPushButton:pressed {
61
+ background: rgba(50, 50, 50, 0.8);
62
+ border: 1px solid rgba(100, 100, 100, 0.6);
63
+ }
64
+ """
65
+ )
66
+ self.toggle_button.clicked.connect(self.toggle_collapse)
67
+
68
+ title_label = QLabel(title)
69
+ title_label.setStyleSheet(
70
+ """
71
+ QLabel {
72
+ color: #E0E0E0;
73
+ font-weight: bold;
74
+ font-size: 11px;
75
+ background: transparent;
76
+ border: none;
77
+ padding: 2px;
78
+ }
79
+ """
80
+ )
81
+
82
+ header_layout.addWidget(self.toggle_button)
83
+ header_layout.addWidget(title_label)
84
+ header_layout.addStretch()
85
+
86
+ self.header_widget = QWidget()
87
+ self.header_widget.setLayout(header_layout)
88
+ self.header_widget.setStyleSheet(
89
+ """
90
+ QWidget {
91
+ background-color: rgba(60, 60, 60, 0.3);
92
+ border-radius: 3px;
93
+ border: 1px solid rgba(80, 80, 80, 0.4);
94
+ }
95
+ """
96
+ )
97
+ self.header_widget.setFixedHeight(20)
98
+
99
+ layout.addWidget(self.header_widget)
100
+ layout.addWidget(content_widget)
101
+
102
+ # Add some spacing below content
103
+ layout.addSpacing(4)
104
+
105
+ def toggle_collapse(self):
106
+ """Toggle the collapsed state."""
107
+ self.is_collapsed = not self.is_collapsed
108
+ self.content_widget.setVisible(not self.is_collapsed)
109
+ self.toggle_button.setText("▶" if self.is_collapsed else "▼")
110
+
111
+
112
+ class ProfessionalCard(QFrame):
113
+ """A professional-looking card widget for containing controls."""
114
+
115
+ def __init__(self, title: str = "", parent=None):
116
+ super().__init__(parent)
117
+ self.setFrameStyle(QFrame.Shape.Box)
118
+ self.setStyleSheet(
119
+ """
120
+ QFrame {
121
+ background-color: rgba(40, 40, 40, 0.8);
122
+ border: 1px solid rgba(80, 80, 80, 0.6);
123
+ border-radius: 8px;
124
+ margin: 2px;
125
+ }
126
+ """
127
+ )
128
+
129
+ layout = QVBoxLayout(self)
130
+ layout.setContentsMargins(8, 8, 8, 8)
131
+ layout.setSpacing(6)
132
+
133
+ if title:
134
+ title_label = QLabel(title)
135
+ title_label.setStyleSheet(
136
+ """
137
+ QLabel {
138
+ color: #E0E0E0;
139
+ font-weight: bold;
140
+ font-size: 11px;
141
+ border: none;
142
+ background: transparent;
143
+ padding: 0px;
144
+ margin-bottom: 4px;
145
+ }
146
+ """
147
+ )
148
+ layout.addWidget(title_label)
149
+
150
+ self.content_layout = layout
151
+
152
+ def addWidget(self, widget):
153
+ """Add a widget to the card."""
154
+ self.content_layout.addWidget(widget)
155
+
156
+ def addLayout(self, layout):
157
+ """Add a layout to the card."""
158
+ self.content_layout.addLayout(layout)
159
+
160
+
161
+ class ControlPanel(QWidget):
162
+ """Left control panel with mode controls and settings."""
163
+
164
+ # Signals
165
+ sam_mode_requested = pyqtSignal()
166
+ polygon_mode_requested = pyqtSignal()
167
+ bbox_mode_requested = pyqtSignal()
168
+ selection_mode_requested = pyqtSignal()
169
+ edit_mode_requested = pyqtSignal()
170
+ clear_points_requested = pyqtSignal()
171
+ fit_view_requested = pyqtSignal()
172
+ browse_models_requested = pyqtSignal()
173
+ refresh_models_requested = pyqtSignal()
174
+ model_selected = pyqtSignal(str)
175
+ annotation_size_changed = pyqtSignal(int)
176
+ pan_speed_changed = pyqtSignal(int)
177
+ join_threshold_changed = pyqtSignal(int)
178
+ fragment_threshold_changed = pyqtSignal(int)
179
+ brightness_changed = pyqtSignal(int)
180
+ contrast_changed = pyqtSignal(int)
181
+ gamma_changed = pyqtSignal(int)
182
+ reset_adjustments_requested = pyqtSignal()
183
+ image_adjustment_changed = pyqtSignal()
184
+ hotkeys_requested = pyqtSignal()
185
+ pop_out_requested = pyqtSignal()
186
+ settings_changed = pyqtSignal()
187
+ # Border crop signals
188
+ crop_draw_requested = pyqtSignal()
189
+ crop_clear_requested = pyqtSignal()
190
+ crop_applied = pyqtSignal(int, int, int, int) # x1, y1, x2, y2
191
+ # Channel threshold signals
192
+ channel_threshold_changed = pyqtSignal()
193
+ # FFT threshold signals
194
+ fft_threshold_changed = pyqtSignal()
195
+
196
+ def __init__(self, parent=None):
197
+ super().__init__(parent)
198
+ self.setMinimumWidth(260) # Slightly wider for better layout
199
+ self.preferred_width = 280
200
+ self._setup_ui()
201
+ self._connect_signals()
202
+
203
+ def _setup_ui(self):
204
+ """Setup the professional UI layout."""
205
+ layout = QVBoxLayout(self)
206
+ layout.setContentsMargins(8, 8, 8, 8)
207
+ layout.setSpacing(8)
208
+
209
+ # Create widgets first
210
+ self.model_widget = ModelSelectionWidget()
211
+ self.crop_widget = BorderCropWidget()
212
+ self.channel_threshold_widget = ChannelThresholdWidget()
213
+ self.fft_threshold_widget = FFTThresholdWidget()
214
+ self.settings_widget = SettingsWidget()
215
+ self.adjustments_widget = AdjustmentsWidget()
216
+ self.fragment_widget = FragmentThresholdWidget()
217
+
218
+ # Top header with pop-out button
219
+ header_layout = QHBoxLayout()
220
+ header_layout.addStretch()
221
+
222
+ self.btn_popout = QPushButton("⋯")
223
+ self.btn_popout.setToolTip("Pop out panel to separate window")
224
+ self.btn_popout.setMaximumWidth(30)
225
+ self.btn_popout.setMaximumHeight(25)
226
+ self.btn_popout.setStyleSheet(
227
+ """
228
+ QPushButton {
229
+ background-color: rgba(60, 60, 60, 0.8);
230
+ border: 1px solid rgba(80, 80, 80, 0.6);
231
+ border-radius: 4px;
232
+ color: #E0E0E0;
233
+ }
234
+ QPushButton:hover {
235
+ background-color: rgba(80, 80, 80, 0.9);
236
+ }
237
+ QPushButton:pressed {
238
+ background-color: rgba(40, 40, 40, 0.9);
239
+ }
240
+ """
241
+ )
242
+ header_layout.addWidget(self.btn_popout)
243
+ layout.addLayout(header_layout)
244
+
245
+ # Fixed Mode Controls Section (Always Visible)
246
+ mode_card = self._create_mode_card()
247
+ layout.addWidget(mode_card)
248
+
249
+ # Tabbed Interface for Everything Else
250
+ self.tab_widget = QTabWidget()
251
+ self.tab_widget.setStyleSheet(
252
+ """
253
+ QTabWidget::pane {
254
+ border: 1px solid rgba(80, 80, 80, 0.6);
255
+ border-radius: 6px;
256
+ background-color: rgba(35, 35, 35, 0.9);
257
+ margin-top: 2px;
258
+ }
259
+ QTabWidget::tab-bar {
260
+ alignment: center;
261
+ }
262
+ QTabBar::tab {
263
+ background-color: rgba(50, 50, 50, 0.8);
264
+ border: 1px solid rgba(70, 70, 70, 0.6);
265
+ border-bottom: none;
266
+ border-radius: 4px 4px 0 0;
267
+ padding: 4px 8px;
268
+ margin-right: 1px;
269
+ color: #B0B0B0;
270
+ font-size: 9px;
271
+ min-width: 45px;
272
+ max-width: 80px;
273
+ }
274
+ QTabBar::tab:selected {
275
+ background-color: rgba(70, 70, 70, 0.9);
276
+ color: #E0E0E0;
277
+ font-weight: bold;
278
+ }
279
+ QTabBar::tab:hover:!selected {
280
+ background-color: rgba(60, 60, 60, 0.8);
281
+ color: #D0D0D0;
282
+ }
283
+ """
284
+ )
285
+
286
+ # AI & Settings Tab
287
+ ai_tab = self._create_ai_tab()
288
+ self.tab_widget.addTab(ai_tab, "🤖 AI")
289
+
290
+ # Processing & Adjustments Tab
291
+ processing_tab = self._create_processing_tab()
292
+ self.tab_widget.addTab(processing_tab, "🛠️ Tools")
293
+
294
+ layout.addWidget(self.tab_widget, 1)
295
+
296
+ # Status label at bottom
297
+ self.notification_label = QLabel("")
298
+ self.notification_label.setStyleSheet(
299
+ """
300
+ QLabel {
301
+ color: #FFA500;
302
+ font-style: italic;
303
+ font-size: 9px;
304
+ background: transparent;
305
+ border: none;
306
+ padding: 4px;
307
+ }
308
+ """
309
+ )
310
+ self.notification_label.setWordWrap(True)
311
+ layout.addWidget(self.notification_label)
312
+
313
+ def _create_mode_card(self):
314
+ """Create the fixed mode controls card."""
315
+ mode_card = ProfessionalCard("Mode Controls")
316
+
317
+ # Mode buttons in a clean grid
318
+ buttons_layout = QVBoxLayout()
319
+ buttons_layout.setSpacing(4)
320
+
321
+ # First row: AI and Polygon
322
+ row1_layout = QHBoxLayout()
323
+ row1_layout.setSpacing(4)
324
+
325
+ self.btn_sam_mode = self._create_mode_button(
326
+ "AI", "1", "Switch to AI Mode for AI segmentation"
327
+ )
328
+ self.btn_sam_mode.setCheckable(True)
329
+ self.btn_sam_mode.setChecked(True) # Default mode
330
+
331
+ self.btn_polygon_mode = self._create_mode_button(
332
+ "Poly", "2", "Switch to Polygon Drawing Mode"
333
+ )
334
+ self.btn_polygon_mode.setCheckable(True)
335
+
336
+ row1_layout.addWidget(self.btn_sam_mode)
337
+ row1_layout.addWidget(self.btn_polygon_mode)
338
+ buttons_layout.addLayout(row1_layout)
339
+
340
+ # Second row: BBox and Selection
341
+ row2_layout = QHBoxLayout()
342
+ row2_layout.setSpacing(4)
343
+
344
+ self.btn_bbox_mode = self._create_mode_button(
345
+ "Box", "3", "Switch to Bounding Box Drawing Mode"
346
+ )
347
+ self.btn_bbox_mode.setCheckable(True)
348
+
349
+ self.btn_selection_mode = self._create_mode_button(
350
+ "Select", "E", "Toggle segment selection"
351
+ )
352
+ self.btn_selection_mode.setCheckable(True)
353
+
354
+ row2_layout.addWidget(self.btn_bbox_mode)
355
+ row2_layout.addWidget(self.btn_selection_mode)
356
+ buttons_layout.addLayout(row2_layout)
357
+
358
+ mode_card.addLayout(buttons_layout)
359
+
360
+ # Bottom utility row: Edit and Hotkeys
361
+ utility_layout = QHBoxLayout()
362
+ utility_layout.setSpacing(4)
363
+
364
+ self.btn_edit_mode = self._create_utility_button(
365
+ "Edit", "R", "Edit segments and polygons"
366
+ )
367
+ self.btn_edit_mode.setCheckable(True) # Make edit button checkable
368
+
369
+ self.btn_hotkeys = self._create_utility_button(
370
+ "⌨️ Hotkeys", "", "Configure keyboard shortcuts"
371
+ )
372
+
373
+ utility_layout.addWidget(self.btn_edit_mode)
374
+ utility_layout.addWidget(self.btn_hotkeys)
375
+
376
+ mode_card.addLayout(utility_layout)
377
+
378
+ return mode_card
379
+
380
+ def _create_mode_button(self, text, key, tooltip):
381
+ """Create a professional mode button."""
382
+ button = QPushButton(f"{text} ({key})")
383
+ button.setToolTip(f"{tooltip} ({key})")
384
+ button.setFixedHeight(28)
385
+ button.setFixedWidth(75) # Fixed width for consistency
386
+ button.setStyleSheet(
387
+ """
388
+ QPushButton {
389
+ background-color: rgba(60, 90, 120, 0.8);
390
+ border: 1px solid rgba(80, 110, 140, 0.8);
391
+ border-radius: 6px;
392
+ color: #E0E0E0;
393
+ font-weight: bold;
394
+ font-size: 10px;
395
+ padding: 4px 8px;
396
+ }
397
+ QPushButton:hover {
398
+ background-color: rgba(80, 110, 140, 0.9);
399
+ border-color: rgba(100, 130, 160, 0.9);
400
+ }
401
+ QPushButton:pressed {
402
+ background-color: rgba(40, 70, 100, 0.9);
403
+ }
404
+ QPushButton:checked {
405
+ background-color: rgba(120, 170, 220, 1.0);
406
+ border: 2px solid rgba(150, 200, 250, 1.0);
407
+ color: #FFFFFF;
408
+ font-weight: bold;
409
+ }
410
+ QPushButton:checked:hover {
411
+ background-color: rgba(140, 190, 240, 1.0);
412
+ border: 2px solid rgba(170, 220, 255, 1.0);
413
+ }
414
+ """
415
+ )
416
+ return button
417
+
418
+ def _create_utility_button(self, text, key, tooltip):
419
+ """Create a utility button with consistent styling."""
420
+ if key:
421
+ button_text = f"{text} ({key})"
422
+ tooltip_text = f"{tooltip} ({key})"
423
+ else:
424
+ button_text = text
425
+ tooltip_text = tooltip
426
+
427
+ button = QPushButton(button_text)
428
+ button.setToolTip(tooltip_text)
429
+ button.setFixedHeight(28)
430
+ button.setFixedWidth(75) # Fixed width for consistency
431
+ button.setStyleSheet(
432
+ """
433
+ QPushButton {
434
+ background-color: rgba(70, 100, 130, 0.8);
435
+ border: 1px solid rgba(90, 120, 150, 0.8);
436
+ border-radius: 6px;
437
+ color: #E0E0E0;
438
+ font-weight: bold;
439
+ font-size: 10px;
440
+ padding: 4px 8px;
441
+ }
442
+ QPushButton:hover {
443
+ background-color: rgba(90, 120, 150, 0.9);
444
+ border-color: rgba(110, 140, 170, 0.9);
445
+ }
446
+ QPushButton:pressed {
447
+ background-color: rgba(50, 80, 110, 0.9);
448
+ }
449
+ QPushButton:checked {
450
+ background-color: rgba(120, 170, 220, 1.0);
451
+ border: 2px solid rgba(150, 200, 250, 1.0);
452
+ color: #FFFFFF;
453
+ font-weight: bold;
454
+ }
455
+ QPushButton:checked:hover {
456
+ background-color: rgba(140, 190, 240, 1.0);
457
+ border: 2px solid rgba(170, 220, 255, 1.0);
458
+ }
459
+ """
460
+ )
461
+ return button
462
+
463
+ def _get_mode_sized_button_style(self):
464
+ """Get styling for utility buttons that matches mode button size."""
465
+ return """
466
+ QPushButton {
467
+ background-color: rgba(80, 80, 80, 0.8);
468
+ border: 1px solid rgba(100, 100, 100, 0.6);
469
+ border-radius: 6px;
470
+ color: #E0E0E0;
471
+ font-weight: bold;
472
+ font-size: 10px;
473
+ padding: 4px 8px;
474
+ min-height: 22px;
475
+ }
476
+ QPushButton:hover {
477
+ background-color: rgba(100, 100, 100, 0.9);
478
+ border-color: rgba(120, 120, 120, 0.8);
479
+ }
480
+ QPushButton:pressed {
481
+ background-color: rgba(60, 60, 60, 0.9);
482
+ }
483
+ """
484
+
485
+ def _get_utility_button_style(self):
486
+ """Get styling for utility buttons."""
487
+ return """
488
+ QPushButton {
489
+ background-color: rgba(80, 80, 80, 0.8);
490
+ border: 1px solid rgba(100, 100, 100, 0.6);
491
+ border-radius: 5px;
492
+ color: #E0E0E0;
493
+ font-size: 10px;
494
+ padding: 4px 8px;
495
+ min-height: 22px;
496
+ }
497
+ QPushButton:hover {
498
+ background-color: rgba(100, 100, 100, 0.9);
499
+ }
500
+ QPushButton:pressed {
501
+ background-color: rgba(60, 60, 60, 0.9);
502
+ }
503
+ """
504
+
505
+ def _create_ai_tab(self):
506
+ """Create the AI & Settings tab."""
507
+ tab_widget = QWidget()
508
+
509
+ # Create scroll area for AI and settings
510
+ scroll = QScrollArea()
511
+ scroll.setWidgetResizable(True)
512
+ scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
513
+ scroll.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
514
+ scroll.setStyleSheet(
515
+ """
516
+ QScrollArea {
517
+ border: none;
518
+ background: transparent;
519
+ }
520
+ QScrollBar:vertical {
521
+ background-color: rgba(60, 60, 60, 0.5);
522
+ width: 8px;
523
+ border-radius: 4px;
524
+ }
525
+ QScrollBar::handle:vertical {
526
+ background-color: rgba(120, 120, 120, 0.7);
527
+ border-radius: 4px;
528
+ min-height: 20px;
529
+ }
530
+ QScrollBar::handle:vertical:hover {
531
+ background-color: rgba(140, 140, 140, 0.8);
532
+ }
533
+ """
534
+ )
535
+
536
+ scroll_content = QWidget()
537
+ layout = QVBoxLayout(scroll_content)
538
+ layout.setContentsMargins(6, 6, 6, 6)
539
+ layout.setSpacing(8)
540
+
541
+ # AI Model Selection - collapsible
542
+ model_collapsible = SimpleCollapsible("AI Model Selection", self.model_widget)
543
+ layout.addWidget(model_collapsible)
544
+
545
+ # AI Fragment Filter - collapsible
546
+ fragment_collapsible = SimpleCollapsible(
547
+ "AI Fragment Filter", self.fragment_widget
548
+ )
549
+ layout.addWidget(fragment_collapsible)
550
+
551
+ # Application Settings - collapsible
552
+ settings_collapsible = SimpleCollapsible(
553
+ "Application Settings", self.settings_widget
554
+ )
555
+ layout.addWidget(settings_collapsible)
556
+
557
+ layout.addStretch()
558
+
559
+ scroll.setWidget(scroll_content)
560
+
561
+ tab_layout = QVBoxLayout(tab_widget)
562
+ tab_layout.setContentsMargins(0, 0, 0, 0)
563
+ tab_layout.addWidget(scroll)
564
+
565
+ return tab_widget
566
+
567
+ def _create_processing_tab(self):
568
+ """Create the Processing & Tools tab."""
569
+ tab_widget = QWidget()
570
+
571
+ # Create scroll area for processing controls
572
+ scroll = QScrollArea()
573
+ scroll.setWidgetResizable(True)
574
+ scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
575
+ scroll.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
576
+ scroll.setStyleSheet(
577
+ """
578
+ QScrollArea {
579
+ border: none;
580
+ background: transparent;
581
+ }
582
+ QScrollBar:vertical {
583
+ background-color: rgba(60, 60, 60, 0.5);
584
+ width: 8px;
585
+ border-radius: 4px;
586
+ }
587
+ QScrollBar::handle:vertical {
588
+ background-color: rgba(120, 120, 120, 0.7);
589
+ border-radius: 4px;
590
+ min-height: 20px;
591
+ }
592
+ QScrollBar::handle:vertical:hover {
593
+ background-color: rgba(140, 140, 140, 0.8);
594
+ }
595
+ """
596
+ )
597
+
598
+ scroll_content = QWidget()
599
+ layout = QVBoxLayout(scroll_content)
600
+ layout.setContentsMargins(6, 6, 6, 6)
601
+ layout.setSpacing(8)
602
+
603
+ # Border Crop - collapsible
604
+ crop_collapsible = SimpleCollapsible("Border Crop", self.crop_widget)
605
+ layout.addWidget(crop_collapsible)
606
+
607
+ # Channel Threshold - collapsible
608
+ threshold_collapsible = SimpleCollapsible(
609
+ "Channel Threshold", self.channel_threshold_widget
610
+ )
611
+ layout.addWidget(threshold_collapsible)
612
+
613
+ # FFT Threshold - collapsible
614
+ fft_threshold_collapsible = SimpleCollapsible(
615
+ "FFT Threshold", self.fft_threshold_widget
616
+ )
617
+ layout.addWidget(fft_threshold_collapsible)
618
+
619
+ # Image Adjustments - collapsible
620
+ adjustments_collapsible = SimpleCollapsible(
621
+ "Image Adjustments", self.adjustments_widget
622
+ )
623
+ layout.addWidget(adjustments_collapsible)
624
+
625
+ layout.addStretch()
626
+
627
+ scroll.setWidget(scroll_content)
628
+
629
+ tab_layout = QVBoxLayout(tab_widget)
630
+ tab_layout.setContentsMargins(0, 0, 0, 0)
631
+ tab_layout.addWidget(scroll)
632
+
633
+ return tab_widget
634
+
635
+ def _connect_signals(self):
636
+ """Connect internal signals."""
637
+ self.btn_sam_mode.clicked.connect(self._on_sam_mode_clicked)
638
+ self.btn_polygon_mode.clicked.connect(self._on_polygon_mode_clicked)
639
+ self.btn_bbox_mode.clicked.connect(self._on_bbox_mode_clicked)
640
+ self.btn_selection_mode.clicked.connect(self._on_selection_mode_clicked)
641
+ self.btn_edit_mode.clicked.connect(self._on_edit_mode_clicked)
642
+ self.btn_hotkeys.clicked.connect(self.hotkeys_requested)
643
+ self.btn_popout.clicked.connect(self.pop_out_requested)
644
+
645
+ # Model widget signals
646
+ self.model_widget.browse_requested.connect(self.browse_models_requested)
647
+ self.model_widget.refresh_requested.connect(self.refresh_models_requested)
648
+ self.model_widget.model_selected.connect(self.model_selected)
649
+
650
+ # Settings widget signals
651
+ self.settings_widget.settings_changed.connect(self.settings_changed)
652
+
653
+ # Adjustments widget signals
654
+ self.adjustments_widget.annotation_size_changed.connect(
655
+ self.annotation_size_changed
656
+ )
657
+ self.adjustments_widget.pan_speed_changed.connect(self.pan_speed_changed)
658
+ self.adjustments_widget.join_threshold_changed.connect(
659
+ self.join_threshold_changed
660
+ )
661
+ self.adjustments_widget.brightness_changed.connect(self.brightness_changed)
662
+ self.adjustments_widget.contrast_changed.connect(self.contrast_changed)
663
+ self.adjustments_widget.gamma_changed.connect(self.gamma_changed)
664
+ self.adjustments_widget.reset_requested.connect(
665
+ self.reset_adjustments_requested
666
+ )
667
+ self.adjustments_widget.image_adjustment_changed.connect(
668
+ self.image_adjustment_changed
669
+ )
670
+
671
+ # Fragment threshold widget signals
672
+ self.fragment_widget.fragment_threshold_changed.connect(
673
+ self.fragment_threshold_changed
674
+ )
675
+
676
+ # Border crop signals
677
+ self.crop_widget.crop_draw_requested.connect(self.crop_draw_requested)
678
+ self.crop_widget.crop_clear_requested.connect(self.crop_clear_requested)
679
+ self.crop_widget.crop_applied.connect(self.crop_applied)
680
+
681
+ # Channel threshold signals
682
+ self.channel_threshold_widget.thresholdChanged.connect(
683
+ self.channel_threshold_changed
684
+ )
685
+
686
+ # FFT threshold signals
687
+ self.fft_threshold_widget.fft_threshold_changed.connect(
688
+ self.fft_threshold_changed
689
+ )
690
+
691
+ def _on_sam_mode_clicked(self):
692
+ """Handle AI mode button click."""
693
+ self._set_active_mode_button(self.btn_sam_mode)
694
+ self.sam_mode_requested.emit()
695
+
696
+ def _on_polygon_mode_clicked(self):
697
+ """Handle polygon mode button click."""
698
+ self._set_active_mode_button(self.btn_polygon_mode)
699
+ self.polygon_mode_requested.emit()
700
+
701
+ def _on_bbox_mode_clicked(self):
702
+ """Handle bbox mode button click."""
703
+ self._set_active_mode_button(self.btn_bbox_mode)
704
+ self.bbox_mode_requested.emit()
705
+
706
+ def _on_selection_mode_clicked(self):
707
+ """Handle selection mode button click."""
708
+ self._set_active_mode_button(self.btn_selection_mode)
709
+ self.selection_mode_requested.emit()
710
+
711
+ def _on_edit_mode_clicked(self):
712
+ """Handle edit mode button click."""
713
+ # For now, emit the signal - the main window will handle polygon checking
714
+ self.edit_mode_requested.emit()
715
+
716
+ def _set_active_mode_button(self, active_button):
717
+ """Set the active mode button and deactivate others."""
718
+ mode_buttons = [
719
+ self.btn_sam_mode,
720
+ self.btn_polygon_mode,
721
+ self.btn_bbox_mode,
722
+ self.btn_selection_mode,
723
+ ]
724
+
725
+ # Clear all mode buttons
726
+ for button in mode_buttons:
727
+ button.setChecked(button == active_button if active_button else False)
728
+
729
+ # Clear edit button when setting mode buttons
730
+ if active_button and active_button != self.btn_edit_mode:
731
+ self.btn_edit_mode.setChecked(False)
732
+
733
+ def mouseDoubleClickEvent(self, event):
734
+ """Handle double-click to expand collapsed panel."""
735
+ if (
736
+ self.width() < 50
737
+ and self.parent()
738
+ and hasattr(self.parent(), "_expand_left_panel")
739
+ ):
740
+ self.parent()._expand_left_panel()
741
+ super().mouseDoubleClickEvent(event)
742
+
743
+ def show_notification(self, message: str, duration: int = 3000):
744
+ """Show a notification message."""
745
+ self.notification_label.setText(message)
746
+ # Note: Timer should be handled by the caller
747
+
748
+ def clear_notification(self):
749
+ """Clear the notification message."""
750
+ self.notification_label.clear()
751
+
752
+ def set_mode_text(self, mode: str):
753
+ """Set the active mode by highlighting the corresponding button."""
754
+ # Map internal mode names to buttons
755
+ mode_buttons = {
756
+ "sam_points": self.btn_sam_mode,
757
+ "polygon": self.btn_polygon_mode,
758
+ "bbox": self.btn_bbox_mode,
759
+ "selection": self.btn_selection_mode,
760
+ "edit": self.btn_edit_mode,
761
+ }
762
+
763
+ active_button = mode_buttons.get(mode)
764
+ if active_button:
765
+ # Clear all mode buttons first
766
+ self._set_active_mode_button(None)
767
+ # Set edit button separately if it's edit mode
768
+ if mode == "edit":
769
+ self.btn_edit_mode.setChecked(True)
770
+ else:
771
+ self._set_active_mode_button(active_button)
772
+
773
+ def set_edit_mode_active(self, active: bool):
774
+ """Set edit mode button as active or inactive."""
775
+ if active:
776
+ # Clear all mode buttons and set edit as active
777
+ self._set_active_mode_button(None)
778
+ self.btn_edit_mode.setChecked(True)
779
+ else:
780
+ self.btn_edit_mode.setChecked(False)
781
+
782
+ # Delegate methods for sub-widgets
783
+ def populate_models(self, models):
784
+ """Populate the models combo box."""
785
+ self.model_widget.populate_models(models)
786
+
787
+ def set_current_model(self, model_name):
788
+ """Set the current model display."""
789
+ self.model_widget.set_current_model(model_name)
790
+
791
+ def get_settings(self):
792
+ """Get current settings from the settings widget."""
793
+ return self.settings_widget.get_settings()
794
+
795
+ def set_settings(self, settings):
796
+ """Set settings in the settings widget."""
797
+ self.settings_widget.set_settings(settings)
798
+
799
+ def get_annotation_size(self):
800
+ """Get current annotation size."""
801
+ return self.adjustments_widget.get_annotation_size()
802
+
803
+ def set_annotation_size(self, value):
804
+ """Set annotation size."""
805
+ self.adjustments_widget.set_annotation_size(value)
806
+
807
+ def set_pan_speed(self, value):
808
+ """Set pan speed."""
809
+ self.adjustments_widget.set_pan_speed(value)
810
+
811
+ def set_join_threshold(self, value):
812
+ """Set join threshold."""
813
+ self.adjustments_widget.set_join_threshold(value)
814
+
815
+ def set_fragment_threshold(self, value):
816
+ """Set fragment threshold."""
817
+ self.fragment_widget.set_fragment_threshold(value)
818
+
819
+ def set_brightness(self, value):
820
+ """Set brightness."""
821
+ self.adjustments_widget.set_brightness(value)
822
+
823
+ def set_contrast(self, value):
824
+ """Set contrast."""
825
+ self.adjustments_widget.set_contrast(value)
826
+
827
+ def set_gamma(self, value):
828
+ """Set gamma."""
829
+ self.adjustments_widget.set_gamma(value)
830
+
831
+ def set_sam_mode_enabled(self, enabled: bool):
832
+ """Enable or disable the SAM mode button."""
833
+ self.btn_sam_mode.setEnabled(enabled)
834
+ if not enabled:
835
+ self.btn_sam_mode.setToolTip("AI Mode (SAM model not available)")
836
+ else:
837
+ self.btn_sam_mode.setToolTip("Switch to AI Mode for AI segmentation (1)")
838
+
839
+ def set_popout_mode(self, is_popped_out: bool):
840
+ """Update the pop-out button based on panel state."""
841
+ if is_popped_out:
842
+ self.btn_popout.setText("⇤")
843
+ self.btn_popout.setToolTip("Return panel to main window")
844
+ else:
845
+ self.btn_popout.setText("⋯")
846
+ self.btn_popout.setToolTip("Pop out panel to separate window")
847
+
848
+ # Border crop delegate methods
849
+ def set_crop_coordinates(self, x1, y1, x2, y2):
850
+ """Set crop coordinates in the crop widget."""
851
+ self.crop_widget.set_crop_coordinates(x1, y1, x2, y2)
852
+
853
+ def clear_crop_coordinates(self):
854
+ """Clear crop coordinates."""
855
+ self.crop_widget.clear_crop_coordinates()
856
+
857
+ def get_crop_coordinates(self):
858
+ """Get current crop coordinates."""
859
+ return self.crop_widget.get_crop_coordinates()
860
+
861
+ def has_crop(self):
862
+ """Check if crop coordinates are set."""
863
+ return self.crop_widget.has_crop()
864
+
865
+ def set_crop_status(self, message):
866
+ """Set crop status message."""
867
+ self.crop_widget.set_status(message)
868
+
869
+ # Channel threshold delegate methods
870
+ def update_channel_threshold_for_image(self, image_array):
871
+ """Update channel threshold widget for new image."""
872
+ self.channel_threshold_widget.update_for_image(image_array)
873
+
874
+ def get_channel_threshold_widget(self):
875
+ """Get the channel threshold widget."""
876
+ return self.channel_threshold_widget
877
+
878
+ # FFT threshold delegate methods
879
+ def update_fft_threshold_for_image(self, image_array):
880
+ """Update FFT threshold widget for new image."""
881
+ self.fft_threshold_widget.update_fft_threshold_for_image(image_array)
882
+
883
+ def get_fft_threshold_widget(self):
884
+ """Get the FFT threshold widget."""
885
+ return self.fft_threshold_widget