Skip to content

Commit c684a48

Browse files
committed
Fix: enhance refresh_plot method to include options for only_visible and only_existing items
Fix #161
1 parent b1660b2 commit c684a48

File tree

7 files changed

+107
-35
lines changed

7 files changed

+107
-35
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ See DataLab [roadmap page](https://datalab-platform.com/en/contributing/roadmap.
1616
* Fixed [Issue #158](https://github.com./DataLab-Platform/DataLab/issues/158) - When editing ROI of a list of images, the first image of the selection is shown (instead of the last as in the image panel)
1717
* Fixed [Issue #159](https://github.com./DataLab-Platform/DataLab/issues/159) - When selecting multiple images just after opening an HDF5 file, the "View in a new window" feature does not work (`KeyError` exception)
1818
* Fixed [Issue #160](https://github.com./DataLab-Platform/DataLab/issues/160) - When selecting multiple images and clearing ROI in ROI editor, only the first image is affected
19+
* Fixed [Issue #161](https://github.com./DataLab-Platform/DataLab/issues/161) - Refresh image items only if necessary (when editing ROI, pasting/deleting metadata)
1920

2021
## DataLab Version 0.19.0 ##
2122

cdl/core/gui/panel/base.py

+30-13
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class BaseDataPanel(AbstractPanel, Generic[TypeObj, TypeROI, TypeROIEditor]):
280280
IO_REGISTRY: SignalIORegistry | ImageIORegistry | None = None
281281
SIG_STATUS_MESSAGE = QC.Signal(str) # emitted by "qt_try_except" decorator
282282
SIG_REFRESH_PLOT = QC.Signal(
283-
str, bool, bool
283+
str, bool, bool, bool, bool
284284
) # Connected to PlotHandler.refresh_plot
285285
ROIDIALOGOPTIONS = {}
286286

@@ -475,10 +475,14 @@ def setup_panel(self) -> None:
475475
self.add_objprop_buttons()
476476

477477
def refresh_plot(
478-
self, what: str, update_items: bool = True, force: bool = False
478+
self,
479+
what: str,
480+
update_items: bool = True,
481+
force: bool = False,
482+
only_visible: bool = True,
483+
only_existing: bool = False,
479484
) -> None:
480-
"""Refresh plot. This method simply emits the signal SIG_REFRESH_PLOT which is
481-
connected to the method `PlotHandler.refresh_plot`.
485+
"""Refresh plot.
482486
483487
Args:
484488
what: string describing the objects to refresh.
@@ -489,17 +493,26 @@ def refresh_plot(
489493
If False, only show the items (do not update them, except if the
490494
option "Use reference item LUT range" is enabled and more than one
491495
item is selected). Defaults to True.
492-
force: if True, force refresh even if auto refresh is disabled,
493-
and refresh all items associated to objects (even the hidden ones, e.g.
494-
when selecting multiple images of the same size and position). Defaults
495-
to False.
496+
force: if True, force refresh even if auto refresh is disabled.
497+
Defaults to False.
498+
only_visible: if True, only refresh visible items. Defaults to True.
499+
Visible items are the ones that are not hidden by other items or the items
500+
except the first one if the option "Show first only" is enabled.
501+
This is useful for images, where the last image is the one that is shown.
502+
If False, all items are refreshed.
503+
only_existing: if True, only refresh existing items. Defaults to False.
504+
Existing items are the ones that have already been created and are
505+
associated to the object uuid. If False, create new items for the
506+
objects that do not have an item yet.
496507
497508
Raises:
498509
ValueError: if `what` is not a valid value
499510
"""
500511
if what not in ("selected", "all", "existing") and not isinstance(what, str):
501512
raise ValueError(f"Invalid value for 'what': {what}")
502-
self.SIG_REFRESH_PLOT.emit(what, update_items, force)
513+
self.SIG_REFRESH_PLOT.emit(
514+
what, update_items, force, only_visible, only_existing
515+
)
503516

504517
def manual_refresh(self) -> None:
505518
"""Manual refresh"""
@@ -622,10 +635,12 @@ def paste_metadata(self, param: PasteMetadataParam | None = None) -> None:
622635
sel_objects = self.objview.get_sel_objects(include_groups=True)
623636
for obj in sorted(sel_objects, key=lambda obj: obj.short_id, reverse=True):
624637
obj.update_metadata_from(metadata)
625-
# We have to do a manual refresh in order to force the plot handler to update
638+
# We have to do a special refresh in order to force the plot handler to update
626639
# all plot items, even the ones that are not visible (otherwise, image masks
627640
# would not be updated after pasting the metadata: see issue #123)
628-
self.manual_refresh()
641+
self.refresh_plot(
642+
"selected", update_items=True, only_visible=False, only_existing=True
643+
)
629644

630645
def remove_object(self, force: bool = False) -> None:
631646
"""Remove signal/image object
@@ -716,11 +731,13 @@ def delete_metadata(
716731
if index == 0:
717732
self.selection_changed()
718733
if refresh_plot:
719-
# We have to do a manual refresh in order to force the plot handler to
734+
# We have to do a special refresh in order to force the plot handler to
720735
# update all plot items, even the ones that are not visible (otherwise,
721736
# image masks would remained visible after deleting the ROI for example:
722737
# see issue #122)
723-
self.manual_refresh()
738+
self.refresh_plot(
739+
"selected", update_items=True, only_visible=False, only_existing=True
740+
)
724741

725742
def add_annotations_from_items(
726743
self, items: list, refresh_plot: bool = True

cdl/core/gui/plothandler.py

+46-13
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __getitem__(self, oid: str) -> TypePlotItem:
9999
# (object has been added to model but the corresponding plot item has not
100100
# been created yet)
101101
if not self.__auto_refresh:
102-
self.refresh_plot("selected", True, force=True)
102+
self.refresh_plot(oid, True, force=True, only_visible=False)
103103
return self.__plotitems[oid]
104104
# Item does not exist and auto refresh is enabled: this should not happen
105105
raise exc
@@ -282,7 +282,12 @@ def reduce_shown_oids(self, oids: list[str]) -> list[str]:
282282
return oids
283283

284284
def refresh_plot(
285-
self, what: str, update_items: bool = True, force: bool = False
285+
self,
286+
what: str,
287+
update_items: bool = True,
288+
force: bool = False,
289+
only_visible: bool = True,
290+
only_existing: bool = False,
286291
) -> None:
287292
"""Refresh plot.
288293
@@ -295,10 +300,17 @@ def refresh_plot(
295300
If False, only show the items (do not update them, except if the
296301
option "Use reference item LUT range" is enabled and more than one
297302
item is selected). Defaults to True.
298-
force: if True, force refresh even if auto refresh is disabled,
299-
and refresh all items associated to objects (even the hidden ones, e.g.
300-
when selecting multiple images of the same size and position). Defaults
301-
to False.
303+
force: if True, force refresh even if auto refresh is disabled.
304+
Defaults to False.
305+
only_visible: if True, only refresh visible items. Defaults to True.
306+
Visible items are the ones that are not hidden by other items or the items
307+
except the first one if the option "Show first only" is enabled.
308+
This is useful for images, where the last image is the one that is shown.
309+
If False, all items are refreshed.
310+
only_existing: if True, only refresh existing items. Defaults to False.
311+
Existing items are the ones that have already been created and are
312+
associated to the object uuid. If False, create new items for the
313+
objects that do not have an item yet.
302314
303315
Raises:
304316
ValueError: if `what` is not a valid value
@@ -344,7 +356,8 @@ def refresh_plot(
344356
scales_dict = {}
345357

346358
if oids:
347-
if what != "existing" and not force:
359+
if what != "existing" and only_visible:
360+
# Remove hidden items from the list of objects to refresh
348361
oids = self.reduce_shown_oids(oids)
349362
ref_item = None
350363
with create_progress_bar(
@@ -377,6 +390,8 @@ def refresh_plot(
377390
# Update or add item to plot
378391
item = self.get(oid)
379392
if item is None:
393+
if only_existing:
394+
continue
380395
item = self.__add_item_to_plot(oid)
381396
else:
382397
self.__update_item_on_plot(
@@ -536,7 +551,12 @@ def reduce_shown_oids(self, oids: list[str]) -> list[str]:
536551
return oids
537552

538553
def refresh_plot(
539-
self, what: str, update_items: bool = True, force: bool = False
554+
self,
555+
what: str,
556+
update_items: bool = True,
557+
force: bool = False,
558+
only_visible: bool = True,
559+
only_existing: bool = False,
540560
) -> None:
541561
"""Refresh plot.
542562
@@ -549,15 +569,28 @@ def refresh_plot(
549569
If False, only show the items (do not update them, except if the
550570
option "Use reference item LUT range" is enabled and more than one
551571
item is selected). Defaults to True.
552-
force: if True, force refresh even if auto refresh is disabled,
553-
and refresh all items associated to objects (even the hidden ones, e.g.
554-
when selecting multiple images of the same size and position). Defaults
555-
to False.
572+
force: if True, force refresh even if auto refresh is disabled.
573+
Defaults to False.
574+
only_visible: if True, only refresh visible items. Defaults to True.
575+
Visible items are the ones that are not hidden by other items or the items
576+
except the first one if the option "Show first only" is enabled.
577+
This is useful for images, where the last image is the one that is shown.
578+
If False, all items are refreshed.
579+
only_existing: if True, only refresh existing items. Defaults to False.
580+
Existing items are the ones that have already been created and are
581+
associated to the object uuid. If False, create new items for the
582+
objects that do not have an item yet.
556583
557584
Raises:
558585
ValueError: if `what` is not a valid value
559586
"""
560-
super().refresh_plot(what=what, update_items=update_items, force=force)
587+
super().refresh_plot(
588+
what=what,
589+
update_items=update_items,
590+
force=force,
591+
only_visible=only_visible,
592+
only_existing=only_existing,
593+
)
561594
self.plotwidget.contrast.setVisible(Conf.view.show_contrast.get(True))
562595

563596
def cleanup_dataview(self) -> None:

cdl/core/gui/processor/base.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,12 @@ def edit_regions_of_interest(
10991099
obj_i.roi = edited_roi
11001100
self.SIG_ADD_SHAPE.emit(obj.uuid)
11011101
# self.panel.selection_changed(update_items=True)
1102-
self.panel.manual_refresh()
1102+
self.panel.refresh_plot(
1103+
"selected",
1104+
update_items=True,
1105+
only_visible=False,
1106+
only_existing=True,
1107+
)
11031108
return edited_roi
11041109

11051110
def delete_regions_of_interest(self) -> None:

doc/locale/fr/LC_MESSAGES/api/core.gui/panel.po

+10-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: DataLab \n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2025-03-31 09:43+0200\n"
11+
"POT-Creation-Date: 2025-04-07 19:11+0200\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language: fr\n"
@@ -17,7 +17,7 @@ msgstr ""
1717
"MIME-Version: 1.0\n"
1818
"Content-Type: text/plain; charset=utf-8\n"
1919
"Content-Transfer-Encoding: 8bit\n"
20-
"Generated-By: Babel 2.17.0\n"
20+
"Generated-By: Babel 2.14.0\n"
2121

2222
msgid "Panel"
2323
msgstr "Panneau"
@@ -202,7 +202,7 @@ msgstr ""
202202
msgid "Setup panel"
203203
msgstr ""
204204

205-
msgid "Refresh plot. This method simply emits the signal SIG_REFRESH_PLOT which is connected to the method `PlotHandler.refresh_plot`."
205+
msgid "Refresh plot."
206206
msgstr ""
207207

208208
msgid "string describing the objects to refresh. Valid values are \"selected\" (refresh the selected objects), \"all\" (refresh all objects), \"existing\" (refresh existing plot items), or an object uuid."
@@ -211,7 +211,13 @@ msgstr ""
211211
msgid "if True, update the items. If False, only show the items (do not update them, except if the option \"Use reference item LUT range\" is enabled and more than one item is selected). Defaults to True."
212212
msgstr ""
213213

214-
msgid "if True, force refresh even if auto refresh is disabled, and refresh all items associated to objects (even the hidden ones, e.g. when selecting multiple images of the same size and position). Defaults to False."
214+
msgid "if True, force refresh even if auto refresh is disabled. Defaults to False."
215+
msgstr ""
216+
217+
msgid "if True, only refresh visible items. Defaults to True. Visible items are the ones that are not hidden by other items or the items except the first one if the option \"Show first only\" is enabled. This is useful for images, where the last image is the one that is shown. If False, all items are refreshed."
218+
msgstr ""
219+
220+
msgid "if True, only refresh existing items. Defaults to False. Existing items are the ones that have already been created and are associated to the object uuid. If False, create new items for the objects that do not have an item yet."
215221
msgstr ""
216222

217223
msgid "Raises"

doc/locale/fr/LC_MESSAGES/api/core.gui/plothandler.po

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: DataLab \n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2025-03-20 14:15+0100\n"
11+
"POT-Creation-Date: 2025-04-07 19:11+0200\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language: fr\n"
@@ -17,7 +17,7 @@ msgstr ""
1717
"MIME-Version: 1.0\n"
1818
"Content-Type: text/plain; charset=utf-8\n"
1919
"Content-Transfer-Encoding: 8bit\n"
20-
"Generated-By: Babel 2.17.0\n"
20+
"Generated-By: Babel 2.14.0\n"
2121

2222
msgid "Plot handler"
2323
msgstr "Gestionnaire de visualisation"
@@ -85,7 +85,13 @@ msgstr "chaîne décrivant les objets à actualiser. Les valeurs valides sont \"
8585
msgid "if True, update the items. If False, only show the items (do not update them, except if the option \"Use reference item LUT range\" is enabled and more than one item is selected). Defaults to True."
8686
msgstr "si True, mettre à jour les items. Si False, seulement afficher les items (ne pas les mettre à jour, sauf si l'option \"Utiliser la plage LUT de l'item de référence\" est activée et que plus d'un item est sélectionné). Par défaut à True."
8787

88-
msgid "if True, force refresh even if auto refresh is disabled, and refresh all items associated to objects (even the hidden ones, e.g. when selecting multiple images of the same size and position). Defaults to False."
88+
msgid "if True, force refresh even if auto refresh is disabled. Defaults to False."
89+
msgstr ""
90+
91+
msgid "if True, only refresh visible items. Defaults to True. Visible items are the ones that are not hidden by other items or the items except the first one if the option \"Show first only\" is enabled. This is useful for images, where the last image is the one that is shown. If False, all items are refreshed."
92+
msgstr ""
93+
94+
msgid "if True, only refresh existing items. Defaults to False. Existing items are the ones that have already been created and are associated to the object uuid. If False, create new items for the objects that do not have an item yet."
8995
msgstr ""
9096

9197
msgid "Raises"
@@ -123,3 +129,4 @@ msgstr "Gestionnaire de visualisation d'images"
123129

124130
msgid "Object handling image plot items, plot dialogs, plot options"
125131
msgstr "Objet gérant les items de visualisation d'images, les dialogues de visualisation et les options de visualisation"
132+

doc/locale/fr/LC_MESSAGES/contributing/changelog.po

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: DataLab \n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2025-04-07 18:28+0200\n"
10+
"POT-Creation-Date: 2025-04-07 19:11+0200\n"
1111
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1212
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1313
"Language: fr\n"
@@ -60,6 +60,9 @@ msgstr "Correction de l'[Issue #159](https://github.com./DataLab-Platform/DataLab
6060
msgid "Fixed [Issue #160](https://github.com./DataLab-Platform/DataLab/issues/160) - When selecting multiple images and clearing ROI in ROI editor, only the first image is affected"
6161
msgstr "Correction de l'[Issue #160](https://github.com./DataLab-Platform/DataLab/issues/160) - Lors de la sélection de plusieurs images et de l'effacement de la ROI dans l'éditeur de ROI, seule la première image est affectée"
6262

63+
msgid "Fixed [Issue #161](https://github.com./DataLab-Platform/DataLab/issues/161) - Refresh image items only if necessary (when editing ROI, pasting/deleting metadata)"
64+
msgstr "Correction de l'[Issue #161](https://github.com./DataLab-Platform/DataLab/issues/161) - Rafraîchir les items d'image uniquement si nécessaire (lors de l'édition de la ROI, du collage/de la suppression de métadonnées)"
65+
6366
msgid "DataLab Version 0.19.0"
6467
msgstr "DataLab Version 0.19.0"
6568

0 commit comments

Comments
 (0)