lazylabel-gui 1.0.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Deniz N. Cakan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,147 @@
1
+ Metadata-Version: 2.4
2
+ Name: lazylabel-gui
3
+ Version: 1.0.0
4
+ Summary: An image segmentation GUI for generating mask tensors.
5
+ Author-email: "Deniz N. Cakan" <deniz.n.cakan@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Deniz N. Cakan
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/dnzckn/lazylabel
29
+ Project-URL: Bug Tracker, https://github.com/dnzckn/lazylabel/issues
30
+ Classifier: Programming Language :: Python :: 3
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Operating System :: OS Independent
33
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
34
+ Classifier: Environment :: X11 Applications :: Qt
35
+ Requires-Python: >=3.10
36
+ Description-Content-Type: text/markdown
37
+ License-File: LICENSE
38
+ Requires-Dist: PyQt6>=6.9.0
39
+ Requires-Dist: pyqtdarktheme==2.1.0
40
+ Requires-Dist: torch>=2.7.1
41
+ Requires-Dist: torchvision>=0.22.1
42
+ Requires-Dist: segment-anything==1.0
43
+ Requires-Dist: numpy>=2.3.0
44
+ Requires-Dist: opencv-python>=4.11.0.86
45
+ Requires-Dist: scipy>=1.15.3
46
+ Requires-Dist: requests>=2.32.4
47
+ Requires-Dist: tqdm>=4.67.1
48
+ Dynamic: license-file
49
+
50
+ # <img src="https://raw.githubusercontent.com/dnzckn/LazyLabel/main/src/lazylabel/demo_pictures/logo2.png" alt="LazyLabel Logo" style="height:60px; vertical-align:middle;" /> <img src="https://raw.githubusercontent.com/dnzckn/LazyLabel/main/src/lazylabel/demo_pictures/logo_black.png" alt="LazyLabel Cursive" style="height:60px; vertical-align:middle;" />
51
+ LazyLabel is an intuitive, AI-assisted image segmentation tool. It uses Meta's Segment Anything Model (SAM) for quick, precise mask generation, alongside advanced polygon editing for fine-tuned control. Outputs are saved in a clean, one-hot encoded format for easy machine learning integration.
52
+
53
+ Inspired by [LabelMe](https://github.com/wkentaro/labelme?tab=readme-ov-file#installation) and [Segment-Anything-UI](https://github.com/branislavhesko/segment-anything-ui/tree/main).
54
+
55
+ ![LazyLabel Screenshot](https://raw.githubusercontent.com/dnzckn/LazyLabel/main/src/lazylabel/demo_pictures/gui.PNG)
56
+
57
+ ---
58
+
59
+ ## ✨ Core Features
60
+
61
+ * **AI-Powered Segmentation**: Generate masks with simple left-click (positive) and right-click (negative) interactions.
62
+ * **Vector Polygon Tool**: Full control to draw, edit, and reshape polygons. Drag vertices or move entire shapes.
63
+ * **Advanced Class Management**: Assign multiple segments to a single class ID for organized labeling.
64
+ * **Intuitive Editing & Refinement**: Select, merge, and re-order segments.
65
+ * **Interactive UI**: Color-coded segments, sortable lists, and hover highlighting.
66
+ * **Smart I/O**: Loads existing `.npz` masks; saves work as clean, one-hot encoded outputs.
67
+
68
+ ---
69
+
70
+ ## 🚀 Getting Started
71
+
72
+ ### Prerequisites
73
+ Ensure you have **Python 3.10** or newer.
74
+
75
+ ### Installation
76
+
77
+ #### For Users (via PyPI)
78
+ 1. Install LazyLabel directly:
79
+ ```bash
80
+ pip install lazylabel-gui
81
+ ```
82
+ 2. Run the application:
83
+ ```bash
84
+ lazylabel-gui
85
+ ```
86
+
87
+ #### For Developers (from Source)
88
+ 1. Clone the repository:
89
+ ```bash
90
+ git clone [https://github.com/dnzckn/LazyLabel.git](https://github.com/dnzckn/LazyLabel.git)
91
+ cd LazyLabel
92
+ ```
93
+ 2. Install in editable mode, which links the installed package to your source directory:
94
+ ```bash
95
+ pip install -e .
96
+ ```
97
+ 3. Run the application:
98
+ ```bash
99
+ lazylabel-gui
100
+ ```
101
+
102
+ **Note**: On the first run, the application will automatically download the SAM model checkpoint (~2.5 GB) from Meta's repository to a local cache. This is a one-time download.
103
+
104
+ ---
105
+
106
+ ## ⌨️ Controls & Keybinds
107
+
108
+ ### Modes
109
+ | Key | Action |
110
+ |---|---|
111
+ | `1` | Enter **Point Mode** (for AI segmentation). |
112
+ | `2` | Enter **Polygon Drawing Mode**. |
113
+ | `E` | Toggle **Selection Mode** to select existing segments. |
114
+ | `R` | Enter **Edit Mode** for selected polygons (drag shape or vertices). |
115
+ | `Q` | Toggle **Pan Mode** (click and drag the image). |
116
+
117
+ ### Actions
118
+ | Key(s) | Action |
119
+ |---|---|
120
+ | `L-Click` | Add positive point (Point Mode) or polygon vertex. |
121
+ | `R-Click` | Add negative point (Point Mode). |
122
+ | `Ctrl + Z` | Undo last point. |
123
+ | `Spacebar` | Finalize and save current AI segment. |
124
+ | `Enter` | **Save final mask for the current image to a `.npz` file.** |
125
+ | `M` | **Merge** selected segments into a single class. |
126
+ | `V` / `Delete` / `Backspace`| **Delete** selected segments. |
127
+ | `C` | Clear temporary points/vertices. |
128
+ | `W/A/S/D` | Pan image. |
129
+ | `Scroll Wheel` | Zoom-in or -out. |
130
+
131
+ ---
132
+
133
+ ## 📦 Output Format
134
+
135
+ LazyLabel saves your work as a compressed NumPy array (`.npz`) with the same name as your image file.
136
+
137
+ The file contains a single data key, `'mask'`, holding a **one-hot encoded tensor** with the shape `(H, W, C)`:
138
+ * `H`: Image height.
139
+ * `W`: Image width.
140
+ * `C`: Total unique classes.
141
+
142
+ Each channel is a binary mask for a class, combining all assigned segments into a clean, ML-ready output.
143
+
144
+ ---
145
+
146
+ ## ☕ Support LazyLabel
147
+ [If you found LazyLabel helpful, consider supporting the project!](https://buymeacoffee.com/dnzckn)
@@ -0,0 +1,98 @@
1
+ # <img src="https://raw.githubusercontent.com/dnzckn/LazyLabel/main/src/lazylabel/demo_pictures/logo2.png" alt="LazyLabel Logo" style="height:60px; vertical-align:middle;" /> <img src="https://raw.githubusercontent.com/dnzckn/LazyLabel/main/src/lazylabel/demo_pictures/logo_black.png" alt="LazyLabel Cursive" style="height:60px; vertical-align:middle;" />
2
+ LazyLabel is an intuitive, AI-assisted image segmentation tool. It uses Meta's Segment Anything Model (SAM) for quick, precise mask generation, alongside advanced polygon editing for fine-tuned control. Outputs are saved in a clean, one-hot encoded format for easy machine learning integration.
3
+
4
+ Inspired by [LabelMe](https://github.com/wkentaro/labelme?tab=readme-ov-file#installation) and [Segment-Anything-UI](https://github.com/branislavhesko/segment-anything-ui/tree/main).
5
+
6
+ ![LazyLabel Screenshot](https://raw.githubusercontent.com/dnzckn/LazyLabel/main/src/lazylabel/demo_pictures/gui.PNG)
7
+
8
+ ---
9
+
10
+ ## ✨ Core Features
11
+
12
+ * **AI-Powered Segmentation**: Generate masks with simple left-click (positive) and right-click (negative) interactions.
13
+ * **Vector Polygon Tool**: Full control to draw, edit, and reshape polygons. Drag vertices or move entire shapes.
14
+ * **Advanced Class Management**: Assign multiple segments to a single class ID for organized labeling.
15
+ * **Intuitive Editing & Refinement**: Select, merge, and re-order segments.
16
+ * **Interactive UI**: Color-coded segments, sortable lists, and hover highlighting.
17
+ * **Smart I/O**: Loads existing `.npz` masks; saves work as clean, one-hot encoded outputs.
18
+
19
+ ---
20
+
21
+ ## 🚀 Getting Started
22
+
23
+ ### Prerequisites
24
+ Ensure you have **Python 3.10** or newer.
25
+
26
+ ### Installation
27
+
28
+ #### For Users (via PyPI)
29
+ 1. Install LazyLabel directly:
30
+ ```bash
31
+ pip install lazylabel-gui
32
+ ```
33
+ 2. Run the application:
34
+ ```bash
35
+ lazylabel-gui
36
+ ```
37
+
38
+ #### For Developers (from Source)
39
+ 1. Clone the repository:
40
+ ```bash
41
+ git clone [https://github.com/dnzckn/LazyLabel.git](https://github.com/dnzckn/LazyLabel.git)
42
+ cd LazyLabel
43
+ ```
44
+ 2. Install in editable mode, which links the installed package to your source directory:
45
+ ```bash
46
+ pip install -e .
47
+ ```
48
+ 3. Run the application:
49
+ ```bash
50
+ lazylabel-gui
51
+ ```
52
+
53
+ **Note**: On the first run, the application will automatically download the SAM model checkpoint (~2.5 GB) from Meta's repository to a local cache. This is a one-time download.
54
+
55
+ ---
56
+
57
+ ## ⌨️ Controls & Keybinds
58
+
59
+ ### Modes
60
+ | Key | Action |
61
+ |---|---|
62
+ | `1` | Enter **Point Mode** (for AI segmentation). |
63
+ | `2` | Enter **Polygon Drawing Mode**. |
64
+ | `E` | Toggle **Selection Mode** to select existing segments. |
65
+ | `R` | Enter **Edit Mode** for selected polygons (drag shape or vertices). |
66
+ | `Q` | Toggle **Pan Mode** (click and drag the image). |
67
+
68
+ ### Actions
69
+ | Key(s) | Action |
70
+ |---|---|
71
+ | `L-Click` | Add positive point (Point Mode) or polygon vertex. |
72
+ | `R-Click` | Add negative point (Point Mode). |
73
+ | `Ctrl + Z` | Undo last point. |
74
+ | `Spacebar` | Finalize and save current AI segment. |
75
+ | `Enter` | **Save final mask for the current image to a `.npz` file.** |
76
+ | `M` | **Merge** selected segments into a single class. |
77
+ | `V` / `Delete` / `Backspace`| **Delete** selected segments. |
78
+ | `C` | Clear temporary points/vertices. |
79
+ | `W/A/S/D` | Pan image. |
80
+ | `Scroll Wheel` | Zoom-in or -out. |
81
+
82
+ ---
83
+
84
+ ## 📦 Output Format
85
+
86
+ LazyLabel saves your work as a compressed NumPy array (`.npz`) with the same name as your image file.
87
+
88
+ The file contains a single data key, `'mask'`, holding a **one-hot encoded tensor** with the shape `(H, W, C)`:
89
+ * `H`: Image height.
90
+ * `W`: Image width.
91
+ * `C`: Total unique classes.
92
+
93
+ Each channel is a binary mask for a class, combining all assigned segments into a clean, ML-ready output.
94
+
95
+ ---
96
+
97
+ ## ☕ Support LazyLabel
98
+ [If you found LazyLabel helpful, consider supporting the project!](https://buymeacoffee.com/dnzckn)
@@ -0,0 +1,40 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "lazylabel-gui"
7
+ version = "1.0.0"
8
+ authors = [
9
+ { name="Deniz N. Cakan", email="deniz.n.cakan@gmail.com" },
10
+ ]
11
+ description = "An image segmentation GUI for generating mask tensors."
12
+ readme = "README.md"
13
+ license = { file="LICENSE" }
14
+ requires-python = ">=3.10"
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ "Topic :: Scientific/Engineering :: Image Processing",
20
+ "Environment :: X11 Applications :: Qt",
21
+ ]
22
+ dependencies = [
23
+ "PyQt6>=6.9.0",
24
+ "pyqtdarktheme==2.1.0",
25
+ "torch>=2.7.1",
26
+ "torchvision>=0.22.1",
27
+ "segment-anything==1.0",
28
+ "numpy>=2.3.0",
29
+ "opencv-python>=4.11.0.86",
30
+ "scipy>=1.15.3",
31
+ "requests>=2.32.4",
32
+ "tqdm>=4.67.1"
33
+ ]
34
+
35
+ [project.urls]
36
+ "Homepage" = "https://github.com/dnzckn/lazylabel"
37
+ "Bug Tracker" = "https://github.com/dnzckn/lazylabel/issues"
38
+
39
+ [project.scripts]
40
+ lazylabel-gui = "lazylabel.main:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,108 @@
1
+ from PyQt6.QtWidgets import (
2
+ QWidget,
3
+ QVBoxLayout,
4
+ QPushButton,
5
+ QLabel,
6
+ QFrame,
7
+ QTableWidget,
8
+ QTreeView,
9
+ QAbstractItemView,
10
+ QHBoxLayout,
11
+ QComboBox,
12
+ QHeaderView,
13
+ )
14
+ from PyQt6.QtCore import Qt
15
+ from .reorderable_class_table import ReorderableClassTable
16
+
17
+
18
+ class ControlPanel(QWidget):
19
+ def __init__(self, parent=None):
20
+ super().__init__(parent)
21
+ layout = QVBoxLayout(self)
22
+ layout.setAlignment(Qt.AlignmentFlag.AlignTop)
23
+ self.mode_label = QLabel("Mode: Points")
24
+ font = self.mode_label.font()
25
+ font.setPointSize(14)
26
+ font.setBold(True)
27
+ self.mode_label.setFont(font)
28
+ layout.addWidget(self.mode_label)
29
+ self.btn_sam_mode = QPushButton("Point Mode (1)")
30
+ self.btn_polygon_mode = QPushButton("Polygon Mode (2)")
31
+ self.btn_selection_mode = QPushButton("Selection Mode (E)")
32
+ layout.addWidget(self.btn_sam_mode)
33
+ layout.addWidget(self.btn_polygon_mode)
34
+ layout.addWidget(self.btn_selection_mode)
35
+ layout.addSpacing(20)
36
+ line1 = QFrame()
37
+ line1.setFrameShape(QFrame.Shape.HLine)
38
+ layout.addWidget(line1)
39
+ layout.addSpacing(10)
40
+ self.btn_clear_points = QPushButton("Clear Clicks (C)")
41
+ layout.addWidget(self.btn_clear_points)
42
+ layout.addStretch()
43
+ self.device_label = QLabel("Device: Unknown")
44
+ layout.addWidget(self.device_label)
45
+ self.setFixedWidth(250)
46
+
47
+
48
+ class RightPanel(QWidget):
49
+ def __init__(self, parent=None):
50
+ super().__init__(parent)
51
+ layout = QVBoxLayout(self)
52
+
53
+ # File Explorer
54
+ file_explorer_layout = QVBoxLayout()
55
+ self.btn_open_folder = QPushButton("Open Image Folder")
56
+ self.file_tree = QTreeView()
57
+ file_explorer_layout.addWidget(self.btn_open_folder)
58
+ file_explorer_layout.addWidget(self.file_tree)
59
+ layout.addLayout(file_explorer_layout)
60
+
61
+ # Status Label
62
+ self.status_label = QLabel("")
63
+ self.status_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
64
+ layout.addWidget(self.status_label)
65
+
66
+ # Segment Table
67
+ segment_layout = QVBoxLayout()
68
+ class_filter_layout = QHBoxLayout()
69
+ class_filter_layout.addWidget(QLabel("Filter Class:"))
70
+ self.class_filter_combo = QComboBox()
71
+ class_filter_layout.addWidget(self.class_filter_combo)
72
+ segment_layout.addLayout(class_filter_layout)
73
+
74
+ self.segment_table = QTableWidget()
75
+ self.segment_table.setColumnCount(3)
76
+ self.segment_table.setHorizontalHeaderLabels(["Index", "Class", "Type"])
77
+ self.segment_table.horizontalHeader().setSectionResizeMode(
78
+ QHeaderView.ResizeMode.Stretch
79
+ )
80
+ self.segment_table.setSelectionBehavior(
81
+ QAbstractItemView.SelectionBehavior.SelectRows
82
+ )
83
+ self.segment_table.setSortingEnabled(True)
84
+ segment_layout.addWidget(self.segment_table)
85
+
86
+ segment_action_layout = QHBoxLayout()
87
+ self.btn_merge_selection = QPushButton("Merge to Class")
88
+ self.btn_delete_selection = QPushButton("Delete")
89
+ segment_action_layout.addWidget(self.btn_merge_selection)
90
+ segment_action_layout.addWidget(self.btn_delete_selection)
91
+ segment_layout.addLayout(segment_action_layout)
92
+ layout.addLayout(segment_layout, 2)
93
+
94
+ # Class Table
95
+ class_layout = QVBoxLayout()
96
+ class_layout.addWidget(QLabel("Class Order:"))
97
+ self.class_table = ReorderableClassTable()
98
+ self.class_table.setColumnCount(1)
99
+ self.class_table.setHorizontalHeaderLabels(["Class ID"])
100
+ self.class_table.horizontalHeader().setSectionResizeMode(
101
+ QHeaderView.ResizeMode.Stretch
102
+ )
103
+ class_layout.addWidget(self.class_table)
104
+ self.btn_reassign_classes = QPushButton("Reassign Class IDs")
105
+ class_layout.addWidget(self.btn_reassign_classes)
106
+ layout.addLayout(class_layout, 1)
107
+
108
+ self.setFixedWidth(350)
@@ -0,0 +1,57 @@
1
+ import os
2
+ from PyQt6.QtCore import Qt, QModelIndex, QDir
3
+ from PyQt6.QtGui import QFileSystemModel, QBrush, QColor
4
+
5
+
6
+ class CustomFileSystemModel(QFileSystemModel):
7
+ def __init__(self, parent=None):
8
+ super().__init__(parent)
9
+ self.setFilter(QDir.Filter.NoDotAndDotDot | QDir.Filter.Files)
10
+ self.setNameFilterDisables(False)
11
+ self.setNameFilters(["*.png", "*.jpg", "*.jpeg", "*.tiff"])
12
+ self.highlighted_path = None
13
+
14
+ def set_highlighted_path(self, path):
15
+ self.highlighted_path = path
16
+
17
+ def columnCount(self, parent: QModelIndex = QModelIndex()) -> int:
18
+ return 2
19
+
20
+ def headerData(
21
+ self,
22
+ section: int,
23
+ orientation: Qt.Orientation,
24
+ role: int = Qt.ItemDataRole.DisplayRole,
25
+ ):
26
+ if (
27
+ orientation == Qt.Orientation.Horizontal
28
+ and role == Qt.ItemDataRole.DisplayRole
29
+ ):
30
+ if section == 0:
31
+ return "File Name"
32
+ if section == 1:
33
+ return "Mask"
34
+ return super().headerData(section, orientation, role)
35
+
36
+ def data(self, index: QModelIndex, role: int = Qt.ItemDataRole.DisplayRole):
37
+ if not index.isValid():
38
+ return None
39
+
40
+ # Handle the temporary highlight for saving
41
+ if role == Qt.ItemDataRole.BackgroundRole:
42
+ filePath = self.filePath(index)
43
+ if filePath == self.highlighted_path:
44
+ return QBrush(QColor("yellow"))
45
+
46
+ if index.column() == 1:
47
+ if role == Qt.ItemDataRole.CheckStateRole:
48
+ filePath = self.filePath(index.siblingAtColumn(0))
49
+ mask_path = os.path.splitext(filePath)[0] + ".npz"
50
+ return (
51
+ Qt.CheckState.Checked
52
+ if os.path.exists(mask_path)
53
+ else Qt.CheckState.Unchecked
54
+ )
55
+ return None
56
+
57
+ return super().data(index, role)
@@ -0,0 +1,25 @@
1
+ from PyQt6.QtWidgets import QGraphicsEllipseItem, QGraphicsItem
2
+ from PyQt6.QtCore import Qt
3
+ from PyQt6.QtGui import QBrush, QPen
4
+
5
+
6
+ class EditableVertexItem(QGraphicsEllipseItem):
7
+ def __init__(self, main_window, segment_index, vertex_index, x, y, w, h):
8
+ super().__init__(x, y, w, h)
9
+ self.main_window = main_window
10
+ self.segment_index = segment_index
11
+ self.vertex_index = vertex_index
12
+
13
+ self.setZValue(200)
14
+ self.setBrush(QBrush(Qt.GlobalColor.cyan))
15
+ self.setPen(QPen(Qt.GlobalColor.white, 1))
16
+ self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsMovable)
17
+ self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemSendsGeometryChanges)
18
+
19
+ def itemChange(self, change, value):
20
+ if change == QGraphicsItem.GraphicsItemChange.ItemPositionHasChanged:
21
+ new_pos = value
22
+ self.main_window.update_vertex_pos(
23
+ self.segment_index, self.vertex_index, new_pos
24
+ )
25
+ return super().itemChange(change, value)
@@ -0,0 +1,23 @@
1
+ from PyQt6.QtWidgets import QGraphicsPolygonItem
2
+ from PyQt6.QtGui import QBrush
3
+
4
+
5
+ class HoverablePolygonItem(QGraphicsPolygonItem):
6
+ def __init__(self, polygon, parent=None):
7
+ super().__init__(polygon, parent)
8
+ self.setAcceptHoverEvents(True)
9
+ self.default_brush = QBrush()
10
+ self.hover_brush = QBrush()
11
+
12
+ def set_brushes(self, default_brush, hover_brush):
13
+ self.default_brush = default_brush
14
+ self.hover_brush = hover_brush
15
+ self.setBrush(self.default_brush)
16
+
17
+ def hoverEnterEvent(self, event):
18
+ self.setBrush(self.hover_brush)
19
+ super().hoverEnterEvent(event)
20
+
21
+ def hoverLeaveEvent(self, event):
22
+ self.setBrush(self.default_brush)
23
+ super().hoverLeaveEvent(event)