Skip to content
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

Fix #89 and #90 - delete_object fixes #95

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion riscos_toolbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
# These methods and functions are imported for legacy purposes.
from ._types import * # noqa
from ._consts import * # noqa
from .base import Object, _objects, get_object, create_object, find_objects, _application # noqa
from .base import Object, _objects, get_object, create_object, delete_object, \
find_objects, _application # noqa
from .events import * # noqa


Expand Down
9 changes: 6 additions & 3 deletions riscos_toolbox/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ def create_object(template, klass=None, args=None):


def delete_object(object, recursive=True):
swi.swi('Toolbox_DeleteObject', 'Ii', 1 if recursive else 0, object.id)
if object.id in _objects:
del _objects[id]
if isinstance(object, Object):
object = object.id # Take either an Object or its ID as an argument

swi.swi('Toolbox_DeleteObject', 'Ii', 1 if recursive else 0, object)
if object in _objects:
del _objects[object]


class Component:
Expand Down