[SciPy-dev] gui_thread and chaco under Linux
Pearu Peterson
pearu at scipy.org
Mon Oct 6 15:20:40 CDT 2003
Hi,
Ok, now I have made some progress with calling chaco from Python prompt
under Linux. What follows is work-in-progress but shows that the idea
works:
from parallel_exec import ParallelExec
# the code of parallel_exec is given below
pexec = ParallelExec()
pexec("""\
import wxPython.wx
from chaco.wxplt import *
class MyApp(wxPython.wx.wxApp):
def OnInit(self):
return True
def show(): MyApp().MainLoop()
""")
plot([1,2,4]);pexec('show()') # shows a graph of [1,2,4]
# you can enter Python commands from the prompt
plot([1,2,5,4]);pexec('show()') # replaces previous graph with [1,2,5,4]
Note that show() must be called using pexec (that executes command in
the so-called parallel thread) otherwise Python prompt hangs until
a plot window is closed.
A way how to open multiple plot windows must be figured out. Ideas are
welcome.
Pearu
#-------------- parallel_exec.py -----------
# Author: Pearu Peteson <pearu at cens.ioc.ee>
# Created: Oct 6, 2003
import sys
import threading
import Queue
import traceback
class ParallelExec(threading.Thread):
""" Create a thread of parallel execution.
"""
def __init__(self,frame_level=0):
self.__queue = Queue.Queue(0)
self.__frame = sys._getframe(frame_level+1)
threading.Thread.__init__(self)
self.setDaemon(1)
self.start()
def __call__(self,code):
self.__queue.put(code)
def shutdown(self):
self.__queue.put(None)
def run(self):
while 1:
code = self.__queue.get()
if code is None:
break
frame = self.__frame
try:
exec (code, frame.f_globals,frame.f_locals)
except Exception:
traceback.print_exc()
#------------- EOF parallel_exec.py -----------
More information about the Scipy-dev
mailing list