dbgcommands.py :  » Windows » pyExcelerator » pywin32-214 » pythonwin » pywin » framework » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Windows » pyExcelerator 
pyExcelerator » pywin32 214 » pythonwin » pywin » framework » dbgcommands.py
# Command Handlers for the debugger.

# Not in the debugger package, as I always want these interfaces to be
# available, even if the debugger has not yet been (or can not be)
# imported
import win32ui, win32con
import scriptutils
import warnings
      
IdToBarNames = {
  win32ui.IDC_DBG_STACK : ("Stack",0),
  win32ui.IDC_DBG_BREAKPOINTS : ("Breakpoints",0),
  win32ui.IDC_DBG_WATCH : ("Watch",1),
  }

class DebuggerCommandHandler:
  def HookCommands(self):
    commands = ( (self.OnStep, None, win32ui.IDC_DBG_STEP),
                      (self.OnStepOut, self.OnUpdateOnlyBreak, win32ui.IDC_DBG_STEPOUT),
                      (self.OnStepOver, None, win32ui.IDC_DBG_STEPOVER),
                      (self.OnGo, None, win32ui.IDC_DBG_GO),
                      (self.OnClose, self.OnUpdateClose, win32ui.IDC_DBG_CLOSE),
                      (self.OnAdd, self.OnUpdateAddBreakpoints, win32ui.IDC_DBG_ADD),
                      (self.OnClearAll, self.OnUpdateClearAllBreakpoints, win32ui.IDC_DBG_CLEAR),
#                      (self.OnDebuggerToolbar, self.OnUpdateDebuggerToolbar, win32ui.ID_DEBUGGER_TOOLBAR),
                    )

    frame = win32ui.GetMainFrame()

    for methHandler, methUpdate, id in commands:
      frame.HookCommand(methHandler, id);
      if not methUpdate is None:
        frame.HookCommandUpdate(methUpdate, id)

    for id in IdToBarNames.keys():
      frame.HookCommand( self.OnDebuggerBar, id)
      frame.HookCommandUpdate(self.OnUpdateDebuggerBar, id)

  def OnDebuggerToolbar(self, id, code):
    if code==0:
      return not win32ui.GetMainFrame().OnBarCheck(id)

  def OnUpdateDebuggerToolbar(self, cmdui):
    win32ui.GetMainFrame().OnUpdateControlBarMenu(cmdui)
    cmdui.Enable(1)

  def _GetDebugger(self):
    try:
      import pywin.debugger
      return pywin.debugger.currentDebugger
    except ImportError:
      return None

  def _DoOrStart(self, doMethod, startFlag):
    d=self._GetDebugger()
    if d is not None and d.IsDebugging():
      method = getattr(d, doMethod)
      method()
    else:
      scriptutils.RunScript(defName=None, defArgs=None, bShowDialog = 0, debuggingType=startFlag)

  def OnStep(self, msg, code):
    self._DoOrStart("do_set_step", scriptutils.RS_DEBUGGER_STEP)

  def OnStepOver(self, msg, code):
    self._DoOrStart("do_set_next", scriptutils.RS_DEBUGGER_STEP)

  def OnStepOut(self, msg, code):
    d=self._GetDebugger()
    if d is not None and d.IsDebugging():
      d.do_set_return()

  def OnGo(self, msg, code):
    self._DoOrStart("do_set_continue", scriptutils.RS_DEBUGGER_GO)

  def OnClose(self, msg, code):
    d=self._GetDebugger()
    if d is not None:
      if d.IsDebugging():
        d.set_quit()
      else:
        d.close()

  def OnUpdateClose(self, cmdui):
    d=self._GetDebugger()
    if d is not None and d.inited:
      cmdui.Enable(1)
    else:
      cmdui.Enable(0)

  def OnAdd(self, msg, code):
    doc, view = scriptutils.GetActiveEditorDocument()
    if doc is None:
      ## Don't do a messagebox, as this could be triggered from the app's
      ## idle loop whenever the debug toolbar is visible, giving a never-ending
      ## series of dialogs.  This can happen when the OnUpdate handler
      ## for the toolbar button IDC_DBG_ADD fails, since MFC falls back to
      ## sending a normal command if the UI update command fails.
      ## win32ui.MessageBox('There is no active window - no breakpoint can be added')
      warnings.warn('There is no active window - no breakpoint can be added')
      return None
    pathName = doc.GetPathName()
    lineNo = view.LineFromChar(view.GetSel()[0])+1
    # If I have a debugger, then tell it, otherwise just add a marker
    d=self._GetDebugger()
    if d is None:
      import pywin.framework.editor.color.coloreditor
      doc.MarkerToggle(lineNo, pywin.framework.editor.color.coloreditor.MARKER_BREAKPOINT)
    else:
      if d.get_break(pathName, lineNo):
        win32ui.SetStatusText('Clearing breakpoint',1)
        rc = d.clear_break(pathName, lineNo)
      else:
        win32ui.SetStatusText('Setting breakpoint',1)
        rc = d.set_break(pathName, lineNo)
      if rc:
        win32ui.MessageBox(rc)
      d.GUIRespondDebuggerData()

  def OnClearAll(self, msg, code):
    win32ui.SetStatusText('Clearing all breakpoints')
    d=self._GetDebugger()
    if d is None:
      import pywin.framework.editor
      import pywin.framework.editor.color.coloreditor
      for doc in pywin.framework.editor.editorTemplate.GetDocumentList():
        doc.MarkerDeleteAll(pywin.framework.editor.color.coloreditor.MARKER_BREAKPOINT)
    else:
      d.clear_all_breaks()
      d.UpdateAllLineStates()
      d.GUIRespondDebuggerData()

  def OnUpdateOnlyBreak(self, cmdui):
    d=self._GetDebugger()
    ok = d is not None and d.IsBreak()
    cmdui.Enable(ok)

  def OnUpdateAddBreakpoints(self, cmdui):
    doc, view = scriptutils.GetActiveEditorDocument()
    if doc is None:
      enabled = 0
    else:
      enabled = 1
      lineNo = view.LineFromChar(view.GetSel()[0])+1
      import pywin.framework.editor.color.coloreditor
      cmdui.SetCheck(doc.MarkerAtLine(lineNo, pywin.framework.editor.color.coloreditor.MARKER_BREAKPOINT) != 0)
    cmdui.Enable(enabled)

  def OnUpdateClearAllBreakpoints(self, cmdui):
    d=self._GetDebugger()
    cmdui.Enable(d is None or len(d.breaks)!=0)

  def OnUpdateDebuggerBar(self, cmdui):
    name, always = IdToBarNames.get(cmdui.m_nID)
    enabled = always
    d=self._GetDebugger()
    if d is not None and d.IsDebugging() and name is not None:
      enabled = 1
      bar = d.GetDebuggerBar(name)
      cmdui.SetCheck(bar.IsWindowVisible())
    cmdui.Enable(enabled)

  def OnDebuggerBar(self, id, code):
    name = IdToBarNames.get(id)[0]
    d=self._GetDebugger()
    if d is not None and name is not None:
      bar = d.GetDebuggerBar(name)
      newState = not bar.IsWindowVisible()
      win32ui.GetMainFrame().ShowControlBar(bar, newState, 1)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.