From 60cc1134dfa109622dfb9d5d2bf3f2782d0cd175 Mon Sep 17 00:00:00 2001 From: Ole Artz Date: Mon, 14 Aug 2017 14:34:05 +0200 Subject: [PATCH] DASH: precision rounding / unit replacement / switch --- python_suite/dashboard/dashboard.py | 12 +++-- python_suite/dashboard/static/css/style.css | 46 ++++++++++++++++++- .../dashboard/views/pv_overview.jinja2 | 15 +++++- 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/python_suite/dashboard/dashboard.py b/python_suite/dashboard/dashboard.py index 5c3b242..6eea493 100755 --- a/python_suite/dashboard/dashboard.py +++ b/python_suite/dashboard/dashboard.py @@ -39,6 +39,7 @@ def cb_connection_change(**kwargs): pv['value'] = '- disconnected -' pv['unit'] = '' pv['classes'] = 'disconnected' + pv['precision'] = None def cb_value_update(**kwargs): @@ -64,11 +65,15 @@ def cb_value_update(**kwargs): pv['value'] = kwargs['char_value'] else: pv['value'] = kwargs['value'] + pv['precision'] = kwargs['precision'] + #if type(kwargs['precision']) == int and ('double' in kwargs['type'] or 'float' in kwargs['type']): + # pv['value'] = round(pv['value'], kwargs['precision']) + if kwargs['enum_strs'] == (b'OFF', b'ON'): + pv['classes'] += ' switch' if pv['value'] is None: pv['value'] = '- disconnected -' pv['unit'] = kwargs['units'] or '' - if pv['value'] == 'OFF': pv['value'] = '- OFF -' - if pv['value'] == 'ON': pv['value'] = '- ON -' - + if pv['unit'] == 'deg C': pv['unit'] = '°C' + if pv['unit'] == 'g/m3': pv['unit'] = 'g/m³' @route('/') @view('pv_overview.jinja2') def index(): @@ -109,6 +114,7 @@ def main(): for pv in group['PVs']: pv['value'] = '- disconnected (initial) -' pv['unit'] = '' + pv['precision'] = None pv['classes'] = 'disconnected' PVS[pv['name']] = epics.PV(pv['name'], auto_monitor=True, form='ctrl', callback=cb_value_update, connection_callback=cb_connection_change) diff --git a/python_suite/dashboard/static/css/style.css b/python_suite/dashboard/static/css/style.css index 78969f5..d347cdc 100644 --- a/python_suite/dashboard/static/css/style.css +++ b/python_suite/dashboard/static/css/style.css @@ -28,14 +28,15 @@ text-align: center; } -.Cooling table, th, td { +table, th, td { border: 1px solid black; } -.Cooling table, th { +table, th { text-align: left; } +/* ALARMS */ .invalid_alarm:after { content: "- invalid -"; position: relative; @@ -69,3 +70,44 @@ border: 3px solid #EBFF00; } +/* TOGGLE ON/OFF */ +.toggle { + overflow: hidden; + display: inline-block; + width: 8em; + padding: 0.125em; + } + .toggle input { + position: absolute; + visibility: hidden; + } + .toggle span { + position: relative; + left: 0%; + display: block; + text-transform: uppercase; + text-align: center; + + -webkit-transition: left 200ms ease-out; + -moz-transition: left 200ms ease-out; + -o-transition: left 200ms ease-out; + transition: left 200ms ease-out; + } + .toggle :checked + span { + left: 50%; + } + + .toggle span:before { + content: attr(data-unchecked); + display: block; + width: 50%; + background-color: #525252; + border-radius: 0.15em; + box-shadow: inset 0 0.1em 0 rgba(255, 255, 255, 0.3); + color: white; + } + + .toggle :checked + span:before { + content: attr(data-checked); + background-color: #0099CC; + } diff --git a/python_suite/dashboard/views/pv_overview.jinja2 b/python_suite/dashboard/views/pv_overview.jinja2 index 56b4ded..85be53e 100644 --- a/python_suite/dashboard/views/pv_overview.jinja2 +++ b/python_suite/dashboard/views/pv_overview.jinja2 @@ -30,7 +30,20 @@ {% for PV in group.PVs %} {{ PV.name }} - {{ PV.value }} + + {% if 'switch' in PV.classes %} + + {% else %} + {% if PV.precision is number %} + {{ PV.value|round(PV.precision) }} + {% else %} + {{ PV.value }} + {% endif %} + {% endif %} + {{ PV.unit }} {% endfor %} -- 2.43.0