python - Starting a new event loop for chaco-traits popup window from pyside? -
i trying make numpy image slider using chaco launched pyside. ive tried using matplotlib lacked speed updating ive been trying chaco instead. script below starts initializing pyside dialog, here trying open chaco/traits window used display different views of numpy arrays using slider scroll through arrays movie. script works warning message:
qcoreapplication::exec: event loop running
i think need start chaco window using own thread or not sure how go it. appreciated, script below:
import numpy np import sys pyside.qtcore import * pyside.qtgui import * app = qapplication(sys.argv) traits.api import * traitsui.api import * enable.api import * enable.component_editor import * chaco.api import * chaco.tools.api import * chaco import * class chacowindow(hastraits): #chaco popup window slider plot = instance(hplotcontainer) #slider max value set using frame frame = int high = 100 traits_view = view(group( item('plot', editor=componenteditor(), show_label=false), item( 'frame', editor = rangeeditor( high_name = 'high', format = '%d', is_float = false))), width=1000, height=600, resizable=true, title="track viewer") def __init__(self, datadict, arg1): self.high = arg1 - 1 self.datadict = datadict self.data1 = self.datadict['movie1'] self.data2 = self.datadict['movie2'] #left plot self.plotdata1 = arrayplotdata(image1 = self.data1['0']) plotleft = plot(self.plotdata1) plotleft.img_plot("image1") #right plot self.plotdata2 = arrayplotdata(image2 = self.data2['0']) plotright = plot(self.plotdata2) plotright.img_plot("image2") #add zoom/pan tools plotleft.tools.append(pantool(plotleft)) plotleft.tools.append(betterzoom(plotleft, zoom_factor=0.8, zoom_to_mouse = true)) plotleft.tools.append(dragzoom(plotleft, drag_button="right")) plotright.tools.append(pantool(plotright)) plotright.tools.append(betterzoom(plotright)) plotright.tools.append(dragzoom(plotright, drag_button="right")) #axes shared plotleft.range2d = plotright.range2d container = hplotcontainer(plotleft, plotright) self.plot = container def _frame_changed(self): #change frame when slider changes self.plotdata1.set_data("image1", self.data1[str(self.frame)]) self.plotdata2.set_data("image2", self.data2[str(self.frame)]) class form(qdialog): #basic form dialog using pyside def __init__(self, datadict, parent=none): super(form, self).__init__(parent) self.datadict = datadict self.totalframes = len(datadict['movie1']) formatbutton1 = qpushbutton("format 1") buttonlayout = qhboxlayout() buttonlayout.addstretch() buttonlayout.addwidget(formatbutton1) #add vbox space widgets layout = qvboxlayout() layout.addlayout(buttonlayout) self.setlayout(layout) self.connect(formatbutton1, signal("clicked()"), self.setchaco) self.setwindowtitle('master form') def setchaco(self): #create chaco window instance scatter = chacowindow(datadict, self.totalframes) scatter.configure_traits(self) if __name__ == "__main__": #make demo data ar0 = np.zeros((25,25)) ar0[10][10] = 1 ar1 = np.zeros((25,25)) ar1[12][12] = 1 #dictionary of images datadict = {'movie1': {'0': ar0, '1':ar1, '2':ar0}, 'movie2': {'0': ar1, '1':ar0, '2':ar1}} form = form(datadict) form.show() app.exec_()
i managed find solution. changing function solves problem:
def setchaco(self): #create chaco window instance scatter = chacowindow(datadict, self.totalframes) #change line: scatter.configure_traits(self) scatter.edit_traits()
this appears let pyside event loop handle everything.
Comments
Post a Comment