[28] | 1 | # The main file for the GUI
|
---|
| 2 |
|
---|
[29] | 3 | from statusicon import StatusIcon
|
---|
[32] | 4 | from statusbar import Statusbar
|
---|
[90] | 5 | from info import FlightInfo
|
---|
[36] | 6 | from update import Updater
|
---|
[29] | 7 | from mlx.gui.common import *
|
---|
[42] | 8 | from mlx.gui.flight import Wizard
|
---|
[77] | 9 | from mlx.gui.monitor import MonitorWindow
|
---|
[28] | 10 |
|
---|
| 11 | import mlx.const as const
|
---|
| 12 | import mlx.fs as fs
|
---|
| 13 | import mlx.flight as flight
|
---|
| 14 | import mlx.logger as logger
|
---|
| 15 | import mlx.acft as acft
|
---|
[41] | 16 | import mlx.web as web
|
---|
[107] | 17 | from mlx.i18n import xstr
|
---|
[28] | 18 |
|
---|
| 19 | import time
|
---|
[38] | 20 | import threading
|
---|
| 21 | import sys
|
---|
[28] | 22 |
|
---|
[77] | 23 | #------------------------------------------------------------------------------
|
---|
| 24 |
|
---|
[28] | 25 | class GUI(fs.ConnectionListener):
|
---|
| 26 | """The main GUI class."""
|
---|
[96] | 27 | @staticmethod
|
---|
| 28 | def _formatFlightLogLine(timeStr, line):
|
---|
| 29 | """Format the given line for flight logging."""
|
---|
| 30 | if timeStr is not None:
|
---|
| 31 | line = timeStr + ": " + line
|
---|
| 32 | return line + "\n"
|
---|
| 33 |
|
---|
[36] | 34 | def __init__(self, programDirectory, config):
|
---|
[28] | 35 | """Construct the GUI."""
|
---|
| 36 | gobject.threads_init()
|
---|
| 37 |
|
---|
[36] | 38 | self._programDirectory = programDirectory
|
---|
[42] | 39 | self.config = config
|
---|
[28] | 40 | self._connecting = False
|
---|
[59] | 41 | self._reconnecting = False
|
---|
[28] | 42 | self._connected = False
|
---|
[96] | 43 | self._logger = logger.Logger(self)
|
---|
[28] | 44 | self._flight = None
|
---|
| 45 | self._simulator = None
|
---|
[59] | 46 | self._monitoring = False
|
---|
[38] | 47 |
|
---|
| 48 | self._stdioLock = threading.Lock()
|
---|
| 49 | self._stdioText = ""
|
---|
[28] | 50 |
|
---|
[41] | 51 | self.webHandler = web.Handler()
|
---|
| 52 | self.webHandler.start()
|
---|
| 53 |
|
---|
[38] | 54 | self.toRestart = False
|
---|
| 55 |
|
---|
[29] | 56 | def build(self, iconDirectory):
|
---|
[28] | 57 | """Build the GUI."""
|
---|
[29] | 58 |
|
---|
[36] | 59 | window = gtk.Window()
|
---|
[105] | 60 | window.set_title(WINDOW_TITLE_BASE)
|
---|
[36] | 61 | window.set_icon_from_file(os.path.join(iconDirectory, "logo.ico"))
|
---|
| 62 | window.connect("delete-event",
|
---|
| 63 | lambda a, b: self.hideMainWindow())
|
---|
| 64 | window.connect("window-state-event", self._handleMainWindowState)
|
---|
[93] | 65 | accelGroup = gtk.AccelGroup()
|
---|
| 66 | window.add_accel_group(accelGroup)
|
---|
[28] | 67 |
|
---|
| 68 | mainVBox = gtk.VBox()
|
---|
[36] | 69 | window.add(mainVBox)
|
---|
[28] | 70 |
|
---|
[93] | 71 | menuBar = self._buildMenuBar(accelGroup)
|
---|
| 72 | mainVBox.pack_start(menuBar, False, False, 0)
|
---|
| 73 |
|
---|
[92] | 74 | self._notebook = gtk.Notebook()
|
---|
[93] | 75 | mainVBox.pack_start(self._notebook, True, True, 4)
|
---|
[42] | 76 |
|
---|
[46] | 77 | self._wizard = Wizard(self)
|
---|
[107] | 78 | label = gtk.Label(xstr("tab_flight"))
|
---|
[46] | 79 | label.set_use_underline(True)
|
---|
[108] | 80 | label.set_tooltip_text(xstr("tab_flight_tooltip"))
|
---|
[92] | 81 | self._notebook.append_page(self._wizard, label)
|
---|
[42] | 82 |
|
---|
[90] | 83 | self._flightInfo = FlightInfo(self)
|
---|
[107] | 84 | label = gtk.Label(xstr("tab_flight_info"))
|
---|
[90] | 85 | label.set_use_underline(True)
|
---|
[108] | 86 | label.set_tooltip_text(xstr("tab_flight_info_tooltip"))
|
---|
[92] | 87 | self._notebook.append_page(self._flightInfo, label)
|
---|
[93] | 88 | self._flightInfo.disable()
|
---|
[90] | 89 |
|
---|
[93] | 90 | (logWidget, self._logView) = self._buildLogWidget()
|
---|
[107] | 91 | label = gtk.Label(xstr("tab_log"))
|
---|
[46] | 92 | label.set_use_underline(True)
|
---|
[108] | 93 | label.set_tooltip_text(xstr("tab_log_tooltip"))
|
---|
[93] | 94 | self._notebook.append_page(logWidget, label)
|
---|
| 95 |
|
---|
| 96 | (self._debugLogWidget, self._debugLogView) = self._buildLogWidget()
|
---|
| 97 | self._debugLogWidget.show_all()
|
---|
[32] | 98 |
|
---|
| 99 | mainVBox.pack_start(gtk.HSeparator(), False, False, 0)
|
---|
| 100 |
|
---|
| 101 | self._statusbar = Statusbar()
|
---|
| 102 | mainVBox.pack_start(self._statusbar, False, False, 0)
|
---|
| 103 |
|
---|
[92] | 104 | self._notebook.connect("switch-page", self._notebookPageSwitch)
|
---|
[46] | 105 |
|
---|
[77] | 106 | self._monitorWindow = MonitorWindow(self, iconDirectory)
|
---|
[93] | 107 | self._monitorWindow.add_accel_group(accelGroup)
|
---|
[77] | 108 | self._monitorWindowX = None
|
---|
| 109 | self._monitorWindowY = None
|
---|
[93] | 110 | self._selfToggling = False
|
---|
[77] | 111 |
|
---|
[46] | 112 | window.show_all()
|
---|
| 113 | self._wizard.grabDefault()
|
---|
[28] | 114 |
|
---|
[36] | 115 | self._mainWindow = window
|
---|
[29] | 116 |
|
---|
| 117 | self._statusIcon = StatusIcon(iconDirectory, self)
|
---|
[28] | 118 |
|
---|
[49] | 119 | self._busyCursor = gdk.Cursor(gdk.CursorType.WATCH if pygobject
|
---|
| 120 | else gdk.WATCH)
|
---|
| 121 |
|
---|
[59] | 122 | @property
|
---|
[105] | 123 | def mainWindow(self):
|
---|
| 124 | """Get the main window of the GUI."""
|
---|
| 125 | return self._mainWindow
|
---|
| 126 |
|
---|
| 127 | @property
|
---|
[97] | 128 | def logger(self):
|
---|
| 129 | """Get the logger used by us."""
|
---|
| 130 | return self._logger
|
---|
| 131 |
|
---|
| 132 | @property
|
---|
[59] | 133 | def simulator(self):
|
---|
| 134 | """Get the simulator used by us."""
|
---|
| 135 | return self._simulator
|
---|
| 136 |
|
---|
[71] | 137 | @property
|
---|
| 138 | def flight(self):
|
---|
| 139 | """Get the flight being performed."""
|
---|
| 140 | return self._flight
|
---|
[84] | 141 |
|
---|
| 142 | @property
|
---|
[97] | 143 | def bookedFlight(self):
|
---|
| 144 | """Get the booked flight selected, if any."""
|
---|
| 145 | return self._wizard.bookedFlight
|
---|
| 146 |
|
---|
| 147 | @property
|
---|
| 148 | def cargoWeight(self):
|
---|
| 149 | """Get the cargo weight."""
|
---|
| 150 | return self._wizard.cargoWeight
|
---|
| 151 |
|
---|
| 152 | @property
|
---|
[84] | 153 | def zfw(self):
|
---|
| 154 | """Get Zero-Fuel Weight calculated for the current flight."""
|
---|
| 155 | return self._wizard.zfw
|
---|
| 156 |
|
---|
| 157 | @property
|
---|
[97] | 158 | def filedCruiseAltitude(self):
|
---|
| 159 | """Get cruise altitude filed for the current flight."""
|
---|
| 160 | return self._wizard.filedCruiseAltitude
|
---|
| 161 |
|
---|
| 162 | @property
|
---|
[84] | 163 | def cruiseAltitude(self):
|
---|
[97] | 164 | """Get cruise altitude set for the current flight."""
|
---|
[84] | 165 | return self._wizard.cruiseAltitude
|
---|
[97] | 166 |
|
---|
| 167 | @property
|
---|
| 168 | def route(self):
|
---|
| 169 | """Get the flight route."""
|
---|
| 170 | return self._wizard.route
|
---|
| 171 |
|
---|
| 172 | @property
|
---|
| 173 | def departureMETAR(self):
|
---|
| 174 | """Get the METAR of the deprature airport."""
|
---|
| 175 | return self._wizard.departureMETAR
|
---|
[84] | 176 |
|
---|
| 177 | @property
|
---|
[97] | 178 | def arrivalMETAR(self):
|
---|
| 179 | """Get the METAR of the deprature airport."""
|
---|
| 180 | return self._wizard.arrivalMETAR
|
---|
| 181 |
|
---|
| 182 | @property
|
---|
| 183 | def departureRunway(self):
|
---|
| 184 | """Get the name of the departure runway."""
|
---|
| 185 | return self._wizard.departureRunway
|
---|
| 186 |
|
---|
| 187 | @property
|
---|
| 188 | def sid(self):
|
---|
| 189 | """Get the SID."""
|
---|
| 190 | return self._wizard.sid
|
---|
| 191 |
|
---|
| 192 | @property
|
---|
[84] | 193 | def v1(self):
|
---|
| 194 | """Get the V1 speed calculated for the flight."""
|
---|
| 195 | return self._wizard.v1
|
---|
| 196 |
|
---|
| 197 | @property
|
---|
| 198 | def vr(self):
|
---|
| 199 | """Get the Vr speed calculated for the flight."""
|
---|
| 200 | return self._wizard.vr
|
---|
| 201 |
|
---|
| 202 | @property
|
---|
| 203 | def v2(self):
|
---|
| 204 | """Get the V2 speed calculated for the flight."""
|
---|
| 205 | return self._wizard.v2
|
---|
[71] | 206 |
|
---|
[86] | 207 | @property
|
---|
[97] | 208 | def arrivalRunway(self):
|
---|
| 209 | """Get the arrival runway."""
|
---|
| 210 | return self._wizard.arrivalRunway
|
---|
| 211 |
|
---|
| 212 | @property
|
---|
| 213 | def star(self):
|
---|
| 214 | """Get the STAR."""
|
---|
| 215 | return self._wizard.star
|
---|
| 216 |
|
---|
| 217 | @property
|
---|
| 218 | def transition(self):
|
---|
| 219 | """Get the transition."""
|
---|
| 220 | return self._wizard.transition
|
---|
| 221 |
|
---|
| 222 | @property
|
---|
| 223 | def approachType(self):
|
---|
| 224 | """Get the approach type."""
|
---|
| 225 | return self._wizard.approachType
|
---|
| 226 |
|
---|
| 227 | @property
|
---|
[86] | 228 | def vref(self):
|
---|
| 229 | """Get the Vref speed calculated for the flight."""
|
---|
| 230 | return self._wizard.vref
|
---|
| 231 |
|
---|
[97] | 232 | @property
|
---|
| 233 | def flightType(self):
|
---|
| 234 | """Get the flight type."""
|
---|
| 235 | return self._wizard.flightType
|
---|
| 236 |
|
---|
| 237 | @property
|
---|
| 238 | def online(self):
|
---|
| 239 | """Get whether the flight was online or not."""
|
---|
| 240 | return self._wizard.online
|
---|
| 241 |
|
---|
| 242 | @property
|
---|
| 243 | def comments(self):
|
---|
| 244 | """Get the comments."""
|
---|
| 245 | return self._flightInfo.comments
|
---|
| 246 |
|
---|
| 247 | @property
|
---|
| 248 | def flightDefects(self):
|
---|
| 249 | """Get the flight defects."""
|
---|
| 250 | return self._flightInfo.flightDefects
|
---|
| 251 |
|
---|
[99] | 252 | @property
|
---|
| 253 | def delayCodes(self):
|
---|
| 254 | """Get the delay codes."""
|
---|
| 255 | return self._flightInfo.delayCodes
|
---|
| 256 |
|
---|
[28] | 257 | def run(self):
|
---|
| 258 | """Run the GUI."""
|
---|
[42] | 259 | if self.config.autoUpdate:
|
---|
[38] | 260 | self._updater = Updater(self,
|
---|
| 261 | self._programDirectory,
|
---|
[42] | 262 | self.config.updateURL,
|
---|
[36] | 263 | self._mainWindow)
|
---|
| 264 | self._updater.start()
|
---|
| 265 |
|
---|
[28] | 266 | gtk.main()
|
---|
[36] | 267 |
|
---|
[91] | 268 | self._disconnect()
|
---|
[28] | 269 |
|
---|
| 270 | def connected(self, fsType, descriptor):
|
---|
| 271 | """Called when we have connected to the simulator."""
|
---|
| 272 | self._connected = True
|
---|
| 273 | self._logger.untimedMessage("Connected to the simulator %s" % (descriptor,))
|
---|
[59] | 274 | gobject.idle_add(self._handleConnected, fsType, descriptor)
|
---|
| 275 |
|
---|
| 276 | def _handleConnected(self, fsType, descriptor):
|
---|
| 277 | """Called when the connection to the simulator has succeeded."""
|
---|
| 278 | self._statusbar.updateConnection(self._connecting, self._connected)
|
---|
| 279 | self.endBusy()
|
---|
| 280 | if not self._reconnecting:
|
---|
| 281 | self._wizard.connected(fsType, descriptor)
|
---|
| 282 | self._reconnecting = False
|
---|
| 283 |
|
---|
| 284 | def connectionFailed(self):
|
---|
| 285 | """Called when the connection failed."""
|
---|
| 286 | self._logger.untimedMessage("Connection to the simulator failed")
|
---|
| 287 | gobject.idle_add(self._connectionFailed)
|
---|
| 288 |
|
---|
| 289 | def _connectionFailed(self):
|
---|
| 290 | """Called when the connection failed."""
|
---|
| 291 | self.endBusy()
|
---|
| 292 | self._statusbar.updateConnection(self._connecting, self._connected)
|
---|
| 293 |
|
---|
[105] | 294 | dialog = gtk.MessageDialog(parent = self._mainWindow,
|
---|
| 295 | type = MESSAGETYPE_ERROR,
|
---|
[108] | 296 | message_format = xstr("conn_failed"))
|
---|
| 297 |
|
---|
[105] | 298 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
[108] | 299 | dialog.format_secondary_markup(xstr("conn_failed_sec"))
|
---|
[59] | 300 |
|
---|
[108] | 301 | dialog.add_button(xstr("button_cancel"), 0)
|
---|
| 302 | dialog.add_button(xstr("button_tryagain"), 1)
|
---|
[59] | 303 | dialog.set_default_response(1)
|
---|
| 304 |
|
---|
| 305 | result = dialog.run()
|
---|
| 306 | dialog.hide()
|
---|
| 307 | if result == 1:
|
---|
[107] | 308 | self.beginBusy(xstr("connect_busy"))
|
---|
[59] | 309 | self._simulator.reconnect()
|
---|
| 310 | else:
|
---|
[91] | 311 | self.reset()
|
---|
[28] | 312 |
|
---|
| 313 | def disconnected(self):
|
---|
| 314 | """Called when we have disconnected from the simulator."""
|
---|
| 315 | self._connected = False
|
---|
| 316 | self._logger.untimedMessage("Disconnected from the simulator")
|
---|
[59] | 317 |
|
---|
| 318 | gobject.idle_add(self._disconnected)
|
---|
| 319 |
|
---|
| 320 | def _disconnected(self):
|
---|
| 321 | """Called when we have disconnected from the simulator unexpectedly."""
|
---|
| 322 | self._statusbar.updateConnection(self._connecting, self._connected)
|
---|
| 323 |
|
---|
| 324 | dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
|
---|
[108] | 325 | message_format = xstr("conn_broken"),
|
---|
[59] | 326 | parent = self._mainWindow)
|
---|
[105] | 327 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
[108] | 328 | dialog.format_secondary_markup(xstr("conn_broken_sec"))
|
---|
[59] | 329 |
|
---|
[108] | 330 | dialog.add_button(xstr("button_cancel"), 0)
|
---|
| 331 | dialog.add_button(xstr("button_reconnect"), 1)
|
---|
[59] | 332 | dialog.set_default_response(1)
|
---|
| 333 |
|
---|
| 334 | result = dialog.run()
|
---|
| 335 | dialog.hide()
|
---|
| 336 | if result == 1:
|
---|
[108] | 337 | self.beginBusy(xstr("connect_busy"))
|
---|
[59] | 338 | self._reconnecting = True
|
---|
| 339 | self._simulator.reconnect()
|
---|
| 340 | else:
|
---|
[91] | 341 | self.reset()
|
---|
| 342 |
|
---|
[93] | 343 | def enableFlightInfo(self):
|
---|
| 344 | """Enable the flight info tab."""
|
---|
| 345 | self._flightInfo.enable()
|
---|
| 346 |
|
---|
[91] | 347 | def reset(self):
|
---|
| 348 | """Reset the GUI."""
|
---|
| 349 | self._disconnect()
|
---|
[92] | 350 |
|
---|
[91] | 351 | self._flightInfo.reset()
|
---|
[93] | 352 | self._flightInfo.disable()
|
---|
[91] | 353 | self.resetFlightStatus()
|
---|
[28] | 354 |
|
---|
[92] | 355 | self._wizard.reset()
|
---|
| 356 | self._notebook.set_current_page(0)
|
---|
| 357 |
|
---|
| 358 | self._logView.get_buffer().set_text("")
|
---|
| 359 |
|
---|
[91] | 360 | def _disconnect(self):
|
---|
| 361 | """Disconnect from the simulator if connected."""
|
---|
[92] | 362 | self.stopMonitoring()
|
---|
| 363 |
|
---|
[91] | 364 | if self._connected:
|
---|
| 365 | self._flight.simulator.disconnect()
|
---|
| 366 | self._connected = False
|
---|
| 367 |
|
---|
| 368 | self._connecting = False
|
---|
| 369 | self._reconnecting = False
|
---|
| 370 | self._statusbar.updateConnection(False, False)
|
---|
| 371 |
|
---|
[96] | 372 | def addFlightLogLine(self, timeStr, line):
|
---|
| 373 | """Write the given message line to the log."""
|
---|
| 374 | gobject.idle_add(self._writeLog,
|
---|
| 375 | GUI._formatFlightLogLine(timeStr, line),
|
---|
| 376 | self._logView)
|
---|
| 377 |
|
---|
| 378 | def updateFlightLogLine(self, index, timeStr, line):
|
---|
| 379 | """Update the line with the given index."""
|
---|
| 380 | gobject.idle_add(self._updateFlightLogLine, index,
|
---|
| 381 | GUI._formatFlightLogLine(timeStr, line))
|
---|
| 382 |
|
---|
| 383 | def _updateFlightLogLine(self, index, line):
|
---|
| 384 | """Replace the contents of the given line in the log."""
|
---|
| 385 | buffer = self._logView.get_buffer()
|
---|
| 386 | startIter = buffer.get_iter_at_line(index)
|
---|
| 387 | endIter = buffer.get_iter_at_line(index + 1)
|
---|
| 388 | buffer.delete(startIter, endIter)
|
---|
| 389 | buffer.insert(startIter, line)
|
---|
| 390 | self._logView.scroll_mark_onscreen(buffer.get_insert())
|
---|
| 391 |
|
---|
[28] | 392 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
| 393 | """Update the data."""
|
---|
[77] | 394 | gobject.idle_add(self._monitorWindow.setData, state)
|
---|
[80] | 395 | gobject.idle_add(self._statusbar.updateTime, state.timestamp)
|
---|
[28] | 396 |
|
---|
[31] | 397 | def resetFlightStatus(self):
|
---|
| 398 | """Reset the status of the flight."""
|
---|
[32] | 399 | self._statusbar.resetFlightStatus()
|
---|
[80] | 400 | self._statusbar.updateTime()
|
---|
[31] | 401 | self._statusIcon.resetFlightStatus()
|
---|
| 402 |
|
---|
| 403 | def setStage(self, stage):
|
---|
| 404 | """Set the stage of the flight."""
|
---|
| 405 | gobject.idle_add(self._setStage, stage)
|
---|
| 406 |
|
---|
| 407 | def _setStage(self, stage):
|
---|
| 408 | """Set the stage of the flight."""
|
---|
[32] | 409 | self._statusbar.setStage(stage)
|
---|
[31] | 410 | self._statusIcon.setStage(stage)
|
---|
[84] | 411 | self._wizard.setStage(stage)
|
---|
[88] | 412 | if stage==const.STAGE_END:
|
---|
[91] | 413 | self._disconnect()
|
---|
[31] | 414 |
|
---|
| 415 | def setRating(self, rating):
|
---|
| 416 | """Set the rating of the flight."""
|
---|
| 417 | gobject.idle_add(self._setRating, rating)
|
---|
| 418 |
|
---|
| 419 | def _setRating(self, rating):
|
---|
| 420 | """Set the rating of the flight."""
|
---|
[32] | 421 | self._statusbar.setRating(rating)
|
---|
[31] | 422 | self._statusIcon.setRating(rating)
|
---|
| 423 |
|
---|
| 424 | def setNoGo(self, reason):
|
---|
| 425 | """Set the rating of the flight to No-Go with the given reason."""
|
---|
| 426 | gobject.idle_add(self._setNoGo, reason)
|
---|
| 427 |
|
---|
| 428 | def _setNoGo(self, reason):
|
---|
| 429 | """Set the rating of the flight."""
|
---|
[32] | 430 | self._statusbar.setNoGo(reason)
|
---|
[31] | 431 | self._statusIcon.setNoGo(reason)
|
---|
| 432 |
|
---|
[29] | 433 | def _handleMainWindowState(self, window, event):
|
---|
| 434 | """Hande a change in the state of the window"""
|
---|
| 435 | iconified = gdk.WindowState.ICONIFIED if pygobject \
|
---|
| 436 | else gdk.WINDOW_STATE_ICONIFIED
|
---|
| 437 | if (event.changed_mask&iconified)!=0 and (event.new_window_state&iconified)!=0:
|
---|
[35] | 438 | self.hideMainWindow(savePosition = False)
|
---|
[29] | 439 |
|
---|
[35] | 440 | def hideMainWindow(self, savePosition = True):
|
---|
[29] | 441 | """Hide the main window and save its position."""
|
---|
[35] | 442 | if savePosition:
|
---|
| 443 | (self._mainWindowX, self._mainWindowY) = \
|
---|
| 444 | self._mainWindow.get_window().get_root_origin()
|
---|
| 445 | else:
|
---|
| 446 | self._mainWindowX = self._mainWindowY = None
|
---|
[29] | 447 | self._mainWindow.hide()
|
---|
| 448 | self._statusIcon.mainWindowHidden()
|
---|
| 449 | return True
|
---|
| 450 |
|
---|
| 451 | def showMainWindow(self):
|
---|
| 452 | """Show the main window at its former position."""
|
---|
[35] | 453 | if self._mainWindowX is not None and self._mainWindowY is not None:
|
---|
| 454 | self._mainWindow.move(self._mainWindowX, self._mainWindowY)
|
---|
| 455 |
|
---|
| 456 | self._mainWindow.show()
|
---|
[29] | 457 | self._mainWindow.deiconify()
|
---|
[35] | 458 |
|
---|
[29] | 459 | self._statusIcon.mainWindowShown()
|
---|
| 460 |
|
---|
| 461 | def toggleMainWindow(self):
|
---|
| 462 | """Toggle the main window."""
|
---|
| 463 | if self._mainWindow.get_visible():
|
---|
| 464 | self.hideMainWindow()
|
---|
| 465 | else:
|
---|
| 466 | self.showMainWindow()
|
---|
[36] | 467 |
|
---|
[77] | 468 | def hideMonitorWindow(self, savePosition = True):
|
---|
| 469 | """Hide the monitor window."""
|
---|
| 470 | if savePosition:
|
---|
| 471 | (self._monitorWindowX, self._monitorWindowY) = \
|
---|
| 472 | self._monitorWindow.get_window().get_root_origin()
|
---|
| 473 | else:
|
---|
| 474 | self._monitorWindowX = self._monitorWindowY = None
|
---|
| 475 | self._monitorWindow.hide()
|
---|
| 476 | self._statusIcon.monitorWindowHidden()
|
---|
[93] | 477 | if self._showMonitorMenuItem.get_active():
|
---|
| 478 | self._selfToggling = True
|
---|
| 479 | self._showMonitorMenuItem.set_active(False)
|
---|
[77] | 480 | return True
|
---|
| 481 |
|
---|
| 482 | def showMonitorWindow(self):
|
---|
| 483 | """Show the monitor window."""
|
---|
| 484 | if self._monitorWindowX is not None and self._monitorWindowY is not None:
|
---|
| 485 | self._monitorWindow.move(self._monitorWindowX, self._monitorWindowY)
|
---|
| 486 | self._monitorWindow.show_all()
|
---|
| 487 | self._statusIcon.monitorWindowShown()
|
---|
[93] | 488 | if not self._showMonitorMenuItem.get_active():
|
---|
| 489 | self._selfToggling = True
|
---|
| 490 | self._showMonitorMenuItem.set_active(True)
|
---|
| 491 |
|
---|
| 492 | def _toggleMonitorWindow(self, menuItem):
|
---|
| 493 | if self._selfToggling:
|
---|
| 494 | self._selfToggling = False
|
---|
| 495 | elif self._monitorWindow.get_visible():
|
---|
| 496 | self.hideMonitorWindow()
|
---|
| 497 | else:
|
---|
| 498 | self.showMonitorWindow()
|
---|
[77] | 499 |
|
---|
[38] | 500 | def restart(self):
|
---|
| 501 | """Quit and restart the application."""
|
---|
| 502 | self.toRestart = True
|
---|
[81] | 503 | self._quit(force = True)
|
---|
[38] | 504 |
|
---|
| 505 | def flushStdIO(self):
|
---|
| 506 | """Flush any text to the standard error that could not be logged."""
|
---|
| 507 | if self._stdioText:
|
---|
| 508 | sys.__stderr__.write(self._stdioText)
|
---|
| 509 |
|
---|
[36] | 510 | def writeStdIO(self, text):
|
---|
| 511 | """Write the given text into standard I/O log."""
|
---|
[38] | 512 | with self._stdioLock:
|
---|
| 513 | self._stdioText += text
|
---|
| 514 |
|
---|
| 515 | gobject.idle_add(self._writeStdIO)
|
---|
[36] | 516 |
|
---|
[49] | 517 | def beginBusy(self, message):
|
---|
| 518 | """Begin a period of background processing."""
|
---|
[93] | 519 | self._wizard.set_sensitive(False)
|
---|
[49] | 520 | self._mainWindow.get_window().set_cursor(self._busyCursor)
|
---|
| 521 | self._statusbar.updateBusyState(message)
|
---|
| 522 |
|
---|
| 523 | def endBusy(self):
|
---|
| 524 | """End a period of background processing."""
|
---|
| 525 | self._mainWindow.get_window().set_cursor(None)
|
---|
[93] | 526 | self._wizard.set_sensitive(True)
|
---|
[49] | 527 | self._statusbar.updateBusyState(None)
|
---|
| 528 |
|
---|
[38] | 529 | def _writeStdIO(self):
|
---|
[36] | 530 | """Perform the real writing."""
|
---|
[38] | 531 | with self._stdioLock:
|
---|
| 532 | text = self._stdioText
|
---|
| 533 | self._stdioText = ""
|
---|
| 534 | if not text: return
|
---|
| 535 |
|
---|
[36] | 536 | lines = text.splitlines()
|
---|
| 537 | if text[-1]=="\n":
|
---|
| 538 | text = ""
|
---|
| 539 | else:
|
---|
| 540 | text = lines[-1]
|
---|
| 541 | lines = lines[:-1]
|
---|
| 542 |
|
---|
| 543 | for line in lines:
|
---|
[96] | 544 | #print >> sys.__stdout__, line
|
---|
[93] | 545 | self._writeLog(line + "\n", self._debugLogView)
|
---|
[36] | 546 |
|
---|
| 547 | if text:
|
---|
[96] | 548 | #print >> sys.__stdout__, text,
|
---|
[93] | 549 | self._writeLog(text, self._debugLogView)
|
---|
[51] | 550 |
|
---|
[59] | 551 | def connectSimulator(self, aircraftType):
|
---|
| 552 | """Connect to the simulator for the first time."""
|
---|
| 553 | self._logger.reset()
|
---|
| 554 |
|
---|
| 555 | self._flight = flight.Flight(self._logger, self)
|
---|
| 556 | self._flight.aircraftType = aircraftType
|
---|
| 557 | self._flight.aircraft = acft.Aircraft.create(self._flight)
|
---|
| 558 | self._flight.aircraft._checkers.append(self)
|
---|
| 559 |
|
---|
| 560 | if self._simulator is None:
|
---|
| 561 | self._simulator = fs.createSimulator(const.SIM_MSFS9, self)
|
---|
| 562 |
|
---|
| 563 | self._flight.simulator = self._simulator
|
---|
| 564 |
|
---|
[107] | 565 | self.beginBusy(xstr("connect_busy"))
|
---|
[59] | 566 | self._statusbar.updateConnection(self._connecting, self._connected)
|
---|
| 567 |
|
---|
| 568 | self._connecting = True
|
---|
| 569 | self._simulator.connect(self._flight.aircraft)
|
---|
| 570 |
|
---|
[70] | 571 | def startMonitoring(self):
|
---|
| 572 | """Start monitoring."""
|
---|
[88] | 573 | if not self._monitoring:
|
---|
| 574 | self.simulator.startMonitoring()
|
---|
| 575 | self._monitoring = True
|
---|
[70] | 576 |
|
---|
| 577 | def stopMonitoring(self):
|
---|
| 578 | """Stop monitoring."""
|
---|
[88] | 579 | if self._monitoring:
|
---|
| 580 | self.simulator.stopMonitoring()
|
---|
| 581 | self._monitoring = False
|
---|
[70] | 582 |
|
---|
[93] | 583 | def _buildMenuBar(self, accelGroup):
|
---|
| 584 | """Build the main menu bar."""
|
---|
| 585 | menuBar = gtk.MenuBar()
|
---|
| 586 |
|
---|
[110] | 587 | fileMenuItem = gtk.MenuItem(xstr("menu_file"))
|
---|
[93] | 588 | fileMenu = gtk.Menu()
|
---|
| 589 | fileMenuItem.set_submenu(fileMenu)
|
---|
| 590 | menuBar.append(fileMenuItem)
|
---|
| 591 |
|
---|
| 592 | quitMenuItem = gtk.ImageMenuItem(gtk.STOCK_QUIT)
|
---|
| 593 | quitMenuItem.set_use_stock(True)
|
---|
[110] | 594 | quitMenuItem.set_label(xstr("menu_file_quit"))
|
---|
[93] | 595 | quitMenuItem.add_accelerator("activate", accelGroup,
|
---|
[110] | 596 | ord(xstr("menu_file_quit_key")),
|
---|
| 597 | CONTROL_MASK, ACCEL_VISIBLE)
|
---|
[93] | 598 | quitMenuItem.connect("activate", self._quit)
|
---|
| 599 | fileMenu.append(quitMenuItem)
|
---|
| 600 |
|
---|
| 601 |
|
---|
[110] | 602 | viewMenuItem = gtk.MenuItem(xstr("menu_view"))
|
---|
[93] | 603 | viewMenu = gtk.Menu()
|
---|
| 604 | viewMenuItem.set_submenu(viewMenu)
|
---|
| 605 | menuBar.append(viewMenuItem)
|
---|
[28] | 606 |
|
---|
[93] | 607 | self._showMonitorMenuItem = gtk.CheckMenuItem()
|
---|
[110] | 608 | self._showMonitorMenuItem.set_label(xstr("menu_view_monitor"))
|
---|
[93] | 609 | self._showMonitorMenuItem.set_use_underline(True)
|
---|
| 610 | self._showMonitorMenuItem.set_active(False)
|
---|
| 611 | self._showMonitorMenuItem.add_accelerator("activate", accelGroup,
|
---|
[110] | 612 | ord(xstr("menu_view_monitor_key")),
|
---|
| 613 | CONTROL_MASK, ACCEL_VISIBLE)
|
---|
[93] | 614 | self._showMonitorMenuItem.connect("toggled", self._toggleMonitorWindow)
|
---|
| 615 | viewMenu.append(self._showMonitorMenuItem)
|
---|
| 616 |
|
---|
| 617 | showDebugMenuItem = gtk.CheckMenuItem()
|
---|
[110] | 618 | showDebugMenuItem.set_label(xstr("menu_view_debug"))
|
---|
[93] | 619 | showDebugMenuItem.set_use_underline(True)
|
---|
| 620 | showDebugMenuItem.set_active(False)
|
---|
| 621 | showDebugMenuItem.add_accelerator("activate", accelGroup,
|
---|
[110] | 622 | ord(xstr("menu_view_debug_key")),
|
---|
| 623 | CONTROL_MASK, ACCEL_VISIBLE)
|
---|
[93] | 624 | showDebugMenuItem.connect("toggled", self._toggleDebugLog)
|
---|
| 625 | viewMenu.append(showDebugMenuItem)
|
---|
[28] | 626 |
|
---|
[93] | 627 | return menuBar
|
---|
[28] | 628 |
|
---|
[93] | 629 | def _toggleDebugLog(self, menuItem):
|
---|
| 630 | """Toggle the debug log."""
|
---|
| 631 | if menuItem.get_active():
|
---|
[107] | 632 | label = gtk.Label(xstr("tab_debug_log"))
|
---|
[93] | 633 | label.set_use_underline(True)
|
---|
[110] | 634 | label.set_tooltip_text(xstr("tab_debug_log_tooltip"))
|
---|
[93] | 635 | self._debugLogPage = self._notebook.append_page(self._debugLogWidget, label)
|
---|
| 636 | self._notebook.set_current_page(self._debugLogPage)
|
---|
| 637 | else:
|
---|
| 638 | self._notebook.remove_page(self._debugLogPage)
|
---|
| 639 |
|
---|
| 640 | def _buildLogWidget(self):
|
---|
| 641 | """Build the widget for the log."""
|
---|
| 642 | alignment = gtk.Alignment(xscale = 1.0, yscale = 1.0)
|
---|
| 643 |
|
---|
| 644 | alignment.set_padding(padding_top = 8, padding_bottom = 8,
|
---|
| 645 | padding_left = 16, padding_right = 16)
|
---|
[28] | 646 |
|
---|
| 647 | logScroller = gtk.ScrolledWindow()
|
---|
[93] | 648 | # FIXME: these should be constants in common
|
---|
| 649 | logScroller.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
|
---|
| 650 | else gtk.POLICY_AUTOMATIC,
|
---|
| 651 | gtk.PolicyType.AUTOMATIC if pygobject
|
---|
| 652 | else gtk.POLICY_AUTOMATIC)
|
---|
| 653 | logScroller.set_shadow_type(gtk.ShadowType.IN if pygobject
|
---|
| 654 | else gtk.SHADOW_IN)
|
---|
| 655 | logView = gtk.TextView()
|
---|
| 656 | logView.set_editable(False)
|
---|
| 657 | logScroller.add(logView)
|
---|
[28] | 658 |
|
---|
| 659 | logBox = gtk.VBox()
|
---|
| 660 | logBox.pack_start(logScroller, True, True, 0)
|
---|
| 661 | logBox.set_size_request(-1, 200)
|
---|
| 662 |
|
---|
[93] | 663 | alignment.add(logBox)
|
---|
[28] | 664 |
|
---|
[93] | 665 | return (alignment, logView)
|
---|
[28] | 666 |
|
---|
[93] | 667 | def _writeLog(self, msg, logView):
|
---|
[28] | 668 | """Write the given message to the log."""
|
---|
[93] | 669 | buffer = logView.get_buffer()
|
---|
[28] | 670 | buffer.insert(buffer.get_end_iter(), msg)
|
---|
[93] | 671 | logView.scroll_mark_onscreen(buffer.get_insert())
|
---|
[28] | 672 |
|
---|
[81] | 673 | def _quit(self, what = None, force = False):
|
---|
[38] | 674 | """Quit from the application."""
|
---|
[81] | 675 | if force:
|
---|
| 676 | result=RESPONSETYPE_YES
|
---|
| 677 | else:
|
---|
[105] | 678 | dialog = gtk.MessageDialog(parent = self._mainWindow,
|
---|
| 679 | type = MESSAGETYPE_QUESTION,
|
---|
[81] | 680 | buttons = BUTTONSTYPE_YES_NO,
|
---|
[110] | 681 | message_format = xstr("quit_question"))
|
---|
| 682 |
|
---|
[105] | 683 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
[81] | 684 | result = dialog.run()
|
---|
| 685 | dialog.hide()
|
---|
[76] | 686 |
|
---|
| 687 | if result==RESPONSETYPE_YES:
|
---|
| 688 | self._statusIcon.destroy()
|
---|
| 689 | return gtk.main_quit()
|
---|
[38] | 690 |
|
---|
[46] | 691 | def _notebookPageSwitch(self, notebook, page, page_num):
|
---|
| 692 | """Called when the current page of the notebook has changed."""
|
---|
| 693 | if page_num==0:
|
---|
[48] | 694 | gobject.idle_add(self._wizard.grabDefault)
|
---|
[46] | 695 | else:
|
---|
| 696 | self._mainWindow.set_default(None)
|
---|