Exemple #1
0
    def lines(self, indent=0):
        """
            indent: the number of preceding whitespace.

            return the lines of table.
        """
        # reverse the table and get the max_len of cols.
    
        idt = " " * indent
        s_sep = "".join(["+" + ("-" * (l + 1)) for l in self.col_max_w])
        line_sep = idt + s_sep + "+"
        line_head = re.sub('-','=',line_sep)

        lines = []
        for row in self.list:
            if row[0] == " |S":
                lines.append(line_sep)
            elif row[0] == " |H":
                lines.append(line_head)
            else:
                s_col = ""
                for i , cell in enumerate(row):
                    c = cell
                    s_col += "|" + c + (" " * (self.col_max_w[i] - wstr_len(c))) + " "
                line_con = idt + s_col + "|"
                lines.append(line_con)

        if lines:
            if lines[-1] != line_sep:
                lines.append(line_sep)
            if lines[0] != line_sep:
                lines.insert(0,line_sep)

        return lines
    def lines(self, indent=0):
        """
            indent: the number of preceding whitespace.

            return the lines of table.
        """
        # reverse the table and get the max_len of cols.

        idt = " " * indent
        s_sep = "".join(["+" + ("-" * (l + 1)) for l in self.col_max_w])
        line_sep = idt + s_sep + "+"
        line_head = re.sub('-', '=', line_sep)

        lines = []
        for row in self.list:
            if row[0] == " |S":
                lines.append(line_sep)
            elif row[0] == " |H":
                lines.append(line_head)
            else:
                s_col = ""
                for i, cell in enumerate(row):
                    c = cell
                    s_col += "|" + c + (
                        " " * (self.col_max_w[i] - wstr_len(c))) + " "
                line_con = idt + s_col + "|"
                lines.append(line_con)

        if lines:
            if lines[-1] != line_sep:
                lines.append(line_sep)
            if lines[0] != line_sep:
                lines.insert(0, line_sep)

        return lines
Exemple #3
0
 def parse_col_max_width(self):
     '''
     A list contains the max width of each column.
     e.g | e     | e   | ee |
         | eeeee | e   | e  |
         | ee    | eee | e  |
     will set col_max_w to  [5 , 3 ,2]
     '''
     v_tbl = zip(*self.list)
     col_max_w = []
     for v_cols in v_tbl:
         max_len = 0         # two space
         for col in v_cols:
             if re.match(' \|S| \|H',col):
                 continue
             c_len = wstr_len(col)
             if c_len > max_len:
                 max_len = c_len
         col_max_w.append(max_len)
     self.col_max_w = col_max_w
 def parse_col_max_width(self):
     '''
     A list contains the max width of each column.
     e.g | e     | e   | ee |
         | eeeee | e   | e  |
         | ee    | eee | e  |
     will set col_max_w to  [5 , 3 ,2]
     '''
     v_tbl = zip(*self.list)
     col_max_w = []
     for v_cols in v_tbl:
         max_len = 0  # two space
         for col in v_cols:
             if re.match(' \|S| \|H', col):
                 continue
             c_len = wstr_len(col)
             if c_len > max_len:
                 max_len = c_len
         col_max_w.append(max_len)
     self.col_max_w = col_max_w