RE: [PyCrust] Attribute list hook
Brought to you by:
pobrien
|
From: Kevin A. <al...@se...> - 2001-08-11 15:27:18
|
Is it possible to have doc strings for attributes? If so, that is another
thing I would like to be able to do, so that when you are using
command-completion you could also have a calltip pop up as you go over an
attribute to see what it is for and the types that are valid for it. Come to
think of it, I would like to have calltips pop up for methods when scrolling
through the command-completion menu as well.
Neil's solution might need to be expanded so the documentation for the
attributes can be made available as well.
ka
> -----Original Message-----
> From: pyc...@li...
> [mailto:pyc...@li...]On Behalf Of Neil
> Hodgson
> Sent: Saturday, August 11, 2001 12:35 AM
> To: pyc...@li...
> Subject: [PyCrust] Attribute list hook
>
>
> On the PythonCard list I've been pushing the use of __getattr__ and
> __setattr__ to allow access to widget properties through dot notation -
>
> self.components.btnTranslate.label = "Celsius to Fahrenheit"
>
> rather than
>
> self.components.getWidget("btnTranslate").setLabel("Celsius to
> Fahrenheit")
>
> One problem with this is that interactive shells such as PyCrust can't
> find out the names of these attributes as they are not in __dict__ even
> though the set of such attributes is normally well known. This is easy
> enough to solve in the context of PythonCard using PyCrust by adding some
> code (or stuffing __dict__ with the known attributes) but this is
> a generic
> problem that should be solved for use by all interactive shells.
>
> Has this been solved for any other shells?
>
> If not, I propose a convention which is to provide a getAttributeNames
> method on any class that wants to expose its dynamic (or semi-dynamic)
> attributes to shells. Thus
>
> class D11:
> def getAttributeNames(self):
> return ["woderwick", "woger", "weginald"]
>
> class D12:
> pass
>
> def attrList(d):
> try:
> print d.getAttributeNames()
> except AttributeError, x:
> print "Empty"
>
> Then interactively:
>
> >>> d = D11()
> >>> attrList(d)
> ['woderwick', 'woger', 'weginald']
> >>> e = D12()
> >>> attrList(e)
> Empty
>
> If there is resistance to using exceptions here, then a more complex
> mechanism that involves checking the __class__ and
> __class__.__bases__ could
> be used or a marker attribute added.
>
> I'll leave this message here for a day and if there are no big problems
> will copy it to comp.lang.python to see if there are more opinions.
>
> Neil
>
>
> _______________________________________________
> PyCrust-users mailing list
> PyC...@li...
> http://lists.sourceforge.net/lists/listinfo/pycrust-users
>
|