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