coralnet-toolbox 0.0.67__py2.py3-none-any.whl → 0.0.69__py2.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.
@@ -1616,6 +1616,49 @@ class MainWindow(QMainWindow):
1616
1616
  except Exception as e:
1617
1617
  QMessageBox.critical(self, "Critical Error", f"{e}")
1618
1618
 
1619
+ def set_main_window_enabled_state(self, enable_list=None, disable_list=None):
1620
+ """
1621
+ Modular method to enable/disable widgets and actions in the main window.
1622
+ - enable_list: list of widgets/actions to enable
1623
+ - disable_list: list of widgets/actions to disable
1624
+ If both are None, enables everything.
1625
+ """
1626
+ # All main widgets/actions to consider
1627
+ all_widgets = [
1628
+ self.toolbar,
1629
+ self.menu_bar,
1630
+ self.image_window,
1631
+ self.label_window,
1632
+ self.confidence_window,
1633
+ self.annotation_window,
1634
+ # Status bar widgets
1635
+ *(self.status_bar_layout.itemAt(i).widget() for i in range(self.status_bar_layout.count()))
1636
+ ]
1637
+ # Remove None entries (in case any status bar slot is empty)
1638
+ all_widgets = [w for w in all_widgets if w is not None]
1639
+
1640
+ # If neither list is provided, enable everything
1641
+ if enable_list is None and disable_list is None:
1642
+ for w in all_widgets:
1643
+ w.setEnabled(True)
1644
+ return
1645
+
1646
+ # Disable everything by default
1647
+ for w in all_widgets:
1648
+ w.setEnabled(False)
1649
+
1650
+ # Enable specified widgets/actions
1651
+ if enable_list:
1652
+ for w in enable_list:
1653
+ if w is not None:
1654
+ w.setEnabled(True)
1655
+
1656
+ # Disable specified widgets/actions (overrides enable if both present)
1657
+ if disable_list:
1658
+ for w in disable_list:
1659
+ if w is not None:
1660
+ w.setEnabled(False)
1661
+
1619
1662
  def open_explorer_window(self):
1620
1663
  """Open the Explorer window, moving the LabelWindow into it."""
1621
1664
  # Check if there are any images in the project
@@ -1638,24 +1681,33 @@ class MainWindow(QMainWindow):
1638
1681
  self.explorer_window = ExplorerWindow(self)
1639
1682
 
1640
1683
  # Move the label_window from the main layout to the explorer
1641
- # The ExplorerWindow's __init__ will handle adding it to its own layout.
1642
1684
  self.left_layout.removeWidget(self.label_window)
1643
1685
  self.label_window.setParent(self.explorer_window.left_panel) # Re-parent
1644
1686
  self.explorer_window.left_layout.insertWidget(1, self.label_window) # Add to explorer layout
1645
1687
 
1646
- # Make the explorer window modal to block interaction with main window
1647
- self.explorer_window.setWindowModality(Qt.ApplicationModal)
1648
- # Disable the main window explicitly
1649
- self.setEnabled(False)
1688
+ # Disable all main window widgets except select few
1689
+ self.set_main_window_enabled_state(
1690
+ enable_list=[self.annotation_window,
1691
+ self.label_window,
1692
+ self.transparency_widget],
1693
+ disable_list=[self.toolbar,
1694
+ self.menu_bar,
1695
+ self.image_window,
1696
+ self.confidence_window]
1697
+ )
1650
1698
 
1651
1699
  self.explorer_window.showMaximized()
1652
1700
  self.explorer_window.activateWindow()
1653
1701
  self.explorer_window.raise_()
1702
+
1654
1703
  except Exception as e:
1655
1704
  QMessageBox.critical(self, "Critical Error", f"{e}")
1656
1705
  if self.explorer_window:
1657
1706
  self.explorer_window.close() # Ensure cleanup
1707
+
1658
1708
  self.explorer_window = None
1709
+ # Re-enable everything if there was an error
1710
+ self.set_main_window_enabled_state()
1659
1711
 
1660
1712
  def explorer_closed(self):
1661
1713
  """Handle the explorer window being closed."""
