1
0

notify.py 2.1 KB

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