Skip to content

Commit 0a7da70

Browse files
committed
Sync point-size to config immediately
Remove debounced/pending write machinery and write point-size to config immediately when committing. Deleted the QTimer, _pending_config_point_size_write attribute, and _flush_pending_point_size_config_write method. _commit_active_points_size_to_config now calls save_point_size_to_config directly, reports success via viewer.status, and logs failures; related scheduling code in the size setter was removed. This simplifies point-size persistence and improves error handling.
1 parent 8a23fcd commit 0a7da70

1 file changed

Lines changed: 6 additions & 32 deletions

File tree

src/napari_deeplabcut/_widgets.py

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,6 @@ def _close_event(event):
265265
self._layer_status_panel.point_size_commit_requested.connect(self._commit_active_points_size_to_config)
266266
self._layout.addWidget(self._layer_status_panel)
267267

268-
self._pending_config_point_size_write: tuple[Path, int] | None = None
269-
self._config_point_size_write_timer = QTimer(self)
270-
self._config_point_size_write_timer.setSingleShot(True)
271-
self._config_point_size_write_timer.setInterval(350) # lightweight debounce
272-
self._config_point_size_write_timer.timeout.connect(self._flush_pending_point_size_config_write)
273-
274268
self._layout.addLayout(grid)
275269

276270
# form buttons for selection of annotation mode
@@ -1036,16 +1030,6 @@ def _on_active_points_size_changed(self, size: int) -> None:
10361030
set_uniform_point_size(layer, size)
10371031
mark_layer_presentation_changed(layer)
10381032

1039-
config_path = self._resolve_config_path_for_layer(layer)
1040-
if config_path is not None:
1041-
self._pending_config_point_size_write = (config_path, int(size))
1042-
self._config_point_size_write_timer.start()
1043-
else:
1044-
logger.debug(
1045-
"No config.yaml could be resolved for active layer %r",
1046-
getattr(layer, "name", layer),
1047-
)
1048-
10491033
def _commit_active_points_size_to_config(self, size: int) -> None:
10501034
layer = self._current_dlc_points_layer()
10511035
if layer is None:
@@ -1059,8 +1043,12 @@ def _commit_active_points_size_to_config(self, size: int) -> None:
10591043
)
10601044
return
10611045

1062-
self._pending_config_point_size_write = (config_path, int(size))
1063-
self._flush_pending_point_size_config_write()
1046+
try:
1047+
changed = save_point_size_to_config(config_path, int(size))
1048+
if changed:
1049+
self.viewer.status = f"Updated config dotsize to {int(size)}"
1050+
except Exception:
1051+
logger.debug("Failed to sync point size to config", exc_info=True)
10641052

10651053
def _maybe_initialize_layer_point_size_from_config(self, layer: Points) -> None:
10661054
config_path = self._resolve_config_path_for_layer(layer)
@@ -1081,20 +1069,6 @@ def _maybe_initialize_layer_point_size_from_config(self, layer: Points) -> None:
10811069
except Exception:
10821070
logger.debug("Could not initialize layer point size from config", exc_info=True)
10831071

1084-
def _flush_pending_point_size_config_write(self) -> None:
1085-
pending = self._pending_config_point_size_write
1086-
self._pending_config_point_size_write = None
1087-
if pending is None:
1088-
return
1089-
1090-
config_path, size = pending
1091-
try:
1092-
changed = save_point_size_to_config(config_path, size)
1093-
if changed:
1094-
self.viewer.status = f"Updated config dotsize to {size}"
1095-
except Exception:
1096-
logger.debug("Failed to sync point size to config", exc_info=True)
1097-
10981072
def _connect_layer_status_events(self, layer: Points) -> None:
10991073
"""
11001074
Keep the UX panel live without adding heavy watchers.

0 commit comments

Comments
 (0)