E5XML/SessionHandler.py

changeset 50
a36eecf45b2e
parent 45
9a18f4dbb493
child 53
c3eb7cc1ff8b
equal deleted inserted replaced
49:f991944e859c 50:a36eecf45b2e
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 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.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
116 folds = attrs.get("folds", "")
117 if folds:
118 self.folds = [int(f) for f in folds.split(',')]
119 else:
120 self.folds = []
121
122 def endFilename(self):
123 """
124 Handler method for the "Filename" end tag.
125 """
126 self.vm.openFiles(self.buffer)
127 ed = self.vm.getOpenEditor(self.buffer)
128 if ed is not None:
129 if self.folds:
130 ed.recolor()
131 for line in self.folds:
132 ed.foldLine(line - 1)
133 ed.setCursorPosition(self.cline, self.cindex)
134 ed.ensureCursorVisible()
135
136 def startBreakpoint(self, attrs):
137 """
138 Handler method for the "Breakpoint" start tag.
139
140 @param attrs list of tag attributes
141 """
142 self.filename = ""
143 self.lineno = 0
144 self.bpCond = ""
145 self.bpTemp = False
146 self.bpEnabled = True
147 self.bpCount = 0
148
149 def endBreakpoint(self):
150 """
151 Handler method for the "Breakpoint" end tag.
152 """
153 self.dbs.getBreakPointModel().addBreakPoint(self.filename, self.lineno,
154 (self.bpCond, self.bpTemp, self.bpEnabled, self.bpCount))
155
156 def startWatchexpression(self, attrs):
157 """
158 Handler method for the "Watchexpression" start tag.
159
160 @param attrs list of tag attributes
161 """
162 self.bpCond = ""
163 self.bpTemp = False
164 self.bpEnabled = True
165 self.bpCount = 0
166 self.wpSpecialCond = ""
167
168 def endWatchexpression(self):
169 """
170 Handler method for the "Watchexpression" end tag.
171 """
172 self.dbs.getWatchPointModel().addWatchPoint(self.bpCond,
173 (self.bpTemp, self.bpEnabled, self.bpCount, self.wpSpecialCond))
174
175 def endBFilename(self):
176 """
177 Handler method for the "BFilename" end tag.
178 """
179 self.filename = self.buffer
180
181 def startLinenumber(self, attrs):
182 """
183 Handler method for the "Linenumber" start tag.
184
185 @param attrs list of tag attributes
186 """
187 self.lineno = int(attrs["value"])
188
189 def endCondition(self):
190 """
191 Handler method for the "Condition" end tag.
192 """
193 cond = self.unescape(self.buffer)
194 if cond == 'None':
195 self.bpCond = ''
196 else:
197 self.bpCond = cond
198
199 def startEnabled(self, attrs):
200 """
201 Handler method for the "Enabled" start tag.
202
203 @param attrs list of tag attributes
204 """
205 self.bpEnabled = attrs["value"]
206 if self.bpEnabled in ["True", "False"]:
207 self.bpEnabled = self.bpEnabled == "True"
208 else:
209 self.bpEnabled = bool(int(self.bpEnabled))
210
211 def startTemporary(self, attrs):
212 """
213 Handler method for the "Temporary" start tag.
214
215 @param attrs list of tag attributes
216 """
217 self.bpTemp = attrs["value"]
218 if self.bpTemp in ["True", "False"]:
219 self.bpTemp = self.bpTemp == "True"
220 else:
221 self.bpTemp = bool(int(self.bpTemp))
222
223 def startCount(self, attrs):
224 """
225 Handler method for the "Count" start tag.
226
227 @param attrs list of tag attributes
228 """
229 self.bpCount = int(attrs["value"])
230
231 def endSpecial(self):
232 """
233 Handler method for the "Special" end tag.
234 """
235 self.wpSpecialCond = self.buffer
236
237 def endCommandLine(self):
238 """
239 Handler method for the "CommandLine" end tag.
240 """
241 self.buffer = self.unescape(self.buffer)
242 self.dbg.setArgvHistory(self.buffer)
243 if not self.isGlobal:
244 self.project.dbgCmdline = self.buffer
245
246 def endWorkingDirectory(self):
247 """
248 Handler method for the "WorkinDirectory" end tag.
249 """
250 self.dbg.setWdHistory(self.buffer)
251 if not self.isGlobal:
252 self.project.dbgWd = self.buffer
253
254 def endEnvironment(self):
255 """
256 Handler method for the "Environment" end tag.
257 """
258 self.dbg.setEnvHistory(self.buffer)
259 if not self.isGlobal:
260 self.project.dbgEnv = self.buffer
261
262 def startReportExceptions(self, attrs):
263 """
264 Handler method for the "ReportExceptions" start tag.
265
266 @param attrs list of tag attributes
267 """
268 exc = attrs.get("value", "False")
269 if exc in ["True", "False"]:
270 if exc == "True":
271 exc = True
272 else:
273 exc = False
274 else:
275 exc = bool(int(exc))
276 self.dbg.setExceptionReporting(exc)
277 if not self.isGlobal:
278 self.project.dbgReportExceptions = exc
279
280 def startExceptions(self, attrs):
281 """
282 Handler method for the "Exceptions" start tag.
283
284 @param attrs list of tag attributes
285 """
286 self.dbgExcList = []
287
288 def endExceptions(self):
289 """
290 Handler method for the "Exceptions" end tag.
291 """
292 self.dbg.setExcList(self.dbgExcList)
293 if not self.isGlobal:
294 self.project.dbgExcList = self.dbgExcList[:] # keep a copy
295
296 def endException(self):
297 """
298 Handler method for the "Exception" end tag.
299 """
300 self.dbgExcList.append(self.buffer)
301
302 def startIgnoredExceptions(self, attrs):
303 """
304 Handler method for the "IgnoredExceptions" start tag.
305
306 @param attrs list of tag attributes
307 """
308 self.dbgExcIgnoreList = []
309
310 def endIgnoredExceptions(self):
311 """
312 Handler method for the "IgnoredExceptions" end tag.
313 """
314 self.dbg.setExcIgnoreList(self.dbgExcIgnoreList)
315 if not self.isGlobal:
316 self.project.dbgExcIgnoreList = self.dbgExcIgnoreList[:] # keep a copy
317
318 def endIgnoredException(self):
319 """
320 Handler method for the "IgnoredException" end tag.
321 """
322 self.dbgExcIgnoreList.append(self.buffer)
323
324 def startAutoClearShell(self, attrs):
325 """
326 Handler method for the "AutoClearShell" start tag.
327
328 @param attrs list of tag attributes
329 """
330 autoClearShell = attrs.get("value", "False")
331 if autoClearShell == "True":
332 autoClearShell = True
333 else:
334 autoClearShell = False
335 self.dbg.setAutoClearShell(autoClearShell)
336 if not self.isGlobal:
337 self.project.dbgAutoClearShell = autoClearShell
338
339 def startTracePython(self, attrs):
340 """
341 Handler method for the "TracePython" start tag.
342
343 @param attrs list of tag attributes
344 """
345 tracePython = attrs.get("value", "False")
346 if tracePython in ["True", "False"]:
347 if tracePython == "True":
348 tracePython = True
349 else:
350 tracePython = False
351 else:
352 tracePython = bool(int(tracePython))
353 self.dbg.setTracePython(tracePython)
354 if not self.isGlobal:
355 self.project.dbgTracePython = tracePython
356
357 def startAutoContinue(self, attrs):
358 """
359 Handler method for the "AutoContinue" start tag.
360
361 @param attrs list of tag attributes
362 """
363 autoContinue = attrs.get("value", "False")
364 if autoContinue == "True":
365 autoContinue = True
366 else:
367 autoContinue = False
368 self.dbg.setAutoContinue(autoContinue)
369 if not self.isGlobal:
370 self.project.dbgAutoContinue = autoContinue
371
372 def startBookmark(self, attrs):
373 """
374 Handler method for the "Bookmark" start tag.
375
376 @param attrs list of tag attributes
377 """
378 self.filename = ""
379 self.lineno = 0
380
381 def endBookmark(self):
382 """
383 Handler method for the "Bookmark" end tag.
384 """
385 editor = self.vm.getOpenEditor(self.filename)
386 if editor is not None:
387 editor.toggleBookmark(self.lineno)
388
389 def startSession(self, attrs):
390 """
391 Handler method for the "Session" start tag.
392
393 @param attrs list of tag attributes
394 """
395 self.version = attrs.get('version', sessionFileFormatVersion)
396
397 def getVersion(self):
398 """
399 Public method to retrieve the version of the session.
400
401 @return String containing the version number.
402 """
403 return self.version

eric ide

mercurial