-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…function Add a section on triggering notifcation from heavy function
- Loading branch information
Showing
3 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
Binary file modified
BIN
+819 KB
(440%)
docs/tutorials/visuals/4_long_callbacks/images/long_running_callbacks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
docs/tutorials/visuals/4_long_callbacks/src/trigger_update.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from taipy.gui import Gui, invoke_long_callback, get_state_id, invoke_callback | ||
import taipy.gui.builder as tgb | ||
import time | ||
|
||
logs = "" | ||
result = "No response yet" | ||
|
||
def status_fct(state, status, result): | ||
state.logs = "" | ||
state.result = result | ||
|
||
def user_status(state, info): | ||
state.logs = state.logs + "\n" + info | ||
|
||
def heavy_function(gui, state_id): | ||
invoke_callback(gui, state_id, user_status, ["Searching documents"]) | ||
time.sleep(5) | ||
invoke_callback(gui, state_id, user_status, ["Responding to user"]) | ||
time.sleep(5) | ||
invoke_callback(gui, state_id, user_status, ["Fact Checking"]) | ||
return "Here is the answer" | ||
|
||
|
||
def respond(state): | ||
invoke_long_callback(state=state, | ||
user_function=heavy_function, user_function_args=[gui, get_state_id(state)], | ||
user_status_function=status_fct, user_status_function_args=[]) | ||
|
||
with tgb.Page() as main_page: | ||
tgb.button("Respond", on_action=respond) | ||
with tgb.part("card"): | ||
tgb.text("{logs}", mode="pre") | ||
|
||
tgb.text("# Result", mode="md") | ||
tgb.text("{result}") | ||
|
||
|
||
gui = Gui(main_page) | ||
gui.run() |