示例#1
0
文件: graphGL.py 项目: gic888/MIEN
	def editPlot(self, event):
		pn=self.selectPlot()
		if not pn:
			return
		plot=self.plots[pn]
		keys=plot.keys()
		for tag in self.dontedit:
			try:
				keys.remove(tag)
			except:
				pass
		l=askParameters(self, [{"Name":"Which Attribute?",
				                "Type":"Prompt",
				                "Value":keys}])
		if not l:
			return None
		an=l[0]	
		if plot.get(an):
			d=[{"Name":an,"Value":repr(plot[an])}]
		else:
			d=[{"Name":an,"Type":str}]		
		l=askParameters(self, d)
		if not l:
			return
		nv=eval(l[0])
		plot[an]=nv
		self.styles[plot['style']](pn)
		self.OnDraw()
示例#2
0
文件: graphGL.py 项目: gic888/MIEN
	def addScale(self, event):
		l=askParameters(self, [{"Name":"Bar Length",
				                "Value":self.extent/2.0}])
		if not l:
			return None
		ulc, hor, ver=self.frontPlane()
		start=ulc+.05*hor+.05*ver+self.forward
		hor=hor/sqrt(sum(hor**2))
		stop=start+hor*l[0]
		self.SetCurrent()
		color=[1-x for x in self.clearcolor]
		materialColor(color)
		glLineWidth(8)
		glBegin(GL_LINES)
		glVertex3fv(start)
		glVertex3fv(stop)
		glEnd()	

		glMatrixMode(GL_MODELVIEW)
		glPushMatrix()
		il=(start+stop)/2-self.up
		glRasterPos3f(il[0], il[1], il[2])
		im=makeTextImage("%.4g" % l[0], 14, color, self.clearcolor, False)
		im=im.Mirror(False)
		w=im.GetWidth()
		h=im.GetHeight()
		id=im.GetData()
		pix=fromstring(id, 'B')
		pix=reshape(pix, (w, h, 3))
		glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
		glDrawPixelsub(GL_RGB, pix)
		glPopMatrix()

		glFlush()
		self.SwapBuffers()
示例#3
0
文件: graphGL.py 项目: gic888/MIEN
	def savePresets(self, event=None):
		l=askParameters(self, [{"Name":"File Name",
				                "Value":"viewpresets.txt"}])
		if not l:
			return
		fname=l[0]
		open(fname, 'w').write(repr(self.views))
示例#4
0
文件: graphGL.py 项目: gic888/MIEN
	def loadPresets(self, event=None):
		l=askParameters(self, [{"Name":"File Name",
				                "Value":"viewpresets.txt"}])
		if not l:
			return
		fname=l[0]
		s=open(fname).read()
		self.views=eval(s)
示例#5
0
文件: graphGL.py 项目: gic888/MIEN
	def editGlobals(self, event):
		options=self.global_options
		l=askParameters(self, [{"Name":"Which Attribute?",
				                "Type":"List",
				                "Value":options}])
		if not l:
			return None
		an=l[0]	
		val=getattr(self, an)	
		l=askParameters(self, [{"Name":an,
				                "Value":repr(val)}])
		if not l:
			return
		try:
			nv=eval(l[0])
		except TypeError:
			nv = l[0]
		setattr(self, an, nv)
		for pn in self.plots.keys():
			self.styles[self.plots[pn]['style']](pn)
		self.OnDraw()
示例#6
0
文件: graphGL.py 项目: gic888/MIEN
	def selectPlot(self):
		if not self.plots:
			return None
		elif len(self.plots.keys())==1:
			return self.plots.keys()[0]
		else:
			l=askParameters(self, [{"Name":"Which Plot?",
						            "Type":"List",
						            "Value":self.plots.keys()}])
			if not l:
				return None
			return l[0]	
示例#7
0
文件: widgets.py 项目: gic888/MIEN
def selectDvData(source, **kwargs):
	header=source.header
	args={'chans':None, 'start':0, 'stop':None, 'SR':None}
	gui=kwargs.get('gui', True)
	if gui is True:
		gui=None
#	d = askParameters(gui, d)
	cns = header["Labels"]
	toomany=False
	if len(cns)>35:
		toomany=len(cns)
		modes=self.modes.keys()
		cns=["Load all (%i) channels" % toomany, "Select channels using ranges"]
	fs = header.get("SamplesPerSecond", 1.0)
	l = askParameters(gui, [{"Name":"Start",
						"Value":0},
					   {"Name":"Stop",
						"Value":int(header["Length"])},
					   {"Name":"Channels",
						"Type":"Select",
						"Value":cns},
					   {"Name":"Set SamplesPerSecond",
						"Value":fs},
						{"Name":'Down-sample', 'Value':0}
					   ])
	if not l:
		args['abort']=True
		return args
	start, stop, chans, set_sr, down = l[0], l[1], l[2], l[3], l[4]
	if chans:
		if not toomany:
			chans = [cns.index(x) for x in chans]
		elif "Select" in chans:
			d=askParameters(gui, [{"Name":"Channels (python list or range from %i total channels)" % toomany,
									"Value":"range(10)"}])
			try:
				chans=eval(d[0])
			except:
				chans=range(10)
	return {'Channels':chans, 'Start':start, 'Stop':stop, 'SamplesPerSecond':set_sr, 'Downsample':down}
