-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDemo.py
171 lines (126 loc) · 6.07 KB
/
Demo.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
from typing import Generator
import matplotlib
import matplotlib.pyplot as plt
from SimuClasses import *
from tkinter import *
import time
import os
from tkinter import messagebox
from PIL import ImageTk, Image
import sys
import tkinter.font
import requests
from tkinter.filedialog import askopenfilename, askdirectory
from pathlib import Path
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
FONT = "Verdana"
class DemoGUI:
def split(self):
return " "
def startUI(self):
def set_text(entry, text):
entry.delete(0, END)
entry.insert(0, text)
return None
def set_label_text(label, text):
label.config(text=text)
return None
def refresh(self):
self.destroy()
self.__init__()
def Giris():
def message(text):
set_label_text(result,text)
# 2 Entry, 3 Button, 1 checkbutton,1 Label olacak
# simulasyon butonuna basıldığında 2 pencere daha çıkacak biri map'ı gösterecek diğeri de step monitor
mainGUI = Tk()
boyut = 800
mainGUI.geometry("%dx%d" % (boyut, boyut))
mainGUI.title("UAV Simulation Demo")
mainGUI.resizable(False, False)
result = None
ModelFolder = None
UserData = None
UserDataDialog = None
ModelFolderDialog = None
generateRandomEnv = None
generateOptionCheckBox = None
StartSimuButton = None
def load_file():
fname = fname = askopenfilename(defaultextension='.pkl')
set_text(UserData, fname)
def load_dir():
fname = askdirectory()
set_text(ModelFolder, fname)
def simulation_start():
result_dict = {}
gen = test_env(ModelFolder.get(),UserData.get(),
random_env = generateRandomEnv.get(),step_count=int(StepCountEntry.get()),
plot_trajectories=showTrajectoriesVar.get())
for i in gen:
plt.pause(0.0000000000001)
result_dict = i
set_label_text(result,"Average Sum Rate Score: {:.2f}\nFinal Sum Rate Score: {:.2f}"
.format(*(result_dict["scores"])))
def disable_dialog():
def switch(obj):
st = obj["state"]
obj["state"] = "normal" if st=="disabled" else "disabled"
switch(UserData)
switch(UserDataDialog)
def render():
# Sol üst 0,0 yani Aşağı gidildikçe y artıyor
def LOC(X,Y,obj):
return {"relx":X,"rely":Y,"obj":obj}
COL_START_X = 0.2
COL_SPACE_X = 0.4
COL2_START_X = COL_START_X + COL_SPACE_X
resultLoc = LOC(0.35,0.1,result)
ModelFolderLoc,ModelFolderDialogLoc = LOC(COL_START_X, 0.4,ModelFolder),LOC(COL2_START_X, 0.39,ModelFolderDialog)
generateOptionCheckBoxLoc = LOC(COL_START_X,0.5,generateOptionCheckBox)
UserDataLoc,UserDataDialogLoc = LOC(COL_START_X, 0.6,UserData),LOC(COL2_START_X, 0.59,UserDataDialog)
stepCountLabelLoc, StepCountEntryLoc = LOC(COL_START_X, 0.7,stepCountLabel),LOC(COL_START_X+0.2, 0.7,StepCountEntry)
showTrajectoriesCheckBoxLoc = LOC(COL_START_X, 0.8,showTrajectoriesCheckBox)
StartSimuButtonLoc = LOC(0.35,0.9,StartSimuButton)
pack = [resultLoc,
generateOptionCheckBoxLoc,
UserDataLoc,UserDataDialogLoc,
ModelFolderLoc,ModelFolderDialogLoc,
stepCountLabelLoc,StepCountEntryLoc,
showTrajectoriesCheckBoxLoc,
StartSimuButtonLoc]
for location in pack:
location.pop("obj").place(**location)
result = Label(mainGUI, bg="white", fg="Black",
font=FONT+ " 13", text="")
ModelFolder = Entry(
mainGUI, relief=FLAT, bg="white", fg="black",
font=FONT+" 15 italic", text="")
UserData = Entry(
mainGUI, relief=FLAT, bg="white", fg="black",
font=FONT+" 15 italic", text="")
UserDataDialog = Button(mainGUI, relief=FLAT, bg="white", fg="black",
font=FONT+" 15 italic", text="Choose User Data",
command=load_file)
ModelFolderDialog = Button(mainGUI, relief=FLAT, bg="white", fg="black",
font=FONT+" 15 italic", text="Choose Model Folder",
command=load_dir)
generateRandomEnv = tkinter.BooleanVar()
generateOptionCheckBox = tkinter.Checkbutton(mainGUI, text='Random Environment',variable=generateRandomEnv,
font=FONT+ " 15 italic", onvalue=1, offvalue=0, command=disable_dialog)
stepCountLabel = Label(mainGUI, fg="Black",
font=FONT+ " 13", text="Step Count:")
StepCountEntry = Entry(
mainGUI, relief=FLAT, bg="white", fg="black",
font=FONT+" 15 italic", text="64")
showTrajectoriesVar = tkinter.BooleanVar()
showTrajectoriesCheckBox = tkinter.Checkbutton(mainGUI, text='Show Past Trajectories',variable=showTrajectoriesVar,
font=FONT+ " 15 italic", onvalue=1, offvalue=0)
StartSimuButton = Button(mainGUI, relief=FLAT, bg="white", fg="black", font=FONT+ " 15 italic", text="Start Simulation",
command=simulation_start)
render()
Giris()
mainloop()
gui = DemoGUI()
gui.startUI()