-
Notifications
You must be signed in to change notification settings - Fork 0
/
aligner.py
49 lines (38 loc) · 1.34 KB
/
aligner.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
from prettytable import PrettyTable
class Aligner():
def __init__(self, original, toalign) -> None:
self.original = original
self.toalign = toalign
self.table = PrettyTable()
self.table.field_names = ["Orginal", "Index", "Translated"]
self.table.align["Orginal"] = "l"
self.table.align["Translated"] = "l"
self.table.max_width["Orginal"] = 60
self.table.max_width["Translated"] = 60
def print_table(self):
self.table.clear_rows()
for index, value in enumerate(self.original):
original_text = value
if len(self.toalign) > index:
toalign_text = self.toalign[index]
else:
toalign_text = ""
self.table.add_row([original_text, index, toalign_text])
print(self.table)
def shift_lines(self, index):
if self.toalign[index] == "":
del self.toalign[index]
else:
self.toalign.insert(index, "")
def align(self):
while True:
self.print_table()
userInput = input("Insert empty line at:")
try:
index = int(userInput)
self.shift_lines(index)
continue
except ValueError:
print("Save")
break
return self.toalign