Skip to content

Commit 0d84868

Browse files
committed
refactor: more properties
1 parent ed0a9c0 commit 0d84868

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/mpl_image_segmenter/_segmenter.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,23 @@ def __init__( # type: ignore
143143
self._pm = PanManager(self.fig, button=pan_mousebutton)
144144
self.disconnect_zoom = zoom_factory(self.ax)
145145
self.current_class = 1
146-
self.erasing = False
146+
self._erasing = False
147147
self._paths: dict[str, list[Path]] = {"adding": [], "erasing": []}
148148

149149
@property
150150
def panmanager(self) -> PanManager:
151151
return self._pm
152152

153+
@property
154+
def erasing(self) -> bool:
155+
return self._erasing
156+
157+
@erasing.setter
158+
def erasing(self, val: bool) -> None:
159+
if not isinstance(val, bool):
160+
raise TypeError(f"Erasing must be a bool - got type {type(val)}")
161+
self._erasing = val
162+
153163
def get_paths(self) -> dict[str, list[Path]]:
154164
"""
155165
Get a dictionary of all the paths used to create the mask.
@@ -164,7 +174,7 @@ def get_paths(self) -> dict[str, list[Path]]:
164174
def _onselect(self, verts: Any) -> None:
165175
p = Path(verts)
166176
self.indices = p.contains_points(self.pix, radius=0).reshape(self.mask.shape)
167-
if self.erasing:
177+
if self._erasing:
168178
self.mask[self.indices] = 0
169179
self._overlay[self.indices] = [0, 0, 0, 0]
170180
self._paths["erasing"].append(p)

0 commit comments

Comments
 (0)