Example #1
0
class EMGLWidget(QtOpenGL.QGLWidget):
	"""
	This class encapsulates the use of the EMParentWin to provide a status bar with a size grip on Mac.
	It also handles much of the inspector behavior, displays help in a web browser, and provides 
	a self.busy attribute to prevent updateGL() from redrawing before all changes to display parameters are in place. 
	"""
	
	def hide(self):
		if self.qt_parent:
			self.qt_parent.hide()
			
	def resize(self, w, h):
		if self.qt_parent:
			QtOpenGL.QGLWidget.resize(self, w, h)
			if get_platform()=="Darwin" : self.qt_parent.resize(w, h+22)
			else : self.qt_parent.resize(w+4, h+4)
			
	def show(self):
		if self.qt_parent:
			self.qt_parent.show()
			
	def setWindowTitle(self, title):
		if self.qt_parent:
			self.qt_parent.setWindowTitle(title)
		else:
			self.setWindowTitle(title)
			
	def __init__(self, parent=None,enable_timer=False, application_control=True,winid=None):
		if parent==None : 
			self.qt_parent = EMParentWin(enable_timer)
			self.myparent=True			# we allocated the parent, responsible for cleaning it up
		else: 
			self.qt_parent=parent
			self.myparent=False			# we did not allocate our parent, so we should not get rid of it
		
		QtOpenGL.QGLWidget.__init__(self,self.qt_parent)
		if self.myparent : self.qt_parent.setup(self)
		
		self.inspector = None # a Qt Widget for changing display parameters, setting the data, accessing metadata, etc.
		self.winid=winid # a 'unique' identifier for the window used to restore locations on the screen
		
		self.image_change_count =  0# this is important when the user has more than one display instance of the same image, for instance in e2.py if 
		app = get_application()
		if app != None and application_control:
			app.attach_child(self)
		
		self.application_control = application_control
		self.file_name = ""
		self.disable_inspector = False
		
		self.makeCurrent()
		self.font_renderer = get_3d_font_renderer()
		if self.font_renderer == None : 
			print "FTGL not initialized. Please make sure you have FTGL installed, and configured for compilation in CMake. If using a binary, please report a problem to [email protected]."
			sys.exit(1)
		self.font_renderer.set_face_size(16)
		self.font_renderer.set_font_mode(FTGLFontMode.TEXTURE)
			
		self.busy = False #updateGL() does nothing when self.busy == True
		
	def closeEvent(self, event):
		if self.inspector:
			self.inspector.close()
		QtOpenGL.QGLWidget.closeEvent(self, event)
		if self.myparent : self.qt_parent.close()
		self.emit(QtCore.SIGNAL("module_closed")) # this could be a useful signal, especially for something like the selector module, which can potentially show a lot of images but might want to close them all when it is closed
		event.accept()
		
	def display_web_help(self,url="http://blake.bcm.edu/emanwiki/e2display"):
		try:
			try:
				import webbrowser
				webbrowser.open(url)
			except:
				try:
					test = self.browser
				except: 
					self.browser = QtWebKit.QWebView()
					self.browser.load(QtCore.QUrl())
					self.browser.resize(800,800)
				
				if not self.browser.isVisible(): self.browser.show(url)
		except:
			pass

	def enable_inspector(self,val=True): 
		self.disable_inspector = not val
		
			
	def show_inspector(self,force=0):
		if self.disable_inspector: 
			return
		
		self.emit(QtCore.SIGNAL("inspector_shown")) # debug only
		app = get_application()
		if app == None:
			print "can't show an inspector with having an associated application"
		
		if not force and self.inspector==None : 
			return
		if not self.inspector : 
			self.inspector = self.get_inspector()
			if self.inspector == None: 
				return # sometimes this happens
		if not app.child_is_attached(self.inspector):
			app.attach_child(self.inspector)
		app.show_specific(self.inspector)
		
	def update_inspector_texture(self):
		if self.inspector != None:
			self.inspector.update()
			
	def updateGL(self):
		if self.busy:
			return
		else:
			QtOpenGL.QGLWidget.updateGL(self)
