-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintEngine.py
88 lines (74 loc) · 2.86 KB
/
printEngine.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
class Window:
def __init__(self, width, height, bg=" ", normalize = False):
self.bg = bg
self.normalize = normalize
self.createMemory(width, height)
# clear memory and create new
def createMemory(self, width, height):
self.width = width
self.height = height
try:
del self.memory
except AttributeError:
pass
for i in range(self.height):
self.memory = [[self.bg for i in range(width)] for j in range(height)]
# clear all
def clear(self):
for i in range(self.height):
for j in range(self.width):
self.memory[i][j] = self.bg
# x = start X, y = start Y
def write(self, string, x=0, y=0, way="x"):
if (way == "x"):
for i in range(len(string)):
self.memory[y][x+i] = string[i]
elif (way == "y"):
for i in range(len(string)):
self.memory[y+i][x] = string[i]
else:
raise Exception("unknown way")
# draw from list
def draw(self, stringList, x=0, y=0, skip=" "):
for i in range(len(stringList)):
for j in range(len(stringList[i])):
if (stringList[i][j] == skip):
pass
else:
self.memory[y+i][x+j] = stringList[i][j]
# draw square
def square(self, x=0, y=0, width=1, height=1, border="▓", filler=""):
if (filler == ""):
for i in range(width):
self.memory[y][x+i] = border
self.memory[y-1+height][x+i] = border
for i in range(height):
self.memory[y+i][x] = border
self.memory[y+i][x-1+width] = border
else:
for i in range(width):
self.memory[y][x+i] = border
for i in range(1, height-1):
self.memory[y+i][x] = border
for j in range(1, width-1):
self.memory[y+i][x+j] = filler
self.memory[y+i][x+width-1] = border
for i in range(width):
self.memory[y+height-1][x+i] = border
# upload memory from another window
def upload(self, windowMemory, x=0, y=0):
windowWidth = len(windowMemory[0])
windowHeight = len(windowMemory)
for i in range(windowHeight):
for j in range(windowWidth):
self.memory[y+i][x+j] = windowMemory[i][j]
# print all
def flush(self):
if (self.normalize == False):
for i in range(self.height):
print("".join(self.memory[i]))
else:
for i in range(self.height):
for j in range(self.width):
print(self.memory[i][j]+" ", end="")
print()