progress.py 2.1 KB

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