Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self):
Controller.__init__(self, controller_id, name)
for key in cls.__dict__.keys():
prop = cls.__dict__[key]
if isinstance(prop, KerviValue):
if prop.is_input:
self.inputs._add_internal(key, prop)
else:
self.outputs._add_internal(key, prop)
cls.__init__(self)
return _ControllerClass
"top" the chart buttons are shown above the chart.
* *chart_grid* (``bool``) -- If true the value grid is displayed.
* *chart_interval* (``str``) -- Initial time interval displayed.
possible values are "5min", "15min", "30min", "hour" (default), "day", "week", "month", "year"
"""
KerviComponent.link_to_dashboard(
self,
dashboard_id,
section_id,
**kwargs
)
class StringValue(KerviValue):
"""
Value that holds a string.
"""
def __init__(self, name, **kwargs):
KerviValue.__init__(self, name, "string-value", **kwargs)
#self.spine = Spine()
self._value = ""
self._ui_parameters["type"] = "text"
def link_to_dashboard(self, dashboard_id, section_id, **kwargs):
r"""
Links this value to a dashboard panel.
:param dashboard_id:
Id of the dashboard to link to.
:type dashboard_id: str
The value will only occupy as much space as the label and input takes.
* *input_size* (``int | str``) -- Width of the input field. Use px, % or rem as unit.
* *value_size* (``int``) -- width of the value area as a percentage of the total container it sits in.
"""
KerviComponent.link_to_dashboard(
self,
dashboard_id,
panel_id,
**kwargs
)
class DateTimeValue(KerviValue):
"""
A value that holds a date and/or time.
"""
def __init__(self, name, input_type="datetime", **kwargs):
KerviValue.__init__(self, name, "datetime-value", **kwargs)
#self.spine = Spine()
self._value = ""
self._default_value = ""
self._ui_parameters["type"] = input_type
@property
def value(self):
"""Current value of the component"""
if self._value:
try:
return datetime.strptime(self._value,'%Y-%m-%dT%H:%M:%SZ')
#Copyright 2017 Tim Wentlau.
#Distributed under the MIT License. See LICENSE in root of project.
import time
try:
from datetime import datetime
except:
from kervi.core.utility.udatetime import datetime
from kervi.values.kervi_value import KerviValue
from kervi.core.utility.component import KerviComponent
from kervi.config import Configuration
class NumberValue(KerviValue):
"""
Value that holds a float value.
If this value is an input it is shown as a slider on dashboards.
If is an output it is possible to specify different kinds of gauges.
"""
def __init__(self, name, **kwargs):
self._q_unit = None
self._q_display = None
self._min_value = -100
self._max_value = 100
try:
from pint import UnitRegistry
self._ureg = UnitRegistry()
self._ureg.autoconvert_offset_to_baseunit = True
self._Q = self._ureg.Quantity
def __init__(self, name, **kwargs):
self._q_unit = None
self._q_display = None
self._min_value = -100
self._max_value = 100
try:
from pint import UnitRegistry
self._ureg = UnitRegistry()
self._ureg.autoconvert_offset_to_baseunit = True
self._Q = self._ureg.Quantity
except ImportError:
self._Q = None
KerviValue.__init__(self, name, "number-value", **kwargs)
#self.spine = Spine()
self._type = None
#self._display_unit = None
self._value = 0
self._default_value = 0
self._delta = None
self._ui_parameters["type"] = ""
self._ui_parameters["value_icon"] = None
self._ui_parameters["min_integer_digits"] = 1
self._ui_parameters["min_fraction_digits"] = 1
self._ui_parameters["max_fraction_digits"] = 1
self._ui_parameters["show_sparkline"] = False
self._ui_parameters["show_value"] = True
self._ui_parameters["pad_auto_center"] = False
def __init__(self, name, **kwargs):
KerviValue.__init__(self, name, "string-value", **kwargs)
#self.spine = Spine()
self._value = ""
self._ui_parameters["type"] = "text"
# self._value = self.selected_options
# self.value_changed(self.selected_options, None)
# if self._persist_value and allow_persist:
# self.settings.store_value("value", self.selected_options)
# self.spine.trigger_event(
# "valueChanged",
# self.component_id,
# {"select":self.component_id, "value":self.selected_options}
# )
class ColorValue(KerviValue):
"""
A value that holds a rgb value.
When linked to a dashboard it is represented as a color button.
"""
def __init__(self, name, **kwargs):
KerviValue.__init__(self, name, "color-value", **kwargs)
self._value = (255, 255, 255)
self._default_value = (255, 255, 255)
self._type = None
self._ui_parameters["type"] = "button"
self._ui_parameters["button_icon"] = None
self._ui_parameters["button_text"] = self.name,
self._ui_parameters["button_width"] = None
self._ui_parameters["button_height"] = None,
self._ui_parameters["input_size"] = 0
def __init__(self, name, **kwargs):
KerviValue.__init__(self, name, "string-value", **kwargs)
#self.spine = Spine()
self._value = ""
self._default_value = ""
self._ui_parameters["type"] = "text"
self._ui_parameters["input_size"] = "5rem"
def _normalize_value(self, new_value):
if isinstance(new_value, str) and new_value[0]=="#":
#self._set_value(new_value)
KerviValue._set_value(self, new_value)
elif isinstance(new_value, list) and len(new_value)==3:
value = '#%02x%02x%02x' % (new_value[0], new_value[1], new_value[2])
KerviValue._set_value(self, value)
#self._set_value(value)
elif isinstance(new_value, tuple) and len(new_value):
value = '#%02x%02x%02x' % new_value
KerviValue._set_value(self, value)
else:
raise ValueError("invalid color value:" + str(new_value))
"top" the chart buttons are shown above the chart.
* *chart_grid* (``bool``) -- If true the value grid is displayed.
* *chart_interval* (``str``) -- Initial time interval displayed.
possible values are "5min", "15min", "30min", "hour" (default), "day", "week", "month", "year"
"""
KerviComponent.link_to_dashboard(
self,
dashboard_id,
panel_id,
**kwargs
)
class StringValue(KerviValue):
"""
Value that holds a string.
"""
def __init__(self, name, **kwargs):
KerviValue.__init__(self, name, "string-value", **kwargs)
#self.spine = Spine()
self._value = ""
self._default_value = ""
self._ui_parameters["type"] = "text"
self._ui_parameters["input_size"] = "5rem"
def link_to_dashboard(self, dashboard_id=None, panel_id=None, **kwargs):
r"""
Links this value to a dashboard panel.
:param dashboard_id: