Esempio n. 1
0
	def validate_file_name(self,file_name):
		'''
		Validate the file name and do any internal preparation for the impending call to
		save.
		Checks to make sure the file name is valid
		Confirms overwrite and asks to append
		@return 0 if something went wrong (e.g. the user cancelled), 1 if it's okay to call save now
		'''
		
		msg = QtGui.QMessageBox()
		error = self.__validate_file_name(file_name)
		if error != None:
			# error is therefore a string
			msg.setText(error)
			msg.exec_()
			return 0
		
		# If we make it here the file name is fine, but it may exist
		self.overwrite = False
		self.append = False
		if file_exists(file_name):
			file_exists_dialog = EMFileExistsDialog(file_name,self.__item_list)
			code = file_exists_dialog.exec_()
			if code == 0:
				return 0
			elif code == 1:
				self.overwrite = True
			elif code == 2:
				self.append = True
			else: raise NotImplementedError("A developer has modified the code and this has caused an error. Please notify us")
			
		return 1
Esempio n. 2
0
	def validate_file_name(self,file_name):
		'''
		Validate the file name and do any internal preparation for the impending call to
		save.
		Checks to make sure the file name is valid
		Confirms overwrite and asks to append
		@return 0 if something went wrong (e.g. the user cancelled), 1 if it's okay to call save now
		'''
		
		msg = QtGui.QMessageBox()
		error = self.__validate_file_name(file_name)
		if error != None:
			# error is therefore a string
			msg.setText(error)
			msg.exec_()
			return 0
		
		# If we make it here the file name is fine, but it may exist
		self.overwrite = False
		self.append = False
		if file_exists(file_name):
			file_exists_dialog = EMFileExistsDialog(file_name,self.__item_list)
			code = file_exists_dialog.exec_()
			if code == 0:
				return 0
			elif code == 1:
				self.overwrite = True
			elif code == 2:
				self.append = True
			else: raise NotImplementedError("A developer has modified the code and this has caused an error. Please notify us")
			
		return 1
Esempio n. 3
0
	def __init__(self,file_name,idx=0):
		'''
		@exception RuntimeError raised if the file_name does not exist
		'''
		if not file_exists(file_name): raise RuntimeError("%s does not exist" %file_name)
		self.file_name = file_name
		self.idx = idx
Esempio n. 4
0
	def __init__(self,file_name,idx=0):
		'''
		@exception RuntimeError raised if the file_name does not exist
		'''
		if not file_exists(file_name): raise RuntimeError("%s does not exist" %file_name)
		self.file_name = file_name
		self.idx = idx
Esempio n. 5
0
	def __new__(cls, file_name):
		if not file_exists(file_name): raise
		splt = file_name.split(".")
		if len(file_name) > 4 and file_name[:4] == "bdb:": pass
		elif EMUtil.get_image_ext_type(splt[-1]) == EMUtil.ImageType.IMAGE_UNKNOWN:
			raise
		
		if splt[-1] in ["img","hed"]: return EMImagicTmpFileHandle(file_name)
		elif file_name[:4] == "bdb:": return EMDBTmpFileHandle(file_name)
		else: return EMGeneralTmpFileHandle(file_name)
Esempio n. 6
0
	def __new__(cls, file_name):
		if not file_exists(file_name): raise
		splt = file_name.split(".")
		if len(file_name) > 4 and file_name[:4] == "bdb:": pass
		elif EMUtil.get_image_ext_type(splt[-1]) == EMUtil.ImageType.IMAGE_UNKNOWN:
			raise
		
		if splt[-1] in ["img","hed"]: return EMImagicTmpFileHandle(file_name)
		elif file_name[:4] == "bdb:": return EMDBTmpFileHandle(file_name)
		else: return EMGeneralTmpFileHandle(file_name)
Esempio n. 7
0
def display(img,app,title="EMAN2 image"):
	if len(img)==1 : img=img[0]
	w=EMImageWidget(data=img,old=None,app=app)
	w.setWindowTitle(title)
	try:
		if file_exists(title):
			w.set_file_name(title)
	except: pass
	app.show_specific(w)
	try: w.optimally_resize()
	except: pass
	return w
Esempio n. 8
0
def display(img,app,title="EMAN2 image"):
	if len(img)==1 : img=img[0]
	w=EMImageWidget(data=img,old=None,app=app)
	w.setWindowTitle(title)
	try:
		if file_exists(title):
			w.set_file_name(title)
	except: pass
	app.show_specific(w)
	try: w.optimally_resize()
	except: pass
	return w
Esempio n. 9
0
def check_options(options,args):
	'''
	A way to check the options, arg as returned by parser.parse_args()  in e2tomoaverage
	'''
	error = []
	
	error.extend(check_tomo_options(options)) # there is a big bunch of generic options
	
	if len(args) < 2:
		error.append("Error - to average you must supply atleast two images")
	else:
		for arg in args:
			if not file_exists(arg):
				error.append("%s does not exist" %arg)
	
	if options.path != None:
		if not os.path.exists(options.path):
			error.append( "Error: the path %s does not exist" %options.path)
	else:
		options.path = EMAN2.numbered_path(tomo_ave_path_root,True)
			
	return error
Esempio n. 10
0
	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
Esempio n. 11
0
	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
Esempio n. 12
0
def main():
	progname = os.path.basename(sys.argv[0])
	usage = """prog [options] <image file> ...

	This program can be used to visualize most files used in EMAN2. Running it without arguments
	will open a browser window with more flexible functionality than the command-line.
	
	"""
	global app,win,options

	parser = EMArgumentParser(usage=usage,version=EMANVERSION)

	parser.add_argument("--classmx",type=str,help="<classmx>,<#> Show particles in one class from a classification matrix. Pass raw particle file as first argument to command.")
	parser.add_argument("--classes",type=str,help="<rawptcl>,<classmx> Show particles associated class-averages")
	parser.add_argument("--pdb",type=str,help="<pdb file> Show PDB structure.")
	parser.add_argument("--singleimage",action="store_true",default=False,help="Display a stack in a single image view")
	parser.add_argument("--plot",action="store_true",default=False,help="Data file(s) should be plotted rather than displayed in 2-D")
	parser.add_argument("--plot3",action="store_true",default=False,help="Data file(s) should be plotted rather than displayed in 3-D")
	parser.add_argument("--fullrange",action="store_true",default=False,help="A specialized flag that disables auto contrast for the display of particles stacks and 2D images only.")
	parser.add_argument("--newwidget",action="store_true",default=False,help="Use the new 3D widgetD. Highly recommended!!!!")
	parser.add_argument("--ppid", type=int, help="Set the PID of the parent process, used for cross platform PPID",default=-2)
	parser.add_argument("--verbose", "-v", dest="verbose", action="store", metavar="n", type=int, default=0, help="verbose level [0-9], higner number means higher level of verboseness")

	(options, args) = parser.parse_args()

#	logid=E2init(sys.argv)

	app = EMApp()
	#gapp = app
	#QtGui.QApplication(sys.argv)
	win=[]
	if options.fullrange:
		fullrangeparms = set_full_range()
	
	if len(args) < 1:
		global dialog
		file_list = []
		dialog = embrowser.EMBrowserWidget(withmodal=False,multiselect=False)
		dialog.show()
		try: dialog.raise_()
# 			QtCore.QObject.connect(dialog,QtCore.SIGNAL("ok"),on_browser_done)
# 			QtCore.QObject.connect(dialog,QtCore.SIGNAL("cancel"),on_browser_cancel)
		except: pass
	
	elif options.pdb:
		load_pdb(args,app)
	
	elif options.plot:
		plot(args,app)
		
	elif options.plot3:
		plot_3d(args,app)
		
	elif options.classes:
		options.classes=options.classes.split(",")
		imgs=EMData.read_images(args[0])
		display(imgs,app,args[0])

		QtCore.QObject.connect(win[0].child,QtCore.SIGNAL("mousedown"),lambda a,b:selectclass(options.classes[0],options.classes[1],a,b))
		try:
			out=file("selected.lst","w")
			out.write("#LST\n")
			out.close()
		except: pass
		
	elif options.classmx:
		options.classmx=options.classmx.split(",")
		clsnum=int(options.classmx[1])
		imgs=getmxim(args[0],options.classmx[0],clsnum)
		display(imgs,app,args[0])
	
	else:
		for i in args:
			if not file_exists(i):
				print "%s doesn't exist" %i
				sys.exit(1)
			display_file(i,app,options.singleimage,usescenegraph=options.newwidget)
	
	if options.fullrange:
		revert_full_range(fullrangeparms)

	app.exec_()
Esempio n. 13
0
def main():
    progname = os.path.basename(sys.argv[0])
    usage = """prog [options] <image file> ...

	This program can be used to visualize most files used in EMAN2. Running it without arguments
	will open a browser window with more flexible functionality than the command-line.
	"""
    global app, win, options

    parser = EMArgumentParser(usage=usage, version=EMANVERSION)

    parser.add_argument(
        "--classmx",
        type=str,
        help=
        "<classmx>,<#> Show particles in one class from a classification matrix. Pass raw particle file as first argument to command."
    )
    parser.add_argument(
        "--classes",
        type=str,
        help="<rawptcl>,<classmx> Show particles associated class-averages")
    parser.add_argument("--pdb",
                        type=str,
                        help="<pdb file> Show PDB structure.")
    parser.add_argument("--singleimage",
                        action="store_true",
                        default=False,
                        help="Display a stack in a single image view")
    parser.add_argument(
        "--plot",
        action="store_true",
        default=False,
        help="Data file(s) should be plotted rather than displayed in 2-D")
    parser.add_argument(
        "--hist",
        action="store_true",
        default=False,
        help=
        "Data file(s) should be plotted as a histogram rather than displayed in 2-D."
    )
    parser.add_argument(
        "--plot3d",
        action="store_true",
        default=False,
        help="Data file(s) should be plotted rather than displayed in 3-D")
    parser.add_argument(
        "--fullrange",
        action="store_true",
        default=False,
        help=
        "A specialized flag that disables auto contrast for the display of particles stacks and 2D images only."
    )
    parser.add_argument("--newwidget",
                        action="store_true",
                        default=False,
                        help="Use the new 3D widgetD. Highly recommended!!!!")
    parser.add_argument(
        "--ppid",
        type=int,
        help="Set the PID of the parent process, used for cross platform PPID",
        default=-2)
    parser.add_argument(
        "--verbose",
        "-v",
        dest="verbose",
        action="store",
        metavar="n",
        type=int,
        default=0,
        help=
        "verbose level [0-9], higher number means higher level of verboseness")

    (options, args) = parser.parse_args()

    #	logid=E2init(sys.argv)

    app = EMApp()
    #gapp = app
    #QtWidgets.QApplication(sys.argv)
    win = []
    if options.fullrange:
        print(
            """The --fullrange option has been removed, and replaced with an option in user preferences.
To set your preferences for full-range 2-D display, please run:
e2procjson.py --setoption display2d.autocontrast:true
""")
        sys.exit(0)

    if len(args) < 1:
        global dialog
        file_list = []
        dialog = embrowser.EMBrowserWidget(withmodal=False, multiselect=False)
        dialog.show()
        try:
            dialog.raise_()
            # 			QtCore.QObject.connect(dialog,QtCore.SIGNAL("ok"),on_browser_done)
            # 			QtCore.QObject.connect(dialog,QtCore.SIGNAL("cancel"),on_browser_cancel)
        except:
            pass

    elif options.pdb:
        load_pdb(args, app)

    elif options.plot:
        plot(args, app)

    elif options.hist:
        hist(args, app)

    elif options.plot3d:
        plot_3d(args, app)

    elif options.classes:
        options.classes = options.classes.split(",")
        imgs = EMData.read_images(args[0])
        display(imgs, app, args[0])

        win[0].child.mousedown.connect(lambda a, b: selectclass(
            options.classes[0], options.classes[1], a, b))
        try:
            out = open("selected.lst", "w")
            out.write("#LST\n")
            out.close()
        except:
            pass

    elif options.classmx:
        options.classmx = options.classmx.split(",")
        clsnum = int(options.classmx[1])
        imgs = getmxim(args[0], options.classmx[0], clsnum)
        display(imgs, app, args[0])

    else:
        for i in args:
            if not file_exists(i):
                print("%s doesn't exist" % i)
                sys.exit(1)
            display_file(i,
                         app,
                         options.singleimage,
                         usescenegraph=options.newwidget)

    app.exec_()