Here's how I implement intellisense in Python. This is very easy for an interactive command line, and a bit trickier for an editor. The code was gleaned from an Idle implementation, and I haven't changed it in years. It works fine with both CPython and IronPython, returning both the stdlib and .NET methods in IronPython.
(This is greatly simplified, but it's the general approach) 1. Load the functions _find_constructor() and get_arg_text() into Python - see code below or refer to Idle source code. 2. When the user presses the period key, look to see if there's a valid Python object directly preceding the period. a. If a valid object is found, e.g. myobject, temporarily redirect Python output to a string and call dir(myobject) on the object to get a list of methods/properties. b. Remove double underscore methods from the string, and populate a list box with the methods. c. Pop up the listbox in front of the period and let the user select one via mouse or keystroke. 3. When the user presses the left-bracket, temporarily redirect Python output to a string and call get_arg_text(object) on the object immediately preceding the bracket. a. If text is returned, display it in a tooltip window. HTH -------------- Python code below ---------------------- def _find_constructor(class_ob): # Given a class object, return a function object used for the # constructor (ie, __init__() ) or None if we can't find one. try: return class_ob.__init__.im_func except AttributeError: for base in class_ob.__bases__: rc = _find_constructor(base) if rc is not None: return rc return None def get_arg_text(ob): import types argText = '' if ob is not None: argOffset = 0 if type(ob)==types.ClassType: fob = _find_constructor(ob) if fob is None: fob = lambda: None else: argOffset = 1 elif type(ob)==types.MethodType: fob = ob.im_func argOffset = 1 else: fob = ob # Try and build one for Python defined functions if type(fob) in [types.FunctionType, types.LambdaType]: try: realArgs = fob.func_code.co_varnames[argOffset:fob.func_code.co_argcount] defaults = fob.func_defaults or [] defaults = list(map(lambda name: '=%s' % name, defaults)) defaults = [''] * (len(realArgs)-len(defaults)) + defaults items = map(lambda arg, dflt: arg+dflt, realArgs, defaults) if fob.func_code.co_flags & 0x4: items.append('...') if fob.func_code.co_flags & 0x8: items.append('***') argText = string.join(items , ', ') argText = '(%s)' % argText except: pass # See if we can use the docstring doc = getattr(ob, '__doc__', '') if doc: while doc[:1] in ' \t\n': doc = doc[1:] pos = doc.find('\n') if pos < 0 or pos > 70: pos = 70 if argText: argText += '\n' argText += doc[:pos] return argText _____ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Blesson Varghese Sent: Tuesday, November 28, 2006 1:58 AM To: users@lists.ironpython.com Subject: [IronPython] Do we have any option for Intellisense?? I want to write code to provide Intellisense to an IDE for Iron Python...Do we have any options within the Python Engine to do that??? _____ Find out what India is talking about on - Yahoo! <http://us.rd.yahoo.com/mail/in/yanswers/*http:/in.answers.yahoo.com/> Answers India Send FREE SMS to your friend's mobile from Yahoo! Messenger Version 8. Get <http://us.rd.yahoo.com/mail/in/messengertagline/*http:/in.messenger.yahoo.c om> it NOW
_______________________________________________ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com