Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 57cbfba

Browse filesBrowse files
authored
add in operator to PlotArea (#321)
1 parent 32db614 commit 57cbfba
Copy full SHA for 57cbfba

File tree

1 file changed

+22
-0
lines changed
Filter options

1 file changed

+22
-0
lines changed

‎fastplotlib/layouts/_base.py

Copy file name to clipboardExpand all lines: fastplotlib/layouts/_base.py
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,28 @@ def __getitem__(self, name: str):
522522
f"The current selectors are:\n {selector_names}"
523523
)
524524

525+
def __contains__(self, item: Union[str, Graphic]):
526+
to_check = [*self.graphics, *self.selectors]
527+
528+
if isinstance(item, Graphic):
529+
if item in to_check:
530+
return True
531+
else:
532+
return False
533+
534+
elif isinstance(item, str):
535+
for graphic in to_check:
536+
# only check named graphics
537+
if graphic.name is None:
538+
continue
539+
540+
if graphic.name == item:
541+
return True
542+
543+
return False
544+
545+
raise TypeError("PlotArea `in` operator accepts only `Graphic` or `str` types")
546+
525547
def __str__(self):
526548
if self.name is None:
527549
name = "unnamed"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.