def create_table(self):
xlist = []
xlist.append({'desc': 'blabla blabla', 'amt': 5, 'prc': 2.50})
xlist.append({'desc': 'blabla blabla', 'amt': 5, 'prc': 2.50})
xlist.append({'desc': 'blabla blabla', 'amt': 5, 'prc': 2.50})
xlist.append({'desc': 'blabla blabla', 'amt': 5, 'prc': 2.50})
xlist.append({'desc': 'blabla blabla', 'amt': 5, 'prc': 2.50})
xlist.append({'desc': 'blabla blabla', 'amt': 5, 'prc': 2.50})
table = self.ctrl.WriteTable(len(xlist), 3)
for pos, cont in enumerate(xlist):
# Description
cell = table.GetCell(row=pos, col=0)
prg = cell.GetParagraphAtLine(0)
prg.InsertText(1, str(cont['desc']))
prg.SetAttributes(self.set_alignment(prg, "left"))
cell.SetBasicStyle(self.set_colwidth(cell, 460))
cell.UpdateRanges()
# Amount
cell = table.GetCell(row=pos, col=1)
prg = cell.GetParagraphAtLine(0)
prg.InsertText(1, str(cont['amt']))
prg.SetAttributes(self.set_alignment(prg, "right"))
cell.SetBasicStyle(self.set_colwidth(cell, 40))
cell.UpdateRanges()
# Price
cell = table.GetCell(row=pos, col=2)
prg = cell.GetParagraphAtLine(0)
prg.InsertText(1, str(cont['prc']))
prg.SetAttributes(self.set_alignment(prg, "right"))
cell.SetBasicStyle(self.set_colwidth(cell, 60))
cell.UpdateRanges()
def set_colwidth(self, cell, width):
dim_atr = rt.TextAttrDimension()
dim_atr.SetValue(width)
dim_atr.SetUnits(rt.TEXT_ATTR_UNITS_PIXELS)
size_atr = rt.TextAttrSize()
size_atr.SetWidth(dim_atr)
box_atr = rt.TextBoxAttr()
box_atr.SetSize(size_atr)
cell_atr = cell.GetBasicStyle()
cell_atr.SetTextBoxAttr(box_atr)
return cell_atr
def set_alignment(self, prg, ori):
attr = prg.GetAttributes()
if ori == "left":
attr.SetAlignment(wx.TEXT_ALIGNMENT_LEFT)
attr.SetLeftIndent(16)
elif ori == "right":
attr.SetAlignment(wx.TEXT_ALIGNMENT_RIGHT)
attr.SetRightIndent(16)
return attr