1
0

progress.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from typing import Optional
  2. from nicegui import ui
  3. from ..colors import set_text_color
  4. from .mixins.value_element import ValueElement
  5. class LinearProgress(ValueElement):
  6. VALUE_PROP = 'value'
  7. def __init__(self,
  8. value: float = 0.0, *,
  9. size: Optional[str] = None,
  10. show_value: bool = True,
  11. color: Optional[str] = 'primary',
  12. ) -> None:
  13. """Linear Progress
  14. A linear progress bar wrapping Quasar's
  15. `QLinearProgress <https://quasar.dev/vue-components/linear-progress>`_ component.
  16. :param value: the initial value of the field (from 0.0 to 1.0)
  17. :param size: the height of the progress bar (default: "20px" with value label and "4px" without)
  18. :param show_value: whether to show a value label in the center (default: `True`)
  19. :param color: color (either a Quasar, Tailwind, or CSS color or `None`, default: "primary")
  20. """
  21. super().__init__(tag='q-linear-progress', value=value, on_value_change=None)
  22. self._props['size'] = size if size is not None else '20px' if show_value else '4px'
  23. set_text_color(self, color)
  24. if show_value:
  25. with self:
  26. ui.label().classes('absolute-center text-sm text-white').bind_text_from(self, 'value')
  27. class CircularProgress(ValueElement):
  28. VALUE_PROP = 'value'
  29. def __init__(self,
  30. value: float = 0.0, *,
  31. min: float = 0.0,
  32. max: float = 1.0,
  33. size: str = 'xl',
  34. show_value: bool = True,
  35. color: Optional[str] = 'primary',
  36. ) -> None:
  37. """Circular Progress
  38. A circular progress bar wrapping Quasar's
  39. `QCircularProgress <https://quasar.dev/vue-components/circular-progress>`_.
  40. :param value: the initial value of the field
  41. :param min: the minimum value (default: 0.0)
  42. :param max: the maximum value (default: 1.0)
  43. :param size: the size of the progress circle (default: "xl")
  44. :param show_value: whether to show a value label in the center (default: `True`)
  45. :param color: color (either a Quasar, Tailwind, or CSS color or `None`, default: "primary")
  46. """
  47. super().__init__(tag='q-circular-progress', value=value, on_value_change=None)
  48. self._props['min'] = min
  49. self._props['max'] = max
  50. self._props['size'] = size
  51. self._props['show-value'] = show_value
  52. set_text_color(self, color)
  53. self._props['track-color'] = 'grey-4'
  54. if show_value:
  55. with self:
  56. ui.label().classes('absolute-center text-xs').bind_text_from(self, 'value')