[227] | 1 | # -*- coding: utf-8 -*-
|
---|
[28] | 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
|
---|
[117] | 10 | from mlx.gui.weighthelp import WeightHelp
|
---|
[118] | 11 | from mlx.gui.gates import FleetGateStatus
|
---|
[123] | 12 | from mlx.gui.prefs import Preferences
|
---|
[172] | 13 | from mlx.gui.checklist import ChecklistEditor
|
---|
[264] | 14 | from mlx.gui.callouts import ApproachCalloutsEditor
|
---|
[220] | 15 | from mlx.gui.pirep import PIREPViewer
|
---|
[483] | 16 | from mlx.gui.bugreport import BugReportDialog
|
---|
[28] | 17 |
|
---|
| 18 | import mlx.const as const
|
---|
| 19 | import mlx.fs as fs
|
---|
| 20 | import mlx.flight as flight
|
---|
| 21 | import mlx.logger as logger
|
---|
| 22 | import mlx.acft as acft
|
---|
[41] | 23 | import mlx.web as web
|
---|
[182] | 24 | import mlx.singleton as singleton
|
---|
[261] | 25 | import mlx.airports as airports
|
---|
[227] | 26 | from mlx.i18n import xstr, getLanguage
|
---|
[151] | 27 | from mlx.pirep import PIREP
|
---|
[28] | 28 |
|
---|
| 29 | import time
|
---|
[38] | 30 | import threading
|
---|
| 31 | import sys
|
---|
[203] | 32 | import datetime
|
---|
[227] | 33 | import webbrowser
|
---|
[28] | 34 |
|
---|
[77] | 35 | #------------------------------------------------------------------------------
|
---|
| 36 |
|
---|
[300] | 37 | ## @package mlx.gui.gui
|
---|
| 38 | #
|
---|
| 39 | # The main GUI class.
|
---|
| 40 | #
|
---|
| 41 | # The \ref GUI class is the main class of the GUI. It is a connection listener,
|
---|
| 42 | # and aggregates all the windows, the menu, etc. It maintains the connection to
|
---|
| 43 | # the simulator as well as the flight object.
|
---|
| 44 |
|
---|
| 45 | #------------------------------------------------------------------------------
|
---|
| 46 |
|
---|
[28] | 47 | class GUI(fs.ConnectionListener):
|
---|
| 48 | """The main GUI class."""
|
---|
[276] | 49 | _authors = [ (u"Váradi", u"István", "prog_test"),
|
---|
| 50 | (u"Galyassy", u"Tamás", "negotiation"),
|
---|
| 51 | (u"Kurják", u"Ákos", "test"),
|
---|
| 52 | (u"Nagy", u"Dániel", "test"),
|
---|
[393] | 53 | (u"Radó", u"Iván", "test"),
|
---|
| 54 | (u"Petrovszki", u"Gábor", "test"),
|
---|
| 55 | (u"Serfőző", u"Tamás", "test"),
|
---|
| 56 | (u"Szebenyi", u"Bálint", "test"),
|
---|
| 57 | (u"Zsebényi-Loksa", u"Gergely", "test") ]
|
---|
[227] | 58 |
|
---|
[36] | 59 | def __init__(self, programDirectory, config):
|
---|
[28] | 60 | """Construct the GUI."""
|
---|
| 61 | gobject.threads_init()
|
---|
| 62 |
|
---|
[36] | 63 | self._programDirectory = programDirectory
|
---|
[42] | 64 | self.config = config
|
---|
[28] | 65 | self._connecting = False
|
---|
[59] | 66 | self._reconnecting = False
|
---|
[28] | 67 | self._connected = False
|
---|
[96] | 68 | self._logger = logger.Logger(self)
|
---|
[28] | 69 | self._flight = None
|
---|
| 70 | self._simulator = None
|
---|
[430] | 71 | self._fsType = None
|
---|
[59] | 72 | self._monitoring = False
|
---|
[130] | 73 |
|
---|
[119] | 74 | self._fleet = None
|
---|
[130] | 75 |
|
---|
[119] | 76 | self._fleetCallback = None
|
---|
[38] | 77 |
|
---|
[130] | 78 | self._updatePlaneCallback = None
|
---|
| 79 | self._updatePlaneTailNumber = None
|
---|
| 80 | self._updatePlaneStatus = None
|
---|
| 81 | self._updatePlaneGateNumber = None
|
---|
| 82 |
|
---|
[38] | 83 | self._stdioLock = threading.Lock()
|
---|
| 84 | self._stdioText = ""
|
---|
[203] | 85 | self._stdioStartingLine = True
|
---|
[28] | 86 |
|
---|
[151] | 87 | self._sendPIREPCallback = None
|
---|
[484] | 88 | self._sendBugReportCallback = None
|
---|
[151] | 89 |
|
---|
[41] | 90 | self.webHandler = web.Handler()
|
---|
| 91 | self.webHandler.start()
|
---|
| 92 |
|
---|
[38] | 93 | self.toRestart = False
|
---|
| 94 |
|
---|
[29] | 95 | def build(self, iconDirectory):
|
---|
[28] | 96 | """Build the GUI."""
|
---|
[345] | 97 |
|
---|
[123] | 98 | self._mainWindow = window = gtk.Window()
|
---|
[105] | 99 | window.set_title(WINDOW_TITLE_BASE)
|
---|
[36] | 100 | window.set_icon_from_file(os.path.join(iconDirectory, "logo.ico"))
|
---|
[202] | 101 | window.set_resizable(False)
|
---|
[249] | 102 | window.connect("delete-event", self.deleteMainWindow)
|
---|
[36] | 103 | window.connect("window-state-event", self._handleMainWindowState)
|
---|
[93] | 104 | accelGroup = gtk.AccelGroup()
|
---|
| 105 | window.add_accel_group(accelGroup)
|
---|
[28] | 106 |
|
---|
| 107 | mainVBox = gtk.VBox()
|
---|
[36] | 108 | window.add(mainVBox)
|
---|
[28] | 109 |
|
---|
[123] | 110 | self._preferences = Preferences(self)
|
---|
[172] | 111 | self._checklistEditor = ChecklistEditor(self)
|
---|
[264] | 112 | self._approachCalloutsEditor = ApproachCalloutsEditor(self)
|
---|
[484] | 113 | self._bugReportDialog = BugReportDialog(self)
|
---|
[123] | 114 |
|
---|
[93] | 115 | menuBar = self._buildMenuBar(accelGroup)
|
---|
| 116 | mainVBox.pack_start(menuBar, False, False, 0)
|
---|
| 117 |
|
---|
[92] | 118 | self._notebook = gtk.Notebook()
|
---|
[93] | 119 | mainVBox.pack_start(self._notebook, True, True, 4)
|
---|
[345] | 120 |
|
---|
[46] | 121 | self._wizard = Wizard(self)
|
---|
[107] | 122 | label = gtk.Label(xstr("tab_flight"))
|
---|
[46] | 123 | label.set_use_underline(True)
|
---|
[108] | 124 | label.set_tooltip_text(xstr("tab_flight_tooltip"))
|
---|
[92] | 125 | self._notebook.append_page(self._wizard, label)
|
---|
[42] | 126 |
|
---|
[90] | 127 | self._flightInfo = FlightInfo(self)
|
---|
[107] | 128 | label = gtk.Label(xstr("tab_flight_info"))
|
---|
[90] | 129 | label.set_use_underline(True)
|
---|
[108] | 130 | label.set_tooltip_text(xstr("tab_flight_info_tooltip"))
|
---|
[92] | 131 | self._notebook.append_page(self._flightInfo, label)
|
---|
[93] | 132 | self._flightInfo.disable()
|
---|
[90] | 133 |
|
---|
[117] | 134 | self._weightHelp = WeightHelp(self)
|
---|
| 135 | label = gtk.Label(xstr("tab_weight_help"))
|
---|
| 136 | label.set_use_underline(True)
|
---|
| 137 | label.set_tooltip_text(xstr("tab_weight_help_tooltip"))
|
---|
| 138 | self._notebook.append_page(self._weightHelp, label)
|
---|
[345] | 139 |
|
---|
[93] | 140 | (logWidget, self._logView) = self._buildLogWidget()
|
---|
[345] | 141 | addFaultTag(self._logView.get_buffer())
|
---|
[107] | 142 | label = gtk.Label(xstr("tab_log"))
|
---|
[46] | 143 | label.set_use_underline(True)
|
---|
[108] | 144 | label.set_tooltip_text(xstr("tab_log_tooltip"))
|
---|
[93] | 145 | self._notebook.append_page(logWidget, label)
|
---|
| 146 |
|
---|
[118] | 147 | self._fleetGateStatus = FleetGateStatus(self)
|
---|
| 148 | label = gtk.Label(xstr("tab_gates"))
|
---|
| 149 | label.set_use_underline(True)
|
---|
| 150 | label.set_tooltip_text(xstr("tab_gates_tooltip"))
|
---|
| 151 | self._notebook.append_page(self._fleetGateStatus, label)
|
---|
[345] | 152 |
|
---|
[93] | 153 | (self._debugLogWidget, self._debugLogView) = self._buildLogWidget()
|
---|
| 154 | self._debugLogWidget.show_all()
|
---|
[32] | 155 |
|
---|
| 156 | mainVBox.pack_start(gtk.HSeparator(), False, False, 0)
|
---|
| 157 |
|
---|
[281] | 158 | self._statusbar = Statusbar(iconDirectory)
|
---|
[32] | 159 | mainVBox.pack_start(self._statusbar, False, False, 0)
|
---|
| 160 |
|
---|
[92] | 161 | self._notebook.connect("switch-page", self._notebookPageSwitch)
|
---|
[46] | 162 |
|
---|
[77] | 163 | self._monitorWindow = MonitorWindow(self, iconDirectory)
|
---|
[93] | 164 | self._monitorWindow.add_accel_group(accelGroup)
|
---|
[77] | 165 | self._monitorWindowX = None
|
---|
| 166 | self._monitorWindowY = None
|
---|
[93] | 167 | self._selfToggling = False
|
---|
[77] | 168 |
|
---|
[220] | 169 | self._pirepViewer = PIREPViewer(self)
|
---|
| 170 |
|
---|
[46] | 171 | window.show_all()
|
---|
| 172 | self._wizard.grabDefault()
|
---|
[117] | 173 | self._weightHelp.reset()
|
---|
| 174 | self._weightHelp.disable()
|
---|
[28] | 175 |
|
---|
[29] | 176 | self._statusIcon = StatusIcon(iconDirectory, self)
|
---|
[28] | 177 |
|
---|
[49] | 178 | self._busyCursor = gdk.Cursor(gdk.CursorType.WATCH if pygobject
|
---|
| 179 | else gdk.WATCH)
|
---|
| 180 |
|
---|
[151] | 181 | self._loadPIREPDialog = None
|
---|
| 182 | self._lastLoadedPIREP = None
|
---|
| 183 |
|
---|
[168] | 184 | self._hotkeySetID = None
|
---|
[178] | 185 | self._pilotHotkeyIndex = None
|
---|
| 186 | self._checklistHotkeyIndex = None
|
---|
[168] | 187 |
|
---|
[227] | 188 | self._aboutDialog = None
|
---|
| 189 |
|
---|
[59] | 190 | @property
|
---|
[105] | 191 | def mainWindow(self):
|
---|
| 192 | """Get the main window of the GUI."""
|
---|
| 193 | return self._mainWindow
|
---|
[345] | 194 |
|
---|
[105] | 195 | @property
|
---|
[97] | 196 | def logger(self):
|
---|
| 197 | """Get the logger used by us."""
|
---|
| 198 | return self._logger
|
---|
[345] | 199 |
|
---|
[97] | 200 | @property
|
---|
[59] | 201 | def simulator(self):
|
---|
| 202 | """Get the simulator used by us."""
|
---|
| 203 | return self._simulator
|
---|
[345] | 204 |
|
---|
[71] | 205 | @property
|
---|
| 206 | def flight(self):
|
---|
| 207 | """Get the flight being performed."""
|
---|
| 208 | return self._flight
|
---|
[84] | 209 |
|
---|
| 210 | @property
|
---|
[430] | 211 | def fsType(self):
|
---|
| 212 | """Get the flight simulator type."""
|
---|
| 213 | return self._fsType
|
---|
| 214 |
|
---|
| 215 | @property
|
---|
[184] | 216 | def entranceExam(self):
|
---|
| 217 | """Get whether an entrance exam is about to be taken."""
|
---|
| 218 | return self._wizard.entranceExam
|
---|
[215] | 219 |
|
---|
| 220 | @property
|
---|
| 221 | def loggedIn(self):
|
---|
| 222 | """Indicate if the user has logged in properly."""
|
---|
| 223 | return self._wizard.loggedIn
|
---|
[345] | 224 |
|
---|
[184] | 225 | @property
|
---|
[139] | 226 | def loginResult(self):
|
---|
| 227 | """Get the result of the login."""
|
---|
| 228 | return self._wizard.loginResult
|
---|
| 229 |
|
---|
| 230 | @property
|
---|
[97] | 231 | def bookedFlight(self):
|
---|
| 232 | """Get the booked flight selected, if any."""
|
---|
| 233 | return self._wizard.bookedFlight
|
---|
| 234 |
|
---|
| 235 | @property
|
---|
[303] | 236 | def numCrew(self):
|
---|
| 237 | """Get the number of crew members."""
|
---|
| 238 | return self._wizard.numCrew
|
---|
| 239 |
|
---|
| 240 | @property
|
---|
| 241 | def numPassengers(self):
|
---|
| 242 | """Get the number of passengers."""
|
---|
| 243 | return self._wizard.numPassengers
|
---|
| 244 |
|
---|
| 245 | @property
|
---|
| 246 | def bagWeight(self):
|
---|
| 247 | """Get the bag weight."""
|
---|
| 248 | return self._wizard.bagWeight
|
---|
| 249 |
|
---|
| 250 | @property
|
---|
[97] | 251 | def cargoWeight(self):
|
---|
| 252 | """Get the cargo weight."""
|
---|
| 253 | return self._wizard.cargoWeight
|
---|
| 254 |
|
---|
| 255 | @property
|
---|
[303] | 256 | def mailWeight(self):
|
---|
| 257 | """Get the mail weight."""
|
---|
| 258 | return self._wizard.mailWeight
|
---|
| 259 |
|
---|
| 260 | @property
|
---|
[84] | 261 | def zfw(self):
|
---|
| 262 | """Get Zero-Fuel Weight calculated for the current flight."""
|
---|
| 263 | return self._wizard.zfw
|
---|
[345] | 264 |
|
---|
[84] | 265 | @property
|
---|
[97] | 266 | def filedCruiseAltitude(self):
|
---|
| 267 | """Get cruise altitude filed for the current flight."""
|
---|
| 268 | return self._wizard.filedCruiseAltitude
|
---|
[345] | 269 |
|
---|
[97] | 270 | @property
|
---|
[84] | 271 | def cruiseAltitude(self):
|
---|
[97] | 272 | """Get cruise altitude set for the current flight."""
|
---|
[84] | 273 | return self._wizard.cruiseAltitude
|
---|
[97] | 274 |
|
---|
| 275 | @property
|
---|
[383] | 276 | def loggableCruiseAltitude(self):
|
---|
| 277 | """Get the cruise altitude that can be logged."""
|
---|
| 278 | return self._wizard.loggableCruiseAltitude
|
---|
| 279 |
|
---|
| 280 | @property
|
---|
[97] | 281 | def route(self):
|
---|
| 282 | """Get the flight route."""
|
---|
| 283 | return self._wizard.route
|
---|
| 284 |
|
---|
| 285 | @property
|
---|
| 286 | def departureMETAR(self):
|
---|
| 287 | """Get the METAR of the deprature airport."""
|
---|
| 288 | return self._wizard.departureMETAR
|
---|
[345] | 289 |
|
---|
[84] | 290 | @property
|
---|
[97] | 291 | def arrivalMETAR(self):
|
---|
| 292 | """Get the METAR of the deprature airport."""
|
---|
| 293 | return self._wizard.arrivalMETAR
|
---|
| 294 |
|
---|
| 295 | @property
|
---|
| 296 | def departureRunway(self):
|
---|
| 297 | """Get the name of the departure runway."""
|
---|
| 298 | return self._wizard.departureRunway
|
---|
[345] | 299 |
|
---|
[97] | 300 | @property
|
---|
| 301 | def sid(self):
|
---|
| 302 | """Get the SID."""
|
---|
| 303 | return self._wizard.sid
|
---|
| 304 |
|
---|
| 305 | @property
|
---|
[84] | 306 | def v1(self):
|
---|
| 307 | """Get the V1 speed calculated for the flight."""
|
---|
| 308 | return self._wizard.v1
|
---|
[345] | 309 |
|
---|
[84] | 310 | @property
|
---|
| 311 | def vr(self):
|
---|
| 312 | """Get the Vr speed calculated for the flight."""
|
---|
| 313 | return self._wizard.vr
|
---|
[345] | 314 |
|
---|
[84] | 315 | @property
|
---|
| 316 | def v2(self):
|
---|
| 317 | """Get the V2 speed calculated for the flight."""
|
---|
| 318 | return self._wizard.v2
|
---|
[345] | 319 |
|
---|
[86] | 320 | @property
|
---|
[384] | 321 | def derate(self):
|
---|
| 322 | """Get the derate value calculated for the flight."""
|
---|
| 323 | return self._wizard.derate
|
---|
| 324 |
|
---|
| 325 | @property
|
---|
[391] | 326 | def takeoffAntiIceOn(self):
|
---|
| 327 | """Get whether the anti-ice system was on during take-off."""
|
---|
| 328 | return self._wizard.takeoffAntiIceOn
|
---|
| 329 |
|
---|
| 330 | @takeoffAntiIceOn.setter
|
---|
| 331 | def takeoffAntiIceOn(self, value):
|
---|
| 332 | """Set the anti-ice on indicator."""
|
---|
| 333 | gobject.idle_add(self._setTakeoffAntiIceOn, value)
|
---|
| 334 |
|
---|
| 335 | @property
|
---|
[349] | 336 | def rtoIndicated(self):
|
---|
| 337 | """Get whether the pilot has indicated than an RTO has occured."""
|
---|
| 338 | return self._wizard.rtoIndicated
|
---|
| 339 |
|
---|
| 340 | @property
|
---|
[97] | 341 | def arrivalRunway(self):
|
---|
| 342 | """Get the arrival runway."""
|
---|
| 343 | return self._wizard.arrivalRunway
|
---|
| 344 |
|
---|
| 345 | @property
|
---|
| 346 | def star(self):
|
---|
| 347 | """Get the STAR."""
|
---|
| 348 | return self._wizard.star
|
---|
| 349 |
|
---|
| 350 | @property
|
---|
| 351 | def transition(self):
|
---|
| 352 | """Get the transition."""
|
---|
| 353 | return self._wizard.transition
|
---|
| 354 |
|
---|
| 355 | @property
|
---|
| 356 | def approachType(self):
|
---|
| 357 | """Get the approach type."""
|
---|
| 358 | return self._wizard.approachType
|
---|
| 359 |
|
---|
| 360 | @property
|
---|
[86] | 361 | def vref(self):
|
---|
| 362 | """Get the Vref speed calculated for the flight."""
|
---|
| 363 | return self._wizard.vref
|
---|
[345] | 364 |
|
---|
[97] | 365 | @property
|
---|
[391] | 366 | def landingAntiIceOn(self):
|
---|
| 367 | """Get whether the anti-ice system was on during landing."""
|
---|
| 368 | return self._wizard.landingAntiIceOn
|
---|
| 369 |
|
---|
| 370 | @landingAntiIceOn.setter
|
---|
| 371 | def landingAntiIceOn(self, value):
|
---|
| 372 | """Set the anti-ice on indicator."""
|
---|
| 373 | gobject.idle_add(self._setLandingAntiIceOn, value)
|
---|
| 374 |
|
---|
| 375 | @property
|
---|
[97] | 376 | def flightType(self):
|
---|
| 377 | """Get the flight type."""
|
---|
| 378 | return self._wizard.flightType
|
---|
| 379 |
|
---|
| 380 | @property
|
---|
| 381 | def online(self):
|
---|
| 382 | """Get whether the flight was online or not."""
|
---|
| 383 | return self._wizard.online
|
---|
| 384 |
|
---|
| 385 | @property
|
---|
| 386 | def comments(self):
|
---|
| 387 | """Get the comments."""
|
---|
| 388 | return self._flightInfo.comments
|
---|
| 389 |
|
---|
| 390 | @property
|
---|
[349] | 391 | def hasComments(self):
|
---|
| 392 | """Indicate whether there is a comment."""
|
---|
| 393 | return self._flightInfo.hasComments
|
---|
| 394 |
|
---|
| 395 | @property
|
---|
[97] | 396 | def flightDefects(self):
|
---|
| 397 | """Get the flight defects."""
|
---|
| 398 | return self._flightInfo.flightDefects
|
---|
| 399 |
|
---|
[99] | 400 | @property
|
---|
| 401 | def delayCodes(self):
|
---|
| 402 | """Get the delay codes."""
|
---|
| 403 | return self._flightInfo.delayCodes
|
---|
| 404 |
|
---|
[28] | 405 | def run(self):
|
---|
| 406 | """Run the GUI."""
|
---|
[42] | 407 | if self.config.autoUpdate:
|
---|
[38] | 408 | self._updater = Updater(self,
|
---|
| 409 | self._programDirectory,
|
---|
[42] | 410 | self.config.updateURL,
|
---|
[36] | 411 | self._mainWindow)
|
---|
| 412 | self._updater.start()
|
---|
[345] | 413 |
|
---|
[182] | 414 | singleton.raiseCallback = self.raiseCallback
|
---|
[28] | 415 | gtk.main()
|
---|
[182] | 416 | singleton.raiseCallback = None
|
---|
[36] | 417 |
|
---|
[91] | 418 | self._disconnect()
|
---|
[28] | 419 |
|
---|
| 420 | def connected(self, fsType, descriptor):
|
---|
| 421 | """Called when we have connected to the simulator."""
|
---|
| 422 | self._connected = True
|
---|
[241] | 423 | self._logger.untimedMessage("MLX %s connected to the simulator %s" % \
|
---|
| 424 | (const.VERSION, descriptor))
|
---|
[133] | 425 | fs.sendMessage(const.MESSAGETYPE_INFORMATION,
|
---|
| 426 | "Welcome to MAVA Logger X " + const.VERSION)
|
---|
[59] | 427 | gobject.idle_add(self._handleConnected, fsType, descriptor)
|
---|
| 428 |
|
---|
| 429 | def _handleConnected(self, fsType, descriptor):
|
---|
| 430 | """Called when the connection to the simulator has succeeded."""
|
---|
| 431 | self._statusbar.updateConnection(self._connecting, self._connected)
|
---|
| 432 | self.endBusy()
|
---|
| 433 | if not self._reconnecting:
|
---|
| 434 | self._wizard.connected(fsType, descriptor)
|
---|
| 435 | self._reconnecting = False
|
---|
[430] | 436 | self._fsType = fsType
|
---|
[168] | 437 | self._listenHotkeys()
|
---|
[59] | 438 |
|
---|
| 439 | def connectionFailed(self):
|
---|
| 440 | """Called when the connection failed."""
|
---|
| 441 | self._logger.untimedMessage("Connection to the simulator failed")
|
---|
| 442 | gobject.idle_add(self._connectionFailed)
|
---|
| 443 |
|
---|
| 444 | def _connectionFailed(self):
|
---|
| 445 | """Called when the connection failed."""
|
---|
| 446 | self.endBusy()
|
---|
| 447 | self._statusbar.updateConnection(self._connecting, self._connected)
|
---|
| 448 |
|
---|
[105] | 449 | dialog = gtk.MessageDialog(parent = self._mainWindow,
|
---|
| 450 | type = MESSAGETYPE_ERROR,
|
---|
[108] | 451 | message_format = xstr("conn_failed"))
|
---|
[345] | 452 |
|
---|
[105] | 453 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
[108] | 454 | dialog.format_secondary_markup(xstr("conn_failed_sec"))
|
---|
[345] | 455 |
|
---|
[108] | 456 | dialog.add_button(xstr("button_cancel"), 0)
|
---|
| 457 | dialog.add_button(xstr("button_tryagain"), 1)
|
---|
[59] | 458 | dialog.set_default_response(1)
|
---|
[345] | 459 |
|
---|
[59] | 460 | result = dialog.run()
|
---|
| 461 | dialog.hide()
|
---|
| 462 | if result == 1:
|
---|
[107] | 463 | self.beginBusy(xstr("connect_busy"))
|
---|
[59] | 464 | self._simulator.reconnect()
|
---|
| 465 | else:
|
---|
[91] | 466 | self.reset()
|
---|
[345] | 467 |
|
---|
[28] | 468 | def disconnected(self):
|
---|
| 469 | """Called when we have disconnected from the simulator."""
|
---|
| 470 | self._connected = False
|
---|
| 471 | self._logger.untimedMessage("Disconnected from the simulator")
|
---|
[59] | 472 |
|
---|
| 473 | gobject.idle_add(self._disconnected)
|
---|
| 474 |
|
---|
| 475 | def _disconnected(self):
|
---|
[345] | 476 | """Called when we have disconnected from the simulator unexpectedly."""
|
---|
[59] | 477 | self._statusbar.updateConnection(self._connecting, self._connected)
|
---|
| 478 |
|
---|
| 479 | dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
|
---|
[108] | 480 | message_format = xstr("conn_broken"),
|
---|
[59] | 481 | parent = self._mainWindow)
|
---|
[105] | 482 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
[108] | 483 | dialog.format_secondary_markup(xstr("conn_broken_sec"))
|
---|
[59] | 484 |
|
---|
[108] | 485 | dialog.add_button(xstr("button_cancel"), 0)
|
---|
| 486 | dialog.add_button(xstr("button_reconnect"), 1)
|
---|
[59] | 487 | dialog.set_default_response(1)
|
---|
| 488 |
|
---|
| 489 | result = dialog.run()
|
---|
| 490 | dialog.hide()
|
---|
| 491 | if result == 1:
|
---|
[108] | 492 | self.beginBusy(xstr("connect_busy"))
|
---|
[59] | 493 | self._reconnecting = True
|
---|
| 494 | self._simulator.reconnect()
|
---|
| 495 | else:
|
---|
[91] | 496 | self.reset()
|
---|
| 497 |
|
---|
[436] | 498 | def enableFlightInfo(self, aircraftType):
|
---|
[93] | 499 | """Enable the flight info tab."""
|
---|
[436] | 500 | self._flightInfo.enable(aircraftType)
|
---|
[93] | 501 |
|
---|
[208] | 502 | def cancelFlight(self):
|
---|
| 503 | """Cancel the current file, if the user confirms it."""
|
---|
| 504 | dialog = gtk.MessageDialog(parent = self._mainWindow,
|
---|
| 505 | type = MESSAGETYPE_QUESTION,
|
---|
| 506 | message_format = xstr("cancelFlight_question"))
|
---|
| 507 |
|
---|
| 508 | dialog.add_button(xstr("button_no"), RESPONSETYPE_NO)
|
---|
| 509 | dialog.add_button(xstr("button_yes"), RESPONSETYPE_YES)
|
---|
| 510 |
|
---|
| 511 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
| 512 | result = dialog.run()
|
---|
| 513 | dialog.hide()
|
---|
[345] | 514 |
|
---|
[208] | 515 | if result==RESPONSETYPE_YES:
|
---|
| 516 | self.reset()
|
---|
| 517 |
|
---|
[91] | 518 | def reset(self):
|
---|
| 519 | """Reset the GUI."""
|
---|
| 520 | self._disconnect()
|
---|
[92] | 521 |
|
---|
[501] | 522 | self._simulator = None
|
---|
| 523 |
|
---|
[91] | 524 | self._flightInfo.reset()
|
---|
[93] | 525 | self._flightInfo.disable()
|
---|
[91] | 526 | self.resetFlightStatus()
|
---|
[28] | 527 |
|
---|
[117] | 528 | self._weightHelp.reset()
|
---|
| 529 | self._weightHelp.disable()
|
---|
[92] | 530 | self._notebook.set_current_page(0)
|
---|
| 531 |
|
---|
| 532 | self._logView.get_buffer().set_text("")
|
---|
| 533 |
|
---|
[215] | 534 | if self.loggedIn:
|
---|
| 535 | self._wizard.reloadFlights(self._handleReloadResult)
|
---|
| 536 | else:
|
---|
| 537 | self._wizard.reset(None)
|
---|
[208] | 538 |
|
---|
| 539 | def _handleReloadResult(self, returned, result):
|
---|
| 540 | """Handle the result of the reloading of the flights."""
|
---|
| 541 | self._wizard.reset(result if returned and result.loggedIn else None)
|
---|
| 542 |
|
---|
[152] | 543 | def _disconnect(self, closingMessage = None, duration = 3):
|
---|
[91] | 544 | """Disconnect from the simulator if connected."""
|
---|
[92] | 545 | self.stopMonitoring()
|
---|
[168] | 546 | self._clearHotkeys()
|
---|
[92] | 547 |
|
---|
[91] | 548 | if self._connected:
|
---|
[152] | 549 | if closingMessage is None:
|
---|
| 550 | self._flight.simulator.disconnect()
|
---|
| 551 | else:
|
---|
| 552 | fs.sendMessage(const.MESSAGETYPE_ENVIRONMENT,
|
---|
| 553 | closingMessage, duration,
|
---|
| 554 | disconnect = True)
|
---|
[91] | 555 | self._connected = False
|
---|
| 556 |
|
---|
| 557 | self._connecting = False
|
---|
| 558 | self._reconnecting = False
|
---|
| 559 | self._statusbar.updateConnection(False, False)
|
---|
[128] | 560 | self._weightHelp.disable()
|
---|
[134] | 561 |
|
---|
| 562 | return True
|
---|
[345] | 563 |
|
---|
| 564 | def insertFlightLogLine(self, index, timestampString, text, isFault):
|
---|
| 565 | """Insert the flight log line with the given data."""
|
---|
| 566 | gobject.idle_add(self._insertFlightLogLine, index,
|
---|
| 567 | formatFlightLogLine(timestampString, text),
|
---|
| 568 | isFault)
|
---|
| 569 |
|
---|
| 570 | def _insertFlightLogLine(self, index, line, isFault):
|
---|
| 571 | """Perform the real insertion.
|
---|
[96] | 572 |
|
---|
[345] | 573 | To be called from the event loop."""
|
---|
| 574 | buffer = self._logView.get_buffer()
|
---|
| 575 | lineIter = buffer.get_iter_at_line(index)
|
---|
| 576 | insertTextBuffer(buffer, lineIter, line, isFault = isFault)
|
---|
| 577 | self._logView.scroll_mark_onscreen(buffer.get_insert())
|
---|
[96] | 578 |
|
---|
[345] | 579 | def removeFlightLogLine(self, index):
|
---|
| 580 | """Remove the flight log line with the given index."""
|
---|
| 581 | gobject.idle_add(self._removeFlightLogLine, index)
|
---|
| 582 |
|
---|
| 583 | def _removeFlightLogLine(self, index):
|
---|
| 584 | """Perform the real removal."""
|
---|
[96] | 585 | buffer = self._logView.get_buffer()
|
---|
| 586 | startIter = buffer.get_iter_at_line(index)
|
---|
[345] | 587 | endIter = buffer.get_iter_at_line(index+1)
|
---|
[96] | 588 | buffer.delete(startIter, endIter)
|
---|
| 589 | self._logView.scroll_mark_onscreen(buffer.get_insert())
|
---|
| 590 |
|
---|
[28] | 591 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
| 592 | """Update the data."""
|
---|
[77] | 593 | gobject.idle_add(self._monitorWindow.setData, state)
|
---|
[80] | 594 | gobject.idle_add(self._statusbar.updateTime, state.timestamp)
|
---|
[28] | 595 |
|
---|
[31] | 596 | def resetFlightStatus(self):
|
---|
| 597 | """Reset the status of the flight."""
|
---|
[32] | 598 | self._statusbar.resetFlightStatus()
|
---|
[80] | 599 | self._statusbar.updateTime()
|
---|
[31] | 600 | self._statusIcon.resetFlightStatus()
|
---|
| 601 |
|
---|
| 602 | def setStage(self, stage):
|
---|
| 603 | """Set the stage of the flight."""
|
---|
| 604 | gobject.idle_add(self._setStage, stage)
|
---|
| 605 |
|
---|
| 606 | def _setStage(self, stage):
|
---|
| 607 | """Set the stage of the flight."""
|
---|
[32] | 608 | self._statusbar.setStage(stage)
|
---|
[31] | 609 | self._statusIcon.setStage(stage)
|
---|
[84] | 610 | self._wizard.setStage(stage)
|
---|
[88] | 611 | if stage==const.STAGE_END:
|
---|
[261] | 612 | welcomeMessage = \
|
---|
| 613 | airports.getWelcomeMessage(self.bookedFlight.arrivalICAO)
|
---|
[152] | 614 | self._disconnect(closingMessage =
|
---|
[261] | 615 | "Flight plan closed. " + welcomeMessage,
|
---|
[152] | 616 | duration = 5)
|
---|
[31] | 617 |
|
---|
| 618 | def setRating(self, rating):
|
---|
| 619 | """Set the rating of the flight."""
|
---|
| 620 | gobject.idle_add(self._setRating, rating)
|
---|
| 621 |
|
---|
| 622 | def _setRating(self, rating):
|
---|
| 623 | """Set the rating of the flight."""
|
---|
[32] | 624 | self._statusbar.setRating(rating)
|
---|
[31] | 625 | self._statusIcon.setRating(rating)
|
---|
| 626 |
|
---|
| 627 | def setNoGo(self, reason):
|
---|
| 628 | """Set the rating of the flight to No-Go with the given reason."""
|
---|
| 629 | gobject.idle_add(self._setNoGo, reason)
|
---|
| 630 |
|
---|
| 631 | def _setNoGo(self, reason):
|
---|
| 632 | """Set the rating of the flight."""
|
---|
[32] | 633 | self._statusbar.setNoGo(reason)
|
---|
[31] | 634 | self._statusIcon.setNoGo(reason)
|
---|
| 635 |
|
---|
[29] | 636 | def _handleMainWindowState(self, window, event):
|
---|
| 637 | """Hande a change in the state of the window"""
|
---|
| 638 | iconified = gdk.WindowState.ICONIFIED if pygobject \
|
---|
| 639 | else gdk.WINDOW_STATE_ICONIFIED
|
---|
[246] | 640 |
|
---|
| 641 | if (event.changed_mask&WINDOW_STATE_WITHDRAWN)!=0:
|
---|
| 642 | if (event.new_window_state&WINDOW_STATE_WITHDRAWN)!=0:
|
---|
| 643 | self._statusIcon.mainWindowHidden()
|
---|
| 644 | else:
|
---|
| 645 | self._statusIcon.mainWindowShown()
|
---|
| 646 |
|
---|
| 647 | if self.config.hideMinimizedWindow and not pygobject and \
|
---|
| 648 | (event.changed_mask&WINDOW_STATE_ICONIFIED)!=0 and \
|
---|
| 649 | (event.new_window_state&WINDOW_STATE_ICONIFIED)!=0:
|
---|
[35] | 650 | self.hideMainWindow(savePosition = False)
|
---|
[246] | 651 | elif (event.changed_mask&WINDOW_STATE_ICONIFIED)!=0 and \
|
---|
| 652 | (event.new_window_state&WINDOW_STATE_ICONIFIED)==0:
|
---|
| 653 | self._mainWindow.present()
|
---|
[345] | 654 |
|
---|
[182] | 655 | def raiseCallback(self):
|
---|
| 656 | """Callback for the singleton handling code."""
|
---|
| 657 | gobject.idle_add(self.raiseMainWindow)
|
---|
| 658 |
|
---|
| 659 | def raiseMainWindow(self):
|
---|
[246] | 660 | """Show the main window if invisible, and raise it."""
|
---|
[182] | 661 | if not self._mainWindow.get_visible():
|
---|
| 662 | self.showMainWindow()
|
---|
| 663 | self._mainWindow.present()
|
---|
| 664 |
|
---|
[249] | 665 | def deleteMainWindow(self, window, event):
|
---|
| 666 | """Handle the delete event for the main window."""
|
---|
| 667 | if self.config.quitOnClose:
|
---|
| 668 | self._quit()
|
---|
| 669 | else:
|
---|
| 670 | self.hideMainWindow()
|
---|
| 671 | return True
|
---|
| 672 |
|
---|
[35] | 673 | def hideMainWindow(self, savePosition = True):
|
---|
[29] | 674 | """Hide the main window and save its position."""
|
---|
[35] | 675 | if savePosition:
|
---|
| 676 | (self._mainWindowX, self._mainWindowY) = \
|
---|
| 677 | self._mainWindow.get_window().get_root_origin()
|
---|
| 678 | else:
|
---|
| 679 | self._mainWindowX = self._mainWindowY = None
|
---|
[29] | 680 | self._mainWindow.hide()
|
---|
| 681 | return True
|
---|
| 682 |
|
---|
| 683 | def showMainWindow(self):
|
---|
| 684 | """Show the main window at its former position."""
|
---|
[35] | 685 | if self._mainWindowX is not None and self._mainWindowY is not None:
|
---|
| 686 | self._mainWindow.move(self._mainWindowX, self._mainWindowY)
|
---|
| 687 |
|
---|
[246] | 688 | if pygobject:
|
---|
| 689 | self._mainWindow.show()
|
---|
| 690 | else:
|
---|
| 691 | self._mainWindow.present()
|
---|
[29] | 692 | self._mainWindow.deiconify()
|
---|
[345] | 693 |
|
---|
[29] | 694 | def toggleMainWindow(self):
|
---|
| 695 | """Toggle the main window."""
|
---|
| 696 | if self._mainWindow.get_visible():
|
---|
| 697 | self.hideMainWindow()
|
---|
| 698 | else:
|
---|
| 699 | self.showMainWindow()
|
---|
[36] | 700 |
|
---|
[77] | 701 | def hideMonitorWindow(self, savePosition = True):
|
---|
| 702 | """Hide the monitor window."""
|
---|
| 703 | if savePosition:
|
---|
| 704 | (self._monitorWindowX, self._monitorWindowY) = \
|
---|
| 705 | self._monitorWindow.get_window().get_root_origin()
|
---|
| 706 | else:
|
---|
| 707 | self._monitorWindowX = self._monitorWindowY = None
|
---|
| 708 | self._monitorWindow.hide()
|
---|
| 709 | self._statusIcon.monitorWindowHidden()
|
---|
[93] | 710 | if self._showMonitorMenuItem.get_active():
|
---|
| 711 | self._selfToggling = True
|
---|
| 712 | self._showMonitorMenuItem.set_active(False)
|
---|
[77] | 713 | return True
|
---|
| 714 |
|
---|
| 715 | def showMonitorWindow(self):
|
---|
| 716 | """Show the monitor window."""
|
---|
| 717 | if self._monitorWindowX is not None and self._monitorWindowY is not None:
|
---|
| 718 | self._monitorWindow.move(self._monitorWindowX, self._monitorWindowY)
|
---|
| 719 | self._monitorWindow.show_all()
|
---|
| 720 | self._statusIcon.monitorWindowShown()
|
---|
[93] | 721 | if not self._showMonitorMenuItem.get_active():
|
---|
| 722 | self._selfToggling = True
|
---|
| 723 | self._showMonitorMenuItem.set_active(True)
|
---|
| 724 |
|
---|
| 725 | def _toggleMonitorWindow(self, menuItem):
|
---|
| 726 | if self._selfToggling:
|
---|
| 727 | self._selfToggling = False
|
---|
| 728 | elif self._monitorWindow.get_visible():
|
---|
| 729 | self.hideMonitorWindow()
|
---|
| 730 | else:
|
---|
| 731 | self.showMonitorWindow()
|
---|
[77] | 732 |
|
---|
[38] | 733 | def restart(self):
|
---|
| 734 | """Quit and restart the application."""
|
---|
| 735 | self.toRestart = True
|
---|
[81] | 736 | self._quit(force = True)
|
---|
[38] | 737 |
|
---|
| 738 | def flushStdIO(self):
|
---|
| 739 | """Flush any text to the standard error that could not be logged."""
|
---|
| 740 | if self._stdioText:
|
---|
| 741 | sys.__stderr__.write(self._stdioText)
|
---|
[345] | 742 |
|
---|
[36] | 743 | def writeStdIO(self, text):
|
---|
| 744 | """Write the given text into standard I/O log."""
|
---|
[38] | 745 | with self._stdioLock:
|
---|
| 746 | self._stdioText += text
|
---|
| 747 |
|
---|
| 748 | gobject.idle_add(self._writeStdIO)
|
---|
[36] | 749 |
|
---|
[49] | 750 | def beginBusy(self, message):
|
---|
| 751 | """Begin a period of background processing."""
|
---|
[93] | 752 | self._wizard.set_sensitive(False)
|
---|
[117] | 753 | self._weightHelp.set_sensitive(False)
|
---|
[49] | 754 | self._mainWindow.get_window().set_cursor(self._busyCursor)
|
---|
| 755 | self._statusbar.updateBusyState(message)
|
---|
| 756 |
|
---|
| 757 | def endBusy(self):
|
---|
| 758 | """End a period of background processing."""
|
---|
| 759 | self._mainWindow.get_window().set_cursor(None)
|
---|
[117] | 760 | self._weightHelp.set_sensitive(True)
|
---|
[93] | 761 | self._wizard.set_sensitive(True)
|
---|
[49] | 762 | self._statusbar.updateBusyState(None)
|
---|
| 763 |
|
---|
[117] | 764 | def initializeWeightHelp(self):
|
---|
| 765 | """Initialize the weight help tab."""
|
---|
| 766 | self._weightHelp.reset()
|
---|
| 767 | self._weightHelp.enable()
|
---|
| 768 |
|
---|
[134] | 769 | def getFleetAsync(self, callback = None, force = None):
|
---|
| 770 | """Get the fleet asynchronously."""
|
---|
| 771 | gobject.idle_add(self.getFleet, callback, force)
|
---|
| 772 |
|
---|
[119] | 773 | def getFleet(self, callback = None, force = False):
|
---|
| 774 | """Get the fleet.
|
---|
| 775 |
|
---|
| 776 | If force is False, and we already have a fleet retrieved,
|
---|
| 777 | that one will be used."""
|
---|
| 778 | if self._fleet is None or force:
|
---|
| 779 | self._fleetCallback = callback
|
---|
| 780 | self.beginBusy(xstr("fleet_busy"))
|
---|
| 781 | self.webHandler.getFleet(self._fleetResultCallback)
|
---|
| 782 | else:
|
---|
| 783 | callback(self._fleet)
|
---|
| 784 |
|
---|
[349] | 785 | def updateRTO(self, inLoop = False):
|
---|
| 786 | """Indicate that the RTO state should be updated."""
|
---|
| 787 | if inLoop:
|
---|
| 788 | self._wizard.updateRTO()
|
---|
| 789 | else:
|
---|
| 790 | gobject.idle_add(self.updateRTO, True)
|
---|
| 791 |
|
---|
| 792 | def rtoToggled(self, indicated):
|
---|
| 793 | """Called when the user has toggled the RTO checkbox."""
|
---|
| 794 | self._flight.rtoToggled(indicated)
|
---|
| 795 |
|
---|
[119] | 796 | def _fleetResultCallback(self, returned, result):
|
---|
| 797 | """Called when the fleet has been queried."""
|
---|
| 798 | gobject.idle_add(self._handleFleetResult, returned, result)
|
---|
| 799 |
|
---|
| 800 | def _handleFleetResult(self, returned, result):
|
---|
| 801 | """Handle the fleet result."""
|
---|
| 802 | self.endBusy()
|
---|
| 803 | if returned:
|
---|
| 804 | self._fleet = result.fleet
|
---|
| 805 | else:
|
---|
| 806 | self._fleet = None
|
---|
| 807 |
|
---|
[120] | 808 | dialog = gtk.MessageDialog(parent = self.mainWindow,
|
---|
[119] | 809 | type = MESSAGETYPE_ERROR,
|
---|
| 810 | message_format = xstr("fleet_failed"))
|
---|
[130] | 811 | dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK)
|
---|
| 812 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
| 813 | dialog.run()
|
---|
| 814 | dialog.hide()
|
---|
| 815 |
|
---|
| 816 | callback = self._fleetCallback
|
---|
| 817 | self._fleetCallback = None
|
---|
| 818 | if callback is not None:
|
---|
| 819 | callback(self._fleet)
|
---|
| 820 | self._fleetGateStatus.handleFleet(self._fleet)
|
---|
| 821 |
|
---|
| 822 | def updatePlane(self, tailNumber, status,
|
---|
| 823 | gateNumber = None, callback = None):
|
---|
| 824 | """Update the status of the given plane."""
|
---|
| 825 | self.beginBusy(xstr("fleet_update_busy"))
|
---|
| 826 |
|
---|
| 827 | self._updatePlaneCallback = callback
|
---|
| 828 |
|
---|
| 829 | self._updatePlaneTailNumber = tailNumber
|
---|
| 830 | self._updatePlaneStatus = status
|
---|
| 831 | self._updatePlaneGateNumber = gateNumber
|
---|
[345] | 832 |
|
---|
[130] | 833 | self.webHandler.updatePlane(self._updatePlaneResultCallback,
|
---|
| 834 | tailNumber, status, gateNumber)
|
---|
| 835 |
|
---|
| 836 | def _updatePlaneResultCallback(self, returned, result):
|
---|
| 837 | """Called when the status of a plane has been updated."""
|
---|
| 838 | gobject.idle_add(self._handleUpdatePlaneResult, returned, result)
|
---|
| 839 |
|
---|
| 840 | def _handleUpdatePlaneResult(self, returned, result):
|
---|
| 841 | """Handle the plane update result."""
|
---|
| 842 | self.endBusy()
|
---|
| 843 | if returned:
|
---|
| 844 | success = result.success
|
---|
| 845 | if success:
|
---|
| 846 | if self._fleet is not None:
|
---|
| 847 | self._fleet.updatePlane(self._updatePlaneTailNumber,
|
---|
| 848 | self._updatePlaneStatus,
|
---|
| 849 | self._updatePlaneGateNumber)
|
---|
| 850 | self._fleetGateStatus.handleFleet(self._fleet)
|
---|
| 851 | else:
|
---|
| 852 | dialog = gtk.MessageDialog(parent = self.mainWindow,
|
---|
| 853 | type = MESSAGETYPE_ERROR,
|
---|
| 854 | message_format = xstr("fleet_update_failed"))
|
---|
[124] | 855 | dialog.add_button(xstr("button_ok"), RESPONSETYPE_ACCEPT)
|
---|
[119] | 856 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
| 857 | dialog.run()
|
---|
| 858 | dialog.hide()
|
---|
| 859 |
|
---|
[130] | 860 | success = None
|
---|
| 861 |
|
---|
| 862 | callback = self._updatePlaneCallback
|
---|
| 863 | self._updatePlaneCallback = None
|
---|
| 864 | if callback is not None:
|
---|
| 865 | callback(success)
|
---|
[119] | 866 |
|
---|
[38] | 867 | def _writeStdIO(self):
|
---|
[36] | 868 | """Perform the real writing."""
|
---|
[38] | 869 | with self._stdioLock:
|
---|
| 870 | text = self._stdioText
|
---|
| 871 | self._stdioText = ""
|
---|
| 872 | if not text: return
|
---|
[345] | 873 |
|
---|
[36] | 874 | lines = text.splitlines()
|
---|
| 875 | if text[-1]=="\n":
|
---|
| 876 | text = ""
|
---|
| 877 | else:
|
---|
| 878 | text = lines[-1]
|
---|
| 879 | lines = lines[:-1]
|
---|
[203] | 880 |
|
---|
| 881 | now = datetime.datetime.now()
|
---|
| 882 | timeStr = "%02d:%02d:%02d: " % (now.hour, now.minute, now.second)
|
---|
[345] | 883 |
|
---|
[36] | 884 | for line in lines:
|
---|
[96] | 885 | #print >> sys.__stdout__, line
|
---|
[203] | 886 | if self._stdioStartingLine:
|
---|
| 887 | self._writeLog(timeStr, self._debugLogView)
|
---|
[93] | 888 | self._writeLog(line + "\n", self._debugLogView)
|
---|
[203] | 889 | self._stdioStartingLine = True
|
---|
[36] | 890 |
|
---|
| 891 | if text:
|
---|
[96] | 892 | #print >> sys.__stdout__, text,
|
---|
[203] | 893 | if self._stdioStartingLine:
|
---|
| 894 | self._writeLog(timeStr, self._debugLogView)
|
---|
[93] | 895 | self._writeLog(text, self._debugLogView)
|
---|
[203] | 896 | self._stdioStartingLine = False
|
---|
[51] | 897 |
|
---|
[501] | 898 | def connectSimulator(self, aircraftType, simulatorType):
|
---|
[59] | 899 | """Connect to the simulator for the first time."""
|
---|
| 900 | self._logger.reset()
|
---|
| 901 |
|
---|
| 902 | self._flight = flight.Flight(self._logger, self)
|
---|
[131] | 903 | self._flight.flareTimeFromFS = self.config.flareTimeFromFS
|
---|
[59] | 904 | self._flight.aircraftType = aircraftType
|
---|
| 905 | self._flight.aircraft = acft.Aircraft.create(self._flight)
|
---|
| 906 | self._flight.aircraft._checkers.append(self)
|
---|
[345] | 907 |
|
---|
[59] | 908 | if self._simulator is None:
|
---|
[501] | 909 | self._simulator = fs.createSimulator(simulatorType, self)
|
---|
[133] | 910 | fs.setupMessageSending(self.config, self._simulator)
|
---|
[148] | 911 | self._setupTimeSync()
|
---|
[345] | 912 |
|
---|
[59] | 913 | self._flight.simulator = self._simulator
|
---|
| 914 |
|
---|
[107] | 915 | self.beginBusy(xstr("connect_busy"))
|
---|
[59] | 916 | self._statusbar.updateConnection(self._connecting, self._connected)
|
---|
| 917 |
|
---|
| 918 | self._connecting = True
|
---|
[345] | 919 | self._simulator.connect(self._flight.aircraft)
|
---|
[59] | 920 |
|
---|
[70] | 921 | def startMonitoring(self):
|
---|
| 922 | """Start monitoring."""
|
---|
[88] | 923 | if not self._monitoring:
|
---|
| 924 | self.simulator.startMonitoring()
|
---|
| 925 | self._monitoring = True
|
---|
[70] | 926 |
|
---|
| 927 | def stopMonitoring(self):
|
---|
| 928 | """Stop monitoring."""
|
---|
[88] | 929 | if self._monitoring:
|
---|
| 930 | self.simulator.stopMonitoring()
|
---|
| 931 | self._monitoring = False
|
---|
[70] | 932 |
|
---|
[304] | 933 | def cruiseLevelChanged(self):
|
---|
| 934 | """Called when the cruise level is changed in the flight wizard."""
|
---|
| 935 | if self._flight is not None:
|
---|
[383] | 936 | return self._flight.cruiseLevelChanged()
|
---|
| 937 | else:
|
---|
| 938 | return False
|
---|
[304] | 939 |
|
---|
[93] | 940 | def _buildMenuBar(self, accelGroup):
|
---|
| 941 | """Build the main menu bar."""
|
---|
| 942 | menuBar = gtk.MenuBar()
|
---|
[345] | 943 |
|
---|
[110] | 944 | fileMenuItem = gtk.MenuItem(xstr("menu_file"))
|
---|
[93] | 945 | fileMenu = gtk.Menu()
|
---|
| 946 | fileMenuItem.set_submenu(fileMenu)
|
---|
| 947 | menuBar.append(fileMenuItem)
|
---|
| 948 |
|
---|
[151] | 949 | loadPIREPMenuItem = gtk.ImageMenuItem(gtk.STOCK_OPEN)
|
---|
| 950 | loadPIREPMenuItem.set_use_stock(True)
|
---|
| 951 | loadPIREPMenuItem.set_label(xstr("menu_file_loadPIREP"))
|
---|
| 952 | loadPIREPMenuItem.add_accelerator("activate", accelGroup,
|
---|
| 953 | ord(xstr("menu_file_loadPIREP_key")),
|
---|
| 954 | CONTROL_MASK, ACCEL_VISIBLE)
|
---|
| 955 | loadPIREPMenuItem.connect("activate", self._loadPIREP)
|
---|
| 956 | fileMenu.append(loadPIREPMenuItem)
|
---|
| 957 |
|
---|
| 958 | fileMenu.append(gtk.SeparatorMenuItem())
|
---|
| 959 |
|
---|
[93] | 960 | quitMenuItem = gtk.ImageMenuItem(gtk.STOCK_QUIT)
|
---|
| 961 | quitMenuItem.set_use_stock(True)
|
---|
[110] | 962 | quitMenuItem.set_label(xstr("menu_file_quit"))
|
---|
[93] | 963 | quitMenuItem.add_accelerator("activate", accelGroup,
|
---|
[110] | 964 | ord(xstr("menu_file_quit_key")),
|
---|
| 965 | CONTROL_MASK, ACCEL_VISIBLE)
|
---|
[93] | 966 | quitMenuItem.connect("activate", self._quit)
|
---|
| 967 | fileMenu.append(quitMenuItem)
|
---|
| 968 |
|
---|
[123] | 969 | toolsMenuItem = gtk.MenuItem(xstr("menu_tools"))
|
---|
| 970 | toolsMenu = gtk.Menu()
|
---|
| 971 | toolsMenuItem.set_submenu(toolsMenu)
|
---|
| 972 | menuBar.append(toolsMenuItem)
|
---|
| 973 |
|
---|
[204] | 974 | checklistMenuItem = gtk.ImageMenuItem(gtk.STOCK_APPLY)
|
---|
[172] | 975 | checklistMenuItem.set_use_stock(True)
|
---|
| 976 | checklistMenuItem.set_label(xstr("menu_tools_chklst"))
|
---|
| 977 | checklistMenuItem.add_accelerator("activate", accelGroup,
|
---|
| 978 | ord(xstr("menu_tools_chklst_key")),
|
---|
| 979 | CONTROL_MASK, ACCEL_VISIBLE)
|
---|
| 980 | checklistMenuItem.connect("activate", self._editChecklist)
|
---|
| 981 | toolsMenu.append(checklistMenuItem)
|
---|
| 982 |
|
---|
[264] | 983 | approachCalloutsMenuItem = gtk.ImageMenuItem(gtk.STOCK_EDIT)
|
---|
| 984 | approachCalloutsMenuItem.set_use_stock(True)
|
---|
| 985 | approachCalloutsMenuItem.set_label(xstr("menu_tools_callouts"))
|
---|
| 986 | approachCalloutsMenuItem.add_accelerator("activate", accelGroup,
|
---|
| 987 | ord(xstr("menu_tools_callouts_key")),
|
---|
| 988 | CONTROL_MASK, ACCEL_VISIBLE)
|
---|
| 989 | approachCalloutsMenuItem.connect("activate", self._editApproachCallouts)
|
---|
| 990 | toolsMenu.append(approachCalloutsMenuItem)
|
---|
| 991 |
|
---|
[204] | 992 | prefsMenuItem = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES)
|
---|
[123] | 993 | prefsMenuItem.set_use_stock(True)
|
---|
| 994 | prefsMenuItem.set_label(xstr("menu_tools_prefs"))
|
---|
| 995 | prefsMenuItem.add_accelerator("activate", accelGroup,
|
---|
| 996 | ord(xstr("menu_tools_prefs_key")),
|
---|
| 997 | CONTROL_MASK, ACCEL_VISIBLE)
|
---|
| 998 | prefsMenuItem.connect("activate", self._editPreferences)
|
---|
| 999 | toolsMenu.append(prefsMenuItem)
|
---|
[93] | 1000 |
|
---|
[482] | 1001 | toolsMenu.append(gtk.SeparatorMenuItem())
|
---|
| 1002 |
|
---|
| 1003 | bugReportMenuItem = gtk.ImageMenuItem(gtk.STOCK_PASTE)
|
---|
| 1004 | bugReportMenuItem.set_use_stock(True)
|
---|
| 1005 | bugReportMenuItem.set_label(xstr("menu_tools_bugreport"))
|
---|
| 1006 | bugReportMenuItem.add_accelerator("activate", accelGroup,
|
---|
| 1007 | ord(xstr("menu_tools_bugreport_key")),
|
---|
| 1008 | CONTROL_MASK, ACCEL_VISIBLE)
|
---|
| 1009 | bugReportMenuItem.connect("activate", self._reportBug)
|
---|
| 1010 | toolsMenu.append(bugReportMenuItem)
|
---|
| 1011 |
|
---|
[110] | 1012 | viewMenuItem = gtk.MenuItem(xstr("menu_view"))
|
---|
[93] | 1013 | viewMenu = gtk.Menu()
|
---|
| 1014 | viewMenuItem.set_submenu(viewMenu)
|
---|
| 1015 | menuBar.append(viewMenuItem)
|
---|
[28] | 1016 |
|
---|
[93] | 1017 | self._showMonitorMenuItem = gtk.CheckMenuItem()
|
---|
[110] | 1018 | self._showMonitorMenuItem.set_label(xstr("menu_view_monitor"))
|
---|
[93] | 1019 | self._showMonitorMenuItem.set_use_underline(True)
|
---|
| 1020 | self._showMonitorMenuItem.set_active(False)
|
---|
| 1021 | self._showMonitorMenuItem.add_accelerator("activate", accelGroup,
|
---|
[110] | 1022 | ord(xstr("menu_view_monitor_key")),
|
---|
| 1023 | CONTROL_MASK, ACCEL_VISIBLE)
|
---|
[93] | 1024 | self._showMonitorMenuItem.connect("toggled", self._toggleMonitorWindow)
|
---|
| 1025 | viewMenu.append(self._showMonitorMenuItem)
|
---|
| 1026 |
|
---|
| 1027 | showDebugMenuItem = gtk.CheckMenuItem()
|
---|
[110] | 1028 | showDebugMenuItem.set_label(xstr("menu_view_debug"))
|
---|
[93] | 1029 | showDebugMenuItem.set_use_underline(True)
|
---|
| 1030 | showDebugMenuItem.set_active(False)
|
---|
| 1031 | showDebugMenuItem.add_accelerator("activate", accelGroup,
|
---|
[110] | 1032 | ord(xstr("menu_view_debug_key")),
|
---|
| 1033 | CONTROL_MASK, ACCEL_VISIBLE)
|
---|
[93] | 1034 | showDebugMenuItem.connect("toggled", self._toggleDebugLog)
|
---|
| 1035 | viewMenu.append(showDebugMenuItem)
|
---|
[28] | 1036 |
|
---|
[227] | 1037 | helpMenuItem = gtk.MenuItem(xstr("menu_help"))
|
---|
| 1038 | helpMenu = gtk.Menu()
|
---|
| 1039 | helpMenuItem.set_submenu(helpMenu)
|
---|
| 1040 | menuBar.append(helpMenuItem)
|
---|
| 1041 |
|
---|
| 1042 | manualMenuItem = gtk.ImageMenuItem(gtk.STOCK_HELP)
|
---|
| 1043 | manualMenuItem.set_use_stock(True)
|
---|
| 1044 | manualMenuItem.set_label(xstr("menu_help_manual"))
|
---|
| 1045 | manualMenuItem.add_accelerator("activate", accelGroup,
|
---|
| 1046 | ord(xstr("menu_help_manual_key")),
|
---|
| 1047 | CONTROL_MASK, ACCEL_VISIBLE)
|
---|
| 1048 | manualMenuItem.connect("activate", self._showManual)
|
---|
| 1049 | helpMenu.append(manualMenuItem)
|
---|
| 1050 |
|
---|
| 1051 | helpMenu.append(gtk.SeparatorMenuItem())
|
---|
[345] | 1052 |
|
---|
[227] | 1053 | aboutMenuItem = gtk.ImageMenuItem(gtk.STOCK_ABOUT)
|
---|
| 1054 | aboutMenuItem.set_use_stock(True)
|
---|
| 1055 | aboutMenuItem.set_label(xstr("menu_help_about"))
|
---|
| 1056 | aboutMenuItem.add_accelerator("activate", accelGroup,
|
---|
| 1057 | ord(xstr("menu_help_about_key")),
|
---|
| 1058 | CONTROL_MASK, ACCEL_VISIBLE)
|
---|
| 1059 | aboutMenuItem.connect("activate", self._showAbout)
|
---|
| 1060 | helpMenu.append(aboutMenuItem)
|
---|
| 1061 |
|
---|
[93] | 1062 | return menuBar
|
---|
[28] | 1063 |
|
---|
[93] | 1064 | def _toggleDebugLog(self, menuItem):
|
---|
| 1065 | """Toggle the debug log."""
|
---|
| 1066 | if menuItem.get_active():
|
---|
[107] | 1067 | label = gtk.Label(xstr("tab_debug_log"))
|
---|
[93] | 1068 | label.set_use_underline(True)
|
---|
[345] | 1069 | label.set_tooltip_text(xstr("tab_debug_log_tooltip"))
|
---|
[93] | 1070 | self._debugLogPage = self._notebook.append_page(self._debugLogWidget, label)
|
---|
| 1071 | self._notebook.set_current_page(self._debugLogPage)
|
---|
| 1072 | else:
|
---|
| 1073 | self._notebook.remove_page(self._debugLogPage)
|
---|
| 1074 |
|
---|
| 1075 | def _buildLogWidget(self):
|
---|
| 1076 | """Build the widget for the log."""
|
---|
| 1077 | alignment = gtk.Alignment(xscale = 1.0, yscale = 1.0)
|
---|
| 1078 |
|
---|
| 1079 | alignment.set_padding(padding_top = 8, padding_bottom = 8,
|
---|
| 1080 | padding_left = 16, padding_right = 16)
|
---|
[28] | 1081 |
|
---|
| 1082 | logScroller = gtk.ScrolledWindow()
|
---|
[93] | 1083 | # FIXME: these should be constants in common
|
---|
| 1084 | logScroller.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
|
---|
| 1085 | else gtk.POLICY_AUTOMATIC,
|
---|
| 1086 | gtk.PolicyType.AUTOMATIC if pygobject
|
---|
| 1087 | else gtk.POLICY_AUTOMATIC)
|
---|
| 1088 | logScroller.set_shadow_type(gtk.ShadowType.IN if pygobject
|
---|
| 1089 | else gtk.SHADOW_IN)
|
---|
| 1090 | logView = gtk.TextView()
|
---|
| 1091 | logView.set_editable(False)
|
---|
[171] | 1092 | logView.set_cursor_visible(False)
|
---|
[93] | 1093 | logScroller.add(logView)
|
---|
[28] | 1094 |
|
---|
| 1095 | logBox = gtk.VBox()
|
---|
| 1096 | logBox.pack_start(logScroller, True, True, 0)
|
---|
| 1097 | logBox.set_size_request(-1, 200)
|
---|
| 1098 |
|
---|
[93] | 1099 | alignment.add(logBox)
|
---|
[28] | 1100 |
|
---|
[93] | 1101 | return (alignment, logView)
|
---|
[28] | 1102 |
|
---|
[226] | 1103 | def _writeLog(self, msg, logView, isFault = False):
|
---|
[28] | 1104 | """Write the given message to the log."""
|
---|
[93] | 1105 | buffer = logView.get_buffer()
|
---|
[226] | 1106 | appendTextBuffer(buffer, msg, isFault = isFault)
|
---|
[93] | 1107 | logView.scroll_mark_onscreen(buffer.get_insert())
|
---|
[28] | 1108 |
|
---|
[81] | 1109 | def _quit(self, what = None, force = False):
|
---|
[38] | 1110 | """Quit from the application."""
|
---|
[81] | 1111 | if force:
|
---|
| 1112 | result=RESPONSETYPE_YES
|
---|
| 1113 | else:
|
---|
[105] | 1114 | dialog = gtk.MessageDialog(parent = self._mainWindow,
|
---|
| 1115 | type = MESSAGETYPE_QUESTION,
|
---|
[110] | 1116 | message_format = xstr("quit_question"))
|
---|
| 1117 |
|
---|
[124] | 1118 | dialog.add_button(xstr("button_no"), RESPONSETYPE_NO)
|
---|
| 1119 | dialog.add_button(xstr("button_yes"), RESPONSETYPE_YES)
|
---|
| 1120 |
|
---|
[105] | 1121 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
[81] | 1122 | result = dialog.run()
|
---|
| 1123 | dialog.hide()
|
---|
[345] | 1124 |
|
---|
[76] | 1125 | if result==RESPONSETYPE_YES:
|
---|
| 1126 | self._statusIcon.destroy()
|
---|
| 1127 | return gtk.main_quit()
|
---|
[38] | 1128 |
|
---|
[46] | 1129 | def _notebookPageSwitch(self, notebook, page, page_num):
|
---|
| 1130 | """Called when the current page of the notebook has changed."""
|
---|
| 1131 | if page_num==0:
|
---|
[48] | 1132 | gobject.idle_add(self._wizard.grabDefault)
|
---|
[46] | 1133 | else:
|
---|
| 1134 | self._mainWindow.set_default(None)
|
---|
[123] | 1135 |
|
---|
[172] | 1136 | def _editChecklist(self, menuItem):
|
---|
| 1137 | """Callback for editing the checklists."""
|
---|
| 1138 | self._checklistEditor.run()
|
---|
[345] | 1139 |
|
---|
[264] | 1140 | def _editApproachCallouts(self, menuItem):
|
---|
| 1141 | """Callback for editing the approach callouts."""
|
---|
| 1142 | self._approachCalloutsEditor.run()
|
---|
[345] | 1143 |
|
---|
[123] | 1144 | def _editPreferences(self, menuItem):
|
---|
| 1145 | """Callback for editing the preferences."""
|
---|
[168] | 1146 | self._clearHotkeys()
|
---|
[123] | 1147 | self._preferences.run(self.config)
|
---|
[148] | 1148 | self._setupTimeSync()
|
---|
[168] | 1149 | self._listenHotkeys()
|
---|
[148] | 1150 |
|
---|
[482] | 1151 | def _reportBug(self, menuItem):
|
---|
| 1152 | """Callback for reporting a bug."""
|
---|
[484] | 1153 | self._bugReportDialog.run()
|
---|
[482] | 1154 |
|
---|
[148] | 1155 | def _setupTimeSync(self):
|
---|
| 1156 | """Enable or disable the simulator time synchronization based on the
|
---|
| 1157 | configuration."""
|
---|
| 1158 | simulator = self._simulator
|
---|
| 1159 | if simulator is not None:
|
---|
| 1160 | if self.config.syncFSTime:
|
---|
| 1161 | simulator.enableTimeSync()
|
---|
| 1162 | else:
|
---|
| 1163 | simulator.disableTimeSync()
|
---|
[151] | 1164 |
|
---|
| 1165 | def _loadPIREP(self, menuItem):
|
---|
| 1166 | """Load a PIREP for sending."""
|
---|
| 1167 | dialog = self._getLoadPirepDialog()
|
---|
| 1168 |
|
---|
| 1169 | if self._lastLoadedPIREP:
|
---|
| 1170 | dialog.set_current_folder(os.path.dirname(self._lastLoadedPIREP))
|
---|
| 1171 | else:
|
---|
| 1172 | pirepDirectory = self.config.pirepDirectory
|
---|
| 1173 | if pirepDirectory is not None:
|
---|
| 1174 | dialog.set_current_folder(pirepDirectory)
|
---|
[345] | 1175 |
|
---|
[151] | 1176 | result = dialog.run()
|
---|
| 1177 | dialog.hide()
|
---|
| 1178 |
|
---|
| 1179 | if result==RESPONSETYPE_OK:
|
---|
[164] | 1180 | self._lastLoadedPIREP = text2unicode(dialog.get_filename())
|
---|
[151] | 1181 |
|
---|
| 1182 | pirep = PIREP.load(self._lastLoadedPIREP)
|
---|
| 1183 | if pirep is None:
|
---|
| 1184 | dialog = gtk.MessageDialog(parent = self._mainWindow,
|
---|
| 1185 | type = MESSAGETYPE_ERROR,
|
---|
| 1186 | message_format = xstr("loadPIREP_failed"))
|
---|
| 1187 | dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK)
|
---|
| 1188 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
| 1189 | dialog.format_secondary_markup(xstr("loadPIREP_failed_sec"))
|
---|
| 1190 | dialog.run()
|
---|
| 1191 | dialog.hide()
|
---|
| 1192 | else:
|
---|
| 1193 | dialog = self._getSendLoadedDialog(pirep)
|
---|
| 1194 | dialog.show_all()
|
---|
[239] | 1195 | while True:
|
---|
| 1196 | result = dialog.run()
|
---|
[151] | 1197 |
|
---|
[239] | 1198 | if result==RESPONSETYPE_OK:
|
---|
| 1199 | self.sendPIREP(pirep)
|
---|
| 1200 | elif result==1:
|
---|
| 1201 | self._pirepViewer.setPIREP(pirep)
|
---|
| 1202 | self._pirepViewer.show_all()
|
---|
| 1203 | self._pirepViewer.run()
|
---|
| 1204 | self._pirepViewer.hide()
|
---|
| 1205 | else:
|
---|
| 1206 | break
|
---|
| 1207 |
|
---|
| 1208 | dialog.hide()
|
---|
[151] | 1209 |
|
---|
| 1210 | def _getLoadPirepDialog(self):
|
---|
| 1211 | """Get the PIREP loading file chooser dialog.
|
---|
| 1212 |
|
---|
| 1213 | If it is not created yet, it will be created."""
|
---|
| 1214 | if self._loadPIREPDialog is None:
|
---|
| 1215 | dialog = gtk.FileChooserDialog(title = WINDOW_TITLE_BASE + " - " +
|
---|
| 1216 | xstr("loadPIREP_browser_title"),
|
---|
| 1217 | action = FILE_CHOOSER_ACTION_OPEN,
|
---|
| 1218 | buttons = (gtk.STOCK_CANCEL,
|
---|
| 1219 | RESPONSETYPE_CANCEL,
|
---|
| 1220 | gtk.STOCK_OK, RESPONSETYPE_OK),
|
---|
| 1221 | parent = self._mainWindow)
|
---|
| 1222 | dialog.set_modal(True)
|
---|
[345] | 1223 |
|
---|
[151] | 1224 |
|
---|
| 1225 | filter = gtk.FileFilter()
|
---|
[184] | 1226 | filter.set_name(xstr("file_filter_pireps"))
|
---|
[151] | 1227 | filter.add_pattern("*.pirep")
|
---|
| 1228 | dialog.add_filter(filter)
|
---|
[345] | 1229 |
|
---|
[151] | 1230 | filter = gtk.FileFilter()
|
---|
[184] | 1231 | filter.set_name(xstr("file_filter_all"))
|
---|
[151] | 1232 | filter.add_pattern("*.*")
|
---|
| 1233 | dialog.add_filter(filter)
|
---|
| 1234 |
|
---|
| 1235 | self._loadPIREPDialog = dialog
|
---|
| 1236 |
|
---|
| 1237 | return self._loadPIREPDialog
|
---|
| 1238 |
|
---|
| 1239 | def _getSendLoadedDialog(self, pirep):
|
---|
| 1240 | """Get a dialog displaying the main information of the flight from the
|
---|
| 1241 | PIREP and providing Cancel and Send buttons."""
|
---|
| 1242 | dialog = gtk.Dialog(title = WINDOW_TITLE_BASE + " - " +
|
---|
| 1243 | xstr("loadPIREP_send_title"),
|
---|
| 1244 | parent = self._mainWindow,
|
---|
| 1245 | flags = DIALOG_MODAL)
|
---|
| 1246 |
|
---|
| 1247 | contentArea = dialog.get_content_area()
|
---|
| 1248 |
|
---|
| 1249 | label = gtk.Label(xstr("loadPIREP_send_help"))
|
---|
| 1250 | alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 1251 | xscale = 0.0, yscale = 0.0)
|
---|
| 1252 | alignment.set_padding(padding_top = 16, padding_bottom = 0,
|
---|
| 1253 | padding_left = 48, padding_right = 48)
|
---|
| 1254 | alignment.add(label)
|
---|
| 1255 | contentArea.pack_start(alignment, False, False, 8)
|
---|
| 1256 |
|
---|
| 1257 | table = gtk.Table(5, 2)
|
---|
| 1258 | tableAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 1259 | xscale = 0.0, yscale = 0.0)
|
---|
| 1260 | tableAlignment.set_padding(padding_top = 0, padding_bottom = 32,
|
---|
| 1261 | padding_left = 48, padding_right = 48)
|
---|
| 1262 | table.set_row_spacings(4)
|
---|
| 1263 | table.set_col_spacings(16)
|
---|
| 1264 | tableAlignment.add(table)
|
---|
| 1265 | contentArea.pack_start(tableAlignment, True, True, 8)
|
---|
| 1266 |
|
---|
| 1267 | bookedFlight = pirep.bookedFlight
|
---|
| 1268 |
|
---|
| 1269 | label = gtk.Label("<b>" + xstr("loadPIREP_send_flightno") + "</b>")
|
---|
| 1270 | label.set_use_markup(True)
|
---|
| 1271 | labelAlignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
|
---|
| 1272 | xscale = 0.0, yscale = 0.0)
|
---|
| 1273 | labelAlignment.add(label)
|
---|
| 1274 | table.attach(labelAlignment, 0, 1, 0, 1)
|
---|
[345] | 1275 |
|
---|
[151] | 1276 | label = gtk.Label(bookedFlight.callsign)
|
---|
| 1277 | labelAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
|
---|
| 1278 | xscale = 0.0, yscale = 0.0)
|
---|
| 1279 | labelAlignment.add(label)
|
---|
| 1280 | table.attach(labelAlignment, 1, 2, 0, 1)
|
---|
| 1281 |
|
---|
| 1282 | label = gtk.Label("<b>" + xstr("loadPIREP_send_date") + "</b>")
|
---|
| 1283 | label.set_use_markup(True)
|
---|
| 1284 | labelAlignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
|
---|
| 1285 | xscale = 0.0, yscale = 0.0)
|
---|
| 1286 | labelAlignment.add(label)
|
---|
| 1287 | table.attach(labelAlignment, 0, 1, 1, 2)
|
---|
[345] | 1288 |
|
---|
[151] | 1289 | label = gtk.Label(str(bookedFlight.departureTime.date()))
|
---|
| 1290 | labelAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
|
---|
| 1291 | xscale = 0.0, yscale = 0.0)
|
---|
| 1292 | labelAlignment.add(label)
|
---|
| 1293 | table.attach(labelAlignment, 1, 2, 1, 2)
|
---|
| 1294 |
|
---|
| 1295 | label = gtk.Label("<b>" + xstr("loadPIREP_send_from") + "</b>")
|
---|
| 1296 | label.set_use_markup(True)
|
---|
| 1297 | labelAlignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
|
---|
| 1298 | xscale = 0.0, yscale = 0.0)
|
---|
| 1299 | labelAlignment.add(label)
|
---|
| 1300 | table.attach(labelAlignment, 0, 1, 2, 3)
|
---|
[345] | 1301 |
|
---|
[151] | 1302 | label = gtk.Label(bookedFlight.departureICAO)
|
---|
| 1303 | labelAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
|
---|
| 1304 | xscale = 0.0, yscale = 0.0)
|
---|
| 1305 | labelAlignment.add(label)
|
---|
| 1306 | table.attach(labelAlignment, 1, 2, 2, 3)
|
---|
| 1307 |
|
---|
| 1308 | label = gtk.Label("<b>" + xstr("loadPIREP_send_to") + "</b>")
|
---|
| 1309 | label.set_use_markup(True)
|
---|
| 1310 | labelAlignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
|
---|
| 1311 | xscale = 0.0, yscale = 0.0)
|
---|
| 1312 | labelAlignment.add(label)
|
---|
| 1313 | table.attach(labelAlignment, 0, 1, 3, 4)
|
---|
[345] | 1314 |
|
---|
[151] | 1315 | label = gtk.Label(bookedFlight.arrivalICAO)
|
---|
| 1316 | labelAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
|
---|
| 1317 | xscale = 0.0, yscale = 0.0)
|
---|
| 1318 | labelAlignment.add(label)
|
---|
| 1319 | table.attach(labelAlignment, 1, 2, 3, 4)
|
---|
| 1320 |
|
---|
| 1321 | label = gtk.Label("<b>" + xstr("loadPIREP_send_rating") + "</b>")
|
---|
| 1322 | label.set_use_markup(True)
|
---|
| 1323 | labelAlignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
|
---|
| 1324 | xscale = 0.0, yscale = 0.0)
|
---|
| 1325 | labelAlignment.add(label)
|
---|
| 1326 | table.attach(labelAlignment, 0, 1, 4, 5)
|
---|
| 1327 |
|
---|
| 1328 | rating = pirep.rating
|
---|
| 1329 | label = gtk.Label()
|
---|
| 1330 | if rating<0:
|
---|
| 1331 | label.set_markup('<b><span foreground="red">NO GO</span></b>')
|
---|
| 1332 | else:
|
---|
| 1333 | label.set_text("%.1f %%" % (rating,))
|
---|
[345] | 1334 |
|
---|
[151] | 1335 | labelAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
|
---|
| 1336 | xscale = 0.0, yscale = 0.0)
|
---|
| 1337 | labelAlignment.add(label)
|
---|
| 1338 | table.attach(labelAlignment, 1, 2, 4, 5)
|
---|
| 1339 |
|
---|
| 1340 | dialog.add_button(xstr("button_cancel"), RESPONSETYPE_REJECT)
|
---|
[220] | 1341 | dialog.add_button(xstr("viewPIREP"), 1)
|
---|
[151] | 1342 | dialog.add_button(xstr("sendPIREP"), RESPONSETYPE_OK)
|
---|
[345] | 1343 |
|
---|
[151] | 1344 | return dialog
|
---|
[345] | 1345 |
|
---|
[151] | 1346 | def sendPIREP(self, pirep, callback = None):
|
---|
| 1347 | """Send the given PIREP."""
|
---|
| 1348 | self.beginBusy(xstr("sendPIREP_busy"))
|
---|
| 1349 | self._sendPIREPCallback = callback
|
---|
| 1350 | self.webHandler.sendPIREP(self._pirepSentCallback, pirep)
|
---|
| 1351 |
|
---|
| 1352 | def _pirepSentCallback(self, returned, result):
|
---|
| 1353 | """Callback for the PIREP sending result."""
|
---|
| 1354 | gobject.idle_add(self._handlePIREPSent, returned, result)
|
---|
| 1355 |
|
---|
| 1356 | def _handlePIREPSent(self, returned, result):
|
---|
| 1357 | """Callback for the PIREP sending result."""
|
---|
| 1358 | self.endBusy()
|
---|
| 1359 | secondaryMarkup = None
|
---|
| 1360 | type = MESSAGETYPE_ERROR
|
---|
| 1361 | if returned:
|
---|
| 1362 | if result.success:
|
---|
| 1363 | type = MESSAGETYPE_INFO
|
---|
| 1364 | messageFormat = xstr("sendPIREP_success")
|
---|
| 1365 | secondaryMarkup = xstr("sendPIREP_success_sec")
|
---|
| 1366 | elif result.alreadyFlown:
|
---|
| 1367 | messageFormat = xstr("sendPIREP_already")
|
---|
| 1368 | secondaryMarkup = xstr("sendPIREP_already_sec")
|
---|
| 1369 | elif result.notAvailable:
|
---|
| 1370 | messageFormat = xstr("sendPIREP_notavail")
|
---|
| 1371 | else:
|
---|
| 1372 | messageFormat = xstr("sendPIREP_unknown")
|
---|
| 1373 | secondaryMarkup = xstr("sendPIREP_unknown_sec")
|
---|
| 1374 | else:
|
---|
| 1375 | print "PIREP sending failed", result
|
---|
| 1376 | messageFormat = xstr("sendPIREP_failed")
|
---|
| 1377 | secondaryMarkup = xstr("sendPIREP_failed_sec")
|
---|
[345] | 1378 |
|
---|
[151] | 1379 | dialog = gtk.MessageDialog(parent = self._wizard.gui.mainWindow,
|
---|
| 1380 | type = type, message_format = messageFormat)
|
---|
| 1381 | dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK)
|
---|
| 1382 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
| 1383 | if secondaryMarkup is not None:
|
---|
| 1384 | dialog.format_secondary_markup(secondaryMarkup)
|
---|
| 1385 |
|
---|
| 1386 | dialog.run()
|
---|
| 1387 | dialog.hide()
|
---|
| 1388 |
|
---|
| 1389 | callback = self._sendPIREPCallback
|
---|
| 1390 | self._sendPIREPCallback = None
|
---|
| 1391 | if callback is not None:
|
---|
| 1392 | callback(returned, result)
|
---|
[168] | 1393 |
|
---|
[484] | 1394 | def sendBugReport(self, summary, description, email, callback = None):
|
---|
| 1395 | """Send the bug report with the given data."""
|
---|
[490] | 1396 | description += "\n\n" + ("=" * 40)
|
---|
| 1397 | description += "\n\nThe contents of the log:\n\n"
|
---|
| 1398 |
|
---|
| 1399 | for (timestampString, text) in self._logger.lines:
|
---|
| 1400 | description += unicode(formatFlightLogLine(timestampString, text))
|
---|
| 1401 |
|
---|
| 1402 | description += "\n\n" + ("=" * 40)
|
---|
| 1403 | description += "\n\nThe contents of the debug log:\n\n"
|
---|
| 1404 |
|
---|
| 1405 | buffer = self._debugLogView.get_buffer()
|
---|
| 1406 | description += buffer.get_text(buffer.get_start_iter(),
|
---|
| 1407 | buffer.get_end_iter(), True)
|
---|
| 1408 |
|
---|
[484] | 1409 | self.beginBusy(xstr("sendBugReport_busy"))
|
---|
| 1410 | self._sendBugReportCallback = callback
|
---|
| 1411 | self.webHandler.sendBugReport(self._bugReportSentCallback,
|
---|
| 1412 | summary, description, email)
|
---|
| 1413 |
|
---|
| 1414 | def _bugReportSentCallback(self, returned, result):
|
---|
| 1415 | """Callback function for the bug report sending result."""
|
---|
| 1416 | gobject.idle_add(self._handleBugReportSent, returned, result)
|
---|
| 1417 |
|
---|
| 1418 | def _handleBugReportSent(self, returned, result):
|
---|
| 1419 | """Callback for the bug report sending result."""
|
---|
| 1420 | self.endBusy()
|
---|
| 1421 | secondaryMarkup = None
|
---|
| 1422 | type = MESSAGETYPE_ERROR
|
---|
| 1423 | if returned:
|
---|
| 1424 | if result.success:
|
---|
| 1425 | type = MESSAGETYPE_INFO
|
---|
[491] | 1426 | messageFormat = xstr("sendBugReport_success") % (result.ticketID,)
|
---|
[484] | 1427 | secondaryMarkup = xstr("sendBugReport_success_sec")
|
---|
| 1428 | else:
|
---|
| 1429 | messageFormat = xstr("sendBugReport_error")
|
---|
| 1430 | secondaryMarkup = xstr("sendBugReport_siteerror_sec")
|
---|
| 1431 | else:
|
---|
| 1432 | messageFormat = xstr("sendBugReport_error")
|
---|
| 1433 | secondaryMarkup = xstr("sendBugReport_error_sec")
|
---|
| 1434 |
|
---|
| 1435 | dialog = gtk.MessageDialog(parent = self._wizard.gui._bugReportDialog,
|
---|
| 1436 | type = type, message_format = messageFormat)
|
---|
| 1437 | dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK)
|
---|
| 1438 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
| 1439 | if secondaryMarkup is not None:
|
---|
| 1440 | dialog.format_secondary_markup(secondaryMarkup)
|
---|
| 1441 |
|
---|
| 1442 | dialog.run()
|
---|
| 1443 | dialog.hide()
|
---|
| 1444 |
|
---|
| 1445 | callback = self._sendBugReportCallback
|
---|
| 1446 | self._sendBugReportCallback = None
|
---|
| 1447 | if callback is not None:
|
---|
| 1448 | callback(returned, result)
|
---|
| 1449 |
|
---|
[168] | 1450 | def _listenHotkeys(self):
|
---|
| 1451 | """Setup the hotkeys based on the configuration."""
|
---|
| 1452 | if self._hotkeySetID is None and self._simulator is not None:
|
---|
[178] | 1453 | self._pilotHotkeyIndex = None
|
---|
| 1454 | self._checklistHotkeyIndex = None
|
---|
| 1455 |
|
---|
| 1456 | hotkeys = []
|
---|
| 1457 |
|
---|
| 1458 | config = self.config
|
---|
| 1459 | if config.enableSounds and config.pilotControlsSounds:
|
---|
| 1460 | self._pilotHotkeyIndex = len(hotkeys)
|
---|
| 1461 | hotkeys.append(config.pilotHotkey)
|
---|
| 1462 |
|
---|
| 1463 | if config.enableChecklists:
|
---|
| 1464 | self._checklistHotkeyIndex = len(hotkeys)
|
---|
| 1465 | hotkeys.append(config.checklistHotkey)
|
---|
| 1466 |
|
---|
| 1467 | if hotkeys:
|
---|
| 1468 | self._hotkeySetID = \
|
---|
| 1469 | self._simulator.listenHotkeys(hotkeys, self._handleHotkeys)
|
---|
[168] | 1470 |
|
---|
| 1471 | def _clearHotkeys(self):
|
---|
| 1472 | """Clear the hotkeys."""
|
---|
| 1473 | if self._hotkeySetID is not None:
|
---|
| 1474 | self._hotkeySetID=None
|
---|
| 1475 | self._simulator.clearHotkeys()
|
---|
| 1476 |
|
---|
| 1477 | def _handleHotkeys(self, id, hotkeys):
|
---|
| 1478 | """Handle the hotkeys."""
|
---|
| 1479 | if id==self._hotkeySetID:
|
---|
[170] | 1480 | for index in hotkeys:
|
---|
[178] | 1481 | if index==self._pilotHotkeyIndex:
|
---|
| 1482 | print "gui.GUI._handleHotkeys: pilot hotkey pressed"
|
---|
[170] | 1483 | self._flight.pilotHotkeyPressed()
|
---|
[178] | 1484 | elif index==self._checklistHotkeyIndex:
|
---|
| 1485 | print "gui.GUI._handleHotkeys: checklist hotkey pressed"
|
---|
| 1486 | self._flight.checklistHotkeyPressed()
|
---|
[170] | 1487 | else:
|
---|
[178] | 1488 | print "gui.GUI._handleHotkeys: unhandled hotkey index:", index
|
---|
[227] | 1489 |
|
---|
| 1490 | def _showManual(self, menuitem):
|
---|
| 1491 | """Show the user's manual."""
|
---|
| 1492 | webbrowser.open(url ="file://" +
|
---|
| 1493 | os.path.join(self._programDirectory, "doc", "manual",
|
---|
| 1494 | getLanguage(), "index.html"),
|
---|
| 1495 | new = 1)
|
---|
| 1496 |
|
---|
| 1497 | def _showAbout(self, menuitem):
|
---|
| 1498 | """Show the about dialog."""
|
---|
| 1499 | dialog = self._getAboutDialog()
|
---|
| 1500 | dialog.show_all()
|
---|
| 1501 | dialog.run()
|
---|
| 1502 | dialog.hide()
|
---|
| 1503 |
|
---|
| 1504 | def _getAboutDialog(self):
|
---|
| 1505 | """Get the about dialog.
|
---|
| 1506 |
|
---|
| 1507 | If it does not exist yet, it will be created."""
|
---|
| 1508 | if self._aboutDialog is None:
|
---|
[276] | 1509 | dialog = gtk.AboutDialog()
|
---|
[227] | 1510 | dialog.set_transient_for(self._mainWindow)
|
---|
| 1511 | dialog.set_modal(True)
|
---|
[345] | 1512 |
|
---|
[227] | 1513 | logoPath = os.path.join(self._programDirectory, "logo.png")
|
---|
| 1514 | logo = pixbuf_new_from_file(logoPath)
|
---|
| 1515 | dialog.set_logo(logo)
|
---|
[345] | 1516 |
|
---|
[227] | 1517 | dialog.set_program_name(PROGRAM_NAME)
|
---|
| 1518 | dialog.set_version(const.VERSION)
|
---|
| 1519 | dialog.set_copyright("(c) 2012 by István Váradi")
|
---|
[237] | 1520 | dialog.set_website("http://mlx.varadiistvan.hu")
|
---|
| 1521 | dialog.set_website_label(xstr("about_website"))
|
---|
[227] | 1522 |
|
---|
| 1523 | isHungarian = getLanguage()=="hu"
|
---|
| 1524 | authors = []
|
---|
| 1525 | for (familyName, firstName, role) in GUI._authors:
|
---|
[276] | 1526 | author = "%s %s" % \
|
---|
| 1527 | (familyName if isHungarian else firstName,
|
---|
| 1528 | firstName if isHungarian else familyName)
|
---|
| 1529 | role = xstr("about_role_" + role)
|
---|
| 1530 | authors.append(author + " (" + role + ")")
|
---|
[227] | 1531 | dialog.set_authors(authors)
|
---|
| 1532 |
|
---|
| 1533 | dialog.set_license(xstr("about_license"))
|
---|
| 1534 |
|
---|
[237] | 1535 | if not pygobject:
|
---|
| 1536 | gtk.about_dialog_set_url_hook(self._showAboutURL, None)
|
---|
| 1537 |
|
---|
[276] | 1538 | self._aboutDialog = dialog
|
---|
| 1539 |
|
---|
[227] | 1540 | return self._aboutDialog
|
---|
[237] | 1541 |
|
---|
| 1542 | def _showAboutURL(self, dialog, link, user_data):
|
---|
[345] | 1543 | """Show the about URL."""
|
---|
[237] | 1544 | webbrowser.open(url = link, new = 1)
|
---|
[391] | 1545 |
|
---|
| 1546 | def _setTakeoffAntiIceOn(self, value):
|
---|
| 1547 | """Set the anti-ice on indicator."""
|
---|
| 1548 | self._wizard.takeoffAntiIceOn = value
|
---|
| 1549 |
|
---|
| 1550 | def _setLandingAntiIceOn(self, value):
|
---|
| 1551 | """Set the anti-ice on indicator."""
|
---|
| 1552 | self._wizard.landingAntiIceOn = value
|
---|