On 2007-09-27, Thorsten Kampe wrote: > * Mark Summerfield (Thu, 27 Sep 2007 08:45:59 +0100) > > > On 2007-09-26, Thorsten Kampe wrote: > > > I'm trying to teach myself GUI programmming with the help of the new > > > PyQt book and the examples from the PyQt package. Although I've been > > > doing Python for five years I have a hard time doing OOP stuff. > > > Frankly, I never know when and where to put this "self" thing. > > > > My book assumes that you're comfortable with the basics of OOP (and does > > mention this in the first para of the Introduction), so it will be a bit > > of a climb for you! > > I guess I am comfortable with OOP basics but I (like problably many > Pythonistas) hardly ever use (in my case because my scripts are all > less than one hundred lines of code). [snip]
One of Python's benefits is that it doesn't force the use of OOP. But in my view, OOP makes GUI programming a lot easier. > What I actually wanted to say is that I'm not sure whether I have > problems with OOP but I definitely have a problem with "self". > > I've tried your and Michael's version > > Michael's... > > # > dlg=QtGui.QDialog() > [...] > dlg.exec_() > # > ...works as well as > > # > dlg=QtGui.QDialog(self) > [...] > dlg.exec_() > # > > while your... > # > helpDialog = QtGui.QDialog(self) > [...] > helpDialog.show() > # > ...works only with "self". Using self in this context is better practice. If you have a top-level window in its own right then you don't need or want a parent (so don't pass self); but for all other widgets and windows (including dialogs) you should pass self. (See the Object Ownership sidebar on page 119 and the first para on page 142.) > Anyway, thanks a lot for the code completion and improvement... That's okay; good luck with your program:-) -- Mark Summerfield, Qtrac Ltd., www.qtrac.eu _______________________________________________ PyQt mailing list [email protected] http://www.riverbankcomputing.com/mailman/listinfo/pyqt