@@ -1667,8 +1719,8 @@ class MainWindow(QMainWindow):
1667
1719
  self.label_window.resizeEvent(None)
1668
1720
  self.resizeEvent(None)
1669
1721
 
1670
- # Re-enable the main window
1671
- self.setEnabled(True)
1722
+ # Re-enable all main window widgets
1723
+ self.set_main_window_enabled_state()
1672
1724
 
1673
1725
  # Clean up reference
1674
1726
  self.explorer_window = None
@@ -1,6 +1,6 @@
1
1
  """Top-level package for CoralNet-Toolbox."""
2
2
 
3
- __version__ = "0.0.67"
3
+ __version__ = "0.0.69"
4
4
  __author__ = "Jordan Pierce"
5
5
  __email__ = "jordan.pierce@noaa.gov"
6
6
  __credits__ = "National Center for Coastal and Ocean Sciences (NCCOS)"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: coralnet-toolbox
3
- Version: 0.0.67
3
+ Version: 0.0.69
4
4
  Summary: Tools for annotating and developing ML models for benthic imagery
5
5
  Author-email: Jordan Pierce <jordan.pierce@noaa.gov>
6
6
  License: MIT License
@@ -22,6 +22,7 @@ Requires-Dist: open-clip-torch>=2.20.0
22
22
  Requires-Dist: supervision>=0.24.0
23
23
  Requires-Dist: scikit-learn
24
24
  Requires-Dist: umap-learn
25
+ Requires-Dist: faiss-cpu
25
26
  Requires-Dist: pycocotools
26
27
  Requires-Dist: ujson
27
28
  Requires-Dist: timm==0.9.2
@@ -136,12 +137,17 @@ These models enable fast, accurate, and flexible annotation workflows for a wide
136
137
 
137
138
  <div align="center">
138
139
 
139
- | ![Patch Annotation Tool](https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Patches.gif)<br><sub>**Patch Annotation**</sub> | ![Rectangle Annotation Tool](https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Rectangles.gif)<br><sub>**Rectangle Annotation**</sub> | ![Polygon Annotation Tool](https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Polygons.gif)<br><sub>**(Multi) Polygon Annotation**</sub> |
140
+ | <img src="https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Patches.gif" alt="Patch Annotation Tool" width="256" height="256"/><br><sub>**Patch Annotation**</sub> | <img src="https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Rectangles.gif" alt="Rectangle Annotation Tool" width="256" height="256"/><br><sub>**Rectangle Annotation**</sub> | <img src="https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Polygons.gif" alt="Polygon Annotation Tool" width="256" height="256"/><br><sub>**(Multi) Polygon Annotation**</sub> |
140
141
  |:--:|:--:|:--:|
