GUI Properties¶
- class arcade.gui.DictProperty[source]¶
Bases:
Property
Property that represents a dict. Only dict are allowed. Any other classes are forbidden.
- default_factory¶
- obs: WeakKeyDictionary[Any, _Obs]¶
- class arcade.gui.ListProperty[source]¶
Bases:
Property
Property that represents a list. Only list are allowed. Any other classes are forbidden.
- default_factory¶
- obs: WeakKeyDictionary[Any, _Obs]¶
- class arcade.gui.Property(default: P | None = None, default_factory: Callable[[Any, Any], P] | None = None)[source]¶
Bases:
Generic
[P
]An observable property which triggers observers when changed.
def log_change(instance, value): print("Something changed") class MyObject: name = Property() my_obj = MyObject() bind(my_obj, "name", log_change) unbind(my_obj, "name", log_change) my_obj.name = "Hans" # > Something changed :param default: Default value which is returned, if no value set before :param default_factory: A callable which returns the default value. Will be called with the property and the instance
- default_factory¶
- obs: WeakKeyDictionary[Any, _Obs]¶
- arcade.gui.bind(instance, property: str, callback)[source]¶
Binds a function to the change event of the property. A reference to the function will be kept, so that it will be still invoked, even if it would normally have been garbage collected.
- def log_change(instance, value):
print(f”Value of {instance} changed to {value}”)
- class MyObject:
name = Property()
my_obj = MyObject() bind(my_obj, “name”, log_change)
my_obj.name = “Hans” # > Value of <__main__.MyObject …> changed to Hans
- Parameters:
instance – Instance owning the property
property – Name of the property
callback – Function to call
- Returns:
None
- arcade.gui.unbind(instance, property: str, callback)[source]¶
Unbinds a function from the change event of the property.
- def log_change(instance, value):
print(“Something changed”)
- class MyObject:
name = Property()
my_obj = MyObject() bind(my_obj, “name”, log_change) unbind(my_obj, “name”, log_change)
my_obj.name = “Hans” # > Something changed
- Parameters:
instance – Instance owning the property
property – Name of the property
callback – Function to unbind
- Returns:
None