#Autogenerated by ReportLab guiedit do not edit
from rlextra.graphics.guiedit.datacharts import ODBCDataSource, DataAssociation, DataAwareDrawing
from reportlab.pdfbase.pdfmetrics import stringWidth
from reportlab.graphics.shapes import _DrawingEditorMixin, String
from reportlab.graphics.charts.textlabels import _simpleSplit

class DataTester(_DrawingEditorMixin,DataAwareDrawing):
	def __init__(self,width=400,height=200,*args,**kw):
		DataAwareDrawing.__init__(*(self,width,height)+args, **kw)
		self.dataSource = ODBCDataSource()
		self.dataSource.host = 'www.reportlab.co.uk'
		self.dataSource.name = 'testdb'
		self.dataSource.driver = 'mysql'
		self.dataSource.password = 'whistl3r'
		self.dataSource.user = 'rptlabi'
		self.dataSource.sql = 'SELECT chartId,periodEnd,fundReturn,indexReturn FROM testtable'
		self.dataSource.groupingColumn = 0
		self.dataSource.associations.size = 2
		self.dataSource.associations.element00 = DataAssociation(column=0, target='chartId', assocType='scalar')
		self.dataSource.associations.element01 = DataAssociation(column=((1,2),(1,3)), target='data', assocType='tmatrix')
		self.chartId = None
		self.data = None
		self.fontName = 'Helvetica'
		self.fontSize = 10
		self.leading = 1.2*self.fontSize

	def getContents(self):
		SW = lambda text, fN=self.fontName, fS=self.fontSize: stringWidth(text, fN, fS)
		L=['chartId: %s'%self.chartId] + _simpleSplit(str(self.data),self.width-20,SW)
		self.contents[:] = [String(10,self.height-self.leading*(1+i),l,fontName=self.fontName,fontSize=self.fontSize) for i,l in enumerate(L)]
		return DataAwareDrawing.getContents(*(self,))

if __name__=="__main__": #NORUNTESTS
	DataTester().go()