Example #2
0
class EMGLWidget(QtOpenGL.QGLWidget):
	"""
	This class encapsulates the use of the EMParentWin to provide a status bar with a size grip on Mac.
	It also handles much of the inspector behavior, displays help in a web browser, and provides 
	a self.busy attribute to prevent updateGL() from redrawing before all changes to display parameters are in place. 
	"""
	
	def hide(self):
		if self.qt_parent:
			self.qt_parent.hide()
			
	def resize(self, w, h):
		if self.qt_parent:
			QtOpenGL.QGLWidget.resize(self, w, h)
			if get_platform()=="Darwin" : self.qt_parent.resize(w, h+22)
			else : self.qt_parent.resize(w+4, h+4)
			
	def show(self):
		if self.qt_parent:
			self.qt_parent.show()
			
	def setWindowTitle(self, title):
		if self.qt_parent:
			self.qt_parent.setWindowTitle(title)
		else:
			self.setWindowTitle(title)
			
	def __init__(self, parent=None,enable_timer=False, application_control=True,winid=None):
		if parent==None : 
			self.qt_parent = EMParentWin(enable_timer)
			self.myparent=True			# we allocated the parent, responsible for cleaning it up
		else: 
			self.qt_parent=parent
			self.myparent=False			# we did not allocate our parent, so we should not get rid of it
		
		QtOpenGL.QGLWidget.__init__(self,self.qt_parent)
		if self.myparent : self.qt_parent.setup(self)
		
		self.inspector = None # a Qt Widget for changing display parameters, setting the data, accessing metadata, etc.
		self.winid=winid # a 'unique' identifier for the window used to restore locations on the screen
		
		self.image_change_count =  0# this is important when the user has more than one display instance of the same image, for instance in e2.py if 
		app = get_application()
		if app != None and application_control:
			app.attach_child(self)
		
		self.application_control = application_control
		self.file_name = ""
		self.disable_inspector = False
		
		self.makeCurrent()
		self.font_renderer = get_3d_font_renderer()
		if self.font_renderer == None : 
			print("FTGL not initialized. Please make sure you have FTGL installed, and configured for compilation in CMake. If using a binary, please report a problem to [email protected].")
			sys.exit(1)
		self.font_renderer.set_face_size(16)
		self.font_renderer.set_font_mode(FTGLFontMode.TEXTURE)
			
		self.busy = False #updateGL() does nothing when self.busy == True
		
	def closeEvent(self, event):
		if self.inspector:
			self.inspector.close()
		QtOpenGL.QGLWidget.closeEvent(self, event)
		if self.myparent : self.qt_parent.close()
		self.emit(QtCore.SIGNAL("module_closed")) # this could be a useful signal, especially for something like the selector module, which can potentially show a lot of images but might want to close them all when it is closed
		event.accept()
		
	def display_web_help(self,url="http://blake.bcm.edu/emanwiki/e2display"):
		try:
			try:
				import webbrowser
				webbrowser.open(url)
			except:
				try:
					test = self.browser
				except: 
					self.browser = QtWebKit.QWebView()
					self.browser.load(QtCore.QUrl())
					self.browser.resize(800,800)
				
				if not self.browser.isVisible(): self.browser.show(url)
		except:
			pass

	def enable_inspector(self,val=True): 
		self.disable_inspector = not val
		
			
	def show_inspector(self,force=0):
		if self.disable_inspector: 
			return
		
		self.emit(QtCore.SIGNAL("inspector_shown")) # debug only
		app = get_application()
		if app == None:
			print("can't show an inspector with having an associated application")
		
		if not force and self.inspector==None : 
			return
		if not self.inspector : 
			self.inspector = self.get_inspector()
			if self.inspector == None: 
				return # sometimes this happens
		if not app.child_is_attached(self.inspector):
			app.attach_child(self.inspector)
		app.show_specific(self.inspector)
		
	def update_inspector_texture(self):
		if self.inspector != None:
			self.inspector.update()
			
	def updateGL(self):
		if self.busy:
			return
		else:
			QtOpenGL.QGLWidget.updateGL(self)