lpcmanager

Variable Options : fixed parsing, add On Load fix
som6
2020-11-12, Edouard Tisserant
fecb8381e105
Variable Options : fixed parsing, add On Load fix
- fixed parsing to deal with dblquotes and old bugs better, use intermediate representation once parsed, and add function to generate options string from that representation,
- add On Load fix to be backward compatible with previous options syntax and onchange column
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
#
# --------- Libraries Extension ------------
#
import features
from POULibrary import SimplePOULibraryFactory
from LPCArch import GetLPCProduct, GetLPCSOM, MC9_modules, WX_GOT_modules, SVG_GOT_modules
# _lpcmanager_path, arch, etc are defined here because
# globals() of LPCManager.py are passed to extentions
wanted_features_names = ["c_ext", "py_ext", "wxglade_hmi"]
features.libraries=[('Native', 'NativeLib.NativeLibrary', True)]
def _poulibpath(name):
return os.path.join(_lpcmanager_path, 'Pous', "pous"+name+".xml")
product = GetLPCProduct()
if product in MC9_modules + WX_GOT_modules + SVG_GOT_modules:
features.libraries += [('Python', 'py_ext.PythonLibrary', True),
('RTC', SimplePOULibraryFactory(_poulibpath("RTC")), True)]
if product in WX_GOT_modules:
features.libraries += [('GOT', SimplePOULibraryFactory(_poulibpath("GOT")), True)]
if product in SVG_GOT_modules:
features.libraries += [('SVGHMI', 'LPCSVGHMI.SVGHMILibrary', True)]
else: # MC8 ?
features.libraries += [('LPC', SimplePOULibraryFactory(_poulibpath("LPC")), True)]
if product in WX_GOT_modules:
wanted_features_names.extend(["wxglade_hmi"])
#
# --------- Configuration Tree Nodes (CTN) catalog extension ------------
#
_oldcatalog = features.catalog
catalog_index = dict(zip(zip(*_oldcatalog)[0],_oldcatalog))
wanted_beremiz_features = [catalog_index[feature]
for feature in wanted_features_names]
features.catalog = wanted_beremiz_features + [
('lpchmi', _('Smarteh HMI'), _('Create customized HMI'), 'lpchmi.LPCHMI'),
('bacnet', _('Bacnet support'), _('Map located variables over Bacnet'), 'LPCBACnet.RootClass'),
('modbus', _('Modbus'), _('Map located variables over Modbus'), 'LPCModbus.RootClass'),
('LPCBus', _('LPC bus'), _('Support for Smarteh modules'), 'LPCBus.LPCBus'),
('CanOpen', _('CANOpen'), _('Support for CANopen'), 'LPCCanFestival.LPCCanOpen')]
if product in SVG_GOT_modules:
features.catalog += [ catalog_index['svghmi'][:3]+('LPCSVGHMI.SVGHMI',) ]
#
# --------- Connectors Extension ------------
#
import connectors
from functools import partial
# On demand monkey patching
def CustomWAMPFactory(*args, **kwargs):
from connectors import WAMP
from WampAuthentication import WampSession
return WAMP._WAMP_connector_factory(WampSession, *args, **kwargs)
connectors.connectors["WAMP"] = lambda:CustomWAMPFactory
# TODO
# from LPCconnector import LPC_connector_factory
# connectors.connectors["LPC"] = lambda: LPC_connector_factory
#
# --------- Targets/Toolchains Extension ------------
#
import targets
from LPCtarget import LPC_target
som = GetLPCSOM()
if som is not None:
targets.targets = {product : {
"xsd": os.path.join(_lpcmanager_path, som+"target", "XSD"),
"class": targets.targets["Xenomai"]["class"],
"code": {"plc_"+som+"_main.c": targets.targets["Xenomai"]["code"]["plc_Xenomai_main.c"],
"plc_"+som+"_main_retain.c": os.path.join(_lpcmanager_path,
som+"target",
"plc_"+som+"_main_retain.c")}}}
else:
raise NotImplemented
# targets.targets["LPC"] = {"xsd": os.path.join(_lpcmanager_path, "LPCtarget", "XSD"),
# "class": lambda: LPC_target,
# "code": {os.path.join(_lpcmanager_path, "LPCtarget", "plc_LPC_main.c")}}
# targets.toolchains["makefile"] = os.path.join(_lpcmanager_path, "LPCtarget", "XSD_toolchain_makefile")
#
# --------- Custom columns function Extension ------------
#
from WampOptionsEditor import WampOptionsCellEditor
from py_ext.PythonEditor import PythonEditor
from wxglade_hmi import WxGladeHMI
from WxGladeEditor import WxGladeEditor
WxGladeHMI.EditorType = WxGladeEditor
PythonEditor.COLUMNS_TYPE = {'Options': WampOptionsCellEditor}
#
# --------- special OnChange behavior ------------
# ----- on load options and OnChange colums fix --------
#
from py_ext.PythonFileCTNMixin import PythonFileCTNMixin
from OnChangeFromOptions import GetVarOnChangeContent, FixOptions
PythonFileCTNMixin.GetVarOnChangeContent = GetVarOnChangeContent
old_PythonFileCTNMixin__init__ = PythonFileCTNMixin.__init__
def PythonFileCTNMixin__init__with_FixOptions(self):
old_PythonFileCTNMixin__init__(self)
FixOptions(self)
PythonFileCTNMixin.__init__ = PythonFileCTNMixin__init__with_FixOptions