source: src/mlx/gui/gui.py@ 31:c9ed7a60bf3b

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

Various information about the flight is displayed in the status icon's tooltip or menu

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