-
Notifications
You must be signed in to change notification settings - Fork 0
/
VroMADGUI.py
240 lines (206 loc) · 10.4 KB
/
VroMADGUI.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import traceback
import multiprocessing as mp
from multiprocessing import freeze_support
import queue
import tkinter as tk
import tkinter.filedialog
import tkinter.ttk
import VroMAD
#Very ugly hackjob for GUI, I have no idea what I'm doing
class VroMADGUI():
CONST_GAUSS_SIM = 0
CONST_EUCLID_DIST = 1
CONST_CELL_W = 32
CONST_99 = '#039331'
CONST_98 = '#3A9B20'
CONST_95 = '#92C00E'
CONST_94 = '#C5D300'
CONST_93 = '#E6E209'
CONST_90 = '#ED9E0A'
CONST_L = '#CA2136'
def __init__(self):
self.processed = False
self.vromad = VroMAD.VroMAD()
self.referencePath = ""
self.testPath = ""
self.root = tk.Tk()
self.root.title("vroMAD v0.1.2")
self.frame = tk.Frame(self.root)
self.frame.grid(row=0, column=0, padx=5, pady=5)
##Label and reference path handling
self.pathLabel = tk.Label(self.frame, text="Path of reference replays")
self.pathLabel.grid(row=0, column=0, columnspan=4, sticky=tk.W)
self.pathFrame = tk.Frame(self.frame)
self.pathFrame['borderwidth']=2
self.pathFrame['relief']='sunken'
self.pathFrame.grid(row=1, column=0, columnspan=4, sticky=tk.W)
self.pathFrameLabel = tk.Label(self.pathFrame, width=50, text="")
self.pathFrameLabel.grid(row=0,column=0, sticky=tk.W)
#Label and test path handling
self.idPathLabel = tk.Label(self.frame, text="Path of replay to analyze")
self.idPathLabel.grid(row=0, column=5, columnspan=4,sticky=tk.W)
self.idPathFrame = tk.Frame(self.frame)
self.idPathFrame['borderwidth']=2
self.idPathFrame['relief']='sunken'
self.idPathFrame.grid(row=1, column=5, columnspan=4, sticky=tk.W)
self.idPathFrameLabel = tk.Label(self.idPathFrame, width=50,text="")
self.idPathFrameLabel.grid(row=0, column=0, sticky=tk.W)
#Browse buttons
self.button1 = tk.Button(self.frame, text="Browse...", command=self.changePath)
self.button1.grid(row=1, column=4, padx=2, pady=2, sticky=tk.W)
self.button2 = tk.Button(self.frame, text="Browse...",command=self.changeFile)
self.button2.grid(row=1, column=9, padx=2, pady=2, sticky=tk.W)
#Start button
self.button3 = tk.Button(self.frame, text="Start", command=self.start)
self.button3.grid(row=2, column=0, padx=5,pady=5, sticky=tk.W)
self.startStatusLabel = tk.Label(self.frame, text="")
self.startStatusLabel.grid(row=2,column=1,columnspan=3, sticky=tk.W)
#Hideous hack below, I have no idea how this really works
#We need this to be able to use pack nevermind we don't
#self.canvasContainerFrame = tk.Frame(self.frame)
#self.canvasContainerFrame.grid(row=3,column=0,columnspan=10)
#Still, I don't really know how this works
#Canvas for table, we need
self.tableCanvas = tk.Canvas(self.frame,width=1000,height=400,bg='white')
#Scrollbar for canvas
self.scrollBar = tk.Scrollbar(self.frame,command=self.tableCanvas.yview)
self.scrollBar.grid(row=4, column=10, sticky=tk.N+tk.S)
self.tableCanvas.configure(yscrollcommand=self.scrollBar.set)
#Frame for table canvas
self.tableFrame = tk.Frame(self.tableCanvas, bg='white')
self.tableFrame.grid()
self.tableLabels = list()
self.tableCanvas.grid(row=4, column=0,columnspan=10)
self.tableCanvas.create_window((0,0),window=self.tableFrame, anchor='nw')
#The <Configure> here is our salvation
self.tableFrame.bind("<Configure>", self.OnFrameConfigure)
self.tableCanvas.configure(scrollregion=self.tableCanvas.bbox('all'))
##Create labels
self.playerLabel = tk.Label(self.tableFrame, text="Player",width=self.CONST_CELL_W,bg='white')
self.playerLabel.grid(row=0,column=0)
self.simLabel = tk.Label(self.tableFrame, text="Similarity",width=self.CONST_CELL_W,bg='white')
self.simLabel.grid(row=0,column=1)
self.raceLabel = tk.Label(self.tableFrame, text="Race",width=self.CONST_CELL_W,bg='white')
self.raceLabel.grid(row=0,column=2)
self.mapLabel = tk.Label(self.tableFrame,text="Map",width=self.CONST_CELL_W,bg='white')
self.mapLabel.grid(row=0,column=3)
#Radio buttons for player selection
self.radioButtonVar = tk.IntVar()
self.radioButtonP1 = tk.Radiobutton(self.frame,text="Player 0", variable=self.radioButtonVar, value=0, command=self.drawTable)
self.radioButtonP1.grid(row=2,column=4,columnspan=3, sticky=tk.W)
self.radioButtonP2 = tk.Radiobutton(self.frame,text="Player 1", variable=self.radioButtonVar, value=1, command=self.drawTable)
self.radioButtonP2.grid(row=3,column=4,columnspan=3, sticky=tk.W)
#Popup with exception information
self.popup = None
#Progressbar
self.progressBar = tk.ttk.Progressbar(self.frame,length=1000)
self.progressBar.grid(row=5,column=0,columnspan=10)
def OnFrameConfigure(self, event):
self.tableCanvas.configure(scrollregion=self.tableCanvas.bbox('all'))
def paint(self):
self.root.mainloop()
def changePath(self):
self.referencePath = tk.filedialog.askdirectory()
newPathContent = tk.StringVar()
self.pathFrameLabel['textvariable']=newPathContent
newPathContent.set(self.referencePath)
def changeFile(self):
self.testPath = tk.filedialog.askopenfilename()
newPathContent = tk.StringVar()
self.idPathFrameLabel['textvariable']=newPathContent
newPathContent.set(self.testPath)
def start(self):
self.startStatus = tk.StringVar()
self.startStatusLabel['textvariable']=self.startStatus
if self.testPath != "" and self.referencePath != "":
self.startStatus.set("OK.")
self.vromad.samplePath = self.referencePath
self.vromad.testPath = self.testPath
outqueue = mp.Queue()
objqueue = mp.Queue()
progqueue = mp.Queue()
errqueue = mp.Queue()
process = mp.Process(target=self.vromad.extractPlayers_mp,args=[outqueue, objqueue, progqueue, errqueue])
#process = mp.Process(target=wrapper, args=[self.vromad, outqueue, objqueue, progqueue, errqueue])
process.daemon = True
process.start()
print("started process")
self.frame.after(10, self.checkStatus,[outqueue, objqueue, progqueue, errqueue])
print("bar should have started")
else:
self.startStatus.set("Please select valid paths.")
def drawTable(self):
if self.processed:
results = self.vromad.calcSimGauss()
self.resultLabels = list()
i=1
choice = self.radioButtonVar.get()
for player in results[choice]:
currentRow = list()
currentRow.append(tk.Label(self.tableFrame,text=player.name,width=self.CONST_CELL_W, bg='white'))
currentRow[-1].grid(row=i,column=0)
currentRow.append(tk.Label(self.tableFrame,text=str(player.simToTest[choice]),width=self.CONST_CELL_W, bg='white'))
if player.simToTest[choice] >= 0.99:
currentRow[-1].configure(bg=self.CONST_99)
elif player.simToTest[choice] >= 0.98:
currentRow[-1].configure(bg=self.CONST_98)
elif player.simToTest[choice] >= 0.95:
currentRow[-1].configure(bg=self.CONST_95)
elif player.simToTest[choice] >= 0.94:
currentRow[-1].configure(bg=self.CONST_94)
elif player.simToTest[choice] >= 0.93:
currentRow[-1].configure(bg=self.CONST_93)
elif player.simToTest[choice] >= 0.90:
currentRow[-1].configure(bg=self.CONST_90)
else:
currentRow[-1].configure(bg=self.CONST_L)
currentRow[-1].grid(row=i,column=1)
currentRow.append(tk.Label(self.tableFrame,text=player.race,width=self.CONST_CELL_W, bg='white'))
currentRow[-1].grid(row=i,column=2)
currentRow.append(tk.Label(self.tableFrame,text=player.mapName,width=self.CONST_CELL_W, bg='white'))
currentRow[-1].grid(row=i,column=3)
self.resultLabels.append(currentRow)
i=i+1
def exceptionPopUp(self,msg):
self.popup = tk.Toplevel()
self.errMessage = tk.Message(self.popup, text=msg)
self.errMessage.pack()
self.popup.title("Exception")
def checkStatus(self,queues):
print("updateplz")
try:
queuestuff = queues[2].get_nowait()
except queue.Empty:
print("empty")
self.frame.after(10, self.checkStatus, queues)
return
if queuestuff == "FATAL":
filepath, e, formatted_str = queues[3].get()
if isinstance(e, AttributeError):
#Looks like we may know what we are dealing with here
self.exceptionPopUp("Oops, looks like one of the files had a " +
"bad replay.tracker.events, but we can keep going\n" +
filepath + '\n' + formatted_str)
self.frame.after(10, self.checkStatus, queues)
else:
self.exceptionPopUp(filepath + formatted_str)
return
elif queuestuff != "ALLDONEHERE":
self.progressBar.step(float(queuestuff))
self.frame.after(10, self.checkStatus, queues)
else:
#Handle done
extractStatus = queues[0].get()
self.vromad = queues[1].get()
if extractStatus <= 0:
self.startStatus.set("Please try a different path")
else:
self.startStatus.set("Found " + str(extractStatus) + " players in reference folder.")
self.processed = True
self.drawTable()
self.radioButtonP1.configure(text="Player 0 (" + self.vromad.testPlayers[0].name + ")")
self.radioButtonP2.configure(text="Player 1 (" + self.vromad.testPlayers[1].name + ")")
#def wrapper(vromad, outqueue, objqueue, progqueue, errqueue):
# vromad.extractPlayers_mp(outqueue, objqueue, progqueue, errqueue)
def wtf():
print("WTF")