notify.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from typing import Any, Literal, Optional, Union
  2. from ..context import context
  3. ARG_MAP = {
  4. 'close_button': 'closeBtn',
  5. 'multi_line': 'multiLine',
  6. }
  7. # pylint: disable=unused-argument
  8. def notify(message: Any, *,
  9. position: Literal[
  10. 'top-left',
  11. 'top-right',
  12. 'bottom-left',
  13. 'bottom-right',
  14. 'top',
  15. 'bottom',
  16. 'left',
  17. 'right',
  18. 'center',
  19. ] = 'bottom',
  20. close_button: Union[bool, str] = False,
  21. type: Optional[Literal[ # pylint: disable=redefined-builtin
  22. 'positive',
  23. 'negative',
  24. 'warning',
  25. 'info',
  26. 'ongoing',
  27. ]] = None,
  28. color: Optional[str] = None,
  29. multi_line: bool = False,
  30. **kwargs: Any,
  31. ) -> None:
  32. """Notification
  33. Displays a notification on the screen.
  34. :param message: content of the notification
  35. :param position: position on the screen ("top-left", "top-right", "bottom-left", "bottom-right", "top", "bottom", "left", "right" or "center", default: "bottom")
  36. :param close_button: optional label of a button to dismiss the notification (default: `False`)
  37. :param type: optional type ("positive", "negative", "warning", "info" or "ongoing")
  38. :param color: optional color name
  39. :param multi_line: enable multi-line notifications
  40. Note: You can pass additional keyword arguments according to `Quasar's Notify API <https://quasar.dev/quasar-plugins/notify#notify-api>`_.
  41. """
  42. options = {ARG_MAP.get(key, key): value for key, value in locals().items() if key != 'kwargs' and value is not None}
  43. options['message'] = str(message)
  44. options.update(kwargs)
  45. client = context.client
  46. client.outbox.enqueue_message('notify', options, client.id)