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