def renderLongText(self, objectToRender, pathToObject="", alternateTitle="Default View"): result = "" import types import wx.py.introspect as introspect EXCLUDE = ['MethodType', 'UnboundMethodType', 'BuiltinFunctionType', 'BuiltinMethodType'] EXCLUDETYPES = [getattr(types, t) for t in EXCLUDE] Simple = ['IntType', 'FloatType', 'StringType'] SIMPLETYPES = [getattr(types, t) for t in Simple] SIMPLETYPES = [getattr(types, t) for t in dir(types) \ if not t.startswith('_') and t not in EXCLUDE] del t if type(objectToRender) in SIMPLETYPES: return "" result += "<center><h2>%s</h2></center>" % alternateTitle result += "<center>%s</center><hr>" % pathToObject result += "<table border=\"1\">" for key in introspect.getAttributeNames(objectToRender): try: if key.startswith("_"): continue sub = getattr(objectToRender, key) if not type(sub) in SIMPLETYPES and not type(sub) in EXCLUDETYPES: result += "<tr><td>" + key + "</td><td><a href =\"_pytree_object_id#%s.%s\">%s</a></td></tr>" % (pathToObject, key, cgi.escape(str(sub))) continue if isinstance(sub, list): result +="<tr><td>" + key +"</td><td>" for ii in xrange(len(sub)): nav = pathToObject + "." + key + "[%d]" % ii result += "<a href=\"_pytree_object_id#%s\">[%d] %s</a><br>" % (nav, ii, cgi.escape(str(sub[ii]))) result += "</td></tr>" continue if isinstance(sub, dict): result +="<tr><td>" + key +"</td><td>" for ii in xrange(len(sub.keys())): nav = pathToObject + "." + key + "[%d]" % ii result += "<a href=\"_pytree_object_id#%s\">[%s] %s</a><br>" % (nav, cgi.escape(str(sub.keys()[ii])), cgi.escape(str(sub.values()[ii]))) result += "</td></tr>" continue if not type(sub) in EXCLUDETYPES and not key.startswith("_"): result += "<tr><td>" + key + "</td><td>" + str(type(sub)) + cgi.escape(str(sub)) + "</td></tr>" except: pass result += "</table>" for renderer in self.customRenderers: result += renderer.renderLongText(objectToRender, pathToObject) return result
def objGetChildren(self, obj): """Возращает свойства или содержимое объекта obj""" otype = type(obj) if otype is types.DictType and hasattr(obj, 'keys'): return obj d = {} if otype is types.ListType or otype is types.TupleType: for n in range(len(obj)): key = "[%02d]" % n d[key] = obj[n] if otype not in COMMONTYPES: for key in introspect.getAttributeNames(obj): try: d[key] = getattr(obj, key) except: pass return d
def objGetChildren(self, obj): """Return dictionary with attributes or contents of object.""" busy = wx.BusyCursor() otype = type(obj) if otype is types.DictType \ or str(otype)[17:23] == 'BTrees' and hasattr(obj, 'keys'): return obj d = {} if otype is types.ListType or otype is types.TupleType: for n in range(len(obj)): key = '[' + str(n) + ']' d[key] = obj[n] if otype not in typecategories.COMMONTYPES: for key in introspect.getAttributeNames(obj): # Believe it or not, some attributes can disappear, # such as the exc_traceback attribute of the sys # module. So this is nested in a try block. try: d[key] = getattr(obj, key) except: pass return d
def renderLongText(self, objectToRender, pathToObject="", alternateTitle="Default View"): result = "" import types import wx.py.introspect as introspect EXCLUDE = [ 'MethodType', 'UnboundMethodType', 'BuiltinFunctionType', 'BuiltinMethodType' ] EXCLUDETYPES = [getattr(types, t) for t in EXCLUDE] Simple = ['IntType', 'FloatType', 'StringType'] SIMPLETYPES = [getattr(types, t) for t in Simple] SIMPLETYPES = [getattr(types, t) for t in dir(types) \ if not t.startswith('_') and t not in EXCLUDE] del t if type(objectToRender) in SIMPLETYPES: return "" result += "<center><h2>%s</h2></center>" % alternateTitle result += "<center>%s</center><hr>" % pathToObject result += "<table border=\"1\">" for key in introspect.getAttributeNames(objectToRender): try: if key.startswith("_"): continue sub = getattr(objectToRender, key) if not type(sub) in SIMPLETYPES and not type( sub) in EXCLUDETYPES: result += "<tr><td>" + key + "</td><td><a href =\"_pytree_object_id#%s.%s\">%s</a></td></tr>" % ( pathToObject, key, cgi.escape(str(sub))) continue if isinstance(sub, list): result += "<tr><td>" + key + "</td><td>" for ii in xrange(len(sub)): nav = pathToObject + "." + key + "[%d]" % ii result += "<a href=\"_pytree_object_id#%s\">[%d] %s</a><br>" % ( nav, ii, cgi.escape(str(sub[ii]))) result += "</td></tr>" continue if isinstance(sub, dict): result += "<tr><td>" + key + "</td><td>" for ii in xrange(len(sub.keys())): nav = pathToObject + "." + key + "[%d]" % ii result += "<a href=\"_pytree_object_id#%s\">[%s] %s</a><br>" % ( nav, cgi.escape(str(sub.keys()[ii])), cgi.escape(str(sub.values()[ii]))) result += "</td></tr>" continue if not type(sub) in EXCLUDETYPES and not key.startswith("_"): result += "<tr><td>" + key + "</td><td>" + str( type(sub)) + cgi.escape(str(sub)) + "</td></tr>" except: pass result += "</table>" for renderer in self.customRenderers: result += renderer.renderLongText(objectToRender, pathToObject) return result