forked from Avaiga/taipy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
broadcast callback on non shared variables (Avaiga#1441)
* broadcast callback on non shared variables resolves Avaiga#1207 * update example * remove shared from the broadcast example * - remove broadcast_callback_on_shared - add state to global ctx to allow use of state in function call used as bound value * remove broadcast_callback_on_shared * some of Fab's comments * some of Fab's comments * Merci les tests * Expose invoke_callback() and broadcast_callback() as Gui methods. * Added Gui.broadcast_change() and gui.broadcast_changes() * Fix Gui.broadcast_changes() * Group shared/broadcast tests * Fix tests * Spelling * Fix mypy * Update doc examples * Linter * More linters * Fix tests and make linters even more happy * Fix test [2] * Re-re-re-re-re-fix tests * avoid impact of invoke callback on current state --------- Co-authored-by: Fred Lefévère-Laoide <[email protected]> Co-authored-by: Fabien Lelaquais <[email protected]>
- Loading branch information
1 parent
c5618f1
commit c9a4729
Showing
20 changed files
with
425 additions
and
128 deletions.
There are no files selected for viewing
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
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,57 @@ | ||
# Copyright 2021-2024 Avaiga Private Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations under the License. | ||
# ----------------------------------------------------------------------------------------- | ||
# To execute this script, make sure that the taipy-gui package is installed in your | ||
# Python environment and run: | ||
# python <script> | ||
# ----------------------------------------------------------------------------------------- | ||
# Demonstrate how to update the value of a variable across multiple clients. | ||
# This application creates a thread that sets a variable to the current time. | ||
# The value is updated for every client when Gui.broadcast_change() is invoked. | ||
# ----------------------------------------------------------------------------------------- | ||
from datetime import datetime | ||
from threading import Thread | ||
from time import sleep | ||
|
||
from taipy.gui import Gui | ||
|
||
current_time = datetime.now() | ||
update = False | ||
|
||
|
||
# Update the 'current_time' state variable if 'update' is True | ||
def update_state(state, updated_time): | ||
if state.update: | ||
state.current_time = updated_time | ||
|
||
|
||
# The function that executes in its own thread. | ||
# Call 'update_state()` every second. | ||
def update_time(gui): | ||
while True: | ||
gui.broadcast_callback(update_state, [datetime.now()]) | ||
sleep(1) | ||
|
||
|
||
page = """ | ||
Current time is: <|{current_time}|format=HH:mm:ss|> | ||
Update: <|{update}|toggle|> | ||
""" | ||
|
||
gui = Gui(page) | ||
|
||
# Run thread that regularly updates the current time | ||
thread = Thread(target=update_time, args=[gui], name="clock") | ||
thread.daemon = True | ||
thread.start() | ||
|
||
gui.run() |
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,48 @@ | ||
# Copyright 2021-2024 Avaiga Private Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations under the License. | ||
# ----------------------------------------------------------------------------------------- | ||
# To execute this script, make sure that the taipy-gui package is installed in your | ||
# Python environment and run: | ||
# python <script> | ||
# ----------------------------------------------------------------------------------------- | ||
# Demonstrate how to invoke a callback for different clients. | ||
# This application creates a thread that, every second, invokes a callback for every client | ||
# so the current time may be updated, under a state-dependant condition. | ||
# ----------------------------------------------------------------------------------------- | ||
from datetime import datetime | ||
from threading import Thread | ||
from time import sleep | ||
|
||
from taipy.gui import Gui | ||
|
||
current_time = datetime.now() | ||
|
||
|
||
# The function that executes in its own thread. | ||
# Update the current time every second. | ||
def update_time(gui): | ||
while True: | ||
gui.broadcast_change("current_time", datetime.now()) | ||
sleep(1) | ||
|
||
|
||
page = """ | ||
Current time is: <|{current_time}|format=HH:mm:ss|> | ||
""" | ||
|
||
gui = Gui(page) | ||
|
||
# Run thread that regularly updates the current time | ||
thread = Thread(target=update_time, args=[gui], name="clock") | ||
thread.daemon = True | ||
thread.start() | ||
|
||
gui.run() |
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
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
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
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 |
---|---|---|
|
@@ -21,4 +21,3 @@ | |
|
||
|
||
Gui(page).run() | ||
|
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 |
---|---|---|
|
@@ -40,4 +40,3 @@ | |
""" | ||
|
||
Gui(page).run() | ||
|
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 |
---|---|---|
|
@@ -25,4 +25,3 @@ | |
|
||
|
||
Gui(page).run() | ||
|
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 |
---|---|---|
|
@@ -23,4 +23,3 @@ | |
""" | ||
|
||
Gui(page).run() | ||
|
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 |
---|---|---|
|
@@ -27,4 +27,3 @@ | |
|
||
|
||
Gui(page).run() | ||
|
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
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
Oops, something went wrong.