Skip to content
This repository was archived by the owner on Sep 15, 2024. It is now read-only.

Variables

Kevin edited this page Jan 31, 2024 · 12 revisions

All variables inherit their attributes and methods from Variable. Unlike a regular variable, a variable that inherits from gobject.object is an object that emits a signal when its internal value changes. This allows for the use of dynamic content within widgets.

Variable

inherits from GObject.Object

Constructor

Parameter Value Expected Default Value Description
initial_value any The initial value of the variable can be of any type.

Methods

Method Arguments Type Description
set_value any Sets the internal value of the variable; when it changes, it emits a signal.
get_value Returns the internal value of the variable.
bind function The function argument must be callable. The bind method is used to connect to the variable. When the internal value of the variable changes, the callback is executed. By default, the new value is passed as an argument to the callback.

Example

MyFirstVariable = Variable(False)

BogosBinted = Widget.Button(
    children=Widget.Label(MyFirstVariable),
    onclick=lambda: MyFirstVariable.set_value(not MyFirstVariable.get_value()),
)


Poll

inherits from Variable

Constructor

Parameter Value Expected Default Value Description
interval str or int Interval between iterations, it can be "1s", "2m", "3h" or 1000 for ms.
callback any The callback to exec between iterations.
initial_value any None The initial value of the variable can be of any type.

Methods

Method Arguments Type Description
start_poll Sets the internal value of the variable; when it changes, it emits a signal.
get_value Returns the internal value of the variable.
bind function The function argument must be callable. The bind method is used to connect to the variable. When the internal value of the variable changes, the callback is executed. By default, the new value is passed as an argument to the callback.

Example

from datetime import datetime

## int for ms, str to convert to ms
# clock = Poll("1s", lambda: datetime.now())
clock = Poll(1000, datetime.now)

labelclock = Widget.Label(clock)

## Both works
# labelclock = Widget.Label(Poll(1000, lambda: datetime.now()))
Clone this wiki locally