Menu

[r90]: / plugins / TracebackMenu.py  Maximize  Restore  History

Download this file

123 lines (98 with data), 4.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Programmer: Daniel Pozmanter
# E-mail: drpython@bluebottle.com
# Note: You must reply to the verification e-mail to get through.
#
# Copyright 2003-2004 Daniel Pozmanter
#
# Distributed under the terms of the GPL (GNU Public License)
#
# DrPython is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#Plugin
#Traceback Menu
import wx
import wx.lib.dialogs
def OnAbout(DrFrame):
Version = "Traceback Menu: Version: 1.0.2\n"
AboutString = Version + "By Daniel Pozmanter\n\nReleased under the GPL."
d = wx.lib.dialogs.ScrolledMessageDialog(DrFrame, AboutString, "About")
d.ShowModal()
d.Destroy()
def InsertTraceback(DrFrame, Position, LineNumber):
eol = DrFrame.txtDocument.GetEndOfLineCharacter()
addchar = DrFrame.txtDocument.GetIndentationString()
aistring = ""
numtabs = DrFrame.txtDocument.GetLineIndentation(LineNumber) / DrFrame.prefs.tabwidth
x = 0
while x < numtabs:
aistring = aistring + addchar
x = x + 1
aistring = aistring + addchar
insertText = eol + aistring \
+ "import sys, traceback" + eol + aistring \
+ "slist = traceback.format_tb(sys.exc_info()[2])" + eol + aistring \
+ "l = len(slist)" + eol + aistring \
+ "x = 0" + eol + aistring \
+ "rstring = \"\"" + eol + aistring \
+ "while x < l:" + eol + aistring \
+ addchar + "rstring = rstring + slist[x]" + eol + aistring \
+ addchar + "x = x + 1" + eol + aistring \
+ "print \"Traceback (most recent call last):\\n\" + rstring \\" + eol + aistring \
+ "+ str(sys.exc_info()[0]).lstrip(\"exceptions.\") + \": \" + str(sys.exc_info()[1])" + eol
#Add Tag:
insertText = eol + "#***DRPYTHON TRACEBACK***" + eol + insertText + eol + "#***END DRPYTHON TRACEBACK***"
DrFrame.txtDocument.InsertText(Position, insertText)
def Plugin(DrFrame):
def OnAddTracebacks(event):
pos = 0
while pos < DrFrame.txtDocument.GetLength():
exceptpos = DrFrame.txtDocument.GetText()[pos:].find("except:")
if exceptpos > -1:
exceptpos = pos + exceptpos + 7
DrFrame.txtDocument.SetCurrentPos(exceptpos)
InsertTraceback(DrFrame, exceptpos, DrFrame.txtDocument.GetCurrentLine())
pos = exceptpos
else:
pos = DrFrame.txtDocument.GetLength() + 1
def OnInsertTraceback(event):
InsertTraceback(DrFrame, DrFrame.txtDocument.GetCurrentPos(), DrFrame.txtDocument.GetCurrentLine())
def OnRemoveTracebacks(event):
text = DrFrame.txtDocument.GetText()
l = len("#***END DRPYTHON TRACEBACK***")
start = text.find("#***DRPYTHON TRACEBACK***")
end = text.find("#***END DRPYTHON TRACEBACK***") + l
while start > -1:
text = text[:start] + text[end:]
start = text.find("#***DRPYTHON TRACEBACK***")
end = text.find("#***END DRPYTHON TRACEBACK***") + l
DrFrame.txtDocument.SetText(text)
ID_INSERT_TRACEBACK = DrFrame.GetNewId()
ID_ADD_TRACEBACKS = DrFrame.GetNewId()
ID_REMOVE_TRACEBACKS = DrFrame.GetNewId()
DrFrame.LoadPluginShortcuts('TracebackMenu')
tracebackmenu = wx.Menu()
tracebackmenu.Append(ID_INSERT_TRACEBACK, "Insert Traceback")
tracebackmenu.Append(ID_ADD_TRACEBACKS, "Add Tracebacks")
tracebackmenu.Append(ID_REMOVE_TRACEBACKS, "Remove All Tracebacks")
DrFrame.editmenu.AppendSeparator()
DrFrame.editmenu.AppendMenu(DrFrame.GetNewId(), "Tracebacks", tracebackmenu)
DrFrame.Bind(wx.EVT_MENU, OnInsertTraceback, id=ID_INSERT_TRACEBACK)
DrFrame.Bind(wx.EVT_MENU, OnAddTracebacks, id=ID_ADD_TRACEBACKS)
DrFrame.Bind(wx.EVT_MENU, OnRemoveTracebacks, id=ID_REMOVE_TRACEBACKS)
DrFrame.AddPluginShortcutFunction("TracebackMenu", "OnInsertTraceback", OnInsertTraceback)
DrFrame.AddPluginShortcutFunction("TracebackMenu", "OnAddTracebacks", OnAddTracebacks)
DrFrame.AddPluginShortcutFunction("TracebackMenu", "OnRemoveTracebacks", OnRemoveTracebacks)
DrFrame.AddPluginPopUpMenuFunction("TracebackMenu", "Insert Traceback", OnInsertTraceback)
DrFrame.AddPluginPopUpMenuFunction("TracebackMenu", "Add Tracebacks", OnAddTracebacks)
DrFrame.AddPluginPopUpMenuFunction("TracebackMenu", "Remove Tracebacks", OnRemoveTracebacks)