[PyKDE] Auto-connecting Slots
Gerard Vermeulen
gerard.vermeulen at grenoble.cnrs.fr
Sat Jan 28 13:40:09 GMT 2006
On Sat, 28 Jan 2006 11:57:00 +0000
Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
> On Saturday 28 January 2006 11:29 am, Giovanni Bajo wrote:
> > Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
> > >>> The QtCore.signature() decorator takes a single argument which is,
> > >>> in effect, the C++ signature of the method which tells the
> > >>> auto-connect
> > >>> code which signal to connect. For example...
> > >>>
> > >>> @QtCore.signature("on_spinbox_valueChanged(int)")
> > >>> def on_spinbox_valueChanged(self, value):
> > >>> # value will only ever be an integer.
> > >>
> > >> Notice that naming it "signature" is a namespace violation from
> > >> those using "from QtCore import *". OTOH, you shouldn't impose this
> > >> code style of prefixing each and every name with the QtModule name:
> > >> I personally hate it, and I can't see why Python code should get 3
> > >> times more verbose than the corresponding C++ code. Having 'Q' at
> > >> the beginning of the word is enough namespace for me and for every
> > >> C++ Qt project out there. Specifically, Qt itself does not expose
> > >> anything but symbols which begins with "Q" (or fullly-uppercase
> > >> macros and similar things).
> > >>
> > >> I'd really prefer to have it named something like "qtsignature".
> > >
> > > A decorator is just a function and needs to reside in a namespace.
> > > While I could put the signature() function in the global namespace,
> > > that would be dumb.
> >
> > You can put it within the QtCore namespace, but please consider that many
> > people *will* use "from QtCore import *", as it's the default way to make
> > the code similar to the C++ counterpart. If Trolltech added a "signature()"
> > function, people would complain. Trolltech doesn't use standard C++
> > namespaces, but they have their own namespace: they prefix every class name
> > with uppercase Q, and every function name with lowercase q. This is why I
> > think PyQt is going the wrong way if it starts suggesting to explicitally
> > use QtCore before everything and/or makes it harder for people to use the
> > "from QtCore import *" form.
> >
> > So, if you're going to add a PyQt-specific name, please make it follow the
> > Trolltech's convention. QtCore.qSignature would surely be better (there are
> > pre cedence of global functions named qFooBar in Qt's API).
>
> Trolltech are much more likely to add a function called qSignature() than one
> called signature(). Isn't calling it pyqtSignature() the safest and most
> consistent?
>
dir(QtCore) shows that it contains other Qt names which are not prefixed
with 'q' or 'Q'. IMO, those names serve to make Qt streams feel like the
standard C++ streams.
The risk that TT will pollute the C++ global namespace with other names not
prefixed by 'q' or 'Q' looks rather low.
signature() has a clear meaning, the pyqt prefix is arbitrary (PYQT_ is an
existing prefix) and tries to fix something which will very likely never break.
Gerard
PS: I agree with Giovanni that the explicit QtModule.-style is way too verbose
Two of my fingers are already showing RSI symptoms and it is hard to keep code
within a 80 character line length).
'import PyQt4.QtCore as qt' is a partial solution.
More information about the PyQt
mailing list