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