[PyQt] Symbol naming system for PyQt under Python 3
david at boddie.org.uk
Fri Dec 12 23:49:50 GMT 2008
On Fri Dec 12 22:57:22 GMT 2008, Paul A. Giannaros wrote:
> Way out, I'm afraid. ~60% of QtCore symbols start with a "Q", and a
> further ~21% start with a "q". That still leaves around 32 symbols
> (16%) once you weed out __doc__ etc. Some have ridiculously common
> names ("center", "flush", "bin"), and some conflict with basic Python
> builtins ("hex" and "oct").
I hate the way hex pollutes the namespace. I'd really like those
functions to be put away somewhere, like the Qt namespace for instance,
though maybe it's not so great an impact for others as it is for me.
> QtGui is much better but still has a "Display" class.
I believe that this class is of limited use from within Python, but maybe
it's just another case where a class should have been put in a namespace.
> Anyways, I believe I've seen it mentioned on this list that "import *"
> with PyQt method is frowned upon.
Yes, importing QtGui as a module rather than importing its contents. With
your suggestion, this would result in something like this:
w = QtGui.Widget()
> No, my proposal is dropping the leading Q and using a Qt namespace
> that doesn't require loading all modules. That way does seem
> particularly odd, though. Perhaps a less counter-intuitive method
> would be something like
> from pyqt4 import Qt
> Qt.load('core', 'gui', 'svg')
That's a fairly unusual solution, it has to be said.
My only problem with the Q-less naming convention is that some of the class
names are fairly generic and might conflict with the users' own naming
conventions. On the other hand, if people feel more comfortable with this
style, perhaps it could be enabled if the user imports a particular module
that contains proxies for all the Q-prefixed classes.
However, the major disadvantage with supporting two different naming schemes
is the confusion it might cause for new users.
More information about the PyQt