class PlotData:
	'holds the data for gnuplot'
	""" order of values in gnuplotdata is important!
	0:title 1:datastyle 2:seconds 3:filename 4:readdata
	5:labelx 6:labely"""
	gnuplotdata = ['','','','','','','','']
	""" order of values in gnuplotcheckboxes is important!
	0:reread, 1:autoscale, 2:grid, 3:key, 4:logx, 5:logy """
	gnuplotcheckboxes = ['','','','','','']
	# valuepairs; if no second option, leave empty ['foo', '']
	# TODO: put this in an extra ascii file
	cb_possibilities = [['\nreread',''],['\nset autoscale',''], \
		['\nset grid','\nset nogrid'],['\nset key','\nset nokey'], \
		['\nset logscale x','\nset nologscale x'], \
		['\nset logscale y','\nset nologscale y']]
## this is for testing only..
	comment = "\n# ___insert your plot here___ "\
		"\n#e.g.: plot \"mydata.file\" using 2:5 "
##

	def __init__(self):
		pass

	def get_all_values(self):
		return self.gnuplotdata

	def set_important_values(self, a,b,c,d,e,f,g):
		self.gnuplotdata = [a,b,c,d,e,f,g]
		#print self.gnuplotdata

	def set_checkbox_values(self, a,b,c,d,e,f):
		self.gnuplotcheckboxes = [a,b,c,d,e,f]
		#print self.gnuplotcheckboxes
		self.__interpret_cb_values()
		#print self.gnuplotcheckboxes

	def write_tofile(self):
		'write all options to the specified file'
### uncomment the following lines to deny file overwriting !!
		#import os
		#if os.path.exists(self.gnuplotdata[3]):
		  	#return "file exists! cowardly refusing to write"
###
		try:
			gnuplotfile = open(self.gnuplotdata[3],'w')
		except:
			return "could NOT write to "+self.gnuplotdata[3]
		gnuplotfile.write("set title \""+self.gnuplotdata[0]+"\";")
		gnuplotfile.write("\nset data style "+self.gnuplotdata[1]+";")
		gnuplotfile.write("\nset xlabel \""+self.gnuplotdata[5]+"\";")
		gnuplotfile.write("\nset ylabel \""+self.gnuplotdata[6]+"\";")
		# don't print first element (reread)
		for element in range(len(self.gnuplotcheckboxes)-1):
			gnuplotfile.write(self.gnuplotcheckboxes[element+1])
		### plot command
		self.plot = "\nplot \""+self.gnuplotdata[4]+"\" every 2::0 using 7 smooth unique title 'Fensterbank' , \""+self.gnuplotdata[4]+"\" every 2::1 using 7 smooth unique title'Kernschmelze'"
		###
		gnuplotfile.write(self.comment)
		gnuplotfile.write(self.plot)
		gnuplotfile.write("\npause "+self.gnuplotdata[2])
		# reread option is always printed at the end
		gnuplotfile.write(self.gnuplotcheckboxes[0])
		gnuplotfile.close()
		return "successfully written to "+ self.gnuplotdata[3]

	### private functions
	def __interpret_cb_values(self):
		'test if a setting is checked, if so then write the \
		responding option in gnuplotcheckboxes'
		for xxx in range(len(self.gnuplotcheckboxes)):
			if self.gnuplotcheckboxes[xxx]:
				self.gnuplotcheckboxes[xxx] = self.cb_possibilities[xxx][0]
			else:
				self.gnuplotcheckboxes[xxx] = self.cb_possibilities[xxx][1]