QT window closes immediately

News123 news1234 at free.fr
Wed Nov 17 02:19:53 CET 2010


On 11/15/2010 02:04 AM, Martin Caum wrote:
> I am attempting to open a window on mouse activity which works, but
> the window fails to stay open.
> I set it to terminate when the escape key is pressed even when the
> program is not currently selected. This works fine. Originally I had
> it create the window only with a right click, but when I noticed the
> window closed immediately I set it to any mouse activity for easier
> debugging. My script is as follows:
> [code]
> import pythoncom, pyHook
> import sys
> import win32api
> from PyQt4 import QtGui, QtCore
> 
> class WindowObject(QtGui.QWidget):
> 	def __init__(self, parent=None):
> 		QtGui.QWidget.__init__(self, parent)
> 		self.setWindowTitle('Window')
> 		self.resize(50, 250)
> 
> def OnKeyboardEvent(event):
> 	if event.KeyID == 27:
> 		win32api.PostQuitMessage()
> 	return 1
> 
> def OnMouseEvent(event):
> 	x = event.Position[0]
> 	y = event.Position[1]
> 	createWindow(x, y)
> 	return 1
> 
> def createWindow(x, y):
> 	menu = WindowObject()
> 	menu.move(x, y)
> 	menu.show()
> 
> hm = pyHook.HookManager()
> hm.MouseAll = OnMouseEvent
> hm.KeyDown = OnKeyboardEvent
> hm.HookMouse()
> hm.HookKeyboard()
> 
> app = QtGui.QApplication(sys.argv)
> pythoncom.PumpMessages()[/code]
> I'm fairly certain that this is due to my lack of understanding in the
> PumpMessages command and the HookManager. Any advice?


Shouldn't every QT application have an event loop.

I would have expecte a call to app._exec()

as you need already pumpMessages() fro the COM interface, I assume you
had to use the threading or multiprocessing module as well.





More information about the Python-list mailing list