141
- | ![Patch-based Image Classification](https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Classification.gif)<br><sub>**Image Classification**</sub> | ![Object Detection](https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Object_Detection.gif)<br><sub>**Object Detection**</sub> | ![Instance Segmentation](https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Instance_Segmentation.gif)<br><sub>**Instance Segmentation**</sub> |
142
- | ![Segment Anything Model (SAM)](https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Segment_Anything.gif)<br><sub>**Segment Anything (SAM)**</sub> | ![Polygon Classification](https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Classifying_Polygons.gif)<br><sub>**Polygon Classification**</sub> | ![Region-based Detection](https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Work_Areas.gif)<br><sub>**Region-based Detection**</sub> |
143
- | ![Cut](https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Cut.gif)<br><sub>**Cut**</sub> | ![Combine](https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Combine.gif)<br><sub>**Combine**</sub> | ![Simplify](https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Simplify.gif)<br><sub>**Simplify**</sub> |
144
- | ![See Anything (YOLOE)](https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/See_Anything.gif)<br><sub>**See Anything (YOLOE)**</sub> | ![Patch-based LAI Classification](https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Classifying_Orthomosaics.gif)<br><sub>**Patch-based LAI Classification**</sub> | ![Video Inference](https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Analytics.gif)<br><sub>**Video Inference**</sub> |
142
+ | <img src="https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Classification.gif" alt="Patch-based Image Classification" width="256" height="256"/><br><sub>**Image Classification**</sub> | <img src="https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Object_Detection.gif" alt="Object Detection" width="256" height="256"/><br><sub>**Object Detection**</sub> | <img src="https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Instance_Segmentation.gif" alt="Instance Segmentation" width="256" height="256"/><br><sub>**Instance Segmentation**</sub> |
143
+ | <img src="https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Segment_Anything.gif" alt="Segment Anything Model (SAM)" width="256" height="256"/><br><sub>**Segment Anything (SAM)**</sub> | <img src="https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Classifying_Polygons.gif" alt="Polygon Classification" width="256" height="256"/><br><sub>**Polygon Classification**</sub> | <img src="https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Work_Areas.gif" alt="Region-based Detection" width="256" height="256"/><br><sub>**Region-based Detection**</sub> |
144
+ | <img src="https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Cut.gif" alt="Cut" width="256" height="256"/><br><sub>**Cut**</sub> | <img src="https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Combine.gif" alt="Combine" width="256" height="256"/><br><sub>**Combine**</sub> | <img src="https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Simplify.gif" alt="Simplify" width="256" height="256"/><br><sub>**Simplify**</sub> |
145
+ | <img src="https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/See_Anything.gif" alt="See Anything (YOLOE)" width="256" height="256"/><br><sub>**See Anything (YOLOE)**</sub> | <img src="https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Classifying_Orthomosaics.gif" alt="Patch-based LAI Classification" width="256" height="256"/><br><sub>**LAI Classification**</sub> | |
146
+
147
+ <br>
148
+
149
+ | <img src="https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Analytics.gif" alt="Video Inference" width="450"/><br><sub>**Video Inference**</sub> | <img src="https://raw.githubusercontent.com/Jordan-Pierce/CoralNet-Toolbox/refs/heads/main/figures/tools/Explorer.gif" alt="Explorer" width="450"/><br><sub>**Explorer**</sub> |
150
+ |:--:|:--:|
145
151
 
146
152
  </div>
147
153
 
@@ -166,11 +172,12 @@ Enhance your CoralNet experience with these tools:
166
172
  - Uses `Grounding DINO`, `OWLViT`, `OmDetTurbo`
167
173
  - 📻 Tune: Tune hyperparameters to identify ideal training conditions
168
174
  - 🧠 Train: Build local patch-based classifiers, object detection, and instance segmentation models
169
- - 🔮 Deploy: Use trained models for predictions
175
+ - 🧙‍♂️ Deploy: Use trained models for predictions
170
176
  - 📊 Evaluation: Evaluate model performance
171
177
  - 🚀 Optimize: Productionize models for faster inferencing
172
178
  - ⚙️ Batch Inference: Perform predictions on multiple images, automatically
173
179
  - 🎞️ Video Inference: Perform predictions on a video in real-time, record the output and analytics
180
+ - 🔮 Explorer: Cluster, view, and re-label annotations using embeddings, mapped from feature-space
174
181
  - ↔️ I/O: Import and Export annotations from / to CoralNet, Viscore, and TagLab
