Skip to content

Commit f8bb5f6

Browse files
committed
Let PlotWidget.remove* method support item as their legend argument
1 parent 76f20a6 commit f8bb5f6

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

src/silx/gui/plot/PlotWidget.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,7 +2003,11 @@ def hideCurve(self, legend, flag=True):
20032003
_ACTIVE_ITEM_KINDS = "curve", "scatter", "image"
20042004
"""List of item's kind which have a active item."""
20052005

2006-
def remove(self, legend=None, kind=ITEM_KINDS):
2006+
def remove(
2007+
self,
2008+
legend: str | items.Item | None = None,
2009+
kind: str | Sequence[str] = ITEM_KINDS,
2010+
):
20072011
"""Remove one or all element(s) of the given legend and kind.
20082012
20092013
Examples:
@@ -2017,13 +2021,16 @@ def remove(self, legend=None, kind=ITEM_KINDS):
20172021
- ``remove('myImage')`` removes elements (for instance curve, image,
20182022
item and marker) with legend 'myImage'.
20192023
2020-
:param str legend: The legend associated to the element to remove,
2021-
or None to remove
2022-
:param kind: The kind of elements to remove from the plot.
2024+
:param legend:
2025+
The legend of the item to remove or the item itself.
2026+
If None all items of given kind are removed.
2027+
:param kind: The kind of items to remove from the plot.
20232028
See :attr:`ITEM_KINDS`.
20242029
By default, it removes all kind of elements.
2025-
:type kind: str or tuple of str to specify multiple kinds.
20262030
"""
2031+
if isinstance(legend, items.Item):
2032+
return self.removeItem(legend)
2033+
20272034
if kind == "all": # Replace all by tuple of all kinds
20282035
kind = self.ITEM_KINDS
20292036

@@ -2050,31 +2057,40 @@ def remove(self, legend=None, kind=ITEM_KINDS):
20502057
if item is not None:
20512058
self.removeItem(item)
20522059

2053-
def removeCurve(self, legend):
2060+
def removeCurve(self, legend: str | items.Curve | None):
20542061
"""Remove the curve associated to legend from the graph.
20552062
2056-
:param str legend: The legend associated to the curve to be deleted
2063+
:param legend:
2064+
The legend of the curve to be deleted or the curve item
20572065
"""
20582066
if legend is None:
20592067
return
2068+
if isinstance(legend, items.Item):
2069+
return self.removeItem(legend)
20602070
self.remove(legend, kind="curve")
20612071

2062-
def removeImage(self, legend):
2072+
def removeImage(self, legend: str | items.ImageBase | None):
20632073
"""Remove the image associated to legend from the graph.
20642074
2065-
:param str legend: The legend associated to the image to be deleted
2075+
:param legend:
2076+
The legend of the image to be deleted or the image item
20662077
"""
20672078
if legend is None:
20682079
return
2080+
if isinstance(legend, items.Item):
2081+
return self.removeItem(legend)
20692082
self.remove(legend, kind="image")
20702083

2071-
def removeMarker(self, legend):
2084+
def removeMarker(self, legend: str | items.Marker | None):
20722085
"""Remove the marker associated to legend from the graph.
20732086
2074-
:param str legend: The legend associated to the marker to be deleted
2087+
:param legend:
2088+
The legend of the marker to be deleted or the marker item
20752089
"""
20762090
if legend is None:
20772091
return
2092+
if isinstance(legend, items.Item):
2093+
return self.removeItem(legend)
20782094
self.remove(legend, kind="marker")
20792095

20802096
# Clear

0 commit comments

Comments
 (0)