etisserant@12: import os
lbessard@11: from nodelist import NodeList
lbessard@11: from nodemanager import NodeManager
lbessard@11: import config_utils, gen_cfile
etisserant@12: from networkedit import networkedit
lbessard@11:
etisserant@13: class _NetworkEdit(networkedit):
etisserant@13: " Overload some of CanFestival Network Editor methods "
etisserant@12: def OnCloseFrame(self, event):
etisserant@13: " Do reset _NodeListPlug.View when closed"
etisserant@13: self._onclose()
etisserant@12: event.Skip()
etisserant@12:
etisserant@13: class _NodeListPlug(NodeList):
etisserant@12: XSD = """
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@12: """
etisserant@12:
etisserant@12: def __init__(self, buspath):
lbessard@11: manager = NodeManager()
lbessard@11: NodeList.__init__(self, manager)
lbessard@11: self.LoadProject(buspath)
lbessard@11:
etisserant@13: _View = None
etisserant@13: def _OpenView(self):
etisserant@13: if not self._View:
etisserant@13: def _onclose():
etisserant@13: self.View = None
etisserant@13: self._View = _NetworkEdit()
etisserant@13: self._View._onclose = _onclose
etisserant@13: return self.View
etisserant@13: PluginMethods = [("NetworkEdit",_OpenView)]
etisserant@13:
etisserant@13: def OnPlugClose(self):
etisserant@13: if self._View:
etisserant@13: self._View.Close()
etisserant@13:
etisserant@13: def PlugTestModified(self):
etisserant@12: return self.HasChanged()
etisserant@12:
etisserant@13: def PlugRequestSave(self):
lbessard@11: self.SaveProject()
etisserant@12: return True
etisserant@12:
etisserant@12: def Generate_C(self, dirpath, locations):
etisserant@12: """
etisserant@12: return C code for network dictionnary
etisserant@12: """
etisserant@12: filepath = os.path.join(dirpath, "master.c")
etisserant@12: master = config_utils.GenerateConciseDCF(locations, self)
etisserant@12: res = gen_cfile.GenerateFile(filepath, master)
etisserant@12: if not res:
etisserant@12: s = str(self.BaseParams.BusId)+"_IN(){}\n"
etisserant@13: s += "CanOpen(\""+self.CanFestivalNode.CAN_Device+"\")"
etisserant@12: f = file(filepath, 'a')
etisserant@12: f.write(s)
etisserant@12: else:
etisserant@12: pass # error
etisserant@12: return {"headers":["master.h"],"sources":["master.c"]}
etisserant@12:
etisserant@13: class RootClass:
etisserant@12: XSD = """
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@12: """
lbessard@11:
etisserant@13: PlugChildsTypes = [("CanOpenNode",_NodeListPlug)]
etisserant@13:
lbessard@11: def Generate_C(self, filepath, locations):
lbessard@11: """
lbessard@11: return C code for network dictionnary
lbessard@11: """
lbessard@11: master = config_utils.GenerateConciseDCF(locations, self)
lbessard@11: res = gen_cfile.GenerateFile(filepath, master)
lbessard@11: if not res:
etisserant@12: s = str(self.BaseParams.BusId)+"_IN(){}\n"
etisserant@13: s += "CanOpen(str(\""+self.CanFestivalNode.CAN_Device+"\")"
lbessard@11: f = file(filepath, 'a')
lbessard@11: f.write(s)
lbessard@11: else:
lbessard@11: pass # error
lbessard@11: