[PyKDE] qt/python event loops

Gey-Hong Gweon gweon at umich.edu
Sat Jun 24 23:00:58 BST 2000


Have you ever run the python IDE "idle"? There, something like what you
want to do is achieved by inheriting the class
code.InteractiveInterpreter to make it suitable in the Tk
environment. If something like this is acceptable to you, then perhaps
you can do similarly in the Qt environment?

On Thu June/22/2000, 11:44:14 -0700, Ted Drain wrote: 
 > Hi all,
 > 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
 > so good.
 > 
 > 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
 > our users.  
 > 
 > 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!
 > 
 > Thanks
 > Ted
 > Ted Drain                             ted.drain at jpl.nasa.gov
 > 
 > 
 > _______________________________________________
 > PyKDE mailing list    PyKDE at mats.gmd.de
 > http://mats.gmd.de/mailman/listinfo/pykde

-- 
Gey-Hong Gweon, Research Fellow, Ph.D.
The University of Michigan, Physics Department, Ann Arbor, MI 48109-1120
(734) 647-9434 (Office), 763-3417 (Lab), 763-9694 (Fax) 




More information about the PyQt mailing list