plugins/canfestival/canfestival.py
changeset 13 f1f0edbeb313
parent 12 a1f9e514f708
child 15 7a473efc4530
equal deleted inserted replaced
12:a1f9e514f708 13:f1f0edbeb313
     2 from nodelist import NodeList
     2 from nodelist import NodeList
     3 from nodemanager import NodeManager
     3 from nodemanager import NodeManager
     4 import config_utils, gen_cfile
     4 import config_utils, gen_cfile
     5 from networkedit import networkedit
     5 from networkedit import networkedit
     6 
     6 
     7 class _NetworkEditPlugg(networkedit):
     7 class _NetworkEdit(networkedit):
       
     8     " Overload some of CanFestival Network Editor methods "
     8     def OnCloseFrame(self, event):
     9     def OnCloseFrame(self, event):
     9         self.OnPluggClose()
    10         " Do reset _NodeListPlug.View when closed"
       
    11         self._onclose()
    10         event.Skip()
    12         event.Skip()
    11 
    13 
    12 class BusController(NodeList):
    14 class _NodeListPlug(NodeList):
    13     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
    15     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
    14     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    16     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    15       <xsd:element name="CanFestivalNode">
    17       <xsd:element name="CanFestivalNode">
    16         <xsd:complexType>
    18         <xsd:complexType>
    17           <xsd:attribute name="CAN_Device" type="xsd:string" use="required" />
    19           <xsd:attribute name="CAN_Device" type="xsd:string" use="required" />
    18         </xsd:complexType>
    20         </xsd:complexType>
    19       </xsd:element>
    21       </xsd:element>
    20     </xsd:schema>
    22     </xsd:schema>
    21     """
    23     """
    22 
    24 
    23     ViewClass = _NetworkEditPlugg
       
    24     
       
    25     def __init__(self, buspath):
    25     def __init__(self, buspath):
    26         manager = NodeManager()
    26         manager = NodeManager()
    27         NodeList.__init__(self, manager)
    27         NodeList.__init__(self, manager)
    28         self.LoadProject(buspath)
    28         self.LoadProject(buspath)
    29 
    29 
    30     def TestModified(self):
    30     _View = None
       
    31     def _OpenView(self):
       
    32         if not self._View:
       
    33             def _onclose():
       
    34                 self.View = None
       
    35             self._View = _NetworkEdit()
       
    36             self._View._onclose = _onclose
       
    37         return self.View
       
    38     PluginMethods = [("NetworkEdit",_OpenView)]
       
    39 
       
    40     def OnPlugClose(self):
       
    41         if self._View:
       
    42             self._View.Close()
       
    43 
       
    44     def PlugTestModified(self):
    31         return self.HasChanged()
    45         return self.HasChanged()
    32         
    46         
    33     def ReqSave(self):
    47     def PlugRequestSave(self):
    34         self.SaveProject()
    48         self.SaveProject()
    35         return True
    49         return True
    36 
    50 
    37     def Generate_C(self, dirpath, locations):
    51     def Generate_C(self, dirpath, locations):
    38         """
    52         """
    41         filepath = os.path.join(dirpath, "master.c")
    55         filepath = os.path.join(dirpath, "master.c")
    42         master = config_utils.GenerateConciseDCF(locations, self)
    56         master = config_utils.GenerateConciseDCF(locations, self)
    43         res = gen_cfile.GenerateFile(filepath, master)
    57         res = gen_cfile.GenerateFile(filepath, master)
    44         if not res:
    58         if not res:
    45              s = str(self.BaseParams.BusId)+"_IN(){}\n"
    59              s = str(self.BaseParams.BusId)+"_IN(){}\n"
    46              s += "CanOpen(str(\""+self.CanFestivalNode.CAN_Device)+"\")"
    60              s += "CanOpen(\""+self.CanFestivalNode.CAN_Device+"\")"
    47              f = file(filepath, 'a')
    61              f = file(filepath, 'a')
    48              f.write(s)
    62              f.write(s)
    49         else:
    63         else:
    50              pass # error
    64              pass # error
    51         return {"headers":["master.h"],"sources":["master.c"]}
    65         return {"headers":["master.h"],"sources":["master.c"]}
    52     
    66     
    53 class PluginController:
    67 class RootClass:
    54     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
    68     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
    55     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    69     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    56       <xsd:element name="CanFestivalInstance">
    70       <xsd:element name="CanFestivalInstance">
    57         <xsd:complexType>
    71         <xsd:complexType>
    58           <xsd:attribute name="CAN_Driver" type="xsd:string" use="required" />
    72           <xsd:attribute name="CAN_Driver" type="xsd:string" use="required" />
    59         </xsd:complexType>
    73         </xsd:complexType>
    60       </xsd:element>
    74       </xsd:element>
    61     </xsd:schema>
    75     </xsd:schema>
    62     """
    76     """
    63 
    77 
       
    78     PlugChildsTypes = [("CanOpenNode",_NodeListPlug)]
       
    79 
    64     def Generate_C(self, filepath, locations):
    80     def Generate_C(self, filepath, locations):
    65         """
    81         """
    66         return C code for network dictionnary
    82         return C code for network dictionnary
    67         """
    83         """
    68         master = config_utils.GenerateConciseDCF(locations, self)
    84         master = config_utils.GenerateConciseDCF(locations, self)
    69         res = gen_cfile.GenerateFile(filepath, master)
    85         res = gen_cfile.GenerateFile(filepath, master)
    70         if not res:
    86         if not res:
    71              s = str(self.BaseParams.BusId)+"_IN(){}\n"
    87              s = str(self.BaseParams.BusId)+"_IN(){}\n"
    72              s += "CanOpen(str(\""+self.CanFestivalNode.CAN_Device)+"\")"
    88              s += "CanOpen(str(\""+self.CanFestivalNode.CAN_Device+"\")"
    73              f = file(filepath, 'a')
    89              f = file(filepath, 'a')
    74              f.write(s)
    90              f.write(s)
    75         else:
    91         else:
    76              pass # error
    92              pass # error
    77 
    93