# 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
#A Simple Graphical User Interface to a tweaked version of the Python Debugger
import sys, os.path, re, socket, string, time
import wx
import drPrefsFile
##import drPositionChooser
def OnAbout(DrFrame):
AboutString = """Simple Debugger:
Version: 0.0.5
By Daniel Pozmanter
Released under the GPL.
Credits:
Matthew Thornley: 3 Bug-Reports.
Franz Steinhausler: Bug-Report.
"""
DrFrame.ShowMessage(AboutString, "About")
def OnHelp(DrFrame):
HelpString = """SimpleDebugger Documentation:
This plugin simply provides a connection between
DrPython and Pdb. The commands are exactly the same.
To run a pdb command while debugging:
Send Raw Command to Pdb
The Commands Panel lets you set a list
of commands sent directly to pdb,
as though you had typed them in.
These commands are run every time
you start the debugger.
When you add a variable watch, the value will be automatically
reported every time you run "Step" or "Next".
"""
DrFrame.ShowMessage(HelpString, "SimpleDebugger: Help")
def checkandremove(plugindir, pngname):
if os.path.exists(plugindir + "/bitmaps/16/" + pngname + ".png"):
os.remove(plugindir + "/bitmaps/16/" + pngname + ".png")
if os.path.exists(plugindir + "/bitmaps/24/" + pngname + ".png"):
os.remove(plugindir + "/bitmaps/24/" + pngname + ".png")
def UnInstall(DrFrame):
plugindir = DrFrame.GetPluginDirectory()
if os.path.exists(plugindir + "/SimpleDebugger/drPythonDebugger.py"):
os.remove(plugindir + "/SimpleDebugger/drPythonDebugger.py")
os.rmdir(plugindir + "/SimpleDebugger")
checkandremove(plugindir, 'debug')
checkandremove(plugindir, 'continue')
checkandremove(plugindir, 'down')
checkandremove(plugindir, 'next')
checkandremove(plugindir, 'step')
checkandremove(plugindir, 'toggledebuggerpanel')
checkandremove(plugindir, 'up')
DrFrame.RemovePluginIcon("Debug The Current Document")
DrFrame.RemovePluginIcon("Continue")
DrFrame.RemovePluginIcon("Move Down a Frame")
DrFrame.RemovePluginIcon("Next")
DrFrame.RemovePluginIcon("Step")
DrFrame.RemovePluginIcon("Toggle Debugger Panel")
DrFrame.RemovePluginIcon("Move Up a Frame")
return True
class OutputPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.theSizer = wx.BoxSizer(wx.VERTICAL)
self.txtOutput = wx.TextCtrl(self, -1, "", wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE | wx.TE_READONLY)
self.theSizer.Add(self.txtOutput, 9, wx.EXPAND)
self.SetAutoLayout(True)
self.SetSizer(self.theSizer)
class CommandsPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.theSizer = wx.BoxSizer(wx.VERTICAL)
self.txtCommands = wx.TextCtrl(self, -1, "", wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE)
self.theSizer.Add(self.txtCommands, 9, wx.EXPAND)
self.SetAutoLayout(True)
self.SetSizer(self.theSizer)
class VariableWatchPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.ID_VARIABLES = 12001
self.Lines = []
self.theSizer = wx.BoxSizer(wx.VERTICAL)
self.boxVariables = wx.ListCtrl(self, self.ID_VARIABLES, wx.DefaultPosition, wx.Size(200, 200), wx.LC_REPORT)
self.theSizer.Add(self.boxVariables, 9, wx.EXPAND)
self.boxVariables.InsertColumn(0, "Variable")
self.boxVariables.InsertColumn(1, "Value")
self.SetAutoLayout(True)
self.SetSizer(self.theSizer)
self.Bind(wx.EVT_SIZE, self.OnSize)
def OnSize(self, event):
width = self.GetSizeTuple()[0]
lwidth = int(width * .4)
rwidth = int(width * .6)
self.boxVariables.SetColumnWidth(0, lwidth)
self.boxVariables.SetColumnWidth(1, rwidth)
event.Skip()
class DebuggerPanel(wx.Panel):
def __init__(self, parent, id, Position):
wx.Panel.__init__(self, parent, id)
self.ID_CLOSE = 12002
self.theSizer = wx.BoxSizer(wx.VERTICAL)
self.nbDebugger = wx.Notebook(self, -1)
self.VariableWatchesPanel = VariableWatchPanel(self.nbDebugger, -1)
self.CommandsPanel = CommandsPanel(self.nbDebugger, -1)
self.OutputPanel = OutputPanel(self.nbDebugger, -1)
self.nbDebugger.AddPage(self.VariableWatchesPanel, "Watches")
self.nbDebugger.AddPage(self.CommandsPanel, "Commands")
self.nbDebugger.AddPage(self.OutputPanel, "Output")
self.theSizer.Add(self.nbDebugger, 9, wx.EXPAND)
self.bSizer = wx.BoxSizer(wx.HORIZONTAL)
self.btnClose = wx.Button(self, self.ID_CLOSE, "&Close")
self.bSizer.Add(self.btnClose, 0, wx.SHAPED | wx.ALIGN_RIGHT)
self.theSizer.Add(self.bSizer, 0, wx.EXPAND)
self.parent = parent
self.panelparent = parent.GetGrandParent().GetParent()
self.grandparent = parent.GetGrandParent().GetGrandParent().GetParent()
self.SetAutoLayout(True)
self.SetSizer(self.theSizer)
self.Bind(wx.EVT_BUTTON, self.OnbtnClose, id=self.ID_CLOSE)
def AddText(self, text):
self.OutputPanel.txtOutput.AppendText(text)
def AddWatch(self, variablename, value):
self.VariableWatchesPanel.boxVariables.InsertStringItem(0, variablename)
self.VariableWatchesPanel.boxVariables.SetStringItem(0, 1, str(value))
def Clear(self):
self.VariableWatchesPanel.boxVariables.DeleteAllItems()
self.OutputPanel.SetText("")
def GetCommands(self):
return self.CommandsPanel.txtCommands.GetValue()
def OnbtnClose(self, event):
self.grandparent.txtDocument.DebuggerPanel = None
self.panelparent.ClosePanel(self.Position, self.Index)
def UpdateWatch(self, variablename, value):
i = self.VariableWatchesPanel.boxVariables.FindItem(-1, variablename)
self.VariableWatchesPanel.boxVariables.SetStringItem(i, 1, str(value))
class SimpleDebuggerPrefsDialog(wx.Dialog):
def __init__(self, parent, id):
wx.Dialog.__init__(self, parent, id, "Simple Debugger Preferences", wx.Point(50, 50), wx.Size(-1, -1), wx.DEFAULT_DIALOG_STYLE | wx.MAXIMIZE_BOX | wx.THICK_FRAME | wx.RESIZE_BORDER)
self.parent = parent
self.theSizer = wx.FlexGridSizer(8, 3, 5, 10)
self.ID_CLOSE = 101
self.ID_SAVE = 105
self.ID_BROWSE = 110
self.txtpdb = wx.TextCtrl(self, -1, "", wx.Point(225, 215), wx.Size(250, -1))
self.positionchooser = drPositionChooser.drPositionChooser(self)
self.txtpdb.SetValue(self.parent.DEBUGGERDOCLOCATION)
self.positionchooser.SetValue(self.parent.DEBUGGERPANELPOSITION)
self.btnBrowseP = wx.Button(self, self.ID_BROWSE, " &Browse ")
self.theSizer = wx.FlexGridSizer(4, 3, 5, 10)
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
self.theSizer.Add(wx.StaticText(self, -1, "Pdb Documentation:"),1,wx.SHAPED)
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
self.theSizer.Add(self.txtpdb, 1, wx.SHAPED)
self.theSizer.Add(self.btnBrowseP, 1, wx.SHAPED)
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
self.theSizer.Add(wx.StaticText(self, -1, "Position:"), 1, wx.SHAPED)
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
self.theSizer.Add(self.positionchooser ,1,wx.SHAPED)
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
self.buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
self.btnCancel = wx.Button(self, self.ID_CLOSE, " &Close ")
self.btnCancel.SetDefault()
self.btnSave = wx.Button(self, self.ID_SAVE, " &Save And Update ")
self.buttonSizer.Add(self.btnCancel, 0, wx.SHAPED)
self.buttonSizer.Add(self.btnSave, 0, wx.SHAPED)
self.theSizer.Add(wx.StaticText(self, -1, " "), 0, wx.SHAPED | wx.ALIGN_CENTER)
self.theSizer.Add(self.buttonSizer, 0, wx.SHAPED | wx.ALIGN_CENTER)
self.SetAutoLayout(True)
self.SetSizerAndFit(self.theSizer)
self.Bind(wx.EVT_BUTTON, self.OnbtnClose, id=self.ID_CLOSE)
self.Bind(wx.EVT_BUTTON, self.OnbtnSave, id=self.ID_SAVE)
self.Bind(wx.EVT_BUTTON, self.OnbtnBrowseDoc, id=self.ID_BROWSE)
def OnbtnBrowseDoc(self, event):
result = ""
dlg = wx.FileDialog(self, "Location of Pdb Documentation", "", "", "All files (*)|*", wx.OPEN)
if (dlg.ShowModal() == wx.ID_OK):
result = dlg.GetPath()
dlg.Destroy()
if len(result) > 0:
self.txtpdb.SetValue(result)
def OnbtnClose(self, event):
self.EndModal(0)
def OnbtnSave(self, event):
if (not os.path.exists(self.parent.homedirectory)):
d = drScrolledMessageDialog.ScrolledMessageDialog(self, ("Dude, you've got some problems...\nYour homedirectory (" + self.parent.homedirectory + ") does not exist!\nLet's not bother speculating about how or why.\nRead the help file for this truly screwed up situation.\nDrPython will now politely ignore your request to save.\nTry again when you have fixed this problem."), "Huge Error")
d.ShowModal()
d.Destroy()
return
self.parent.DEBUGGERDOCLOCATION = self.txtpdb.GetValue()
self.parent.DEBUGGERPANELPOSITION = int(self.radposition.GetSelection())
preffile = self.parent.homedirectory + "/plugins/SimpleDebugger.preferences.dat"
f = file(preffile, 'w')
f.write("<simple.debugger.pdb.documentation.location>" + self.parent.DEBUGGERDOCLOCATION + "</simple.debugger.pdb.documentation.location>\n")
f.write("<simple.debugger.panel.position>" + str(self.parent.DEBUGGERPANELPOSITION) + "</simple.debugger.panel.position>\n")
f.close()
if self.GetParent().prefs.enablefeedback:
DrFrame.ShowMessage(("Succesfully wrote to:\n" + preffile + "\nand updated the current instance of DrPython."), "Saved Preferences")
def OnPreferences(DrFrame):
d = SimpleDebuggerPrefsDialog(DrFrame, -1)
d.ShowModal()
d.Destroy()
def Plugin(DrFrame):
def DoCommand(command):
if (DrFrame.txtPrompt.process is not None):
DrFrame.txtPrompt.DebuggerConnection.send(command + "\n")
if len(DrFrame.Watches) > 0:
DrFrame.txtPrompt.DebuggerConnection.send('p ' + string.join(DrFrame.Watches, ' ') + '\n')
text = DrFrame.txtPrompt.DebuggerConnection.recv(100000)
DrFrame.DebuggerPanel.AddText(text)
if len(text) < 1:
DrFrame.txtPrompt.pid = -1
return
UpdatePosition(text)
for variable in DrFrame.Watches:
reDebugVariableStart = re.compile('\*\*\*' + variable + '\*\*\*', re.M)
reDebugVariableEnd = re.compile('\*\*\*/' + variable + '\*\*\*', re.M)
varstart = reDebugVariableStart.search(text)
varend = reDebugVariableEnd.search(text)
if (varstart is not None) and (varend is not None):
variablevalue = text[varstart.end():varend.start()]
try:
DrFrame.DebuggerPanel.UpdateWatch(variable, variablevalue)
except:
pass
def OnAddBreakpoint(event):
d = wx.TextEntryDialog(DrFrame, "Line Number for the breakpoint:", "Add Breakpoint", str(DrFrame.txtDocument.GetCurrentLine() + 1))
answer = d.ShowModal()
d.Destroy()
if answer == wx.ID_OK:
try:
x = int(d.GetValue()) - 1
except:
DrFrame.ShowMessage("You must enter an integer (number, eg 1,2,128)", "DrPython")
return
DrFrame.txtDocument.MarkerDefine(0, wx.stc.STC_MARK_CIRCLE, DrFrame.txtDocument.marginbackground, DrFrame.txtDocument.marginforeground)
if (x > -1) and (x < DrFrame.txtDocument.GetLineCount()):
line = DrFrame.txtDocument.GetLine(x).strip(' ')
if (line and not line.startswith('#')):
if len(DrFrame.breakpoints) == 0:
DrFrame.txtDocument.SetMarginWidth(0, 10)
DrFrame.txtDocument.MarkerAdd(x, 0)
DrFrame.breakpoints.append(x)
else:
DrFrame.ShowMessage(("Line number: " + str(x + 1) + "\nIs either a comment, or whitespace"), "DrPython")
else:
DrFrame.ShowMessage("Line number does not exist", "DrPython")
return
def OnAddWatch(event):
d = wx.TextEntryDialog(DrFrame, "Enter Variable Name:", "Add Variable Watch", "")
answer = d.ShowModal()
d.Destroy()
if answer == wx.ID_OK:
var = d.GetValue()
DrFrame.Watches.append(var)
try:
DrFrame.DebuggerPanel.AddWatch(var, '<No Value>')
except:
pass
def OnContinue(event):
if DrFrame.txtPrompt.pid == -1:
return
DoCommand('c')
def OnDown(event):
if DrFrame.txtPrompt.pid == -1:
return
DoCommand('d')
def OnNext(event):
if DrFrame.txtPrompt.pid == -1:
return
DoCommand('n')
def OnProcessEnded(event):
#First, check for any leftover output.
try:
DrFrame.OpenFile(DrFrame.txtDocument.debugfile, False, False)
DrFrame.txtPrompt.DebuggerConnection.close()
except:
pass
DrFrame.txtPrompt.OnIdle(event)
if len(DrFrame.breakpoints) < 1:
DrFrame.txtDocument.SetMarginWidth(0, 0)
DrFrame.txtDocument.lastmarker = -1
#Set the process info to the correct position in the array.
i = 0
epid = event.GetPid()
try:
i = map(lambda tprompt: tprompt.pid == epid, DrFrame.txtPromptArray).index(True)
except:
return
#If this is the process for the current window:
if DrFrame.docPosition == i:
DrFrame.txtPrompt.process.Destroy()
DrFrame.txtPrompt.process = None
DrFrame.txtPrompt.pid = -1
DrFrame.txtPrompt.SetReadOnly(1)
DrFrame.txtPrompt.pythonintepreter = 0
DrFrame.UpdateMenuAndToolbar()
DrFrame.SetStatusText("", 2)
else:
DrFrame.txtPromptArray[i].process.Destroy()
DrFrame.txtPromptArray[i].process = None
DrFrame.txtPromptArray[i].pid = -1
DrFrame.txtPromptArray[i].SetReadOnly(1)
DrFrame.txtPromptArray[i].pythonintepreter = 0
def OnRawCommand(event):
d = wx.TextEntryDialog(DrFrame, "Enter Pdb Command:", "Send Raw Command to Pdb", "")
answer = d.ShowModal()
v = d.GetValue()
d.Destroy()
if (answer == wx.ID_OK):
DoCommand(v)
def OnRemoveAllBreakpoints(event):
l = len(DrFrame.breakpoints)
if (l > 0):
d = wx.MessageDialog(DrFrame, "This will remove all breakpoints\nAre you sure you want to do this?", "DrPython", wx.YES_NO | wx.ICON_QUESTION)
answer = d.ShowModal()
d.Destroy()
if (answer == wx.ID_YES):
l = DrFrame.txtDocument.GetLineCount()
x = 0
while (x < l):
i = DrFrame.breakpoints.count(x)
if (i > 0):
i = DrFrame.breakpoints.index(x)
DrFrame.breakpoints.pop(i)
DrFrame.txtDocument.MarkerDelete(x, 0)
x = x + 1
DrFrame.txtDocument.SetMarginWidth(0, 0)
def OnRemoveBreakpoint(event):
l = len(DrFrame.breakpoints)
if (l > 0):
d = wx.TextEntryDialog(DrFrame, "Line Number for the breakpoint:", "Add Breakpoint", str(DrFrame.txtDocument.GetCurrentLine() + 1))
answer = d.ShowModal()
d.Destroy()
if answer == wx.ID_OK:
try:
x = int(d.GetValue()) - 1
except:
DrFrame.ShowMessage("You must enter an integer (number, eg 1,2,128)", "DrPython")
return
try:
i = DrFrame.breakpoints.index(x)
except:
DrFrame.ShowMessage("Breakpoint(" + str(x + 1) + ") does not exist", "DrPython")
return
DrFrame.breakpoints.pop(i)
DrFrame.txtDocument.MarkerDelete(x, 0)
if len(DrFrame.breakpoints) == 0:
DrFrame.txtDocument.SetMarginWidth(0, 0)
def OnRemoveWatch(event):
d = wx.SingleChoiceDialog(DrFrame, 'Remove Watch:', "SimpleDebugger", DrFrame.Watches, wx.CHOICEDLG_STYLE)
d.SetSize(wx.Size(250, 250))
answer = d.ShowModal()
d.Destroy()
if (answer == wx.ID_OK):
i = d.GetSelection()
try:
DrFrame.Watches.pop(i)
except:
pass
def OnRunWithDebugger(event):
if (DrFrame.txtDocument.GetModify()):
d = wx.MessageDialog(DrFrame, "The file has been modified.\nIt would be wise to save before running.\nWould you like to save the file?", "DrPython", wx.YES_NO | wx.ICON_QUESTION)
answer = d.ShowModal()
d.Destroy()
if (answer == wx.ID_YES):
DrFrame.OnSave(event)
DrFrame.txtDocument.lastmarker = -1
DrFrame.txtDocument.SetMarginWidth(0, 10)
DrFrame.txtDocument.MarkerDefine(1, wx.stc.STC_MARK_ARROW, DrFrame.txtDocument.marginbackground, DrFrame.txtDocument.marginforeground)
DrFrame.txtDocument.debugfile = DrFrame.txtDocument.filename
largs = ""
if (len(DrFrame.lastprogargs) > 0):
largs = ' ' + DrFrame.lastprogargs
HOST = 'localhost'
PORT = 59000 + DrFrame.docPosition
DrFrame.txtPrompt.DebuggerSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
DrFrame.txtPrompt.DebuggerSocket.bind((HOST, PORT))
pdbstring = DrFrame.GetPluginDirectory() + "/SimpleDebugger/drPythonDebugger.py" + '" "' + str(PORT)
DrFrame.txtPrompt.DebuggerSocket.listen(1)
if DrFrame.PLATFORM_IS_WIN:
DrFrame.runcommand((DrFrame.pythexecw + ' -u ' + DrFrame.prefs.pythonargs + ' "' + pdbstring + '" "' + DrFrame.txtDocument.filename.replace('\\', '/') + '"' + largs), 'Running With PDB')
else:
DrFrame.runcommand((DrFrame.pythexec + ' -u ' + DrFrame.prefs.pythonargs + ' "' + pdbstring + '" "' + DrFrame.txtDocument.filename + '"' + largs), 'Running With PDB')
DrFrame.txtPrompt.DebuggerConnection, addr = DrFrame.txtPrompt.DebuggerSocket.accept()
ShowDebuggerPanel()
cmds = DrFrame.DebuggerPanel.GetCommands()
wx.Yield()
wx.BeginBusyCursor()
time.sleep(1)
try:
l = len(DrFrame.breakpoints)
if (l > 0):
for x in xrange(l):
DoCommand("break " + str(DrFrame.breakpoints[x] + 1) + '\n')
DoCommand('s')
DrFrame.txtPrompt.DebuggerConnection.send(cmds + '\n')
except Exception, e:
DrFrame.txtPrompt.AddText('\n' + str(e) + '\n')
pass
wx.EndBusyCursor()
def OnStep(event):
if DrFrame.txtPrompt.pid == -1:
return
DoCommand('s')
def OnToggleDebuggerPanel(event):
try:
x = DrFrame.DebuggerPanel
except:
DrFrame.DebuggerPanel = None
if not (DrFrame.DebuggerPanel):
target, i = DrFrame.mainpanel.GetTargetNotebookPage(DrFrame.DebuggerPanelPositon,"SimpleDebugger")
DrFrame.DebuggerPanel = DebuggerPanel(target, -1, DrFrame.DebuggerPanelPositon)
target.SetPanel(DrFrame.DebuggerPanel )
DrFrame.mainpanel.ShowPanel(DrFrame.DebuggerPanelPositon, i)
DrFrame.DebuggerPanel.PanelPosition=DrFrame.DebuggerPanelPositon
DrFrame.DebuggerPanel.PanelIndex=i
DrFrame.currentpage.OnSize(None)
else:
if not DrFrame.mainpanel.IsVisible(DrFrame.DebuggerPanel.PanelPosition, DrFrame.DebuggerPanel.PanelIndex):
DrFrame.mainpanel.ShowPanel(DrFrame.DebuggerPanel.PanelPosition, DrFrame.DebuggerPanel.PanelIndex, True)
else:
DrFrame.mainpanel.ShowPanel(DrFrame.DebuggerPanel.PanelPosition, DrFrame.DebuggerPanel.PanelIndex, False)
def OnViewPdbDocs(event):
wx.Execute((DrFrame.prefs.documentationbrowser + ' "' + DrFrame.DEBUGGERDOCLOCATION + '"'), wx.EXEC_ASYNC)
def OnUp(event):
if DrFrame.txtPrompt.pid == -1:
return
DoCommand('u')
def ShowDebuggerPanel():
try:
x = DrFrame.DebuggerPanel
except:
DrFrame.DebuggerPanel = None
if not (DrFrame.DebuggerPanel):
target, i = DrFrame.mainpanel.GetTargetNotebookPage(DrFrame.DebuggerPanelPositon,"SimpleDebugger")
DrFrame.DebuggerPanel = DebuggerPanel(target, -1, DrFrame.DebuggerPanelPositon)
target.SetPanel(DrFrame.DebuggerPanel )
DrFrame.mainpanel.ShowPanel(DrFrame.DebuggerPanelPositon, i)
DrFrame.DebuggerPanel.PanelPosition=DrFrame.DebuggerPanelPositon
DrFrame.DebuggerPanel.PanelIndex=i
DrFrame.currentpage.OnSize(None)
else:
DrFrame.mainpanel.ShowPanel(DrFrame.DebuggerPanel.PanelPosition, DrFrame.DebuggerPanel.PanelIndex, True)
try:
DrFrame.DebuggerPanel.Clear()
except:
pass
for Watch in DrFrame.Watches:
DrFrame.DebuggerPanel.AddWatch(Watch, '<No Value>')
def UpdatePosition(text):
fnmatch = DrFrame.reDebugLine.search(text)
fnmatchend = DrFrame.reDebugLineEnd.search(text)
fnFmatch = DrFrame.reDebugFilename.search(text)
if (fnmatch is not None) and (fnmatchend is not None) and (fnFmatch is not None):
linenumber = text[fnmatch.end():fnmatchend.start()]
filename = text[fnFmatch.start():fnFmatch.end()]
### windows case insensitive/backslash fix
if (os.path.normcase(filename) != os.path.normcase(DrFrame.txtDocument.filename)):
alreadyopen = map(lambda x: os.path.normcase(x.filename), DrFrame.txtDocumentArray)
if os.path.normcase(filename) in alreadyopen:
i = alreadyopen.index(filename)
DrFrame.setDocumentTo(i)
elif os.path.exists(filename):
DrFrame.OpenFile(filename, True, False)
try:
currentline = int(linenumber)-1
DrFrame.txtDocument.GotoLine(currentline)
hfrom = DrFrame.txtDocument.GetCurrentPos()
hto = DrFrame.txtDocument.GetLineEndPosition(currentline)
DrFrame.txtDocument.SetSelection(hfrom, hto)
if DrFrame.txtDocument.lastmarker > -1:
DrFrame.txtDocument.MarkerDelete(DrFrame.txtDocument.lastmarker, 1)
DrFrame.txtDocument.MarkerAdd(currentline, 1)
DrFrame.txtDocument.lastmarker = currentline
except:
pass
#Preferences:
DrFrame.DEBUGGERDOCLOCATION = "http://www.python.org/doc/current/lib/module-pdb.html"
DrFrame.DEBUGGERPANELPOSITION = 0
if os.path.exists(DrFrame.homedirectory + "/plugins/SimpleDebugger.preferences.dat"):
f = file(DrFrame.homedirectory + "/plugins/SimpleDebugger.preferences.dat", 'r')
text = f.read()
f.close()
DrFrame.DEBUGGERDOCLOCATION = drPrefsFile.GetPrefFromText(DrFrame.DEBUGGERDOCLOCATION, text, "simple.debugger.pdb.documentation.location")
DrFrame.DEBUGGERPANELPOSITION = drPrefsFile.GetPrefFromText(DrFrame.DEBUGGERPANELPOSITION, text, "simple.debugger.panel.position", True)
#End Preferences
DrFrame.breakpoints = []
DrFrame.DebuggerPanelPositon = DrFrame.DEBUGGERPANELPOSITION
DrFrame.reDebugLine = re.compile('^.*?\(', re.M)
DrFrame.reDebugLineEnd = re.compile('\).*?\(', re.M)
DrFrame.reDebugFilename = re.compile('^.*?\.py', re.M)
DrFrame.Bind(wx.EVT_END_PROCESS, OnProcessEnded, id=-1)
DrFrame.Watches = []
ID_PYTHON_DEBUGGER = DrFrame.GetNewId()
ID_STEP = DrFrame.GetNewId()
ID_NEXT = DrFrame.GetNewId()
ID_CONTINUE = DrFrame.GetNewId()
ID_UP = DrFrame.GetNewId()
ID_DOWN = DrFrame.GetNewId()
ID_ADD_WATCH = DrFrame.GetNewId()
ID_REMOVE_WATCH = DrFrame.GetNewId()
ID_ADD_BREAKPOINT = DrFrame.GetNewId()
ID_REMOVE_BREAKPOINT = DrFrame.GetNewId()
ID_REMOVE_ALL_BREAKPOINTS = DrFrame.GetNewId()
ID_RAW_COMMAND = DrFrame.GetNewId()
ID_TOGGLE_DEBUGGER_PANEL = DrFrame.GetNewId()
ID_VIEW_PDB_DOCUMENTATION = DrFrame.GetNewId()
DrFrame.programmenu.AppendSeparator()
DrFrame.programmenu.Append(ID_PYTHON_DEBUGGER, "Debug The Current Document")
DrFrame.programmenu.AppendSeparator()
DrFrame.programmenu.Append(ID_STEP, "Step")
DrFrame.programmenu.Append(ID_NEXT, "Next")
DrFrame.programmenu.Append(ID_CONTINUE, "Continue")
DrFrame.programmenu.Append(ID_UP, "Move Up a Frame")
DrFrame.programmenu.Append(ID_DOWN, "Move Down a Frame")
DrFrame.programmenu.AppendSeparator()
DrFrame.programmenu.Append(ID_ADD_WATCH, "Add Variable Watch")
DrFrame.programmenu.Append(ID_REMOVE_WATCH, "Remove Variable Watch")
DrFrame.programmenu.AppendSeparator()
DrFrame.programmenu.Append(ID_ADD_BREAKPOINT, "&Add Breakpoint...")
DrFrame.programmenu.Append(ID_REMOVE_BREAKPOINT, "Remove &Breakpoint...")
DrFrame.programmenu.Append(ID_REMOVE_ALL_BREAKPOINTS, "Remove &All Breakpoints...")
DrFrame.programmenu.AppendSeparator()
DrFrame.programmenu.Append(ID_RAW_COMMAND, "Send Raw Command to Pdb...")
DrFrame.viewmenu.AppendSeparator()
DrFrame.viewmenu.Append(ID_TOGGLE_DEBUGGER_PANEL, "Toggle Debugger Panel...")
DrFrame.helpmenu.AppendSeparator()
DrFrame.helpmenu.Append(ID_VIEW_PDB_DOCUMENTATION, "Pdb Documentation")
DrFrame.Bind(wx.EVT_MENU, OnRunWithDebugger, id=ID_PYTHON_DEBUGGER)
DrFrame.Bind(wx.EVT_MENU, OnStep, id=ID_STEP)
DrFrame.Bind(wx.EVT_MENU, OnNext, id=ID_NEXT)
DrFrame.Bind(wx.EVT_MENU, OnContinue, id=ID_CONTINUE)
DrFrame.Bind(wx.EVT_MENU, OnUp, id=ID_UP)
DrFrame.Bind(wx.EVT_MENU, OnDown, id=ID_DOWN)
DrFrame.Bind(wx.EVT_MENU, OnAddWatch, id=ID_ADD_WATCH)
DrFrame.Bind(wx.EVT_MENU, OnRemoveWatch, id=ID_REMOVE_WATCH)
DrFrame.Bind(wx.EVT_MENU, OnAddBreakpoint, id=ID_ADD_BREAKPOINT)
DrFrame.Bind(wx.EVT_MENU, OnRemoveBreakpoint, id=ID_REMOVE_BREAKPOINT)
DrFrame.Bind(wx.EVT_MENU, OnRemoveAllBreakpoints, id=ID_REMOVE_ALL_BREAKPOINTS)
DrFrame.Bind(wx.EVT_MENU, OnToggleDebuggerPanel, id=ID_TOGGLE_DEBUGGER_PANEL)
DrFrame.Bind(wx.EVT_MENU, OnRawCommand, id=ID_RAW_COMMAND)
DrFrame.Bind(wx.EVT_MENU, OnViewPdbDocs, id=ID_VIEW_PDB_DOCUMENTATION)
DrFrame.AddPluginFunction("SimpleDebugger", "Debug The Current Document", OnRunWithDebugger)
DrFrame.AddPluginFunction("SimpleDebugger", "Step", OnStep)
DrFrame.AddPluginFunction("SimpleDebugger", "Next", OnNext)
DrFrame.AddPluginFunction("SimpleDebugger", "Continue", OnContinue)
DrFrame.AddPluginFunction("SimpleDebugger", "Move Up a Frame", OnUp)
DrFrame.AddPluginFunction("SimpleDebugger", "Move Down a Frame", OnDown)
DrFrame.AddPluginFunction("SimpleDebugger", "Add Variable Watch", OnAddWatch)
DrFrame.AddPluginFunction("SimpleDebugger", "Remove Variable Watch", OnRemoveWatch)
DrFrame.AddPluginFunction("SimpleDebugger", "Add Breakpoint", OnAddBreakpoint)
DrFrame.AddPluginFunction("SimpleDebugger", "Remove Breakpoint", OnRemoveBreakpoint)
DrFrame.AddPluginFunction("SimpleDebugger", "Remove All Breakpoints", OnRemoveAllBreakpoints)
DrFrame.AddPluginFunction("SimpleDebugger", "Send Raw Command to Pdb", OnRawCommand)
DrFrame.AddPluginFunction("SimpleDebugger", "Toggle Debugger Panel", OnToggleDebuggerPanel)
DrFrame.AddPluginFunction("SimpleDebugger", "Pdb Documentation", OnViewPdbDocs)