📄 debuggerservice.py
字号:
self._executor.Execute(initialArgs, startIn, environment)
def ExecutorFinished(self):
self._tb.EnableTool(self.KILL_PROCESS_ID, False)
nb = self.GetParent()
for i in range(0,nb.GetPageCount()):
if self == nb.GetPage(i):
text = nb.GetPageText(i)
newText = text.replace("Running", "Finished")
nb.SetPageText(i, newText)
break
def StopExecution(self):
if not self._stopped:
self._stopped = True
self.Unbind(EVT_UPDATE_STDTEXT)
self.Unbind(EVT_UPDATE_ERRTEXT)
self._executor.DoStopExecution()
def AppendText(self, event):
self._textCtrl.SetReadOnly(False)
self._textCtrl.AddText(event.value)
self._textCtrl.ScrollToLine(self._textCtrl.GetLineCount())
self._textCtrl.SetReadOnly(True)
def AppendErrorText(self, event):
self._textCtrl.SetReadOnly(False)
self._textCtrl.SetFontColor(wx.RED)
self._textCtrl.StyleClearAll()
self._textCtrl.AddText(event.value)
self._textCtrl.ScrollToLine(self._textCtrl.GetLineCount())
self._textCtrl.SetFontColor(wx.BLACK)
self._textCtrl.StyleClearAll()
self._textCtrl.SetReadOnly(True)
def StopAndRemoveUI(self, event):
self.StopExecution()
self.StopExecution()
index = self._noteBook.GetSelection()
self._noteBook.GetPage(index).Show(False)
self._noteBook.RemovePage(index)
#------------------------------------------------------------------------------
# Event handling
#-----------------------------------------------------------------------------
def OnToolClicked(self, event):
id = event.GetId()
if id == self.KILL_PROCESS_ID:
self.StopExecution()
elif id == self.CLOSE_TAB_ID:
self.StopAndRemoveUI(event)
def OnDoubleClick(self, event):
# Looking for a stack trace line.
lineText, pos = self._textCtrl.GetCurLine()
fileBegin = lineText.find("File \"")
fileEnd = lineText.find("\", line ")
lineEnd = lineText.find(", in ")
if lineText == "\n" or fileBegin == -1 or fileEnd == -1 or lineEnd == -1:
# Check the line before the one that was clicked on
lineNumber = self._textCtrl.GetCurrentLine()
if(lineNumber == 0):
return
lineText = self._textCtrl.GetLine(lineNumber - 1)
fileBegin = lineText.find("File \"")
fileEnd = lineText.find("\", line ")
lineEnd = lineText.find(", in ")
if lineText == "\n" or fileBegin == -1 or fileEnd == -1 or lineEnd == -1:
return
filename = lineText[fileBegin + 6:fileEnd]
lineNum = int(lineText[fileEnd + 8:lineEnd])
foundView = None
openDocs = wx.GetApp().GetDocumentManager().GetDocuments()
for openDoc in openDocs:
if openDoc.GetFilename() == filename:
foundView = openDoc.GetFirstView()
break
if not foundView:
doc = wx.GetApp().GetDocumentManager().CreateDocument(filename, wx.lib.docview.DOC_SILENT)
foundView = doc.GetFirstView()
if foundView:
foundView.GetFrame().SetFocus()
foundView.Activate()
foundView.GotoLine(lineNum)
startPos = foundView.PositionFromLine(lineNum)
lineText = foundView.GetCtrl().GetLine(lineNum - 1)
foundView.SetSelection(startPos, startPos + len(lineText.rstrip("\n")))
import OutlineService
wx.GetApp().GetService(OutlineService.OutlineService).LoadOutline(foundView, position=startPos)
DEFAULT_PORT = 32032
DEFAULT_HOST = 'localhost'
PORT_COUNT = 21
class BaseDebuggerUI(wx.Panel):
debuggers = []
def NotifyDebuggersOfBreakpointChange():
for debugger in BaseDebuggerUI.debuggers:
debugger.BreakPointChange()
NotifyDebuggersOfBreakpointChange = staticmethod(NotifyDebuggersOfBreakpointChange)
def DebuggerRunning():
for debugger in BaseDebuggerUI.debuggers:
if debugger._executor:
return True
return False
DebuggerRunning = staticmethod(DebuggerRunning)
def DebuggerInWait():
for debugger in BaseDebuggerUI.debuggers:
if debugger._executor:
if debugger._callback._waiting:
return True
return False
DebuggerInWait = staticmethod(DebuggerInWait)
def DebuggerPastAutoContinue():
for debugger in BaseDebuggerUI.debuggers:
if debugger._executor:
if debugger._callback._waiting and not debugger._callback._autoContinue:
return True
return False
DebuggerPastAutoContinue = staticmethod(DebuggerPastAutoContinue)
def ShutdownAllDebuggers():
for debugger in BaseDebuggerUI.debuggers:
try:
debugger.StopExecution(None)
except wx._core.PyDeadObjectError:
pass
BaseDebuggerUI.debuggers = []
ShutdownAllDebuggers = staticmethod(ShutdownAllDebuggers)
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self._parentNoteBook = parent
self._service = None
self._executor = None
self._callback = None
self._stopped = False
BaseDebuggerUI.debuggers.append(self)
self._stopped = True
self.Bind(EVT_UPDATE_STDTEXT, self.AppendText)
self.Bind(EVT_UPDATE_ERRTEXT, self.AppendErrorText)
self._executor = None
self.STEP_ID = wx.NewId()
self.CONTINUE_ID = wx.NewId()
self.STEP_OUT_ID = wx.NewId()
self.NEXT_ID = wx.NewId()
self.KILL_PROCESS_ID = wx.NewId()
self.CLOSE_WINDOW_ID = wx.NewId()
self.BREAK_INTO_DEBUGGER_ID = wx.NewId()
self.CLEAR_ID = wx.NewId()
self.ADD_WATCH_ID = wx.NewId()
sizer = wx.BoxSizer(wx.VERTICAL)
self._tb = tb = wx.ToolBar(self, -1, wx.DefaultPosition, (1000,30), wx.TB_HORIZONTAL| wx.NO_BORDER| wx.TB_FLAT| wx.TB_TEXT, "Debugger" )
sizer.Add(tb, 0, wx.EXPAND |wx.ALIGN_LEFT|wx.ALL, 1)
tb.SetToolBitmapSize((16,16))
close_bmp = getCloseBitmap()
tb.AddSimpleTool( self.CLOSE_WINDOW_ID, close_bmp, _('Close Window'))
wx.EVT_TOOL(self, self.CLOSE_WINDOW_ID, self.StopAndRemoveUI)
stop_bmp = getStopBitmap()
tb.AddSimpleTool( self.KILL_PROCESS_ID, stop_bmp, _("Stop Debugging"))
wx.EVT_TOOL(self, self.KILL_PROCESS_ID, self.StopExecution)
tb.AddSeparator()
break_bmp = getBreakBitmap()
tb.AddSimpleTool( self.BREAK_INTO_DEBUGGER_ID, break_bmp, _("Break into Debugger"))
wx.EVT_TOOL(self, self.BREAK_INTO_DEBUGGER_ID, self.BreakExecution)
tb.AddSeparator()
continue_bmp = getContinueBitmap()
tb.AddSimpleTool( self.CONTINUE_ID, continue_bmp, _("Continue Execution"))
wx.EVT_TOOL(self, self.CONTINUE_ID, self.OnContinue)
self.Bind(EVT_DEBUG_INTERNAL, self.OnContinue)
tb.AddSeparator()
next_bmp = getNextBitmap()
tb.AddSimpleTool( self.NEXT_ID, next_bmp, _("Step to next line"))
wx.EVT_TOOL(self, self.NEXT_ID, self.OnNext)
step_bmp = getStepInBitmap()
tb.AddSimpleTool( self.STEP_ID, step_bmp, _("Step in"))
wx.EVT_TOOL(self, self.STEP_ID, self.OnSingleStep)
stepOut_bmp = getStepReturnBitmap()
tb.AddSimpleTool(self.STEP_OUT_ID, stepOut_bmp, _("Stop at function return"))
wx.EVT_TOOL(self, self.STEP_OUT_ID, self.OnStepOut)
tb.AddSeparator()
if _WATCHES_ON:
watch_bmp = getAddWatchBitmap()
tb.AddSimpleTool(self.ADD_WATCH_ID, watch_bmp, _("Add a watch"))
wx.EVT_TOOL(self, self.ADD_WATCH_ID, self.OnAddWatch)
tb.AddSeparator()
clear_bmp = getClearOutputBitmap()
tb.AddSimpleTool(self.CLEAR_ID, clear_bmp, _("Clear output pane"))
wx.EVT_TOOL(self, self.CLEAR_ID, self.OnClearOutput)
self._toolEnabled = True
self.framesTab = None
self.DisableWhileDebuggerRunning()
self.framesTab = self.MakeFramesUI(self, wx.NewId(), None)
sizer.Add(self.framesTab, 1, wx.ALIGN_LEFT|wx.ALL|wx.EXPAND, 1)
self._statusBar = wx.StatusBar( self, -1)
self._statusBar.SetFieldsCount(1)
sizer.Add(self._statusBar, 0, wx.EXPAND |wx.ALIGN_LEFT|wx.ALL, 1)
self.SetStatusText("Starting debug...")
self.SetSizer(sizer)
tb.Realize()
sizer.Fit(self)
def OnSingleStep(self, event):
self._callback.SingleStep()
def OnContinue(self, event):
self._callback.Continue()
def OnStepOut(self, event):
self._callback.Return()
def OnNext(self, event):
self._callback.Next()
def BreakPointChange(self):
if not self._stopped:
self._callback.PushBreakpoints()
self.framesTab.PopulateBPList()
def __del__(self):
# See comment on PythonDebuggerUI.StopExecution
self.StopExecution(None)
def DisableWhileDebuggerRunning(self):
if self._toolEnabled:
self._tb.EnableTool(self.STEP_ID, False)
self._tb.EnableTool(self.CONTINUE_ID, False)
self._tb.EnableTool(self.STEP_OUT_ID, False)
self._tb.EnableTool(self.NEXT_ID, False)
self._tb.EnableTool(self.BREAK_INTO_DEBUGGER_ID, True)
if _WATCHES_ON:
self._tb.EnableTool(self.ADD_WATCH_ID, False)
self.DeleteCurrentLineMarkers()
if self.framesTab:
self.framesTab.ClearWhileRunning()
self._toolEnabled = False
def EnableWhileDebuggerStopped(self):
self._tb.EnableTool(self.STEP_ID, True)
self._tb.EnableTool(self.CONTINUE_ID, True)
self._tb.EnableTool(self.STEP_OUT_ID, True)
self._tb.EnableTool(self.NEXT_ID, True)
self._tb.EnableTool(self.BREAK_INTO_DEBUGGER_ID, False)
self._tb.EnableTool(self.KILL_PROCESS_ID, True)
if _WATCHES_ON:
self._tb.EnableTool(self.ADD_WATCH_ID, True)
self._toolEnabled = True
def DisableAfterStop(self):
if self._toolEnabled:
self.DisableWhileDebuggerRunning()
self._tb.EnableTool(self.BREAK_INTO_DEBUGGER_ID, False)
self._tb.EnableTool(self.KILL_PROCESS_ID, False)
def ExecutorFinished(self):
if _VERBOSE: print "In ExectorFinished"
try:
self.DisableAfterStop()
except wx._core.PyDeadObjectError:
pass
try:
nb = self.GetParent()
for i in range(0, nb.GetPageCount()):
if self == nb.GetPage(i):
text = nb.GetPageText(i)
newText = text.replace("Debugging", "Finished")
nb.SetPageText(i, newText)
if _VERBOSE: print "In ExectorFinished, changed tab title."
break
except:
if _VERBOSE: print "In ExectorFinished, got exception"
def SetStatusText(self, text):
self._statusBar.SetStatusText(text,0)
def BreakExecution(self, event):
self._callback.BreakExecution()
def StopExecution(self, event):
self._callback.ShutdownServer()
def Execute(self, initialArgs, startIn, environment, onWebServer = False):
assert False, "Execute not overridden"
def SynchCurrentLine(self, filename, lineNum, noArrow=False):
self.DeleteCurrentLineMarkers()
# Filename will be <string> if we're in a bit of code that was executed from
# a string (rather than a file). I haven't been able to get the original string
# for display.
if filename == '<string>':
return
foundView = None
openDocs = wx.GetApp().GetDocumentManager().GetDocuments()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -