コード例 #1
0
ファイル: emimage.py プロジェクト: cpsemmens/eman2
	def __new__(cls,filename,application,force_plot=False,force_2d=False,old=None):
		
		file_type = Util.get_filename_ext(filename)
		em_file_type = EMUtil.get_image_ext_type(file_type)
		if not file_exists(filename): return None
		
		if force_plot and force_2d:
			# ok this sucks but it suffices for the time being
			print "Error, the force_plot and force_2d options are mutually exclusive"
			return None
		
		if force_plot:
			from emplot2d import EMPlot2DWidget
			if isinstance(old,EMPlot2DWidget): widget = old
			else: widget = EMPlot2DWidget(application=application)
			widget.set_data_from_file(filename)
			return widget
		
		if em_file_type != IMAGE_UNKNOWN or filename[:4] == "bdb:":
			n = EMUtil.get_image_count(filename)
			nx,ny,nz = gimme_image_dimensions3D(filename)
			if n > 1 and nz == 1: 
				if force_2d:
					a = EMData()
					data=a.read_images(filename)
				else:
					data = None # This is like a flag - the ImageMXWidget only needs the file name
			elif nz == 1:
				data = [EMData(filename,0)]
			else:
				data = EMData()
				data.read_image(filename,0,not force_2d)		# This should be 3-D. We read the header-only here
				data = [data]
				
			if data != None and len(data) == 1: data = data[0]
			
			if force_2d or isinstance(data,EMData) and data.get_zsize()==1:
				if isinstance(data,list) or data.get_ysize() != 1:
					from emimage2d import EMImage2DWidget
					if isinstance(old,EMImage2DWidget): widget = old
					else: widget= EMImage2DWidget(application=application)
				else:
					from emplot2d import EMPlot2DWidget
					if isinstance(old,EMPlot2DWidget): widget = old
					else: widget = EMPlot2DWidget(application=application)
					widget.set_data_from_file(filename)
					return widget
			elif isinstance(data,EMData):
				if isinstance(old,EMScene3D): widget = old
				else: widget = EMScene3D()
#				print n,data
				for ii in xrange(n):
					data=EMData(filename,ii)
					datai = EMDataItem3D(data, transform=Transform())
					widget.insertNewNode(os.path.basename(filename), datai, parentnode=widget)
					isosurface = EMIsosurface(datai, transform=Transform())
					widget.insertNewNode("Iso", isosurface, parentnode=datai)
				return widget
				
			elif data == None or isinstance(data,list):
				from emimagemx import EMImageMXWidget
				if isinstance(old,EMImageMXWidget): widget = old
				else: widget = EMImageMXWidget(application=application)
				data = filename
			else: 
				print filename
				raise # weirdness, this should never happen
			widget.set_data(data,filename)
			return widget
		else:
			from emplot2d import EMPlot2DWidget
			if isinstance(old,EMPlot2DWidget): widget = old
			else: widget = EMPlot2DWidget(application=application)
			widget.set_data_from_file(filename)
			return widget
コード例 #2
0
ファイル: emsave.py プロジェクト: CVL-dev/StructuralBiology
	def __init__(self,filename,item_list):
		'''
		@param filename the name of the file that is being overwritten
		@param item_list a list - the first object must have supply the get_attr_dict function, the keys "nx", "ny" and "nz therein
		If you want to use this function for a single EMData object then just put it in a list
		'''
		QtGui.QDialog.__init__(self,None)
		self.resize(480,320)
		self.setWindowIcon(QtGui.QIcon(get_image_directory() + "/eman.png"))
		self.setWindowTitle("File already exists")
		self.appendable_types = ["hed","img","spi","hdf"] #image types that can be stacks - TODO bdb ?
		
		append_enable = False 
		
		splt = filename.split(".")
		if splt[-1] in self.appendable_types or (len(filename) > 3 and filename[:4] == "bdb:"):
			(nx,ny,nz) = gimme_image_dimensions3D(filename)
			d = item_list[0].get_attr_dict()
			nz1 = d["nz"]
			ny1 = d["ny"]
			nx1 = d["nx"]
			# can only append if the dimensions are the same
			if nx == nx1 and ny == ny1 and nz == nz1:
				append_enable=True
		
		# some widgets
		vbl = QtGui.QVBoxLayout(self)
		hbl = QtGui.QHBoxLayout()
		overwrite = QtGui.QPushButton("Overwrite")
		cancel = QtGui.QPushButton("Cancel")
		
		# add Widgets to Layouts
		hbl.addWidget(cancel)
		if append_enable:
			append = QtGui.QPushButton("Append")
			hbl.addWidget(append)
		hbl.addWidget(overwrite)
		if (len(filename) > 3 and filename[:4] == "bdb:"):
			overwrite.setEnabled(False)
			overwrite.setToolTip("Overwriting bdb files is currently disabled.")
		
		# Text to alert the user
		hbl2 = QtGui.QHBoxLayout()
		text_edit = QtGui.QTextEdit("",self)
		text_edit.setReadOnly(True)
		text_edit.setWordWrapMode(QtGui.QTextOption.WordWrap)
		if (filename == ""):
			if append_enable:
				help = "The file already exists. You can choose to append to it, to overwrite it, or to cancel this operation."
			else:
				help = "The file already exists. You can choose to overwrite it, or to cancel this operation."			
		else:
			if append_enable:
				help = "The file %s already exists. You can choose to append to it, to overwrite it, or to cancel this operation." %filename
			else:
				help = "The file %s already exists. You can choose to to overwrite it, or to cancel this operation." %filename
		
		help += "\n\nBe careful about overwriting data as it may cause errors when using EMAN2 virtual stacks."
		
		text_edit.setText(help)
		hbl2.addWidget(text_edit,0)
		
		groupbox = QtGui.QGroupBox("Warning")
		groupbox.setLayout(hbl2)
		vbl.addWidget(groupbox)
		
		vbl.addLayout(hbl)
		
		if append_enable:
			QtCore.QObject.connect(append, QtCore.SIGNAL("clicked(bool)"), self.append_clicked)
		QtCore.QObject.connect(overwrite, QtCore.SIGNAL("clicked(bool)"), self.overwrite_clicked)
		QtCore.QObject.connect(cancel, QtCore.SIGNAL("clicked(bool)"), self.cancel_clicked)
		
		self.__result = 0
コード例 #3
0
ファイル: emimage.py プロジェクト: phonchi/eman2
	def __new__(cls,filename,application,force_plot=False,force_2d=False,old=None):
		
		file_type = Util.get_filename_ext(filename)
		em_file_type = EMUtil.get_image_ext_type(file_type)
		if not file_exists(filename): return None
		
		if force_plot and force_2d:
			# ok this sucks but it suffices for the time being
			print("Error, the force_plot and force_2d options are mutually exclusive")
			return None
		
		if force_plot:
			from .emplot2d import EMPlot2DWidget
			if isinstance(old,EMPlot2DWidget): widget = old
			else: widget = EMPlot2DWidget(application=application)
			widget.set_data_from_file(filename)
			return widget
		
		if em_file_type != IMAGE_UNKNOWN or filename[:4] == "bdb:":
			n = EMUtil.get_image_count(filename)
			nx,ny,nz = gimme_image_dimensions3D(filename)
			if n > 1 and nz == 1: 
				if force_2d:
					a = EMData()
					data=a.read_images(filename)
				else:
					data = None # This is like a flag - the ImageMXWidget only needs the file name
			elif nz == 1:
				data = [EMData(filename,0)]
			else:
				data = EMData()
				data.read_image(filename,0,not force_2d)		# This should be 3-D. We read the header-only here
				data = [data]
				
			if data != None and len(data) == 1: data = data[0]
			
			if force_2d or isinstance(data,EMData) and data.get_zsize()==1:
				if isinstance(data,list) or data.get_ysize() != 1:
					from .emimage2d import EMImage2DWidget
					if isinstance(old,EMImage2DWidget): widget = old
					else: widget= EMImage2DWidget(application=application)
				else:
					from .emplot2d import EMPlot2DWidget
					if isinstance(old,EMPlot2DWidget): widget = old
					else: widget = EMPlot2DWidget(application=application)
					widget.set_data_from_file(filename)
					return widget
			elif isinstance(data,EMData):
				if isinstance(old,EMScene3D): widget = old
				else: widget = EMScene3D()
#				print n,data
				for ii in range(n):
					data=EMData(filename,ii)
					datai = EMDataItem3D(data, transform=Transform())
					widget.insertNewNode(os.path.basename(filename), datai, parentnode=widget)
					isosurface = EMIsosurface(datai, transform=Transform())
					widget.insertNewNode("Iso", isosurface, parentnode=datai)
				return widget
				
			elif data == None or isinstance(data,list):
				from .emimagemx import EMImageMXWidget
				if isinstance(old,EMImageMXWidget): widget = old
				else: widget = EMImageMXWidget(application=application)
				data = filename
			else: 
				print(filename)
				raise # weirdness, this should never happen
			widget.set_data(data,filename)
			return widget
		else:
			from .emplot2d import EMPlot2DWidget
			if isinstance(old,EMPlot2DWidget): widget = old
			else: widget = EMPlot2DWidget(application=application)
			widget.set_data_from_file(filename)
			return widget
コード例 #4
0
ファイル: emsave.py プロジェクト: phonchi/eman2
    def __init__(self, filename, item_list):
        '''
		@param filename the name of the file that is being overwritten
		@param item_list a list - the first object must have supply the get_attr_dict function, the keys "nx", "ny" and "nz therein
		If you want to use this function for a single EMData object then just put it in a list
		'''
        QtGui.QDialog.__init__(self, None)
        self.resize(480, 320)
        self.setWindowIcon(QtGui.QIcon(get_image_directory() + "/eman.png"))
        self.setWindowTitle("File already exists")
        self.appendable_types = [
            "hed", "img", "spi", "hdf"
        ]  #image types that can be stacks - TODO bdb ?

        append_enable = False

        splt = filename.split(".")
        if splt[-1] in self.appendable_types or (len(filename) > 3
                                                 and filename[:4] == "bdb:"):
            (nx, ny, nz) = gimme_image_dimensions3D(filename)
            d = item_list[0].get_attr_dict()
            nz1 = d["nz"]
            ny1 = d["ny"]
            nx1 = d["nx"]
            # can only append if the dimensions are the same
            if nx == nx1 and ny == ny1 and nz == nz1:
                append_enable = True

        # some widgets
        vbl = QtGui.QVBoxLayout(self)
        hbl = QtGui.QHBoxLayout()
        overwrite = QtGui.QPushButton("Overwrite")
        cancel = QtGui.QPushButton("Cancel")

        # add Widgets to Layouts
        hbl.addWidget(cancel)
        if append_enable:
            append = QtGui.QPushButton("Append")
            hbl.addWidget(append)
        hbl.addWidget(overwrite)
        if (len(filename) > 3 and filename[:4] == "bdb:"):
            overwrite.setEnabled(False)
            overwrite.setToolTip(
                "Overwriting bdb files is currently disabled.")

        # Text to alert the user
        hbl2 = QtGui.QHBoxLayout()
        text_edit = QtGui.QTextEdit("", self)
        text_edit.setReadOnly(True)
        text_edit.setWordWrapMode(QtGui.QTextOption.WordWrap)
        if (filename == ""):
            if append_enable:
                help = "The file already exists. You can choose to append to it, to overwrite it, or to cancel this operation."
            else:
                help = "The file already exists. You can choose to overwrite it, or to cancel this operation."
        else:
            if append_enable:
                help = "The file %s already exists. You can choose to append to it, to overwrite it, or to cancel this operation." % filename
            else:
                help = "The file %s already exists. You can choose to to overwrite it, or to cancel this operation." % filename

        help += "\n\nBe careful about overwriting data as it may cause errors when using EMAN2 virtual stacks."

        text_edit.setText(help)
        hbl2.addWidget(text_edit, 0)

        groupbox = QtGui.QGroupBox("Warning")
        groupbox.setLayout(hbl2)
        vbl.addWidget(groupbox)

        vbl.addLayout(hbl)

        if append_enable:
            append.clicked[bool].connect(self.append_clicked)
        overwrite.clicked[bool].connect(self.overwrite_clicked)
        cancel.clicked[bool].connect(self.cancel_clicked)

        self.__result = 0