source: src/mlx/gui/gui.py@ 36:f79362793664

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

Update seems to work

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