-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGUI.py
252 lines (156 loc) · 5.89 KB
/
GUI.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
241
242
243
244
245
246
247
248
249
250
251
252
"""Importing All Functional Kivy Classes"""
import kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.image import Image
from kivy.uix.popup import Popup
"""Importing Additional Libraries"""
import matplotlib.pyplot as plt
import numpy as np
import math
import time
import os
import sys
"""Importing The Backend Classes"""
from Simulation import Simulation
from main import Aircraft
#Setting default application window size
Window.size = (1280,720)
#Declaring Current Simulation Class For Current Runtime
curr_simulation = Simulation()
class Intro_Screen(Screen):
num_aircrafts = ObjectProperty(None)
filename = ObjectProperty(None)
nav_main = ObjectProperty(None)
nav_plot = ObjectProperty(None)
def intro_enter(self):
num_aircrafts = self.num_aircrafts.text
filename = self.filename.text
#printing to terminal
print(f'Current Number Of Aircraft In Airspace {num_aircrafts} and the Terrain File Is: {filename}')
#input validation
ic = self.integer_checker(int(num_aircrafts))
fc = self.filename_checker(str(filename))
if ic == 1:
#If integer check returns integer "1" prompt invalid input popup
intro_pop = Popup(title = "Invalid Input(s)",
content = Label(text = "Please fill in all input boxs with valid data", font_size = 18))
intro_pop.open()
if fc == 1:
#If filename search returns integer "1" prompt invalid input popup
intro_pop = Popup(title = "Invalid Input(s)",
content = Label(text = "Please fill in all input boxs with valid data", font_size = 18))
intro_pop.open()
else:
#else (input is valid) make aircraft count the given number of aircraft, switch screen to main screen and clear input boxs
curr_simulation.aircraft_count = int(num_aircrafts)
curr_simulation.fn = str(filename)
self.intro_clear()
sm.current = "main"
pass
def integer_checker(self, num_aircrafts):
#Parsing kivy textinput values into simulation class methods
return curr_simulation.aircraft_num_checker(int(num_aircrafts))
def filename_checker(self, filename):
#error checking with simulation method
return curr_simulation.get_filename(str(filename))
def intro_clear(self):
self.num_aircrafts = ""
self.filename = ""
def navto_plot(self):
sm.current = "plot"
return
def navto_main(self):
sm.current = "main"
return
class Main_Screen(Screen):
aircraft_name = ObjectProperty(None)
aircraft_speed = ObjectProperty(None)
aircraft_alt = ObjectProperty(None)
aircraft_x = ObjectProperty(None)
aircraft_y = ObjectProperty(None)
aircraft_dir = ObjectProperty(None)
aircraft_entered_label = ObjectProperty(None)
nav_plot = ObjectProperty(None)
nav_intro = ObjectProperty(None)
#tracking for amount of aircraft entered
curr_ac_num = 0
def pass_aircraft(self):
curr_simulation.add_aircraft_kivy(
self.aircraft_name.text,
self.aircraft_alt.text,
self.aircraft_speed.text,
self.aircraft_x.text,
self.aircraft_y.text,
self.aircraft_dir.text
)
def main_enter(self):
self.pass_aircraft()
self.curr_ac_num += 1
self.aircraft_entered_label.text = f'{self.curr_ac_num}/{curr_simulation.aircraft_count} Aircraft Entered'
self.main_clear()
def main_clear(self):
self.aircraft_name.text = ""
self.aircraft_speed.text = ""
self.aircraft_alt.text = ""
self.aircraft_x.text = ""
self.aircraft_y.text = ""
self.aircraft_dir.text = ""
def navto_intro(self):
sm.current = "intro"
return
def navto_plot(self):
sm.current = "plot"
return
class Plot_Screen(Screen):
validate_button = ObjectProperty(None)
flight_hours = ObjectProperty(None)
flight_hours_label = ObjectProperty(None)
plot_button = ObjectProperty(None)
nav_main = ObjectProperty(None)
nav_intro = ObjectProperty(None)
def validate_terrain(self):
curr_simulation.create_terrain()
self.validate_button.background_color = (17/255.0,168/255.0,40/255.0,0.75)
def run_plot(self):
hours = int(self.flight_hours.text)
curr_simulation.run_simulation(hours)
def navto_intro(self):
sm.current = "intro"
return
def navto_main(self):
sm.current = "main"
return
class Window_Manager(ScreenManager):
pass
#Load kivy design langauage file
kv = Builder.load_file("my.kv")
# declare variable "sm" (screenmanager) to be used as the window manager
sm = Window_Manager()
# iterable list of screens
screens = [Intro_Screen(name = "intro"), Main_Screen(name = "main"), Plot_Screen(name = "plot")]
# appending all screens within screens list to be individual widgets
for screen in screens:
sm.add_widget(screen)
# screen to show when runtime executes (landing screen)
sm.current = "main"
"""App Run Class"""
class MyApp(App):
# builds and returns current screen held within variable "sm"
def build(self):
return sm
# if name is main then do the following (execution line)
if __name__ == "__main__":
MyApp().run()
plt.show()