source: src/mlx/gui/monitor.py@ 335:db900a4a0930

Last change on this file since 335:db900a4a0930 was 334:7978a2496c31, checked in by István Váradi <ivaradi@…>, 12 years ago

#139: the transponder state is now queried and made available

File size: 14.1 KB
Line 
1
2from mlx.gui.common import *
3
4import mlx.const as const
5import mlx.util as util
6
7import time
8
9#------------------------------------------------------------------------------
10
11## @package mlx.gui.monitor
12#
13# The monitoring window
14#
15# The \ref MonitorWindow class is a window containing the data received from
16# the simulator by the logger.
17
18#------------------------------------------------------------------------------
19
20class MonitorWindow(gtk.Window):
21 """The window for the data monitor."""
22 def __init__(self, gui, iconDirectory):
23 """Construct the monitor window."""
24 super(MonitorWindow, self).__init__()
25
26 self._gui = gui
27
28 self.set_resizable(False)
29 self.set_title(WINDOW_TITLE_BASE + " - Data Monitor")
30 self.set_icon_from_file(os.path.join(iconDirectory, "logo.ico"))
31 self.connect("delete-event",
32 lambda a, b: self._gui.hideMonitorWindow())
33
34 alignment = gtk.Alignment(xscale = 1.0, yscale = 1.0)
35
36 alignment.set_padding(padding_top = 4, padding_bottom = 10,
37 padding_left = 16, padding_right = 16)
38
39 table = gtk.Table(rows = 7, columns = 12)
40 table.set_homogeneous(False)
41 table.set_row_spacings(4)
42 table.set_col_spacings(8)
43
44 (label, self._timestamp) = self._createLabeledEntry("Time:")
45 table.attach(label, 0, 1, 0, 1)
46 table.attach(self._timestamp, 1, 2, 0, 1)
47
48 self._paused = gtk.Label("PAUSED")
49 table.attach(self._paused, 2, 4, 0, 1)
50
51 self._trickMode = gtk.Label("TRICKMODE")
52 table.attach(self._trickMode, 4, 6, 0, 1, xoptions = 0)
53
54 self._overspeed = gtk.Label("OVERSPEED")
55 table.attach(self._overspeed, 6, 8, 0, 1)
56
57 self._stalled = gtk.Label("STALLED")
58 table.attach(self._stalled, 8, 10, 0, 1)
59
60 self._onTheGround = gtk.Label("ONTHEGROUND")
61 table.attach(self._onTheGround, 10, 12, 0, 1)
62
63 (label, self._zfw) = self._createLabeledEntry("ZFW:", 6)
64 table.attach(label, 0, 1, 1, 2)
65 table.attach(self._zfw, 1, 2, 1, 2)
66
67 (label, self._grossWeight) = self._createLabeledEntry("Weight:", 6)
68 table.attach(label, 2, 3, 1, 2)
69 table.attach(self._grossWeight, 3, 4, 1, 2)
70
71 (label, self._heading) = self._createLabeledEntry("Heading:", 3)
72 table.attach(label, 4, 5, 1, 2)
73 table.attach(self._heading, 5, 6, 1, 2)
74
75 (label, self._pitch) = self._createLabeledEntry("Pitch:", 3)
76 table.attach(label, 6, 7, 1, 2)
77 table.attach(self._pitch, 7, 8, 1, 2)
78
79 (label, self._bank) = self._createLabeledEntry("Bank:", 3)
80 table.attach(label, 8, 9, 1, 2)
81 table.attach(self._bank, 9, 10, 1, 2)
82
83 (label, self._vs) = self._createLabeledEntry("VS:", 13)
84 table.attach(label, 10, 11, 1, 2)
85 table.attach(self._vs, 11, 12, 1, 2)
86
87 (label, self._ias) = self._createLabeledEntry("IAS:", 11)
88 table.attach(label, 0, 1, 2, 3)
89 table.attach(self._ias, 1, 2, 2, 3)
90
91 (label, self._mach) = self._createLabeledEntry("Mach:", 4)
92 table.attach(label, 2, 3, 2, 3)
93 table.attach(self._mach, 3, 4, 2, 3)
94
95 (label, self._groundSpeed) = self._createLabeledEntry("GS:", 4)
96 table.attach(label, 4, 5, 2, 3)
97 table.attach(self._groundSpeed, 5, 6, 2, 3)
98
99 (label, self._radioAltitude) = self._createLabeledEntry("Radio alt.:", 6)
100 table.attach(label, 6, 7, 2, 3)
101 table.attach(self._radioAltitude, 7, 8, 2, 3)
102
103 (label, self._altitude) = self._createLabeledEntry("Altitude:", 6)
104 table.attach(label, 8, 9, 2, 3)
105 table.attach(self._altitude, 9, 10, 2, 3)
106
107 (label, self._gLoad) = self._createLabeledEntry("G-Load:", 4)
108 table.attach(label, 10, 11, 2, 3)
109 table.attach(self._gLoad, 11, 12, 2, 3)
110
111 (label, self._flapsSet) = self._createLabeledEntry("Flaps set:", 2)
112 table.attach(label, 0, 1, 3, 4)
113 table.attach(self._flapsSet, 1, 2, 3, 4)
114
115 (label, self._flaps) = self._createLabeledEntry("Flaps:", 2)
116 table.attach(label, 2, 3, 3, 4)
117 table.attach(self._flaps, 3, 4, 3, 4)
118
119 (label, self._altimeter) = self._createLabeledEntry("Altimeter:", 4)
120 table.attach(label, 4, 5, 3, 4)
121 table.attach(self._altimeter, 5, 6, 3, 4)
122
123 (label, self._squawk) = self._createLabeledEntry("Squawk:", 4)
124 table.attach(label, 6, 7, 3, 4)
125 table.attach(self._squawk, 7, 8, 3, 4)
126
127 (label, self._nav1) = self._createLabeledEntry("NAV1:", 5)
128 table.attach(label, 8, 9, 3, 4)
129 table.attach(self._nav1, 9, 10, 3, 4)
130
131 (label, self._nav2) = self._createLabeledEntry("NAV2:", 5)
132 table.attach(label, 10, 11, 3, 4)
133 table.attach(self._nav2, 11, 12, 3, 4)
134
135 (label, self._fuel) = self._createLabeledEntry("Fuel:", 40, xalign = 0.0)
136 table.attach(label, 0, 1, 4, 5)
137 table.attach(self._fuel, 1, 4, 4, 5)
138
139 (label, self._n1) = self._createLabeledEntry("N1/RPM:", 20, xalign = 0.0)
140 table.attach(label, 4, 5, 4, 5)
141 table.attach(self._n1, 5, 8, 4, 5)
142
143 (label, self._reverser) = self._createLabeledEntry("Reverser:", 20, xalign = 0.0)
144 table.attach(label, 8, 9, 4, 5)
145 table.attach(self._reverser, 9, 12, 4, 5)
146
147 self._navLightsOn = gtk.Label("NAV")
148 table.attach(self._navLightsOn, 0, 1, 5, 6)
149
150 self._antiCollisionLightsOn = gtk.Label("ANTICOLLISION")
151 table.attach(self._antiCollisionLightsOn, 1, 2, 5, 6)
152
153 self._strobeLightsOn = gtk.Label("STROBE")
154 table.attach(self._strobeLightsOn, 2, 3, 5, 6)
155
156 self._landingLightsOn = gtk.Label("LANDING")
157 table.attach(self._landingLightsOn, 3, 4, 5, 6)
158
159 self._pitotHeatOn = gtk.Label("PITOT HEAT")
160 table.attach(self._pitotHeatOn, 4, 5, 5, 6)
161
162 self._parking = gtk.Label("PARKING")
163 table.attach(self._parking, 5, 6, 5, 6)
164
165 self._gearControlDown = gtk.Label("GEAR LEVER DOWN")
166 table.attach(self._gearControlDown, 6, 8, 5, 6)
167
168 self._gearsDown = gtk.Label("GEARS DOWN")
169 table.attach(self._gearsDown, 8, 10, 5, 6)
170
171 self._spoilersArmed = gtk.Label("SPOILERS ARMED")
172 table.attach(self._spoilersArmed, 10, 12, 5, 6)
173
174 (label, self._spoilersExtension) = self._createLabeledEntry("Spoilers:", 3)
175 table.attach(label, 0, 1, 6, 7)
176 table.attach(self._spoilersExtension, 1, 2, 6, 7)
177
178 (label, self._windSpeed) = self._createLabeledEntry("Wind speed:", 3)
179 table.attach(label, 2, 3, 6, 7)
180 table.attach(self._windSpeed, 3, 4, 6, 7)
181
182 (label, self._windDirection) = self._createLabeledEntry("Wind from:", 3)
183 table.attach(label, 4, 5, 6, 7)
184 table.attach(self._windDirection, 5, 6, 6, 7)
185
186 (label, self._position) = self._createLabeledEntry("Position:", 25)
187 table.attach(label, 6, 7, 6, 7)
188 table.attach(self._position, 7, 10, 6, 7)
189
190 self._xpdrC = gtk.Label("XPDR CHARLIE")
191 table.attach(self._xpdrC, 10, 12, 6, 7)
192
193 alignment.add(table)
194
195 self.add(alignment)
196
197 self._previousState = None
198
199 self.setData()
200
201 def _createLabeledEntry(self, label, width = 8, xalign = 1.0):
202 """Create a labeled entry.
203
204 Return a tuple consisting of:
205 - the box
206 - the entry."""
207
208 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5, xscale = 1.0)
209 alignment.set_padding(padding_top = 0, padding_bottom = 0,
210 padding_left = 0, padding_right = 16)
211 alignment.add(gtk.Label(label))
212
213 entry = gtk.Entry()
214 entry.set_editable(False)
215 entry.set_width_chars(width)
216 entry.set_max_length(width)
217 entry.set_alignment(xalign)
218
219 return (alignment, entry)
220
221 def setData(self, aircraftState = None):
222 """Set the data.
223
224 If aircraftState is None, everything will be set to its default."""
225 if aircraftState is None:
226 self._timestamp.set_text("--:--:--")
227 self._paused.set_sensitive(False)
228 self._trickMode.set_sensitive(False)
229 self._overspeed.set_sensitive(False)
230 self._stalled.set_sensitive(False)
231 self._onTheGround.set_sensitive(False)
232 self._zfw.set_text("-")
233 self._grossWeight.set_text("-")
234 self._heading.set_text("-")
235 self._pitch.set_text("-")
236 self._bank.set_text("-")
237 self._vs.set_text("-")
238 self._ias.set_text("-")
239 self._mach.set_text("-")
240 self._groundSpeed.set_text("-")
241 self._radioAltitude.set_text("-")
242 self._altitude.set_text("-")
243 self._gLoad.set_text("-")
244 self._flapsSet.set_text("-")
245 self._flaps.set_text("-")
246 self._altimeter.set_text("-")
247 self._squawk.set_text("-")
248 self._nav1.set_text("-")
249 self._nav2.set_text("-")
250 self._fuel.set_text("-")
251 self._n1.set_text("-")
252 self._reverser.set_text("-")
253 self._navLightsOn.set_sensitive(False)
254 self._antiCollisionLightsOn.set_sensitive(False)
255 self._strobeLightsOn.set_sensitive(False)
256 self._landingLightsOn.set_text("LANDING")
257 self._landingLightsOn.set_sensitive(False)
258 self._pitotHeatOn.set_sensitive(False)
259 self._parking.set_sensitive(False)
260 self._gearControlDown.set_sensitive(False)
261 self._gearsDown.set_sensitive(False)
262 self._spoilersArmed.set_sensitive(False)
263 self._spoilersExtension.set_text("-")
264 self._windSpeed.set_text("-")
265 self._windDirection.set_text("-")
266 self._position.set_text("-")
267 self._xpdrC.set_sensitive(False)
268 else:
269 self._timestamp.set_text(time.strftime("%H:%M:%S",
270 time.gmtime(aircraftState.timestamp)))
271 self._paused.set_sensitive(aircraftState.paused)
272 self._trickMode.set_sensitive(aircraftState.trickMode)
273 self._overspeed.set_sensitive(aircraftState.overspeed)
274 self._stalled.set_sensitive(aircraftState.stalled)
275 self._onTheGround.set_sensitive(aircraftState.onTheGround)
276 self._zfw.set_text("%.0f" % (aircraftState.zfw,))
277 self._grossWeight.set_text("%.0f" % (aircraftState.grossWeight,))
278 self._heading.set_text("%03.0f" % (aircraftState.heading,))
279 self._pitch.set_text("%.0f" % (aircraftState.pitch,))
280 self._bank.set_text("%.0f" % (aircraftState.bank,))
281 self._vs.set_text("%.0f (%.0f)" % (aircraftState.vs,
282 aircraftState.smoothedVS))
283 self._ias.set_text("%.0f (%.0f)" % (aircraftState.ias,
284 aircraftState.smoothedIAS))
285 self._mach.set_text("%.2f" % (aircraftState.mach,))
286 self._groundSpeed.set_text("%.0f" % (aircraftState.groundSpeed,))
287 self._radioAltitude.set_text("%.0f" % (aircraftState.radioAltitude,))
288 self._altitude.set_text("%.0f" % (aircraftState.altitude,))
289 self._gLoad.set_text("%.2f" % (aircraftState.gLoad,))
290 self._flapsSet.set_text("%.0f" % (aircraftState.flapsSet,))
291 self._flaps.set_text("%.0f" % (aircraftState.flaps,))
292 self._altimeter.set_text("%.0f" % (aircraftState.altimeter,))
293 self._squawk.set_text(aircraftState.squawk)
294 self._nav1.set_text("-" if aircraftState.nav1 is None else aircraftState.nav1)
295 self._nav2.set_text("-" if aircraftState.nav2 is None else aircraftState.nav2)
296
297 fuelStr = ""
298 for (_tank, fuel) in aircraftState.fuel:
299 if fuelStr: fuelStr += ", "
300 fuelStr += "%.0f" % (fuel,)
301 self._fuel.set_text(fuelStr)
302
303 if aircraftState.n1 is not None:
304 n1Str = ""
305 for n1 in aircraftState.n1:
306 if n1Str: n1Str += ", "
307 n1Str += "%.0f" % (n1,)
308 elif aircraftState.rpm is not None:
309 n1Str = ""
310 for rpm in aircraftState.rpm:
311 if n1Str: n1Str += ", "
312 n1Str += "%.0f" % (rpm,)
313 else:
314 n1Str = "-"
315 self._n1.set_text(n1Str)
316
317 reverserStr = ""
318 for reverser in aircraftState.reverser:
319 if reverserStr: reverserStr += ", "
320 reverserStr += "ON" if reverser else "OFF"
321 self._reverser.set_text(reverserStr)
322
323 self._navLightsOn.set_sensitive(aircraftState.navLightsOn)
324 self._antiCollisionLightsOn.set_sensitive(aircraftState.antiCollisionLightsOn)
325 self._strobeLightsOn.set_sensitive(aircraftState.strobeLightsOn)
326
327 if self._previousState is None or \
328 ((self._previousState.landingLightsOn is None)!=
329 (aircraftState.landingLightsOn is None)):
330 if aircraftState.landingLightsOn is None:
331 self._landingLightsOn.set_markup('<span strikethrough="true">LANDING</span>')
332 else:
333 self._landingLightsOn.set_text("LANDING")
334 self._landingLightsOn.set_sensitive(aircraftState.landingLightsOn is True)
335
336 self._pitotHeatOn.set_sensitive(aircraftState.pitotHeatOn)
337 self._parking.set_sensitive(aircraftState.parking)
338 self._gearControlDown.set_sensitive(aircraftState.gearControlDown)
339 self._gearsDown.set_sensitive(aircraftState.gearsDown)
340 self._spoilersArmed.set_sensitive(aircraftState.spoilersArmed)
341 self._spoilersExtension.set_text("%.0f" % (aircraftState.spoilersExtension,))
342 self._windSpeed.set_text("%.0f" % (aircraftState.windSpeed,))
343 self._windDirection.set_text("%03.0f" % (aircraftState.windDirection,))
344 self._position.set_text(util.getCoordinateString((aircraftState.latitude,
345 aircraftState.longitude)))
346 self._xpdrC.set_sensitive(aircraftState.xpdrC)
347
348#------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.