[PyKDE] QApplication.notify gets QObject receiver arg

alh at jenkon.com alh at jenkon.com
Thu Apr 25 22:22:01 BST 2002


Howdy,

I have some interesting behavior that 


Environment is Win2000, Python 2.1.3, Qt 3.0.3, PyQt 3.1.


Console:

C:\>python test.py
focus-in <qt.QPushButton instance at 0080331C>
open <__main__.TestWin instance at 0080AF34>
focus-in <qt.QLineEdit instance at 007FD7AC>
focus-in <qt.QLineEdit instance at 007FD134>
focus-in <qt.QLineEdit instance at 007FD7AC>
focus-in <qt.QPushButton instance at 0080331C>
close <__main__.TestWin instance at 0080AF34>
open <__main__.TestWin instance at 0080AF34>
focus-in <qt.QObject instance at 007F5704>
focus-in <qt.QObject instance at 007F568C>
focus-in <qt.QObject instance at 007F5704>
focus-in <qt.QPushButton instance at 0080331C>
close <__main__.TestWin instance at 0080AF34>


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

import sys
import qt

class App(qt.QApplication):
    def notify(self, receiver, event):
        if event.type() == qt.QEvent.FocusIn:
            print 'focus-in', receiver
        return qt.QApplication.notify(self, receiver, event)

class MainWin(qt.QMainWindow):
    def __init__(self):
        qt.QMainWindow.__init__(self)
        self.wnd = None
        btn = qt.QPushButton('Click', self)
        btn.resize(btn.sizeHint())
        self.connect(btn, qt.SIGNAL('clicked()'), self.toggleWindow)

    def toggleWindow(self):
        if self.wnd:
            print 'close', self.wnd
            self.wnd.close(1)
            self.wnd = None
        else:
            self.wnd = TestWin()
            print 'open', self.wnd
            self.wnd.show()

class TestWin(qt.QMainWindow):
    def __init__(self):
        qt.QMainWindow.__init__(self)
        main = qt.QWidget(self)
        self.setCentralWidget(main)
        layout = qt.QVBoxLayout(main)
        layout.addWidget(qt.QLineEdit(main))
        layout.addWidget(qt.QLineEdit(main))

if __name__ == '__main__':
    app = App(sys.argv)
    win = MainWin()
    win.show()
    app.connect(app, qt.SIGNAL('lastWindowClosed()'), app, qt.SLOT('quit()'))
    app.exec_loop()

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<










More information about the PyQt mailing list