from CppSTC import CppSTC
from plugger import PlugTemplate
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="C_File">
<xsd:attribute name="FileName" type="xsd:string" use="required" default="myfile.c"/>
if not os.path.isfile(self.CFileName()):
f = open(self.CFileName(), 'w')
return os.path.join(self.PlugPath(),self.C_File.getFileName())
def SetParamsAttribute(self, path, value, logger):
oldname = self.CFileName()
res = PlugTemplate.SetParamsAttribute(self, path, value, logger)
if path == "C_File.FileName":
shutil.move(oldname, self.CFileName())
logger.write("\"%s\" renamed \"%s\"\n"%(oldname, self.CFileName()))
def _OpenView(self, logger):
self._View = wx.Frame(self.GetPlugRoot().AppFrame,-1)
self._View.Bind(wx.EVT_CLOSE, _onclose)
ed = CppSTC(self._View, wx.NewId())
ed.SetText(open(self.CFileName()).read())
ed.SetMarginType(1, stc.STC_MARGIN_NUMBER)
PluginMethods = [("Edit C File",_OpenView)]
f = open(self.CFileName(),'w')
f.write(self._View.ed.GetText())
def PlugGenerate_C(self, buildpath, locations, logger):
@param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5)
@param locations: List of complete variables locations \
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
"NAME" : name of the variable (generally "__IW0_1_2" style)
"DIR" : direction "Q","I" or "M"
"SIZE" : size "X", "B", "W", "D", "L"
"LOC" : tuple of interger for IEC location (0,1,2,...)
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
current_location = self.GetCurrentLocation()
# define a unique name for the generated C file
prefix = "_".join(map(lambda x:str(x), current_location))
Gen_Cfile_path = os.path.join(buildpath, prefix + "_CFile.c" )
f = open(Gen_Cfile_path,'w')
f.write("/* Header generated by Beremiz c_ext plugin */\n")
f.write("#include \"iec_std_lib.h\"\n")
f.write(loc["IEC_TYPE"]+" "+loc["NAME"]+";\n")
f.write("/* End of header generated by Beremiz c_ext plugin */\n")
return [(Gen_Cfile_path,"")],""
PlugChildsTypes = [("C_File",_Cfile)]
def PlugGenerate_C(self, buildpath, locations, logger):