knob.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from typing import Union
  2. from ..dependencies import register_component
  3. from .icon import Icon
  4. from .label import Label
  5. from .mixins.value_element import ValueElement
  6. class Knob(ValueElement):
  7. def __init__(
  8. self,
  9. value: float = 100.0,
  10. color: str = 'primary',
  11. center_color: str = 'white',
  12. track_color: str = 'secondary',
  13. size: str = '',
  14. show_value: Union[bool, None] = False,
  15. icon_name: Union[str, None] = None,
  16. icon_color: str = 'black',
  17. icon_size: str = '1rem',
  18. ) -> None:
  19. """Knob
  20. This element is based on Quasar's `QKnob <https://quasar.dev/vue-components/knob>`_ component.
  21. The element is used to take a number input from the user through mouse/touch panning.
  22. :param value: the initial value of the field (from 0.0 to 100.0)
  23. :param color: color name for component, examples: primary, teal-10.
  24. :param center_color: color name for the center part of the component, examples: primary, teal-10.
  25. :param track_color: color name for the track of the component, examples: primary, teal-10.
  26. :param size: size in CSS units, including unit name or standard size name (xs|sm|md|lg|xl), examples: 16px, 2rem.
  27. :param icon: name for the icon in the center of thecomponent, examples: volume_up, volume_down.
  28. :param icon_color: color name for the icon in the center of the component, examples: primary, teal-10.
  29. :param icon_size: size in CSS units, including unit name or standard size name (xs|sm|md|lg|xl), examples: 16px, 2rem.
  30. """
  31. super().__init__(tag='q-knob', value=value, on_value_change=None)
  32. self._props['color'] = color
  33. self._props['center-color'] = center_color
  34. self._props['track-color'] = track_color
  35. self._props['size'] = size
  36. if show_value:
  37. self._props['show-value'] = True
  38. with self:
  39. self.label = Label('0').bind_text_from(self, 'value')
  40. if icon_name:
  41. self._props['show-value'] = True
  42. with self:
  43. self.icon = Icon(icon_name)
  44. self.icon._props['size'] = icon_size
  45. self.icon._props['color'] = icon_color