source: src/mlx/gui/gui.py@ 33:a9150c8d2767

Last change on this file since 33:a9150c8d2767 was 32:46c1a12f72d1, checked in by István Váradi <ivaradi@…>, 13 years ago

Implemented the status bar.

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