source: src/mlx/gui/gui.py@ 38:08f7e6592452

Last change on this file since 38:08f7e6592452 was 38:08f7e6592452, checked in by István Váradi <ivaradi@…>, 11 years ago

The status icon is now hidden properly when the program quits, and made restarting nicer

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