call plt.image from a wx GUI?
![](https://secure.gravatar.com/avatar/89216dd750588714b8fd5b15ab239f0b.jpg?s=120&d=mm&r=g)
Hi all, I have a GUI that uses wxWindows. Following the tutorial, I've been starting it like:
import gui_thread <Importing wxPython... done.> import wxCCD proxy_class = gui_thread.register(wxCCD.MainWindow) win = proxy_class()
Now the GUI starts without tying up the command line. I'd like the GUI to display some data in another window, so it calls plt.image(scaled_data,None,None,colormap,'no') which hangs. A simple call to plt.plot([1,2,3],[4,5,6]) does that same. (Note: plt.image, plt.plot work fine from the command line, even with the wx GUI running.) Is there a good way to call the plt functions from within a wx GUI? Thanks, Adam scipy cvs_version = (1,105,1464,3694) Python 2.2.1 Redhat 7.3
![](https://secure.gravatar.com/avatar/606c6b30649a819832da296039ab3e6c.jpg?s=120&d=mm&r=g)
"AF" == Adam C Finnefrock <finnefro@sas.upenn.edu> writes:
>>>> import gui_thread <Importing wxPython... done.> >>>> import wxCCD proxy_class = >>>> gui_thread.register(wxCCD.MainWindow) win = proxy_class() AF> Now the GUI starts without tying up the command line. AF> I'd like the GUI to display some data in another window, so it AF> calls plt.image(scaled_data,None,None,colormap,'no') which AF> hangs. AF> A simple call to plt.plot([1,2,3],[4,5,6]) does that same. I thought that this used to work. There is obviously some threading issue here. Check to see if a proxied class is really created when you call the plt.plot function. It could also be that a proxied class is not created because the call is executed inside a proxy event. And once the function call is done there is a threading problem. I guess what I'm saying doesnt make any sense to you. Its just that gui_thread can get fairly complex. I ran a test case and got segfaults when I created a plot but the segfault occured only when I closed the window. Wierd. I dont have the time now to check it out. If I do get to doing it I'll see. However for now you can use the plot code from your code by doing something like so: def __init__(self, blah, blah): # add this next line somewhere in your constructor or whereever # you pack your gui elements. self.plotter = plt.plot_canvas(self, size=wxSize(250,250), title="Slicer") def plot(self, x, y): """ Use this to plot. """ self.plotter.line_list.data = [] lines = [] lines.extend(plt.lines_from_group((x,y))) for i in lines: self.plotter.line_list.append(i) self.plotter.update() This way you use the basic widget from the plt code inside yours and all this code should be proxied properly. I'll try and understand the gui_thread issue when I get some spare time. cheers, prabhu
![](https://secure.gravatar.com/avatar/89216dd750588714b8fd5b15ab239f0b.jpg?s=120&d=mm&r=g)
Prabhu Ramachandran <prabhu@aero.iitm.ernet.in> writes:
If I do get to doing it I'll see. However for now you can use the plot code from your code by doing something like so:
def __init__(self, blah, blah):
# add this next line somewhere in your constructor or whereever # you pack your gui elements. self.plotter = plt.plot_canvas(self, size=wxSize(250,250), title="Slicer")
def plot(self, x, y): """ Use this to plot. """ self.plotter.line_list.data = [] lines = [] lines.extend(plt.lines_from_group((x,y))) for i in lines: self.plotter.line_list.append(i) self.plotter.update()
Thanks very much! This worked well, and followed your example to add: def show_image(self, img, x=None, y=None, colormap='grey', scale='no'): """ Use this for images. """ self.plotter.line_list.data = [] self.plotter.image_list.data = [] image = plt.wxplt.image_object(img,x,y,colormap=colormap,scale=scale) self.plotter.image_list.append(image) self.plotter.update() Adam
participants (2)
-
finnefro@sas.upenn.edu
-
Prabhu Ramachandran