-
Notifications
You must be signed in to change notification settings - Fork 53
add Deleted
as a graphic feature
#404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from ._base import GraphicFeature, FeatureEvent | ||
|
||
|
||
class Deleted(GraphicFeature): | ||
""" | ||
Used when a graphic is deleted, triggers events that can be useful to indicate this graphic has been deleted | ||
|
||
**event pick info:** | ||
|
||
==================== ======================== ========================================================================= | ||
key type description | ||
==================== ======================== ========================================================================= | ||
"collection-index" int the index of the graphic within the collection that triggered the event | ||
"world_object" pygfx.WorldObject world object | ||
==================== ======================== ========================================================================= | ||
""" | ||
|
||
def __init__(self, parent, value: bool): | ||
super(Deleted, self).__init__(parent, value) | ||
|
||
def _set(self, value: bool): | ||
value = self._parse_set_value(value) | ||
self._feature_changed(key=None, new_data=value) | ||
|
||
def _feature_changed(self, key, new_data): | ||
# this is a non-indexable feature so key=None | ||
|
||
pick_info = { | ||
"index": None, | ||
"collection-index": self._collection_index, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the difference here between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. index is buffer index, used for things like |
||
"world_object": self._parent.world_object, | ||
"new_data": new_data, | ||
} | ||
|
||
event_data = FeatureEvent(type="deleted", pick_info=pick_info) | ||
|
||
self._call_event_handlers(event_data) | ||
|
||
def __repr__(self) -> str: | ||
s = f"DeletedFeature for {self._parent}" | ||
return s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this will get triggered when
__del__
is called andself.deleted = True
is set?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are we preventing users from if a graphic has been deleted to still having reference to the graphic and trying to say something silly like
graphic.deleted=False
? Will this throw an error if the graphic has already been deleted? I would assume so because there will be no reference.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes,
Graphic.__del__
setsself.deleted = True
https://github.com/fastplotlib/fastplotlib/pull/404/files#diff-a57994ecff1cde4e05c8175265219f0b5200da144ce8733b9eb560c09bcea7ddR179Since users are only given acccess to weakreferences, it will throw a reference error if they try to do anything with a deleted
Graphic
.