[PyKDE] qt/python event loops
teddrain at earthlink.net
Thu Jun 22 22:06:42 BST 2000
I trying to solve a seemingly difficult problem. We have a large set of
C/C++ code that we want to be scriptable (include Qt widgets/code). I've
written a C++ main program that does a lot of initialization and then calls:
PyRun_AnyFile( stdin, "<stdin>" )
to start the python processing from standard input. I don't have any
problems getting the existing library code available from python. So far
Now, we want to provide our users w/ a matlab style scripting interface w/
plotting support. I grabbed qwt (Qt plotting widget) and it works fine
for this application. What I'm trying to figure out is how to manage the
python/readline event loop and the Qt event loop. I want the user to be
able to create a plot widget and manipulate it on the screen while still
being able to use the python prompt in a normal way. Having to call
qapp.exec() to process the Qt events means I can't use the python prompt
until the Qt code is finished.
I have experience using select() and other event processing systems and
looked at the QSocketNotifier class. I've also experimented with the
readline library callback mechanism (for use w/ select) and understand how
that works. My initial plan was to setup a QSocketNotifier to watch stdin
and then start a qt event loop from my main program. I don't want to use
PyRun_SimpleString because I want a normal python interpreter w/ >>> and
... prompting, etc.
The problem I'm having is that python expects to call a readline function
like (I forget the actual python name):
char* getline( char* prompt )
Python uses a global function pointer variable for this call. I've
overloaded this function to provide a basic logging to file capability for
What I really wish I could do is have python tell me the correct prompt to
display, tell readline to display it, then go into the qt event loop. The
problem is that I don't know what prompt to display until this routine is
called, but python expects this routine to return the line to process.
What I really need is to have python call a setup( char* prompt ) function
to display the prompt and then have a processLine( char* line ) function
that I can call when a line is read. Since I can't find anything like this
in the python library, I'm now looking at processing the qt event loop by
hand inside the getline() routine that python is calling.
Has anyone tackled this problem before? Any help is greatly appreciated!
Ted Drain ted.drain at jpl.nasa.gov
More information about the PyQt