E4XML/SessionHandler.py

changeset 0
de9c2efb9d02
child 12
1d8dd9706f46
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2003 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the handler class for reading an XML project session file.
8 """
9
10 from E4Gui.E4Application import e4App
11
12 from Config import sessionFileFormatVersion
13 from XMLHandlerBase import XMLHandlerBase
14
15 class SessionHandler(XMLHandlerBase):
16 """
17 Class implementing a sax handler to read an XML project session file.
18 """
19 def __init__(self, project):
20 """
21 Constructor
22
23 @param project Reference to the project object to store the
24 information into.
25 """
26 XMLHandlerBase.__init__(self)
27
28 self.startDocumentSpecific = self.startDocumentSession
29
30 self.elements.update({
31 'Session' : (self.startSession, self.defaultEndElement),
32 'MultiProject' : (self.defaultStartElement, self.endMultiProject),
33 'Project' : (self.defaultStartElement, self.endProject),
34 'Filename' : (self.startFilename, self.endFilename),
35 'ActiveWindow' : (self.startFilename, self.endFilename),
36 'Breakpoint' : (self.startBreakpoint, self.endBreakpoint),
37 'BpFilename' : (self.defaultStartElement, self.endBFilename),
38 'Linenumber' : (self.startLinenumber, self.defaultEndElement),
39 'Condition' : (self.defaultStartElement, self.endCondition),
40 'Enabled' : (self.startEnabled, self.defaultEndElement),
41 'Temporary' : (self.startTemporary, self.defaultEndElement),
42 'Count' : (self.startCount, self.defaultEndElement),
43 'Watchexpression' : (self.startWatchexpression, self.endWatchexpression),
44 'Special' : (self.defaultStartElement, self.endSpecial),
45 'CommandLine' : (self.defaultStartElement, self.endCommandLine),
46 'WorkingDirectory' : (self.defaultStartElement, self.endWorkingDirectory),
47 'Environment' : (self.defaultStartElement, self.endEnvironment),
48 'ReportExceptions' : (self.startReportExceptions, self.defaultEndElement),
49 'Exceptions' : (self.startExceptions, self.endExceptions),
50 'Exception' : (self.defaultStartElement, self.endException),
51 'IgnoredExceptions' : (self.startIgnoredExceptions, self.endIgnoredExceptions),
52 'IgnoredException' : (self.defaultStartElement, self.endIgnoredException),
53 'AutoClearShell' : (self.startAutoClearShell, self.defaultEndElement),
54 'TracePython' : (self.startTracePython, self.defaultEndElement),
55 'AutoContinue' : (self.startAutoContinue, self.defaultEndElement),
56 'Bookmark' : (self.startBookmark, self.endBookmark),
57 'BmFilename' : (self.defaultStartElement, self.endBFilename),
58
59 ####################################################################
60 ## backward compatibility
61 ####################################################################
62 'Watchpoint' : (self.startWatchexpression, self.endWatchexpression), # 4.0
63 'CovexcPattern' : (self.defaultStartElement, self.defaultEndElement), # 4.3
64 })
65
66 self.project = project
67 self.isGlobal = project is None
68
69 self.project = e4App().getObject("Project")
70 self.multiProject = e4App().getObject("MultiProject")
71 self.vm = e4App().getObject("ViewManager")
72 self.dbg = e4App().getObject("DebugUI")
73 self.dbs = e4App().getObject("DebugServer")
74
75 def startDocumentSession(self):
76 """
77 Handler called, when the document parsing is started.
78 """
79 if not self.isGlobal:
80 # clear all breakpoints and bookmarks first
81 # (in case we are rereading a session file)
82 files = self.project.getSources(True)
83 for file in files:
84 editor = self.vm.getOpenEditor(file)
85 if editor is not None:
86 editor.clearBookmarks()
87 self.dbs.getBreakPointModel().deleteAll()
88 self.version = ''
89
90 ###################################################
91 ## below follow the individual handler functions
92 ###################################################
93
94 def endMultiProject(self):
95 """
96 Handler method for the "MultiProject" end tag.
97 """
98 self.buffer = self.utf8_to_code(self.buffer)
99 self.multiProject.openMultiProject(self.buffer, False)
100
101 def endProject(self):
102 """
103 Handler method for the "Project" end tag.
104 """
105 self.buffer = self.utf8_to_code(self.buffer)
106 self.project.openProject(self.buffer, False)
107
108 def startFilename(self, attrs):
109 """
110 Handler method for the "Filename" start tag.
111
112 @param attrs list of tag attributes
113 """
114 self.buffer = ""
115 self.cline = int(attrs.get("cline", "0"))
116 self.cindex = int(attrs.get("cindex", "0"))
117
118 folds = attrs.get("folds", "")
119 if folds:
120 self.folds = [int(f) for f in folds.split(',')]
121 else:
122 self.folds = []
123
124 def endFilename(self):
125 """
126 Handler method for the "Filename" end tag.
127 """
128 self.buffer = self.utf8_to_code(self.buffer)
129 self.vm.openFiles(self.buffer)
130 ed = self.vm.getOpenEditor(self.buffer)
131 if ed is not None:
132 if self.folds:
133 ed.recolor()
134 for line in self.folds:
135 ed.foldLine(line - 1)
136 ed.setCursorPosition(self.cline, self.cindex)
137 ed.ensureCursorVisible()
138
139 def startBreakpoint(self, attrs):
140 """
141 Handler method for the "Breakpoint" start tag.
142
143 @param attrs list of tag attributes
144 """
145 self.filename = ""
146 self.lineno = 0
147 self.bpCond = ""
148 self.bpTemp = False
149 self.bpEnabled = True
150 self.bpCount = 0
151
152 def endBreakpoint(self):
153 """
154 Handler method for the "Breakpoint" end tag.
155 """
156 self.dbs.getBreakPointModel().addBreakPoint(self.filename, self.lineno,
157 (self.bpCond, self.bpTemp, self.bpEnabled, self.bpCount))
158
159 def startWatchexpression(self, attrs):
160 """
161 Handler method for the "Watchexpression" start tag.
162
163 @param attrs list of tag attributes
164 """
165 self.bpCond = ""
166 self.bpTemp = False
167 self.bpEnabled = True
168 self.bpCount = 0
169 self.wpSpecialCond = ""
170
171 def endWatchexpression(self):
172 """
173 Handler method for the "Watchexpression" end tag.
174 """
175 self.dbs.getWatchPointModel().addWatchPoint(self.bpCond,
176 (self.bpTemp, self.bpEnabled, self.bpCount, self.wpSpecialCond))
177
178 def endBFilename(self):
179 """
180 Handler method for the "BFilename" end tag.
181 """
182 self.filename = self.utf8_to_code(self.buffer)
183
184 def startLinenumber(self, attrs):
185 """
186 Handler method for the "Linenumber" start tag.
187
188 @param attrs list of tag attributes
189 """
190 self.lineno = int(attrs["value"])
191
192 def endCondition(self):
193 """
194 Handler method for the "Condition" end tag.
195 """
196 cond = self.utf8_to_code(self.buffer)
197 cond = self.unescape(cond)
198 if cond == 'None':
199 self.bpCond = ''
200 else:
201 self.bpCond = cond
202
203 def startEnabled(self, attrs):
204 """
205 Handler method for the "Enabled" start tag.
206
207 @param attrs list of tag attributes
208 """
209 self.bpEnabled = attrs["value"]
210 if self.bpEnabled in ["True", "False"]:
211 self.bpEnabled = self.bpEnabled == "True"
212 else:
213 self.bpEnabled = bool(int(self.bpEnabled))
214
215 def startTemporary(self, attrs):
216 """
217 Handler method for the "Temporary" start tag.
218
219 @param attrs list of tag attributes
220 """
221 self.bpTemp = attrs["value"]
222 if self.bpTemp in ["True", "False"]:
223 self.bpTemp = self.bpTemp == "True"
224 else:
225 self.bpTemp = bool(int(self.bpTemp))
226
227 def startCount(self, attrs):
228 """
229 Handler method for the "Count" start tag.
230
231 @param attrs list of tag attributes
232 """
233 self.bpCount = int(attrs["value"])
234
235 def endSpecial(self):
236 """
237 Handler method for the "Special" end tag.
238 """
239 self.wpSpecialCond = self.utf8_to_code(self.buffer)
240
241 def endCommandLine(self):
242 """
243 Handler method for the "CommandLine" end tag.
244 """
245 self.buffer = self.utf8_to_code(self.buffer)
246 self.buffer = self.unescape(self.buffer)
247 self.dbg.setArgvHistory(self.buffer)
248 if not self.isGlobal:
249 self.project.dbgCmdline = self.buffer
250
251 def endWorkingDirectory(self):
252 """
253 Handler method for the "WorkinDirectory" end tag.
254 """
255 self.buffer = self.utf8_to_code(self.buffer)
256 self.dbg.setWdHistory(self.buffer)
257 if not self.isGlobal:
258 self.project.dbgWd = self.buffer
259
260 def endEnvironment(self):
261 """
262 Handler method for the "Environment" end tag.
263 """
264 self.buffer = self.utf8_to_code(self.buffer)
265 self.dbg.setEnvHistory(self.buffer)
266 if not self.isGlobal:
267 self.project.dbgEnv = self.buffer
268
269 def startReportExceptions(self, attrs):
270 """
271 Handler method for the "ReportExceptions" start tag.
272
273 @param attrs list of tag attributes
274 """
275 exc = attrs.get("value", "False")
276 if exc in ["True", "False"]:
277 if exc == "True":
278 exc = True
279 else:
280 exc = False
281 else:
282 exc = bool(int(exc))
283 self.dbg.setExceptionReporting(exc)
284 if not self.isGlobal:
285 self.project.dbgReportExceptions = exc
286
287 def startExceptions(self, attrs):
288 """
289 Handler method for the "Exceptions" start tag.
290
291 @param attrs list of tag attributes
292 """
293 self.dbgExcList = []
294
295 def endExceptions(self):
296 """
297 Handler method for the "Exceptions" end tag.
298 """
299 self.dbg.setExcList(self.dbgExcList)
300 if not self.isGlobal:
301 self.project.dbgExcList = self.dbgExcList[:] # keep a copy
302
303 def endException(self):
304 """
305 Handler method for the "Exception" end tag.
306 """
307 self.buffer = self.utf8_to_code(self.buffer)
308 self.dbgExcList.append(self.buffer)
309
310 def startIgnoredExceptions(self, attrs):
311 """
312 Handler method for the "IgnoredExceptions" start tag.
313
314 @param attrs list of tag attributes
315 """
316 self.dbgExcIgnoreList = []
317
318 def endIgnoredExceptions(self):
319 """
320 Handler method for the "IgnoredExceptions" end tag.
321 """
322 self.dbg.setExcIgnoreList(self.dbgExcIgnoreList)
323 if not self.isGlobal:
324 self.project.dbgExcIgnoreList = self.dbgExcIgnoreList[:] # keep a copy
325
326 def endIgnoredException(self):
327 """
328 Handler method for the "IgnoredException" end tag.
329 """
330 self.buffer = self.utf8_to_code(self.buffer)
331 self.dbgExcIgnoreList.append(self.buffer)
332
333 def startAutoClearShell(self, attrs):
334 """
335 Handler method for the "AutoClearShell" start tag.
336
337 @param attrs list of tag attributes
338 """
339 autoClearShell = attrs.get("value", "False")
340 if autoClearShell == "True":
341 autoClearShell = True
342 else:
343 autoClearShell = False
344 self.dbg.setAutoClearShell(autoClearShell)
345 if not self.isGlobal:
346 self.project.dbgAutoClearShell = autoClearShell
347
348 def startTracePython(self, attrs):
349 """
350 Handler method for the "TracePython" start tag.
351
352 @param attrs list of tag attributes
353 """
354 tracePython = attrs.get("value", "False")
355 if tracePython in ["True", "False"]:
356 if tracePython == "True":
357 tracePython = True
358 else:
359 tracePython = False
360 else:
361 tracePython = bool(int(tracePython))
362 self.dbg.setTracePython(tracePython)
363 if not self.isGlobal:
364 self.project.dbgTracePython = tracePython
365
366 def startAutoContinue(self, attrs):
367 """
368 Handler method for the "AutoContinue" start tag.
369
370 @param attrs list of tag attributes
371 """
372 autoContinue = attrs.get("value", "False")
373 if autoContinue == "True":
374 autoContinue = True
375 else:
376 autoContinue = False
377 self.dbg.setAutoContinue(autoContinue)
378 if not self.isGlobal:
379 self.project.dbgAutoContinue = autoContinue
380
381 def startBookmark(self, attrs):
382 """
383 Handler method for the "Bookmark" start tag.
384
385 @param attrs list of tag attributes
386 """
387 self.filename = ""
388 self.lineno = 0
389
390 def endBookmark(self):
391 """
392 Handler method for the "Bookmark" end tag.
393 """
394 editor = self.vm.getOpenEditor(self.filename)
395 if editor is not None:
396 editor.toggleBookmark(self.lineno)
397
398 def startSession(self, attrs):
399 """
400 Handler method for the "Session" start tag.
401
402 @param attrs list of tag attributes
403 """
404 self.version = attrs.get('version', sessionFileFormatVersion)
405
406 def getVersion(self):
407 """
408 Public method to retrieve the version of the session.
409
410 @return String containing the version number.
411 """
412 return self.version

eric ide

mercurial