1 | # The main program
|
---|
2 |
|
---|
3 | import const
|
---|
4 | import fs
|
---|
5 | import flight
|
---|
6 | import logger
|
---|
7 | import acft
|
---|
8 | import sys
|
---|
9 |
|
---|
10 | import os
|
---|
11 | import math
|
---|
12 | import time
|
---|
13 |
|
---|
14 | if os.name=="nt" or "FORCE_PYGTK" in os.environ:
|
---|
15 | print "Using PyGTK"
|
---|
16 | pygobject = False
|
---|
17 | import pygtk
|
---|
18 | import gtk
|
---|
19 | import gobject
|
---|
20 | else:
|
---|
21 | print "Using PyGObject"
|
---|
22 | pygobject = True
|
---|
23 | from gi.repository import Gtk as gtk
|
---|
24 | from gi.repository import GObject as gobject
|
---|
25 |
|
---|
26 | import cairo
|
---|
27 |
|
---|
28 | acftTypes = [ ("Boeing 737-600", const.AIRCRAFT_B736),
|
---|
29 | ("Boeing 737-700", const.AIRCRAFT_B737),
|
---|
30 | ("Boeing 737-800", const.AIRCRAFT_B738),
|
---|
31 | ("Bombardier Dash 8-Q400", const.AIRCRAFT_DH8D),
|
---|
32 | ("Boeing 737-300", const.AIRCRAFT_B733),
|
---|
33 | ("Boeing 737-400", const.AIRCRAFT_B734),
|
---|
34 | ("Boeing 737-500", const.AIRCRAFT_B735),
|
---|
35 | ("Boeing 767-200", const.AIRCRAFT_B762),
|
---|
36 | ("Boeing 767-300", const.AIRCRAFT_B763),
|
---|
37 | ("Bombardier CRJ200", const.AIRCRAFT_CRJ2),
|
---|
38 | ("Fokker 70", const.AIRCRAFT_F70),
|
---|
39 | ("Lisunov Li-2", const.AIRCRAFT_DC3),
|
---|
40 | ("Tupolev Tu-134", const.AIRCRAFT_T134),
|
---|
41 | ("Tupolev Tu-154", const.AIRCRAFT_T154),
|
---|
42 | ("Yakovlev Yak-40", const.AIRCRAFT_YK40) ]
|
---|
43 |
|
---|
44 | class GUI(fs.ConnectionListener):
|
---|
45 | """The main GUI class."""
|
---|
46 | def __init__(self):
|
---|
47 | """Construct the GUI."""
|
---|
48 | self._connecting = False
|
---|
49 | self._connected = False
|
---|
50 | self._logger = logger.Logger(output = self)
|
---|
51 | self._flight = None
|
---|
52 | self._simulator = None
|
---|
53 |
|
---|
54 | def build(self):
|
---|
55 | """Build the GUI."""
|
---|
56 | win = gtk.Window()
|
---|
57 | win.set_title("MAVA Logger X " + const.VERSION)
|
---|
58 | win.connect("delete-event", gtk.main_quit)
|
---|
59 |
|
---|
60 | mainVBox = gtk.VBox()
|
---|
61 | win.add(mainVBox)
|
---|
62 |
|
---|
63 | setupFrame = self._buildSetupFrame()
|
---|
64 | setupFrame.set_border_width(8)
|
---|
65 | mainVBox.pack_start(setupFrame, False, False, 0)
|
---|
66 |
|
---|
67 | dataFrame = self._buildDataFrame()
|
---|
68 | dataFrame.set_border_width(8)
|
---|
69 | mainVBox.pack_start(dataFrame, False, False, 0)
|
---|
70 |
|
---|
71 | logFrame = self._buildLogFrame()
|
---|
72 | logFrame.set_border_width(8)
|
---|
73 | mainVBox.pack_start(logFrame, True, True, 0)
|
---|
74 |
|
---|
75 | win.show_all()
|
---|
76 |
|
---|
77 | def run(self):
|
---|
78 | """Run the GUI."""
|
---|
79 | gtk.main()
|
---|
80 | if self._flight is not None:
|
---|
81 | simulator = self._flight.simulator
|
---|
82 | simulator.stopMonitoring()
|
---|
83 | simulator.disconnect()
|
---|
84 |
|
---|
85 | def connected(self, fsType, descriptor):
|
---|
86 | """Called when we have connected to the simulator."""
|
---|
87 | self._connected = True
|
---|
88 | self._updateConnState()
|
---|
89 | self._logger.untimedMessage("Connected to the simulator %s" % (descriptor,))
|
---|
90 |
|
---|
91 | def disconnected(self):
|
---|
92 | """Called when we have disconnected from the simulator."""
|
---|
93 | self._connected = False
|
---|
94 | self._updateConnState()
|
---|
95 | self._logger.untimedMessage("Disconnected from the simulator")
|
---|
96 |
|
---|
97 | def write(self, msg):
|
---|
98 | """Write the given message to the log."""
|
---|
99 | gobject.idle_add(self._writeLog, msg)
|
---|
100 |
|
---|
101 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
102 | """Update the data."""
|
---|
103 | gobject.idle_add(self._setData, state)
|
---|
104 |
|
---|
105 | def _drawConnState(self, connStateArea, eventOrContext):
|
---|
106 | """Draw the connection state."""
|
---|
107 | context = eventOrContext if pygobject else connStateArea.window.cairo_create()
|
---|
108 |
|
---|
109 | if self._connecting:
|
---|
110 | if self._connected:
|
---|
111 | context.set_source_rgb(0.0, 1.0, 0.0)
|
---|
112 | else:
|
---|
113 | context.set_source_rgb(1.0, 0.0, 0.0)
|
---|
114 | else:
|
---|
115 | context.set_source_rgb(0.75, 0.75, 0.75)
|
---|
116 |
|
---|
117 | width = connStateArea.get_allocated_width() if pygobject \
|
---|
118 | else connStateArea.allocation.width
|
---|
119 | height = connStateArea.get_allocated_height() if pygobject \
|
---|
120 | else connStateArea.allocation.height
|
---|
121 | context.arc(width/2, height/2, 8, 0, 2*math.pi)
|
---|
122 |
|
---|
123 | context.fill()
|
---|
124 |
|
---|
125 | def _updateConnState(self):
|
---|
126 | """Initiate the updating of the connection state icon."""
|
---|
127 | self._connStateArea.queue_draw()
|
---|
128 |
|
---|
129 | def _connectToggled(self, button):
|
---|
130 | """Callback for the connection button."""
|
---|
131 | if self._connectButton.get_active():
|
---|
132 | self._flight = flight.Flight(self._logger)
|
---|
133 |
|
---|
134 | acftListModel = self._acftList.get_model()
|
---|
135 | self._flight.aircraftType = \
|
---|
136 | acftListModel[self._acftList.get_active()][1]
|
---|
137 | self._flight.aircraft = acft.Aircraft.create(self._flight)
|
---|
138 | self._flight.aircraft._checkers.append(self)
|
---|
139 |
|
---|
140 | self._flight.cruiseAltitude = self._flSpinButton.get_value_as_int() * 100
|
---|
141 |
|
---|
142 | self._flight.zfw = self._zfwSpinButton.get_value_as_int()
|
---|
143 |
|
---|
144 | print self._flight.aircraft, self._flight.cruiseAltitude, self._flight.zfw
|
---|
145 |
|
---|
146 | if self._simulator is None:
|
---|
147 | self._simulator = fs.createSimulator(const.SIM_MSFS9, self)
|
---|
148 |
|
---|
149 | self._flight.simulator = self._simulator
|
---|
150 |
|
---|
151 | self._connecting = True
|
---|
152 | self._simulator.connect(self._flight.aircraft)
|
---|
153 | self._simulator.startMonitoring()
|
---|
154 | else:
|
---|
155 | self._connecting = False
|
---|
156 | self._simulator.stopMonitoring()
|
---|
157 | self._simulator.disconnect()
|
---|
158 | self._flight = None
|
---|
159 |
|
---|
160 | self._updateConnState()
|
---|
161 |
|
---|
162 | def _buildSetupFrame(self):
|
---|
163 | """Build the setup frame."""
|
---|
164 | setupFrame = gtk.Frame(label = "Setup")
|
---|
165 |
|
---|
166 | frameAlignment = gtk.Alignment(xalign = 0.5)
|
---|
167 |
|
---|
168 | frameAlignment.set_padding(padding_top = 4, padding_bottom = 10,
|
---|
169 | padding_left = 16, padding_right = 16)
|
---|
170 |
|
---|
171 | setupFrame.add(frameAlignment)
|
---|
172 |
|
---|
173 | setupBox = gtk.HBox()
|
---|
174 | frameAlignment.add(setupBox)
|
---|
175 |
|
---|
176 | # self._fs9Button = gtk.RadioButton(label = "FS9")
|
---|
177 | # self._fs9Button.set_tooltip_text("Use MS Flight Simulator 2004")
|
---|
178 | # setupBox.pack_start(self._fs9Button, False, False, 0)
|
---|
179 |
|
---|
180 | # self._fsxButton = gtk.RadioButton(group = self._fs9Button, label = "FSX")
|
---|
181 | # self._fsxButton.set_tooltip_text("Use MS Flight Simulator X")
|
---|
182 | # setupBox.pack_start(self._fsxButton, False, False, 0)
|
---|
183 |
|
---|
184 | # setupBox.pack_start(gtk.VSeparator(), False, False, 8)
|
---|
185 |
|
---|
186 | alignment = gtk.Alignment(yalign = 0.5)
|
---|
187 | alignment.set_padding(padding_top = 0, padding_bottom = 0,
|
---|
188 | padding_left = 0, padding_right = 16)
|
---|
189 | alignment.add(gtk.Label("Aicraft:"))
|
---|
190 | setupBox.pack_start(alignment, False, False, 0)
|
---|
191 |
|
---|
192 | acftListModel = gtk.ListStore(str, int)
|
---|
193 | for (name, type) in acftTypes:
|
---|
194 | acftListModel.append([name, type])
|
---|
195 |
|
---|
196 | self._acftList = gtk.ComboBox(model = acftListModel)
|
---|
197 | renderer_text = gtk.CellRendererText()
|
---|
198 | self._acftList.pack_start(renderer_text, True)
|
---|
199 | self._acftList.add_attribute(renderer_text, "text", 0)
|
---|
200 | self._acftList.set_active(0)
|
---|
201 | self._acftList.set_tooltip_text("Select the type of the aircraft used for the flight.")
|
---|
202 |
|
---|
203 | setupBox.pack_start(self._acftList, True, True, 0)
|
---|
204 |
|
---|
205 | setupBox.pack_start(gtk.VSeparator(), False, False, 8)
|
---|
206 |
|
---|
207 | alignment = gtk.Alignment(yalign = 0.5)
|
---|
208 | alignment.set_padding(padding_top = 0, padding_bottom = 0,
|
---|
209 | padding_left = 0, padding_right = 16)
|
---|
210 | alignment.add(gtk.Label("Cruise FL:"))
|
---|
211 | setupBox.pack_start(alignment, False, False, 0)
|
---|
212 |
|
---|
213 | self._flSpinButton = gtk.SpinButton()
|
---|
214 | self._flSpinButton.set_increments(step = 10, page = 100)
|
---|
215 | self._flSpinButton.set_range(min = 0, max = 500)
|
---|
216 | self._flSpinButton.set_value(240)
|
---|
217 | self._flSpinButton.set_tooltip_text("The cruise flight level.")
|
---|
218 | self._flSpinButton.set_numeric(True)
|
---|
219 |
|
---|
220 | setupBox.pack_start(self._flSpinButton, False, False, 0)
|
---|
221 |
|
---|
222 | setupBox.pack_start(gtk.VSeparator(), False, False, 8)
|
---|
223 |
|
---|
224 | alignment = gtk.Alignment(yalign = 0.5)
|
---|
225 | alignment.set_padding(padding_top = 0, padding_bottom = 0,
|
---|
226 | padding_left = 0, padding_right = 16)
|
---|
227 | alignment.add(gtk.Label("ZFW:"))
|
---|
228 | setupBox.pack_start(alignment, False, False, 0)
|
---|
229 |
|
---|
230 | self._zfwSpinButton = gtk.SpinButton()
|
---|
231 | self._zfwSpinButton.set_increments(step = 100, page = 1000)
|
---|
232 | self._zfwSpinButton.set_range(min = 0, max = 500000)
|
---|
233 | self._zfwSpinButton.set_value(50000)
|
---|
234 | self._zfwSpinButton.set_tooltip_text("The Zero Fuel Weight for the flight in kgs")
|
---|
235 | self._zfwSpinButton.set_numeric(True)
|
---|
236 |
|
---|
237 | setupBox.pack_start(self._zfwSpinButton, False, False, 0)
|
---|
238 |
|
---|
239 | setupBox.pack_start(gtk.VSeparator(), False, False, 8)
|
---|
240 |
|
---|
241 | self._connectButton = gtk.ToggleButton(label = "Connect")
|
---|
242 | self._connectButton.set_tooltip_text("Push to connect to Flight Simulator and start a new flight.\n"
|
---|
243 | "Push again to disconnect from FS.")
|
---|
244 |
|
---|
245 | self._connectButton.connect("toggled", self._connectToggled)
|
---|
246 |
|
---|
247 | setupBox.pack_start(self._connectButton, False, False, 0)
|
---|
248 |
|
---|
249 | setupBox.pack_start(gtk.VSeparator(), False, False, 8)
|
---|
250 |
|
---|
251 | self._connStateArea = gtk.DrawingArea()
|
---|
252 | self._connStateArea.set_size_request(16, 16)
|
---|
253 | self._connStateArea.set_tooltip_markup('The state of the connection.\n'
|
---|
254 | '<span foreground="grey">Grey</span> means idle.\n'
|
---|
255 | '<span foreground="red">Red</span> means trying to connect.\n'
|
---|
256 | '<span foreground="green">Green</span> means connected.')
|
---|
257 |
|
---|
258 | if pygobject:
|
---|
259 | self._connStateArea.connect("draw", self._drawConnState)
|
---|
260 | else:
|
---|
261 | self._connStateArea.connect("expose_event", self._drawConnState)
|
---|
262 |
|
---|
263 | alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5)
|
---|
264 | alignment.add(self._connStateArea)
|
---|
265 |
|
---|
266 | setupBox.pack_start(alignment, False, False, 8)
|
---|
267 |
|
---|
268 | return setupFrame
|
---|
269 |
|
---|
270 | def _createLabeledEntry(self, label, width = 8, xalign = 1.0):
|
---|
271 | """Create a labeled entry.
|
---|
272 |
|
---|
273 | Return a tuple consisting of:
|
---|
274 | - the box
|
---|
275 | - the entry."""
|
---|
276 |
|
---|
277 | alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5, xscale = 1.0)
|
---|
278 | alignment.set_padding(padding_top = 0, padding_bottom = 0,
|
---|
279 | padding_left = 0, padding_right = 16)
|
---|
280 | alignment.add(gtk.Label(label))
|
---|
281 |
|
---|
282 | entry = gtk.Entry()
|
---|
283 | entry.set_editable(False)
|
---|
284 | entry.set_width_chars(width)
|
---|
285 | entry.set_max_length(width)
|
---|
286 | entry.set_alignment(xalign)
|
---|
287 |
|
---|
288 | return (alignment, entry)
|
---|
289 |
|
---|
290 | def _buildDataFrame(self):
|
---|
291 | """Build the frame for the data."""
|
---|
292 | dataFrame = gtk.Frame(label = "Data")
|
---|
293 |
|
---|
294 | frameAlignment = gtk.Alignment(xscale = 1.0, yscale = 1.0)
|
---|
295 |
|
---|
296 | frameAlignment.set_padding(padding_top = 4, padding_bottom = 10,
|
---|
297 | padding_left = 16, padding_right = 16)
|
---|
298 |
|
---|
299 | table = gtk.Table(rows = 7, columns = 12)
|
---|
300 | table.set_homogeneous(False)
|
---|
301 | table.set_row_spacings(4)
|
---|
302 | table.set_col_spacings(8)
|
---|
303 |
|
---|
304 | (label, self._timestamp) = self._createLabeledEntry("Time:")
|
---|
305 | table.attach(label, 0, 1, 0, 1)
|
---|
306 | table.attach(self._timestamp, 1, 2, 0, 1)
|
---|
307 |
|
---|
308 | self._paused = gtk.Label("PAUSED")
|
---|
309 | table.attach(self._paused, 2, 4, 0, 1)
|
---|
310 |
|
---|
311 | self._trickMode = gtk.Label("TRICKMODE")
|
---|
312 | table.attach(self._trickMode, 4, 6, 0, 1, xoptions = 0)
|
---|
313 |
|
---|
314 | self._overspeed = gtk.Label("OVERSPEED")
|
---|
315 | table.attach(self._overspeed, 6, 8, 0, 1)
|
---|
316 |
|
---|
317 | self._stalled = gtk.Label("STALLED")
|
---|
318 | table.attach(self._stalled, 8, 10, 0, 1)
|
---|
319 |
|
---|
320 | self._onTheGround = gtk.Label("ONTHEGROUND")
|
---|
321 | table.attach(self._onTheGround, 10, 12, 0, 1)
|
---|
322 |
|
---|
323 | (label, self._zfw) = self._createLabeledEntry("ZFW:", 6)
|
---|
324 | table.attach(label, 0, 1, 1, 2)
|
---|
325 | table.attach(self._zfw, 1, 2, 1, 2)
|
---|
326 |
|
---|
327 | (label, self._grossWeight) = self._createLabeledEntry("Weight:", 6)
|
---|
328 | table.attach(label, 2, 3, 1, 2)
|
---|
329 | table.attach(self._grossWeight, 3, 4, 1, 2)
|
---|
330 |
|
---|
331 | (label, self._heading) = self._createLabeledEntry("Heading:", 3)
|
---|
332 | table.attach(label, 4, 5, 1, 2)
|
---|
333 | table.attach(self._heading, 5, 6, 1, 2)
|
---|
334 |
|
---|
335 | (label, self._pitch) = self._createLabeledEntry("Pitch:", 3)
|
---|
336 | table.attach(label, 6, 7, 1, 2)
|
---|
337 | table.attach(self._pitch, 7, 8, 1, 2)
|
---|
338 |
|
---|
339 | (label, self._bank) = self._createLabeledEntry("Bank:", 3)
|
---|
340 | table.attach(label, 8, 9, 1, 2)
|
---|
341 | table.attach(self._bank, 9, 10, 1, 2)
|
---|
342 |
|
---|
343 | (label, self._vs) = self._createLabeledEntry("VS:", 5)
|
---|
344 | table.attach(label, 10, 11, 1, 2)
|
---|
345 | table.attach(self._vs, 11, 12, 1, 2)
|
---|
346 |
|
---|
347 | (label, self._ias) = self._createLabeledEntry("IAS:", 4)
|
---|
348 | table.attach(label, 0, 1, 2, 3)
|
---|
349 | table.attach(self._ias, 1, 2, 2, 3)
|
---|
350 |
|
---|
351 | (label, self._mach) = self._createLabeledEntry("Mach:", 4)
|
---|
352 | table.attach(label, 2, 3, 2, 3)
|
---|
353 | table.attach(self._mach, 3, 4, 2, 3)
|
---|
354 |
|
---|
355 | (label, self._groundSpeed) = self._createLabeledEntry("GS:", 4)
|
---|
356 | table.attach(label, 4, 5, 2, 3)
|
---|
357 | table.attach(self._groundSpeed, 5, 6, 2, 3)
|
---|
358 |
|
---|
359 | (label, self._radioAltitude) = self._createLabeledEntry("Radio alt.:", 4)
|
---|
360 | table.attach(label, 6, 7, 2, 3)
|
---|
361 | table.attach(self._radioAltitude, 7, 8, 2, 3)
|
---|
362 |
|
---|
363 | (label, self._altitude) = self._createLabeledEntry("Altitude:", 4)
|
---|
364 | table.attach(label, 8, 9, 2, 3)
|
---|
365 | table.attach(self._altitude, 9, 10, 2, 3)
|
---|
366 |
|
---|
367 | (label, self._gLoad) = self._createLabeledEntry("G-Load:", 4)
|
---|
368 | table.attach(label, 10, 11, 2, 3)
|
---|
369 | table.attach(self._gLoad, 11, 12, 2, 3)
|
---|
370 |
|
---|
371 | (label, self._flapsSet) = self._createLabeledEntry("Flaps set:", 2)
|
---|
372 | table.attach(label, 0, 1, 3, 4)
|
---|
373 | table.attach(self._flapsSet, 1, 2, 3, 4)
|
---|
374 |
|
---|
375 | (label, self._flaps) = self._createLabeledEntry("Flaps:", 2)
|
---|
376 | table.attach(label, 2, 3, 3, 4)
|
---|
377 | table.attach(self._flaps, 3, 4, 3, 4)
|
---|
378 |
|
---|
379 | (label, self._altimeter) = self._createLabeledEntry("Altimeter:", 4)
|
---|
380 | table.attach(label, 4, 5, 3, 4)
|
---|
381 | table.attach(self._altimeter, 5, 6, 3, 4)
|
---|
382 |
|
---|
383 | (label, self._squawk) = self._createLabeledEntry("Squawk:", 4)
|
---|
384 | table.attach(label, 6, 7, 3, 4)
|
---|
385 | table.attach(self._squawk, 7, 8, 3, 4)
|
---|
386 |
|
---|
387 | (label, self._nav1) = self._createLabeledEntry("NAV1:", 5)
|
---|
388 | table.attach(label, 8, 9, 3, 4)
|
---|
389 | table.attach(self._nav1, 9, 10, 3, 4)
|
---|
390 |
|
---|
391 | (label, self._nav2) = self._createLabeledEntry("NAV2:", 5)
|
---|
392 | table.attach(label, 10, 11, 3, 4)
|
---|
393 | table.attach(self._nav2, 11, 12, 3, 4)
|
---|
394 |
|
---|
395 | (label, self._fuel) = self._createLabeledEntry("Fuel:", 20, xalign = 0.0)
|
---|
396 | table.attach(label, 0, 1, 4, 5)
|
---|
397 | table.attach(self._fuel, 1, 4, 4, 5)
|
---|
398 |
|
---|
399 | (label, self._n1) = self._createLabeledEntry("N1/RPM:", 20, xalign = 0.0)
|
---|
400 | table.attach(label, 4, 5, 4, 5)
|
---|
401 | table.attach(self._n1, 5, 8, 4, 5)
|
---|
402 |
|
---|
403 | (label, self._reverser) = self._createLabeledEntry("Reverser:", 20, xalign = 0.0)
|
---|
404 | table.attach(label, 8, 9, 4, 5)
|
---|
405 | table.attach(self._reverser, 9, 12, 4, 5)
|
---|
406 |
|
---|
407 | self._navLightsOn = gtk.Label("NAV")
|
---|
408 | table.attach(self._navLightsOn, 0, 1, 5, 6)
|
---|
409 |
|
---|
410 | self._antiCollisionLightsOn = gtk.Label("ANTICOLLISION")
|
---|
411 | table.attach(self._antiCollisionLightsOn, 1, 3, 5, 6)
|
---|
412 |
|
---|
413 | self._strobeLightsOn = gtk.Label("STROBE")
|
---|
414 | table.attach(self._strobeLightsOn, 3, 4, 5, 6)
|
---|
415 |
|
---|
416 | self._landingLightsOn = gtk.Label("LANDING")
|
---|
417 | table.attach(self._landingLightsOn, 4, 5, 5, 6)
|
---|
418 |
|
---|
419 | self._pitotHeatOn = gtk.Label("PITOT HEAT")
|
---|
420 | table.attach(self._pitotHeatOn, 5, 7, 5, 6)
|
---|
421 |
|
---|
422 | self._parking = gtk.Label("PARKING")
|
---|
423 | table.attach(self._parking, 7, 8, 5, 6)
|
---|
424 |
|
---|
425 | self._gearsDown = gtk.Label("GEARS DOWN")
|
---|
426 | table.attach(self._gearsDown, 8, 10, 5, 6)
|
---|
427 |
|
---|
428 | self._spoilersArmed = gtk.Label("SPOILERS ARMED")
|
---|
429 | table.attach(self._spoilersArmed, 10, 12, 5, 6)
|
---|
430 |
|
---|
431 | (label, self._spoilersExtension) = self._createLabeledEntry("Spoilers:", 3)
|
---|
432 | table.attach(label, 0, 1, 6, 7)
|
---|
433 | table.attach(self._spoilersExtension, 1, 2, 6, 7)
|
---|
434 |
|
---|
435 | (label, self._windSpeed) = self._createLabeledEntry("Wind speed:", 3)
|
---|
436 | table.attach(label, 2, 3, 6, 7)
|
---|
437 | table.attach(self._windSpeed, 3, 4, 6, 7)
|
---|
438 |
|
---|
439 | (label, self._windDirection) = self._createLabeledEntry("Wind from:", 3)
|
---|
440 | table.attach(label, 4, 5, 6, 7)
|
---|
441 | table.attach(self._windDirection, 5, 6, 6, 7)
|
---|
442 |
|
---|
443 | frameAlignment.add(table)
|
---|
444 |
|
---|
445 | dataFrame.add(frameAlignment)
|
---|
446 |
|
---|
447 | self._setData()
|
---|
448 |
|
---|
449 | return dataFrame
|
---|
450 |
|
---|
451 | def _setData(self, aircraftState = None):
|
---|
452 | """Set the data.
|
---|
453 |
|
---|
454 | If aircraftState is None, everything will be set to its default."""
|
---|
455 | if aircraftState is None:
|
---|
456 | self._timestamp.set_text("--:--:--")
|
---|
457 | self._paused.set_sensitive(False)
|
---|
458 | self._trickMode.set_sensitive(False)
|
---|
459 | self._overspeed.set_sensitive(False)
|
---|
460 | self._stalled.set_sensitive(False)
|
---|
461 | self._onTheGround.set_sensitive(False)
|
---|
462 | self._zfw.set_text("-")
|
---|
463 | self._grossWeight.set_text("-")
|
---|
464 | self._heading.set_text("-")
|
---|
465 | self._pitch.set_text("-")
|
---|
466 | self._bank.set_text("-")
|
---|
467 | self._vs.set_text("-")
|
---|
468 | self._ias.set_text("-")
|
---|
469 | self._mach.set_text("-")
|
---|
470 | self._groundSpeed.set_text("-")
|
---|
471 | self._radioAltitude.set_text("-")
|
---|
472 | self._altitude.set_text("-")
|
---|
473 | self._gLoad.set_text("-")
|
---|
474 | self._flapsSet.set_text("-")
|
---|
475 | self._flaps.set_text("-")
|
---|
476 | self._altimeter.set_text("-")
|
---|
477 | self._squawk.set_text("-")
|
---|
478 | self._nav1.set_text("-")
|
---|
479 | self._nav2.set_text("-")
|
---|
480 | self._fuel.set_text("-")
|
---|
481 | self._n1.set_text("-")
|
---|
482 | self._reverser.set_text("-")
|
---|
483 | self._navLightsOn.set_sensitive(False)
|
---|
484 | self._antiCollisionLightsOn.set_sensitive(False)
|
---|
485 | self._strobeLightsOn.set_sensitive(False)
|
---|
486 | self._landingLightsOn.set_sensitive(False)
|
---|
487 | self._pitotHeatOn.set_sensitive(False)
|
---|
488 | self._parking.set_sensitive(False)
|
---|
489 | self._gearsDown.set_sensitive(False)
|
---|
490 | self._spoilersArmed.set_sensitive(False)
|
---|
491 | self._spoilersExtension.set_text("-")
|
---|
492 | self._windSpeed.set_text("-")
|
---|
493 | self._windDirection.set_text("-")
|
---|
494 | else:
|
---|
495 | self._timestamp.set_text(time.strftime("%H:%M:%S",
|
---|
496 | time.gmtime(aircraftState.timestamp)))
|
---|
497 | self._paused.set_sensitive(aircraftState.paused)
|
---|
498 | self._trickMode.set_sensitive(aircraftState.trickMode)
|
---|
499 | self._overspeed.set_sensitive(aircraftState.overspeed)
|
---|
500 | self._stalled.set_sensitive(aircraftState.stalled)
|
---|
501 | self._onTheGround.set_sensitive(aircraftState.onTheGround)
|
---|
502 | self._zfw.set_text("%.0f" % (aircraftState.zfw,))
|
---|
503 | self._grossWeight.set_text("%.0f" % (aircraftState.grossWeight,))
|
---|
504 | self._heading.set_text("%03.0f" % (aircraftState.heading,))
|
---|
505 | self._pitch.set_text("%.0f" % (aircraftState.pitch,))
|
---|
506 | self._bank.set_text("%.0f" % (aircraftState.bank,))
|
---|
507 | self._vs.set_text("%.0f" % (aircraftState.vs,))
|
---|
508 | self._ias.set_text("%.0f" % (aircraftState.ias,))
|
---|
509 | self._mach.set_text("%.2f" % (aircraftState.mach,))
|
---|
510 | self._groundSpeed.set_text("%.0f" % (aircraftState.groundSpeed,))
|
---|
511 | self._radioAltitude.set_text("%.0f" % (aircraftState.radioAltitude,))
|
---|
512 | self._altitude.set_text("%.0f" % (aircraftState.altitude,))
|
---|
513 | self._gLoad.set_text("%.2f" % (aircraftState.gLoad,))
|
---|
514 | self._flapsSet.set_text("%.0f" % (aircraftState.flapsSet,))
|
---|
515 | self._flaps.set_text("%.0f" % (aircraftState.flaps,))
|
---|
516 | self._altimeter.set_text("%.0f" % (aircraftState.altimeter,))
|
---|
517 | self._squawk.set_text(aircraftState.squawk)
|
---|
518 | self._nav1.set_text(aircraftState.nav1)
|
---|
519 | self._nav2.set_text(aircraftState.nav2)
|
---|
520 |
|
---|
521 | fuelStr = ""
|
---|
522 | for fuel in aircraftState.fuel:
|
---|
523 | if fuelStr: fuelStr += ", "
|
---|
524 | fuelStr += "%.0f" % (fuel,)
|
---|
525 | self._fuel.set_text(fuelStr)
|
---|
526 |
|
---|
527 | if hasattr(aircraftState, "n1"):
|
---|
528 | n1Str = ""
|
---|
529 | for n1 in aircraftState.n1:
|
---|
530 | if n1Str: n1Str += ", "
|
---|
531 | n1Str += "%.0f" % (n1,)
|
---|
532 | elif hasattr(aircraftState, "rpm"):
|
---|
533 | n1Str = ""
|
---|
534 | for rpm in aircraftState.rpm:
|
---|
535 | if n1Str: n1Str += ", "
|
---|
536 | n1Str += "%.0f" % (rpm,)
|
---|
537 | else:
|
---|
538 | n1Str = "-"
|
---|
539 | self._n1.set_text(n1Str)
|
---|
540 |
|
---|
541 | reverserStr = ""
|
---|
542 | for reverser in aircraftState.reverser:
|
---|
543 | if reverserStr: reverserStr += ", "
|
---|
544 | reverserStr += "ON" if reverser else "OFF"
|
---|
545 | self._reverser.set_text(reverserStr)
|
---|
546 |
|
---|
547 | self._navLightsOn.set_sensitive(aircraftState.navLightsOn)
|
---|
548 | self._antiCollisionLightsOn.set_sensitive(aircraftState.antiCollisionLightsOn)
|
---|
549 | self._strobeLightsOn.set_sensitive(aircraftState.strobeLightsOn)
|
---|
550 | self._landingLightsOn.set_sensitive(aircraftState.landingLightsOn)
|
---|
551 | self._pitotHeatOn.set_sensitive(aircraftState.pitotHeatOn)
|
---|
552 | self._parking.set_sensitive(aircraftState.parking)
|
---|
553 | self._gearsDown.set_sensitive(aircraftState.gearsDown)
|
---|
554 | self._spoilersArmed.set_sensitive(aircraftState.spoilersArmed)
|
---|
555 | self._spoilersExtension.set_text("%.0f" % (aircraftState.spoilersExtension,))
|
---|
556 | self._windSpeed.set_text("%.0f" % (aircraftState.windSpeed,))
|
---|
557 | self._windDirection.set_text("%03.0f" % (aircraftState.windDirection,))
|
---|
558 |
|
---|
559 | def _buildLogFrame(self):
|
---|
560 | """Build the frame for the log."""
|
---|
561 | logFrame = gtk.Frame(label = "Log")
|
---|
562 |
|
---|
563 | frameAlignment = gtk.Alignment(xscale = 1.0, yscale = 1.0)
|
---|
564 |
|
---|
565 | frameAlignment.set_padding(padding_top = 4, padding_bottom = 10,
|
---|
566 | padding_left = 16, padding_right = 16)
|
---|
567 |
|
---|
568 | logFrame.add(frameAlignment)
|
---|
569 |
|
---|
570 | logScroller = gtk.ScrolledWindow()
|
---|
571 | self._logView = gtk.TextView()
|
---|
572 | self._logView.set_editable(False)
|
---|
573 | logScroller.add(self._logView)
|
---|
574 |
|
---|
575 | logBox = gtk.VBox()
|
---|
576 | logBox.pack_start(logScroller, True, True, 0)
|
---|
577 | logBox.set_size_request(-1, 200)
|
---|
578 |
|
---|
579 | frameAlignment.add(logBox)
|
---|
580 |
|
---|
581 | return logFrame
|
---|
582 |
|
---|
583 | def _writeLog(self, msg):
|
---|
584 | """Write the given message to the log."""
|
---|
585 | buffer = self._logView.get_buffer()
|
---|
586 | buffer.insert(buffer.get_end_iter(), msg)
|
---|
587 | self._logView.scroll_mark_onscreen(buffer.get_insert())
|
---|
588 |
|
---|
589 | def main():
|
---|
590 | """The main operation of the program."""
|
---|
591 | gobject.threads_init()
|
---|
592 | gui = GUI()
|
---|
593 | gui.build()
|
---|
594 | gui.run()
|
---|
595 |
|
---|
596 | if __name__ == "__main__":
|
---|
597 | main()
|
---|
598 |
|
---|
599 |
|
---|