1234567891011121314151617181920212223242526272829303132 |
- from nicegui import ui
- from ...model import UiElementDocumentation
- class TimerDocumentation(UiElementDocumentation, element=ui.timer):
- def main_demo(self) -> None:
- from datetime import datetime
- label = ui.label()
- ui.timer(1.0, lambda: label.set_text(f'{datetime.now():%X}'))
- def more(self) -> None:
- @self.demo('Activate, deactivate and cancel a timer', '''
- You can activate and deactivate a timer using the `active` property.
- You can cancel a timer using the `cancel` method.
- After canceling a timer, it cannot be activated anymore.
- ''')
- def activate_deactivate_demo():
- slider = ui.slider(min=0, max=1, value=0.5)
- timer = ui.timer(0.1, lambda: slider.set_value((slider.value + 0.01) % 1.0))
- ui.switch('active').bind_value_to(timer, 'active')
- ui.button('Cancel', on_click=timer.cancel)
- @self.demo('Call a function after a delay', '''
- You can call a function after a delay using a timer with the `once` parameter.
- ''')
- def call_after_delay_demo():
- def handle_click():
- ui.timer(1.0, lambda: ui.notify('Hi!'), once=True)
- ui.button('Notify after 1 second', on_click=handle_click)
|