ATLAS Offline Software
Functions | Variables
fancyTab Namespace Reference

Functions

def print_table_row (row, top_border=False, bottom_border=False)
 
def print_table (rows)
 
def get_column (matrix=[], column=0)
 
def max_cell_length (cells)
 
def align_cell_content (cell, max_cell_length=0, alignment=0, truncate=True)
 

Variables

string __author__ = "rottmrei"
 
string __date__ = "$28.01.2011 19:43:01$"
 

Function Documentation

◆ align_cell_content()

def fancyTab.align_cell_content (   cell,
  max_cell_length = 0,
  alignment = 0,
  truncate = True 
)
Returns the given cell padded with spaces to the max_cell_length.
You may choose the alignment of the cell contents:

0 : align left
1 : align right
2 : center

In case the cell contents is longer than max_cell_length, the contents
gets truncated. You may choose to not truncate any cell data.

Definition at line 93 of file fancyTab.py.

93 def align_cell_content(cell, max_cell_length=0, alignment=0, truncate=True):
94  """Returns the given cell padded with spaces to the max_cell_length.
95  You may choose the alignment of the cell contents:
96 
97  0 : align left
98  1 : align right
99  2 : center
100 
101  In case the cell contents is longer than max_cell_length, the contents
102  gets truncated. You may choose to not truncate any cell data.
103  """
104 
105  if max_cell_length == 0:
106  return cell
107  cur_cell_length=len(cell)
108  padding=max_cell_length-cur_cell_length
109  if padding == 0:
110  return cell
111  if padding < 0:
112  if truncate:
113  return cell[:max_cell_length]
114  else:
115  return cell
116  else:
117  if alignment == 0:
118  # align left
119  return cell + " " * padding
120  if alignment == 1:
121  # align right:
122  return " " * padding + cell
123  else:
124  # center
125  pl = int(math.ceil(padding / 2.0))
126  pr = padding -pl
127  return " " * pl + cell + " " * pr
128 
129 
130 
131 

◆ get_column()

def fancyTab.get_column (   matrix = [],
  column = 0 
)
Returns one column from the given matrix.

Definition at line 74 of file fancyTab.py.

74 def get_column(matrix=[], column=0):
75  """Returns one column from the given matrix."""
76  col = []
77  for row in matrix:
78  cell=""
79  if len(row) >= column:
80  cell = row[column]
81  col.append(cell)
82  return col
83 

◆ max_cell_length()

def fancyTab.max_cell_length (   cells)
Returns the length of the longest cell from all the given cells.

Definition at line 84 of file fancyTab.py.

84 def max_cell_length(cells):
85  """Returns the length of the longest cell from all the given cells."""
86  max_len=0
87  for c in cells:
88  cur_len=len(c)
89  if cur_len > max_len:
90  max_len = cur_len
91  return max_len
92 

◆ print_table()

def fancyTab.print_table (   rows)
Prints the rows of a table by calling print_table_row function.
The first row is assumed to be the heading line. The heading line
and the last line of the table are printed with seperator lines.

Definition at line 43 of file fancyTab.py.

43 def print_table(rows):
44  """Prints the rows of a table by calling print_table_row function.
45  The first row is assumed to be the heading line. The heading line
46  and the last line of the table are printed with seperator lines.
47  """
48  if isinstane(rows,(list,tuple)):
49  print ("ERROR: Table rows have to be of the type ListType.")
50  return 1
51  r = 0
52  """row counter"""
53  # space-pad the cells and right align the contents
54  c = 0
55  """column number"""
56  while c < len(rows[0]):
57  col = get_column(rows, c)
58  cell_width = max_cell_length(col)
59  for row in rows:
60  if row[c]:
61  row[c] = align_cell_content(row[c], cell_width, 1, False)
62  c+=1
63  for row in rows:
64  if r == 0 and len(rows) > 0:
65  print_table_row(row, True, True)
66  else:
67  if r == len(rows)-1:
68  print_table_row(row, False, True)
69  else:
70  print_table_row(row)
71  r += 1
72  return 0
73 

◆ print_table_row()

def fancyTab.print_table_row (   row,
  top_border = False,
  bottom_border = False 
)
Prints columns of a single table row with ascii cell seperator and
an optional top and/or bottom border line.

Definition at line 10 of file fancyTab.py.

10 def print_table_row(row, top_border=False, bottom_border=False):
11  """Prints columns of a single table row with ascii cell seperator and
12  an optional top and/or bottom border line.
13  """
14  if isinstane(row,(list,tuple)):
15  print ("ERROR: A line has to be of the type ListType.")
16  return 1
17  cc = "+"
18  """corner char"""
19  hc = "-"
20  """horizontal char"""
21  vc = "|"
22  """vertical char"""
23  # create seperator line and output row
24  sep = ""
25  """seperator line"""
26  out = ""
27  """output row"""
28  sep = cc
29  out = vc
30  c = 0
31  for col in row:
32  sep = sep + hc * len(col) + cc
33  out = out + row[c] + vc
34  c += 1
35  # now print table row
36  if top_border:
37  print (sep)
38  print (out)
39  if bottom_border:
40  print (sep)
41  return 0
42 

Variable Documentation

◆ __author__

string fancyTab.__author__ = "rottmrei"
private

Definition at line 7 of file fancyTab.py.

◆ __date__

string fancyTab.__date__ = "$28.01.2011 19:43:01$"
private

Definition at line 8 of file fancyTab.py.

fancyTab.max_cell_length
def max_cell_length(cells)
Definition: fancyTab.py:84
fancyTab.print_table
def print_table(rows)
Definition: fancyTab.py:43
fancyTab.align_cell_content
def align_cell_content(cell, max_cell_length=0, alignment=0, truncate=True)
Definition: fancyTab.py:93
fancyTab.get_column
def get_column(matrix=[], column=0)
Definition: fancyTab.py:74
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
fancyTab.print_table_row
def print_table_row(row, top_border=False, bottom_border=False)
Definition: fancyTab.py:10