diff -r 5e05d7d3db9c Lib/idlelib/ClassBrowser.py --- a/Lib/idlelib/ClassBrowser.py Sat Mar 01 07:53:28 2014 -0500 +++ b/Lib/idlelib/ClassBrowser.py Sun Mar 02 20:12:09 2014 +0530 @@ -5,7 +5,6 @@ - reparse when source changed (maybe just a button would be OK?) (or recheck on window popup) - add popup menu with more options (e.g. doc strings, base classes, imports) -- show function argument list? (have to do pattern matching on source) - should the classes and methods lists also be in the module's menu bar? - add base classes to class browser tree """ @@ -13,6 +12,8 @@ import os import sys import pyclbr +import inspect +import imp from idlelib import PyShell from idlelib.WindowList import ListedToplevel @@ -134,7 +135,10 @@ def GetText(self): if self.isfunction: - return "def " + self.name + "(...)" + module = imp.load_source('module',self.file) + function = getattr(module,self.name) + args = inspect.getargspec(function) + return "def " + self.name + "({})".format(self.FormatArgumentList(args)) else: return "class " + self.name @@ -180,6 +184,20 @@ list.append(name) return list + def FormatArgumentList(self,args): + #See documentation of inspect.argspec(),for + #more information on how args is formatted. + formatted_args = [] + if args.args : + formatted_args = formatted_args + [', '.join(args.args)] + if args.varargs: + formatted_args = formatted_args + ['*' + args.varargs] + if args.keywords: + formatted_args = formatted_args + ['**' + args.keywords] + if args.defaults: + formatted_args = formatted_args + ['defualts=' + str(args.defaults)] + return ', '.join(formatted_args) + class MethodBrowserTreeItem(TreeItem): def __init__(self, name, cl, file): @@ -188,7 +206,12 @@ self.file = file def GetText(self): - return "def " + self.name + "(...)" + module = imp.load_source('m',self.file) + class_ = getattr(module, self.cl.name) + function = getattr(class_, self.name) + args = inspect.getargspec(function) + formatted_args = self.FormatArgumentList(args) + return "def " + self.name + "({})".format(formatted_args) def GetIconName(self): return "python" # XXX @@ -202,7 +225,24 @@ edit = PyShell.flist.open(self.file) edit.gotoline(self.cl.methods[self.name]) + def FormatArgumentList(self,args): + #See documentation of inspect.argspec(),for + #more information on how args is formatted. + formatted_args = [] + if args.args : + formatted_args = formatted_args + [', '.join(args.args)] + if args.varargs: + formatted_args = formatted_args + ['*' + args.varargs] + if args.keywords: + formatted_args = formatted_args + ['**' + args.keywords] + if args.defaults: + formatted_args = formatted_args + ['defualts=' + str(args.defaults)] + return ', '.join(formatted_args) + def main(): + from idlelib.PyShell import PyShell, PyShellFileList + from tkinter import Tk, Button + try: file = __file__ except NameError: @@ -213,9 +253,18 @@ file = sys.argv[0] dir, file = os.path.split(file) name = os.path.splitext(file)[0] - ClassBrowser(PyShell.flist, name, [dir]) + root = Tk() + root.title('Class Browser Test Dialog') + root.geometry("%dx%d%+d%+d" % (275, 25, 50, 50)) + flist = PyShellFileList(root) + + def run(): + ClassBrowser(flist, name, [dir]) + + Button(root, text='ClassBrowser', command=run,).pack() if sys.stdin is sys.__stdin__: - mainloop() - + root.mainloop() + if __name__ == "__main__": + """Run the dialog""" main() diff -r 5e05d7d3db9c Lib/idlelib/TreeWidget.py --- a/Lib/idlelib/TreeWidget.py Sat Mar 01 07:53:28 2014 -0500 +++ b/Lib/idlelib/TreeWidget.py Sun Mar 02 20:12:09 2014 +0530 @@ -357,6 +357,9 @@ def OnDoubleClick(self): """Called on a double-click on the item.""" + def FormatArgumentList(self): + """Return formatted non-Nonetype arguments in argument list""" + # Example application