4

I have a GUI application that is written using win API's and we need to launch a new GUI application when the user selects some command menu items. We decided to write the new application in PyQt and launch the PyQt application usig Python C Api.

Everything is working fine except that the Parent window, through which we launch the PyQt Application, is not responding to some of the events when PyQt application is open. Once we close the PyQt Application it starts responding again to the key events.

I guess, that once the PyQt Gui application is launched, somehow the messages are not passed to the Parent window.

Inspecting with Spy++ I've found the following result:

Receives messages for:
  - ALT key
  - F1, F2 keys
  - Mouse events

Does NOT receive messages for:
  - CTRL key
  - All other Fn keys
  - All letter keys
  - SHIFT, CAPS keys

Any thoughts to solve this problem would be appreciated

Luis Quijada
  • 2,345
  • 1
  • 26
  • 31
Maverick
  • 366
  • 1
  • 5
  • 11
  • So you mean the parent window is not a Qt widget? How are you launching QApplication? In a separate thread? Are you handling F1, F2 keypressEvents in ur Qt widget? – Chenna V Jun 28 '12 at 16:32
  • Yes parent window is not a QtWigget its entirely written using C and WinAPI's and PyQt window is launched by embedding the python interpreter in that C code. – Maverick Jun 28 '12 at 16:56
  • well QApplication should be running by calling exec() which is a blocking call so I guess you are running it in a separate thread. And I expect none of the keypresses to be sent to the parent window since its not a parent widget of the PyQt window. – Chenna V Jun 28 '12 at 17:43
  • Using Python C API we can import the python module and run it Which eventually call the exec() method of QApplication. We haven't used any new thread to launch PyQt app and still nothing has be blocked except the Key events. – Maverick Jun 28 '12 at 18:01

2 Answers2

0

I believe what you are trying to do -- operate two separate GUIs within a single process -- is not supported by any major operating system. A while back, I searched for a long time for ways to do this and never came up with any advice except "don't".

I'm surprised that missing keys are the only problem you have.. I recommend finding a different solution before you discover more trouble (unless you can find some good evidence that this is at least supposed to work).

Could you perhaps spawn a new process to run the Qt event loop instead? Since you already have python embedded in the main process, this should be fairly easy--use python's built-in IPC to handle the communication between processes.

Luke
  • 11,374
  • 2
  • 48
  • 61
  • You are not actually running two separate GUIs. On Windows Qt is just a wrapper aroudn the Win32 API. The two can be made to work together in C++ using the QtWinMigrate DLL. – cdiggins Nov 29 '13 at 15:44
0

One solution is to build the QtWinMigrate module to create a QWinHost which supports parenting to a native HWND but unfortunately it is not part of the PyQt distribution.

You can find some sources here: https://github.com/glennra/PyQtWinMigrate.

This is what had to be done for Python integration in 3ds Max by Blur studio. I am currently studying the C++ source code of QWinWidget too see if I can work out an alternative solution using Win32 calls.

cdiggins
  • 17,602
  • 7
  • 105
  • 102