6.14.4.7. Tables

Start python section to interscript/weavers/text.py[8 /11 ] Next Prev First Last
   179: #line 196 "text_weaver.ipk"
   180:   def __htabrule(self,colw):
   181:     self._write('+')
   182:     for w in colw:
   183:       self._write('-'*(w+2)+'+')
   184:     self._writeline()
   185: 
   186:   def __tabrow(self,colw,data):
   187:     self._write('|')
   188:     for i in range(len(colw)):
   189:       w = colw[i]
   190:       entry = ' '* w
   191:       if i<len(data):
   192:         entry = (data[i]+entry)[:w]
   193:       self._write(' '+entry+' |')
   194:     self._writeline()
   195: 
   196:   def begin_table(self,*headings, **kwds):
   197:     self.table_headings = headings
   198:     self.table_data = []
   199: 
   200:   def table_row(self,data):
   201:     self.table_data.append(data)
   202: 
   203:   def table_rule(self):
   204:     self.table_data.append(table_rule_object)
   205: 
   206:   def end_table(self):
   207:     width = len(self.table_headings)
   208:     for row in self.table_data:
   209:       if row is not table_rule_object:
   210:         w = len(row)
   211:         if w>width : width = w
   212:     colw = [0] * width
   213:     for i in range(len(self.table_headings)):
   214:       w = len(self.table_headings[i])
   215:       if colw[i]<w: colw[i]=w
   216:     for row in self.table_data:
   217:       if row is not table_rule_object:
   218:         for i in range(len(row)):
   219:           w = len(row[i])
   220:           if colw[i]<w: colw[i]=w
   221:     self._flush()
   222:     self._writeline()
   223:     self.__htabrule(colw)
   224:     self.__tabrow(colw,self.table_headings)
   225:     self.__htabrule(colw)
   226:     for data in self.table_data:
   227:       if data is table_rule_object:
   228:         self.__htabrule(colw)
   229:       else:
   230:         self.__tabrow(colw,data)
   231:     self.__htabrule(colw)
   232:     del self.table_headings
   233:     del self.table_data
   234: 
End python section to interscript/weavers/text.py[8]