home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Mac / Tools / IDE / Wtraceback.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-06-23  |  9.5 KB  |  219 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. import traceback
  5. import sys
  6. import W
  7. import os
  8. import types
  9. import List
  10.  
  11. class TraceBack:
  12.     
  13.     def __init__(self, title = 'Traceback'):
  14.         app = W.getapplication()
  15.         self.title = title
  16.         self.w = None
  17.         self.closed = 1
  18.         self.start = 0
  19.         self.lastwindowtitle = ''
  20.         self.bounds = (360, 298)
  21.  
  22.     
  23.     def traceback(self, start = 0, lastwindowtitle = ''):
  24.         
  25.         try:
  26.             self.lastwindowtitle = lastwindowtitle
  27.             self.start = start
  28.             (self.type, self.value, self.tb) = (sys.exc_type, sys.exc_value, sys.exc_traceback)
  29.             if self.type is not SyntaxError:
  30.                 self.show()
  31.                 if type(self.type) == types.ClassType:
  32.                     errortext = self.type.__name__
  33.                 else:
  34.                     errortext = str(self.type)
  35.                 value = str(self.value)
  36.                 if self.value and value:
  37.                     errortext = errortext + ': ' + value
  38.                 
  39.                 self.w.text.set(errortext)
  40.                 self.buildtblist()
  41.                 self.w.list.set(self.textlist)
  42.                 self.w.list.setselection([
  43.                     len(self.textlist) - 1])
  44.                 self.w.wid.SelectWindow()
  45.                 self.closed = 0
  46.             else:
  47.                 self.syntaxerror()
  48.         except:
  49.             traceback.print_exc()
  50.  
  51.  
  52.     
  53.     def syntaxerror(self):
  54.         
  55.         try:
  56.             (filename, lineno, charno, line) = (value,)
  57.         except:
  58.             filename = ''
  59.             lineno = None
  60.             value = self.value
  61.  
  62.         if not filename and self.lastwindowtitle:
  63.             filename = self.lastwindowtitle
  64.         elif not filename:
  65.             filename = '<unknown>'
  66.         
  67.         if filename and os.path.exists(filename):
  68.             filename = os.path.split(filename)[1]
  69.         
  70.         if lineno:
  71.             charno = charno - 1
  72.             text = str(value) + '\rFile: "' + str(filename) + '", line ' + str(lineno) + '\r\r' + line[:charno] + '\xa5' + line[charno:-1]
  73.         else:
  74.             text = str(value) + '\rFile: "' + str(filename) + '"'
  75.         self.syntaxdialog = W.ModalDialog((360, 120), 'Syntax Error')
  76.         self.syntaxdialog.text = W.TextBox((10, 10, -10, -40), text)
  77.         self.syntaxdialog.cancel = W.Button((-190, -32, 80, 16), 'Cancel', self.syntaxclose)
  78.         self.syntaxdialog.edit = W.Button((-100, -32, 80, 16), 'Edit', self.syntaxedit)
  79.         self.syntaxdialog.setdefaultbutton(self.syntaxdialog.edit)
  80.         self.syntaxdialog.bind('cmd.', self.syntaxdialog.cancel.push)
  81.         self.syntaxdialog.open()
  82.  
  83.     
  84.     def syntaxclose(self):
  85.         self.syntaxdialog.close()
  86.         del self.syntaxdialog
  87.  
  88.     
  89.     def syntaxedit(self):
  90.         
  91.         try:
  92.             (filename, lineno, charno, line) = (value,)
  93.         except:
  94.             filename = ''
  95.             lineno = None
  96.  
  97.         if not filename and self.lastwindowtitle:
  98.             filename = self.lastwindowtitle
  99.         elif not filename:
  100.             filename = '<unknown>'
  101.         
  102.         self.syntaxclose()
  103.         if lineno:
  104.             W.getapplication().openscript(filename, lineno, charno - 1)
  105.         else:
  106.             W.getapplication().openscript(filename)
  107.  
  108.     
  109.     def show(self):
  110.         if self.closed:
  111.             self.setupwidgets()
  112.             self.w.open()
  113.         else:
  114.             self.w.wid.ShowWindow()
  115.             self.w.wid.SelectWindow()
  116.  
  117.     
  118.     def hide(self):
  119.         if self.closed:
  120.             return None
  121.         
  122.         self.w.close()
  123.  
  124.     
  125.     def close(self):
  126.         self.bounds = self.w.getbounds()
  127.         self.closed = 1
  128.         (self.type, self.value, self.tb) = (None, None, None)
  129.         self.tblist = None
  130.  
  131.     
  132.     def activate(self, onoff):
  133.         if onoff:
  134.             if self.closed:
  135.                 self.traceback()
  136.             
  137.             self.closed = 0
  138.             self.checkbuttons()
  139.         
  140.  
  141.     
  142.     def setupwidgets(self):
  143.         self.w = W.Window(self.bounds, self.title, minsize = (316, 168))
  144.         self.w.text = W.TextBox((10, 10, -10, 30))
  145.         self.w.tbtitle = W.TextBox((10, 40, -10, 10), 'Traceback (innermost last):')
  146.         self.w.list = W.TwoLineList((10, 60, -10, -40), callback = self.listhit)
  147.         self.w.editbutton = W.Button((10, -30, 60, 16), 'Edit', self.edit)
  148.         self.w.editbutton.enable(0)
  149.         self.w.browselocalsbutton = W.Button((80, -30, 100, 16), 'Browse locals\xc9', self.browselocals)
  150.         self.w.browselocalsbutton.enable(0)
  151.         self.w.postmortembutton = W.Button((190, -30, 100, 16), 'Post mortem\xc9', self.postmortem)
  152.         self.w.setdefaultbutton(self.w.editbutton)
  153.         self.w.bind('cmdb', self.w.browselocalsbutton.push)
  154.         self.w.bind('<close>', self.close)
  155.         self.w.bind('<activate>', self.activate)
  156.  
  157.     
  158.     def buildtblist(self):
  159.         tb = self.tb
  160.         for i in range(self.start):
  161.             tb = tb.tb_next
  162.         
  163.         self.tblist = traceback.extract_tb(tb)
  164.         self.textlist = []
  165.         for filename, lineno, func, line in self.tblist:
  166.             tbline = ''
  167.             if line:
  168.                 tbline = tbline + '\r      ' + line
  169.             
  170.             self.textlist.append(tbline[:255])
  171.         
  172.  
  173.     
  174.     def edit(self):
  175.         sel = self.w.list.getselection()
  176.         for i in sel:
  177.             (filename, lineno, func, line) = self.tblist[i]
  178.             W.getapplication().openscript(filename, lineno)
  179.         
  180.  
  181.     
  182.     def browselocals(self):
  183.         sel = self.w.list.getselection()
  184.         for i in sel:
  185.             tb = self.tb
  186.             for j in range(i + self.start):
  187.                 tb = tb.tb_next
  188.             
  189.             self.browse(tb.tb_frame.f_locals)
  190.         
  191.  
  192.     
  193.     def browse(self, object):
  194.         import PyBrowser
  195.         PyBrowser.Browser(object)
  196.  
  197.     
  198.     def postmortem(self):
  199.         import PyDebugger
  200.         PyDebugger.postmortem(self.type, self.value, self.tb)
  201.  
  202.     
  203.     def listhit(self, isdbl):
  204.         if isdbl:
  205.             self.w.editbutton.push()
  206.         else:
  207.             self.checkbuttons()
  208.  
  209.     
  210.     def checkbuttons(self):
  211.         havefile = len(self.w.list.getselection()) > 0
  212.         self.w.editbutton.enable(havefile)
  213.         self.w.browselocalsbutton.enable(havefile)
  214.         if not havefile and self.w.editbutton:
  215.             pass
  216.         self.w.setdefaultbutton(self.w.postmortembutton)
  217.  
  218.  
  219.