ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetCalibAlgs
PixelCalibAlgs
NNClusteringCalibration_RunI
getMinTraining
fancyTab.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
2
3
4
import
types
5
import
math
6
7
__author__ =
"rottmrei"
8
__date__ =
"$28.01.2011 19:43:01$"
9
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 cha
r"""
21
vc = "|"
22
"""
vertical cha
r"""
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
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 counte
r"""
53
# space-pad the cells and right align the contents
54
c = 0
55
"""
column numbe
r"""
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
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
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
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
fancyTab.print_table_row
print_table_row(row, top_border=False, bottom_border=False)
Definition
fancyTab.py:10
Generated on
for ATLAS Offline Software by
1.17.0