示例#8
0
文件: graphGL.py 项目: gic888/MIEN
	def presetView(self, vn):
		if not self.views:
			self.report("No preset views")
			return	
		if not vn:
			if len(self.views.keys())==1:
				vn=self.views.keys()[0]
		if not vn:		
			l=askParameters(self, [{"Name":"Which View?",
						            "Type":"List",
						            "Value":self.views.keys()}])
			if not l:
				return
			vn=l[0]	
		v=self.views[vn]		
		self.viewpoint=v['vp'].copy()
		self.forward=v['forward'].copy()
		self.extent=v['ext']
		self.up=v['up'].copy()
		self.depthoffield=v['depth']
		self.OnDraw()
示例#9
0
文件: graphGL.py 项目: gic888/MIEN
	def viewEdit(self, event=None):
		vp=self.viewpoint.tolist()
		forward=self.forward.tolist()
		up=self.up.tolist()
		size=self.extent
		depth=self.depthoffield
		l=askParameters(self, [{"Name":"Preset Name",
				                "Value":"Preset View"},
				               {"Name":"Viewpoint",						
				                "Value":vp},
				               {"Name":"Forward",
				                "Value":forward},
				               {"Name":"Up",
				                "Value":up},
				               {"Name":"View Extent",
				                "Value":size},
				               {"Name":"Depth",
				                "Value":depth}])
		if not l:
			return
		self.views[l[0]]={"vp":array(l[1]),"forward":array(l[2]), "up":array(l[3]),"ext":l[4], "depth":l[5]}
		self.presetView(l[0])
示例#10
0
文件: graphGL.py 项目: gic888/MIEN
	def screenShot(self, fname=None):
		if not fname:
			l=askParameters(self, [{"Name":"File Name",
						            "Value":"GLScreenShot.jpg"}])
			if not l:
				return None
			fname=l[0]
		size = self.GetClientSize()
		glPixelStorei(GL_PACK_ALIGNMENT, 1)
		screen=array(glReadPixelsub(0,0, size.width, size.height, GL_RGB))
		if type(screen[0,0])!=ArrayType:
			screen=fromstring(screen.tostring(), 'B') 
			screen=reshape(screen, (size.width, size.height, 3))
		else:	
			screen=screen.astype('B')
		img=wx.EmptyImage(screen.shape[0], screen.shape[1])
		img.SetData(screen.tostring())
		img=img.Mirror(False)
		if fname.endswith('.jpg'):
			img.SaveFile(fname, wx.BITMAP_TYPE_JPEG)
		elif fname.endswith('.jpg'):
			img.SaveFile(fname, wx.BITMAP_TYPE_PNG)
		else:
			img.SaveFile(fname, wx.BITMAP_TYPE_BMP)
示例#11
0
文件: cli.py 项目: gic888/MIEN
def askParametersCLI(lod, gui=None):
	if gui:
		if gui is True:
			gui=None
		from mien.wx.dialogs import askParameters
		return askParameters(gui, lod)
	pars=[]
	for dic in lod: 
		if dic["Type"] == "Label":
			print(dic['Value'])
			continue
		if dic["Type"]=="Choice":
			raise StandardError('"choice" dialog type is not supported in cli')
		if not dic.get("Type", "Foo") in ["List", "Prompt", "Select"]:
			if dic.get("Default"):
				if not dic.get("Value"):
					dic["Value"]=dic["Default"]
			if not dic.has_key("Type"):
				dic["Type"]=type(dic["Value"])
			val = raw_input("%s (%s) > " % (dic['Name'], dic.get['Value']))
			try:
				val=dic["Type"](val)
			except:
				print("Couldn't cast value to required type. Hope for the best.")
		else:
			val=askFromList(dic['Name'], dic['Value'], dic['Type']=="Select")
		pars.append(val)
	names=[dic['Name'] for dic in lod if not dic['Type']=='Label']
	ps=','.join(["%s:%s" % (names[i], str(pars[i])) for i in range(len(pars))])
	print("Parameter values are: %s" % ps)
	ok=raw_input("Are these OK? (o)k/(r)eenter/(a)bort > ")
	if ok.lower.startswith('n'):
		return askParametersCLI(lod)
	elif ok.lower.startswith('a'):
		return None
	return pars
示例#12
0
文件: base.py 项目: gic888/MIEN
	def askParam(self, d):
		d = askParameters(self, d)
		if not d:
			self.report("Canceled Parameter Dialog")
		return d