home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / wx / py / filling.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  11.5 KB  |  314 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
  5. __cvsid__ = '$Id: filling.py 37633 2006-02-18 21:40:57Z RD $'
  6. __revision__ = '$Revision: 37633 $'[11:-2]
  7. import wx
  8. import dispatcher
  9. import editwindow
  10. import inspect
  11. import introspect
  12. import keyword
  13. import sys
  14. import types
  15. from version import VERSION
  16. COMMONTYPES = _[1]
  17. DOCTYPES = ('BuiltinFunctionType', 'BuiltinMethodType', 'ClassType', 'FunctionType', 'GeneratorType', 'InstanceType', 'LambdaType', 'MethodType', 'ModuleType', 'UnboundMethodType', 'method-wrapper')
  18. SIMPLETYPES = _[2]
  19. del t
  20.  
  21. try:
  22.     COMMONTYPES.append(type(''.__repr__))
  23. except AttributeError:
  24.     []
  25.     []
  26.     []
  27. except:
  28.     []
  29.  
  30.  
  31. class FillingTree(wx.TreeCtrl):
  32.     name = 'Filling Tree'
  33.     revision = __revision__
  34.     
  35.     def __init__(self, parent, id = -1, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.TR_DEFAULT_STYLE, rootObject = None, rootLabel = None, rootIsNamespace = False, static = False):
  36.         wx.TreeCtrl.__init__(self, parent, id, pos, size, style)
  37.         self.rootIsNamespace = rootIsNamespace
  38.         import __main__
  39.         if rootObject is None:
  40.             rootObject = __main__.__dict__
  41.             self.rootIsNamespace = True
  42.         
  43.         if rootObject is __main__.__dict__ and rootLabel is None:
  44.             rootLabel = 'locals()'
  45.         
  46.         if not rootLabel:
  47.             rootLabel = 'Ingredients'
  48.         
  49.         rootData = wx.TreeItemData(rootObject)
  50.         self.item = self.root = self.AddRoot(rootLabel, -1, -1, rootData)
  51.         self.SetItemHasChildren(self.root, self.objHasChildren(rootObject))
  52.         self.Bind(wx.EVT_TREE_ITEM_EXPANDING, self.OnItemExpanding, id = self.GetId())
  53.         self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed, id = self.GetId())
  54.         self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, id = self.GetId())
  55.         self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnItemActivated, id = self.GetId())
  56.         if not static:
  57.             dispatcher.connect(receiver = self.push, signal = 'Interpreter.push')
  58.         
  59.  
  60.     
  61.     def push(self, command, more):
  62.         self.display()
  63.  
  64.     
  65.     def OnItemExpanding(self, event):
  66.         busy = wx.BusyCursor()
  67.         item = event.GetItem()
  68.         if self.IsExpanded(item):
  69.             return None
  70.         self.addChildren(item)
  71.  
  72.     
  73.     def OnItemCollapsed(self, event):
  74.         busy = wx.BusyCursor()
  75.         item = event.GetItem()
  76.  
  77.     
  78.     def OnSelChanged(self, event):
  79.         busy = wx.BusyCursor()
  80.         self.item = event.GetItem()
  81.         self.display()
  82.  
  83.     
  84.     def OnItemActivated(self, event):
  85.         item = event.GetItem()
  86.         text = self.getFullName(item)
  87.         obj = self.GetPyData(item)
  88.         frame = FillingFrame(parent = self, size = (600, 100), rootObject = obj, rootLabel = text, rootIsNamespace = False)
  89.         frame.Show()
  90.  
  91.     
  92.     def objHasChildren(self, obj):
  93.         return bool(self.objGetChildren(obj))
  94.  
  95.     
  96.     def objGetChildren(self, obj):
  97.         busy = wx.BusyCursor()
  98.         otype = type(obj)
  99.         if (otype is types.DictType or str(otype)[17:23] == 'BTrees') and hasattr(obj, 'keys'):
  100.             return obj
  101.         d = { }
  102.         if otype is types.ListType or otype is types.TupleType:
  103.             for n in range(len(obj)):
  104.                 key = '[' + str(n) + ']'
  105.                 d[key] = obj[n]
  106.             
  107.         
  108.         if otype not in COMMONTYPES:
  109.             for key in introspect.getAttributeNames(obj):
  110.                 
  111.                 try:
  112.                     d[key] = getattr(obj, key)
  113.                 continue
  114.                 continue
  115.  
  116.             
  117.         
  118.         return d
  119.  
  120.     
  121.     def addChildren(self, item):
  122.         self.DeleteChildren(item)
  123.         obj = self.GetPyData(item)
  124.         children = self.objGetChildren(obj)
  125.         if not children:
  126.             return None
  127.         keys = children.keys()
  128.         keys.sort((lambda x, y: cmp(str(x).lower(), str(y).lower())))
  129.         for key in keys:
  130.             itemtext = str(key)
  131.             if type(obj) is types.DictType and type(key) is types.StringType:
  132.                 if (item != self.root or item == self.root) and not (self.rootIsNamespace):
  133.                     itemtext = repr(key)
  134.                 
  135.             child = children[key]
  136.             data = wx.TreeItemData(child)
  137.             branch = self.AppendItem(parent = item, text = itemtext, data = data)
  138.             self.SetItemHasChildren(branch, self.objHasChildren(child))
  139.         
  140.  
  141.     
  142.     def display(self):
  143.         item = self.item
  144.         if not item:
  145.             return None
  146.         if self.IsExpanded(item):
  147.             self.addChildren(item)
  148.         
  149.         self.setText('')
  150.         obj = self.GetPyData(item)
  151.         if wx.Platform == '__WXMSW__':
  152.             if obj is None:
  153.                 return None
  154.         
  155.         self.SetItemHasChildren(item, self.objHasChildren(obj))
  156.         otype = type(obj)
  157.         text = ''
  158.         text += self.getFullName(item)
  159.         text += '\n\nType: ' + str(otype)
  160.         
  161.         try:
  162.             value = str(obj)
  163.         except:
  164.             value = ''
  165.  
  166.         if otype is types.StringType or otype is types.UnicodeType:
  167.             value = repr(obj)
  168.         
  169.         text += '\n\nValue: ' + value
  170.         if otype not in SIMPLETYPES:
  171.             
  172.             try:
  173.                 text += '\n\nDocstring:\n\n"""' + inspect.getdoc(obj).strip() + '"""'
  174.  
  175.         
  176.         if otype is types.InstanceType:
  177.             
  178.             try:
  179.                 text += '\n\nClass Definition:\n\n' + inspect.getsource(obj.__class__)
  180.  
  181.         else:
  182.             
  183.             try:
  184.                 text += '\n\nSource Code:\n\n' + inspect.getsource(obj)
  185.             except:
  186.                 pass
  187.  
  188.         self.setText(text)
  189.  
  190.     
  191.     def getFullName(self, item, partial = ''):
  192.         name = self.GetItemText(item)
  193.         print 'item name', name
  194.         parent = None
  195.         obj = None
  196.         print 'item != self.root? %r != %r?' % (item, self.root)
  197.         if item != self.root:
  198.             parent = self.GetItemParent(item)
  199.             print 'parent = %r' % parent
  200.             obj = self.GetPyData(parent)
  201.             print 'parent.pydata = %r' % obj
  202.         
  203.         if type(obj) is types.DictType or str(type(obj))[17:23] == 'BTrees' or hasattr(obj, 'keys'):
  204.             if (item != self.root or parent != self.root or parent == self.root) and not (self.rootIsNamespace):
  205.                 name = '[' + name + ']'
  206.             
  207.         if partial:
  208.             if partial[0] == '[':
  209.                 name += partial
  210.             else:
  211.                 name += '.' + partial
  212.         
  213.         if (item != self.root or parent != self.root or parent == self.root) and not (self.rootIsNamespace):
  214.             name = self.getFullName(parent, partial = name)
  215.         
  216.         return name
  217.  
  218.     
  219.     def setText(self, text):
  220.         print text
  221.  
  222.     
  223.     def setStatusText(self, text):
  224.         print text
  225.  
  226.  
  227.  
  228. class FillingText(editwindow.EditWindow):
  229.     name = 'Filling Text'
  230.     revision = __revision__
  231.     
  232.     def __init__(self, parent, id = -1, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.CLIP_CHILDREN, static = False):
  233.         editwindow.EditWindow.__init__(self, parent, id, pos, size, style)
  234.         self.SetReadOnly(True)
  235.         self.SetWrapMode(True)
  236.         self.SetMarginWidth(1, 0)
  237.         if not static:
  238.             dispatcher.connect(receiver = self.push, signal = 'Interpreter.push')
  239.         
  240.  
  241.     
  242.     def push(self, command, more):
  243.         self.Refresh()
  244.  
  245.     
  246.     def SetText(self, *args, **kwds):
  247.         self.SetReadOnly(False)
  248.         editwindow.EditWindow.SetText(self, *args, **kwds)
  249.         self.SetReadOnly(True)
  250.  
  251.  
  252.  
  253. class Filling(wx.SplitterWindow):
  254.     name = 'Filling'
  255.     revision = __revision__
  256.     
  257.     def __init__(self, parent, id = -1, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.SP_3D | wx.SP_LIVE_UPDATE, name = 'Filling Window', rootObject = None, rootLabel = None, rootIsNamespace = False, static = False):
  258.         wx.SplitterWindow.__init__(self, parent, id, pos, size, style, name)
  259.         self.tree = FillingTree(parent = self, rootObject = rootObject, rootLabel = rootLabel, rootIsNamespace = rootIsNamespace, static = static)
  260.         self.text = FillingText(parent = self, static = static)
  261.         wx.FutureCall(1, self.SplitVertically, self.tree, self.text, 200)
  262.         self.SetMinimumPaneSize(1)
  263.         self.tree.setText = self.text.SetText
  264.         self.tree.SelectItem(self.tree.root)
  265.         self.tree.display()
  266.         self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.OnChanged)
  267.  
  268.     
  269.     def OnChanged(self, event):
  270.         pass
  271.  
  272.     
  273.     def LoadSettings(self, config):
  274.         pos = config.ReadInt('Sash/FillingPos', 200)
  275.         wx.FutureCall(250, self.SetSashPosition, pos)
  276.         zoom = config.ReadInt('View/Zoom/Filling', -99)
  277.         if zoom != -99:
  278.             self.text.SetZoom(zoom)
  279.         
  280.  
  281.     
  282.     def SaveSettings(self, config):
  283.         config.WriteInt('Sash/FillingPos', self.GetSashPosition())
  284.         config.WriteInt('View/Zoom/Filling', self.text.GetZoom())
  285.  
  286.  
  287.  
  288. class FillingFrame(wx.Frame):
  289.     name = 'Filling Frame'
  290.     revision = __revision__
  291.     
  292.     def __init__(self, parent = None, id = -1, title = 'PyFilling', pos = wx.DefaultPosition, size = (600, 400), style = wx.DEFAULT_FRAME_STYLE, rootObject = None, rootLabel = None, rootIsNamespace = False, static = False):
  293.         wx.Frame.__init__(self, parent, id, title, pos, size, style)
  294.         intro = 'PyFilling - The Tastiest Namespace Inspector'
  295.         self.CreateStatusBar()
  296.         self.SetStatusText(intro)
  297.         import images
  298.         self.SetIcon(images.getPyIcon())
  299.         self.filling = Filling(parent = self, rootObject = rootObject, rootLabel = rootLabel, rootIsNamespace = rootIsNamespace, static = static)
  300.         self.filling.tree.setStatusText = self.SetStatusText
  301.  
  302.  
  303.  
  304. class App(wx.App):
  305.     
  306.     def OnInit(self):
  307.         wx.InitAllImageHandlers()
  308.         self.fillingFrame = FillingFrame()
  309.         self.fillingFrame.Show(True)
  310.         self.SetTopWindow(self.fillingFrame)
  311.         return True
  312.  
  313.  
  314.