[PyQt] Symbol naming system for PyQt under Python 3

Giovanni Bajo rasky at develer.com
Fri Dec 12 22:28:20 GMT 2008


On 12/12/2008 11:18 PM, Paul A. Giannaros wrote:
> On Fri, Dec 12, 2008 at 6:27 PM, Phil Thompson
> <phil at riverbankcomputing.com> wrote:
>> On Fri, 12 Dec 2008 18:09:56 +0000, "Paul A. Giannaros"
>> <paul at giannaros.org> wrote:
>>> Hi all,
>>>
>>> When there was a discussion regarding PyQt wishes for Python 3.0 I
>>> proposed changing the mechanism by which you refer to symbols[1] .
>>> Thus something like "QtGui.QApplication" could be refered to as
>>> "Qt.Application".
>>> As Qt does not use namespaces itself, there would be no conflicts of
>>> names. The idea is that you'd then import any module and its symbols
>>> would then be added to the Qt namespace when you've done so. This
>>> system would therefore save on redundant typing while sidestepping
>>> namespace pollution.
>>>
>>> Any thoughts on this?
>> Nothing printable ;)
>>
>> You can already do Qt.QApplication is you really want to, so you are saving
>> yourself one character.
> 
> "from PyQt4 import Qt" imports every module if I'm not mistaken.
> Wanting a sane way of referencing Qt's symbols is not the same as
> wanting every symbol from every module to be imported.

How is it possible to implement your proposal without importing every 
module at the same time, and without playing magic tricks?

> Surely losing that one character is great if it's unnecessary. The
> QtRuby guys seem to use exactly the same naming system that I propose
> and it works fine for them and looks much better.

In the number-of-character race, I win with star-imports:

from PyQt4.QtCore import *
from PyQt4.QtGui import *

w = QWidget()

Since 99.999% of the names in there starts with "Q", I never ever have a 
conflict. The code is easy on the eye, and resembles its C++ equivalent.

>> Qt does use namespaces. KDE uses lots of namespaces.
> 
> The main Qt library does not for its separate modules, which is what
> I'm talking about. 

... which is exactly why the star-import works perfectly.

[PS: in case it's not clear, I'm -1 on the "Qt.Application" proposal; 
IMO, the official "QtCore.QCoreApplication" and the short-n-fast 
star-imported "QCoreApplication" already cover enough tastes]
-- 
Giovanni Bajo
Develer S.r.l.
http://www.develer.com


More information about the PyQt mailing list