From 439c467a0ca2c0882629a19cd89a1f3242172607 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 13 Oct 1998 03:59:57 +0000 Subject: Adding the beginnings of a Class browser. Incomplete, yet. --- Tools/idle/ClassBrowser.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Tools/idle/ClassBrowser.py diff --git a/Tools/idle/ClassBrowser.py b/Tools/idle/ClassBrowser.py new file mode 100644 index 0000000..289d6f6 --- /dev/null +++ b/Tools/idle/ClassBrowser.py @@ -0,0 +1,70 @@ +from Tkinter import * +import string +import pyclbr + +class ClassBrowser: + + def __init__(self, root, name): + try: + dict = pyclbr.readmodule(name) + except ImportError, msg: + tkMessageBox.showerror("Import error", str(msg), parent=root) + return + if not dict: + tkMessageBox.showerror("Nothing to browse", + "Module %s defines no classes" % name, parent=root) + return + self.root = root + self.top = top = Toplevel(root) + # Create help label + self.helplabel = Label(top, + text="Classes in module %s" % name, + borderwidth=2, relief="groove") + self.helplabel.pack(fill="x") + # Create top frame, with scrollbar and listbox + self.topframe = Frame(top) + self.topframe.pack(fill="both", expand=1) + self.vbar = Scrollbar(self.topframe, name="vbar") + self.vbar.pack(side="right", fill="y") + self.listbox = Listbox(self.topframe, exportselection=0, + takefocus=1, width=60) + self.listbox.pack(expand=1, fill="both") + # Tie listbox and scrollbar together + self.vbar["command"] = self.listbox.yview + self.listbox["yscrollcommand"] = self.vbar.set + # Bind events to the list box + self.listbox.bind("", self.click_event) + self.listbox.bind("", self.double_click_event) + ##self.listbox.bind("", self.popup_event) + self.listbox.bind("", self.up_event) + self.listbox.bind("", self.down_event) + # Load the classes + self.loadclasses(dict) + + def loadclasses(self, dict): + items = dict.items() + items.sort() + l = self.listbox + for key, value in items: + s = key + if value.super: + super = [] + for sup in value.super: + name = sup.name + if sup.module != value.module: + name = "%s.%s" % (sup.module, name) + super.append(name) + s = s + "(%s)" % string.join(super, ", ") + l.insert(END, s) + + def click_event(self, event): + pass + + def double_click_event(self, event): + pass + + def up_event(self, event): + pass + + def down_event(self, event): + pass -- cgit v0.12