Re: [PyKDE] QtCore.Qt and QtGui.Qt
On Thursday 02 March 2006 9:07 am, Sreeram Kandallu wrote: Hi I just have a couple of questions regarding conventions that are being followed in PyQt4. I'm using the '20060226' snapshots of PyQt4 and Sip, and i noticed that the Qt namespace is present in *both* QtCore and QtGui! why is that? Also, enums like Qt::WindowFlags are present in QtCore.Qt, whereas a few enums like Qt::WhiteSpaceMode are present in QtGui.Qt! What is the reasoning for this? The short answer is that the Python objects are placed in the module corresponding to the C++ library in which they are implemented. Up until recently I had planned (and partially implemented) the idea that a namespace would only appear once and that any objects implemented in other modules would be placed in it. In other words... from PyQt4 import QtCore dir(QtCore) from PyQt4 import QtGui dir(QtCore) ...would give different output for each dir(). This was a pain to implement and (I thought) more confusing for the user - I'm not saying which of those carried the most weight. Basically, namespaces are second class citizens compares to modules. Phil ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
Phil Thompson wrote: The short answer is that the Python objects are placed in the module corresponding to the C++ library in which they are implemented. Does this mean that Qt::WindowFlags and such will be moved from QtCore.Qt to QtGui.Qt? Regards Sreeram signature.asc Description: OpenPGP digital signature ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
On Thursday 02 March 2006 9:59 am, Sreeram Kandallu wrote: Phil Thompson wrote: The short answer is that the Python objects are placed in the module corresponding to the C++ library in which they are implemented. Does this mean that Qt::WindowFlags and such will be moved from QtCore.Qt to QtGui.Qt? No. Even though they are GUI related, Qt implements them in QtCore. Phil ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
On Thu, Mar 02, 2006 at 09:46:03AM +, Phil Thompson wrote: The short answer is that the Python objects are placed in the module corresponding to the C++ library in which they are implemented. Hmm, meaning that this: ---[ Code snippet ] from PyQt4.QtCore import Qt as Qt1 from PyQt4.QtGui import Qt as Qt2 if Qt1 is Qt2: print The Force is strong with that one. else: print Wow, we might be having a structural problem of sorts there... --- ... would actually not print out a cheap Star Wars statement regarding PyQt? Shouldn't the Qt namespace be common across all the modules? I understand that's the case with the C++ version, isn't it? With kind regards, -- S. ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
On Thursday 02 March 2006 10:21 am, Sundance wrote: On Thu, Mar 02, 2006 at 09:46:03AM +, Phil Thompson wrote: The short answer is that the Python objects are placed in the module corresponding to the C++ library in which they are implemented. Hmm, meaning that this: ---[ Code snippet ] from PyQt4.QtCore import Qt as Qt1 from PyQt4.QtGui import Qt as Qt2 if Qt1 is Qt2: print The Force is strong with that one. else: print Wow, we might be having a structural problem of sorts there... --- ... would actually not print out a cheap Star Wars statement regarding PyQt? Correct - they are different objects, as you would expect them to be. Shouldn't the Qt namespace be common across all the modules? I understand that's the case with the C++ version, isn't it? A C++ namespace doesn't have an implementation, it just contributes to name mangling. In Python they have to be implemented by something so there is no direct comparison. Phil ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
Phil Thompson [EMAIL PROTECTED] wrote: Up until recently I had planned (and partially implemented) the idea that a namespace would only appear once and that any objects implemented in other modules would be placed in it. In other words... from PyQt4 import QtCore dir(QtCore) from PyQt4 import QtGui dir(QtCore) ...would give different output for each dir(). This was a pain to implement and (I thought) more confusing for the user - I'm not saying which of those carried the most weight. Are you saying that this: --- from PyQt4.QtCore import * from PyQt4.QtGui import * dir(Qt) --- won't show the full Qt namespace, thus making PyQt4 unusable without the annoying QtCore/QtGui prefix in front of everything? -- Giovanni Bajo ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
On 02.03.06 12:09:46, Giovanni Bajo wrote: Phil Thompson [EMAIL PROTECTED] wrote: Up until recently I had planned (and partially implemented) the idea that a namespace would only appear once and that any objects implemented in other modules would be placed in it. In other words... from PyQt4 import QtCore dir(QtCore) from PyQt4 import QtGui dir(QtCore) ...would give different output for each dir(). This was a pain to implement and (I thought) more confusing for the user - I'm not saying which of those carried the most weight. Are you saying that this: --- from PyQt4.QtCore import * from PyQt4.QtGui import * dir(Qt) --- won't show the full Qt namespace, thus making PyQt4 unusable without the annoying QtCore/QtGui prefix in front of everything? I think that's what Phil said, isn't it? [EMAIL PROTECTED]:~/xkbconfigpython Python 2.4.2 (#1, Jan 3 2006, 21:29:15) [GCC 4.0.3 20051201 (prerelease) (Debian 4.0.2-5)] on linux2 Type help, copyright, credits or license for more information. from PyQt4.QtCore import * [25861 refs] len(dir(Qt)) 760 [29386 refs] from PyQt4.QtGui import * ^[[A[42008 refs] len(dir(Qt)) 25 That's the evidence. And if I understood Phil correct, if you want a single Qt namespace you get yourself into a lot of trouble. Andreas -- You will be Told about it Tomorrow. Go Home and Prepare Thyself. ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
On Thursday 02 March 2006 11:09 am, Giovanni Bajo wrote: Phil Thompson [EMAIL PROTECTED] wrote: Up until recently I had planned (and partially implemented) the idea that a namespace would only appear once and that any objects implemented in other modules would be placed in it. In other words... from PyQt4 import QtCore dir(QtCore) from PyQt4 import QtGui dir(QtCore) ...would give different output for each dir(). This was a pain to implement and (I thought) more confusing for the user - I'm not saying which of those carried the most weight. Are you saying that this: --- from PyQt4.QtCore import * from PyQt4.QtGui import * dir(Qt) --- won't show the full Qt namespace, thus making PyQt4 unusable without the annoying QtCore/QtGui prefix in front of everything? Yes - I hadn't considered that - mainly because I don't adopt such a poor programming practice ;) Seriously, I don't have much sympathy for people using a feature that makes it easy to shoot yourself in the foot, and which is slated for removal in a future version of Python. That said I can see lots of bug reports from lazy programmers, and I definitely want to avoid that. Phil ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
Giovanni Bajo wrote: Are you saying that this: --- from PyQt4.QtCore import * from PyQt4.QtGui import * dir(Qt) --- won't show the full Qt namespace, thus making PyQt4 unusable without the annoying QtCore/QtGui prefix in front of everything? There are very few entries in QtGui.Qt, so as a workaround you can import QtCore *after* QtGui from PyQt4.QtGui import * from PyQt4.QtCore import * from PyQt4 import QtGui and if you need QtGui.Qt, you can use that alone with a explicit QtGui prefix. But ofcourse, i would still prefer that QtCore.Qt and QtGui.Qt were the same! :) (or better still, not have QtGui.Qt at all!!) Regards Sreeram signature.asc Description: OpenPGP digital signature ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
On Thu, Mar 02, 2006 at 10:41:45AM +, Phil Thompson wrote: A C++ namespace doesn't have an implementation, it just contributes to name mangling. In Python they have to be implemented by something so there is no direct comparison. Point! Although I feel Giovanni does have a point as well. Having DIFFERENT Qt namespaces lying around is super ungood. Recipe for pain, that. I think this is one of those cases where we should polish things into submission manually if need there. I can see several potential approaches. 1) Having the Qt namespace as an external module. Modules are good. Modules are designed precisely for the purpose of providing namespaces. However, the current PyQt implementation might not make that feasible. 2) Updating QtCore.Qt's __dict__ in the other modules instead of creating a new Qt there. You know, from QtCore import Qt Qt.__dict__.update(my_own_Qt_namespace) ... inside each module other than QtCore. Just an idea anyway. What do you guys think? -- S. ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
Phil Thompson [EMAIL PROTECTED] wrote: --- from PyQt4.QtCore import * from PyQt4.QtGui import * dir(Qt) --- won't show the full Qt namespace, thus making PyQt4 unusable without the annoying QtCore/QtGui prefix in front of everything? Yes - I hadn't considered that - mainly because I don't adopt such a poor programming practice ;) Seriously, I don't have much sympathy for people using a feature that makes it easy to shoot yourself in the foot, So you're one of those programmers who writes a Python module which uses Qt, and defines a class called QWidget or qSIGNAL in it, which has nothing to do with Qt? Because really, that's the only reason why you should suffer from writing **and reading** all those boring and obfuscating QtCore and QtGui prefixes everywhere. I don't need to read QtGui to know what a QComboBox is, while I strongly need re to know what compile means. The star-import is the equivalent of using namespace in C++. It's bad practice to write using namespace in header files (for which there is simply no equivalent in Python), but it's very common and actually *smart* to write using namespace in source files, especially source files which are tightly connected with the library wrapped in the namespace. It'd be a major annoyance if C++ removed using namespace, and in fact they are not going to remove it. But really, I'm not in a one-man war trying to change people's mind. People are obviously free to use UK.RiverbankComputingLtd.PyQt4.QtGui.QWidget if they find it useful, as long as PyQt official supports the star-import alternative syntax. and which is slated for removal in a future version of Python. It must be a *very* future version of Python, since its removal is not even mentioned in PEP 3000. That said I can see lots of bug reports from lazy programmers, and I definitely want to avoid that. Thanks, it's appreciated. -- Giovanni Bajo ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
Sundance [EMAIL PROTECTED] wrote: 1) Having the Qt namespace as an external module. Perfect. I'm +1 on this. 2) Updating QtCore.Qt's _dict_ in the other modules instead of creating a new Qt there. This would be *very* confusing and very implicit. I'm -1000 on this. -- Giovanni Bajo ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
Giovanni Bajo wrote: This would be *very* confusing and very implicit. I'm -1000 on this. Actually, it's more than merely implicit: it's Plain Freaking Magic. And magic is dangerous. I agree that making the Qt namespace a module of its own would be one darn lot better. What I don't know is whether it's possible. Phil? -- S. ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
On Thu, 2 Mar 2006 12:42:42 +0100 Sundance [EMAIL PROTECTED] wrote: On Thu, Mar 02, 2006 at 10:41:45AM +, Phil Thompson wrote: A C++ namespace doesn't have an implementation, it just contributes to name mangling. In Python they have to be implemented by something so there is no direct comparison. Point! Although I feel Giovanni does have a point as well. Having DIFFERENT Qt namespaces lying around is super ungood. Recipe for pain, that. I think this is one of those cases where we should polish things into submission manually if need there. I have been wondering for some time if it wouldn't be better to merge QtCore and QtGui into one single module. This resolves the problem of the Qt namespace clashes. Eventually there could be a QtCore module for people who really only need QtCore (how many?). I see the value of the module prefixes, but the separation in QtCore, QtGui, QtOpenGL is very verbose and I agree that it does not improve readability. I propose a plain Python module PyQt4.qt reading: from PyQt4.QtGui import * from PyQt4.QtOpenGL import * # etc... PyQt4's configure.py can figure out which other modules to import This module could be used as: import qt or (admittedly dangerous): from qt import * Gerard PS: http://mats.imk.fraunhofer.de/pipermail/pykde/2006-January/012179.html is a bit revolutionary, but I like the idea of typing qt.ComboBox. ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
On Thu, 2 Mar 2006 15:26:50 +0100 Gerard Vermeulen [EMAIL PROTECTED] wrote: I have been wondering for some time if it wouldn't be better to merge QtCore and QtGui into one single module. This resolves the problem of the Qt namespace clashes. Eventually there could be a QtCore module for people who really only need QtCore (how many?). I see the value of the module prefixes, but the separation in QtCore, QtGui, QtOpenGL is very verbose and I agree that it does not improve readability. I propose a plain Python module PyQt4.qt reading: from PyQt4.QtGui import * from PyQt4.QtOpenGL import * # etc... PyQt4's configure.py can figure out which other modules to import This module could be used as: import qt or (admittedly dangerous): from qt import * Oops, I mean import PyQt4.qt as qt or from PyQt4.qt import * Gerard ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
On Thu, Mar 02, 2006 at 02:01:35PM +, Phil Thompson wrote: As I said in another reply - I don't see the difference. Whether it's PyQt4.Qt rather than PyQt4.QtCore.Qt, the magic still has to happen when you import QtGui. Well, I think the idea is that the Qt namespace would contain everything it needs to, from all the PyQt modules, right from the start. I.e. even if you only import QtCore, the Qt namespace would contain WhiteSpaceMode and all. Always the same, no changes no matter what you import and don't import. But as said, I understand that this may not be easily feasible within the SIP/PyQt architecture (because, mind, I don't know HOW the namespace is implemented there to start with. There are a lot of people here who Know Their Shit like there's no tomorrow, but I'm not one of them). -- S. ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
On Thursday 02 March 2006 2:26 pm, Gerard Vermeulen wrote: On Thu, 2 Mar 2006 12:42:42 +0100 Sundance [EMAIL PROTECTED] wrote: On Thu, Mar 02, 2006 at 10:41:45AM +, Phil Thompson wrote: A C++ namespace doesn't have an implementation, it just contributes to name mangling. In Python they have to be implemented by something so there is no direct comparison. Point! Although I feel Giovanni does have a point as well. Having DIFFERENT Qt namespaces lying around is super ungood. Recipe for pain, that. I think this is one of those cases where we should polish things into submission manually if need there. I have been wondering for some time if it wouldn't be better to merge QtCore and QtGui into one single module. This resolves the problem of the Qt namespace clashes. Eventually there could be a QtCore module for people who really only need QtCore (how many?). I see the value of the module prefixes, but the separation in QtCore, QtGui, QtOpenGL is very verbose and I agree that it does not improve readability. I'm not going to break the 1:1 relationship between the module and the corresponding Qt library. I'm not going to throw away the benefits that Qt4 introduced by splitting Qt into separate libraries. Phil ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
Gerard Vermeulen [EMAIL PROTECTED] wrote: I have been wondering for some time if it wouldn't be better to merge QtCore and QtGui into one single module. This resolves the problem of the Qt namespace clashes. Eventually there could be a QtCore module for people who really only need QtCore (how many?). Not many Python users of course, but there are C++ people who bought QtCore only (there is a specific license for that) and use it as a portability layer for C++ for non-GUI applications. Qt4 did the split on purpose, and I think PyQt should match it. I propose a plain Python module PyQt4.qt reading: from PyQt4.QtGui import * from PyQt4.QtOpenGL import * # etc... PyQt4's configure.py can figure out which other modules to import Yes, this might be a good idea. PS: http://mats.imk.fraunhofer.de/pipermail/pykde/2006-January/012179.html is a bit revolutionary, but I like the idea of typing qt.ComboBox. Yeah, me too. wxWidgets went for it for a reason. -- Giovanni Bajo ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
On Thursday 02 March 2006 2:45 pm, Sundance wrote: On Thu, Mar 02, 2006 at 02:01:35PM +, Phil Thompson wrote: As I said in another reply - I don't see the difference. Whether it's PyQt4.Qt rather than PyQt4.QtCore.Qt, the magic still has to happen when you import QtGui. Well, I think the idea is that the Qt namespace would contain everything it needs to, from all the PyQt modules, right from the start. I.e. even if you only import QtCore, the Qt namespace would contain WhiteSpaceMode and all. Always the same, no changes no matter what you import and don't import. But as said, I understand that this may not be easily feasible within the SIP/PyQt architecture (because, mind, I don't know HOW the namespace is implemented there to start with. There are a lot of people here who Know Their Shit like there's no tomorrow, but I'm not one of them). What you describe can be implemented, but it means that the Qt module must be linked against the Core and Gui Qt libraries. This is an absolute no as far as I am concerned - you must be able to write a non-GUI application without having to drag in the QtGui library. The magic is needed to avoid this dependency. Phil ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
On Thursday 02 March 2006 2:38 pm, Gerard Vermeulen wrote: On Thu, 2 Mar 2006 15:26:50 +0100 Gerard Vermeulen [EMAIL PROTECTED] wrote: I have been wondering for some time if it wouldn't be better to merge QtCore and QtGui into one single module. This resolves the problem of the Qt namespace clashes. Eventually there could be a QtCore module for people who really only need QtCore (how many?). I see the value of the module prefixes, but the separation in QtCore, QtGui, QtOpenGL is very verbose and I agree that it does not improve readability. I propose a plain Python module PyQt4.qt reading: from PyQt4.QtGui import * from PyQt4.QtOpenGL import * # etc... PyQt4's configure.py can figure out which other modules to import This module could be used as: import qt or (admittedly dangerous): from qt import * Oops, I mean import PyQt4.qt as qt or from PyQt4.qt import * I like it - except I would use Qt rather than qt. In fact I really, really like it. Phil ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
On Thu, Mar 02, 2006 at 02:58:18PM +, Phil Thompson wrote: What you describe can be implemented, but it means that the Qt module must be linked against the Core and Gui Qt libraries. Oookay, you've lost me there. I thought that, with the exception of convertFromPlainText(), escape() and mightBeRichText() (which you can implement as part of QtGui all you want, since they're defined in QTextDocument anyway), the Qt namespace only contained enums? What am I missing here? Does the way PyQt works absolutely requires that the enums would be the exact C++ type that the library uses, rather than, you know, just ints...? Thanks, -- S. ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
On Thursday 02 March 2006 3:43 pm, Sundance wrote: On Thu, Mar 02, 2006 at 02:58:18PM +, Phil Thompson wrote: What you describe can be implemented, but it means that the Qt module must be linked against the Core and Gui Qt libraries. Oookay, you've lost me there. I thought that, with the exception of convertFromPlainText(), escape() and mightBeRichText() (which you can implement as part of QtGui all you want, since they're defined in QTextDocument anyway), the Qt namespace only contained enums? What am I missing here? Does the way PyQt works absolutely requires that the enums would be the exact C++ type that the library uses, rather than, you know, just ints...? It's the functions you mention - their namespace is Qt not QTextDocument. They are defined in the file qtextdocument.cpp but that's irrelevant. Having a namespace convention for enums and a different one for functions and classes isn't acceptable. Phil ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
On Thu, Mar 02, 2006 at 03:15:45PM +, Phil Thompson wrote: I like it - except I would use Qt rather than qt. In fact I really, really like it. Ditto! Giovanni, say: would that also remove the drawback from your awesome static PyQt module project? I looked into the issue of distributing easy-to-install binaries for Windows, and couldn't get around the problem of PyQt's size. So I'm really enthusiastic about your project. Do you intend to distribute pre-made PYDs, by the way? Thanks, -- S. ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] QtCore.Qt and QtGui.Qt
Sundance [EMAIL PROTECTED] wrote: I like it - except I would use Qt rather than qt. In fact I really, really like it. Ditto! Giovanni, say: would that also remove the drawback from your awesome static PyQt module project? I looked into the issue of distributing easy-to-install binaries for Windows, and couldn't get around the problem of PyQt's size. So I'm really enthusiastic about your project. As far as I can tell, yes. It would mean that if you always use PyQt4.Qt instead of naming the single modules, your code will be compatible in both the normal (shared) mode and the static mode. Do you intend to distribute pre-made PYDs, by the way? There are many combinations of course, but I believe we could make a pre-built package for the QtCore+QtGui combo, and one with all the modules compiled in. My opinion is that it would be convenient for the static mode to make it into the official configure.py, and also be the default mode for the official binary Qt4-PyQt4-Win-GPL package. It would mean a smaller download for the developer, and smaller executables for those building stand-alone apps. -- Giovanni Bajo ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde