[SciPy-dev] gui_thread and chaco under Linux
pearu at scipy.org
Wed Oct 8 06:56:07 CDT 2003
On Tue, 7 Oct 2003, Prabhu Ramachandran wrote:
> Well, gui_thread does work under Linux. For example, this works for
> In : import gui_thread
> In : gui_thread.start()
> <Importing wxPython... i done.>
> In : import scipy.plt as plt
> In : p = plt.plot([1,4,9])
> I think its just that wxplt is not using gui_thread and is currently
> pure wxPython code.
Thank you for the clarification! I must admit that at first I really
didn't understand the code in gui_thread (now I do, after re-implementing
it almost from a scratch;-).
> As you have rightly discovered the way to
> chaco-on-interpreter-heaven is to call all wxPython related functions
> from another thread and this thread must be the first to import
> wxPython. To use gui_thread you need to 'register' a class with it.
> gui_thread then returns a massaged class wraps around the actual class
> that the actual functions are called in the right thread. It also
> tries to handle attribute access safely. However, this is from memory
> having hacked on gui_thread about two years ago and a few things might
> have changed. Anyway, the way to register a class with gui_thread is
> to do the following:
> wrapped_class = gui_thread.register(some_wx_python_class)
> Then you create wrapped_class instances as you would create
> some_wx_python_class and it should work (in theory).
This will not work for chaco anymore because chaco executes wxPython
functions during chaco.wxplt import.
> I can't test this because I cannot run chaco anymore. kiva no longer
> builds under gcc 2.95.4. :(
Yes. In fact, this triggered me to upgrade gcc on my debian system.
It turned out to be quite painless, now I have
gcc-2.95 gcc-3.2 gcc-3.3
nicely co-existing on my system.
You could try the same ^K ;-)
> Admittedly, the gui_thread approach is a hack and has limitations but
> it used to work pretty OK. Eric was talking about a better approach
> that IIRC is similar to your approach (1). As you notice its a
> non-trivial job and AFAIK no one has yet had a stab at it.
I took this challenge and here are intermediate results:
>>> from parallel_exec import ParallelExec
>>> pexec=ParallelExec() # create wxPython thread
>>> pexec('import wxPython.wx')
>>> pexec('from wrap_wx import ParallelExec_wxApp;app=ParallelExec_wxApp()')
# Now calling app will execute commands in wxPython thread:
>>> app('from chaco.wxplt import *')
>>> app('plot([1,2])') # creates a plot [1,2]
>>> app('figure()') # opens new empty window
>>> app('plot([5,2])') # creates a plot [5,2] in new window
that is, I can already use chaco from my Linux prompt! And I have made no
changes to chaco for that. The next step is to make
>>> from chaco.wxplt import *
More information about the Scipy-dev