-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvismatrix.py
149 lines (120 loc) · 6.51 KB
/
vismatrix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Visual Matrix
# Author: VolodyaHoi
# Version: 0.5
from multipledispatch import dispatch
class VisualMatrix():
table = []
length = []
current_length = -1
current_max = -1
no_header = True
matrix = []
no_border = True
@staticmethod
def addHeader(header):
if VisualMatrix.no_header != False:
VisualMatrix.table.insert(0, header)
VisualMatrix.no_header = False
@staticmethod
def addRow(row):
VisualMatrix.table.append(row)
@dispatch(list, list, bool)
def setMatrix(user_matrix, header, border):
if VisualMatrix.no_header == True:
for i in range(0, len(user_matrix)):
VisualMatrix.matrix.append(user_matrix[i])
VisualMatrix.matrix.insert(0, header)
VisualMatrix.table = VisualMatrix.matrix
VisualMatrix.no_header = False
VisualMatrix.no_border = border
@dispatch(list)
def setMatrix(user_matrix):
VisualMatrix.table = user_matrix
@staticmethod
def clear():
VisualMatrix.table = []
VisualMatrix.length = []
VisualMatrix.current_length = -1
VisualMatrix.current_max = -1
VisualMatrix.no_header = True
VisualMatrix.matrix = []
VisualMatrix.no_border = True
@staticmethod
def myMatrix():
try:
for i in range(0, len(VisualMatrix.table)):
for j in range(0, len(VisualMatrix.table[0])):
if len(str(VisualMatrix.table[i][j])) > VisualMatrix.current_length:
VisualMatrix.current_length = len(str(VisualMatrix.table[i][j]))
VisualMatrix.length.append(VisualMatrix.current_length)
VisualMatrix.current_length = -1
for i in range(0, len(VisualMatrix.length)):
if VisualMatrix.current_max < VisualMatrix.length[i]:
VisualMatrix.current_max = VisualMatrix.length[i]
if VisualMatrix.current_max % 2 != 0:
VisualMatrix.current_max = VisualMatrix.current_max + 1
if VisualMatrix.no_header == False and VisualMatrix.no_border == True:
for i in range(0, len(VisualMatrix.table[0])):
print("+-" + "-" * VisualMatrix.current_max + "-", end="")
print("+")
for i in range(0, len(VisualMatrix.table)):
if VisualMatrix.no_header == True:
for j in range(0, len(VisualMatrix.table[0])):
if j == 0:
print("+-" + "-" * VisualMatrix.current_max + "-+", end="")
else:
print("-" + "-" * VisualMatrix.current_max + "-+", end="")
print("")
if VisualMatrix.no_border == False:
for j in range(0, len(VisualMatrix.table[0])):
if j == 0:
if i < 2:
print("+=" + "=" * VisualMatrix.current_max + "=+", end="")
else:
print("+-" + "-" * VisualMatrix.current_max + "-+", end="")
else:
if i < 2:
print("=" + "=" * VisualMatrix.current_max + "=+", end="")
else:
print("-" + "-" * VisualMatrix.current_max + "-+", end="")
print("")
for j in range(0, len(VisualMatrix.table[0])):
if j == 0:
if VisualMatrix.current_max != len(str(VisualMatrix.table[i][j])):
if len(str(VisualMatrix.table[i][j])) % 2 == 0:
difChar = int((VisualMatrix.current_max - len(str(VisualMatrix.table[i][j]))) / 2)
print("| " + " " * difChar + str(VisualMatrix.table[i][j]) + " " * difChar + " |", end="")
else:
difChar = int((VisualMatrix.current_max - len(str(VisualMatrix.table[i][j]))) / 2)
print("| " + " " + " " * difChar + str(VisualMatrix.table[i][j]) + " " * difChar + " |", end="")
else:
if len(str(VisualMatrix.table[i][j])) % 2 == 0:
print("| " + str(VisualMatrix.table[i][j]) + " |", end="")
else:
print("| " + str(VisualMatrix.table[i][j]) + " |", end="")
else:
if VisualMatrix.current_max != len(VisualMatrix.table[i][j]):
if len(str(VisualMatrix.table[i][j])) % 2 == 0:
difChar = int((VisualMatrix.current_max - len(str(VisualMatrix.table[i][j]))) / 2)
print(" " + " " * difChar + str(VisualMatrix.table[i][j]) + " " * difChar + " |", end="")
else:
difChar = int((VisualMatrix.current_max - len(str(VisualMatrix.table[i][j]))) / 2)
print(" " + " " + " " * difChar + str(VisualMatrix.table[i][j]) + " " * difChar + " |", end="")
else:
if len(str(VisualMatrix.table[i][j])) % 2 == 0:
print(" " + str(VisualMatrix.table[i][j]) + " |", end="")
else:
print(" " + str(VisualMatrix.table[i][j]) + " |", end="")
print("")
if VisualMatrix.no_header == False:
if i == 0:
if VisualMatrix.no_border == True:
for i in range(0, len(VisualMatrix.table[0])):
print("+-" + "-" * VisualMatrix.current_max + "-", end="")
print("+")
for i in range(0, len(VisualMatrix.table[0])):
print("+-" + "-" * VisualMatrix.current_max + "-", end="")
print("+")
VisualMatrix.clear()
except:
print("Module [Visual Matrix] send error! Check your code on errors or contact with developer.")