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

Gerard Vermeulen gvermeul at grenoble.cnrs.fr
Fri May 30 18:37:00 BST 2003


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 :-)

Gerard




More information about the PyQt mailing list