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