Avaiga / taipy-gui

Graphical User Interface generator for Taipy
Apache License 2.0
59 stars 16 forks source link

Add callbacks for a state #248

Closed FlorianJacta closed 2 years ago

FlorianJacta commented 2 years ago

What would that feature address It is not possible to give a callback function to change the state of one user or for all the users. For example, it will allow the user to add a callback function to Taipy Core jobs and scenarios. Like this, the user's state or all the states "can be warned" of any changes in the backend through this callback.

Description of the ideal solution The ideal solution will be to provide a way to create this callback either to callback a specific state or all the states. It should be compatible with the backend callbacks (subscribers of jobs/scenarios). It will also be ideal to stay close to the format of the other Gui callbacks (on_change/on_action...).

Caveats

Other options

Acceptance Criteria

FredLL-Avaiga commented 2 years ago

We need to:

@FabienLelaquais @dinhlongviolin1 What are your thoughts ?

FredLL-Avaiga commented 2 years ago

the user code would look like:

from taipy.Gui import Gui, State, get_context_id, invoke_state_callback

val = 1

aGui = Gui(some_md)

def a_user_callback(state: State, scenario, job):
    state.val = 10
    notify(state, "I", f"scenario {scenario} is done")

def a_serializable_callback(scenario, job, context_id: str):
    invoke_state_callback(aGui, context_id, user_callback, scenario, job)

def on_init(state: State):
    scenario.subscribe(a_serializable_callback, {"context_id": get_context_id(state)})

aGui.run()