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