notify.py 1023 B

123456789101112131415161718192021222324252627282930313233343536
  1. import justpy as jp
  2. from .element import Element
  3. import asyncio
  4. class Notify(Element):
  5. def __init__(self,
  6. message: str = '',
  7. position: str = 'bottom',
  8. close_button: str = ''
  9. ):
  10. """Notification Element
  11. Displays a notification on the screen.
  12. :param message: the content of the notification
  13. :param position: possible position: 'top-left', 'top-right', 'bottom-left','bottom-right, 'top', 'bottom', 'left', 'right', 'center'
  14. :param close_button: label of the button to dismiss the notification
  15. """
  16. view = jp.QNotify(message=message, position=position)
  17. if close_button:
  18. view.closeBtn = close_button
  19. super().__init__(view)
  20. self.notify()
  21. async def notify_async(self):
  22. self.view.notify = True
  23. await self.wp.update()
  24. self.view.notify = False
  25. def notify(self):
  26. asyncio.get_event_loop().create_task(self.notify_async())