GUI Properties

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

Properties provide a less verbose way to implement the observer pattern in comparison to using the property decorator.

Parameters:
  • default – Default value which is returned, if no value set before

  • default_factory – A callable which returns the default value. Will be called with the property and the instance

bind(instance, callback)[source]

Binds a function to the change event of the property.

A reference to the function will be kept.

Parameters:
  • instance – The instance to bind the callback to.

  • callback – The callback to bind.

default_factory: Callable[[Any, Any], P]

Default factory to create the initial value

dispatch(instance, value)[source]

Notifies every listener, which subscribed to the change event.

Parameters:
  • instance – Property instance

  • value – new value to set

get(instance) P[source]

Get value for owner instance

name: str

Attribute name of the property

obs: WeakKeyDictionary[Any, _Obs]

Weak dictionary to hold the value and listeners

set(instance, value)[source]

Set value for owner instance

unbind(instance, callback)[source]

Unbinds a function from the change event of the property.

Parameters:
  • instance – The target instance.

  • callback – The callback to unbind.

class arcade.gui.DictProperty[source]

Bases: Property[Dict[K, V]], Generic[K, V]

Property that represents a dict.

Only dict are allowed. Any other classes are forbidden.

default_factory: Callable[[Any, Any], P]

Default factory to create the initial value

name: str

Attribute name of the property

obs: WeakKeyDictionary[Any, _Obs]

Weak dictionary to hold the value and listeners

set(instance, value: dict)[source]

Set value for owner instance, wraps the dict into an observable dict.

class arcade.gui.ListProperty[source]

Bases: Property[List[P]], Generic[P]

Property that represents a list.

Only list are allowed. Any other classes are forbidden.

default_factory: Callable[[Any, Any], P]

Default factory to create the initial value

name: str

Attribute name of the property

obs: WeakKeyDictionary[Any, _Obs]

Weak dictionary to hold the value and listeners

set(instance, value: list)[source]

Set value for owner instance, wraps the list into an observable list.

arcade.gui.bind(instance, property: str, callback)[source]

Bind 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