def __init__(self, parent=None): #print "init" self.parent = parent self.w = 0 # renderable width self.h = 0 # renderable height self.imtex=0 self.current = None self.previous = None self.fd = None self.initFlag = True self.qwidgets = [] self.imagewidgets = [] self.inspectorwidgets = [] self.cols = [] self.desktopwidget = None self.suppressUpdateGL = False self.fdxpos = 0 self.fdypos = 0 self.cam = Camera()
class EMDesktopWidgets: """ Something that organizes and display EMGLWidgets """ def __init__(self, parent=None): #print "init" self.parent = parent self.w = 0 # renderable width self.h = 0 # renderable height self.imtex=0 self.current = None self.previous = None self.fd = None self.initFlag = True self.qwidgets = [] self.imagewidgets = [] self.inspectorwidgets = [] self.cols = [] self.desktopwidget = None self.suppressUpdateGL = False self.fdxpos = 0 self.fdypos = 0 self.cam = Camera() def get_depth_for_height(self, height): try: return self.parent.get_depth_for_height(height) except: print "parent can't get height for depth" return 0 def setDims(self, width, height): self.w = width self.h = height def setCamPos(self, x,y,z=0): self.cam.cam_x = x self.cam.cam_y = y self.cam.cam_z = z def height(self): return self.parent.height() def width(self): return self.parent.width() def updateGL(self): if not self.suppressUpdateGL: try: self.parent.updateGL() except: pass def addQtWidgetDrawer(self,widget): pass def getColWidth(self): numcols = len(self.cols) if numcols == 0: return 0 cw = float(self.w)/float(numcols) return cw def getColHeight(self): return float(self.h) def layout(self): print "in layout" numcols = len(self.cols) if numcols == 0: return cw = self.getColWidth() colidx = 0 for i in self.cols: ch = 0 n = len(i) if n == 0: continue for j in i: ch += j.height() if j.width() > cw: print "error, can handle wide widgets",j.width(),cw dif = float(self.h - ch) if dif < 0: print "error, can't handle negative diffs atm", dif, colidx, n dif = 0 ##exit(1) dif /= float(n) dy = dif/2.0 dx = cw/2.0 + colidx*cw for j in i: dy += j.height()/2.0 j.cam.cam_y = dy j.cam.cam_x = dx #print j.cam.cam_y,j.cam.cam_x dy += j.height()/2.0 dy += dif colidx += 1 def render(self): self.cam.position() if ( self.initFlag == True ): self.desktopwidget = EMGLViewQtWidget(self.parent) self.s = EMDesktopInspector(self) self.s.show() self.s.hide() #self.desktopwidget.cam.cam_x = s.width()/2.0 #self.desktopwidget.cam.cam_y = self.h - s.height()/2.0 self.desktopwidget.setQtWidget(self.s) self.qwidgets.append(self.desktopwidget) self.numcols = 1 self.cols = [[self.desktopwidget]] self.layout() self.initFlag = False for i in self.cols: for j in i: glPushMatrix() j.paintGL() glPopMatrix() def changed(self,file): #try: a=EMData.read_images(str(file)) if len(a) == 1: a = a[0] if a.get_zsize() != 1: w = EMGLView3D(self,a) else: w = EMGLView2D(self,a) else: w = EMGLView2D(self,a) try: self.cols[1] = [] except: self.cols.append([]) self.cols[1].append(w) scalex = self.getColWidth()/float(w.width()) scaley = self.getColHeight()/float(w.height()) #print scalex,scaley,yheight,w.height() if scalex > scaley: scalex = scaley try: w.d = scalex*w.d # 3D except: pass w.h = scalex*w.h w.set_width(scalex*w.w) try: w.setOptScale() except: pass insp = w.get_inspector() d = EMGLViewQtWidget(self.parent) d.setQtWidget(insp) try: self.cols[0][2] = d except: self.cols[0].append(d) self.layout() #except: #print "could not open" #return #print "paintGL done" def finished(self,val): pass if ( val == 1 ): for i in self.fd.selectedFiles(): a=EMData.read_images(str(i)) if len(a) == 1: a = a[0] if a.get_zsize() != 1: w = EMGLView3D(self,a) self.qwidgets.append(w) else: w = EMGLView2D(self,a) self.qwidgets.append(w) else: w = EMGLView2D(self,a) self.qwidgets.append(w) def timer(self): pass #self.updateGL() def bindTexture(self,pixmap): return self.parent.bindTexture(pixmap) def deleteTexture(self,val): return self.parent.deleteTexture(val) def get_render_dims_at_depth(self, depth): try: return self.parent.get_render_dims_at_depth(depth) except: print "parent can't get render dims at for depth" return def resizeEvent(self, width, height): widgets = self.qwidgets + self.imagewidgets for i in widgets: i.set_update_P_inv() def getWidgets(self): widgets = [] for i in self.cols: for j in i: widgets.append(j) return widgets def mousePressEvent(self, event): widgets = self.getWidgets() for i in widgets: if ( i.isinwin(event.x(),self.height()-event.y()) ): i.mousePressEvent(event) intercepted = True self.updateGL() return def mouseMoveEvent(self, event): widgets = self.getWidgets() for i in widgets: if ( i.isinwin(event.x(),self.height()-event.y()) ): self.current = i if (self.current != self.previous ): if ( self.previous != None ): self.previous.leaveEvent() i.mouseMoveEvent(event) self.previous = i self.updateGL() return def mouseReleaseEvent(self, event): widgets = self.getWidgets() for i in widgets: if ( i.isinwin(event.x(),self.height()-event.y()) ): i.mouseReleaseEvent(event) self.updateGL() return def mouseDoubleClickEvent(self, event): widgets = self.getWidgets() for i in widgets: if ( i.isinwin(event.x(),self.height()-event.y()) ): i.mouseReleaseEvent(event) self.updateGL() return def wheelEvent(self, event): widgets = self.getWidgets() for i in widgets: if ( i.isinwin(event.x(),self.height()-event.y()) ): i.wheelEvent(event) self.updateGL() return def toolTipEvent(self, event): widgets = self.getWidgets() for i in widgets: if ( i.isinwin(event.x(),self.height()-event.y()) ): i.toolTipEvent(event) self.updateGL() return QtGui.QToolTip.hideText() def dragMoveEvent(self,event): print "received drag move event" def event(self,event): #print "event" #QtGui.QToolTip.hideText() if event.type() == QtCore.QEvent.MouseButtonPress: self.mousePressEvent(event) return True elif event.type() == QtCore.QEvent.MouseButtonRelease: self.mouseReleaseEvent(event) return True elif event.type() == QtCore.QEvent.MouseMove: self.mouseMoveEvent(event) return True elif event.type() == QtCore.QEvent.MouseButtonDblClick: self.mouseDoubleClickEvent(event) return True elif event.type() == QtCore.QEvent.Wheel: self.wheelEvent(event) return True elif event.type() == QtCore.QEvent.ToolTip: self.toolTipEvent(event) return True else: return QtOpenGL.QGLWidget.event(self,event) def hoverEvent(self,event): #print "hoverEvent" if self.inspector : widgets = self.qwidgets + self.imagewidgets for i in widgets: if ( i.isinwin(event.x(),self.height()-event.y()) ): i.hoverEvent(event) break self.updateGL() def addBox(self): pass def getfd(self): if self.fd == None: self.fd = QtGui.QFileDialog(self.parent,"Open File",QtCore.QDir.currentPath(),QtCore.QString("Image files (*.img *.hed *.mrc *.hdf)")) #self.fd = EMDesktopFileDialog(self.parent,"Open File",QtCore.QDir.currentPath(),QtCore.QString("Image files (*.img *.hed *.mrc)")) QtCore.QObject.connect(self.fd, QtCore.SIGNAL("finished(int)"), self.finished) QtCore.QObject.connect(self.fd, QtCore.SIGNAL("currentChanged(QString)"), self.changed) self.fd.show() self.fd.hide() return self.fd def addBrowse(self): #self.numcols = 2 fd = self.getfd() self.fdwidget = EMGLViewQtWidget(self.parent) #self.fdwidget.cam.cam_x = -(self.parent.get_app_width() - fd.width())/2.0 #self.fdwidget.cam.cam_y = (self.parent.get_app_height() - fd.height())/2.0 self.fdwidget.setQtWidget(fd) self.cols = [[self.desktopwidget, self.fdwidget ]] self.layout() def addCompare(self): pass def addFSC(self): pass def close(self): self.cols = [[self.desktopwidget]] self.layout() def get_near_plane_dims(self): return self.parent.get_near_plane_dims() def get_start_z(self): return self.parent.get_start_z()