From 37f2123ef6705940e1037d70c83ceaa2e5e3f158 Mon Sep 17 00:00:00 2001 From: Lauren Rad Date: Sun, 31 Dec 2023 15:30:23 -0800 Subject: [PATCH 1/2] Import delete_object into toplevel namespace to match create_object --- riscos_toolbox/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/riscos_toolbox/__init__.py b/riscos_toolbox/__init__.py index 6147458..4520fa9 100644 --- a/riscos_toolbox/__init__.py +++ b/riscos_toolbox/__init__.py @@ -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 From bb864c1d7b4de0757f5af7a0b5dcea3c56f15d9f Mon Sep 17 00:00:00 2001 From: Lauren Rad Date: Sun, 31 Dec 2023 15:32:24 -0800 Subject: [PATCH 2/2] Fix #90 - fix error in delete_object and make it take either Object or an id --- riscos_toolbox/base.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/riscos_toolbox/base.py b/riscos_toolbox/base.py index bb0c59c..d9bc1b5 100644 --- a/riscos_toolbox/base.py +++ b/riscos_toolbox/base.py @@ -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: