From 16a7888a27a0dac39d9e35b89ac56691f8bf1d9e Mon Sep 17 00:00:00 2001 From: Falko Schindler Date: Thu, 12 Dec 2024 09:38:10 +0100 Subject: [PATCH] add documentation --- .../content/timer_documentation.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/website/documentation/content/timer_documentation.py b/website/documentation/content/timer_documentation.py index 48a56ee70..a76db18d0 100644 --- a/website/documentation/content/timer_documentation.py +++ b/website/documentation/content/timer_documentation.py @@ -32,4 +32,32 @@ def handle_click(): ui.button('Notify after 1 second', on_click=handle_click) +@doc.demo("Don't start immediately", ''' + By default, the timer will start immediately. + You can change this behavior by setting the `immediate` parameter to `False`. + This will delay the first execution of the callback by the given interval. +''') +def start_immediately_demo(): + from datetime import datetime + + label = ui.label() + ui.timer(1.0, lambda: label.set_text(f'{datetime.now():%X}'), immediate=False) + + +@doc.demo('Global app timer', ''' + While `ui.timer` is kind of a UI element that runs in the context of the current page, + you can also use the global `app.timer` for UI-independent timers. +''') +def app_timer_demo(): + from nicegui import app + + counter = {'value': 0} + app.timer(1.0, lambda: counter.update(value=counter['value'] + 1)) + + # @ui.page('/') + def page(): + ui.label().bind_text_from(counter, 'value', lambda value: f'Count: {value}') + page() # HIDE + + doc.reference(ui.timer)