# - support partial or total redisplay
# - for classes/modules, add "open source" to object browser
from idlelib.TreeWidget import TreeItem, TreeNode, ScrolledCanvas
class ObjectTreeItem(TreeItem):
def __init__(self, labeltext, object, setfunction=None):
self.labeltext = labeltext
self.setfunction = setfunction
return myrepr.repr(self.object)
if not self.IsExpandable():
return self.setfunction is not None
return not not dir(self.object)
value = getattr(self.object, key)
item = make_objecttreeitem(
lambda value, key=key, object=self.object:
setattr(object, key, value))
class InstanceTreeItem(ObjectTreeItem):
sublist = ObjectTreeItem.GetSubList(self)
make_objecttreeitem("__class__ =", self.object.__class__))
class ClassTreeItem(ObjectTreeItem):
sublist = ObjectTreeItem.GetSubList(self)
if len(self.object.__bases__) == 1:
item = make_objecttreeitem("__bases__[0] =",
self.object.__bases__[0])
item = make_objecttreeitem("__bases__ =", self.object.__bases__)
class AtomicObjectTreeItem(ObjectTreeItem):
class SequenceTreeItem(ObjectTreeItem):
return len(self.object) > 0
return range(len(self.object))
def setfunction(value, key=key, object=self.object):
item = make_objecttreeitem("%r:" % (key,), value, setfunction)
class DictTreeItem(SequenceTreeItem):
keys = self.object.keys()
IntType: AtomicObjectTreeItem,
LongType: AtomicObjectTreeItem,
FloatType: AtomicObjectTreeItem,
StringType: AtomicObjectTreeItem,
TupleType: SequenceTreeItem,
ListType: SequenceTreeItem,
InstanceType: InstanceTreeItem,
ClassType: ClassTreeItem,
def make_objecttreeitem(labeltext, object, setfunction=None):
return c(labeltext, object, setfunction)
def _object_browser(parent):
root.title("Test ObjectBrowser")
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
root.geometry("+%d+%d"%(x, y + 150))
root.configure(bd=0, bg="yellow")
sc = ScrolledCanvas(root, bg="white", highlightthickness=0, takefocus=1)
sc.frame.pack(expand=1, fill="both")
item = make_objecttreeitem("sys", sys)
node = TreeNode(sc.canvas, None, item)
if __name__ == '__main__':
from idlelib.idle_test.htest import run