E5XML/SessionHandler.py

changeset 599
ee87fe94bf96
parent 598
76c36b6ebbdb
child 600
ed2589a25982
equal deleted inserted replaced
598:76c36b6ebbdb 599:ee87fe94bf96
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2003 - 2010 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 E5Gui.E5Application import e5App
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 = e5App().getObject("Project")
70 self.multiProject = e5App().getObject("MultiProject")
71 self.vm = e5App().getObject("ViewManager")
72 self.dbg = e5App().getObject("DebugUI")
73 self.dbs = e5App().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.multiProject.openMultiProject(self.buffer, False)
99
100 def endProject(self):
101 """
102 Handler method for the "Project" end tag.
103 """
104 self.project.openProject(self.buffer, False)
105
106 def startFilename(self, attrs):
107 """
108 Handler method for the "Filename" start tag.
109
110 @param attrs list of tag attributes
111 """
112 self.buffer = ""
113 self.cline = int(attrs.get("cline", "0"))
114 self.cindex = int(attrs.get("cindex", "0"))
115 self.zoom = int(attrs.get("zoom", "-9999"))
116
117 folds = attrs.get("folds", "")
118 if folds:
119 self.folds = [int(f) for f in folds.split(',')]
120 else:
121 self.folds = []
122
123 def endFilename(self):
124 """
125 Handler method for the "Filename" end tag.
126 """
127 self.vm.openFiles(self.buffer)
128 ed = self.vm.getOpenEditor(self.buffer)
129 if ed is not None:
130 if self.zoom > -9999:
131 ed.zoomTo(self.zoom)
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.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.unescape(self.buffer)
197 if cond == 'None':
198 self.bpCond = ''
199 else:
200 self.bpCond = cond
201
202 def startEnabled(self, attrs):
203 """
204 Handler method for the "Enabled" start tag.
205
206 @param attrs list of tag attributes
207 """
208 self.bpEnabled = attrs["value"]
209 if self.bpEnabled in ["True", "False"]:
210 self.bpEnabled = self.bpEnabled == "True"
211 else:
212 self.bpEnabled = bool(int(self.bpEnabled))
213
214 def startTemporary(self, attrs):
215 """
216 Handler method for the "Temporary" start tag.
217
218 @param attrs list of tag attributes
219 """
220 self.bpTemp = attrs["value"]
221 if self.bpTemp in ["True", "False"]:
222 self.bpTemp = self.bpTemp == "True"
223 else:
224 self.bpTemp = bool(int(self.bpTemp))
225
226 def startCount(self, attrs):
227 """
228 Handler method for the "Count" start tag.
229
230 @param attrs list of tag attributes
231 """
232 self.bpCount = int(attrs["value"])
233
234 def endSpecial(self):
235 """
236 Handler method for the "Special" end tag.
237 """
238 self.wpSpecialCond = self.buffer
239
240 def endCommandLine(self):
241 """
242 Handler method for the "CommandLine" end tag.
243 """
244 self.buffer = self.unescape(self.buffer)
245 self.dbg.setArgvHistory(self.buffer)
246 if not self.isGlobal:
247 self.project.dbgCmdline = self.buffer
248
249 def endWorkingDirectory(self):
250 """
251 Handler method for the "WorkinDirectory" end tag.
252 """
253 self.dbg.setWdHistory(self.buffer)
254 if not self.isGlobal:
255 self.project.dbgWd = self.buffer
256
257 def endEnvironment(self):
258 """
259 Handler method for the "Environment" end tag.
260 """
261 self.dbg.setEnvHistory(self.buffer)
262 if not self.isGlobal:
263 self.project.dbgEnv = self.buffer
264
265 def startReportExceptions(self, attrs):
266 """
267 Handler method for the "ReportExceptions" start tag.
268
269 @param attrs list of tag attributes
270 """
271 exc = attrs.get("value", "False")
272 if exc in ["True", "False"]:
273 if exc == "True":
274 exc = True
275 else:
276 exc = False
277 else:
278 exc = bool(int(exc))
279 self.dbg.setExceptionReporting(exc)
280 if not self.isGlobal:
281 self.project.dbgReportExceptions = exc
282
283 def startExceptions(self, attrs):
284 """
285 Handler method for the "Exceptions" start tag.
286
287 @param attrs list of tag attributes
288 """
289 self.dbgExcList = []
290
291 def endExceptions(self):
292 """
293 Handler method for the "Exceptions" end tag.
294 """
295 self.dbg.setExcList(self.dbgExcList)
296 if not self.isGlobal:
297 self.project.dbgExcList = self.dbgExcList[:] # keep a copy
298
299 def endException(self):
300 """
301 Handler method for the "Exception" end tag.
302 """
303 self.dbgExcList.append(self.buffer)
304
305 def startIgnoredExceptions(self, attrs):
306 """
307 Handler method for the "IgnoredExceptions" start tag.
308
309 @param attrs list of tag attributes
310 """
311 self.dbgExcIgnoreList = []
312
313 def endIgnoredExceptions(self):
314 """
315 Handler method for the "IgnoredExceptions" end tag.
316 """
317 self.dbg.setExcIgnoreList(self.dbgExcIgnoreList)
318 if not self.isGlobal:
319 self.project.dbgExcIgnoreList = self.dbgExcIgnoreList[:] # keep a copy
320
321 def endIgnoredException(self):
322 """
323 Handler method for the "IgnoredException" end tag.
324 """
325 self.dbgExcIgnoreList.append(self.buffer)
326
327 def startAutoClearShell(self, attrs):
328 """
329 Handler method for the "AutoClearShell" start tag.
330
331 @param attrs list of tag attributes
332 """
333 autoClearShell = attrs.get("value", "False")
334 if autoClearShell == "True":
335 autoClearShell = True
336 else:
337 autoClearShell = False
338 self.dbg.setAutoClearShell(autoClearShell)
339 if not self.isGlobal:
340 self.project.dbgAutoClearShell = autoClearShell
341
342 def startTracePython(self, attrs):
343 """
344 Handler method for the "TracePython" start tag.
345
346 @param attrs list of tag attributes
347 """
348 tracePython = attrs.get("value", "False")
349 if tracePython in ["True", "False"]:
350 if tracePython == "True":
351 tracePython = True
352 else:
353 tracePython = False
354 else:
355 tracePython = bool(int(tracePython))
356 self.dbg.setTracePython(tracePython)
357 if not self.isGlobal:
358 self.project.dbgTracePython = tracePython
359
360 def startAutoContinue(self, attrs):
361 """
362 Handler method for the "AutoContinue" start tag.
363
364 @param attrs list of tag attributes
365 """
366 autoContinue = attrs.get("value", "False")
367 if autoContinue == "True":
368 autoContinue = True
369 else:
370 autoContinue = False
371 self.dbg.setAutoContinue(autoContinue)
372 if not self.isGlobal:
373 self.project.dbgAutoContinue = autoContinue
374
375 def startBookmark(self, attrs):
376 """
377 Handler method for the "Bookmark" start tag.
378
379 @param attrs list of tag attributes
380 """
381 self.filename = ""
382 self.lineno = 0
383
384 def endBookmark(self):
385 """
386 Handler method for the "Bookmark" end tag.
387 """
388 editor = self.vm.getOpenEditor(self.filename)
389 if editor is not None:
390 editor.toggleBookmark(self.lineno)
391
392 def startSession(self, attrs):
393 """
394 Handler method for the "Session" start tag.
395
396 @param attrs list of tag attributes
397 """
398 self.version = attrs.get('version', sessionFileFormatVersion)
399
400 def getVersion(self):
401 """
402 Public method to retrieve the version of the session.
403
404 @return String containing the version number.
405 """
406 return self.version

eric ide

mercurial