|
@@ -1,57 +1,57 @@
|
|
|
-from .float_element import FloatElement
|
|
|
-from .quasarcommponents import QLinearProgressExtended, QCircularProgressExtended
|
|
|
-from ..auto_context import ContextMixin
|
|
|
+from typing import Optional
|
|
|
|
|
|
+import justpy as jp
|
|
|
|
|
|
-class LinearProgress(FloatElement, ContextMixin):
|
|
|
+from ..binding import BindableProperty, BindValueMixin
|
|
|
+from .element import Element
|
|
|
|
|
|
- def __init__(self, *, value: float = 0.0, target_object=None, target_name=None, **kwargs):
|
|
|
- """LinearProgress
|
|
|
|
|
|
- An element to create a linear progress bar wrapping
|
|
|
- `Linear Progress <https://v1.quasar.dev/vue-components/linear-progress>`_ component.
|
|
|
+class LinearProgress(Element, BindValueMixin):
|
|
|
+ value = BindableProperty()
|
|
|
|
|
|
- :param value: the initial value of the field (ratio 0.0 - 1.0)
|
|
|
- :param target_object: the object to data bind to
|
|
|
- :param target_name: the field name of the data bound object
|
|
|
+ def __init__(self, value: float = 0.0, *, size: Optional[str] = None, show_value: bool = True) -> None:
|
|
|
+ """Linear Progress
|
|
|
+
|
|
|
+ A linear progress bar wrapping Quasar's
|
|
|
+ `QLinearProgress <https://v1.quasar.dev/vue-components/linear-progress>`_ component.
|
|
|
+
|
|
|
+ :param value: the initial value of the field (from 0.0 to 1.0)
|
|
|
+ :param size: the height of the progress bar (default: "20px" with value label and "4px" without)
|
|
|
+ :param show_value: whether to show a value label in the center (default: `True`)
|
|
|
"""
|
|
|
- view = QLinearProgressExtended(color='primary', size='1.4rem', value=value, temp=False)
|
|
|
- super().__init__(view, value=value, on_change=None, **kwargs)
|
|
|
- if target_object and target_name:
|
|
|
- self.bind_value_from(target_object=target_object, target_name=target_name)
|
|
|
+ view = jp.QLinearProgress(value=value, temp=False)
|
|
|
+ view.prop_list.append('size')
|
|
|
+ view.size = size if size is not None else '20px' if show_value else '4px'
|
|
|
+ super().__init__(view)
|
|
|
+
|
|
|
+ self.value = value
|
|
|
+ self.bind_value_to(self.view, 'value')
|
|
|
|
|
|
+ if show_value:
|
|
|
+ label = jp.Div(text='', classes='absolute-center text-sm text-white', temp=False)
|
|
|
+ label.add_page(self.page)
|
|
|
+ self.view.add(label)
|
|
|
+ self.bind_value_to(label, 'text')
|
|
|
|
|
|
-class CircularProgress(FloatElement, ContextMixin):
|
|
|
|
|
|
- def __init__(self, *, value: float = 0.0, target_object=None, target_name=None, show_value: bool = True,
|
|
|
- **kwargs):
|
|
|
- """CircularProgress
|
|
|
+class CircularProgress(Element, BindValueMixin):
|
|
|
+ value = BindableProperty()
|
|
|
|
|
|
- An element to create a linear progress bar wrapping
|
|
|
- `Circular Progress <https://v1.quasar.dev/vue-components/circular-progress>`_ component.
|
|
|
+ def __init__(self, value: float = 0.0, *,
|
|
|
+ min: float = 0.0, max: float = 1.0, size: str = 'xl', show_value: bool = True) -> None:
|
|
|
+ """Circular Progress
|
|
|
|
|
|
- :param value: the initial value of the field (ratio 0.0 - 1.0)
|
|
|
- :param target_object: the object to data bind to
|
|
|
- :param target_name: the field name of the data bound object
|
|
|
+ A circular progress bar wrapping Quasar's
|
|
|
+ `QCircularProgress <https://v1.quasar.dev/vue-components/circular-progress>`_.
|
|
|
+
|
|
|
+ :param value: the initial value of the field
|
|
|
+ :param size: the size of the progress circle (default: "xl")
|
|
|
+ :param show_value: whether to show a value label in the center (default: `True`)
|
|
|
"""
|
|
|
- value = self._convert_ratio(value)
|
|
|
- view = QCircularProgressExtended(color='primary', value=value, temp=False,
|
|
|
- track_color='grey-4',
|
|
|
- center_color='transparent',
|
|
|
- size='xl', show_value=show_value)
|
|
|
- super().__init__(view, value=value, on_change=None, **kwargs)
|
|
|
- if target_object and target_name:
|
|
|
- self.bind_value_from(target_object=target_object, target_name=target_name)
|
|
|
-
|
|
|
- @property
|
|
|
- def value(self):
|
|
|
- val = getattr(self, '_value')
|
|
|
- return val
|
|
|
-
|
|
|
- @value.setter
|
|
|
- def value(self, value):
|
|
|
- val = self._convert_ratio(value=value)
|
|
|
- setattr(self, '_value', val)
|
|
|
-
|
|
|
- def _convert_ratio(self, value: float) -> float:
|
|
|
- return round(value * 100, 2) if 0.0 <= value <= 1.0 else float(value)
|
|
|
+ view = jp.QCircularProgress(value=value, min=min, max=max, size=size, show_value=show_value,
|
|
|
+ color='primary', track_color='grey-4', temp=False)
|
|
|
+ view.prop_list.append('instant-feedback')
|
|
|
+ super().__init__(view)
|
|
|
+
|
|
|
+ self.value = value
|
|
|
+ self.bind_value_to(self.view, 'value')
|