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

Gerard Vermeulen gvermeul at grenoble.cnrs.fr
Sat May 31 10:48:01 BST 2003


On Fri, 30 May 2003 18:24:40 +0100
Phil Thompson <phil at riverbankcomputing.co.uk> wrote:

> On Friday 30 May 2003 6:15 pm, Gerard Vermeulen wrote:
> > On Fri, 30 May 2003 17:56:20 +0100
> >
[snip]
> > > > >
> > > > > 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.
>
I have attached a rlcompleter that I will include in PyQwt, I will be
happy if it goes into PyQt.

With this I can do from the command line interpreter (iqt -- also in PyQt --
makes PyQt work with command line interpreter), but no reason why it should
not work from Eric:

---------------------------------------------------------------------------------
[packer at venus examples]$ python
Python 2.2.2 (#1, Oct 23 2002, 12:12:09)
[GCC 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)] on linux-i386
Type "help", "copyright", "credits" or "license" for more information.
>>> import iqt
>>> import iqt.rlcompleter
>>> iqt.[TAB]
iqt.__class__         iqt.__hash__          iqt.__repr__
iqt.__delattr__       iqt.__init__          iqt.__setattr__
iqt.__dict__          iqt.__name__          iqt.__str__
iqt.__doc__           iqt.__new__           iqt._iqt
iqt.__file__          iqt.__path__          iqt.readline
iqt.__getattribute__  iqt.__reduce__        iqt.rlcompleter
>>> from qwt import *
>>> w = QwtWheel()
>>> w.d[TAB]
w.darkBlue             w.darkRed              w.dragMoveEvent
w.darkCyan             w.darkYellow           w.draw
w.darkGray             w.destroy              w.drawWheel
w.darkGreen            w.dragEnterEvent       w.drawWheelBackground
w.darkMagenta          w.dragLeaveEvent       w.dropEvent
>>> w.destroy
<built-in method destroy of sip.wrapper object at 0x8125cb0>
>>>
--------------------------------------------------------------------------------

As for doc-strings. Of course, this is an enormous amount of work for PyQt,
even for PyQwt. If there is no support from the sip compiler, it would
be nice it the NULL pointers for doc-strings in the 'lazy' tables could
be initialized from a dictionary { method-name: doc-string }.

Anyhow, I a willing to experiment this, myself. 

Gerard
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rlcompleter.py
Type: application/octet-stream
Size: 4732 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20030531/d7e75fe4/rlcompleter.obj


More information about the PyQt mailing list