1
4 self.profileScriptName = ""
5 self.profileScriptFileName = ""
6 self.profileResults = []
7
22
120
123 import empro
124 self.dialog = empro.gui.SimpleDialog(empro.gui.Ok)
125 self.dialog.resize(800,100)
126 self.dialog.maximumWidth = 800
127 self.dialog.minimumWidth = 800
128 self.dialog.maximumHeight= 400
129 self.dialog.title = "Error"
130 w = empro.gui.Widget()
131 w.layout = empro.gui.HBoxLayout()
132 w.layout.contentsMargin =[0,0,0,0]
133 w.layout.spacing = 0
134 typeBox = self. _typeBox(excInfo)
135 descriptionBox = self._descriptionBox(excInfo)
136 foundBox = self._foundBox(excInfo)
137 w.layout.addLayout(typeBox)
138 w.layout.addLayout(descriptionBox)
139 if foundBox:
140 w.layout.addLayout(foundBox)
141 self.dialog.layout.add(w)
142
144 import empro
145 typeLayout = empro.gui.VBoxLayout()
146 typeLayout.contentsMargin =[0,0,0,0]
147 self.typeLabel = empro.gui.Label("Type")
148 self.typeLabel.frameStyle = empro.gui.Frame.StyledPanel
149 self.typeLabel.addStyleSheet('QLabel {background-color: rgb(36,75,130); color: rgb(255,255,255)}')
150 type = str(excInfo[0]).split("'")[1].split('.')[1]
151 self.typeColumn = empro.gui.TextEdit(type)
152 self.typeColumn.text = type
153 self.typeColumn.readOnly = True
154 typeLayout.addWidget(self.typeLabel)
155 typeLayout.addWidget(self.typeColumn)
156 return typeLayout
157
159 import empro
160 descriptionLayout = empro.gui.VBoxLayout()
161 descriptionLayout.contentsMargin =[0,0,0,0]
162 self.descriptionLabel= empro.gui.Label("Description")
163 self.descriptionLabel.frameStyle = empro.gui.Frame.StyledPanel
164 self.descriptionLabel.addStyleSheet('QLabel {background-color: rgb(36,75,130); color: rgb(255,255,255)}')
165 description = str(excInfo[1])
166 self.descriptionColumn = empro.gui.TextEdit(description)
167 self.descriptionColumn.readOnly = True
168 descriptionLayout.addWidget(self.descriptionLabel)
169 descriptionLayout.addWidget(self.descriptionColumn)
170 return descriptionLayout
171
173 import os
174 import traceback
175 import empro
176 foundLayout = empro.gui.VBoxLayout()
177 foundLayout.contentsMargin =[0,0,0,0]
178 self.foundLabel = empro.gui.Label("Found at")
179 self.foundLabel.frameStyle = empro.gui.Frame.StyledPanel
180 self.foundLabel.addStyleSheet('QLabel {background-color: rgb(36,75,130); color: rgb(255,255,255)}')
181 self.foundColumn = empro.gui.TableView()
182 self.foundColumn.alternatingRowColors = False
183 self.foundColumn.hideVerticalHeader()
184 self.foundColumn.hideHorizontalHeader()
185 self.foundColumn.selectionMode = empro.gui.TableView.NoSelection
186 tb = excInfo[2]
187 errorLines = traceback.format_tb(tb)
188 errorLines = errorLines[3:]
189 errorLines = errorLines[::-1]
190 lineInfo = []
191 for line in errorLines:
192 errorLineFileName = line.split('"',2)[1]
193 errorLineFileName = os.path.basename(errorLineFileName)
194 errorLineNo = line.split('"',2)[-1].split(",")[1].strip()
195 sw = empro.gui.activeScriptWindow()
196 lineNo = errorLineNo.split(" ")[1]
197 sw.showErrorMark(errorLineFileName,int(lineNo),True)
198 sw.activateWindow()
199 info ="%s in %s "%(errorLineNo, errorLineFileName)
200 lineInfo.append(info)
201 self.foundColumn.setColumn(0,lineInfo)
202 self.foundColumn.resizeRowsToContents()
203 self.foundColumn.resizeColumnsToContents()
204 self.refreshListWidget(self.foundColumn)
205 self.foundColumn.onClicked = self.foundColumnClicked
206 foundLayout.addWidget(self.foundLabel)
207 foundLayout.addWidget(self.foundColumn)
208 return foundLayout
209
214
227
229 self.dialog.show(True)
230
232 - def __init__(self,funcName,listOfDict):
233 import os
234 import empro
235 self.choice = None
236 self.data = listOfDict
237 self.dialog = empro.gui.SimpleDialog(empro.gui.Ok)
238 self.dialog.title = funcName
239 self.dialog.resize(400, 200)
240 self.dialog.maximumWidth = 400
241 subjectText = "More than one instance of the <strong> %s</strong> function definition has be found in the loaded scripts.<br> Please select the script which has the required function definition."%(funcName)
242 fields = [os.path.basename(x['_fileName']) for x in self.data]
243 self.subject = empro.gui.Label(subjectText)
244 self.listWidget = empro.gui.TableView()
245 self.listWidget.alternatingRowColors = False
246 self.listWidget.hideHorizontalHeader()
247 self.listWidget.hideVerticalHeader()
248 self.listWidget.selectionMode = empro.gui.TableView.SingleSelection
249 self.listWidget.setColumn(0,fields)
250 self.listWidget.resizeColumnsToContents()
251 self.listWidget.resizeRowsToContents()
252 self.refreshListWidget()
253 self.listWidget.onClicked = self.listWidgetClicked
254 listBox = empro.gui.HBoxLayout()
255 listBox.addWidget(self.listWidget)
256 listBox.addStretch(1)
257 w = empro.gui.Widget()
258 w.layout = empro.gui.VBoxLayout()
259 w.layout.contentsMargin = [0,0,0,0]
260 w.layout.addWidget(self.subject)
261 w.layout.addStretch(1)
262 w.layout.addLayout(listBox)
263 self.dialog.layout.add(w)
264 self.dialog.onClicked = self.onClicked
265 self.dialog.show(True)
266
271
283
285 if (iButton.text == "OK"):
286 import empro
287 sw = empro.gui.activeScriptWindow()
288 sw.removeHighlightMarkFromAllEditors()
289 sw.activateWindow()
290 selectedRow = self.listWidget.selectedRows()
291 if selectedRow :
292 self.choice = selectedRow[0]
293
296
299 import empro
300 import cProfile
301 self._profileData= profileData
302 self._profileToolBar = ProfilerToolBar()
303 self._profiler = cProfile.Profile()
304
306 import empro
307 sw = empro.gui.activeScriptWindow()
308 sw._addProfilerAction(self._profileToolBar.profileAction)
309 sw._addCheckWhiteSpaceAction(self._profileToolBar.checkConflictingWhiteSpaceAction)
310
311
317
319 import empro
320 import os
321 import sys
322 import ast
323
324 globals_ = {"__name__": "__main__", "__file__": scriptFileName}
325 locals_ = globals_
326 emproCodeObj = compile("import empro","<string>","single")
327 self._profiler.runctx(emproCodeObj, globals_, locals_)
328 try_again = True
329 while try_again:
330 try:
331 try_again = False
332 sw = empro.gui.activeScriptWindow()
333 scriptListObj = empro.activeProject.scriptList()
334 sw.makeTab(scriptListObj.at(scriptName),True)
335 sw.activateWindow()
336 cmd = sw.scriptContent(scriptName)
337 scriptCodeObj = compile(cmd,scriptFileName,"exec")
338 self._profiler.clear()
339 self._profiler.runctx(scriptCodeObj, globals_, locals_)
340 except NameError as e:
341 actualErrorInfo = sys.exc_info()
342 try_again = True
343 try:
344 tempVar = str(e).split("'")[1]
345 except:
346 try_again = False
347 errorWindow = ErrorMessage(actualErrorInfo)
348 errorWindow.show()
349 break
350 sw = empro.gui.activeScriptWindow()
351 scriptNames = list(sw.loadedScripts())
352 scriptNametoStoredNameDict = _generateScriptNametoStoredNameDict()
353 data ={}
354 for sName in scriptNames:
355 text = sw.scriptContent(sName)
356 try:
357 tree = ast.parse(text,scriptNametoStoredNameDict[sName],'exec')
358 except:
359 continue
360 for func in tree.body:
361 if isinstance(func,ast.FunctionDef):
362 lastBody = func.body[-1]
363 while isinstance(lastBody,(ast.For,ast.While,ast.If)) :
364 lastBody = lastBody.body[-1]
365 lastLine = lastBody.lineno
366 data.setdefault(func.name,[]).append({'_func':func,'_fileName':sName,'_firstLineNo':func.lineno,'_lastLineNo':lastLine})
367 if tempVar in data.keys():
368 i = 0
369 if len (data[tempVar]) > 1:
370 i = GetChoice(tempVar,data[tempVar]).getValue()
371 if i == None:
372 quitProfiler = empro.gui.MessageBox.question("Exit Profiler","No File Selected.\nDo you want to stop Profiling?", 16384 + 65536, 16384) == 16384
373 if quitProfiler:
374 print "Profiler Stopped"
375 try_again = False
376 break
377 else:
378 continue
379 wrapped = ast.Interactive(body = [data[tempVar][i]['_func']])
380 wrapped = ast.fix_missing_locations(wrapped)
381 codeObj = compile(wrapped,data[tempVar][i]['_fileName'],'single')
382 self._profiler.runctx(codeObj, globals_, locals_)
383 else:
384 try_again = False
385 errorWindow = ErrorMessage(actualErrorInfo)
386 errorWindow.show()
387 except:
388 try_again = False
389 errorWindow = ErrorMessage(sys.exc_info())
390 errorWindow.show()
391 finally:
392 if not try_again:
393 results = self._profiler.getstats()
394 self._profileData.profileScriptName = scriptName
395 self._profileData.profileScriptFileName = scriptFileName
396 self._profileData.profileResults = results
397 self._profilerWidget = ProfilerWidget(self._profileData)
398 self._profilerWidget.show()
399
401 import empro
402 sw = empro.gui.activeScriptWindow()
403 sw.saveAllTabs()
404 scriptName = sw.currentScript()
405 if not scriptName:
406 return
407 scriptCode = sw.scriptContent(scriptName)
408 status = _conflictingWhiteSpace(scriptCode)
409 if not status:
410 status = "There are no conflicting white spaces."
411 print status
412
414 import tabnanny
415 import tokenize
416 import StringIO
417
418 try:
419 tabnanny.process_tokens(tokenize.generate_tokens(StringIO.StringIO(code).readline))
420 except tokenize.TokenError, tokenError:
421 errorMsg = map(str,tokenError)
422 return " ".join(errorMsg)
423 except tabnanny.NannyNag, nannyNag:
424 msg = "Tabs and spaces mixed at line number %s, in the line '%s'." %(nannyNag.get_lineno(),nannyNag.get_line().strip())
425 return msg
426 except IndentationError, indentError:
427 errorArgs = indentError.args
428 msg = errorArgs[0], "at line number %s, in the line '%s'."%(indentError.lineno,indentError.text.strip())
429 return " ".join(msg)
430 except:
431 import sys
432 error = sys.exc_info()[1]
433 return error
434
443
445 import empro
446 sw = empro.gui.activeScriptWindow()
447 loadedScripts = sw.loadedScripts()
448 loadedScriptsStoredName = sw.loadedScriptsStoredName()
449 scriptNametoStoredNameDict = dict(zip(loadedScripts,loadedScriptsStoredName))
450 return scriptNametoStoredNameDict
451
453 import empro
454 sw = empro.gui.activeScriptWindow()
455 sw.removeErrorMarkFromAllEditors()
456 sw.saveAllTabs()
457 sw.activateWindow()
458 scriptNametoStoredNameDict = _generateScriptNametoStoredNameDict()
459 scriptName = sw.currentScript()
460 scriptFileName = scriptNametoStoredNameDict[scriptName]
461 empro.internal.presentProfiler._profileScript(scriptName,scriptFileName)
462
464 import empro
465 empro.internal.presentProfiler = None
466 try:
467 empro.internal.profileToolbar.visible = False
468 del empro.internal.profileToolbar
469 except:
470 pass
471 finally:
472 profileData = ProfilerData()
473 empro.internal.presentProfiler = Profiler(profileData)
474 empro.internal.presentProfiler._addProfileToolBar()
475 empro.internal.presentProfiler._addProfileMenuBar()
476 sw = empro.gui.activeScriptWindow()
477 sw._onActiveScriptChanged = empro.toolkit.profiler._updateProfileToolTip
478 sw.activateWindow()
479