def drawTable(self, group=None, monocell=None, reiter = None): """ Drawing a table """ matrix = [] lst = [] matrix2 = [] vector = [] # Total of element's table cells = int(self.tablesPropertie['cells']) columns = int(self.tablesPropertie['columns']) rows = int(self.tablesPropertie['rows']) widths = self.tablesPropertie['widths'] heights = self.tablesPropertie['heights'] xpos = self.tablesPropertie['xpos'] ypos = self.tablesPropertie['ypos'] # print "DATI", cells, columns, rows, group, heights, widths contColumns = 0 ch = '' col = 0 cycle = False vector = [] alignment= None itexts = self.tablesPropertie['itextsobj'] paras = self.tablesPropertie['parasobj'] stile = TableStyle([]) stile.add('VALIGN',(0,0),(-1,-1),'TOP') tblprop = self.tablesPropertie['cellProperties'] if monocell==True: cells = 1 columns=1 rows = 1 for v in xrange(0,cells): if v == 0: contRows = 0 contColumns = 0 elif columns==1: contColumns = -1 contRows= int(v/columns) else: contRows= int(v/columns) contColumns = ((v)%columns) background = self.backgroundFunc(tblprop[v])# Finding background hexBorderColor = self.hexBorderColorFunc(tblprop[v]['borderColor']) stile.add('ROWBACKGROUNDS', (contColumns,contRows), (contColumns,contRows), (background, background)) cellpr = tblprop[v] cellpict = cellpr['cellPicture'] cellIMGHeight = cellpr['cellHeight'] cellIMGWidth = cellpr['cellWidth'] if (cellpr['bottomLine'] == 1 and cellpr['topLine'] == 1 and\ cellpr['leftLine'] == 1 and cellpr['rightLine'] == 1): stile.add('BOX', (contColumns,contRows), (contColumns,contRows), cellpr['lineWidth'], hexBorderColor) else: if cellpr['bottomLine'] == 1: stile.add('LINEBELOW', (contColumns,contRows), (contColumns,contRows), cellpr['lineWidth'], hexBorderColor) elif cellpr['topLine'] == 1: stile.add('LINEABOVE', (contColumns,contRows), (contColumns,contRows), cellpr['lineWidth'], hexBorderColor) if cellpr['leftLine'] == 1: stile.add('LINEBEFORE', (contColumns,contRows), (contColumns,contRows), cellpr['lineWidth'], hexBorderColor) if cellpr['rightLine'] == 1: stile.add('LINEAFTER', (contColumns,contRows), (contColumns,contRows), cellpr['lineWidth'], hexBorderColor) if not monocell: ch = self.chFunc(itexts[v])[0] itext = self.chFunc(itexts[v])[1] else: try: itext = itexts[0] ch = itexts[0].get('CH') except: itext = None ch = "" # self.chFunc(itexts[0])[1] actualPageObject = self.tablesPropertie# Borders uff = self.tablesPropertie['iterproper'] if uff != [] and v > columns: pdfAlignment = self.alignmentFunc(self.tablesPropertie['iterproper'][contColumns],v, reiter=True) else: pdfAlignment = self.alignmentFunc(paras, v, monocell) #alignment stile.add('ALIGN', (contColumns,contRows), (contColumns,contRows), pdfAlignment) if itext != None: fontName = self.fontNameFunc(itext) # Font name stile.add('FONT', (contColumns,contRows), (contColumns,contRows), fontName) fontSize = self.fontSizeFunc(itext)# Font size stile.add('FONTSIZE', (contColumns,contRows), (contColumns,contRows), fontSize) foreground = self.foregroundFunc(itext) #foreground stile.add('TEXTCOLOR', (contColumns,contRows), (contColumns,contRows), foreground) if "bcview" in ch: alignment="LEFT" vector.append(Sla2pdfUtils.createbarcode(ch)) else: vector.append(Sla2pdfUtils.makeParagraphs(ch, background, foreground, alignment, fontName, fontSize)) elif cellpict: (imgPath, imgFile) = os.path.split(cellpict) path = Environment.imagesDir + imgFile widthIMG = (float(cellIMGHeight)-2)*100/(float(cellIMGWidth)-2) img = Image(path,width=widthIMG,height=float(cellIMGHeight)-2) vector.append(img) else: vector.append('') if monocell==True: cycle= True elif ((v+1)%columns) == 0: contRows = 0 cycle= True if cycle == True: matrix.append(vector) vector = [] cycle = False # if columns > 1 and not reiter: # #wid = [] # hei = [] # for h in range(0,len(heights),rows): # hei.append(heights[h]) # heights = hei table=Table(matrix,style=stile, colWidths=widths[:columns], rowHeights=heights[:rows]) lst.append(table) # Effective table size sumRows = Sla2pdfUtils.sumRowsFunc(heights,rows) sumColumns = Sla2pdfUtils.sumColumnsFunc(widths,columns) f = Frame(x1=(xpos[0] - self.pageProperties[self.pdfPage][9]), y1=(self.pageProperties[self.pdfPage][7] - ypos[0] - sumRows + self.pageProperties[self.pdfPage][10] - 12), width=sumColumns, height=(sumRows+12), showBoundary=0) sumRows = sumColumns = 0 f.addFromList(lst, self.canvas) reiter = False