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