source: src/mlx/gui/gui.py@ 35:d32890325137

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

Hiding after minimizing seems to work now

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