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