[PyQt] Confused by this class hierachie ... (large)

Anon anon at nowhere.net
Thu Sep 13 17:47:19 EDT 2001


Dear Mr. Rempt,

thank you for your answer to my post. Unfortunately it seems that I must 
have been unclear about my problem. Actually it is not my problem to *show* 
the dialog, rather it is to let the dialog perform actions on a specific
class instance. Let me present you some code snippets:

-----------------
file 'widgets.py'
-----------------

from qt import *

class myMultiLineEdit(QMultiLineEdit):
        def __init__(self, *args):
                apply(QMultiLineEdit.__init__, (self, ) + args)

        def mousePressEvent(self,e):
                if e.button() == QMouseEvent.RightButton:
                        contextMenu = QPopupMenu(self)
                        id_link = contextMenu.insertItem("menuItem")
                        r = contextMenu.exec_loop(e.globalPos())
                        if r == id_link:
                                dialog(self.parent())
                else:
                        QMultiLineEdit.mousePressEvent(self,e)

        
- class widget(QWidget)
        o uses myMultiLineEdit
                        
- class mainWidget(QWidget)
        o uses widget

class dialog(QDialog):
        def __init__(self,parent = None,name = None,modal = 0,fl = 0):
                QDialog.__init__(self,parent,name,modal,fl)
                
                Now lets say the user is asked to input some arbitrary
                values which should be added to the shelve object defined 
                below. Therefore I think the dialog instance above has to 
                know about 'w' as an instance of 'gui' - but how?




------------
file 'ui.py'
------------

from qt import *
import widgets, shelve

class gui(QMainWindow):
        def __init__(self, parent=None, name=None, filename='/tmp/test'):
                self.db = shelve.open(filename)
                ...
                self.mw = widgets.mainWidget(self)
                self.setCentralWidget(self.mw)
                ...

        def add(self):
                self.db['key'] = 123

                

---------------
file 'start.py'
---------------

import sys, ui
from qt import *


if __name__ == '__main__':
        a = QApplication(sys.argv)
        QObject.connect(a,SIGNAL('lastWindowClosed()'),a,SLOT('quit()'))
        w = ui.gui()
        a.setMainWidget(w)
        w.show()
        a.exec_loop()




I hope that it is now expressed more clearly what my problem actually is. 
If you could (once again) give me an advice?

Kind regards.



Boudewijn Rempt wrote:

> 
> Well, without some actual code it's difficult to tell exactly what your
> problem is. What I mostly do is create the dialogs in the constructor of
> my main window class - that makes it available everywhere. You create
> the dialog with the main window instance as parent, and that means you
> can get at the main window from the dialog with self.parent().
> 
> You can take a look at http://stage.linuxports.com/pyqt/x1771.htm or
> http://stage.linuxports.com/pyqt/c3816.htm - the first is about the
> standard dialogs PyQt offers, the second about creating real, complex
> dialogs.
> 
> If those chapters don't clear away your confusion, please tell
> me - then I can adapt the text and make it clearer!
> 
> --
> 
> Boudewijn Rempt  | http://www.valdyas.org
> 




More information about the Python-list mailing list