home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyth_os2.zip / python-1.0.2 / Lib / stdwin / wdbsrcwin.py < prev    next >
Text File  |  1993-12-17  |  2KB  |  101 lines

  1. # wdbsrcwin.py -- source window for wdb
  2.  
  3. import stdwin
  4. from stdwinevents import *
  5. import srcwin
  6.  
  7.  
  8. class DebuggerSourceWindow(srcwin.SourceWindow):
  9.     
  10.     def __init__(self, debugger, filename):
  11.         self.debugger = debugger
  12.         self.curlineno = 0
  13.         self.focus = 0
  14.         srcwin.SourceWindow.__init__(self, filename)
  15.     
  16.     def close(self):
  17.         del self.debugger.sourcewindows[self.filename]
  18.         del self.debugger
  19.         srcwin.SourceWindow.close(self)
  20.     
  21.     def dispatch(self, event):
  22.         type, win, detail = event
  23.         if type == WE_CHAR:
  24.             self.char(detail)
  25.         elif type == WE_COMMAND:
  26.             self.command(detail)
  27.         elif type == WE_MOUSE_DOWN:
  28.             self.mouse_down(detail)
  29.         else:
  30.             srcwin.SourceWindow.dispatch(self, event)
  31.     
  32.     def char(self, detail):
  33.         self.debugger.char(detail)
  34.     
  35.     def command(self, detail):
  36.         self.debugger.command(detail)
  37.     
  38.     def mouse_down(self, detail):
  39.         (h, v), clicks, button, mask = detail
  40.         if h >= self.leftmargin:
  41.             srcwin.SourceWindow.dispatch(self, \
  42.                 (WE_MOUSE_DOWN, self.win, detail))
  43.             return
  44.         lineno = v/self.lineheight + 1
  45.         if 1 <= lineno <= self.linecount:
  46.             if self.debugger.get_break(self.filename, lineno):
  47.                 f = self.debugger.clear_break
  48.             else:
  49.                 f = self.debugger.set_break
  50.             err = f(self.filename, lineno)
  51.             if err: stdwin.message(err)
  52.             else: self.changemark(lineno)
  53.         else:
  54.             stdwin.fleep()
  55.     
  56.     def getmark(self, lineno):
  57.         s = `lineno`
  58.         if lineno == self.focus:
  59.             s = '[' + s + ']'
  60.         else:
  61.             s = ' ' + s + ' '
  62.         if lineno == self.curlineno:
  63.             s = s + '->'
  64.         else:
  65.             s = s + '  '
  66.         br = self.debugger.breaks
  67.         if br.has_key(self.filename) and lineno in br[self.filename]:
  68.             s = s + 'B'
  69.         else:
  70.             s = s + ' '
  71.         return s
  72.     
  73.     def getmargin(self):
  74.         return stdwin.textwidth('[' + `self.linecount+1` + ']->B ')
  75.     
  76.     def setlineno(self, newlineno):
  77.         if newlineno != self.curlineno:
  78.             oldlineno = self.curlineno
  79.             self.curlineno = newlineno
  80.             self.changemark(oldlineno)
  81.             self.changemark(newlineno)
  82.         if newlineno != 0:
  83.             self.showline(newlineno)
  84.     
  85.     def resetlineno(self):
  86.         self.setlineno(0)
  87.     
  88.     def setfocus(self, newfocus):
  89.         if newfocus != self.focus:
  90.             oldfocus = self.focus
  91.             self.focus = newfocus
  92.             self.changemark(oldfocus)
  93.             self.changemark(newfocus)
  94.         if newfocus != 0:
  95.             self.showline(newfocus)
  96.     
  97.     def resetfocus(self):
  98.         self.setfocus(0)
  99.  
  100. # XXX Should get rid of focus stuff again
  101.