[PyKDE] dir(QtObjectThing) -> give_me_all_attrs(QtObjectThing)?

Phil Thompson phil at riverbankcomputing.co.uk
Fri May 30 19:25:01 BST 2003


On Friday 30 May 2003 6:15 pm, Gerard Vermeulen wrote:
> On Fri, 30 May 2003 17:56:20 +0100
>
> Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
> > On Friday 30 May 2003 5:36 pm, Gerard Vermeulen wrote:
> > > On Thu, 29 May 2003 18:47:46 +0100
> > >
> > > Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
> > > > On Wednesday 28 May 2003 6:37 pm, Kasper Souren wrote:
> > > > > Hi,
> > > > >
> > > > > I wonder whether there is a simple trick to get all the existing
> > > > > attributes? Now a dir(QtObjectThing) just gives a very limited
> > > > > number of attributes. When exploring PyQy (and PyQwt) it would be a
> > > > > great help when there was a simple way to just see the possible
> > > > > methods. Without resorting to the manual, that is ;)  When working
> > > > > in Python I usually just hack around and use my TAB key a lot (in
> > > > > order to get possible completions).
> > > > >
> > > > > Once an object's method is used it does appear in dir(the_object).
> > > > > So I hope there is a possibility to have a little function that
> > > > > could 'trigger' the possible attributes...
> > > > >
> > > > > Having this automatically would be even cooler, but I guess that
> > > > > that would already have been done if it were easy... And, I hope
> > > > > not but, maybe the same counts for the little hackish function I
> > > > > have in mind.
> > > >
> > > > I'm afraid it's a feature. Without this feature PyQt would take too
> > > > long to load and take up too much memory.
> > >
> > > Adding the following function to each class is sufficient, I think:
> > > class QwtWheel: QwtSliderBase
> > > {
> > > %HeaderCode
> > > #include <qwt_wheel.h>
> > > %End
> > >
> > > public:
> > >     void getLazyMethodNames();
> > > %MemberCode
> > >     if (sipParseArgs(&sipArgsParsed, sipArgs, "")) {
> > >         int i, n;
> > >
> > >         Py_BEGIN_ALLOW_THREADS
> > >         n = sipClassAttrTab_$C.la_nrmethods;
> > >         Py_END_ALLOW_THREADS
> > >
> > >         PyObject *result = PyList_New(n);
> > >         if (!(result))
> > >             return 0;
> > >
> > >         for (i=0; i<n; i++)
> > >             PyList_SetItem(
> > >                 result,
> > >                 i,
> > >
> > > PyString_FromString(sipClassAttrTab_$C.la_methods[i].ml_name) );
> > >
> > >         return result;
> > >     }
> > > %End
> > >
> > >     QwtWheel(QWidget * /TransferThis/ = 0, const char * = 0);
> > >     ...
> > >     ...
> > > };
> > >
> > > With such a function in each class, it will take a few lines of Python
> > > code to adapt the rlcompleter module so that it sees the lazy method
> > > names while they are not yet activated.
> > >
> > > Phil, are you willing to adapt sip so that it will generate a function
> > > like this for each class? That will save me some cut&paste work :-)
> >
> > Interesting. You can avoid the cut&paste by using /AutoGen/, but I think
> > a better solution is to implement a function in the sip module...
> >
> > import sip
> >
> > names = sip.getLazyMethodNames(QwtWheel)
> >
> > At the moment the sip module doesn't contain any functions, but the
> > reason it was changed from a library to a module was to allow these sorts
> > of dirty hacks to be added without polluting PyQt etc.
> >
> > So, tell me exactly what you want - or is the above all that's needed?
>
> Yes, having this in sip is much better (I started to look there, but saw no
> way to break in).
> I think the above is all, but let me change the rlcompleter first, to be
> sure. It would be nice to include such a modified rlcompleter with PyQt.
>
> Warning: you opened Pandora's box, because the next question is ...
> and doc-strings?

Doc string support is fairly trivial - just don't expect them to be added to 
PyQt.

Phil




More information about the PyQt mailing list