Bladeren bron

Removes the necessity of an after event from the notify component.

Christoph Trappe 3 jaren geleden
bovenliggende
commit
d9fed0cb18
3 gewijzigde bestanden met toevoegingen van 11 en 9 verwijderingen
  1. 1 2
      main.py
  2. 0 5
      nicegui/elements/button.py
  3. 10 2
      nicegui/elements/notify.py

+ 1 - 2
main.py

@@ -300,8 +300,7 @@ with example(ui.menu):
 
 with example(ui.notify):
 
-    notification = ui.notify(message='Notification', close_button='Close')
-    ui.button('Get notification', on_click=lambda: notification.notify(True), after=lambda: notification.notify(False))
+    ui.button('Get notification', on_click=lambda: ui.notify(message='Notification', close_button='Close'))
 
 lifecycle = '''### Lifecycle
 

+ 0 - 5
nicegui/elements/button.py

@@ -9,13 +9,11 @@ class Button(Element):
                  text: str = '',
                  *,
                  on_click: Callable = None,
-                 after: Callable = None,
                  ):
         """Button Element
 
         :param text: the label of the button
         :param on_click: callback which is invoked when button is pressed
-        :param after: callback to be executed aftern button is pressed, e.g. to clean up before the next page update
         """
 
         view = jp.QButton(label=text, color='primary')
@@ -23,9 +21,6 @@ class Button(Element):
         if on_click is not None:
             view.on('click', handle_exceptions(provide_arguments(on_click)))
 
-        if after is not None:
-            view.on('after', handle_exceptions(provide_arguments(after)))
-
         super().__init__(view)
 
     @property

+ 10 - 2
nicegui/elements/notify.py

@@ -1,5 +1,7 @@
 import justpy as jp
 from .element import Element
+import asyncio
+
 
 class Notify(Element):
 
@@ -23,6 +25,12 @@ class Notify(Element):
             view.closeBtn = close_button
 
         super().__init__(view)
+        self.notify()
+
+    async def notify_async(self):
+        self.view.notify = True
+        await self.wp.update()
+        self.view.notify = False
 
-    def notify(self, state: bool):
-        self.view.notify = state
+    def notify(self):
+        asyncio.get_event_loop().create_task(self.notify_async())