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