lpcmanager

8bc894a439da
SVGHMI: reflect changes in Beremiz' SVGHMI for multiclient
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import re
VARIABLETYPE = ["None", "Static", "Session", "Alarm"]
opt_parser = re.compile(r'(\w+)\s*(?:=\s*"([^"]+)"\s*|=([^\s]+)\s*)?')
class OptionsType(dict):
def __init__(self):
dict.__init__(self,
is_onchange = False,
is_scada = False,
is_static = False,
variable_type_selection = 0,
unit = None,
min = None,
max = None,
precision = None,
subgroup = None,
other = None,
tags = None)
self.__dict__ = self
def GenOptions(opts):
options = VARIABLETYPE[opts.variable_type_selection]
if options == "None":
options = ""
if opts.is_onchange:
options += " onchange"
if opts.is_scada:
options += " scada"
if opts.is_static:
options += " static"
if opts.min is not None or opts.max is not None:
options += ' min=' + str(opts.min if opts.min is not None else 0)
options += ' max=' + str(opts.max if opts.min is not None else 0)
if opts.precision:
options += ' precision=' + str(opts.precision)
for name in ['subgroup', 'unit', 'other', 'tags']:
content = opts[name]
if content is not None:
quoting = '"' if ' ' in content else ''
options += ' ' + name + '=' + quoting + content + quoting
return options
def ParseOptions(opts):
res = OptionsType()
options = re.findall(opt_parser,opts)
for key,dblquote_value,smpl_value in options:
value = dblquote_value+smpl_value
if value == "":
if key == "onchange":
res.is_onchange = True
elif key in VARIABLETYPE[1:]:
res.variable_type_selection = VARIABLETYPE.index(key)
elif key == "scada":
res.is_scada = True
elif key == "static":
res.is_static = True
else:
if key in ["precision", "min","max"]:
value = int(value)
if key in res:
res[key] = value
else:
raise Exception("Unknown key in options")
return res