175
182
  - Export annotations as [GeoJSONs](https://datatracker.ietf.org/doc/html/rfc7946), segmentation masks
176
183
  - 📸 YOLO: Import and Export YOLO datasets for machine learning
@@ -1,13 +1,13 @@
1
1
  coralnet_toolbox/QtAnnotationWindow.py,sha256=ohYkvUdUAdNmZJXqKtCGnnXQ3cPtnSkFEtwH_mWnn3c,37808
2
2
  coralnet_toolbox/QtConfidenceWindow.py,sha256=L5hR23uW91GpqnsNS9R1XF3zCTe2aU7w0iDoQMV0oyE,16190
3
- coralnet_toolbox/QtEventFilter.py,sha256=mOtprjouvjHSo7II98dtYjtQkejh9GBUU8ORqQVfj-w,6014
3
+ coralnet_toolbox/QtEventFilter.py,sha256=KKC9de3e66PvGVgiML8P7MZ9-r7vvHidPJJYpcbTwyM,6696
4
4
  coralnet_toolbox/QtImageWindow.py,sha256=vLziMSEWFfVRSBN0nUNkosgk3LiNxZDqPwbinz9ZivQ,49356
5
- coralnet_toolbox/QtLabelWindow.py,sha256=ZRJilFpp6hIJohKv6L_dKdt6gnwmyNWnHVtU5IyjrEg,50326
6
- coralnet_toolbox/QtMainWindow.py,sha256=kkd27oCLnrwQkTi_dxcPE83gJg4ZSMy7MJdPW2qJ1FE,110105
5
+ coralnet_toolbox/QtLabelWindow.py,sha256=-4GCk4pTY9g4ADH1iE__4xwqT-7UR_7VCT8v-bJzerk,50869
6
+ coralnet_toolbox/QtMainWindow.py,sha256=r4pNozDqpaoyB1veiPLbUlbdacAwyHQQVHEy8kqJAS0,112034
7
7
  coralnet_toolbox/QtPatchSampling.py,sha256=Ehj06auBGfQwIruLNYQjF8eFOCpl8G72p42UXXb2mUo,29013
8
8
  coralnet_toolbox/QtProgressBar.py,sha256=pnozUOcVjfO_yTS9z8wOMPcrrrOtG_FeCknTcdI6eyk,6250
9
9
  coralnet_toolbox/QtWorkArea.py,sha256=YXRvHQKpWUtWyv_o9lZ8rmxfm28dUOG9pmMUeimDhQ4,13578
10
- coralnet_toolbox/__init__.py,sha256=H0IXXlx-vwZwsjELFjOcUWDaJgGmf3_swUlksKpj5L4,207
10
+ coralnet_toolbox/__init__.py,sha256=ShjZP-Gm_sxpQicWuT6DKcnGnAt8YWuUH08qUGKAPbU,207
11
11
  coralnet_toolbox/main.py,sha256=6j2B_1reC_KDmqvq1C0fB-UeSEm8eeJOozp2f4XXMLQ,1573
12
12
  coralnet_toolbox/utilities.py,sha256=eUkxXuWaNFH83LSW-KniwujkXKJ2rK04czx3k3OPiAY,27115
13
13
  coralnet_toolbox/Annotations/QtAnnotation.py,sha256=I2Givo3p92gfyVYnnFHBjxso-hmQCCXM531Pygiebfw,29242
@@ -35,11 +35,10 @@ coralnet_toolbox/Common/QtUpdateImagePaths.py,sha256=_hJYx6hXdAOfH_m77f75AQduQ0W
35
35
  coralnet_toolbox/CoralNet/QtAuthenticate.py,sha256=Y__iY0Kcosz6AOV7dlJBwiB6Hte40wHahHe-OmRngZA,13267
36
36
  coralnet_toolbox/CoralNet/QtDownload.py,sha256=HBb8TpZRIEFirGIaIAV1v8qg3fL4cP6Bf-hUiqXoiLE,48516
37
37
  coralnet_toolbox/CoralNet/__init__.py,sha256=ILkAZh6mlAK1UaCCZjCB9JZxd-oY4cIgfnIC8UgjjIU,188
38
- coralnet_toolbox/Explorer/QtAnnotationDataItem.py,sha256=Med4WHv-m-hQGKpjqBVnQskP0lgJBY55FxoiqaGCJao,3773
39
- coralnet_toolbox/Explorer/QtAnnotationImageWidget.py,sha256=OKz8B8d0HWthhz7rYM1xzoBPjKAqttCOsfxjPmvqvpM,7384
40
- coralnet_toolbox/Explorer/QtEmbeddingPointItem.py,sha256=zxLzC5-qBUoMaDem-e6Tw8IazPT_Nhv_nRPkIbn_QqY,1178
41
- coralnet_toolbox/Explorer/QtExplorer.py,sha256=cyo6X4W2pbIJqj-QFtbGk328Fmw63D9XxCIriGl2WMI,90169
42
- coralnet_toolbox/Explorer/QtSettingsWidgets.py,sha256=9SUcGaxBBoIDWNhjKGzJoJ4iFwvg1Om4XmZ9T4WsjrE,20584
38
+ coralnet_toolbox/Explorer/QtDataItem.py,sha256=-O2Tneh9wYbAZarqwb_Cvy5cP1F_zQH2IAw9c-rHy1Y,13572
39
+ coralnet_toolbox/Explorer/QtExplorer.py,sha256=rfJr29z3Nduh_NXxVJ-BZCLRxpfXhfeAuAae-2uV878,115844
40
+ coralnet_toolbox/Explorer/QtFeatureStore.py,sha256=kMn--vuBed6wZS-BQhHt_KBA5z-tL1ydFgFkkIoGiB4,6742
41
+ coralnet_toolbox/Explorer/QtSettingsWidgets.py,sha256=hIMj2lzqGKBoFWKYolH7bEPm5ePAIzYcGjYRQv2uWFE,27656
43
42
  coralnet_toolbox/Explorer/__init__.py,sha256=wZPhf2oaUUyIQ2WK48Aj-4q1ENIZG2dGl1HF_mjhI6w,116
44
43
  coralnet_toolbox/IO/QtExportAnnotations.py,sha256=xeaS0BukC3cpkBIGT9DXRqHmvHhp-vOU47h6EoANpNg,4474
45
44
  coralnet_toolbox/IO/QtExportCoralNetAnnotations.py,sha256=4royhF63EmeOlSIBX389EUjjvE-SF44_maW6qm52mdA,2778
@@ -216,9 +215,9 @@ coralnet_toolbox/Tools/QtTool.py,sha256=2MCjT151gYBN8KbsK0GX4WOrEg1uw3oeSkp7Elw1
216
215
  coralnet_toolbox/Tools/QtWorkAreaTool.py,sha256=-CDrEPenOdSI3sf5wn19Cip4alE1ef7WsRDxQFDkHlc,22162
217
216
  coralnet_toolbox/Tools/QtZoomTool.py,sha256=F9CAoABv1jxcUS7dyIh1FYjgjOXYRI1xtBPNIR1g62o,4041
218
217
  coralnet_toolbox/Tools/__init__.py,sha256=218iQ8IFXIkKXiUDVYtXk9e08UY9-LhHjcryaJAanQ0,797
219
- coralnet_toolbox-0.0.67.dist-info/licenses/LICENSE.txt,sha256=AURacZ_G_PZKqqPQ9VB9Sqegblk67RNgWSGAYKwXXMY,521
220
- coralnet_toolbox-0.0.67.dist-info/METADATA,sha256=2XfsFYzFeUyltrApg9HVRc8Smn5ALfwLriIwc6zv994,17096
221
- coralnet_toolbox-0.0.67.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
222
- coralnet_toolbox-0.0.67.dist-info/entry_points.txt,sha256=oEeMoDlJ_2lq95quOeDHIx9hZpubUlSo80OLtgbcrbM,63
223
- coralnet_toolbox-0.0.67.dist-info/top_level.txt,sha256=SMWPh4_9JfB8zVpPOOvjucV2_B_hvWW7bNWmMjG0LsY,17
224
- coralnet_toolbox-0.0.67.dist-info/RECORD,,
218
+ coralnet_toolbox-0.0.69.dist-info/licenses/LICENSE.txt,sha256=AURacZ_G_PZKqqPQ9VB9Sqegblk67RNgWSGAYKwXXMY,521
219
+ coralnet_toolbox-0.0.69.dist-info/METADATA,sha256=tEMfVdY4gbof1mKK4dlo5JyGWtTInnpiP83p9suRO34,18007
220
+ coralnet_toolbox-0.0.69.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
221
+ coralnet_toolbox-0.0.69.dist-info/entry_points.txt,sha256=oEeMoDlJ_2lq95quOeDHIx9hZpubUlSo80OLtgbcrbM,63
222
+ coralnet_toolbox-0.0.69.dist-info/top_level.txt,sha256=SMWPh4_9JfB8zVpPOOvjucV2_B_hvWW7bNWmMjG0LsY,17
223
+ coralnet_toolbox-0.0.69.dist-info/RECORD,,
@@ -1,97 +0,0 @@
1
- import warnings
2
-
3
- import os
4
-
5
- warnings.filterwarnings("ignore", category=DeprecationWarning)
6
-
7
-
8
- # ----------------------------------------------------------------------------------------------------------------------
9
- # Classes
10
- # ----------------------------------------------------------------------------------------------------------------------
11
-
12
-
13
- class AnnotationDataItem:
14
- """Holds annotation information for consistent display across viewers."""
15
-
16
- def __init__(self, annotation, embedding_x=None, embedding_y=None, embedding_id=None):
17
- self.annotation = annotation
18
- self.embedding_x = embedding_x if embedding_x is not None else 0.0
19
- self.embedding_y = embedding_y if embedding_y is not None else 0.0
20
- self.embedding_id = embedding_id if embedding_id is not None else 0
21
- self._is_selected = False
22
- self._preview_label = None
23
- self._original_label = annotation.label
24
- self._marked_for_deletion = False # Track deletion status
25
-
26
- @property
27
- def effective_label(self):
28
- """Get the current effective label (preview if exists, otherwise original)."""
29
- return self._preview_label if self._preview_label else self.annotation.label
30
-
31
- @property
32
- def effective_color(self):
33
- """Get the effective color for this annotation."""
34
- return self.effective_label.color
35
-
36
- @property
37
- def is_selected(self):
38
- """Check if this annotation is selected."""
39
- return self._is_selected
40
-
41
- def set_selected(self, selected):
42
- """Set the selection state."""
43
- self._is_selected = selected
44
-
45
- def set_preview_label(self, label):
46
- """Set a preview label for this annotation."""
47
- self._preview_label = label
48
-
49
- def clear_preview_label(self):
50
- """Clear the preview label and revert to original."""
51
- self._preview_label = None
52
-
53
- def has_preview_changes(self):
54
- """Check if this annotation has preview changes."""
55
- return self._preview_label is not None
56
-
57
- def mark_for_deletion(self):
58
- """Mark this annotation for deletion."""
59
- self._marked_for_deletion = True
60
-
61
- def unmark_for_deletion(self):
62
- """Unmark this annotation for deletion."""
63
- self._marked_for_deletion = False
64
-
65
- def is_marked_for_deletion(self):
66
- """Check if this annotation is marked for deletion."""
67
- return self._marked_for_deletion
68
-
69
- def apply_preview_permanently(self):
70
- """Apply the preview label permanently to the annotation."""
71
- if self._preview_label:
72
- self.annotation.update_label(self._preview_label)
73
- self.annotation.update_user_confidence(self._preview_label)
74
- self._original_label = self._preview_label
75
- self._preview_label = None
76
- return True
77
- return False
78
-
79
- def get_display_info(self):
80
- """Get display information for this annotation."""
81
- return {
82
- 'id': self.annotation.id,
83
- 'label': self.effective_label.short_label_code,
84
- 'confidence': self.get_effective_confidence(),
85
- 'type': type(self.annotation).__name__,
86
- 'image': os.path.basename(self.annotation.image_path),
87
- 'embedding_id': self.embedding_id,
88
- 'color': self.effective_color
89
- }
90
-
91
- def get_effective_confidence(self):
92
- """Get the effective confidence value."""
93
- if self.annotation.verified and hasattr(self.annotation, 'user_confidence') and self.annotation.user_confidence:
94
- return list(self.annotation.user_confidence.values())[0]
95
- elif hasattr(self.annotation, 'machine_confidence') and self.annotation.machine_confidence:
96
- return list(self.annotation.machine_confidence.values())[0]
97
- return 0.0
@@ -1,183 +0,0 @@
1
- import warnings
2
-
3
- from PyQt5.QtGui import QPen, QColor, QPainter
4
- from PyQt5.QtCore import Qt, QTimer
5
-
6
- from PyQt5.QtWidgets import (QVBoxLayout, QLabel, QWidget)
7
-
8
-
9
- warnings.filterwarnings("ignore", category=DeprecationWarning)
10
-
11
-
12
- # ----------------------------------------------------------------------------------------------------------------------
13
- # Constants
14
- # ----------------------------------------------------------------------------------------------------------------------
15
-
16
- ANNOTATION_WIDTH = 5
17
-
18
- # ----------------------------------------------------------------------------------------------------------------------
19
- # Classes
20
- # ----------------------------------------------------------------------------------------------------------------------
21
-
22
-
23
- class AnnotationImageWidget(QWidget):
24
- """Widget to display a single annotation image crop with selection support."""
25
-
26
- def __init__(self, data_item, widget_height=96, annotation_viewer=None, parent=None):
27
- super(AnnotationImageWidget, self).__init__(parent)
28
- self.data_item = data_item
29
- self.annotation = data_item.annotation
30
- self.annotation_viewer = annotation_viewer
31
-
32
- self.widget_height = widget_height
33
- self.aspect_ratio = 1.0 # Default to a square aspect ratio
34
- self.pixmap = None # Cache the original, unscaled pixmap
35
-
36
- self.animation_offset = 0
37
- self.animation_timer = QTimer(self)
38
- self.animation_timer.timeout.connect(self._update_animation_frame)
39
- self.animation_timer.setInterval(75)
40
-
41
- self.setup_ui()
42
- self.load_and_set_image() # Changed from load_annotation_image
43
-
44
- def setup_ui(self):
45
- """Set up the basic UI with a label for the image."""
46
- layout = QVBoxLayout(self)
47
- layout.setContentsMargins(4, 4, 4, 4)
48
-
49
- self.image_label = QLabel()
50
- self.image_label.setAlignment(Qt.AlignCenter)
51
- self.image_label.setScaledContents(True)
52
- self.image_label.setStyleSheet("border: none;")
53
-
54
- layout.addWidget(self.image_label)
55
-
56
- def load_and_set_image(self):
57
- """Load image, calculate its aspect ratio, and set the widget's initial size."""
58
- try:
59
- # Use get_cropped_image_graphic() to get the QPixmap
60
- cropped_pixmap = self.annotation.get_cropped_image_graphic()
61
- if cropped_pixmap and not cropped_pixmap.isNull():
62
- self.pixmap = cropped_pixmap
63
- # Safely calculate aspect ratio
64
- if self.pixmap.height() > 0:
65
- self.aspect_ratio = self.pixmap.width() / self.pixmap.height()
66
- else:
67
- self.aspect_ratio = 1.0
68
- else:
69
- self.image_label.setText("No Image\nAvailable")
70
- self.pixmap = None
71
- self.aspect_ratio = 1.0
72
- except Exception as e:
73
- print(f"Error loading annotation image: {e}")
74
- self.image_label.setText("Error\nLoading Image")
75
- self.pixmap = None
76
- self.aspect_ratio = 1.0
77
-
78
- # Trigger an initial size update
79
- self.update_height(self.widget_height)
80
-
81
- def update_height(self, new_height):
82
- """Updates the widget's height and rescales its width and content accordingly."""
83
- self.widget_height = new_height
84
-
85
- # Calculate the new width based on the stored aspect ratio
86
- new_width = int(self.widget_height * self.aspect_ratio)
87
-
88
- # Set the new fixed size for the entire widget
89
- self.setFixedSize(new_width, new_height)
90
-
91
- if self.pixmap:
92
- # Scale the cached pixmap to fit the new widget size, leaving room for the border
93
- # Note: We use the widget's new dimensions directly
94
- scaled_pixmap = self.pixmap.scaled(
95
- new_width - 8, # Account for horizontal margins
96
- new_height - 8, # Account for vertical margins
97
- Qt.KeepAspectRatio,
98
- Qt.SmoothTransformation
99
- )
100
- self.image_label.setPixmap(scaled_pixmap)
101
-
102
- self.update() # Schedule a repaint if needed
103
-
104
- # Replace update_size with update_height
105
- def update_size(self, new_size):
106
- """Kept for compatibility, redirects to update_height."""
107
- self.update_height(new_size)
108
-
109
- def set_selected(self, selected):
110
- """Set the selection state and update visual appearance."""
111
- was_selected = self.is_selected()
112
-
113
- # Update the shared data item
114
- self.data_item.set_selected(selected)
115
-
116
- # Start or stop the animation timer based on the new selection state
117
- if selected:
118
- if not self.animation_timer.isActive():
119
- self.animation_timer.start()
120
- else:
121
- if self.animation_timer.isActive():
122
- self.animation_timer.stop()
123
- # Reset offset when deselected to ensure a consistent starting look
124
- self.animation_offset = 0
125
-
126
- # A repaint is needed if the selection state changed OR if the item remains
127
- # selected (to keep the animation running).
128
- if was_selected != selected or selected:
129
- self.update()
130
-
131
- def is_selected(self):
132
- """Return whether this widget is selected via the data item."""
133
- return self.data_item.is_selected
134
-
135
- def _update_animation_frame(self):
136
- """Update the animation offset and schedule a repaint."""
137
- self.animation_offset = (self.animation_offset + 1) % 20
138
- self.update()
139
-
140
- def paintEvent(self, event):
141
- """Handle custom drawing for the widget, including the border."""
142
- super().paintEvent(event)
143
- painter = QPainter(self)
144
- painter.setRenderHint(QPainter.Antialiasing)
145
-
146
- # Get the label that is currently active (which could be a preview)
147
- effective_label = self.data_item.effective_label
148
-
149
- # Check if the active label is the special "Review" label (id == "-1")
150
- if effective_label and effective_label.id == "-1":
151
- # If it is, ALWAYS use a black pen for visibility against the white background.
152
- pen_color = QColor("black")
153
- else:
154
- # Otherwise, use the effective color from the data item.
155
- pen_color = self.data_item.effective_color
156
-
157
- if self.is_selected():
158
- pen = QPen(pen_color, ANNOTATION_WIDTH)
159
- pen.setStyle(Qt.CustomDashLine)
160
- pen.setDashPattern([2, 3])
161
- pen.setDashOffset(self.animation_offset)
162
- else:
163
- pen = QPen(pen_color, ANNOTATION_WIDTH)
164
- pen.setStyle(Qt.SolidLine)
165
-
166
- painter.setPen(pen)
167
- painter.setBrush(Qt.NoBrush)
168
-
169
- width = pen.width()
170
- half_width = (width - 1) // 2
171
- rect = self.rect().adjusted(half_width, half_width, -half_width, -half_width)
172
- painter.drawRect(rect)
173
-
174
- def mousePressEvent(self, event):
175
- """Handle mouse press events for selection."""
176
- if event.button() == Qt.LeftButton:
177
- if self.annotation_viewer and hasattr(self.annotation_viewer, 'handle_annotation_selection'):
178
- self.annotation_viewer.handle_annotation_selection(self, event)
179
- # Ignore right mouse button clicks - don't call super() to prevent any selection
180
- elif event.button() == Qt.RightButton:
181
- event.ignore()
182
- return
183
- super().mousePressEvent(event)
@@ -1,30 +0,0 @@
1
- import warnings
2
-
3
- from PyQt5.QtWidgets import QGraphicsEllipseItem, QStyle
4
-
5
- warnings.filterwarnings("ignore", category=DeprecationWarning)
6
-
7
-
8
- # ----------------------------------------------------------------------------------------------------------------------
9
- # Classes
10
- # ----------------------------------------------------------------------------------------------------------------------
11
-
12
-
13
- class EmbeddingPointItem(QGraphicsEllipseItem):
14
- """
15
- A custom QGraphicsEllipseItem that prevents the default selection
16
- rectangle from being drawn, and dynamically gets its color from the
17
- shared AnnotationDataItem.
18
- """
19
-
20
- def paint(self, painter, option, widget):
21
- # Get the shared data item, which holds the current state
22
- data_item = self.data(0)
23
- if data_item:
24
- # Set the brush color based on the item's effective color
25
- # This ensures preview colors are reflected instantly.
26
- self.setBrush(data_item.effective_color)
27
-
28
- # Remove the 'State_Selected' flag to prevent the default box
29
- option.state &= ~QStyle.State_Selected
30
- super(EmbeddingPointItem, self).paint(painter, option, widget)