-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdistanceTableGUI.py
More file actions
93 lines (79 loc) · 3.86 KB
/
Copy pathdistanceTableGUI.py
File metadata and controls
93 lines (79 loc) · 3.86 KB
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
import pygame as pg
from drawText import draw_textLeftToRight
class distanceTableGUIObject:
def __init__(self,screen,x,y,ID,node):
self.screen = screen
self.x = x
self.y = y
self.ID = ID
self.myNode = node
self.fontNormal = pg.font.SysFont('Arial',32)
self.colorBlack = (0,0,0)
self.colorBlue = (45,93,204)
self.padding = 50
self.width = 190
self.height = 190
self.distanceTable = [[1,2,9999,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
self.changeMatrix = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
def resetChangeMatrix(self):
self.changeMatrix = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
def setTable(self):
for row in range(0,4):
for col in range(0,4):
self.distanceTable[row][col] = self.myNode.distanceTable[row][col]
def update(self):
# if self.ID == 1:
# isSame = True
# for row in range(0,4):
# for col in range(0,4):
# if self.distanceTable[row][col] != self.myNode.distanceTable[row][col]:
# isSame = False
# if isSame == False:
# print("change detected")
# self.distanceTable = self.myNode.distanceTable
for row in range(0,4):
for col in range(0,4):
if self.distanceTable[row][col] != self.myNode.distanceTable[row][col]:
self.changeMatrix[row][col] = 1
self.distanceTable[row][col] = self.myNode.distanceTable[row][col]
def draw(self):
#draw id of obj for table (topLeft of x,y)
draw_textLeftToRight(str(self.ID),self.fontNormal,self.colorBlack,self.screen,self.x,self.y)
#draw the header(same for all distanceTableGUIObjects)
#header left->right
draw_textLeftToRight("0",self.fontNormal,self.colorBlack,self.screen,self.x + self.padding,self.y)
draw_textLeftToRight("1",self.fontNormal,self.colorBlack,self.screen,self.x + self.padding*2,self.y)
draw_textLeftToRight("2",self.fontNormal,self.colorBlack,self.screen,self.x + self.padding*3,self.y)
draw_textLeftToRight("3",self.fontNormal,self.colorBlack,self.screen,self.x + self.padding*4,self.y)
#header top->bottom
draw_textLeftToRight("0",self.fontNormal,self.colorBlack,self.screen,self.x,self.y + self.padding)
draw_textLeftToRight("1",self.fontNormal,self.colorBlack,self.screen,self.x,self.y + self.padding * 2)
draw_textLeftToRight("2",self.fontNormal,self.colorBlack,self.screen,self.x,self.y + self.padding * 3)
draw_textLeftToRight("3",self.fontNormal,self.colorBlack,self.screen,self.x,self.y + self.padding * 4)
#draw chart lines
pg.draw.line(self.screen,self.colorBlack,[self.x+self.padding-16,self.y],[self.x+self.padding-16,self.y+self.padding + self.height],5)
pg.draw.line(self.screen,self.colorBlack,[self.x,self.y+self.padding-8],[self.x+self.padding+self.width,self.y+self.padding-8],5)
#draw from and to
draw_textLeftToRight("from",self.fontNormal,self.colorBlack,self.screen,self.x-70,self.y + int(self.height/2) + 20)
draw_textLeftToRight("to",self.fontNormal,self.colorBlack,self.screen,self.x + int(self.width/2) + 30,self.y - 40)
#draw dist table values
for row in range(0,4):
for col in range(0,4):
val = self.distanceTable[col][row]
strVal = ""
if val == 9999:
strVal = "inf."
else:
strVal = str(val)
draw_textLeftToRight(strVal,self.fontNormal,self.colorBlack,self.screen,self.x+self.padding + self.padding * row,self.y+self.padding + self.padding * col)
#draw dist table changed values
for row in range(0,4):
for col in range(0,4):
val = self.distanceTable[col][row]
strVal = ""
if val == 9999:
strVal = "inf."
else:
strVal = str(val)
if self.changeMatrix[col][row] == 1:
draw_textLeftToRight(strVal,self.fontNormal,self.colorBlue,self.screen,self.x+self.padding + self.padding * row,self.y+self.padding + self.padding * col)