author | Laurent Bessard |
Thu, 05 Sep 2013 10:36:33 +0200 | |
changeset 1305 | 714f1381a09a |
parent 1153 | 5bdd82497925 |
child 1315 | ff14a66bbd12 |
permissions | -rw-r--r-- |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
1 |
import os |
401
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
361
diff
changeset
|
2 |
from xml.dom import minidom |
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
361
diff
changeset
|
3 |
import cPickle |
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
361
diff
changeset
|
4 |
|
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
5 |
from xmlclass import GenerateClassesFromXSDstring, UpdateXMLClassGlobals |
401
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
361
diff
changeset
|
6 |
|
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
7 |
from PLCControler import UndoBuffer |
630
91b2ae63ea3d
Including external tools for editing plugin informations into Beremiz window
laurent
parents:
610
diff
changeset
|
8 |
|
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
9 |
CODEFILE_XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
10 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
11 |
<xsd:element name="%(codefile_name)s"> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
12 |
<xsd:complexType> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
13 |
<xsd:sequence> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
14 |
%(includes_section)s |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
15 |
<xsd:element name="variables"> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
16 |
<xsd:complexType> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
17 |
<xsd:sequence> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
18 |
<xsd:element name="variable" minOccurs="0" maxOccurs="unbounded"> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
19 |
<xsd:complexType> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
20 |
<xsd:attribute name="name" type="xsd:string" use="required"/> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
21 |
<xsd:attribute name="type" type="xsd:string" use="required"/> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
22 |
<xsd:attribute name="class" use="optional"> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
23 |
<xsd:simpleType> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
24 |
<xsd:restriction base="xsd:string"> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
25 |
<xsd:enumeration value="input"/> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
26 |
<xsd:enumeration value="memory"/> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
27 |
<xsd:enumeration value="output"/> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
28 |
</xsd:restriction> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
29 |
</xsd:simpleType> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
30 |
</xsd:attribute> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
31 |
<xsd:attribute name="initial" type="xsd:string" use="optional" default=""/> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
32 |
</xsd:complexType> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
33 |
</xsd:element> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
34 |
</xsd:sequence> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
35 |
</xsd:complexType> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
36 |
</xsd:element> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
37 |
%(sections)s |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
38 |
</xsd:sequence> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
39 |
</xsd:complexType> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
40 |
</xsd:element> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
41 |
<xsd:complexType name="CodeText"> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
42 |
<xsd:annotation> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
43 |
<xsd:documentation>Formatted text according to parts of XHTML 1.1</xsd:documentation> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
44 |
</xsd:annotation> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
45 |
<xsd:sequence> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
46 |
<xsd:any namespace="http://www.w3.org/1999/xhtml" processContents="lax"/> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
47 |
</xsd:sequence> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
48 |
</xsd:complexType> |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
49 |
</xsd:schema>""" |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
50 |
|
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
51 |
SECTION_TAG_ELEMENT = "<xsd:element name=\"%s\" type=\"CodeText\"/>" |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
52 |
|
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
53 |
class CodeFile: |
656
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
651
diff
changeset
|
54 |
|
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
55 |
CODEFILE_NAME = "CodeFile" |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
56 |
SECTIONS_NAMES = [] |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
57 |
|
31 | 58 |
def __init__(self): |
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
59 |
sections_str = {"codefile_name": self.CODEFILE_NAME} |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
60 |
if "includes" in self.SECTIONS_NAMES: |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
61 |
sections_str["includes_section"] = SECTION_TAG_ELEMENT % "includes" |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
62 |
else: |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
63 |
sections_str["includes_section"] = "" |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
64 |
sections_str["sections"] = "\n".join( |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
65 |
[SECTION_TAG_ELEMENT % name |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
66 |
for name in self.SECTIONS_NAMES if name != "includes"]) |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
67 |
|
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
68 |
self.CodeFileClasses = GenerateClassesFromXSDstring( |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
69 |
CODEFILE_XSD % sections_str) |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
70 |
|
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
71 |
filepath = self.CodeFileName() |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
72 |
|
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
73 |
self.CodeFile = self.CodeFileClasses[self.CODEFILE_NAME]() |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
74 |
if os.path.isfile(filepath): |
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
75 |
xmlfile = open(filepath, 'r') |
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
76 |
tree = minidom.parse(xmlfile) |
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
77 |
xmlfile.close() |
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
78 |
|
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
79 |
for child in tree.childNodes: |
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
80 |
if child.nodeType == tree.ELEMENT_NODE and child.nodeName in [self.CODEFILE_NAME]: |
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
81 |
self.CodeFile.loadXMLTree(child, ["xmlns", "xmlns:xsi", "xsi:schemaLocation"]) |
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
82 |
self.CreateCodeFileBuffer(True) |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
83 |
else: |
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
84 |
self.CreateCodeFileBuffer(False) |
718 | 85 |
self.OnCTNSave() |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
86 |
|
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
87 |
def GetBaseTypes(self): |
718 | 88 |
return self.GetCTRoot().GetBaseTypes() |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
89 |
|
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
90 |
def GetDataTypes(self, basetypes = False): |
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
91 |
return self.GetCTRoot().GetDataTypes(basetypes=basetypes) |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
92 |
|
1146 | 93 |
def GenerateNewName(self, format, start_idx): |
94 |
return self.GetCTRoot().GenerateNewName( |
|
95 |
None, None, format, start_idx, |
|
1153
5bdd82497925
Fixed bug in New variable name generated in CodeFileEditor Variable Panel
Laurent Bessard
parents:
1146
diff
changeset
|
96 |
dict([(var.getname().upper(), True) |
1146 | 97 |
for var in self.CodeFile.variables.getvariable()])) |
98 |
||
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
99 |
def SetVariables(self, variables): |
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
100 |
self.CodeFile.variables.setvariable([]) |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
101 |
for var in variables: |
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
102 |
variable = self.CodeFileClasses["variables_variable"]() |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
103 |
variable.setname(var["Name"]) |
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
104 |
variable.settype(var["Type"]) |
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
105 |
variable.setinitial(var["Initial"]) |
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
106 |
self.CodeFile.variables.appendvariable(variable) |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
107 |
|
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
108 |
def GetVariables(self): |
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
109 |
datas = [] |
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
110 |
for var in self.CodeFile.variables.getvariable(): |
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
111 |
datas.append({"Name" : var.getname(), |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
112 |
"Type" : var.gettype(), |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
113 |
"Initial" : var.getinitial()}) |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
114 |
return datas |
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
115 |
|
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
116 |
def SetTextParts(self, parts): |
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
117 |
for section in self.SECTIONS_NAMES: |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
118 |
section_code = parts.get(section) |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
119 |
if section_code is not None: |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
120 |
getattr(self.CodeFile, section).settext(section_code) |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
121 |
|
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
122 |
def GetTextParts(self): |
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
123 |
return dict([(section, getattr(self.CodeFile, section).gettext()) |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
124 |
for section in self.SECTIONS_NAMES]) |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
125 |
|
718 | 126 |
def CTNTestModified(self): |
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
127 |
return self.ChangesToSave or not self.CodeFileIsSaved() |
630
91b2ae63ea3d
Including external tools for editing plugin informations into Beremiz window
laurent
parents:
610
diff
changeset
|
128 |
|
1061 | 129 |
def OnCTNSave(self, from_project_path=None): |
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
130 |
filepath = self.CodeFileName() |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
131 |
|
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
132 |
text = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" |
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
133 |
text += self.CodeFile.generateXMLText(self.CODEFILE_NAME, 0) |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
134 |
|
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
135 |
xmlfile = open(filepath,"w") |
430 | 136 |
xmlfile.write(text.encode("utf-8")) |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
137 |
xmlfile.close() |
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
138 |
|
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
139 |
self.MarkCodeFileAsSaved() |
31 | 140 |
return True |
141 |
||
1095 | 142 |
def CTNGlobalInstances(self): |
143 |
current_location = self.GetCurrentLocation() |
|
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
144 |
return [(variable.getname(), |
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
145 |
variable.gettype(), |
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
146 |
variable.getinitial()) |
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
147 |
for variable in self.CodeFile.variables.variable] |
656
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
651
diff
changeset
|
148 |
|
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
149 |
#------------------------------------------------------------------------------- |
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
150 |
# Current Buffering Management Functions |
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
151 |
#------------------------------------------------------------------------------- |
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
152 |
|
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
153 |
def cPickle_loads(self, str_obj): |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
154 |
UpdateXMLClassGlobals(self.CodeFileClasses) |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
155 |
return cPickle.loads(str_obj) |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
156 |
|
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
157 |
def cPickle_dumps(self, obj): |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
158 |
UpdateXMLClassGlobals(self.CodeFileClasses) |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
159 |
return cPickle.dumps(obj) |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
160 |
|
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
161 |
""" |
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
162 |
Return a copy of the codefile model |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
163 |
""" |
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
164 |
def Copy(self, model): |
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
165 |
return self.cPickle_loads(self.cPickle_dumps(model)) |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
166 |
|
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
167 |
def CreateCodeFileBuffer(self, saved): |
658 | 168 |
self.Buffering = False |
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
169 |
self.CodeFileBuffer = UndoBuffer(self.cPickle_dumps(self.CodeFile), saved) |
651
cbeb769b0a56
Adding support for unifying grid table control elements
laurent
parents:
630
diff
changeset
|
170 |
|
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
171 |
def BufferCodeFile(self): |
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
172 |
self.CodeFileBuffer.Buffering(self.cPickle_dumps(self.CodeFile)) |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
173 |
|
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
174 |
def StartBuffering(self): |
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
175 |
self.Buffering = True |
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
176 |
|
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
177 |
def EndBuffering(self): |
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
178 |
if self.Buffering: |
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
179 |
self.CodeFileBuffer.Buffering(self.cPickle_dumps(self.CodeFile)) |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
180 |
self.Buffering = False |
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
181 |
|
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
182 |
def MarkCodeFileAsSaved(self): |
651
cbeb769b0a56
Adding support for unifying grid table control elements
laurent
parents:
630
diff
changeset
|
183 |
self.EndBuffering() |
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
184 |
self.CodeFileBuffer.CurrentSaved() |
651
cbeb769b0a56
Adding support for unifying grid table control elements
laurent
parents:
630
diff
changeset
|
185 |
|
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
186 |
def CodeFileIsSaved(self): |
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
187 |
return self.CodeFileBuffer.IsCurrentSaved() and not self.Buffering |
658 | 188 |
|
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
189 |
def LoadPrevious(self): |
651
cbeb769b0a56
Adding support for unifying grid table control elements
laurent
parents:
630
diff
changeset
|
190 |
self.EndBuffering() |
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
191 |
self.CodeFile = self.cPickle_loads(self.CodeFileBuffer.Previous()) |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
192 |
|
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
193 |
def LoadNext(self): |
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1100
diff
changeset
|
194 |
self.CodeFile = self.cPickle_loads(self.CodeFileBuffer.Next()) |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
195 |
|
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
196 |
def GetBufferState(self): |
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
197 |
first = self.CodeFileBuffer.IsFirst() and not self.Buffering |
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1095
diff
changeset
|
198 |
last = self.CodeFileBuffer.IsLast() |
145
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
199 |
return not first, not last |
94855f7b08a9
Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
137
diff
changeset
|
200 |