1 | # -*- encoding: utf-8 -*-
|
---|
2 |
|
---|
3 | from mlx.gui.common import *
|
---|
4 | import mlx.gui.cef as cef
|
---|
5 | from mlx.gui.flightlist import ColumnDescriptor, FlightList, PendingFlightsWindow
|
---|
6 |
|
---|
7 | import mlx.const as const
|
---|
8 | import mlx.fs as fs
|
---|
9 | import mlx.acft as acft
|
---|
10 | from mlx.flight import Flight
|
---|
11 | from mlx.checks import PayloadChecker
|
---|
12 | from mlx.gates import lhbpGates
|
---|
13 | import mlx.util as util
|
---|
14 | from mlx.pirep import PIREP
|
---|
15 | from mlx.i18n import xstr, getLanguage
|
---|
16 | from mlx.sound import startSound
|
---|
17 | from mlx.rpc import BookedFlight
|
---|
18 | import mlx.web as web
|
---|
19 |
|
---|
20 | import datetime
|
---|
21 | import time
|
---|
22 | import os
|
---|
23 | import tempfile
|
---|
24 | import threading
|
---|
25 | import re
|
---|
26 | import webbrowser
|
---|
27 |
|
---|
28 | #-----------------------------------------------------------------------------
|
---|
29 |
|
---|
30 | ## @package mlx.gui.flight
|
---|
31 | #
|
---|
32 | # The flight "wizard".
|
---|
33 | #
|
---|
34 | # This module implements the main tab of the application, the flight
|
---|
35 | # wizard. The wizard consists of \ref Page "pages", that come one after the
|
---|
36 | # other. As some pages might be skipped, the pages dynamically store the index
|
---|
37 | # of the previous page so that going back to it is simpler. The \ref
|
---|
38 | # Page.activate "activate" function is called before a page is first shown
|
---|
39 | # during a flight. This function should initialize the page's controls and fill
|
---|
40 | # it with initial data. When a page is left for the first time, its \ref
|
---|
41 | # Page.finalize "finalize" function is called. It should set those controls
|
---|
42 | # insensitive, that will not be available if the user comes back to this page.
|
---|
43 | #
|
---|
44 | # Each page has a title at the top displayed in inverted colors and a big
|
---|
45 | # font. There is a help text below it centered, that shortly describes what is
|
---|
46 | # expected on the page. There can be two help texts: one shown when the page is
|
---|
47 | # first displayed during a flight, another shown when the user goes back to the
|
---|
48 | # page. The main content area is below this, also centered. Finally, there are
|
---|
49 | # some buttons at the bottom on the right. As some buttons occur very
|
---|
50 | # frequently, there are functions to add them (\ref Page.addCancelFlightButton
|
---|
51 | # "addCancelFlightButton", \ref Page.addPreviousButton "addPreviousButton" and
|
---|
52 | # \ref Page.addNextButton "addNextButton".
|
---|
53 | #
|
---|
54 | # The \ref Wizard class is the main class to collect the pages. It also stores
|
---|
55 | # some data passed from one page to another and provides properties to access
|
---|
56 | # data items set via the wizard pages.
|
---|
57 |
|
---|
58 | #-----------------------------------------------------------------------------
|
---|
59 |
|
---|
60 | comboModel = Gtk.ListStore(GObject.TYPE_STRING)
|
---|
61 | comboModel.append(("N/A",))
|
---|
62 | comboModel.append(("VECTORS",))
|
---|
63 |
|
---|
64 | #-----------------------------------------------------------------------------
|
---|
65 |
|
---|
66 | class Page(Gtk.Alignment):
|
---|
67 | """A page in the flight wizard."""
|
---|
68 | def __init__(self, wizard, id, title, help, completedHelp = None):
|
---|
69 | """Construct the page."""
|
---|
70 | super(Page, self).__init__(xalign = 0.0, yalign = 0.0,
|
---|
71 | xscale = 1.0, yscale = 1.0)
|
---|
72 | self.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
73 | padding_left = 12, padding_right = 12)
|
---|
74 |
|
---|
75 | frame = Gtk.Frame()
|
---|
76 | self.add(frame)
|
---|
77 |
|
---|
78 | self._vbox = Gtk.VBox()
|
---|
79 | self._vbox.set_homogeneous(False)
|
---|
80 | frame.add(self._vbox)
|
---|
81 |
|
---|
82 | eventBox = Gtk.EventBox()
|
---|
83 |
|
---|
84 | alignment = Gtk.Alignment(xalign = 0.0, xscale = 0.0)
|
---|
85 |
|
---|
86 | titleLabel = Gtk.Label(title)
|
---|
87 | titleLabel.modify_font(Pango.FontDescription("bold 24"))
|
---|
88 | alignment.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
89 | padding_left = 6, padding_right = 0)
|
---|
90 |
|
---|
91 | alignment.add(titleLabel)
|
---|
92 | eventBox.add(alignment)
|
---|
93 |
|
---|
94 | self._vbox.pack_start(eventBox, False, False, 0)
|
---|
95 |
|
---|
96 | self._titleEventBox = eventBox
|
---|
97 | self._titleLabel = titleLabel
|
---|
98 |
|
---|
99 | mainBox = Gtk.VBox()
|
---|
100 |
|
---|
101 | alignment = Gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
102 | xscale = 1.0, yscale = 1.0)
|
---|
103 | alignment.set_padding(padding_top = 16, padding_bottom = 16,
|
---|
104 | padding_left = 16, padding_right = 16)
|
---|
105 | alignment.add(mainBox)
|
---|
106 | self._vbox.pack_start(alignment, True, True, 0)
|
---|
107 |
|
---|
108 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.0,
|
---|
109 | xscale = 0.0, yscale = 0.0)
|
---|
110 | alignment.set_padding(padding_top = 0, padding_bottom = 16,
|
---|
111 | padding_left = 0, padding_right = 0)
|
---|
112 |
|
---|
113 | self._help = help
|
---|
114 | self._completedHelp = completedHelp
|
---|
115 |
|
---|
116 | if self._completedHelp is None or \
|
---|
117 | len(help.splitlines())>=len(completedHelp.splitlines()):
|
---|
118 | longerHelp = help
|
---|
119 | else:
|
---|
120 | longerHelp = completedHelp
|
---|
121 |
|
---|
122 | self._helpLabel = Gtk.Label(longerHelp)
|
---|
123 | # FIXME: should be a constant in common
|
---|
124 | self._helpLabel.set_justify(Gtk.Justification.CENTER)
|
---|
125 | self._helpLabel.set_use_markup(True)
|
---|
126 | alignment.add(self._helpLabel)
|
---|
127 | mainBox.pack_start(alignment, False, False, 0)
|
---|
128 |
|
---|
129 | self._mainAlignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
130 | xscale = 1.0, yscale = 1.0)
|
---|
131 | mainBox.pack_start(self._mainAlignment, True, True, 0)
|
---|
132 |
|
---|
133 | buttonAlignment = Gtk.Alignment(xalign = 1.0, xscale=0.0, yscale = 0.0)
|
---|
134 | buttonAlignment.set_padding(padding_top = 4, padding_bottom = 10,
|
---|
135 | padding_left = 16, padding_right = 16)
|
---|
136 |
|
---|
137 | self._buttonBox = Gtk.HBox()
|
---|
138 | self._buttonBox.set_homogeneous(False)
|
---|
139 | self._defaultButton = None
|
---|
140 | buttonAlignment.add(self._buttonBox)
|
---|
141 |
|
---|
142 | self._vbox.pack_start(buttonAlignment, False, False, 0)
|
---|
143 |
|
---|
144 | self._wizard = wizard
|
---|
145 | self._id = id
|
---|
146 | self._nextPageID = None
|
---|
147 |
|
---|
148 | self._cancelFlightButton = None
|
---|
149 |
|
---|
150 | self._completed = False
|
---|
151 | self._fromPage = None
|
---|
152 |
|
---|
153 | @property
|
---|
154 | def id(self):
|
---|
155 | """Get the identifier of the page."""
|
---|
156 | return self._id
|
---|
157 |
|
---|
158 | @property
|
---|
159 | def nextPageID(self):
|
---|
160 | """Get the identifier of the next page, if set."""
|
---|
161 | return self._nextPageID
|
---|
162 |
|
---|
163 | @nextPageID.setter
|
---|
164 | def nextPageID(self, nextPageID):
|
---|
165 | """Set the identifier of the next page."""
|
---|
166 | self._nextPageID = nextPageID
|
---|
167 |
|
---|
168 | def setMainWidget(self, widget):
|
---|
169 | """Set the given widget as the main one."""
|
---|
170 | self._mainAlignment.add(widget)
|
---|
171 |
|
---|
172 | def addButton(self, label, default = False, sensitive = True,
|
---|
173 | tooltip = None, clicked = None, padding = 4,
|
---|
174 | clickedArg = None):
|
---|
175 | """Add a button with the given label.
|
---|
176 |
|
---|
177 | Return the button object created."""
|
---|
178 | button = Gtk.Button(label)
|
---|
179 | self._buttonBox.pack_start(button, False, False, padding)
|
---|
180 | button.set_use_underline(True)
|
---|
181 | if default:
|
---|
182 | button.set_can_default(True)
|
---|
183 | self._defaultButton = button
|
---|
184 | button.set_sensitive(sensitive)
|
---|
185 | if tooltip is not None:
|
---|
186 | button.set_tooltip_text(tooltip)
|
---|
187 | if clicked is not None:
|
---|
188 | if clickedArg is None:
|
---|
189 | button.connect("clicked", clicked)
|
---|
190 | else:
|
---|
191 | button.connect("clicked", clicked, clickedArg)
|
---|
192 | return button
|
---|
193 |
|
---|
194 | def addCancelFlightButton(self):
|
---|
195 | """Add the 'Cancel flight' button to the page."""
|
---|
196 | self._cancelFlightButton = \
|
---|
197 | self.addButton(xstr("button_cancelFlight"),
|
---|
198 | sensitive = True,
|
---|
199 | tooltip = xstr("button_cancelFlight_tooltip"),
|
---|
200 | clicked = self._cancelFlight,
|
---|
201 | padding = 16)
|
---|
202 | return self._cancelFlightButton
|
---|
203 |
|
---|
204 | def addPreviousButton(self, sensitive = True, clicked = None):
|
---|
205 | """Add the 'Next' button to the page."""
|
---|
206 | return self.addButton(xstr("button_previous"),
|
---|
207 | sensitive = sensitive,
|
---|
208 | tooltip = xstr("button_previous_tooltip"),
|
---|
209 | clicked = clicked)
|
---|
210 |
|
---|
211 | def addNextButton(self, default = True, sensitive = True,
|
---|
212 | clicked = None):
|
---|
213 | """Add the 'Next' button to the page."""
|
---|
214 | return self.addButton(xstr("button_next"),
|
---|
215 | default = default,
|
---|
216 | sensitive = sensitive,
|
---|
217 | tooltip = xstr("button_next_tooltip"),
|
---|
218 | clicked = clicked)
|
---|
219 |
|
---|
220 | def setStyle(self):
|
---|
221 | """Set the styles of some of the items on the page."""
|
---|
222 | context = self.get_style_context()
|
---|
223 | color = context.get_background_color(Gtk.StateFlags.SELECTED)
|
---|
224 | self._titleEventBox.modify_bg(0, color.to_color())
|
---|
225 | color = context.get_color(Gtk.StateFlags.SELECTED)
|
---|
226 | self._titleLabel.modify_fg(0, color.to_color())
|
---|
227 |
|
---|
228 | def initialize(self):
|
---|
229 | """Initialize the page.
|
---|
230 |
|
---|
231 | It sets up the primary help, and calls the activate() function."""
|
---|
232 | self._helpLabel.set_markup(self._help)
|
---|
233 | self._helpLabel.set_sensitive(True)
|
---|
234 | self.activate()
|
---|
235 |
|
---|
236 | def activate(self):
|
---|
237 | """Called when this page becomes active.
|
---|
238 |
|
---|
239 | This default implementation does nothing."""
|
---|
240 | pass
|
---|
241 |
|
---|
242 | def setHelp(self, help):
|
---|
243 | """Set the help string."""
|
---|
244 | self._help = help
|
---|
245 | if not self._completed:
|
---|
246 | self._helpLabel.set_markup(self._help)
|
---|
247 | self._helpLabel.set_sensitive(True)
|
---|
248 |
|
---|
249 | def complete(self):
|
---|
250 | """Called when the page is completed.
|
---|
251 |
|
---|
252 | It greys out/changes the help text and then calls finalize()."""
|
---|
253 | self.finalize()
|
---|
254 | if self._completedHelp is None:
|
---|
255 | self._helpLabel.set_sensitive(False)
|
---|
256 | else:
|
---|
257 | self._helpLabel.set_markup(self._completedHelp)
|
---|
258 | self._completed = True
|
---|
259 |
|
---|
260 | def finalize(self):
|
---|
261 | """Called when the page is finalized."""
|
---|
262 | pass
|
---|
263 |
|
---|
264 | def grabDefault(self):
|
---|
265 | """If the page has a default button, make it the default one."""
|
---|
266 | if self._defaultButton is not None:
|
---|
267 | self._defaultButton.grab_default()
|
---|
268 |
|
---|
269 | def reset(self):
|
---|
270 | """Reset the page if the wizard is reset."""
|
---|
271 | self._completed = False
|
---|
272 | self._fromPage = None
|
---|
273 | if self._cancelFlightButton is not None:
|
---|
274 | self._cancelFlightButton.set_sensitive(True)
|
---|
275 |
|
---|
276 | def goBack(self):
|
---|
277 | """Go to the page we were invoked from."""
|
---|
278 | assert self._fromPage is not None
|
---|
279 |
|
---|
280 | self._wizard.setCurrentPage(self._fromPage, finalize = False)
|
---|
281 |
|
---|
282 | def flightEnded(self):
|
---|
283 | """Called when the flight has ended.
|
---|
284 |
|
---|
285 | This default implementation disables the cancel flight button."""
|
---|
286 | if self._cancelFlightButton is not None:
|
---|
287 | self._cancelFlightButton.set_sensitive(False)
|
---|
288 |
|
---|
289 | def _cancelFlight(self, button):
|
---|
290 | """Called when the Cancel flight button is clicked."""
|
---|
291 | self._wizard.gui.cancelFlight()
|
---|
292 |
|
---|
293 | #-----------------------------------------------------------------------------
|
---|
294 |
|
---|
295 | class LoginPage(Page):
|
---|
296 | """The login page."""
|
---|
297 | def __init__(self, wizard):
|
---|
298 | """Construct the login page."""
|
---|
299 | super(LoginPage, self).__init__(wizard, "login",
|
---|
300 | xstr("login"), xstr("loginHelp"))
|
---|
301 |
|
---|
302 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
303 | xscale = 0.0, yscale = 0.0)
|
---|
304 |
|
---|
305 | table = Gtk.Table(3, 2)
|
---|
306 | table.set_row_spacings(4)
|
---|
307 | table.set_col_spacings(32)
|
---|
308 | alignment.add(table)
|
---|
309 | self.setMainWidget(alignment)
|
---|
310 |
|
---|
311 | labelAlignment = Gtk.Alignment(xalign = 1.0, yalign = 0.5,
|
---|
312 | xscale = 0.0, yscale = 0.0)
|
---|
313 | label = Gtk.Label(xstr("label_pilotID"))
|
---|
314 | label.set_use_underline(True)
|
---|
315 | labelAlignment.add(label)
|
---|
316 | table.attach(labelAlignment, 0, 1, 0, 1)
|
---|
317 |
|
---|
318 | self._pilotID = Gtk.Entry()
|
---|
319 | self._pilotID.connect("changed", self._pilotIDChanged)
|
---|
320 | self._pilotID.set_tooltip_text(xstr("login_pilotID_tooltip"))
|
---|
321 | table.attach(self._pilotID, 1, 2, 0, 1)
|
---|
322 | label.set_mnemonic_widget(self._pilotID)
|
---|
323 |
|
---|
324 | labelAlignment = Gtk.Alignment(xalign = 1.0, yalign = 0.5,
|
---|
325 | xscale = 0.0, yscale = 0.0)
|
---|
326 | label = Gtk.Label(xstr("label_password"))
|
---|
327 | label.set_use_underline(True)
|
---|
328 | labelAlignment.add(label)
|
---|
329 | table.attach(labelAlignment, 0, 1, 1, 2)
|
---|
330 |
|
---|
331 | self._password = Gtk.Entry()
|
---|
332 | self._password.set_visibility(False)
|
---|
333 | self._password.connect("changed", self._setControls)
|
---|
334 | self._password.set_tooltip_text(xstr("login_password_tooltip"))
|
---|
335 | table.attach(self._password, 1, 2, 1, 2)
|
---|
336 | label.set_mnemonic_widget(self._password)
|
---|
337 |
|
---|
338 | self._rememberButton = Gtk.CheckButton(xstr("remember_password"))
|
---|
339 | self._rememberButton.set_use_underline(True)
|
---|
340 | self._rememberButton.set_tooltip_text(xstr("login_remember_tooltip"))
|
---|
341 | table.attach(self._rememberButton, 1, 2, 2, 3, ypadding = 8)
|
---|
342 |
|
---|
343 | self.addButton(xstr("button_login_register"),
|
---|
344 | clicked = self._registerClicked,
|
---|
345 | tooltip = xstr("button_login_register_tooltip"))
|
---|
346 |
|
---|
347 | self.addButton(xstr("button_offline"),
|
---|
348 | clicked = self._offlineClicked,
|
---|
349 | tooltip = xstr("button_offline_tooltip"))
|
---|
350 |
|
---|
351 | self._loginButton = self.addButton(xstr("button_login"), default = True)
|
---|
352 | self._loginButton.connect("clicked", self._loginClicked)
|
---|
353 | self._loginButton.set_tooltip_text(xstr("login_button_tooltip"))
|
---|
354 |
|
---|
355 |
|
---|
356 | @property
|
---|
357 | def pilotID(self):
|
---|
358 | """Get the pilot ID, if given."""
|
---|
359 | return self._pilotID.get_text()
|
---|
360 |
|
---|
361 | def activate(self):
|
---|
362 | """Activate the page."""
|
---|
363 | config = self._wizard.gui.config
|
---|
364 | self._pilotID.set_text(config.pilotID)
|
---|
365 | self._password.set_text(config.password)
|
---|
366 | self._rememberButton.set_active(config.rememberPassword)
|
---|
367 | self._setControls(None)
|
---|
368 |
|
---|
369 | def _pilotIDChanged(self, entry):
|
---|
370 | """Called when the pilot ID has changed.
|
---|
371 |
|
---|
372 | It sets the text to upper-case and calls _setControls to update other
|
---|
373 | stuff."""
|
---|
374 | entry.set_text(entry.get_text().upper())
|
---|
375 | self._setControls(entry)
|
---|
376 |
|
---|
377 | def _setControls(self, entry = None):
|
---|
378 | """Set the sensitivity of the various controls.
|
---|
379 |
|
---|
380 | The login button is sensitive only if both the pilot ID and the
|
---|
381 | password fields contain values.
|
---|
382 |
|
---|
383 | The password field is sensitive only, if the entrance exam checkbox is
|
---|
384 | not selected.
|
---|
385 |
|
---|
386 | The remember password checkbox is sensitive only, if the password field
|
---|
387 | contains text.
|
---|
388 |
|
---|
389 | The entrance exam checkbox is sensitive only, if the pilot ID is not
|
---|
390 | empty."""
|
---|
391 | pilotID = self._pilotID.get_text()
|
---|
392 | password = self._password.get_text()
|
---|
393 | self._rememberButton.set_sensitive(password!="")
|
---|
394 | self._loginButton.set_sensitive(pilotID!="" and password!="")
|
---|
395 |
|
---|
396 | def _registerClicked(self, button):
|
---|
397 | """Called when the Register button was clicked."""
|
---|
398 | self._wizard.jumpPage("register")
|
---|
399 |
|
---|
400 | def _offlineClicked(self, button):
|
---|
401 | """Called when the offline button was clicked."""
|
---|
402 | print("mlx.flight.LoginPage: offline flight selected")
|
---|
403 | self._wizard.nextPage()
|
---|
404 |
|
---|
405 | def _loginClicked(self, button):
|
---|
406 | """Called when the login button was clicked."""
|
---|
407 | print("mlx.flight.LoginPage: logging in")
|
---|
408 | self._wizard.login(self._handleLoginResult,
|
---|
409 | self._pilotID.get_text(),
|
---|
410 | self._password.get_text())
|
---|
411 |
|
---|
412 | def _handleLoginResult(self, returned, result):
|
---|
413 | """Handle the login result."""
|
---|
414 | self._loginButton.set_sensitive(True)
|
---|
415 | if returned and result.loggedIn:
|
---|
416 | config = self._wizard.gui.config
|
---|
417 |
|
---|
418 | config.pilotID = self._pilotID.get_text()
|
---|
419 |
|
---|
420 | rememberPassword = self._rememberButton.get_active()
|
---|
421 | config.password = result.password if rememberPassword else ""
|
---|
422 |
|
---|
423 | config.rememberPassword = rememberPassword
|
---|
424 |
|
---|
425 | config.save()
|
---|
426 | if result.rank=="STU":
|
---|
427 | self._wizard.jumpPage("student")
|
---|
428 | else:
|
---|
429 | self._wizard.nextPage()
|
---|
430 |
|
---|
431 | #-----------------------------------------------------------------------------
|
---|
432 |
|
---|
433 | class FlightSelectionPage(Page):
|
---|
434 | """The page to select the flight."""
|
---|
435 | def __init__(self, wizard):
|
---|
436 | """Construct the flight selection page."""
|
---|
437 | help = xstr("flightsel_help")
|
---|
438 | completedHelp = xstr("flightsel_chelp")
|
---|
439 | super(FlightSelectionPage, self).__init__(wizard, "flightsel",
|
---|
440 | xstr("flightsel_title"),
|
---|
441 | help, completedHelp = completedHelp)
|
---|
442 |
|
---|
443 | mainBox = Gtk.HBox()
|
---|
444 | mainBox.set_homogeneous(False)
|
---|
445 |
|
---|
446 | leftVBox = Gtk.VBox()
|
---|
447 |
|
---|
448 | alignment = Gtk.Alignment(xscale = 1.0)
|
---|
449 | alignment.set_size_request(100, 0)
|
---|
450 |
|
---|
451 | leftVBox.pack_start(alignment, False, False, 0)
|
---|
452 |
|
---|
453 | mainBox.pack_start(leftVBox, True, True, 0)
|
---|
454 |
|
---|
455 | self._flightList = FlightList(popupMenuProducer =
|
---|
456 | self._createListPopupMenu,
|
---|
457 | widthRequest = 400)
|
---|
458 | self._flightList.connect("row-activated", self._rowActivated)
|
---|
459 | self._flightList.connect("selection-changed", self._selectionChanged)
|
---|
460 |
|
---|
461 | mainBox.pack_start(self._flightList, False, False, 8)
|
---|
462 |
|
---|
463 | flightButtonBox = Gtk.VBox()
|
---|
464 |
|
---|
465 | alignment = Gtk.Alignment(xscale = 1.0)
|
---|
466 | alignment.set_size_request(100, 0)
|
---|
467 | flightButtonBox.pack_start(alignment, False, False, 0)
|
---|
468 |
|
---|
469 | flightButtonWidthAlignment = Gtk.Alignment(xscale=1.0, yscale=0.0,
|
---|
470 | xalign=0.0, yalign=0.0)
|
---|
471 | flightButtonWidthAlignment.set_padding(padding_top = 0,
|
---|
472 | padding_bottom = 0,
|
---|
473 | padding_left = 8,
|
---|
474 | padding_right = 0)
|
---|
475 | flightButtonWidthBox = Gtk.VBox()
|
---|
476 |
|
---|
477 | self._saveButton = Gtk.Button(xstr("flightsel_save"))
|
---|
478 | self._saveButton.set_use_underline(True)
|
---|
479 | self._saveButton.set_sensitive(False)
|
---|
480 | self._saveButton.set_tooltip_text(xstr("flightsel_save_tooltip"))
|
---|
481 | self._saveButton.connect("clicked", self._saveClicked)
|
---|
482 |
|
---|
483 | flightButtonWidthBox.pack_start(self._saveButton, True, True, 4)
|
---|
484 |
|
---|
485 | self._printButton = Gtk.Button(xstr("flightsel_print"))
|
---|
486 | self._printButton.set_use_underline(True)
|
---|
487 | self._printButton.set_sensitive(False)
|
---|
488 | self._printButton.set_tooltip_text(xstr("flightsel_print_tooltip"))
|
---|
489 | self._printButton.connect("clicked", self._printClicked)
|
---|
490 |
|
---|
491 | flightButtonWidthBox.pack_start(self._printButton, True, True, 4)
|
---|
492 |
|
---|
493 | self._deleteButton = Gtk.Button(xstr("flightsel_delete"))
|
---|
494 | self._deleteButton.set_use_underline(True)
|
---|
495 | self._deleteButton.set_sensitive(False)
|
---|
496 | self._deleteButton.set_tooltip_text(xstr("flightsel_delete_tooltip"))
|
---|
497 | self._deleteButton.connect("clicked", self._deleteClicked)
|
---|
498 |
|
---|
499 | flightButtonWidthBox.pack_start(self._deleteButton, True, True, 4)
|
---|
500 |
|
---|
501 | flightButtonWidthAlignment.add(flightButtonWidthBox)
|
---|
502 | flightButtonBox.pack_start(flightButtonWidthAlignment, False, False, 0)
|
---|
503 |
|
---|
504 | mainBox.pack_start(flightButtonBox, True, True, 0)
|
---|
505 |
|
---|
506 | self.setMainWidget(mainBox)
|
---|
507 |
|
---|
508 | self._bookButton = self.addButton(xstr("flightsel_book"),
|
---|
509 | sensitive = True,
|
---|
510 | clicked = self._bookClicked,
|
---|
511 | tooltip = xstr("flightsel_book_tooltip"))
|
---|
512 |
|
---|
513 | self._pendingButton = self.addButton(xstr("flightsel_pending"),
|
---|
514 | sensitive = False,
|
---|
515 | clicked = self._pendingClicked,
|
---|
516 | tooltip = xstr("flightsel_pending_tooltip"))
|
---|
517 |
|
---|
518 | self._saveDialog = None
|
---|
519 |
|
---|
520 | self._refreshButton = self.addButton(xstr("flightsel_refresh"),
|
---|
521 | sensitive = True,
|
---|
522 | clicked = self._refreshClicked,
|
---|
523 | tooltip = xstr("flightsel_refresh_tooltip"))
|
---|
524 |
|
---|
525 | self._loadButton = self.addButton(xstr("flightsel_load"),
|
---|
526 | sensitive = True,
|
---|
527 | tooltip = xstr("flightsel_load_tooltip"))
|
---|
528 | self._loadButton.connect("clicked", self._loadButtonClicked)
|
---|
529 | self._loadDialog = None
|
---|
530 |
|
---|
531 | self._button = self.addNextButton(sensitive = False,
|
---|
532 | clicked = self._forwardClicked)
|
---|
533 |
|
---|
534 | self._flights = []
|
---|
535 |
|
---|
536 | self._pendingFlightsWindow = PendingFlightsWindow(self._wizard)
|
---|
537 | self._pendingFlightsWindowShown = False
|
---|
538 | self._pendingFlightsWindow.connect("delete-event",
|
---|
539 | self._deletePendingFlightsWindow)
|
---|
540 |
|
---|
541 | self._printSettings = None
|
---|
542 |
|
---|
543 | def activate(self):
|
---|
544 | """Fill the flight list."""
|
---|
545 | self._setupHelp()
|
---|
546 | self._flightList.set_sensitive(True)
|
---|
547 | self._loadButton.set_sensitive(True)
|
---|
548 | self._refreshButton.set_sensitive(self._wizard.loggedIn)
|
---|
549 | self._buildFlights()
|
---|
550 |
|
---|
551 | def finalize(self):
|
---|
552 | """Finalize the page."""
|
---|
553 | self._flightList.set_sensitive(False)
|
---|
554 | self._loadButton.set_sensitive(False)
|
---|
555 | self._refreshButton.set_sensitive(False)
|
---|
556 |
|
---|
557 | def _setupHelp(self):
|
---|
558 | """Setup the help string"""
|
---|
559 | help = ""
|
---|
560 |
|
---|
561 | if self._wizard.loggedIn:
|
---|
562 | numReported = len(self._wizard.loginResult.reportedFlights)
|
---|
563 | numRejected = len(self._wizard.loginResult.rejectedFlights)
|
---|
564 | if numReported==0 and numRejected==0:
|
---|
565 | help = xstr("flightsel_prehelp_nopending")
|
---|
566 | elif numReported>0 and numRejected==0:
|
---|
567 | help = xstr("flightsel_prehelp_rep_0rej") % (numReported,)
|
---|
568 | elif numReported==0 and numRejected>0:
|
---|
569 | help = xstr("flightsel_prehelp_0rep_rej") % (numRejected,)
|
---|
570 | else:
|
---|
571 | help = xstr("flightsel_prehelp_rep_rej") % \
|
---|
572 | (numReported, numRejected)
|
---|
573 |
|
---|
574 | help += xstr("flightsel_help")
|
---|
575 |
|
---|
576 | self.setHelp(help)
|
---|
577 |
|
---|
578 | def _buildFlights(self):
|
---|
579 | """Rebuild the flights from the login result."""
|
---|
580 | self._flights = []
|
---|
581 | self._flightList.clear()
|
---|
582 | self._pendingFlightsWindow.clear()
|
---|
583 | loginResult = self._wizard.loginResult
|
---|
584 | if self._wizard.loggedIn:
|
---|
585 | for flight in loginResult.flights:
|
---|
586 | self.addFlight(flight)
|
---|
587 | for flight in loginResult.reportedFlights:
|
---|
588 | self._pendingFlightsWindow.addReportedFlight(flight)
|
---|
589 | for flight in loginResult.rejectedFlights:
|
---|
590 | self._pendingFlightsWindow.addRejectedFlight(flight)
|
---|
591 |
|
---|
592 | self._updatePendingButton()
|
---|
593 |
|
---|
594 | def addFlight(self, flight):
|
---|
595 | """Add the given file to the list of flights."""
|
---|
596 | self._flights.append(flight)
|
---|
597 | self._flightList.addFlight(flight)
|
---|
598 |
|
---|
599 | def _reflyFlight(self, flight):
|
---|
600 | """Refly the given flight."""
|
---|
601 | self.addFlight(flight)
|
---|
602 | self._updatePending()
|
---|
603 |
|
---|
604 | def _updatePending(self):
|
---|
605 | """Update the stuff depending on the set of pending flights."""
|
---|
606 | self._setupHelp()
|
---|
607 | self._updatePendingButton()
|
---|
608 |
|
---|
609 | def _bookClicked(self, button):
|
---|
610 | """Called when the Book flights button is clicked."""
|
---|
611 | self._wizard.gui.showTimetable()
|
---|
612 |
|
---|
613 | def _pendingClicked(self, button):
|
---|
614 | """Called when the Pending flights button is clicked."""
|
---|
615 | self._pendingFlightsWindow.show_all()
|
---|
616 | self._pendingFlightsWindowShown = True
|
---|
617 | self._updateNextButton()
|
---|
618 |
|
---|
619 | def _deletePendingFlightsWindow(self, window, event):
|
---|
620 | """Called when the pending flights window is closed."""
|
---|
621 | self._pendingFlightsWindow.hide()
|
---|
622 | self._pendingFlightsWindowShown = False
|
---|
623 | self._updateNextButton()
|
---|
624 | return True
|
---|
625 |
|
---|
626 | def _saveClicked(self, button):
|
---|
627 | """Called when the Save flight button is clicked."""
|
---|
628 | self._saveSelected()
|
---|
629 |
|
---|
630 | def _saveSelected(self):
|
---|
631 | """Save the selected flight."""
|
---|
632 | flight = self._getSelectedFlight()
|
---|
633 | date = flight.departureTime.date()
|
---|
634 | name = "%04d-%02d-%02d %s %s-%s.vaflight" % \
|
---|
635 | (date.year, date.month, date.day, flight.callsign,
|
---|
636 | flight.departureICAO, flight.arrivalICAO)
|
---|
637 |
|
---|
638 | dialog = self._getSaveDialog()
|
---|
639 | dialog.set_current_name(name)
|
---|
640 | dialog.show_all()
|
---|
641 | response = dialog.run()
|
---|
642 | dialog.hide()
|
---|
643 |
|
---|
644 | if response==Gtk.ResponseType.OK:
|
---|
645 | fileName = dialog.get_filename()
|
---|
646 | print("Saving", fileName)
|
---|
647 | try:
|
---|
648 | with open(fileName, "wt") as f:
|
---|
649 | flight.writeIntoFile(f)
|
---|
650 | except Exception as e:
|
---|
651 | print("Failed to save flight:", util.utf2unicode(str(e)))
|
---|
652 | dialog = Gtk.MessageDialog(parent = self._wizard.gui.mainWindow,
|
---|
653 | type = Gtk.MessageType.ERROR,
|
---|
654 | message_format =
|
---|
655 | xstr("flightsel_save_failed"))
|
---|
656 | dialog.add_button(xstr("button_ok"), Gtk.ResponseType.OK)
|
---|
657 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
658 | secondary = xstr("flightsel_save_failed_sec")
|
---|
659 | dialog.format_secondary_markup(secondary)
|
---|
660 | dialog.run()
|
---|
661 | dialog.hide()
|
---|
662 |
|
---|
663 | def _printClicked(self, button):
|
---|
664 | """Called when the Print briefing button is clicked."""
|
---|
665 | self._printSelected()
|
---|
666 |
|
---|
667 | def _printSelected(self):
|
---|
668 | """Print the briefing for the selected flight."""
|
---|
669 | wizard = self._wizard
|
---|
670 | flight = self._getSelectedFlight()
|
---|
671 |
|
---|
672 | printOperation = Gtk.PrintOperation()
|
---|
673 | if self._printSettings is not None:
|
---|
674 | printOperation.set_print_settings(self._printSettings)
|
---|
675 |
|
---|
676 | printOperation.set_n_pages(1)
|
---|
677 | printOperation.set_show_progress(True)
|
---|
678 | printOperation.connect("draw_page", self._drawBriefing)
|
---|
679 |
|
---|
680 | name = "MAVA Briefing %s %s %s" % (wizard.loginResult.pilotID,
|
---|
681 | flight.callsign,
|
---|
682 | flight.departureTime.strftime("%Y-%m-%d %H:%M"))
|
---|
683 | printOperation.set_job_name(name)
|
---|
684 | printOperation.set_export_filename(name)
|
---|
685 | printOperation.set_use_full_page(False)
|
---|
686 |
|
---|
687 | result = printOperation.run(Gtk.PrintOperationAction.PRINT_DIALOG,
|
---|
688 | wizard.gui.mainWindow)
|
---|
689 |
|
---|
690 | if result == Gtk.PrintOperationResult.APPLY:
|
---|
691 | self._printSettings = printOperation.get_print_settings()
|
---|
692 | elif result == Gtk.PrintOperationResult.ERROR:
|
---|
693 | errorDialog(xstr("flightsel_print_failed",
|
---|
694 | wizard.gui.mainWindow,
|
---|
695 | secondary = printOperation.get_error()))
|
---|
696 |
|
---|
697 | def _drawBriefing(self, printOperation, context, pageNumber):
|
---|
698 | """Draw the briefing."""
|
---|
699 | wizard = self._wizard
|
---|
700 | loginResult = wizard.loginResult
|
---|
701 | flight=self._getSelectedFlight()
|
---|
702 |
|
---|
703 | print("DPI", context.get_dpi_x(), context.get_dpi_y())
|
---|
704 |
|
---|
705 | logoSurface = cairo.ImageSurface.create_from_png(
|
---|
706 | os.path.join(wizard.gui.programDirectory, "mavalogo.png"))
|
---|
707 |
|
---|
708 | scale = context.get_dpi_x() / 72.0
|
---|
709 |
|
---|
710 | cr = context.get_cairo_context()
|
---|
711 |
|
---|
712 | cr.set_antialias(cairo.ANTIALIAS_GRAY)
|
---|
713 |
|
---|
714 | pcr = context.create_pango_context()
|
---|
715 |
|
---|
716 | delimiter = "*" * 70
|
---|
717 |
|
---|
718 | layout = Pango.Layout(pcr)
|
---|
719 |
|
---|
720 | font = Pango.FontDescription("Courier")
|
---|
721 | font.set_size(int(12 * Pango.SCALE))
|
---|
722 | font.set_weight(Pango.Weight.THIN)
|
---|
723 | layout.set_font_description(font)
|
---|
724 |
|
---|
725 | fontBold = Pango.FontDescription("Courier")
|
---|
726 | fontBold.set_size(int(12 * Pango.SCALE))
|
---|
727 | fontBold.set_weight(Pango.Weight.BOLD)
|
---|
728 |
|
---|
729 | layout.set_text(delimiter)
|
---|
730 | (_ink, logical) = layout.get_extents()
|
---|
731 | width = logical.width / Pango.SCALE
|
---|
732 |
|
---|
733 | x0 = (context.get_width() - width)/2.0
|
---|
734 |
|
---|
735 | logoWidth = width / 3
|
---|
736 | logoScale = logoSurface.get_width() / logoWidth
|
---|
737 |
|
---|
738 | y = 25 * scale
|
---|
739 |
|
---|
740 | source = cr.get_source()
|
---|
741 | logoSurface.set_device_scale(logoScale, logoScale)
|
---|
742 | cr.set_source_surface(logoSurface, x0, y)
|
---|
743 | cr.rectangle(x0, y, logoSurface.get_width() / logoScale,
|
---|
744 | logoSurface.get_height() / logoScale)
|
---|
745 | cr.fill()
|
---|
746 | cr.set_source(source)
|
---|
747 |
|
---|
748 | y += logoSurface.get_height() / logoScale
|
---|
749 | y += 12 * scale
|
---|
750 |
|
---|
751 | cr.move_to(x0, y)
|
---|
752 | cr.set_line_width(0.1 * scale)
|
---|
753 | PangoCairo.layout_path(cr, layout)
|
---|
754 | cr.stroke_preserve()
|
---|
755 | cr.fill()
|
---|
756 |
|
---|
757 | y += logical.height / Pango.SCALE
|
---|
758 | y += 4 * scale
|
---|
759 |
|
---|
760 | layout.set_text("F L I G H T B R I E F I N G S H E E T")
|
---|
761 | (_ink, logical) = layout.get_extents()
|
---|
762 | width = logical.width / Pango.SCALE
|
---|
763 |
|
---|
764 | cr.move_to((context.get_width() - width)/2.0, y)
|
---|
765 | cr.set_line_width(0.1 * scale)
|
---|
766 | PangoCairo.layout_path(cr, layout)
|
---|
767 | cr.stroke_preserve()
|
---|
768 | cr.fill()
|
---|
769 |
|
---|
770 | y += logical.height / Pango.SCALE
|
---|
771 | y += 4 * scale
|
---|
772 |
|
---|
773 | layout.set_text(delimiter)
|
---|
774 | (_ink, logical) = layout.get_extents()
|
---|
775 | width = logical.width / Pango.SCALE
|
---|
776 |
|
---|
777 | x2 = x0 + width * 0.4
|
---|
778 |
|
---|
779 | cr.move_to(x0, y)
|
---|
780 | cr.set_line_width(0.1 * scale)
|
---|
781 | PangoCairo.layout_path(cr, layout)
|
---|
782 | cr.stroke_preserve()
|
---|
783 | cr.fill()
|
---|
784 |
|
---|
785 | y += logical.height / Pango.SCALE
|
---|
786 | y += 5 * scale
|
---|
787 |
|
---|
788 | layout.set_text("AIRCRAFT: ")
|
---|
789 | layout.set_font_description(fontBold)
|
---|
790 | (_ink, logical) = layout.get_extents()
|
---|
791 | x1 = x0 + logical.width / Pango.SCALE
|
---|
792 |
|
---|
793 | layout.set_text("FLIGHT:")
|
---|
794 | layout.set_font_description(fontBold)
|
---|
795 |
|
---|
796 | cr.move_to(x0, y)
|
---|
797 | cr.set_line_width(0.1 * scale)
|
---|
798 | PangoCairo.layout_path(cr, layout)
|
---|
799 | cr.stroke_preserve()
|
---|
800 | cr.fill()
|
---|
801 |
|
---|
802 | layout.set_text("%s %s-%s" % (flight.callsign,
|
---|
803 | flight.departureICAO,
|
---|
804 | flight.arrivalICAO))
|
---|
805 |
|
---|
806 | layout.set_font_description(font)
|
---|
807 |
|
---|
808 | cr.move_to(x1, y)
|
---|
809 | cr.set_line_width(0.1 * scale)
|
---|
810 | PangoCairo.layout_path(cr, layout)
|
---|
811 | cr.stroke_preserve()
|
---|
812 | cr.fill()
|
---|
813 |
|
---|
814 | layout.set_text("DATE:")
|
---|
815 | layout.set_font_description(fontBold)
|
---|
816 | (_ink, logical) = layout.get_extents()
|
---|
817 | x3 = x2 + logical.width / Pango.SCALE
|
---|
818 |
|
---|
819 | cr.move_to(x2, y)
|
---|
820 | cr.set_line_width(0.1 * scale)
|
---|
821 | PangoCairo.layout_path(cr, layout)
|
---|
822 | cr.stroke_preserve()
|
---|
823 | cr.fill()
|
---|
824 |
|
---|
825 | layout.set_text(" %s" % (flight.date,))
|
---|
826 | layout.set_font_description(font)
|
---|
827 |
|
---|
828 | cr.move_to(x3, y)
|
---|
829 | cr.set_line_width(0.1 * scale)
|
---|
830 | PangoCairo.layout_path(cr, layout)
|
---|
831 | cr.stroke_preserve()
|
---|
832 | cr.fill()
|
---|
833 |
|
---|
834 | layout.set_text(" %02d:%02d" % (flight.departureTime.hour,
|
---|
835 | flight.departureTime.minute))
|
---|
836 | (_ink, logical) = layout.get_extents()
|
---|
837 | x5 = x0 + width - logical.width / Pango.SCALE
|
---|
838 | cr.move_to(x5, y)
|
---|
839 | cr.set_line_width(0.1 * scale)
|
---|
840 | PangoCairo.layout_path(cr, layout)
|
---|
841 | cr.stroke_preserve()
|
---|
842 | cr.fill()
|
---|
843 |
|
---|
844 | layout.set_text("ETD (UTC):")
|
---|
845 | layout.set_font_description(fontBold)
|
---|
846 | (_ink, logical) = layout.get_extents()
|
---|
847 | x4 = x5 - logical.width / Pango.SCALE
|
---|
848 | cr.move_to(x4, y)
|
---|
849 | cr.set_line_width(0.1 * scale)
|
---|
850 | PangoCairo.layout_path(cr, layout)
|
---|
851 | cr.stroke_preserve()
|
---|
852 | cr.fill()
|
---|
853 |
|
---|
854 | y += logical.height / Pango.SCALE
|
---|
855 | y += 4 * scale
|
---|
856 |
|
---|
857 | layout.set_text("AIRCRAFT:")
|
---|
858 | layout.set_font_description(fontBold)
|
---|
859 | cr.move_to(x0, y)
|
---|
860 | cr.set_line_width(0.1 * scale)
|
---|
861 | PangoCairo.layout_path(cr, layout)
|
---|
862 | cr.stroke_preserve()
|
---|
863 | cr.fill()
|
---|
864 |
|
---|
865 | layout.set_text(aircraftNames[flight.aircraftType].upper())
|
---|
866 | layout.set_font_description(font)
|
---|
867 | cr.move_to(x1, y)
|
---|
868 | cr.set_line_width(0.1 * scale)
|
---|
869 | PangoCairo.layout_path(cr, layout)
|
---|
870 | cr.stroke_preserve()
|
---|
871 | cr.fill()
|
---|
872 |
|
---|
873 | layout.set_text(" %02d:%02d" % (flight.arrivalTime.hour,
|
---|
874 | flight.arrivalTime.minute))
|
---|
875 | cr.move_to(x5, y)
|
---|
876 | cr.set_line_width(0.1 * scale)
|
---|
877 | PangoCairo.layout_path(cr, layout)
|
---|
878 | cr.stroke_preserve()
|
---|
879 | cr.fill()
|
---|
880 |
|
---|
881 | layout.set_text("ETA (UTC):")
|
---|
882 | layout.set_font_description(fontBold)
|
---|
883 | cr.move_to(x4, y)
|
---|
884 | cr.set_line_width(0.1 * scale)
|
---|
885 | PangoCairo.layout_path(cr, layout)
|
---|
886 | cr.stroke_preserve()
|
---|
887 | cr.fill()
|
---|
888 |
|
---|
889 | y += logical.height / Pango.SCALE
|
---|
890 | y += 4 * scale
|
---|
891 |
|
---|
892 | layout.set_text("CREW:")
|
---|
893 | layout.set_font_description(fontBold)
|
---|
894 | cr.move_to(x0, y)
|
---|
895 | cr.set_line_width(0.1 * scale)
|
---|
896 | PangoCairo.layout_path(cr, layout)
|
---|
897 | cr.stroke_preserve()
|
---|
898 | cr.fill()
|
---|
899 |
|
---|
900 | layout.set_text("%d + %d" % (flight.numCockpitCrew,
|
---|
901 | flight.numCabinCrew))
|
---|
902 | layout.set_font_description(font)
|
---|
903 | cr.move_to(x1, y)
|
---|
904 | cr.set_line_width(0.1 * scale)
|
---|
905 | PangoCairo.layout_path(cr, layout)
|
---|
906 | cr.stroke_preserve()
|
---|
907 | cr.fill()
|
---|
908 |
|
---|
909 | layout.set_text("DOW:")
|
---|
910 | layout.set_font_description(fontBold)
|
---|
911 | cr.move_to(x4, y)
|
---|
912 | cr.set_line_width(0.1 * scale)
|
---|
913 | PangoCairo.layout_path(cr, layout)
|
---|
914 | cr.stroke_preserve()
|
---|
915 | cr.fill()
|
---|
916 |
|
---|
917 | layout.set_text("%d KG" % (flight.dow,))
|
---|
918 | layout.set_font_description(font)
|
---|
919 | (_ink, logical) = layout.get_extents()
|
---|
920 | x5 = x0 + width - logical.width / Pango.SCALE
|
---|
921 | cr.move_to(x5, y)
|
---|
922 | cr.set_line_width(0.1 * scale)
|
---|
923 | PangoCairo.layout_path(cr, layout)
|
---|
924 | cr.stroke_preserve()
|
---|
925 | cr.fill()
|
---|
926 |
|
---|
927 | y += logical.height / Pango.SCALE
|
---|
928 | y += logical.height / Pango.SCALE
|
---|
929 | y += 4 * scale
|
---|
930 |
|
---|
931 | layout.set_text("PASSENGERS")
|
---|
932 | layout.set_font_description(fontBold)
|
---|
933 | cr.move_to(x0, y)
|
---|
934 | cr.set_line_width(0.1 * scale)
|
---|
935 | PangoCairo.layout_path(cr, layout)
|
---|
936 | cr.stroke_preserve()
|
---|
937 | cr.fill()
|
---|
938 |
|
---|
939 | layout.set_text("CARGO HOLDS")
|
---|
940 | layout.set_font_description(fontBold)
|
---|
941 | cr.move_to(x2, y)
|
---|
942 | cr.set_line_width(0.1 * scale)
|
---|
943 | PangoCairo.layout_path(cr, layout)
|
---|
944 | cr.stroke_preserve()
|
---|
945 | cr.fill()
|
---|
946 |
|
---|
947 | layout.set_text("TOTAL")
|
---|
948 | layout.set_font_description(fontBold)
|
---|
949 | cr.move_to(x4, y)
|
---|
950 | cr.set_line_width(0.1 * scale)
|
---|
951 | PangoCairo.layout_path(cr, layout)
|
---|
952 | cr.stroke_preserve()
|
---|
953 | cr.fill()
|
---|
954 |
|
---|
955 | y += logical.height / Pango.SCALE
|
---|
956 | y += 4 * scale
|
---|
957 |
|
---|
958 | layout.set_text("CHILDREN:")
|
---|
959 | layout.set_font_description(font)
|
---|
960 | (_ink, logical) = layout.get_extents()
|
---|
961 | x1 = x0 + logical.width / Pango.SCALE
|
---|
962 |
|
---|
963 | layout.set_text("CARGO:")
|
---|
964 | layout.set_font_description(font)
|
---|
965 | (_ink, logical) = layout.get_extents()
|
---|
966 | x3 = x2 + logical.width / Pango.SCALE
|
---|
967 |
|
---|
968 | layout.set_text("ADULTS:")
|
---|
969 | layout.set_font_description(font)
|
---|
970 | cr.move_to(x0, y)
|
---|
971 | cr.set_line_width(0.1 * scale)
|
---|
972 | PangoCairo.layout_path(cr, layout)
|
---|
973 | cr.stroke_preserve()
|
---|
974 | cr.fill()
|
---|
975 |
|
---|
976 | layout.set_text(" %3d" % (flight.numPassengers,))
|
---|
977 | layout.set_font_description(font)
|
---|
978 | cr.move_to(x1, y)
|
---|
979 | cr.set_line_width(0.1 * scale)
|
---|
980 | PangoCairo.layout_path(cr, layout)
|
---|
981 | cr.stroke_preserve()
|
---|
982 | cr.fill()
|
---|
983 |
|
---|
984 | layout.set_text("BAGS:")
|
---|
985 | layout.set_font_description(font)
|
---|
986 | cr.move_to(x2, y)
|
---|
987 | cr.set_line_width(0.1 * scale)
|
---|
988 | PangoCairo.layout_path(cr, layout)
|
---|
989 | cr.stroke_preserve()
|
---|
990 | cr.fill()
|
---|
991 |
|
---|
992 | layout.set_text(" %5d KG" % (flight.bagWeight,))
|
---|
993 | layout.set_font_description(font)
|
---|
994 | cr.move_to(x3, y)
|
---|
995 | cr.set_line_width(0.1 * scale)
|
---|
996 | PangoCairo.layout_path(cr, layout)
|
---|
997 | cr.stroke_preserve()
|
---|
998 | cr.fill()
|
---|
999 |
|
---|
1000 | y += logical.height / Pango.SCALE
|
---|
1001 | y += 4 * scale
|
---|
1002 |
|
---|
1003 | layout.set_text("CHILDREN:")
|
---|
1004 | layout.set_font_description(font)
|
---|
1005 | cr.move_to(x0, y)
|
---|
1006 | cr.set_line_width(0.1 * scale)
|
---|
1007 | PangoCairo.layout_path(cr, layout)
|
---|
1008 | cr.stroke_preserve()
|
---|
1009 | cr.fill()
|
---|
1010 |
|
---|
1011 | layout.set_text(" %3d" % (flight.numChildren,))
|
---|
1012 | layout.set_font_description(font)
|
---|
1013 | cr.move_to(x1, y)
|
---|
1014 | cr.set_line_width(0.1 * scale)
|
---|
1015 | PangoCairo.layout_path(cr, layout)
|
---|
1016 | cr.stroke_preserve()
|
---|
1017 | cr.fill()
|
---|
1018 |
|
---|
1019 | layout.set_text("MAIL:")
|
---|
1020 | layout.set_font_description(font)
|
---|
1021 | cr.move_to(x2, y)
|
---|
1022 | cr.set_line_width(0.1 * scale)
|
---|
1023 | PangoCairo.layout_path(cr, layout)
|
---|
1024 | cr.stroke_preserve()
|
---|
1025 | cr.fill()
|
---|
1026 |
|
---|
1027 | layout.set_text(" %5d KG" % (flight.mailWeight,))
|
---|
1028 | layout.set_font_description(font)
|
---|
1029 | cr.move_to(x3, y)
|
---|
1030 | cr.set_line_width(0.1 * scale)
|
---|
1031 | PangoCairo.layout_path(cr, layout)
|
---|
1032 | cr.stroke_preserve()
|
---|
1033 | cr.fill()
|
---|
1034 |
|
---|
1035 | layout.set_text("PAYLOAD:")
|
---|
1036 | layout.set_font_description(font)
|
---|
1037 | cr.move_to(x4, y)
|
---|
1038 | cr.set_line_width(0.1 * scale)
|
---|
1039 | PangoCairo.layout_path(cr, layout)
|
---|
1040 | cr.stroke_preserve()
|
---|
1041 | cr.fill()
|
---|
1042 |
|
---|
1043 | layout.set_text("%5d KG" % (flight.payload,))
|
---|
1044 | layout.set_font_description(font)
|
---|
1045 | (_ink, logical) = layout.get_extents()
|
---|
1046 | x5 = x0 + width - logical.width / Pango.SCALE
|
---|
1047 | cr.move_to(x5, y)
|
---|
1048 | cr.set_line_width(0.1 * scale)
|
---|
1049 | PangoCairo.layout_path(cr, layout)
|
---|
1050 | cr.stroke_preserve()
|
---|
1051 | cr.fill()
|
---|
1052 |
|
---|
1053 | y += logical.height / Pango.SCALE
|
---|
1054 | y += 4 * scale
|
---|
1055 |
|
---|
1056 | layout.set_text("INFANTS:")
|
---|
1057 | layout.set_font_description(font)
|
---|
1058 | cr.move_to(x0, y)
|
---|
1059 | cr.set_line_width(0.1 * scale)
|
---|
1060 | PangoCairo.layout_path(cr, layout)
|
---|
1061 | cr.stroke_preserve()
|
---|
1062 | cr.fill()
|
---|
1063 |
|
---|
1064 | layout.set_text(" %3d" % (flight.numInfants,))
|
---|
1065 | layout.set_font_description(font)
|
---|
1066 | cr.move_to(x1, y)
|
---|
1067 | cr.set_line_width(0.1 * scale)
|
---|
1068 | PangoCairo.layout_path(cr, layout)
|
---|
1069 | cr.stroke_preserve()
|
---|
1070 | cr.fill()
|
---|
1071 |
|
---|
1072 | layout.set_text("CARGO:")
|
---|
1073 | layout.set_font_description(font)
|
---|
1074 | cr.move_to(x2, y)
|
---|
1075 | cr.set_line_width(0.1 * scale)
|
---|
1076 | PangoCairo.layout_path(cr, layout)
|
---|
1077 | cr.stroke_preserve()
|
---|
1078 | cr.fill()
|
---|
1079 |
|
---|
1080 | layout.set_text(" %5d KG" % (flight.cargoWeight,))
|
---|
1081 | layout.set_font_description(font)
|
---|
1082 | cr.move_to(x3, y)
|
---|
1083 | cr.set_line_width(0.1 * scale)
|
---|
1084 | PangoCairo.layout_path(cr, layout)
|
---|
1085 | cr.stroke_preserve()
|
---|
1086 | cr.fill()
|
---|
1087 |
|
---|
1088 | layout.set_text("ZFW:")
|
---|
1089 | layout.set_font_description(font)
|
---|
1090 | cr.move_to(x4, y)
|
---|
1091 | cr.set_line_width(0.1 * scale)
|
---|
1092 | PangoCairo.layout_path(cr, layout)
|
---|
1093 | cr.stroke_preserve()
|
---|
1094 | cr.fill()
|
---|
1095 |
|
---|
1096 | layout.set_text("%5d KG" % (flight.dow + flight.payload,))
|
---|
1097 | layout.set_font_description(font)
|
---|
1098 | (_ink, logical) = layout.get_extents()
|
---|
1099 | x5 = x0 + width - logical.width / Pango.SCALE
|
---|
1100 | cr.move_to(x5, y)
|
---|
1101 | cr.set_line_width(0.1 * scale)
|
---|
1102 | PangoCairo.layout_path(cr, layout)
|
---|
1103 | cr.stroke_preserve()
|
---|
1104 | cr.fill()
|
---|
1105 |
|
---|
1106 | y += logical.height / Pango.SCALE
|
---|
1107 | y += logical.height / Pango.SCALE
|
---|
1108 | y += 4 * scale
|
---|
1109 |
|
---|
1110 | layout.set_text("ROUTE:")
|
---|
1111 | layout.set_font_description(fontBold)
|
---|
1112 | (_ink, logical) = layout.get_extents()
|
---|
1113 | x1 = x0 + logical.width / Pango.SCALE
|
---|
1114 | cr.move_to(x0, y)
|
---|
1115 | cr.set_line_width(0.1 * scale)
|
---|
1116 | PangoCairo.layout_path(cr, layout)
|
---|
1117 | cr.stroke_preserve()
|
---|
1118 | cr.fill()
|
---|
1119 |
|
---|
1120 | routeWords = flight.route.split(" ")
|
---|
1121 | layout.set_font_description(font)
|
---|
1122 |
|
---|
1123 | startWord = 0
|
---|
1124 | textWidth = width - (x1 - x0)
|
---|
1125 | while startWord<len(routeWords):
|
---|
1126 | endWord = startWord + 1
|
---|
1127 | while endWord<=len(routeWords):
|
---|
1128 | layout.set_text(" %s" % (" ".join(routeWords[startWord:endWord]),))
|
---|
1129 | (_ink, logical) = layout.get_extents()
|
---|
1130 | if textWidth<logical.width / Pango.SCALE:
|
---|
1131 | endWord -= 1
|
---|
1132 | if endWord<=startWord:
|
---|
1133 | endWord = startWord + 1
|
---|
1134 | break
|
---|
1135 | endWord += 1
|
---|
1136 |
|
---|
1137 | layout.set_text(" %s" % (" ".join(routeWords[startWord:endWord]),))
|
---|
1138 | cr.move_to(x1, y)
|
---|
1139 | cr.set_line_width(0.1 * scale)
|
---|
1140 | PangoCairo.layout_path(cr, layout)
|
---|
1141 | cr.stroke_preserve()
|
---|
1142 | cr.fill()
|
---|
1143 |
|
---|
1144 | startWord = endWord
|
---|
1145 |
|
---|
1146 | y += logical.height / Pango.SCALE
|
---|
1147 | y += 4 * scale
|
---|
1148 |
|
---|
1149 | y += logical.height / Pango.SCALE
|
---|
1150 |
|
---|
1151 | layout.set_text(delimiter)
|
---|
1152 | layout.set_font_description(font)
|
---|
1153 | cr.move_to(x0, y)
|
---|
1154 | cr.set_line_width(0.1 * scale)
|
---|
1155 | PangoCairo.layout_path(cr, layout)
|
---|
1156 | cr.stroke_preserve()
|
---|
1157 | cr.fill()
|
---|
1158 |
|
---|
1159 | def _deleteClicked(self, button):
|
---|
1160 | """Called when the Delete flight button is clicked."""
|
---|
1161 | self._deleteSelected()
|
---|
1162 |
|
---|
1163 | def _deleteSelected(self):
|
---|
1164 | """Delete the selected flight."""
|
---|
1165 | if askYesNo(xstr("flightsel_delete_confirm"),
|
---|
1166 | parent = self._wizard.gui.mainWindow):
|
---|
1167 | flight = self._getSelectedFlight()
|
---|
1168 | gui = self._wizard.gui
|
---|
1169 | gui.beginBusy(xstr("flightsel_delete_busy"))
|
---|
1170 |
|
---|
1171 | gui.webHandler.deleteFlights(self._deleteResultCallback,
|
---|
1172 | [flight.id])
|
---|
1173 |
|
---|
1174 | def _deleteResultCallback(self, returned, result):
|
---|
1175 | """Called when the deletion result is available."""
|
---|
1176 | GObject.idle_add(self._handleDeleteResult, returned, result)
|
---|
1177 |
|
---|
1178 | def _handleDeleteResult(self, returned, result):
|
---|
1179 | """Handle the delete result."""
|
---|
1180 | gui = self._wizard.gui
|
---|
1181 | gui.endBusy()
|
---|
1182 |
|
---|
1183 | if returned:
|
---|
1184 | indexes = self._flightList.selectedIndexes
|
---|
1185 |
|
---|
1186 | flights = [self._flights[index] for index in indexes]
|
---|
1187 |
|
---|
1188 | self._flightList.removeFlights(indexes)
|
---|
1189 | for index in indexes[::-1]:
|
---|
1190 | del self._flights[index]
|
---|
1191 | else:
|
---|
1192 | communicationErrorDialog()
|
---|
1193 |
|
---|
1194 |
|
---|
1195 | def _refreshClicked(self, button):
|
---|
1196 | """Called when the refresh button is clicked."""
|
---|
1197 | self._wizard.reloadFlights(self._refreshCallback)
|
---|
1198 |
|
---|
1199 | def _refreshCallback(self, returned, result):
|
---|
1200 | """Callback for the refresh."""
|
---|
1201 | if returned:
|
---|
1202 | self._setupHelp()
|
---|
1203 | if result.loggedIn:
|
---|
1204 | self._buildFlights()
|
---|
1205 |
|
---|
1206 | def _selectionChanged(self, flightList, indexes):
|
---|
1207 | """Called when the selection is changed."""
|
---|
1208 | self._saveButton.set_sensitive(len(indexes)==1)
|
---|
1209 | self._printButton.set_sensitive(len(indexes)==1)
|
---|
1210 | self._deleteButton.set_sensitive(len(indexes)==1)
|
---|
1211 | self._updateNextButton()
|
---|
1212 |
|
---|
1213 | def _updatePendingButton(self):
|
---|
1214 | """Update the senstivity of the Pending button."""
|
---|
1215 | self._pendingButton.set_sensitive(self._pendingFlightsWindow.hasFlights)
|
---|
1216 |
|
---|
1217 | def _updateNextButton(self):
|
---|
1218 | """Update the sensitivity of the Next button."""
|
---|
1219 | sensitive = len(self._flightList.selectedIndexes)==1 and \
|
---|
1220 | not self._pendingFlightsWindowShown
|
---|
1221 | if sensitive:
|
---|
1222 | flight = self._getSelectedFlight()
|
---|
1223 | flightDate = datetime.datetime.strptime(flight.date, "%Y-%m-%d").date()
|
---|
1224 | tomorrow = datetime.date.today() + datetime.timedelta(days=1)
|
---|
1225 | print(flightDate, tomorrow)
|
---|
1226 | sensitive = flightDate <= tomorrow
|
---|
1227 | self._button.set_sensitive(sensitive)
|
---|
1228 |
|
---|
1229 | def _loadButtonClicked(self, loadButton):
|
---|
1230 | """Called when the load a flight button is clicked."""
|
---|
1231 | dialog = self._getLoadDialog()
|
---|
1232 | dialog.show_all()
|
---|
1233 | response = dialog.run()
|
---|
1234 | dialog.hide()
|
---|
1235 |
|
---|
1236 | if response==Gtk.ResponseType.OK:
|
---|
1237 | fileName = dialog.get_filename()
|
---|
1238 | print("Loading", fileName)
|
---|
1239 | bookedFlight = web.BookedFlight()
|
---|
1240 | try:
|
---|
1241 | with open(fileName, "rt") as f:
|
---|
1242 | bookedFlight.readFromFile(f, self._wizard._loginResult.fleet)
|
---|
1243 | self.addFlight(bookedFlight)
|
---|
1244 | except Exception as e:
|
---|
1245 | print("Failed to load flight:", util.utf2unicode(str(e)))
|
---|
1246 | dialog = Gtk.MessageDialog(parent = self._wizard.gui.mainWindow,
|
---|
1247 | type = Gtk.MessageType.ERROR,
|
---|
1248 | message_format =
|
---|
1249 | xstr("flightsel_load_failed"))
|
---|
1250 | dialog.add_button(xstr("button_ok"), Gtk.ResponseType.OK)
|
---|
1251 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
1252 | secondary = xstr("flightsel_load_failed_sec")
|
---|
1253 | dialog.format_secondary_markup(secondary)
|
---|
1254 | dialog.run()
|
---|
1255 | dialog.hide()
|
---|
1256 |
|
---|
1257 | def _forwardClicked(self, button):
|
---|
1258 | """Called when the forward button was clicked."""
|
---|
1259 | if self._completed:
|
---|
1260 | self._wizard.jumpPage(self._nextID, finalize = False)
|
---|
1261 | else:
|
---|
1262 | self._flightSelected()
|
---|
1263 |
|
---|
1264 | def _rowActivated(self, flightList, index):
|
---|
1265 | """Called when a row is activated."""
|
---|
1266 | if not self._completed:
|
---|
1267 | self._flightSelected()
|
---|
1268 |
|
---|
1269 | def _flightSelected(self):
|
---|
1270 | """Called when a flight has been selected."""
|
---|
1271 | flight = self._getSelectedFlight()
|
---|
1272 | self._wizard._bookedFlight = flight
|
---|
1273 | self._wizard.gui.enableFlightInfo(flight.aircraftType)
|
---|
1274 |
|
---|
1275 | self._updateDepartureGate()
|
---|
1276 |
|
---|
1277 | def _getSelectedFlight(self):
|
---|
1278 | """Get the currently selected flight."""
|
---|
1279 | indexes = self._flightList.selectedIndexes
|
---|
1280 | assert(len(indexes)==1)
|
---|
1281 | return self._flights[indexes[0]]
|
---|
1282 |
|
---|
1283 | def _updateDepartureGate(self):
|
---|
1284 | """Update the departure gate for the booked flight."""
|
---|
1285 | flight = self._wizard._bookedFlight
|
---|
1286 | if self._wizard.gui.config.onlineGateSystem and \
|
---|
1287 | self._wizard.loggedIn and not self._wizard.entranceExam:
|
---|
1288 | if flight.departureICAO=="LHBP":
|
---|
1289 | self._wizard.getFleet(self._fleetRetrieved)
|
---|
1290 | else:
|
---|
1291 | self._wizard.updatePlane(self._planeUpdated,
|
---|
1292 | flight.tailNumber,
|
---|
1293 | const.PLANE_AWAY)
|
---|
1294 | else:
|
---|
1295 | self._nextID = "connect"
|
---|
1296 | self._wizard.jumpPage("connect")
|
---|
1297 |
|
---|
1298 | def _fleetRetrieved(self, fleet):
|
---|
1299 | """Called when the fleet has been retrieved."""
|
---|
1300 | if fleet is None:
|
---|
1301 | self._nextID = "connect"
|
---|
1302 | self._wizard.jumpPage("connect")
|
---|
1303 | else:
|
---|
1304 | plane = fleet[self._wizard._bookedFlight.tailNumber]
|
---|
1305 | if plane is None:
|
---|
1306 | self._nextID = "connect"
|
---|
1307 | self._wizard.jumpPage("connect")
|
---|
1308 | elif plane.gateNumber is not None and \
|
---|
1309 | not fleet.isGateConflicting(plane):
|
---|
1310 | self._wizard._departureGate = plane.gateNumber
|
---|
1311 | self._nextID = "connect"
|
---|
1312 | self._wizard.jumpPage("connect")
|
---|
1313 | else:
|
---|
1314 | self._nextID = "gatesel"
|
---|
1315 | self._wizard.jumpPage("gatesel")
|
---|
1316 |
|
---|
1317 | def _planeUpdated(self, success):
|
---|
1318 | """Callback for the plane updating."""
|
---|
1319 | self._nextID = "connect"
|
---|
1320 | self._wizard.jumpPage("connect")
|
---|
1321 |
|
---|
1322 | def _getSaveDialog(self):
|
---|
1323 | """Get the dialog to load a flight file."""
|
---|
1324 | if self._saveDialog is not None:
|
---|
1325 | return self._saveDialog
|
---|
1326 |
|
---|
1327 | gui = self._wizard.gui
|
---|
1328 | dialog = Gtk.FileChooserDialog(title = WINDOW_TITLE_BASE + " - " +
|
---|
1329 | xstr("flightsel_save_title"),
|
---|
1330 | action = Gtk.FileChooserAction.SAVE,
|
---|
1331 | buttons = (Gtk.STOCK_CANCEL,
|
---|
1332 | Gtk.ResponseType.CANCEL,
|
---|
1333 | Gtk.STOCK_OK, Gtk.ResponseType.OK),
|
---|
1334 | parent = gui.mainWindow)
|
---|
1335 | dialog.set_modal(True)
|
---|
1336 | dialog.set_do_overwrite_confirmation(True)
|
---|
1337 |
|
---|
1338 | filter = Gtk.FileFilter()
|
---|
1339 | filter.set_name(xstr("flightsel_filter_flights"))
|
---|
1340 | filter.add_pattern("*.vaflight")
|
---|
1341 | dialog.add_filter(filter)
|
---|
1342 |
|
---|
1343 | filter = Gtk.FileFilter()
|
---|
1344 | filter.set_name(xstr("file_filter_all"))
|
---|
1345 | filter.add_pattern("*.*")
|
---|
1346 | dialog.add_filter(filter)
|
---|
1347 |
|
---|
1348 | self._saveDialog = dialog
|
---|
1349 |
|
---|
1350 | return dialog
|
---|
1351 |
|
---|
1352 | def _getLoadDialog(self):
|
---|
1353 | """Get the dialog to load a flight file."""
|
---|
1354 | if self._loadDialog is not None:
|
---|
1355 | return self._loadDialog
|
---|
1356 |
|
---|
1357 | gui = self._wizard.gui
|
---|
1358 | dialog = Gtk.FileChooserDialog(title = WINDOW_TITLE_BASE + " - " +
|
---|
1359 | xstr("flightsel_load_title"),
|
---|
1360 | action = Gtk.FileChooserAction.OPEN,
|
---|
1361 | buttons = (Gtk.STOCK_CANCEL,
|
---|
1362 | Gtk.ResponseType.CANCEL,
|
---|
1363 | Gtk.STOCK_OK, Gtk.ResponseType.OK),
|
---|
1364 | parent = gui.mainWindow)
|
---|
1365 | dialog.set_modal(True)
|
---|
1366 |
|
---|
1367 | filter = Gtk.FileFilter()
|
---|
1368 | filter.set_name(xstr("flightsel_filter_flights"))
|
---|
1369 | filter.add_pattern("*.vaflight")
|
---|
1370 | dialog.add_filter(filter)
|
---|
1371 |
|
---|
1372 | filter = Gtk.FileFilter()
|
---|
1373 | filter.set_name(xstr("file_filter_all"))
|
---|
1374 | filter.add_pattern("*.*")
|
---|
1375 | dialog.add_filter(filter)
|
---|
1376 |
|
---|
1377 | self._loadDialog = dialog
|
---|
1378 |
|
---|
1379 | return dialog
|
---|
1380 |
|
---|
1381 | def _createListPopupMenu(self):
|
---|
1382 | """Get the flight list popup menu."""
|
---|
1383 | menu = Gtk.Menu()
|
---|
1384 |
|
---|
1385 | menuItem = Gtk.MenuItem()
|
---|
1386 | menuItem.set_label(xstr("flightsel_popup_select"))
|
---|
1387 | menuItem.set_use_underline(True)
|
---|
1388 | menuItem.connect("activate", self._popupSelect)
|
---|
1389 | menuItem.show()
|
---|
1390 |
|
---|
1391 | menu.append(menuItem)
|
---|
1392 |
|
---|
1393 | menuItem = Gtk.MenuItem()
|
---|
1394 | menuItem.set_label(xstr("flightsel_popup_save"))
|
---|
1395 | menuItem.set_use_underline(True)
|
---|
1396 | menuItem.connect("activate", self._popupSave)
|
---|
1397 | menuItem.show()
|
---|
1398 |
|
---|
1399 | menu.append(menuItem)
|
---|
1400 |
|
---|
1401 | menuItem = Gtk.MenuItem()
|
---|
1402 | menuItem.set_label(xstr("flightsel_popup_print"))
|
---|
1403 | menuItem.set_use_underline(True)
|
---|
1404 | menuItem.connect("activate", self._popupPrint)
|
---|
1405 | menuItem.show()
|
---|
1406 |
|
---|
1407 | menu.append(menuItem)
|
---|
1408 |
|
---|
1409 | menuItem = Gtk.MenuItem()
|
---|
1410 | menuItem.set_label(xstr("flightsel_popup_delete"))
|
---|
1411 | menuItem.set_use_underline(True)
|
---|
1412 | menuItem.connect("activate", self._popupDelete)
|
---|
1413 | menuItem.show()
|
---|
1414 |
|
---|
1415 | menu.append(menuItem)
|
---|
1416 |
|
---|
1417 | return menu
|
---|
1418 |
|
---|
1419 | def _popupSelect(self, menuItem):
|
---|
1420 | """Called when the Select menu item is activated in the popup menu."""
|
---|
1421 | if not self._completed:
|
---|
1422 | self._flightSelected()
|
---|
1423 |
|
---|
1424 | def _popupSave(self, menuItem):
|
---|
1425 | """Called when the Save menu item is activated in the popup menu."""
|
---|
1426 | if not self._completed:
|
---|
1427 | self._saveSelected()
|
---|
1428 |
|
---|
1429 | def _popupPrint(self, menuItem):
|
---|
1430 | """Called when the Print briefing menu item is activated in the popup menu."""
|
---|
1431 | if not self._completed:
|
---|
1432 | self._printSelected()
|
---|
1433 |
|
---|
1434 | def _popupDelete(self, menuItem):
|
---|
1435 | """Called when the Delete menu item is activated in the popup menu."""
|
---|
1436 | if not self._completed:
|
---|
1437 | self._deleteSelected()
|
---|
1438 |
|
---|
1439 | #-----------------------------------------------------------------------------
|
---|
1440 |
|
---|
1441 | class GateSelectionPage(Page):
|
---|
1442 | """Page to select a free gate at LHBP.
|
---|
1443 | This page should be displayed only if we have fleet information!."""
|
---|
1444 | def __init__(self, wizard):
|
---|
1445 | """Construct the gate selection page."""
|
---|
1446 | super(GateSelectionPage, self).__init__(wizard, "gatesel",
|
---|
1447 | xstr("gatesel_title"),
|
---|
1448 | xstr("gatesel_help"))
|
---|
1449 |
|
---|
1450 | self._listStore = Gtk.ListStore(str)
|
---|
1451 | self._gateList = Gtk.TreeView(self._listStore)
|
---|
1452 | column = Gtk.TreeViewColumn(None, Gtk.CellRendererText(),
|
---|
1453 | text = 0)
|
---|
1454 | column.set_expand(True)
|
---|
1455 | self._gateList.append_column(column)
|
---|
1456 | self._gateList.set_headers_visible(False)
|
---|
1457 | self._gateList.connect("row-activated", self._rowActivated)
|
---|
1458 |
|
---|
1459 | gateSelection = self._gateList.get_selection()
|
---|
1460 | gateSelection.connect("changed", self._selectionChanged)
|
---|
1461 |
|
---|
1462 | scrolledWindow = Gtk.ScrolledWindow()
|
---|
1463 | scrolledWindow.add(self._gateList)
|
---|
1464 | scrolledWindow.set_size_request(50, -1)
|
---|
1465 | scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC,
|
---|
1466 | Gtk.PolicyType.AUTOMATIC)
|
---|
1467 | scrolledWindow.set_shadow_type(Gtk.ShadowType.IN)
|
---|
1468 |
|
---|
1469 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.0, xscale = 0.0, yscale = 1.0)
|
---|
1470 | alignment.add(scrolledWindow)
|
---|
1471 |
|
---|
1472 | self.setMainWidget(alignment)
|
---|
1473 |
|
---|
1474 | self.addCancelFlightButton()
|
---|
1475 |
|
---|
1476 | self.addPreviousButton(clicked = self._backClicked)
|
---|
1477 |
|
---|
1478 | self._button = self.addNextButton(sensitive = False,
|
---|
1479 | clicked = self._forwardClicked)
|
---|
1480 |
|
---|
1481 | def activate(self):
|
---|
1482 | """Fill the gate list."""
|
---|
1483 | self._listStore.clear()
|
---|
1484 | self._gateList.set_sensitive(True)
|
---|
1485 | occupiedGateNumbers = self._wizard._fleet.getOccupiedGateNumbers()
|
---|
1486 | for gate in lhbpGates.gates:
|
---|
1487 | if gate.isAvailable(lhbpGates, occupiedGateNumbers):
|
---|
1488 | self._listStore.append([gate.number])
|
---|
1489 |
|
---|
1490 | def finalize(self):
|
---|
1491 | """Finalize the page."""
|
---|
1492 | self._gateList.set_sensitive(False)
|
---|
1493 |
|
---|
1494 | def _selectionChanged(self, selection):
|
---|
1495 | """Called when the selection is changed."""
|
---|
1496 | self._button.set_sensitive(selection.count_selected_rows()==1)
|
---|
1497 |
|
---|
1498 | def _backClicked(self, button):
|
---|
1499 | """Called when the Back button is pressed."""
|
---|
1500 | self.goBack()
|
---|
1501 |
|
---|
1502 | def _forwardClicked(self, button):
|
---|
1503 | """Called when the forward button is clicked."""
|
---|
1504 | if not self._completed:
|
---|
1505 | self._gateSelected()
|
---|
1506 | else:
|
---|
1507 | self._wizard.jumpPage("connect")
|
---|
1508 |
|
---|
1509 | def _rowActivated(self, flightList, path, column):
|
---|
1510 | """Called when a row is activated."""
|
---|
1511 | if not self._completed:
|
---|
1512 | self._gateSelected()
|
---|
1513 |
|
---|
1514 | def _gateSelected(self):
|
---|
1515 | """Called when a gate has been selected."""
|
---|
1516 | selection = self._gateList.get_selection()
|
---|
1517 | (listStore, iter) = selection.get_selected()
|
---|
1518 | (gateNumber,) = listStore.get(iter, 0)
|
---|
1519 |
|
---|
1520 | self._wizard._departureGate = gateNumber
|
---|
1521 |
|
---|
1522 | self._wizard.updatePlane(self._planeUpdated,
|
---|
1523 | self._wizard._bookedFlight.tailNumber,
|
---|
1524 | const.PLANE_HOME, gateNumber)
|
---|
1525 |
|
---|
1526 | def _planeUpdated(self, success):
|
---|
1527 | """Callback for the plane updating call."""
|
---|
1528 | if success is None or success:
|
---|
1529 | self._wizard.jumpPage("connect")
|
---|
1530 | else:
|
---|
1531 | dialog = Gtk.MessageDialog(parent = self._wizard.gui.mainWindow,
|
---|
1532 | type = Gtk.MessageType.ERROR,
|
---|
1533 | message_format = xstr("gatesel_conflict"))
|
---|
1534 | dialog.add_button(xstr("button_ok"), Gtk.ResponseType.OK)
|
---|
1535 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
1536 | dialog.format_secondary_markup(xstr("gatesel_conflict_sec"))
|
---|
1537 | dialog.run()
|
---|
1538 | dialog.hide()
|
---|
1539 |
|
---|
1540 | self._wizard.getFleet(self._fleetRetrieved)
|
---|
1541 |
|
---|
1542 | def _fleetRetrieved(self, fleet):
|
---|
1543 | """Called when the fleet has been retrieved."""
|
---|
1544 | if fleet is None:
|
---|
1545 | self._wizard.jumpPage("connect")
|
---|
1546 | else:
|
---|
1547 | self.activate()
|
---|
1548 |
|
---|
1549 | #-----------------------------------------------------------------------------
|
---|
1550 |
|
---|
1551 | class RegisterPage(Page):
|
---|
1552 | """A page to enter the registration data."""
|
---|
1553 |
|
---|
1554 | # The minimal year of birth
|
---|
1555 | _minYearOfBirth = 1900
|
---|
1556 |
|
---|
1557 | # The maximal year of birth
|
---|
1558 | _maxYearOfBirth = datetime.date.today().year
|
---|
1559 |
|
---|
1560 | # The regular expression to check the e-mail address with
|
---|
1561 | _emailAddressRE = re.compile("[^@]+@[^@]+\.[^@]+")
|
---|
1562 |
|
---|
1563 | def __init__(self, wizard):
|
---|
1564 | """Construct the registration page."""
|
---|
1565 | super(RegisterPage, self).__init__(wizard, "register",
|
---|
1566 | xstr("register_title"),
|
---|
1567 | xstr("register_help"))
|
---|
1568 |
|
---|
1569 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
1570 | xscale = 0.0, yscale = 0.0)
|
---|
1571 |
|
---|
1572 | table = Gtk.Table(12, 4)
|
---|
1573 | table.set_row_spacings(4)
|
---|
1574 | table.set_col_spacings(24)
|
---|
1575 | alignment.add(table)
|
---|
1576 | self.setMainWidget(alignment)
|
---|
1577 |
|
---|
1578 | row = 0
|
---|
1579 |
|
---|
1580 | labelAlignment = Gtk.Alignment(xalign = 1.0, yalign = 0.5,
|
---|
1581 | xscale = 0.0, yscale = 0.0)
|
---|
1582 | label = Gtk.Label(xstr("register_name1"))
|
---|
1583 | label.set_use_underline(True)
|
---|
1584 | labelAlignment.add(label)
|
---|
1585 | table.attach(labelAlignment, 0, 1, row, row+1)
|
---|
1586 |
|
---|
1587 | self._name1 = Gtk.Entry()
|
---|
1588 | self._name1.connect("changed", self._updateButtons)
|
---|
1589 | self._name1.set_tooltip_text(xstr("register_name1_tooltip"))
|
---|
1590 | self._name1.set_width_chars(15)
|
---|
1591 | table.attach(self._name1, 1, 2, row, row+1)
|
---|
1592 | label.set_mnemonic_widget(self._name1)
|
---|
1593 |
|
---|
1594 | labelAlignment = Gtk.Alignment(xalign = 1.0, yalign = 0.5,
|
---|
1595 | xscale = 0.0, yscale = 0.0)
|
---|
1596 | label = Gtk.Label(xstr("register_name2"))
|
---|
1597 | label.set_use_underline(True)
|
---|
1598 | labelAlignment.add(label)
|
---|
1599 | table.attach(labelAlignment, 2, 3, row, row+1)
|
---|
1600 |
|
---|
1601 | self._name2 = Gtk.Entry()
|
---|
1602 | self._name2.connect("changed", self._updateButtons)
|
---|
1603 | self._name2.set_tooltip_text(xstr("register_name2_tooltip"))
|
---|
1604 | self._name2.set_width_chars(15)
|
---|
1605 | table.attach(self._name2, 3, 4, row, row+1)
|
---|
1606 | label.set_mnemonic_widget(self._name2)
|
---|
1607 |
|
---|
1608 | row += 1
|
---|
1609 |
|
---|
1610 | labelAlignment = Gtk.Alignment(xalign = 1.0, yalign = 0.5,
|
---|
1611 | xscale = 0.0, yscale = 0.0)
|
---|
1612 | label = Gtk.Label(xstr("register_year_of_birth"))
|
---|
1613 | label.set_use_underline(True)
|
---|
1614 | labelAlignment.add(label)
|
---|
1615 | table.attach(labelAlignment, 0, 1, row, row+1)
|
---|
1616 |
|
---|
1617 | alignment = Gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
1618 | xscale = 0.0, yscale = 0.0)
|
---|
1619 |
|
---|
1620 | self._yearOfBirth = Gtk.SpinButton()
|
---|
1621 | self._yearOfBirth.set_increments(step = 1, page = 10)
|
---|
1622 | self._yearOfBirth.set_range(min = RegisterPage._minYearOfBirth,
|
---|
1623 | max = RegisterPage._maxYearOfBirth)
|
---|
1624 | self._yearOfBirth.set_numeric(True)
|
---|
1625 | self._yearOfBirth.set_tooltip_text(xstr("register_year_of_birth_tooltip"))
|
---|
1626 | self._yearOfBirth.set_width_chars(5)
|
---|
1627 | self._yearOfBirth.connect("changed", self._updateButtons)
|
---|
1628 | self._yearOfBirth.connect("value-changed", self._updateButtons)
|
---|
1629 | alignment.add(self._yearOfBirth)
|
---|
1630 | table.attach(alignment, 1, 2, row, row+1)
|
---|
1631 | label.set_mnemonic_widget(self._yearOfBirth)
|
---|
1632 |
|
---|
1633 | row += 1
|
---|
1634 |
|
---|
1635 | labelAlignment = Gtk.Alignment(xalign = 1.0, yalign = 0.5,
|
---|
1636 | xscale = 0.0, yscale = 0.0)
|
---|
1637 | label = Gtk.Label(xstr("register_email"))
|
---|
1638 | label.set_use_underline(True)
|
---|
1639 | labelAlignment.add(label)
|
---|
1640 | table.attach(labelAlignment, 0, 1, row, row+1)
|
---|
1641 |
|
---|
1642 | self._emailAddress = Gtk.Entry()
|
---|
1643 | self._emailAddress.connect("changed", self._updateButtons)
|
---|
1644 | self._emailAddress.set_tooltip_text(xstr("register_email_tooltip"))
|
---|
1645 | table.attach(self._emailAddress, 1, 2, row, row+1)
|
---|
1646 | label.set_mnemonic_widget(self._emailAddress)
|
---|
1647 |
|
---|
1648 | self._emailAddressPublic = Gtk.CheckButton(xstr("register_email_public"))
|
---|
1649 | self._emailAddressPublic.set_use_underline(True)
|
---|
1650 | self._emailAddressPublic.set_tooltip_text(xstr("register_email_public_tooltip"))
|
---|
1651 | table.attach(self._emailAddressPublic, 2, 4, row, row+1)
|
---|
1652 |
|
---|
1653 | row += 1
|
---|
1654 |
|
---|
1655 | labelAlignment = Gtk.Alignment(xalign = 1.0, yalign = 0.5,
|
---|
1656 | xscale = 0.0, yscale = 0.0)
|
---|
1657 | label = Gtk.Label(xstr("register_vatsim_id"))
|
---|
1658 | label.set_use_underline(True)
|
---|
1659 | labelAlignment.add(label)
|
---|
1660 | table.attach(labelAlignment, 0, 1, row, row+1)
|
---|
1661 |
|
---|
1662 | alignment = Gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
1663 | xscale = 0.0, yscale = 0.0)
|
---|
1664 | self._vatsimID = IntegerEntry()
|
---|
1665 | self._vatsimID.connect("changed", self._updateButtons)
|
---|
1666 | self._vatsimID.set_tooltip_text(xstr("register_vatsim_id_tooltip"))
|
---|
1667 | self._vatsimID.set_width_chars(7)
|
---|
1668 | alignment.add(self._vatsimID)
|
---|
1669 | table.attach(alignment, 1, 2, row, row+1)
|
---|
1670 | label.set_mnemonic_widget(self._vatsimID)
|
---|
1671 |
|
---|
1672 | labelAlignment = Gtk.Alignment(xalign = 0.0, yalign = 0.5,
|
---|
1673 | xscale = 0.0, yscale = 0.0)
|
---|
1674 | label = Gtk.Label(xstr("register_ivao_id"))
|
---|
1675 | label.set_use_underline(True)
|
---|
1676 | labelAlignment.add(label)
|
---|
1677 | table.attach(labelAlignment, 2, 3, row, row+1)
|
---|
1678 |
|
---|
1679 | alignment = Gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
1680 | xscale = 0.0, yscale = 0.0)
|
---|
1681 | self._ivaoID = IntegerEntry()
|
---|
1682 | self._ivaoID.connect("changed", self._updateButtons)
|
---|
1683 | self._ivaoID.set_tooltip_text(xstr("register_ivao_id_tooltip"))
|
---|
1684 | self._ivaoID.set_width_chars(7)
|
---|
1685 | alignment.add(self._ivaoID)
|
---|
1686 | table.attach(alignment, 3, 4, row, row+1)
|
---|
1687 | label.set_mnemonic_widget(self._ivaoID)
|
---|
1688 |
|
---|
1689 | row += 1
|
---|
1690 |
|
---|
1691 | labelAlignment = Gtk.Alignment(xalign = 1.0, yalign = 0.5,
|
---|
1692 | xscale = 0.0, yscale = 0.0)
|
---|
1693 | label = Gtk.Label(xstr("register_phone_num"))
|
---|
1694 | label.set_use_underline(True)
|
---|
1695 | label.set_use_markup(True)
|
---|
1696 | labelAlignment.add(label)
|
---|
1697 | table.attach(labelAlignment, 0, 1, row, row+1)
|
---|
1698 |
|
---|
1699 | self._phoneNumber = Gtk.Entry()
|
---|
1700 | self._phoneNumber.set_tooltip_text(xstr("register_phone_num_tooltip"))
|
---|
1701 | table.attach(self._phoneNumber, 1, 2, row, row+1)
|
---|
1702 | label.set_mnemonic_widget(self._phoneNumber)
|
---|
1703 |
|
---|
1704 | row += 1
|
---|
1705 |
|
---|
1706 | labelAlignment = Gtk.Alignment(xalign = 1.0, yalign = 0.5,
|
---|
1707 | xscale = 0.0, yscale = 0.0)
|
---|
1708 | label = Gtk.Label(xstr("register_nationality"))
|
---|
1709 | label.set_use_underline(True)
|
---|
1710 | label.set_use_markup(True)
|
---|
1711 | labelAlignment.add(label)
|
---|
1712 | table.attach(labelAlignment, 0, 1, row, row+1)
|
---|
1713 |
|
---|
1714 |
|
---|
1715 | self._nationality = Gtk.Entry()
|
---|
1716 | self._nationality.set_tooltip_text(xstr("register_nationality_tooltip"))
|
---|
1717 | table.attach(self._nationality, 1, 2, row, row+1)
|
---|
1718 | label.set_mnemonic_widget(self._nationality)
|
---|
1719 |
|
---|
1720 | placeholder = Gtk.Label()
|
---|
1721 | placeholder.set_text(xstr("register_password_mismatch"))
|
---|
1722 | placeholder.set_use_markup(True)
|
---|
1723 | placeholder.set_child_visible(False)
|
---|
1724 | placeholder.hide()
|
---|
1725 | table.attach(placeholder, 2, 4, row, row+1)
|
---|
1726 |
|
---|
1727 | row += 1
|
---|
1728 |
|
---|
1729 | labelAlignment = Gtk.Alignment(xalign = 1.0, yalign = 0.5,
|
---|
1730 | xscale = 0.0, yscale = 0.0)
|
---|
1731 | label = Gtk.Label(xstr("register_password"))
|
---|
1732 | label.set_use_underline(True)
|
---|
1733 | labelAlignment.add(label)
|
---|
1734 | table.attach(labelAlignment, 0, 1, row, row+1)
|
---|
1735 |
|
---|
1736 | self._password = Gtk.Entry()
|
---|
1737 | self._password.set_visibility(False)
|
---|
1738 | self._password.connect("changed", self._updateButtons)
|
---|
1739 | self._password.set_tooltip_text(xstr("register_password_tooltip"))
|
---|
1740 | table.attach(self._password, 1, 2, row, row+1)
|
---|
1741 | label.set_mnemonic_widget(self._password)
|
---|
1742 |
|
---|
1743 | alignment = Gtk.Alignment(xalign = 0.0, yalign = 0.5,
|
---|
1744 | xscale = 0.0, yscale = 0.0)
|
---|
1745 | self._passwordStatus = Gtk.Label()
|
---|
1746 | alignment.add(self._passwordStatus)
|
---|
1747 | table.attach(alignment, 2, 4, row, row+1)
|
---|
1748 |
|
---|
1749 | row += 1
|
---|
1750 |
|
---|
1751 | labelAlignment = Gtk.Alignment(xalign = 1.0, yalign = 0.5,
|
---|
1752 | xscale = 0.0, yscale = 0.0)
|
---|
1753 | label = Gtk.Label(xstr("register_password2"))
|
---|
1754 | label.set_use_underline(True)
|
---|
1755 | labelAlignment.add(label)
|
---|
1756 | table.attach(labelAlignment, 0, 1, row, row+1)
|
---|
1757 |
|
---|
1758 | self._password2 = Gtk.Entry()
|
---|
1759 | self._password2.set_visibility(False)
|
---|
1760 | self._password2.connect("changed", self._updateButtons)
|
---|
1761 | self._password2.set_tooltip_text(xstr("register_password2_tooltip"))
|
---|
1762 | table.attach(self._password2, 1, 2, row, row+1)
|
---|
1763 | label.set_mnemonic_widget(self._password2)
|
---|
1764 |
|
---|
1765 | alignment = Gtk.Alignment(xalign = 0.0, yalign = 0.5,
|
---|
1766 | xscale = 0.0, yscale = 0.0)
|
---|
1767 | self._password2Status = Gtk.Label()
|
---|
1768 | alignment.add(self._password2Status)
|
---|
1769 | table.attach(alignment, 2, 4, row, row+1)
|
---|
1770 |
|
---|
1771 | row += 1
|
---|
1772 |
|
---|
1773 | self._rememberButton = Gtk.CheckButton(xstr("remember_password"))
|
---|
1774 | self._rememberButton.set_use_underline(True)
|
---|
1775 | self._rememberButton.set_tooltip_text(xstr("login_remember_tooltip"))
|
---|
1776 | table.attach(self._rememberButton, 1, 3, row, row+1)
|
---|
1777 |
|
---|
1778 | cancelButton = \
|
---|
1779 | self.addButton(xstr("button_cancel"))
|
---|
1780 | cancelButton.connect("clicked", self._cancelClicked)
|
---|
1781 |
|
---|
1782 | self._registerButton = \
|
---|
1783 | self.addButton(xstr("button_register"), default = True,
|
---|
1784 | tooltip = xstr("button_register_tooltip"))
|
---|
1785 | self._registerButton.connect("clicked", self._registerClicked)
|
---|
1786 |
|
---|
1787 | self._updateButtons()
|
---|
1788 |
|
---|
1789 | @property
|
---|
1790 | def name1(self):
|
---|
1791 | """Get the first name component entered."""
|
---|
1792 | return self._name1.get_text()
|
---|
1793 |
|
---|
1794 | @property
|
---|
1795 | def name2(self):
|
---|
1796 | """Get the second name component entered."""
|
---|
1797 | return self._name2.get_text()
|
---|
1798 |
|
---|
1799 | @property
|
---|
1800 | def yearOfBirth(self):
|
---|
1801 | """Get the year of birth."""
|
---|
1802 | yearOfBirthText = self._yearOfBirth.get_text()
|
---|
1803 | return int(yearOfBirthText) if yearOfBirthText else 0
|
---|
1804 |
|
---|
1805 | @property
|
---|
1806 | def emailAddress(self):
|
---|
1807 | """Get the e-mail address."""
|
---|
1808 | return self._emailAddress.get_text()
|
---|
1809 |
|
---|
1810 | @property
|
---|
1811 | def emailAddressPublic(self):
|
---|
1812 | """Get the whether the e-mail address is public."""
|
---|
1813 | return self._emailAddressPublic.get_active()
|
---|
1814 |
|
---|
1815 | @property
|
---|
1816 | def vatsimID(self):
|
---|
1817 | """Get the VATSIM ID."""
|
---|
1818 | return self._vatsimID.get_int()
|
---|
1819 |
|
---|
1820 | @property
|
---|
1821 | def ivaoID(self):
|
---|
1822 | """Get the IVAO ID."""
|
---|
1823 | return self._ivaoID.get_int()
|
---|
1824 |
|
---|
1825 | @property
|
---|
1826 | def phoneNumber(self):
|
---|
1827 | """Get the phone number."""
|
---|
1828 | return self._phoneNumber.get_text()
|
---|
1829 |
|
---|
1830 | @property
|
---|
1831 | def nationality(self):
|
---|
1832 | """Get the nationality."""
|
---|
1833 | return self._nationality.get_text()
|
---|
1834 |
|
---|
1835 | @property
|
---|
1836 | def password(self):
|
---|
1837 | """Get the password."""
|
---|
1838 | return self._password.get_text()
|
---|
1839 |
|
---|
1840 | @property
|
---|
1841 | def rememberPassword(self):
|
---|
1842 | """Get whether the password should be remembered."""
|
---|
1843 | return self._rememberButton.get_active()
|
---|
1844 |
|
---|
1845 | def activate(self):
|
---|
1846 | """Setup the route from the booked flight."""
|
---|
1847 | self._yearOfBirth.set_value(0)
|
---|
1848 | self._yearOfBirth.set_text("")
|
---|
1849 | self._updateButtons()
|
---|
1850 |
|
---|
1851 | def _updateButtons(self, widget = None):
|
---|
1852 | """Update the sensitive state of the buttons"""
|
---|
1853 | yearOfBirth = self.yearOfBirth
|
---|
1854 |
|
---|
1855 | emailAddress = self.emailAddress
|
---|
1856 | emailAddressMatch = RegisterPage._emailAddressRE.match(emailAddress)
|
---|
1857 |
|
---|
1858 | vatsimID = self.vatsimID
|
---|
1859 | ivaoID = self.ivaoID
|
---|
1860 |
|
---|
1861 | password = self.password
|
---|
1862 | password2 = self._password2.get_text()
|
---|
1863 | if not password:
|
---|
1864 | self._passwordStatus.set_text("")
|
---|
1865 | elif len(password)<5:
|
---|
1866 | self._passwordStatus.set_text(xstr("register_password_too_short"))
|
---|
1867 | else:
|
---|
1868 | self._passwordStatus.set_text(xstr("register_password_ok"))
|
---|
1869 | self._passwordStatus.set_use_markup(True)
|
---|
1870 |
|
---|
1871 | if len(password)<5 or not password2:
|
---|
1872 | self._password2Status.set_text("")
|
---|
1873 | elif password!=password2:
|
---|
1874 | self._password2Status.set_text(xstr("register_password_mismatch"))
|
---|
1875 | else:
|
---|
1876 | self._password2Status.set_text(xstr("register_password_ok"))
|
---|
1877 | self._password2Status.set_use_markup(True)
|
---|
1878 |
|
---|
1879 | sensitive = \
|
---|
1880 | len(self.name1)>0 and len(self.name2)>0 and \
|
---|
1881 | yearOfBirth>=RegisterPage._minYearOfBirth and \
|
---|
1882 | yearOfBirth<=RegisterPage._maxYearOfBirth and \
|
---|
1883 | emailAddressMatch is not None and \
|
---|
1884 | (vatsimID>=800000 or ivaoID>=100000) and \
|
---|
1885 | len(password)>=5 and password==password2
|
---|
1886 |
|
---|
1887 | self._registerButton.set_sensitive(sensitive)
|
---|
1888 |
|
---|
1889 | def _cancelClicked(self, button):
|
---|
1890 | """Called when the Cancel button is clicked."""
|
---|
1891 | self.goBack()
|
---|
1892 |
|
---|
1893 | def _registerClicked(self, button):
|
---|
1894 | """Called when the Register button is clicked."""
|
---|
1895 | nameOrder = xstr("register_nameorder")
|
---|
1896 |
|
---|
1897 | if nameOrder=="eastern":
|
---|
1898 | surName = self.name1
|
---|
1899 | firstName = self.name2
|
---|
1900 | else:
|
---|
1901 | surName = self.name2
|
---|
1902 | firstName = self.name1
|
---|
1903 |
|
---|
1904 | nationality = self.nationality.lower()
|
---|
1905 |
|
---|
1906 | if getLanguage().lower()=="hu" or nationality.find("hung")!=-1 or \
|
---|
1907 | nationality.find("magyar")!=-1:
|
---|
1908 | requestedNameOrder = "eastern"
|
---|
1909 | else:
|
---|
1910 | requestedNameOrder = "western"
|
---|
1911 |
|
---|
1912 | registrationData = web.Registration(surName, firstName,
|
---|
1913 | requestedNameOrder,
|
---|
1914 | self.yearOfBirth,
|
---|
1915 | self.emailAddress,
|
---|
1916 | self.emailAddressPublic,
|
---|
1917 | self.vatsimID, self.ivaoID,
|
---|
1918 | self.phoneNumber, self.nationality,
|
---|
1919 | self.password)
|
---|
1920 | print("Registering with data:")
|
---|
1921 | print(" name:", self.name1, self.name2, registrationData.firstName, registrationData.surName, requestedNameOrder)
|
---|
1922 | print(" yearOfBirth:", self.yearOfBirth, registrationData.yearOfBirth)
|
---|
1923 | print(" emailAddress:", self.emailAddress, registrationData.emailAddress)
|
---|
1924 | print(" emailAddressPublic:", self.emailAddressPublic, registrationData.emailAddressPublic)
|
---|
1925 | print(" vatsimID:", self.vatsimID, registrationData.vatsimID)
|
---|
1926 | print(" ivaoID:", self.ivaoID, registrationData.ivaoID)
|
---|
1927 | print(" phoneNumber:", self.phoneNumber, registrationData.phoneNumber)
|
---|
1928 | print(" nationality:", self.nationality, registrationData.nationality)
|
---|
1929 |
|
---|
1930 | gui = self._wizard.gui
|
---|
1931 | gui.beginBusy(xstr("register_busy"))
|
---|
1932 | gui.webHandler.register(self._registerResultCallback, registrationData)
|
---|
1933 |
|
---|
1934 | def _registerResultCallback(self, returned, result):
|
---|
1935 | """Called when the registration result is available."""
|
---|
1936 | GObject.idle_add(self._handleRegisterResult, returned, result)
|
---|
1937 |
|
---|
1938 | def _handleRegisterResult(self, returned, result):
|
---|
1939 | """Handle the registration result."""
|
---|
1940 | gui = self._wizard.gui
|
---|
1941 |
|
---|
1942 | gui.endBusy()
|
---|
1943 |
|
---|
1944 | print("Registration result:")
|
---|
1945 | print(" returned:", returned)
|
---|
1946 | if returned:
|
---|
1947 | print(" registered:", result.registered)
|
---|
1948 | if result.registered:
|
---|
1949 | print(" pilotID", result.pilotID)
|
---|
1950 | print(" loggedIn", result.loggedIn)
|
---|
1951 | print(" emailAlreadyRegistered:", result.emailAlreadyRegistered)
|
---|
1952 | print(" invalidData:", result.invalidData)
|
---|
1953 |
|
---|
1954 | registrationOK = returned and result.registered
|
---|
1955 |
|
---|
1956 | message = xstr("register_ok") if registrationOK \
|
---|
1957 | else xstr("register_failed")
|
---|
1958 | secondaryMessage = None
|
---|
1959 | if registrationOK:
|
---|
1960 | if result.loggedIn:
|
---|
1961 | secondaryMessage = xstr("register_info") % (result.pilotID,)
|
---|
1962 | else:
|
---|
1963 | secondaryMessage = xstr("register_nologin") % (result.pilotID,)
|
---|
1964 | messageType = Gtk.MessageType.INFO
|
---|
1965 |
|
---|
1966 | config = gui.config
|
---|
1967 | config.pilotID = result.pilotID
|
---|
1968 | config.rememberPassword = self.rememberPassword
|
---|
1969 | if config.rememberPassword:
|
---|
1970 | config.password = self.password
|
---|
1971 | else:
|
---|
1972 | config.password = ""
|
---|
1973 |
|
---|
1974 | config.save()
|
---|
1975 | elif returned and result.emailAlreadyRegistered:
|
---|
1976 | secondaryMessage = xstr("register_email_already")
|
---|
1977 | messageType = Gtk.MessageType.ERROR
|
---|
1978 | elif returned and result.invalidData:
|
---|
1979 | secondaryMessage = xstr("register_invalid_data")
|
---|
1980 | messageType = Gtk.MessageType.ERROR
|
---|
1981 | else:
|
---|
1982 | secondaryMessage = xstr("register_error")
|
---|
1983 | messageType = Gtk.MessageType.ERROR
|
---|
1984 |
|
---|
1985 | dialog = Gtk.MessageDialog(parent = gui.mainWindow,
|
---|
1986 | type = messageType,
|
---|
1987 | message_format = message)
|
---|
1988 | dialog.set_title(WINDOW_TITLE_BASE + " - " +
|
---|
1989 | xstr("register_result_title"))
|
---|
1990 | dialog.format_secondary_markup(secondaryMessage)
|
---|
1991 |
|
---|
1992 | dialog.add_button(xstr("button_ok"), 0)
|
---|
1993 |
|
---|
1994 | dialog.run()
|
---|
1995 | dialog.hide()
|
---|
1996 |
|
---|
1997 | if registrationOK:
|
---|
1998 | if result.loggedIn:
|
---|
1999 | self._wizard._loginResult = result
|
---|
2000 | self._wizard.nextPage()
|
---|
2001 | else:
|
---|
2002 | self._wizard.jumpPage("login")
|
---|
2003 |
|
---|
2004 | #-----------------------------------------------------------------------------
|
---|
2005 |
|
---|
2006 | class StudentPage(Page):
|
---|
2007 | """A page displayed to students after logging in."""
|
---|
2008 | _entryExamStatusQueryInterval = 60*1000
|
---|
2009 |
|
---|
2010 | def __init__(self, wizard):
|
---|
2011 | """Construct the student page."""
|
---|
2012 | super(StudentPage, self).__init__(wizard, "student",
|
---|
2013 | xstr("student_title"),
|
---|
2014 | xstr("student_help"))
|
---|
2015 |
|
---|
2016 |
|
---|
2017 | self._getEntryExamStatusCancelled = False
|
---|
2018 |
|
---|
2019 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
2020 | xscale = 0.5, yscale = 0.0)
|
---|
2021 |
|
---|
2022 | table = Gtk.Table(6, 4)
|
---|
2023 | table.set_row_spacings(4)
|
---|
2024 | table.set_col_spacings(0)
|
---|
2025 | table.set_homogeneous(False)
|
---|
2026 | alignment.add(table)
|
---|
2027 | self.setMainWidget(alignment)
|
---|
2028 |
|
---|
2029 | row = 0
|
---|
2030 |
|
---|
2031 | labelAlignment = Gtk.Alignment(xalign=0.0, yalign = 0.5,
|
---|
2032 | xscale=0.0, yscale = 0.0)
|
---|
2033 | label = Gtk.Label(xstr("student_entry_exam_status"))
|
---|
2034 | label.set_alignment(0.0, 0.5)
|
---|
2035 | labelAlignment.add(label)
|
---|
2036 | labelAlignment.resize_children()
|
---|
2037 | table.attach(labelAlignment, 0, 1, row, row + 1,
|
---|
2038 | xoptions = Gtk.AttachOptions.FILL)
|
---|
2039 |
|
---|
2040 | alignment = Gtk.Alignment(xalign=0.0, yalign = 0.5,
|
---|
2041 | xscale=1.0, yscale = 0.0)
|
---|
2042 | self._entryExamStatus = Gtk.Label()
|
---|
2043 | self._entryExamStatus.set_use_markup(True)
|
---|
2044 | self._entryExamStatus.set_alignment(0.0, 0.5)
|
---|
2045 | alignment.add(self._entryExamStatus)
|
---|
2046 | alignment.resize_children()
|
---|
2047 | table.attach(alignment, 1, 4, row, row + 1)
|
---|
2048 |
|
---|
2049 | row += 1
|
---|
2050 |
|
---|
2051 | buttonAlignment = Gtk.Alignment(xalign=0.0, xscale=1.0)
|
---|
2052 | button = self._entryExamButton = Gtk.Button(xstr("student_entry_exam"))
|
---|
2053 | button.set_use_underline(True)
|
---|
2054 | button.connect("clicked", self._entryExamClicked)
|
---|
2055 | button.set_tooltip_text(xstr("student_entry_exam_tooltip"))
|
---|
2056 |
|
---|
2057 | buttonAlignment.add(button)
|
---|
2058 | table.attach(buttonAlignment, 0, 4, row, row + 1,
|
---|
2059 | xoptions = Gtk.AttachOptions.FILL,
|
---|
2060 | ypadding = 4)
|
---|
2061 |
|
---|
2062 | row += 3
|
---|
2063 |
|
---|
2064 | labelAlignment = Gtk.Alignment(xalign=0.0, yalign = 0.5,
|
---|
2065 | xscale=0.0, yscale = 0.0)
|
---|
2066 | label = Gtk.Label(xstr("student_check_flight_status"))
|
---|
2067 | labelAlignment.add(label)
|
---|
2068 | table.attach(labelAlignment, 0, 1, row, row + 1,
|
---|
2069 | xoptions = Gtk.AttachOptions.FILL)
|
---|
2070 |
|
---|
2071 | alignment = Gtk.Alignment(xalign=0.0, yalign = 0.5,
|
---|
2072 | xscale=1.0, yscale = 0.0)
|
---|
2073 | self._checkFlightStatus = Gtk.Label()
|
---|
2074 | self._checkFlightStatus.set_use_markup(True)
|
---|
2075 | self._checkFlightStatus.set_alignment(0.0, 0.5)
|
---|
2076 | alignment.add(self._checkFlightStatus)
|
---|
2077 | table.attach(alignment, 1, 4, row, row + 1)
|
---|
2078 |
|
---|
2079 | row += 1
|
---|
2080 |
|
---|
2081 | alignment = Gtk.Alignment(xalign=0.0, xscale=1.0)
|
---|
2082 |
|
---|
2083 | hbox = Gtk.HBox()
|
---|
2084 | hbox.set_homogeneous(False)
|
---|
2085 | hbox.set_spacing(0)
|
---|
2086 |
|
---|
2087 | aircraftTypesModel = Gtk.ListStore(str, int)
|
---|
2088 | for aircraftType in web.BookedFlight.checkFlightTypes:
|
---|
2089 | aircraftTypesModel.append([aircraftNames[aircraftType],
|
---|
2090 | aircraftType])
|
---|
2091 |
|
---|
2092 | aircraftTypeAlignment = Gtk.Alignment(xalign = 0.0, xscale = 1.0)
|
---|
2093 |
|
---|
2094 | self._aircraftType = Gtk.ComboBox(model = aircraftTypesModel)
|
---|
2095 | renderer = Gtk.CellRendererText()
|
---|
2096 | self._aircraftType.pack_start(renderer, True)
|
---|
2097 | self._aircraftType.add_attribute(renderer, "text", 0)
|
---|
2098 | self._aircraftType.set_tooltip_text(xstr("student_check_flight_type_tooltip"))
|
---|
2099 | self._aircraftType.set_active(0)
|
---|
2100 |
|
---|
2101 | aircraftTypeAlignment.add(self._aircraftType)
|
---|
2102 |
|
---|
2103 | hbox.pack_start(aircraftTypeAlignment, False, False, 0)
|
---|
2104 |
|
---|
2105 | buttonAlignment = Gtk.Alignment(xalign=0.0, xscale=1.0)
|
---|
2106 | button = self._checkFlightButton = Gtk.Button(xstr("student_check_flight"))
|
---|
2107 | button.set_use_underline(True)
|
---|
2108 | button.connect("clicked", self._checkFlightClicked)
|
---|
2109 | button.set_tooltip_text(xstr("student_check_flight_tooltip"))
|
---|
2110 |
|
---|
2111 | hbox.pack_start(button, True, True, 0)
|
---|
2112 |
|
---|
2113 | alignment.add(hbox)
|
---|
2114 | table.attach(alignment, 0, 4, row, row + 1,
|
---|
2115 | xoptions = Gtk.AttachOptions.FILL)
|
---|
2116 |
|
---|
2117 | @property
|
---|
2118 | def aircraftType(self):
|
---|
2119 | """Get the type of the aircraft used to perform the check flight."""
|
---|
2120 | index = self._aircraftType.get_active()
|
---|
2121 | return self._aircraftType.get_model()[index][1]
|
---|
2122 |
|
---|
2123 | def activate(self):
|
---|
2124 | """Activate the student page."""
|
---|
2125 | print("StudentPage.activate")
|
---|
2126 | self._getEntryExamStatusCancelled = False
|
---|
2127 |
|
---|
2128 | loginResult = self._wizard.loginResult
|
---|
2129 | self._entryExamLink = loginResult.entryExamLink
|
---|
2130 |
|
---|
2131 | self._updateEntryExamStatus(loginResult.entryExamPassed)
|
---|
2132 | self._getEntryExamStatus()
|
---|
2133 |
|
---|
2134 | # FIXME: call with real value
|
---|
2135 | self._updateCheckFlightStatus(self._wizard.loginResult.checkFlightStatus)
|
---|
2136 |
|
---|
2137 | def finalize(self):
|
---|
2138 | """Finalize the page."""
|
---|
2139 | print("StudentPage.finalize")
|
---|
2140 | self._getEntryExamStatusCancelled = True
|
---|
2141 |
|
---|
2142 | def _entryExamClicked(self, button):
|
---|
2143 | """Called when the entry exam button is clicked."""
|
---|
2144 | webbrowser.open(self._entryExamLink)
|
---|
2145 |
|
---|
2146 | def _getEntryExamStatus(self):
|
---|
2147 | """Initiate the query of the entry exam status after the interval."""
|
---|
2148 | if not self._getEntryExamStatusCancelled:
|
---|
2149 | GObject.timeout_add(StudentPage._entryExamStatusQueryInterval,
|
---|
2150 | lambda: self._wizard.gui.webHandler. \
|
---|
2151 | getEntryExamStatus(self._entryExamStatusCallback))
|
---|
2152 |
|
---|
2153 | def _entryExamStatusCallback(self, returned, result):
|
---|
2154 | """Called when the entry exam status is available."""
|
---|
2155 | GObject.idle_add(self._handleEntryExamStatus, returned, result)
|
---|
2156 |
|
---|
2157 | def _handleEntryExamStatus(self, returned, result):
|
---|
2158 | """Called when the entry exam status is availabe."""
|
---|
2159 | print("_handleEntryExamStatus", returned, result)
|
---|
2160 | if returned and not self._getEntryExamStatusCancelled:
|
---|
2161 | self._entryExamLink = result.entryExamLink
|
---|
2162 | self._updateEntryExamStatus(result.entryExamPassed)
|
---|
2163 | if result.madeFO:
|
---|
2164 | self._madeFO()
|
---|
2165 | else:
|
---|
2166 | self._getEntryExamStatus()
|
---|
2167 |
|
---|
2168 | def _updateEntryExamStatus(self, passed):
|
---|
2169 | """Update the entry exam status display and button."""
|
---|
2170 | self._entryExamStatus.set_text(xstr("student_entry_exam_passed")
|
---|
2171 | if passed else
|
---|
2172 | xstr("student_entry_exam_not_passed"))
|
---|
2173 | self._entryExamStatus.set_use_markup(True)
|
---|
2174 | self._entryExamButton.set_sensitive(not passed)
|
---|
2175 | self._wizard._loginResult.entryExamPassed = passed
|
---|
2176 |
|
---|
2177 | def _checkFlightClicked(self, button):
|
---|
2178 | """Called when the check flight button is clicked."""
|
---|
2179 | aircraftType = self.aircraftType
|
---|
2180 | self._wizard._bookedFlight = \
|
---|
2181 | web.BookedFlight.forCheckFlight(aircraftType)
|
---|
2182 | self._wizard.gui.enableFlightInfo(aircraftType)
|
---|
2183 | self._wizard.jumpPage("connect")
|
---|
2184 |
|
---|
2185 | def _updateCheckFlightStatus(self, passed):
|
---|
2186 | """Update the status of the check flight."""
|
---|
2187 | self._aircraftType.set_sensitive(not passed)
|
---|
2188 | self._checkFlightStatus.set_text(xstr("student_check_flight_passed")
|
---|
2189 | if passed else
|
---|
2190 | xstr("student_check_flight_not_passed"))
|
---|
2191 | self._checkFlightStatus.set_use_markup(True)
|
---|
2192 | self._checkFlightButton.set_sensitive(not passed)
|
---|
2193 |
|
---|
2194 | def _madeFO(self):
|
---|
2195 | """Handle the event when the pilot has become a first officer."""
|
---|
2196 | wizard = self._wizard
|
---|
2197 | loginResult = wizard.loginResult
|
---|
2198 | loginResult.rank = "FO"
|
---|
2199 |
|
---|
2200 | gui = wizard.gui
|
---|
2201 |
|
---|
2202 | dialog = Gtk.MessageDialog(parent = gui.mainWindow,
|
---|
2203 | type = Gtk.MessageType.INFO,
|
---|
2204 | message_format = xstr("student_fo"))
|
---|
2205 |
|
---|
2206 | dialog.add_button(xstr("button_ok"), Gtk.ResponseType.OK)
|
---|
2207 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
2208 | secondary = xstr("student_fo_secondary")
|
---|
2209 | dialog.format_secondary_markup(secondary)
|
---|
2210 | dialog.run()
|
---|
2211 | dialog.hide()
|
---|
2212 |
|
---|
2213 | gui.reset()
|
---|
2214 |
|
---|
2215 | #-----------------------------------------------------------------------------
|
---|
2216 |
|
---|
2217 | class ConnectPage(Page):
|
---|
2218 | """Page which displays the departure airport and gate (if at LHBP)."""
|
---|
2219 | def __init__(self, wizard):
|
---|
2220 | """Construct the connect page."""
|
---|
2221 | help = "Load the aircraft below into the simulator and park it\n" \
|
---|
2222 | "at the given airport, at the gate below, if present.\n\n" \
|
---|
2223 | "Then press the Connect button to connect to the simulator."
|
---|
2224 | completedHelp = "The basic data of your flight can be read below."
|
---|
2225 | super(ConnectPage, self).__init__(wizard, "connect",
|
---|
2226 | xstr("connect_title"),
|
---|
2227 | xstr("connect_help"),
|
---|
2228 | completedHelp = xstr("connect_chelp"))
|
---|
2229 |
|
---|
2230 | self._selectSimulator = os.name=="nt" or "FORCE_SELECT_SIM" in os.environ
|
---|
2231 |
|
---|
2232 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
2233 | xscale = 0.0, yscale = 0.0)
|
---|
2234 |
|
---|
2235 | table = Gtk.Table(7 if self._selectSimulator else 5, 2)
|
---|
2236 | table.set_row_spacings(4)
|
---|
2237 | table.set_col_spacings(16)
|
---|
2238 | table.set_homogeneous(True)
|
---|
2239 | alignment.add(table)
|
---|
2240 | self.setMainWidget(alignment)
|
---|
2241 |
|
---|
2242 | labelAlignment = Gtk.Alignment(xalign=1.0, xscale=0.0)
|
---|
2243 | label = Gtk.Label(xstr("connect_flightno"))
|
---|
2244 | labelAlignment.add(label)
|
---|
2245 | table.attach(labelAlignment, 0, 1, 0, 1)
|
---|
2246 |
|
---|
2247 | labelAlignment = Gtk.Alignment(xalign=0.0, xscale=0.0)
|
---|
2248 | self._flightNumber = Gtk.Label()
|
---|
2249 | self._flightNumber.set_width_chars(9)
|
---|
2250 | self._flightNumber.set_alignment(0.0, 0.5)
|
---|
2251 | labelAlignment.add(self._flightNumber)
|
---|
2252 | table.attach(labelAlignment, 1, 2, 0, 1)
|
---|
2253 |
|
---|
2254 | labelAlignment = Gtk.Alignment(xalign=1.0, xscale=0.0)
|
---|
2255 | label = Gtk.Label(xstr("connect_acft"))
|
---|
2256 | labelAlignment.add(label)
|
---|
2257 | table.attach(labelAlignment, 0, 1, 1, 2)
|
---|
2258 |
|
---|
2259 | labelAlignment = Gtk.Alignment(xalign=0.0, xscale=0.0)
|
---|
2260 | self._aircraft = Gtk.Label()
|
---|
2261 | self._aircraft.set_width_chars(25)
|
---|
2262 | self._aircraft.set_alignment(0.0, 0.5)
|
---|
2263 | labelAlignment.add(self._aircraft)
|
---|
2264 | table.attach(labelAlignment, 1, 2, 1, 2)
|
---|
2265 |
|
---|
2266 | labelAlignment = Gtk.Alignment(xalign=1.0, xscale=0.0)
|
---|
2267 | label = Gtk.Label(xstr("connect_tailno"))
|
---|
2268 | labelAlignment.add(label)
|
---|
2269 | table.attach(labelAlignment, 0, 1, 2, 3)
|
---|
2270 |
|
---|
2271 | labelAlignment = Gtk.Alignment(xalign=0.0, xscale=0.0)
|
---|
2272 | self._tailNumber = Gtk.Label()
|
---|
2273 | self._tailNumber.set_width_chars(10)
|
---|
2274 | self._tailNumber.set_alignment(0.0, 0.5)
|
---|
2275 | labelAlignment.add(self._tailNumber)
|
---|
2276 | table.attach(labelAlignment, 1, 2, 2, 3)
|
---|
2277 |
|
---|
2278 | labelAlignment = Gtk.Alignment(xalign=1.0, xscale=0.0)
|
---|
2279 | label = Gtk.Label(xstr("connect_airport"))
|
---|
2280 | labelAlignment.add(label)
|
---|
2281 | table.attach(labelAlignment, 0, 1, 3, 4)
|
---|
2282 |
|
---|
2283 | labelAlignment = Gtk.Alignment(xalign=0.0, xscale=0.0)
|
---|
2284 | self._departureICAO = Gtk.Label()
|
---|
2285 | self._departureICAO.set_width_chars(6)
|
---|
2286 | self._departureICAO.set_alignment(0.0, 0.5)
|
---|
2287 | labelAlignment.add(self._departureICAO)
|
---|
2288 | table.attach(labelAlignment, 1, 2, 3, 4)
|
---|
2289 |
|
---|
2290 | labelAlignment = Gtk.Alignment(xalign=1.0, xscale=0.0)
|
---|
2291 | label = Gtk.Label(xstr("connect_gate"))
|
---|
2292 | labelAlignment.add(label)
|
---|
2293 | table.attach(labelAlignment, 0, 1, 4, 5)
|
---|
2294 |
|
---|
2295 | labelAlignment = Gtk.Alignment(xalign=0.0, xscale=0.0)
|
---|
2296 | self._departureGate = Gtk.Label()
|
---|
2297 | self._departureGate.set_width_chars(5)
|
---|
2298 | self._departureGate.set_alignment(0.0, 0.5)
|
---|
2299 | labelAlignment.add(self._departureGate)
|
---|
2300 | table.attach(labelAlignment, 1, 2, 4, 5)
|
---|
2301 |
|
---|
2302 | if self._selectSimulator:
|
---|
2303 | labelAlignment = Gtk.Alignment(xalign=1.0, xscale=0.0, yalign=0.5)
|
---|
2304 | label = Gtk.Label(xstr("connect_sim"))
|
---|
2305 | labelAlignment.add(label)
|
---|
2306 | table.attach(labelAlignment, 0, 1, 5, 7)
|
---|
2307 |
|
---|
2308 | selectAlignment = Gtk.Alignment(xalign=0.0, xscale=0.0, yalign=0.5)
|
---|
2309 |
|
---|
2310 | selectBox = Gtk.HBox()
|
---|
2311 | self._selectMSFS = \
|
---|
2312 | Gtk.RadioButton.new_with_mnemonic_from_widget(None,
|
---|
2313 | xstr("connect_sim_msfs"))
|
---|
2314 |
|
---|
2315 | selectBox.pack_start(self._selectMSFS, False, False, 0);
|
---|
2316 |
|
---|
2317 | self._selectXPlane = \
|
---|
2318 | Gtk.RadioButton.new_with_mnemonic_from_widget(self._selectMSFS,
|
---|
2319 | xstr("connect_sim_xplane"))
|
---|
2320 |
|
---|
2321 | selectBox.pack_start(self._selectXPlane, False, False, 8);
|
---|
2322 |
|
---|
2323 | selectAlignment.add(selectBox)
|
---|
2324 | table.attach(selectAlignment, 1, 2, 5, 7)
|
---|
2325 |
|
---|
2326 |
|
---|
2327 | self.addCancelFlightButton()
|
---|
2328 |
|
---|
2329 | self._previousButton = \
|
---|
2330 | self.addPreviousButton(clicked = self._backClicked)
|
---|
2331 |
|
---|
2332 | self._button = self.addButton(xstr("button_connect"), default = True,
|
---|
2333 | tooltip = xstr("button_connect_tooltip"))
|
---|
2334 | self._clickedID = self._button.connect("clicked", self._connectClicked)
|
---|
2335 |
|
---|
2336 | def activate(self):
|
---|
2337 | """Setup the departure information."""
|
---|
2338 | self._button.set_label(xstr("button_connect"))
|
---|
2339 | self._button.set_use_underline(True)
|
---|
2340 | self._button.set_tooltip_text(xstr("button_connect_tooltip"))
|
---|
2341 | self._button.disconnect(self._clickedID)
|
---|
2342 | self._clickedID = self._button.connect("clicked", self._connectClicked)
|
---|
2343 |
|
---|
2344 | bookedFlight = self._wizard._bookedFlight
|
---|
2345 |
|
---|
2346 | self._flightNumber.set_markup("<b>" + bookedFlight.callsign + "</b>")
|
---|
2347 |
|
---|
2348 | aircraftType = aircraftNames[bookedFlight.aircraftType]
|
---|
2349 | self._aircraft.set_markup("<b>" + aircraftType + "</b>")
|
---|
2350 |
|
---|
2351 | self._tailNumber.set_markup("<b>" + bookedFlight.tailNumber + "</b>")
|
---|
2352 |
|
---|
2353 | icao = bookedFlight.departureICAO
|
---|
2354 | self._departureICAO.set_markup("<b>" + icao + "</b>")
|
---|
2355 | gate = self._wizard._departureGate
|
---|
2356 | if gate!="-":
|
---|
2357 | gate = "<b>" + gate + "</b>"
|
---|
2358 | self._departureGate.set_markup(gate)
|
---|
2359 |
|
---|
2360 | if self._selectSimulator:
|
---|
2361 | config = self._wizard.gui.config
|
---|
2362 | self._selectMSFS.set_active(config.defaultMSFS)
|
---|
2363 | self._selectXPlane.set_active(not config.defaultMSFS)
|
---|
2364 |
|
---|
2365 | self._previousButton.set_sensitive(not self._wizard.entranceExam)
|
---|
2366 |
|
---|
2367 | def finalize(self):
|
---|
2368 | """Finalize the page."""
|
---|
2369 | self._button.set_label(xstr("button_next"))
|
---|
2370 | self._button.set_use_underline(True)
|
---|
2371 | self._button.set_tooltip_text(xstr("button_next_tooltip"))
|
---|
2372 | self._button.disconnect(self._clickedID)
|
---|
2373 | self._clickedID = self._button.connect("clicked", self._forwardClicked)
|
---|
2374 |
|
---|
2375 | def _backClicked(self, button):
|
---|
2376 | """Called when the Back button is pressed."""
|
---|
2377 | self.goBack()
|
---|
2378 |
|
---|
2379 | def _connectClicked(self, button):
|
---|
2380 | """Called when the Connect button is pressed."""
|
---|
2381 | if self._selectSimulator:
|
---|
2382 | simulatorType = const.SIM_MSFS9 if self._selectMSFS.get_active() \
|
---|
2383 | else const.SIM_XPLANE10
|
---|
2384 | else:
|
---|
2385 | simulatorType = const.SIM_MSFS9 if os.name=="nt" \
|
---|
2386 | else const.SIM_XPLANE10
|
---|
2387 |
|
---|
2388 | config = self._wizard.gui.config
|
---|
2389 | config.defaultMSFS = simulatorType == const.SIM_MSFS9
|
---|
2390 | config.save()
|
---|
2391 |
|
---|
2392 | self._wizard._connectSimulator(simulatorType)
|
---|
2393 |
|
---|
2394 | def _forwardClicked(self, button):
|
---|
2395 | """Called when the Forward button is pressed."""
|
---|
2396 | self._wizard.nextPage()
|
---|
2397 |
|
---|
2398 | #-----------------------------------------------------------------------------
|
---|
2399 |
|
---|
2400 | class PayloadPage(Page):
|
---|
2401 | """Page to allow setting up the payload."""
|
---|
2402 | def __init__(self, wizard):
|
---|
2403 | """Construct the page."""
|
---|
2404 | super(PayloadPage, self).__init__(wizard, "payload",
|
---|
2405 | xstr("payload_title"),
|
---|
2406 | xstr("payload_help") + "\n\n \n \n",
|
---|
2407 | completedHelp = xstr("payload_chelp"))
|
---|
2408 |
|
---|
2409 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
2410 | xscale = 0.0, yscale = 0.0)
|
---|
2411 |
|
---|
2412 | table = Gtk.Table(7, 3)
|
---|
2413 | table.set_row_spacings(4)
|
---|
2414 | table.set_col_spacings(16)
|
---|
2415 | table.set_homogeneous(False)
|
---|
2416 | alignment.add(table)
|
---|
2417 | self.setMainWidget(alignment)
|
---|
2418 |
|
---|
2419 | self._crewLabel = label = Gtk.Label(xstr("payload_crew"))
|
---|
2420 | label.set_use_underline(True)
|
---|
2421 | label.set_alignment(0.0, 0.5)
|
---|
2422 | table.attach(label, 0, 1, 0, 1)
|
---|
2423 |
|
---|
2424 | self._numCockpitCrew = Gtk.Label()
|
---|
2425 |
|
---|
2426 | self._numCabinCrew = IntegerEntry(defaultValue = 0)
|
---|
2427 | self._numCabinCrew.set_width_chars(6)
|
---|
2428 | self._numCabinCrew.connect("integer-changed", self._weightChanged)
|
---|
2429 | self._numCabinCrew.set_tooltip_text(xstr("payload_crew_tooltip"))
|
---|
2430 |
|
---|
2431 | crewBox = Gtk.HBox()
|
---|
2432 | crewBox.pack_start(self._numCockpitCrew, False, False, 0)
|
---|
2433 | crewBox.pack_start(Gtk.Label("+"), False, False, 4)
|
---|
2434 | crewBox.pack_start(self._numCabinCrew, False, False, 0)
|
---|
2435 | crewBox.set_halign(Gtk.Align.END)
|
---|
2436 |
|
---|
2437 | table.attach(crewBox, 1, 2, 0, 1)
|
---|
2438 | label.set_mnemonic_widget(self._numCabinCrew)
|
---|
2439 |
|
---|
2440 | label = Gtk.Label(xstr("payload_crew_info"))
|
---|
2441 | label.set_halign(Gtk.Align.START)
|
---|
2442 | table.attach(label, 2, 3, 0, 1)
|
---|
2443 |
|
---|
2444 | self._paxLabel = label = Gtk.Label(xstr("payload_pax"))
|
---|
2445 | label.set_use_underline(True)
|
---|
2446 | label.set_alignment(0.0, 0.5)
|
---|
2447 | table.attach(label, 0, 1, 1, 2)
|
---|
2448 |
|
---|
2449 | self._numPassengers = IntegerEntry(defaultValue = 0)
|
---|
2450 | self._numPassengers.set_width_chars(6)
|
---|
2451 | self._numPassengers.connect("integer-changed", self._weightChanged)
|
---|
2452 | self._numPassengers.set_tooltip_text(xstr("payload_pax_tooltip"))
|
---|
2453 |
|
---|
2454 | self._numChildren = IntegerEntry(defaultValue = 0)
|
---|
2455 | self._numChildren.set_width_chars(6)
|
---|
2456 | self._numChildren.connect("integer-changed", self._weightChanged)
|
---|
2457 | self._numChildren.set_tooltip_text(xstr("payload_pax_children_tooltip"))
|
---|
2458 |
|
---|
2459 | self._numInfants = IntegerEntry(defaultValue = 0)
|
---|
2460 | self._numInfants.set_width_chars(6)
|
---|
2461 | self._numInfants.connect("integer-changed", self._weightChanged)
|
---|
2462 | self._numInfants.set_tooltip_text(xstr("payload_pax_infants_tooltip"))
|
---|
2463 |
|
---|
2464 | paxBox = Gtk.HBox()
|
---|
2465 | paxBox.pack_start(self._numPassengers, False, False, 0)
|
---|
2466 | paxBox.pack_start(Gtk.Label("+"), False, False, 4)
|
---|
2467 | paxBox.pack_start(self._numChildren, False, False, 0)
|
---|
2468 | paxBox.pack_start(Gtk.Label("+"), False, False, 4)
|
---|
2469 | paxBox.pack_start(self._numInfants, False, False, 0)
|
---|
2470 |
|
---|
2471 | table.attach(paxBox, 1, 2, 1, 2)
|
---|
2472 | label.set_mnemonic_widget(self._numPassengers)
|
---|
2473 |
|
---|
2474 | label = Gtk.Label(xstr("payload_pax_info"))
|
---|
2475 | label.set_halign(Gtk.Align.START)
|
---|
2476 | table.attach(label, 2, 3, 1, 2)
|
---|
2477 |
|
---|
2478 | label = Gtk.Label(xstr("payload_bag"))
|
---|
2479 | label.set_use_underline(True)
|
---|
2480 | label.set_alignment(0.0, 0.5)
|
---|
2481 | table.attach(label, 0, 1, 2, 3)
|
---|
2482 |
|
---|
2483 | self._bagWeight = IntegerEntry(defaultValue = 0)
|
---|
2484 | self._bagWeight.set_width_chars(6)
|
---|
2485 | self._bagWeight.connect("integer-changed", self._weightChanged)
|
---|
2486 | self._bagWeight.set_tooltip_text(xstr("payload_bag_tooltip"))
|
---|
2487 | self._bagWeight.set_hexpand(False)
|
---|
2488 | self._bagWeight.set_halign(Gtk.Align.END)
|
---|
2489 | table.attach(self._bagWeight, 1, 2, 2, 3)
|
---|
2490 | label.set_mnemonic_widget(self._bagWeight)
|
---|
2491 |
|
---|
2492 | label = Gtk.Label("kg")
|
---|
2493 | label.set_halign(Gtk.Align.START)
|
---|
2494 | table.attach(label, 2, 3, 2, 3)
|
---|
2495 |
|
---|
2496 | label = Gtk.Label(xstr("payload_cargo"))
|
---|
2497 | label.set_use_underline(True)
|
---|
2498 | label.set_alignment(0.0, 0.5)
|
---|
2499 | table.attach(label, 0, 1, 3, 4)
|
---|
2500 |
|
---|
2501 | self._cargoWeight = IntegerEntry(defaultValue = 0)
|
---|
2502 | self._cargoWeight.set_width_chars(6)
|
---|
2503 | self._cargoWeight.connect("integer-changed", self._weightChanged)
|
---|
2504 | self._cargoWeight.set_tooltip_text(xstr("payload_cargo_tooltip"))
|
---|
2505 | self._cargoWeight.set_hexpand(False)
|
---|
2506 | self._cargoWeight.set_halign(Gtk.Align.END)
|
---|
2507 | table.attach(self._cargoWeight, 1, 2, 3, 4)
|
---|
2508 | label.set_mnemonic_widget(self._cargoWeight)
|
---|
2509 |
|
---|
2510 | label = Gtk.Label("kg")
|
---|
2511 | label.set_halign(Gtk.Align.START)
|
---|
2512 | table.attach(label, 2, 3, 3, 4)
|
---|
2513 |
|
---|
2514 | label = Gtk.Label(xstr("payload_mail"))
|
---|
2515 | label.set_use_underline(True)
|
---|
2516 | label.set_alignment(0.0, 0.5)
|
---|
2517 | table.attach(label, 0, 1, 4, 5)
|
---|
2518 |
|
---|
2519 | self._mailWeight = IntegerEntry(defaultValue = 0)
|
---|
2520 | self._mailWeight.set_width_chars(6)
|
---|
2521 | self._mailWeight.connect("integer-changed", self._weightChanged)
|
---|
2522 | self._mailWeight.set_tooltip_text(xstr("payload_mail_tooltip"))
|
---|
2523 | self._mailWeight.set_hexpand(False)
|
---|
2524 | self._mailWeight.set_halign(Gtk.Align.END)
|
---|
2525 | table.attach(self._mailWeight, 1, 2, 4, 5)
|
---|
2526 | label.set_mnemonic_widget(self._mailWeight)
|
---|
2527 |
|
---|
2528 | label = Gtk.Label("kg")
|
---|
2529 | label.set_halign(Gtk.Align.START)
|
---|
2530 | table.attach(label, 2, 3, 4, 5)
|
---|
2531 |
|
---|
2532 | label = Gtk.Label("<b>" + xstr("payload_zfw") + "</b>")
|
---|
2533 | label.set_alignment(0.0, 0.5)
|
---|
2534 | label.set_use_markup(True)
|
---|
2535 | table.attach(label, 0, 1, 5, 6)
|
---|
2536 |
|
---|
2537 | self._calculatedZFW = Gtk.Label()
|
---|
2538 | self._calculatedZFW.set_width_chars(6)
|
---|
2539 | self._calculatedZFW.set_alignment(1.0, 0.5)
|
---|
2540 | table.attach(self._calculatedZFW, 1, 2, 5, 6)
|
---|
2541 |
|
---|
2542 | label = Gtk.Label("kg")
|
---|
2543 | label.set_halign(Gtk.Align.START)
|
---|
2544 | table.attach(label, 2, 3, 5, 6)
|
---|
2545 |
|
---|
2546 | self._zfwButton = Gtk.Button(xstr("payload_fszfw"))
|
---|
2547 | self._zfwButton.set_use_underline(True)
|
---|
2548 | self._zfwButton.connect("clicked", self._zfwRequested)
|
---|
2549 | self._zfwButton.set_tooltip_text(xstr("payload_fszfw_tooltip"))
|
---|
2550 | table.attach(self._zfwButton, 0, 1, 6, 7)
|
---|
2551 |
|
---|
2552 | self._simulatorZFW = Gtk.Label("-")
|
---|
2553 | self._simulatorZFW.set_width_chars(6)
|
---|
2554 | self._simulatorZFW.set_alignment(1.0, 0.5)
|
---|
2555 | table.attach(self._simulatorZFW, 1, 2, 6, 7)
|
---|
2556 | self._simulatorZFWValue = None
|
---|
2557 |
|
---|
2558 | label = Gtk.Label("kg")
|
---|
2559 | label.set_halign(Gtk.Align.START)
|
---|
2560 | table.attach(label, 2, 3, 6, 7)
|
---|
2561 |
|
---|
2562 | self.addCancelFlightButton()
|
---|
2563 | self._backButton = self.addPreviousButton(clicked = self._backClicked)
|
---|
2564 | self._button = self.addNextButton(clicked = self._forwardClicked)
|
---|
2565 |
|
---|
2566 | @property
|
---|
2567 | def numCockpitCrew(self):
|
---|
2568 | """The number of the cockpit crew members on the flight."""
|
---|
2569 | return self._wizard._bookedFlight.numCockpitCrew
|
---|
2570 |
|
---|
2571 | @property
|
---|
2572 | def numCabinCrew(self):
|
---|
2573 | """The number of the cabin members on the flight."""
|
---|
2574 | return self._numCabinCrew.get_int()
|
---|
2575 |
|
---|
2576 | @property
|
---|
2577 | def numPassengers(self):
|
---|
2578 | """The number of the adult passengers on the flight."""
|
---|
2579 | return self._numPassengers.get_int()
|
---|
2580 |
|
---|
2581 | @property
|
---|
2582 | def numChildren(self):
|
---|
2583 | """The number of the child passengers on the flight."""
|
---|
2584 | return self._numChildren.get_int()
|
---|
2585 |
|
---|
2586 | @property
|
---|
2587 | def numInfants(self):
|
---|
2588 | """The number of the infant passengers on the flight."""
|
---|
2589 | return self._numInfants.get_int()
|
---|
2590 |
|
---|
2591 | @property
|
---|
2592 | def bagWeight(self):
|
---|
2593 | """Get the bag weight entered."""
|
---|
2594 | return self._bagWeight.get_int()
|
---|
2595 |
|
---|
2596 | @property
|
---|
2597 | def cargoWeight(self):
|
---|
2598 | """Get the cargo weight entered."""
|
---|
2599 | return self._cargoWeight.get_int()
|
---|
2600 |
|
---|
2601 | @property
|
---|
2602 | def mailWeight(self):
|
---|
2603 | """Get the bag weight entered."""
|
---|
2604 | return self._mailWeight.get_int()
|
---|
2605 |
|
---|
2606 | def activate(self):
|
---|
2607 | """Setup the information."""
|
---|
2608 | bookedFlight = self._wizard._bookedFlight
|
---|
2609 |
|
---|
2610 | self._numCockpitCrew.set_markup("<b>" +
|
---|
2611 | str(bookedFlight.numCockpitCrew) +
|
---|
2612 | "</b>")
|
---|
2613 | self._numCabinCrew.set_int(bookedFlight.numCabinCrew)
|
---|
2614 | self._numCabinCrew.set_sensitive(True)
|
---|
2615 |
|
---|
2616 |
|
---|
2617 | self._numPassengers.set_int(bookedFlight.numPassengers)
|
---|
2618 | self._numPassengers.set_sensitive(True)
|
---|
2619 |
|
---|
2620 | self._numChildren.set_int(bookedFlight.numChildren)
|
---|
2621 | self._numChildren.set_sensitive(True)
|
---|
2622 |
|
---|
2623 | self._numInfants.set_int(bookedFlight.numInfants)
|
---|
2624 | self._numInfants.set_sensitive(True)
|
---|
2625 |
|
---|
2626 | self._bagWeight.set_int(bookedFlight.bagWeight)
|
---|
2627 | self._bagWeight.set_sensitive(True)
|
---|
2628 |
|
---|
2629 | if bookedFlight.flightType==const.FLIGHTTYPE_CHARTER:
|
---|
2630 | self._cargoWeight.set_int(0)
|
---|
2631 | self._cargoWeight.set_sensitive(False)
|
---|
2632 | self._mailWeight.set_int(0)
|
---|
2633 | self._mailWeight.set_sensitive(False)
|
---|
2634 | else:
|
---|
2635 | self._cargoWeight.set_int(bookedFlight.cargoWeight)
|
---|
2636 | self._cargoWeight.set_sensitive(True)
|
---|
2637 | self._mailWeight.set_int(bookedFlight.mailWeight)
|
---|
2638 | self._mailWeight.set_sensitive(True)
|
---|
2639 |
|
---|
2640 | self._simulatorZFW.set_text("-")
|
---|
2641 | self._simulatorZFWValue = None
|
---|
2642 | self._zfwButton.set_sensitive(True)
|
---|
2643 | self._updateCalculatedZFW()
|
---|
2644 |
|
---|
2645 | def finalize(self):
|
---|
2646 | """Finalize the payload page."""
|
---|
2647 | self._numCabinCrew.set_sensitive(False)
|
---|
2648 | self._numPassengers.set_sensitive(False)
|
---|
2649 | self._numChildren.set_sensitive(False)
|
---|
2650 | self._numInfants.set_sensitive(False)
|
---|
2651 | self._bagWeight.set_sensitive(False)
|
---|
2652 | self._cargoWeight.set_sensitive(False)
|
---|
2653 | self._mailWeight.set_sensitive(False)
|
---|
2654 | self._wizard.gui.initializeWeightHelp()
|
---|
2655 |
|
---|
2656 | def calculateZFW(self):
|
---|
2657 | """Calculate the ZFW value."""
|
---|
2658 | bookedFlight = self._wizard._bookedFlight
|
---|
2659 |
|
---|
2660 | zfw = bookedFlight.dow
|
---|
2661 | zfw += (self._numCabinCrew.get_int() - bookedFlight.dowNumCabinCrew) * \
|
---|
2662 | const.WEIGHT_CABIN_CREW
|
---|
2663 | zfw += self._numPassengers.get_int() * \
|
---|
2664 | (const.WEIGHT_PASSENGER_CHARTER
|
---|
2665 | if bookedFlight.flightType==const.FLIGHTTYPE_CHARTER
|
---|
2666 | else const.WEIGHT_PASSENGER)
|
---|
2667 | zfw += self._numChildren.get_int() * const.WEIGHT_CHILD
|
---|
2668 | zfw += self._numInfants.get_int() * const.WEIGHT_INFANT
|
---|
2669 | zfw += self._bagWeight.get_int()
|
---|
2670 | zfw += self._cargoWeight.get_int()
|
---|
2671 | zfw += self._mailWeight.get_int()
|
---|
2672 | return zfw
|
---|
2673 |
|
---|
2674 | def _updateCalculatedZFW(self):
|
---|
2675 | """Update the calculated ZFW"""
|
---|
2676 | zfw = self.calculateZFW()
|
---|
2677 |
|
---|
2678 | markupBegin = "<b>"
|
---|
2679 | markupEnd = "</b>"
|
---|
2680 | if self._simulatorZFWValue is not None and \
|
---|
2681 | PayloadChecker.isZFWFaulty(self._simulatorZFWValue, zfw):
|
---|
2682 | markupBegin += '<span foreground="red">'
|
---|
2683 | markupEnd = "</span>" + markupEnd
|
---|
2684 | self._calculatedZFW.set_markup(markupBegin + str(zfw) + markupEnd)
|
---|
2685 |
|
---|
2686 | def _weightChanged(self, entry, weight):
|
---|
2687 | """Called when one of the weight values or humanm counts has
|
---|
2688 | changed."""
|
---|
2689 | bookedFlight = self._wizard._bookedFlight
|
---|
2690 | numPassengers = \
|
---|
2691 | self._numPassengers.get_int() + \
|
---|
2692 | self._numChildren.get_int() + \
|
---|
2693 | self._numInfants.get_int()
|
---|
2694 | minCabinCrew = 0 if numPassengers==0 else \
|
---|
2695 | (bookedFlight.maxPassengers // 50) + 1
|
---|
2696 |
|
---|
2697 | extraHelp = []
|
---|
2698 | enoughCrew = self._numCabinCrew.get_int() >= minCabinCrew
|
---|
2699 | if enoughCrew:
|
---|
2700 | self._crewLabel.set_text(xstr("payload_crew"))
|
---|
2701 | self.setHelp(xstr("payload_help"))
|
---|
2702 | else:
|
---|
2703 | self._crewLabel.set_markup("<b><span foreground=\"red\">" +
|
---|
2704 | xstr("payload_crew") +
|
---|
2705 | "</span></b>")
|
---|
2706 | extraHelp.append(xstr("payload_help_few_crew") % (minCabinCrew,))
|
---|
2707 | self._crewLabel.set_use_underline(True)
|
---|
2708 |
|
---|
2709 | tooManyPassengers = numPassengers>bookedFlight.maxPassengers
|
---|
2710 | if tooManyPassengers:
|
---|
2711 | self._paxLabel.set_markup("<b><span foreground=\"red\">" +
|
---|
2712 | xstr("payload_pax") +
|
---|
2713 | "</span></b>")
|
---|
2714 | extraHelp.append(xstr("payload_help_many_pax") % (bookedFlight.maxPassengers,))
|
---|
2715 | else:
|
---|
2716 | self._paxLabel.set_text(xstr("payload_pax"))
|
---|
2717 | self._paxLabel.set_use_underline(True)
|
---|
2718 |
|
---|
2719 | hlp = xstr("payload_help") + "\n\n"
|
---|
2720 | for eh in extraHelp:
|
---|
2721 | hlp += "<b><span foreground=\"red\">" + eh + "</span></b>\n"
|
---|
2722 | hlp += " \n" * (2-len(extraHelp))
|
---|
2723 | self.setHelp(hlp)
|
---|
2724 |
|
---|
2725 | self._button.set_sensitive(enoughCrew and not tooManyPassengers)
|
---|
2726 |
|
---|
2727 |
|
---|
2728 | self._updateCalculatedZFW()
|
---|
2729 |
|
---|
2730 | def _zfwRequested(self, button):
|
---|
2731 | """Called when the ZFW is requested from the simulator."""
|
---|
2732 | self._zfwButton.set_sensitive(False)
|
---|
2733 | self._backButton.set_sensitive(False)
|
---|
2734 | self._button.set_sensitive(False)
|
---|
2735 | gui = self._wizard.gui
|
---|
2736 | gui.beginBusy(xstr("payload_zfw_busy"))
|
---|
2737 | gui.simulator.requestZFW(self._handleZFW)
|
---|
2738 |
|
---|
2739 | def _handleZFW(self, zfw):
|
---|
2740 | """Called when the ZFW value is retrieved."""
|
---|
2741 | GObject.idle_add(self._processZFW, zfw)
|
---|
2742 |
|
---|
2743 | def _processZFW(self, zfw):
|
---|
2744 | """Process the given ZFW value received from the simulator."""
|
---|
2745 | self._wizard.gui.endBusy()
|
---|
2746 | self._zfwButton.set_sensitive(True)
|
---|
2747 | self._backButton.set_sensitive(True)
|
---|
2748 | self._button.set_sensitive(True)
|
---|
2749 | self._simulatorZFWValue = zfw
|
---|
2750 | self._simulatorZFW.set_text("%.0f" % (zfw,))
|
---|
2751 | self._updateCalculatedZFW()
|
---|
2752 |
|
---|
2753 | def _forwardClicked(self, button):
|
---|
2754 | """Called when the forward button is clicked."""
|
---|
2755 | self._wizard.nextPage()
|
---|
2756 |
|
---|
2757 | def _backClicked(self, button):
|
---|
2758 | """Called when the Back button is pressed."""
|
---|
2759 | self.goBack()
|
---|
2760 |
|
---|
2761 | #-----------------------------------------------------------------------------
|
---|
2762 |
|
---|
2763 | class TimePage(Page):
|
---|
2764 | """Page displaying the departure and arrival times and allows querying the
|
---|
2765 | current time from the flight simulator."""
|
---|
2766 | def __init__(self, wizard):
|
---|
2767 | super(TimePage, self).__init__(wizard, "time",
|
---|
2768 | xstr("time_title"),
|
---|
2769 | xstr("time_help"),
|
---|
2770 | completedHelp = xstr("time_chelp"))
|
---|
2771 |
|
---|
2772 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
2773 | xscale = 0.0, yscale = 0.0)
|
---|
2774 |
|
---|
2775 | table = Gtk.Table(3, 2)
|
---|
2776 | table.set_row_spacings(4)
|
---|
2777 | table.set_col_spacings(16)
|
---|
2778 | table.set_homogeneous(False)
|
---|
2779 | alignment.add(table)
|
---|
2780 | self.setMainWidget(alignment)
|
---|
2781 |
|
---|
2782 | label = Gtk.Label(xstr("time_departure"))
|
---|
2783 | label.set_alignment(0.0, 0.5)
|
---|
2784 | table.attach(label, 0, 1, 0, 1)
|
---|
2785 |
|
---|
2786 | self._departure = Gtk.Label()
|
---|
2787 | self._departure.set_alignment(0.0, 0.5)
|
---|
2788 | table.attach(self._departure, 1, 2, 0, 1)
|
---|
2789 |
|
---|
2790 | label = Gtk.Label(xstr("time_arrival"))
|
---|
2791 | label.set_alignment(0.0, 0.5)
|
---|
2792 | table.attach(label, 0, 1, 1, 2)
|
---|
2793 |
|
---|
2794 | self._arrival = Gtk.Label()
|
---|
2795 | self._arrival.set_alignment(0.0, 0.5)
|
---|
2796 | table.attach(self._arrival, 1, 2, 1, 2)
|
---|
2797 |
|
---|
2798 | self._timeButton = Gtk.Button(xstr("time_fs"))
|
---|
2799 | self._timeButton.set_use_underline(True)
|
---|
2800 | self._timeButton.set_tooltip_text(xstr("time_fs_tooltip"))
|
---|
2801 | self._timeButton.connect("clicked", self._timeRequested)
|
---|
2802 | table.attach(self._timeButton, 0, 1, 2, 3)
|
---|
2803 |
|
---|
2804 | self._simulatorTime = Gtk.Label("-")
|
---|
2805 | self._simulatorTime.set_alignment(0.0, 0.5)
|
---|
2806 | table.attach(self._simulatorTime, 1, 2, 2, 3)
|
---|
2807 |
|
---|
2808 | self.addCancelFlightButton()
|
---|
2809 |
|
---|
2810 | self._backButton = self.addPreviousButton(clicked = self._backClicked)
|
---|
2811 | self._button = self.addNextButton(clicked = self._forwardClicked)
|
---|
2812 |
|
---|
2813 | def activate(self):
|
---|
2814 | """Activate the page."""
|
---|
2815 | self._timeButton.set_sensitive(True)
|
---|
2816 | bookedFlight = self._wizard._bookedFlight
|
---|
2817 | self._departure.set_text(str(bookedFlight.departureTime.time()))
|
---|
2818 | self._arrival.set_text(str(bookedFlight.arrivalTime.time()))
|
---|
2819 | self._simulatorTime.set_text("-")
|
---|
2820 |
|
---|
2821 | def _timeRequested(self, button):
|
---|
2822 | """Request the time from the simulator."""
|
---|
2823 | self._timeButton.set_sensitive(False)
|
---|
2824 | self._backButton.set_sensitive(False)
|
---|
2825 | self._button.set_sensitive(False)
|
---|
2826 | self._wizard.gui.beginBusy(xstr("time_busy"))
|
---|
2827 | self._wizard.gui.simulator.requestTime(self._handleTime)
|
---|
2828 |
|
---|
2829 | def _handleTime(self, timestamp):
|
---|
2830 | """Handle the result of a time retrieval."""
|
---|
2831 | GObject.idle_add(self._processTime, timestamp)
|
---|
2832 |
|
---|
2833 | def _processTime(self, timestamp):
|
---|
2834 | """Process the given time."""
|
---|
2835 | self._wizard.gui.endBusy()
|
---|
2836 | self._timeButton.set_sensitive(True)
|
---|
2837 | self._backButton.set_sensitive(True)
|
---|
2838 | self._button.set_sensitive(True)
|
---|
2839 | tm = time.gmtime(timestamp)
|
---|
2840 | t = datetime.time(tm.tm_hour, tm.tm_min, tm.tm_sec)
|
---|
2841 | self._simulatorTime.set_text(str(t))
|
---|
2842 |
|
---|
2843 | ts = tm.tm_hour * 3600 + tm.tm_min * 60 + tm.tm_sec
|
---|
2844 | dt = self._wizard._bookedFlight.departureTime.time()
|
---|
2845 | dts = dt.hour * 3600 + dt.minute * 60 + dt.second
|
---|
2846 | diff = dts-ts
|
---|
2847 |
|
---|
2848 | markupBegin = ""
|
---|
2849 | markupEnd = ""
|
---|
2850 | if diff < 0:
|
---|
2851 | markupBegin = '<b><span foreground="red">'
|
---|
2852 | markupEnd = '</span></b>'
|
---|
2853 | elif diff < 3*60 or diff > 30*60:
|
---|
2854 | markupBegin = '<b><span foreground="orange">'
|
---|
2855 | markupEnd = '</span></b>'
|
---|
2856 |
|
---|
2857 | self._departure.set_markup(markupBegin + str(dt) + markupEnd)
|
---|
2858 |
|
---|
2859 | def _backClicked(self, button):
|
---|
2860 | """Called when the Back button is pressed."""
|
---|
2861 | self.goBack()
|
---|
2862 |
|
---|
2863 | def _forwardClicked(self, button):
|
---|
2864 | """Called when the forward button is clicked."""
|
---|
2865 | if not self._completed:
|
---|
2866 | gui = self._wizard.gui
|
---|
2867 | gui.beginBusy(xstr("fuel_get_busy"))
|
---|
2868 |
|
---|
2869 | gui.simulator.getFuel(self._handleFuel)
|
---|
2870 | else:
|
---|
2871 | self._wizard.nextPage()
|
---|
2872 |
|
---|
2873 | def _handleFuel(self, fuelData):
|
---|
2874 | """Callback for the fuel query operation."""
|
---|
2875 | GObject.idle_add(self._processFuel, fuelData)
|
---|
2876 |
|
---|
2877 | def _processFuel(self, fuelData):
|
---|
2878 | """Process the given fuel data."""
|
---|
2879 | self._wizard.gui.endBusy()
|
---|
2880 | self._wizard._fuelData = fuelData
|
---|
2881 | self._wizard.nextPage()
|
---|
2882 |
|
---|
2883 | #-----------------------------------------------------------------------------
|
---|
2884 |
|
---|
2885 | class RoutePage(Page):
|
---|
2886 | """The page containing the route and the flight level."""
|
---|
2887 | def __init__(self, wizard):
|
---|
2888 | """Construct the page."""
|
---|
2889 | super(RoutePage, self).__init__(wizard, "route",
|
---|
2890 | xstr("route_title"),
|
---|
2891 | xstr("route_help"),
|
---|
2892 | completedHelp = xstr("route_chelp"))
|
---|
2893 |
|
---|
2894 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
2895 | xscale = 0.0, yscale = 0.0)
|
---|
2896 |
|
---|
2897 | mainBox = Gtk.VBox()
|
---|
2898 | alignment.add(mainBox)
|
---|
2899 | self.setMainWidget(alignment)
|
---|
2900 |
|
---|
2901 | levelBox = Gtk.HBox()
|
---|
2902 |
|
---|
2903 | label = Gtk.Label(xstr("route_level"))
|
---|
2904 | label.set_use_underline(True)
|
---|
2905 | levelBox.pack_start(label, True, True, 0)
|
---|
2906 |
|
---|
2907 | self._cruiseLevel = Gtk.SpinButton()
|
---|
2908 | self._cruiseLevel.set_increments(step = 10, page = 100)
|
---|
2909 | self._cruiseLevel.set_range(min = 0, max = 500)
|
---|
2910 | self._cruiseLevel.set_tooltip_text(xstr("route_level_tooltip"))
|
---|
2911 | self._cruiseLevel.set_numeric(True)
|
---|
2912 | self._cruiseLevel.connect("changed", self._cruiseLevelChanged)
|
---|
2913 | self._cruiseLevel.connect("value-changed", self._cruiseLevelChanged)
|
---|
2914 | label.set_mnemonic_widget(self._cruiseLevel)
|
---|
2915 |
|
---|
2916 | levelBox.pack_start(self._cruiseLevel, False, False, 8)
|
---|
2917 |
|
---|
2918 | alignment = Gtk.Alignment(xalign = 0.0, yalign = 0.5,
|
---|
2919 | xscale = 0.0, yscale = 0.0)
|
---|
2920 | alignment.add(levelBox)
|
---|
2921 |
|
---|
2922 | mainBox.pack_start(alignment, False, False, 0)
|
---|
2923 |
|
---|
2924 |
|
---|
2925 | routeBox = Gtk.VBox()
|
---|
2926 |
|
---|
2927 | alignment = Gtk.Alignment(xalign = 0.0, yalign = 0.5,
|
---|
2928 | xscale = 0.0, yscale = 0.0)
|
---|
2929 | label = Gtk.Label(xstr("route_route"))
|
---|
2930 | label.set_use_underline(True)
|
---|
2931 | alignment.add(label)
|
---|
2932 | routeBox.pack_start(alignment, True, True, 0)
|
---|
2933 |
|
---|
2934 | routeWindow = Gtk.ScrolledWindow()
|
---|
2935 | routeWindow.set_size_request(400, 80)
|
---|
2936 | routeWindow.set_shadow_type(Gtk.ShadowType.IN)
|
---|
2937 | routeWindow.set_policy(Gtk.PolicyType.AUTOMATIC,
|
---|
2938 | Gtk.PolicyType.AUTOMATIC)
|
---|
2939 |
|
---|
2940 | self._uppercasingRoute = False
|
---|
2941 |
|
---|
2942 | self._route = Gtk.TextView()
|
---|
2943 | self._route.set_tooltip_text(xstr("route_route_tooltip"))
|
---|
2944 | self._route.set_wrap_mode(Gtk.WrapMode.WORD)
|
---|
2945 | self._route.get_buffer().connect("changed", self._routeChanged)
|
---|
2946 | self._route.get_buffer().connect_after("insert-text", self._routeInserted)
|
---|
2947 | routeWindow.add(self._route)
|
---|
2948 |
|
---|
2949 | label.set_mnemonic_widget(self._route)
|
---|
2950 | routeBox.pack_start(routeWindow, True, True, 0)
|
---|
2951 |
|
---|
2952 | mainBox.pack_start(routeBox, True, True, 8)
|
---|
2953 |
|
---|
2954 | alternateBox = Gtk.HBox()
|
---|
2955 |
|
---|
2956 | label = Gtk.Label(xstr("route_altn"))
|
---|
2957 | label.set_use_underline(True)
|
---|
2958 | alternateBox.pack_start(label, True, True, 0)
|
---|
2959 |
|
---|
2960 | self._alternate = Gtk.Entry()
|
---|
2961 | self._alternate.set_width_chars(6)
|
---|
2962 | self._alternate.connect("changed", self._alternateChanged)
|
---|
2963 | self._alternate.set_tooltip_text(xstr("route_altn_tooltip"))
|
---|
2964 | label.set_mnemonic_widget(self._alternate)
|
---|
2965 |
|
---|
2966 | alternateBox.pack_start(self._alternate, False, False, 8)
|
---|
2967 |
|
---|
2968 | alignment = Gtk.Alignment(xalign = 0.0, yalign = 0.5,
|
---|
2969 | xscale = 0.0, yscale = 0.0)
|
---|
2970 | alignment.add(alternateBox)
|
---|
2971 |
|
---|
2972 | mainBox.pack_start(alignment, False, False, 0)
|
---|
2973 |
|
---|
2974 | self.addCancelFlightButton()
|
---|
2975 |
|
---|
2976 | self._backButton = self.addPreviousButton(clicked = self._backClicked)
|
---|
2977 | self._button = self.addNextButton(clicked = self._forwardClicked)
|
---|
2978 |
|
---|
2979 | @property
|
---|
2980 | def filedCruiseLevel(self):
|
---|
2981 | """Get the filed cruise level."""
|
---|
2982 | return self._cruiseLevel.get_value_as_int()
|
---|
2983 |
|
---|
2984 | @property
|
---|
2985 | def route(self):
|
---|
2986 | """Get the route."""
|
---|
2987 | return self._getRoute()
|
---|
2988 |
|
---|
2989 | @property
|
---|
2990 | def alternate(self):
|
---|
2991 | """Get the ICAO code of the alternate airport."""
|
---|
2992 | return self._alternate.get_text()
|
---|
2993 |
|
---|
2994 | def activate(self):
|
---|
2995 | """Setup the route from the booked flight."""
|
---|
2996 | self._cruiseLevel.set_value(0)
|
---|
2997 | self._cruiseLevel.set_text("")
|
---|
2998 | self._route.get_buffer().set_text(self._wizard._bookedFlight.route)
|
---|
2999 | self._alternate.set_text("")
|
---|
3000 | self._updateForwardButton()
|
---|
3001 |
|
---|
3002 | def _getRoute(self):
|
---|
3003 | """Get the text of the route."""
|
---|
3004 | buffer = self._route.get_buffer()
|
---|
3005 | return buffer.get_text(buffer.get_start_iter(),
|
---|
3006 | buffer.get_end_iter(), True)
|
---|
3007 |
|
---|
3008 | def _updateForwardButton(self):
|
---|
3009 | """Update the sensitivity of the forward button."""
|
---|
3010 | cruiseLevelText = self._cruiseLevel.get_text()
|
---|
3011 | cruiseLevel = int(cruiseLevelText) if cruiseLevelText else 0
|
---|
3012 | alternate = self._alternate.get_text()
|
---|
3013 | self._button.set_sensitive(cruiseLevel>=50 and self._getRoute()!="" and
|
---|
3014 | (len(alternate)==4 or self._wizard.entranceExam))
|
---|
3015 |
|
---|
3016 | def _cruiseLevelChanged(self, *arg):
|
---|
3017 | """Called when the cruise level has changed."""
|
---|
3018 | self._updateForwardButton()
|
---|
3019 |
|
---|
3020 | def _routeChanged(self, textBuffer):
|
---|
3021 | """Called when the route has changed."""
|
---|
3022 | if not self._uppercasingRoute:
|
---|
3023 | self._updateForwardButton()
|
---|
3024 |
|
---|
3025 | def _routeInserted(self, textBuffer, iter, text, length):
|
---|
3026 | """Called when new characters are inserted into the route.
|
---|
3027 |
|
---|
3028 | It uppercases all characters."""
|
---|
3029 | if not self._uppercasingRoute:
|
---|
3030 | self._uppercasingRoute = True
|
---|
3031 |
|
---|
3032 | iter1 = iter.copy()
|
---|
3033 | iter1.backward_chars(length)
|
---|
3034 | textBuffer.delete(iter, iter1)
|
---|
3035 |
|
---|
3036 | textBuffer.insert(iter, text.upper())
|
---|
3037 |
|
---|
3038 | self._uppercasingRoute = False
|
---|
3039 |
|
---|
3040 | def _alternateChanged(self, entry):
|
---|
3041 | """Called when the alternate airport has changed."""
|
---|
3042 | entry.set_text(entry.get_text().upper())
|
---|
3043 | self._updateForwardButton()
|
---|
3044 |
|
---|
3045 | def _backClicked(self, button):
|
---|
3046 | """Called when the Back button is pressed."""
|
---|
3047 | self.goBack()
|
---|
3048 |
|
---|
3049 | def _forwardClicked(self, button):
|
---|
3050 | """Called when the Forward button is clicked."""
|
---|
3051 | if self._wizard.gui.flight.aircraft.simBriefData is None:
|
---|
3052 | self._wizard.usingSimBrief = False
|
---|
3053 | if self._wizard.gui.config.useSimBrief and \
|
---|
3054 | self._wizard.usingSimBrief is not False:
|
---|
3055 | self._wizard.jumpPage("simbrief_setup")
|
---|
3056 | else:
|
---|
3057 | self._wizard.usingSimBrief = False
|
---|
3058 | self._wizard.jumpPage("fuel")
|
---|
3059 |
|
---|
3060 | #-----------------------------------------------------------------------------
|
---|
3061 |
|
---|
3062 | class SimBriefCredentialsDialog(Gtk.Dialog):
|
---|
3063 | """A dialog window to ask for SimBrief credentials."""
|
---|
3064 | def __init__(self, gui, userName, password, rememberPassword):
|
---|
3065 | """Construct the dialog."""
|
---|
3066 | super(SimBriefCredentialsDialog, self).__init__(WINDOW_TITLE_BASE + " - " +
|
---|
3067 | xstr("simbrief_credentials_title"),
|
---|
3068 | gui.mainWindow,
|
---|
3069 | Gtk.DialogFlags.MODAL)
|
---|
3070 | self.add_button(xstr("button_cancel"), Gtk.ResponseType.CANCEL)
|
---|
3071 | self.add_button(xstr("button_ok"), Gtk.ResponseType.OK)
|
---|
3072 |
|
---|
3073 | contentArea = self.get_content_area()
|
---|
3074 |
|
---|
3075 | contentAlignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
3076 | xscale = 0.0, yscale = 0.0)
|
---|
3077 | contentAlignment.set_padding(padding_top = 4, padding_bottom = 16,
|
---|
3078 | padding_left = 8, padding_right = 8)
|
---|
3079 |
|
---|
3080 | contentArea.pack_start(contentAlignment, False, False, 0)
|
---|
3081 |
|
---|
3082 | contentVBox = Gtk.VBox()
|
---|
3083 | contentAlignment.add(contentVBox)
|
---|
3084 |
|
---|
3085 | label = Gtk.Label(xstr("simbrief_login_failed"))
|
---|
3086 | label.set_alignment(0.0, 0.0)
|
---|
3087 |
|
---|
3088 | contentVBox.pack_start(label, False, False, 0)
|
---|
3089 |
|
---|
3090 | tableAlignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
3091 | xscale = 0.0, yscale = 0.0)
|
---|
3092 | tableAlignment.set_padding(padding_top = 24, padding_bottom = 0,
|
---|
3093 | padding_left = 0, padding_right = 0)
|
---|
3094 |
|
---|
3095 | table = Gtk.Table(3, 2)
|
---|
3096 | table.set_row_spacings(4)
|
---|
3097 | table.set_col_spacings(16)
|
---|
3098 | table.set_homogeneous(False)
|
---|
3099 |
|
---|
3100 | tableAlignment.add(table)
|
---|
3101 | contentVBox.pack_start(tableAlignment, True, True, 0)
|
---|
3102 |
|
---|
3103 | label = Gtk.Label(xstr("simbrief_username"))
|
---|
3104 | label.set_use_underline(True)
|
---|
3105 | label.set_alignment(0.0, 0.5)
|
---|
3106 | table.attach(label, 0, 1, 0, 1)
|
---|
3107 |
|
---|
3108 | self._userName = Gtk.Entry()
|
---|
3109 | self._userName.set_width_chars(16)
|
---|
3110 | #self._userName.connect("changed",
|
---|
3111 | # lambda button: self._updateForwardButton())
|
---|
3112 | self._userName.set_tooltip_text(xstr("simbrief_username_tooltip"))
|
---|
3113 | self._userName.set_text(userName)
|
---|
3114 | table.attach(self._userName, 1, 2, 0, 1)
|
---|
3115 | label.set_mnemonic_widget(self._userName)
|
---|
3116 |
|
---|
3117 | label = Gtk.Label(xstr("simbrief_password"))
|
---|
3118 | label.set_use_underline(True)
|
---|
3119 | label.set_alignment(0.0, 0.5)
|
---|
3120 | table.attach(label, 0, 1, 1, 2)
|
---|
3121 |
|
---|
3122 | self._password = Gtk.Entry()
|
---|
3123 | self._password.set_visibility(False)
|
---|
3124 | #self._password.connect("changed",
|
---|
3125 | # lambda button: self._updateForwardButton())
|
---|
3126 | self._password.set_tooltip_text(xstr("simbrief_password_tooltip"))
|
---|
3127 | self._password.set_text(password)
|
---|
3128 | table.attach(self._password, 1, 2, 1, 2)
|
---|
3129 | label.set_mnemonic_widget(self._password)
|
---|
3130 |
|
---|
3131 | self._rememberButton = Gtk.CheckButton(xstr("simbrief_remember_password"))
|
---|
3132 | self._rememberButton.set_use_underline(True)
|
---|
3133 | self._rememberButton.set_tooltip_text(xstr("simbrief_remember_tooltip"))
|
---|
3134 | self._rememberButton.set_active(rememberPassword)
|
---|
3135 | table.attach(self._rememberButton, 1, 2, 2, 3, ypadding = 8)
|
---|
3136 |
|
---|
3137 | @property
|
---|
3138 | def userName(self):
|
---|
3139 | """Get the user name entered."""
|
---|
3140 | return self._userName.get_text()
|
---|
3141 |
|
---|
3142 | @property
|
---|
3143 | def password(self):
|
---|
3144 | """Get the password entered."""
|
---|
3145 | return self._password.get_text()
|
---|
3146 |
|
---|
3147 | @property
|
---|
3148 | def rememberPassword(self):
|
---|
3149 | """Get whether the password is to be remembered."""
|
---|
3150 | return self._rememberButton.get_active()
|
---|
3151 |
|
---|
3152 | def run(self):
|
---|
3153 | """Run the dialog."""
|
---|
3154 | self.show_all()
|
---|
3155 |
|
---|
3156 | response = super(SimBriefCredentialsDialog, self).run()
|
---|
3157 |
|
---|
3158 | self.hide()
|
---|
3159 |
|
---|
3160 | return response
|
---|
3161 |
|
---|
3162 | #-----------------------------------------------------------------------------
|
---|
3163 |
|
---|
3164 | class SimBriefSetupPage(Page):
|
---|
3165 | """Page for setting up some parameters for SimBrief."""
|
---|
3166 | monthNum2Name = [
|
---|
3167 | "JAN",
|
---|
3168 | "FEB",
|
---|
3169 | "MAR",
|
---|
3170 | "APR",
|
---|
3171 | "MAY",
|
---|
3172 | "JUN",
|
---|
3173 | "JUL",
|
---|
3174 | "AUG",
|
---|
3175 | "SEP",
|
---|
3176 | "OCT",
|
---|
3177 | "NOV",
|
---|
3178 | "DEC"
|
---|
3179 | ]
|
---|
3180 |
|
---|
3181 | progress2Message = {
|
---|
3182 | cef.SIMBRIEF_PROGRESS_SEARCHING_BROWSER: "simbrief_progress_searching_browser",
|
---|
3183 | cef.SIMBRIEF_PROGRESS_LOADING_FORM: "simbrief_progress_loading_form",
|
---|
3184 | cef.SIMBRIEF_PROGRESS_FILLING_FORM: "simbrief_progress_filling_form",
|
---|
3185 | cef.SIMBRIEF_PROGRESS_WAITING_LOGIN: "simbrief_progress_waiting_login",
|
---|
3186 | cef.SIMBRIEF_PROGRESS_LOGGING_IN: "simbrief_progress_logging_in",
|
---|
3187 | cef.SIMBRIEF_PROGRESS_WAITING_RESULT: "simbrief_progress_waiting_result",
|
---|
3188 | cef.SIMBRIEF_PROGRESS_RETRIEVING_BRIEFING: "simbrief_progress_retrieving_briefing"
|
---|
3189 | }
|
---|
3190 |
|
---|
3191 | result2Message = {
|
---|
3192 | cef.SIMBRIEF_RESULT_ERROR_OTHER: "simbrief_result_error_other",
|
---|
3193 | cef.SIMBRIEF_RESULT_ERROR_NO_FORM: "simbrief_result_error_no_form",
|
---|
3194 | cef.SIMBRIEF_RESULT_ERROR_NO_POPUP: "simbrief_result_error_no_popup",
|
---|
3195 | cef.SIMBRIEF_RESULT_ERROR_LOGIN_FAILED: "simbrief_result_error_login_failed"
|
---|
3196 | }
|
---|
3197 |
|
---|
3198 | @staticmethod
|
---|
3199 | def getHTMLFilePath():
|
---|
3200 | """Get the path of the HTML file to contain the generated flight
|
---|
3201 | plan."""
|
---|
3202 | if os.name=="nt":
|
---|
3203 | return os.path.join(tempfile.gettempdir(),
|
---|
3204 | "mlx_simbrief" +
|
---|
3205 | (".secondary" if secondaryInstallation else "") +
|
---|
3206 | ".html")
|
---|
3207 | else:
|
---|
3208 | import pwd
|
---|
3209 | return os.path.join(tempfile.gettempdir(),
|
---|
3210 | "mlx_simbrief." + pwd.getpwuid(os.getuid())[0] + "" +
|
---|
3211 | (".secondary" if secondaryInstallation else "") +
|
---|
3212 | ".html")
|
---|
3213 |
|
---|
3214 | def __init__(self, wizard):
|
---|
3215 | """Construct the setup page."""
|
---|
3216 |
|
---|
3217 | super(SimBriefSetupPage, self).__init__(wizard, "simbrief_setup",
|
---|
3218 | xstr("simbrief_setup_title"),
|
---|
3219 | xstr("simbrief_setup_help"),
|
---|
3220 | xstr("simbrief_setup_chelp"))
|
---|
3221 |
|
---|
3222 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
3223 | xscale = 0.0, yscale = 0.0)
|
---|
3224 |
|
---|
3225 | table = Gtk.Table(9, 3)
|
---|
3226 | table.set_row_spacings(4)
|
---|
3227 | table.set_col_spacings(16)
|
---|
3228 | table.set_homogeneous(False)
|
---|
3229 | alignment.add(table)
|
---|
3230 | self.setMainWidget(alignment)
|
---|
3231 |
|
---|
3232 | label = Gtk.Label(xstr("simbrief_username"))
|
---|
3233 | label.set_use_underline(True)
|
---|
3234 | label.set_alignment(0.0, 0.5)
|
---|
3235 | table.attach(label, 0, 1, 0, 1)
|
---|
3236 |
|
---|
3237 | self._userName = Gtk.Entry()
|
---|
3238 | self._userName.set_width_chars(16)
|
---|
3239 | self._userName.connect("changed",
|
---|
3240 | lambda button: self._updateForwardButton())
|
---|
3241 | self._userName.set_tooltip_text(xstr("simbrief_username_tooltip"))
|
---|
3242 | table.attach(self._userName, 1, 2, 0, 1)
|
---|
3243 | label.set_mnemonic_widget(self._userName)
|
---|
3244 |
|
---|
3245 | label = Gtk.Label(xstr("simbrief_password"))
|
---|
3246 | label.set_use_underline(True)
|
---|
3247 | label.set_alignment(0.0, 0.5)
|
---|
3248 | table.attach(label, 0, 1, 1, 2)
|
---|
3249 |
|
---|
3250 | self._password = Gtk.Entry()
|
---|
3251 | self._password.set_visibility(False)
|
---|
3252 | self._password.connect("changed",
|
---|
3253 | lambda button: self._updateForwardButton())
|
---|
3254 | self._password.set_tooltip_text(xstr("simbrief_password_tooltip"))
|
---|
3255 | table.attach(self._password, 1, 2, 1, 2)
|
---|
3256 | label.set_mnemonic_widget(self._password)
|
---|
3257 |
|
---|
3258 | self._rememberButton = Gtk.CheckButton(xstr("simbrief_remember_password"))
|
---|
3259 | self._rememberButton.set_use_underline(True)
|
---|
3260 | self._rememberButton.set_tooltip_text(xstr("simbrief_remember_tooltip"))
|
---|
3261 | table.attach(self._rememberButton, 1, 2, 2, 3, ypadding = 8)
|
---|
3262 |
|
---|
3263 | label = Gtk.Label(xstr("simbrief_extra_fuel"))
|
---|
3264 | label.set_use_underline(True)
|
---|
3265 | label.set_alignment(0.0, 0.5)
|
---|
3266 | table.attach(label, 0, 1, 3, 4)
|
---|
3267 |
|
---|
3268 | self._extraFuel = IntegerEntry(defaultValue = 0)
|
---|
3269 | self._extraFuel.set_width_chars(6)
|
---|
3270 | self._extraFuel.set_tooltip_text(xstr("simbrief_extra_fuel_tooltip"))
|
---|
3271 | table.attach(self._extraFuel, 1, 2, 3, 4)
|
---|
3272 | label.set_mnemonic_widget(self._extraFuel)
|
---|
3273 |
|
---|
3274 | table.attach(Gtk.Label("kg"), 2, 3, 3, 4)
|
---|
3275 |
|
---|
3276 | label = Gtk.Label(xstr("simbrief_takeoff_runway"))
|
---|
3277 | label.set_use_underline(True)
|
---|
3278 | label.set_alignment(0.0, 0.5)
|
---|
3279 | table.attach(label, 0, 1, 4, 5)
|
---|
3280 |
|
---|
3281 | self._takeoffRunway = Gtk.Entry()
|
---|
3282 | self._takeoffRunway.set_width_chars(10)
|
---|
3283 | self._takeoffRunway.set_tooltip_text(xstr("simbrief_takeoff_runway_tooltip"))
|
---|
3284 | self._takeoffRunway.connect("changed", self._upperChanged)
|
---|
3285 | table.attach(self._takeoffRunway, 1, 2, 4, 5)
|
---|
3286 | label.set_mnemonic_widget(self._takeoffRunway)
|
---|
3287 |
|
---|
3288 | label = Gtk.Label(xstr("simbrief_landing_runway"))
|
---|
3289 | label.set_use_underline(True)
|
---|
3290 | label.set_alignment(0.0, 0.5)
|
---|
3291 | table.attach(label, 0, 1, 5, 6)
|
---|
3292 |
|
---|
3293 | self._landingRunway = Gtk.Entry()
|
---|
3294 | self._landingRunway.set_width_chars(10)
|
---|
3295 | self._landingRunway.set_tooltip_text(xstr("simbrief_takeoff_runway_tooltip"))
|
---|
3296 | self._landingRunway.connect("changed", self._upperChanged)
|
---|
3297 | table.attach(self._landingRunway, 1, 2, 5, 6)
|
---|
3298 | label.set_mnemonic_widget(self._landingRunway)
|
---|
3299 |
|
---|
3300 | label = Gtk.Label(xstr("simbrief_climb_profile"))
|
---|
3301 | label.set_use_underline(True)
|
---|
3302 | label.set_alignment(0.0, 0.5)
|
---|
3303 | table.attach(label, 0, 1, 6, 7)
|
---|
3304 |
|
---|
3305 | self._climbProfile = Gtk.ComboBox()
|
---|
3306 | renderer = Gtk.CellRendererText()
|
---|
3307 | self._climbProfile.pack_start(renderer, True)
|
---|
3308 | self._climbProfile.add_attribute(renderer, "text", 0)
|
---|
3309 | self._climbProfile.set_tooltip_text(xstr("simbrief_climb_profile_tooltip"))
|
---|
3310 | table.attach(self._climbProfile, 1, 2, 6, 7)
|
---|
3311 | label.set_mnemonic_widget(self._climbProfile)
|
---|
3312 |
|
---|
3313 | label = Gtk.Label(xstr("simbrief_cruise_profile"))
|
---|
3314 | label.set_use_underline(True)
|
---|
3315 | label.set_alignment(0.0, 0.5)
|
---|
3316 | table.attach(label, 0, 1, 7, 8)
|
---|
3317 |
|
---|
3318 | self._cruiseProfile = Gtk.ComboBox()
|
---|
3319 | renderer = Gtk.CellRendererText()
|
---|
3320 | self._cruiseProfile.pack_start(renderer, True)
|
---|
3321 | self._cruiseProfile.add_attribute(renderer, "text", 0)
|
---|
3322 | self._cruiseProfile.set_tooltip_text(xstr("simbrief_cruise_profile_tooltip"))
|
---|
3323 | table.attach(self._cruiseProfile, 1, 2, 7, 8)
|
---|
3324 | label.set_mnemonic_widget(self._cruiseProfile)
|
---|
3325 |
|
---|
3326 | label = Gtk.Label(xstr("simbrief_descent_profile"))
|
---|
3327 | label.set_use_underline(True)
|
---|
3328 | label.set_alignment(0.0, 0.5)
|
---|
3329 | table.attach(label, 0, 1, 8, 9)
|
---|
3330 |
|
---|
3331 | self._descentProfile = Gtk.ComboBox()
|
---|
3332 | renderer = Gtk.CellRendererText()
|
---|
3333 | self._descentProfile.pack_start(renderer, True)
|
---|
3334 | self._descentProfile.add_attribute(renderer, "text", 0)
|
---|
3335 | self._descentProfile.set_tooltip_text(xstr("simbrief_descent_profile_tooltip"))
|
---|
3336 | table.attach(self._descentProfile, 1, 2, 8, 9)
|
---|
3337 | label.set_mnemonic_widget(self._descentProfile)
|
---|
3338 |
|
---|
3339 | self.addCancelFlightButton()
|
---|
3340 |
|
---|
3341 | self._backButton = self.addPreviousButton(clicked = self._backClicked)
|
---|
3342 | self._button = self.addNextButton(clicked = self._forwardClicked)
|
---|
3343 |
|
---|
3344 | def activate(self):
|
---|
3345 | """Activate the SimBrief setup page"""
|
---|
3346 | config = self._wizard.gui.config
|
---|
3347 |
|
---|
3348 | self._userName.set_text(config.simBriefUserName)
|
---|
3349 | self._userName.set_sensitive(True)
|
---|
3350 |
|
---|
3351 | self._password.set_text(config.simBriefPassword)
|
---|
3352 | self._password.set_sensitive(True)
|
---|
3353 |
|
---|
3354 | self._rememberButton.set_active(config.rememberSimBriefPassword)
|
---|
3355 | self._rememberButton.set_sensitive(True)
|
---|
3356 |
|
---|
3357 | self._extraFuel.set_int(0)
|
---|
3358 | self._extraFuel.set_sensitive(True)
|
---|
3359 |
|
---|
3360 | self._takeoffRunway.set_text("")
|
---|
3361 | self._takeoffRunway.set_sensitive(True)
|
---|
3362 |
|
---|
3363 | self._landingRunway.set_text("")
|
---|
3364 | self._landingRunway.set_sensitive(True)
|
---|
3365 |
|
---|
3366 | simBriefData = self._wizard.gui.flight.aircraft.simBriefData
|
---|
3367 | for (control, profiles) in [(self._climbProfile,
|
---|
3368 | simBriefData.climbProfiles),
|
---|
3369 | (self._cruiseProfile,
|
---|
3370 | simBriefData.cruiseProfiles),
|
---|
3371 | (self._descentProfile,
|
---|
3372 | simBriefData.descentProfiles)]:
|
---|
3373 | model = Gtk.ListStore(str)
|
---|
3374 | for profile in profiles:
|
---|
3375 | model.append([profile])
|
---|
3376 | control.set_model(model)
|
---|
3377 | control.set_sensitive(True)
|
---|
3378 |
|
---|
3379 | self._climbProfile.set_active(0)
|
---|
3380 | self._cruiseProfile.set_active(0)
|
---|
3381 | self._descentProfile.set_active(0)
|
---|
3382 |
|
---|
3383 | self._updateForwardButton()
|
---|
3384 |
|
---|
3385 | def _updateForwardButton(self):
|
---|
3386 | """Update the sensitivity of the forward button."""
|
---|
3387 | self._button.set_sensitive(len(self._userName.get_text())>0 and
|
---|
3388 | len(self._password.get_text())>0)
|
---|
3389 |
|
---|
3390 | def _backClicked(self, button):
|
---|
3391 | """Called when the Back button is pressed."""
|
---|
3392 | self.goBack()
|
---|
3393 |
|
---|
3394 | def _forwardClicked(self, button):
|
---|
3395 | if self._completed:
|
---|
3396 | self._wizard.nextPage()
|
---|
3397 | else:
|
---|
3398 | config = self._wizard.gui.config
|
---|
3399 |
|
---|
3400 | config.simBriefUserName = self._userName.get_text()
|
---|
3401 |
|
---|
3402 | rememberPassword = self._rememberButton.get_active()
|
---|
3403 | config.simBriefPassword = \
|
---|
3404 | self._password.get_text() if rememberPassword else ""
|
---|
3405 | config.rememberSimBriefPassword = rememberPassword
|
---|
3406 |
|
---|
3407 | config.save()
|
---|
3408 |
|
---|
3409 | plan = self._getPlan()
|
---|
3410 | print("plan:", plan)
|
---|
3411 |
|
---|
3412 | takeoffRunway = self._takeoffRunway.get_text()
|
---|
3413 | if takeoffRunway:
|
---|
3414 | self._wizard.takeoffRunway = takeoffRunway
|
---|
3415 |
|
---|
3416 | landingRunway = self._landingRunway.get_text()
|
---|
3417 | if landingRunway:
|
---|
3418 | self._wizard.landingRunway = landingRunway
|
---|
3419 |
|
---|
3420 | self._userName.set_sensitive(False)
|
---|
3421 | self._password.set_sensitive(False)
|
---|
3422 | self._rememberButton.set_sensitive(False)
|
---|
3423 | self._extraFuel.set_sensitive(False)
|
---|
3424 | self._takeoffRunway.set_sensitive(False)
|
---|
3425 | self._landingRunway.set_sensitive(False)
|
---|
3426 |
|
---|
3427 | self._climbProfile.set_sensitive(False)
|
---|
3428 | self._cruiseProfile.set_sensitive(False)
|
---|
3429 | self._descentProfile.set_sensitive(False)
|
---|
3430 |
|
---|
3431 | self._wizard.gui.beginBusy(xstr("simbrief_calling"))
|
---|
3432 |
|
---|
3433 | cef.callSimBrief(plan,
|
---|
3434 | self._getCredentials,
|
---|
3435 | self._simBriefProgress,
|
---|
3436 | SimBriefSetupPage.getHTMLFilePath())
|
---|
3437 |
|
---|
3438 | startSound(const.SOUND_NOTAM)
|
---|
3439 |
|
---|
3440 | def _getCredentials(self, count):
|
---|
3441 | """Get the credentials.
|
---|
3442 |
|
---|
3443 | If count is 0, the user name and password entered into the setup page
|
---|
3444 | are returned. Otherwise a dialog box is displayed informing the user of
|
---|
3445 | invalid credentials and requesting another set of them."""
|
---|
3446 | print("_getCredentials", count)
|
---|
3447 | if count==0:
|
---|
3448 | return (self._userName.get_text(), self._password.get_text())
|
---|
3449 | else:
|
---|
3450 | gui = self._wizard.gui
|
---|
3451 | config = gui.config
|
---|
3452 |
|
---|
3453 | dialog = SimBriefCredentialsDialog(gui,
|
---|
3454 | config.simBriefUserName,
|
---|
3455 | config.simBriefPassword,
|
---|
3456 | config.rememberSimBriefPassword)
|
---|
3457 | response = dialog.run()
|
---|
3458 |
|
---|
3459 | if response==Gtk.ResponseType.OK:
|
---|
3460 | userName = dialog.userName
|
---|
3461 | self._userName.set_text(userName)
|
---|
3462 | password = dialog.password
|
---|
3463 | self._password.set_text(password)
|
---|
3464 | rememberPassword = dialog.rememberPassword
|
---|
3465 |
|
---|
3466 | config.simBriefUserName = userName
|
---|
3467 |
|
---|
3468 | config.simBriefPassword = \
|
---|
3469 | password if rememberPassword else ""
|
---|
3470 | config.rememberSimBriefPassword = rememberPassword
|
---|
3471 |
|
---|
3472 | config.save()
|
---|
3473 |
|
---|
3474 | return (userName, password)
|
---|
3475 | else:
|
---|
3476 | return (None, None)
|
---|
3477 |
|
---|
3478 | def _simBriefProgress(self, progress, result, flightInfo):
|
---|
3479 | """The real SimBrief progress handler."""
|
---|
3480 | print("_simBriefProgress", progress, result, flightInfo)
|
---|
3481 | if result==cef.SIMBRIEF_RESULT_NONE:
|
---|
3482 | message = SimBriefSetupPage.progress2Message.get(progress,
|
---|
3483 | "simbrief_progress_unknown")
|
---|
3484 | self._wizard.gui.updateBusyState(xstr(message))
|
---|
3485 | else:
|
---|
3486 | self._wizard.gui.endBusy()
|
---|
3487 |
|
---|
3488 | if result==cef.SIMBRIEF_RESULT_OK:
|
---|
3489 | self._wizard.departureMETARChanged(flightInfo["orig_metar"],
|
---|
3490 | self)
|
---|
3491 | self._wizard.arrivalMETARChanged(flightInfo["dest_metar"], self)
|
---|
3492 | self._wizard.nextPage()
|
---|
3493 | else:
|
---|
3494 | message = SimBriefSetupPage.result2Message.get(result,
|
---|
3495 | "simbrief_result_unknown")
|
---|
3496 | dialog = Gtk.MessageDialog(parent = self._wizard.gui.mainWindow,
|
---|
3497 | type = Gtk.MessageType.ERROR,
|
---|
3498 | message_format =
|
---|
3499 | xstr(message) + "\n"+
|
---|
3500 | xstr("simbrief_cancelled"))
|
---|
3501 |
|
---|
3502 | dialog.add_button(xstr("button_ok"), Gtk.ResponseType.OK)
|
---|
3503 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
3504 | secondary = xstr("flightsel_save_failed_sec")
|
---|
3505 | dialog.format_secondary_markup(secondary)
|
---|
3506 | dialog.run()
|
---|
3507 | dialog.hide()
|
---|
3508 |
|
---|
3509 | self._wizard.usingSimBrief = False
|
---|
3510 | self._wizard.jumpPage("fuel", fromPageShift = 1)
|
---|
3511 |
|
---|
3512 | def _getPlan(self):
|
---|
3513 | """Get the flight plan data for SimBrief."""
|
---|
3514 | plan = {
|
---|
3515 | "airline": "MAH",
|
---|
3516 | "selcal": "XXXX",
|
---|
3517 | "fuelfactor": "P000",
|
---|
3518 | "contpct": "0.05",
|
---|
3519 | "resvrule": "45",
|
---|
3520 | "taxiout": "10",
|
---|
3521 | "taxiin": "10",
|
---|
3522 | "civalue": "AUTO"
|
---|
3523 | }
|
---|
3524 |
|
---|
3525 | wizard = self._wizard
|
---|
3526 | gui = wizard.gui
|
---|
3527 |
|
---|
3528 | loginResult = wizard.loginResult
|
---|
3529 | plan["cpt"] = loginResult.pilotName
|
---|
3530 | plan["pid"] = loginResult.pilotID
|
---|
3531 |
|
---|
3532 | bookedFlight = wizard.bookedFlight
|
---|
3533 | plan["fltnum"] = wizard.bookedFlight.callsign[2:]
|
---|
3534 | plan["type"] = const.icaoCodes[bookedFlight.aircraftType]
|
---|
3535 | plan["orig"] = bookedFlight.departureICAO
|
---|
3536 | plan["dest"] = bookedFlight.arrivalICAO
|
---|
3537 | plan["reg"] = bookedFlight.tailNumber
|
---|
3538 | plan["fin"] = bookedFlight.tailNumber[3:]
|
---|
3539 | plan["pax"] = str(bookedFlight.numPassengers)
|
---|
3540 |
|
---|
3541 | departureTime = bookedFlight.departureTime
|
---|
3542 | plan["date"] = "%d%s%d" % (departureTime.day,
|
---|
3543 | SimBriefSetupPage.monthNum2Name[departureTime.month-1],
|
---|
3544 | departureTime.year%100)
|
---|
3545 | plan["deph"] = str(departureTime.hour)
|
---|
3546 | plan["depm"] = str(departureTime.minute)
|
---|
3547 |
|
---|
3548 | arrivalTime = bookedFlight.arrivalTime
|
---|
3549 | plan["steh"] = str(arrivalTime.hour)
|
---|
3550 | plan["stem"] = str(arrivalTime.minute)
|
---|
3551 |
|
---|
3552 | plan["manualzfw"] = str(wizard.zfw / 1000.0)
|
---|
3553 | plan["cargo"] = str((wizard.bagWeight + wizard.cargoWeight + wizard.mailWeight)/1000.0)
|
---|
3554 |
|
---|
3555 | plan["route"] = wizard.route
|
---|
3556 | plan["fl"] = str(wizard.filedCruiseAltitude)
|
---|
3557 | plan["altn"] = wizard.alternate
|
---|
3558 |
|
---|
3559 | plan["addedfuel"] = str(self._extraFuel.get_int() / 1000.0)
|
---|
3560 | plan["origrwy"] = self._takeoffRunway.get_text()
|
---|
3561 | plan["destrwy"] = self._landingRunway.get_text()
|
---|
3562 |
|
---|
3563 | for (key, control) in [("climb", self._climbProfile),
|
---|
3564 | ("cruise", self._cruiseProfile),
|
---|
3565 | ("descent", self._descentProfile)]:
|
---|
3566 | model = control.get_model()
|
---|
3567 | active = control.get_active_iter()
|
---|
3568 | value = model.get_value(active, 0)
|
---|
3569 | plan[key] = value
|
---|
3570 |
|
---|
3571 | return plan
|
---|
3572 |
|
---|
3573 | def _upperChanged(self, entry, arg = None):
|
---|
3574 | """Called when the value of some entry widget has changed and the value
|
---|
3575 | should be converted to uppercase."""
|
---|
3576 | entry.set_text(entry.get_text().upper())
|
---|
3577 |
|
---|
3578 | #-----------------------------------------------------------------------------
|
---|
3579 |
|
---|
3580 | class SimBriefingPage(Page):
|
---|
3581 | """Page to display the SimBrief HTML briefing."""
|
---|
3582 | class BrowserLifeSpanHandler(object):
|
---|
3583 | """The life-span handler of a browser."""
|
---|
3584 | def __init__(self, simBriefingPage):
|
---|
3585 | """Construct the life-span handler for the given page."""
|
---|
3586 | self._simBriefingPage = simBriefingPage
|
---|
3587 |
|
---|
3588 | def OnBeforeClose(self, browser):
|
---|
3589 | """Called before closing the browser."""
|
---|
3590 | self._simBriefingPage._invalidateBrowser()
|
---|
3591 |
|
---|
3592 | def __init__(self, wizard):
|
---|
3593 | """Construct the setup page."""
|
---|
3594 |
|
---|
3595 | super(SimBriefingPage, self).__init__(wizard, "simbrief_result",
|
---|
3596 | xstr("simbrief_result_title"), "")
|
---|
3597 |
|
---|
3598 | self._alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
3599 | xscale = 1.0, yscale = 1.0)
|
---|
3600 |
|
---|
3601 | self._container = cef.getContainer()
|
---|
3602 | self._alignment.add(self._container)
|
---|
3603 |
|
---|
3604 | self.setMainWidget(self._alignment)
|
---|
3605 |
|
---|
3606 | self._browser = None
|
---|
3607 |
|
---|
3608 | self.addCancelFlightButton()
|
---|
3609 |
|
---|
3610 | self.addPreviousButton(clicked = self._backClicked)
|
---|
3611 |
|
---|
3612 | self._button = self.addNextButton(clicked = self._forwardClicked)
|
---|
3613 | self._button.set_label(xstr("briefing_button"))
|
---|
3614 | self._button.set_has_tooltip(False)
|
---|
3615 | self._button.set_use_stock(False)
|
---|
3616 |
|
---|
3617 | def activate(self):
|
---|
3618 | """Activate the SimBrief flight plan page"""
|
---|
3619 | if self._browser is None:
|
---|
3620 | self._startBrowser()
|
---|
3621 | else:
|
---|
3622 | self._browser.Reload()
|
---|
3623 |
|
---|
3624 | def grabDefault(self):
|
---|
3625 | """If the page has a default button, make it the default one."""
|
---|
3626 | super(SimBriefingPage, self).grabDefault()
|
---|
3627 |
|
---|
3628 | if self._browser is None:
|
---|
3629 | self._startBrowser()
|
---|
3630 |
|
---|
3631 | def _backClicked(self, button):
|
---|
3632 | """Called when the Back button has been pressed."""
|
---|
3633 | self.goBack()
|
---|
3634 |
|
---|
3635 | def _forwardClicked(self, button):
|
---|
3636 | """Called when the Forward button has been pressed."""
|
---|
3637 | if not self._completed:
|
---|
3638 | self._button.set_label(xstr("button_next"))
|
---|
3639 | self._button.set_tooltip_text(xstr("button_next_tooltip"))
|
---|
3640 | self._wizard.usingSimBrief = True
|
---|
3641 | self.complete()
|
---|
3642 |
|
---|
3643 | self._wizard.nextPage()
|
---|
3644 |
|
---|
3645 | def _startBrowser(self):
|
---|
3646 | """Start the browser.
|
---|
3647 |
|
---|
3648 | If a container is needed, create one."""
|
---|
3649 | if self._container is None:
|
---|
3650 | self._container = cef.getContainer()
|
---|
3651 | self._alignment.add(self._container)
|
---|
3652 |
|
---|
3653 | url = "file://" + SimBriefSetupPage.getHTMLFilePath()
|
---|
3654 | self._browser = cef.startInContainer(self._container, url)
|
---|
3655 |
|
---|
3656 | lifeSpanHandler = SimBriefingPage.BrowserLifeSpanHandler(self)
|
---|
3657 | self._browser.SetClientHandler(lifeSpanHandler)
|
---|
3658 |
|
---|
3659 | def _invalidateBrowser(self):
|
---|
3660 | """Invalidate the browser (and associated stuff)."""
|
---|
3661 | self._alignment.remove(self._container)
|
---|
3662 | self._container = None
|
---|
3663 | self._browser = None
|
---|
3664 |
|
---|
3665 | #-----------------------------------------------------------------------------
|
---|
3666 |
|
---|
3667 | class FuelTank(Gtk.VBox):
|
---|
3668 | """Widget for the fuel tank."""
|
---|
3669 | def __init__(self, fuelTank, name, capacity, currentWeight):
|
---|
3670 | """Construct the widget for the tank with the given name."""
|
---|
3671 | super(FuelTank, self).__init__()
|
---|
3672 |
|
---|
3673 | self._enabled = True
|
---|
3674 | self.fuelTank = fuelTank
|
---|
3675 | self.capacity = capacity
|
---|
3676 | self.currentWeight = currentWeight
|
---|
3677 | self.expectedWeight = currentWeight
|
---|
3678 |
|
---|
3679 | self._label = label = Gtk.Label("<b>" + name + "</b>")
|
---|
3680 | label.set_use_markup(True)
|
---|
3681 | label.set_use_underline(True)
|
---|
3682 | label.set_justify(Gtk.Justification.CENTER)
|
---|
3683 | label.set_alignment(0.5, 1.0)
|
---|
3684 |
|
---|
3685 | self._tankFigure = Gtk.EventBox()
|
---|
3686 | self._tankFigure.set_size_request(38, 200)
|
---|
3687 | self._tankFigure.set_visible_window(False)
|
---|
3688 | self._tankFigure.set_tooltip_markup(xstr("fuel_tank_tooltip"))
|
---|
3689 |
|
---|
3690 | self._tankFigure.connect("draw", self._drawTankFigure)
|
---|
3691 | self._tankFigure.connect("button_press_event", self._buttonPressed)
|
---|
3692 | self._tankFigure.connect("motion_notify_event", self._motionNotify)
|
---|
3693 |
|
---|
3694 | self._tankFigure.add_events(Gdk.EventMask.SCROLL_MASK)
|
---|
3695 | self._tankFigure.connect("scroll-event", self._scrolled)
|
---|
3696 |
|
---|
3697 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
3698 | xscale = 0.0, yscale = 1.0)
|
---|
3699 | alignment.add(self._tankFigure)
|
---|
3700 |
|
---|
3701 | self.pack_start(alignment, True, True, 4)
|
---|
3702 |
|
---|
3703 | self._expectedButton = Gtk.SpinButton()
|
---|
3704 | self._expectedButton.set_numeric(True)
|
---|
3705 | self._expectedButton.set_range(0, self.capacity)
|
---|
3706 | self._expectedButton.set_increments(10, 100)
|
---|
3707 | self._expectedButton.set_value(currentWeight)
|
---|
3708 | self._expectedButton.set_alignment(1.0)
|
---|
3709 | self._expectedButton.set_width_chars(5)
|
---|
3710 | self._expectedButton.connect("value-changed", self._expectedChanged)
|
---|
3711 |
|
---|
3712 | label.set_mnemonic_widget(self._expectedButton)
|
---|
3713 |
|
---|
3714 | @property
|
---|
3715 | def label(self):
|
---|
3716 | """Get the label with the caption."""
|
---|
3717 | return self._label
|
---|
3718 |
|
---|
3719 | @property
|
---|
3720 | def expectedButton(self):
|
---|
3721 | """Get the button containing the expected value."""
|
---|
3722 | return self._expectedButton
|
---|
3723 |
|
---|
3724 | def setCurrent(self, currentWeight):
|
---|
3725 | """Set the current weight."""
|
---|
3726 | self.currentWeight = currentWeight
|
---|
3727 | self._redraw()
|
---|
3728 |
|
---|
3729 | def isCorrect(self):
|
---|
3730 | """Determine if the contents of the fuel tank are as expected"""
|
---|
3731 | return abs(self.expectedWeight - self.currentWeight)<=1
|
---|
3732 |
|
---|
3733 | def disable(self):
|
---|
3734 | """Disable the fuel tank."""
|
---|
3735 | self._expectedButton.set_sensitive(False)
|
---|
3736 | self._enabled = False
|
---|
3737 |
|
---|
3738 | def _redraw(self):
|
---|
3739 | """Redraw the tank figure."""
|
---|
3740 | self._tankFigure.queue_draw()
|
---|
3741 |
|
---|
3742 | def _drawTankFigure(self, tankFigure, eventOrContext):
|
---|
3743 | """Draw the tank figure."""
|
---|
3744 | triangleSize = 5
|
---|
3745 |
|
---|
3746 | context = eventOrContext
|
---|
3747 | (xOffset, yOffset) = (0, 0)
|
---|
3748 |
|
---|
3749 | width = tankFigure.get_allocated_width()
|
---|
3750 | height = tankFigure.get_allocated_height()
|
---|
3751 |
|
---|
3752 | rectangleX0 = triangleSize
|
---|
3753 | rectangleY0 = triangleSize
|
---|
3754 | rectangleX1 = width - 1 - triangleSize
|
---|
3755 | rectangleY1 = height - 1 - triangleSize
|
---|
3756 | rectangleLineWidth = 2.0
|
---|
3757 |
|
---|
3758 | context.set_source_rgb(0.0, 0.0, 0.0)
|
---|
3759 | context.set_line_width(rectangleLineWidth)
|
---|
3760 | context.rectangle(xOffset + rectangleX0 + rectangleLineWidth/2,
|
---|
3761 | yOffset + rectangleY0 + rectangleLineWidth/2,
|
---|
3762 | rectangleX1 - rectangleX0 - rectangleLineWidth,
|
---|
3763 | rectangleY1 - rectangleY0 - rectangleLineWidth)
|
---|
3764 | context.stroke()
|
---|
3765 |
|
---|
3766 | rectangleInnerLeft = rectangleX0 + rectangleLineWidth
|
---|
3767 | rectangleInnerRight = rectangleX1 - rectangleLineWidth
|
---|
3768 | self._rectangleInnerTop = rectangleInnerTop = rectangleY0 + rectangleLineWidth
|
---|
3769 | self._rectangleInnerBottom = rectangleInnerBottom = rectangleY1 - rectangleLineWidth
|
---|
3770 |
|
---|
3771 | rectangleInnerWidth = rectangleInnerRight - rectangleInnerLeft
|
---|
3772 | rectangleInnerHeight = rectangleInnerBottom - rectangleInnerTop
|
---|
3773 |
|
---|
3774 | context.set_source_rgb(1.0, 0.9, 0.6)
|
---|
3775 | currentHeight = self.currentWeight * rectangleInnerHeight / self.capacity
|
---|
3776 | currentX = rectangleInnerTop + rectangleInnerHeight - currentHeight
|
---|
3777 | context.rectangle(xOffset + rectangleInnerLeft,
|
---|
3778 | yOffset + rectangleInnerTop +
|
---|
3779 | rectangleInnerHeight - currentHeight,
|
---|
3780 | rectangleInnerWidth, currentHeight)
|
---|
3781 | context.fill()
|
---|
3782 |
|
---|
3783 | expectedHeight = self.expectedWeight * rectangleInnerHeight / self.capacity
|
---|
3784 | expectedY = rectangleInnerTop + rectangleInnerHeight - expectedHeight
|
---|
3785 |
|
---|
3786 | context.set_line_width(1.5)
|
---|
3787 | context.set_source_rgb(0.0, 0.85, 0.85)
|
---|
3788 | context.move_to(xOffset + rectangleX0, yOffset + expectedY)
|
---|
3789 | context.line_to(xOffset + rectangleX1, yOffset + expectedY)
|
---|
3790 | context.stroke()
|
---|
3791 |
|
---|
3792 | context.set_line_width(0.0)
|
---|
3793 | context.move_to(xOffset + 0, yOffset + expectedY - triangleSize)
|
---|
3794 | context.line_to(xOffset + 0, yOffset + expectedY + triangleSize)
|
---|
3795 | context.line_to(xOffset + rectangleX0 + 1, yOffset + expectedY)
|
---|
3796 | context.line_to(xOffset + 0, yOffset + expectedY - triangleSize)
|
---|
3797 | context.fill()
|
---|
3798 |
|
---|
3799 | context.set_line_width(0.0)
|
---|
3800 | context.move_to(xOffset + width, yOffset + expectedY - triangleSize)
|
---|
3801 | context.line_to(xOffset + width, yOffset + expectedY + triangleSize)
|
---|
3802 | context.line_to(xOffset + rectangleX1 - 1, yOffset + expectedY)
|
---|
3803 | context.line_to(xOffset + width, yOffset + expectedY - triangleSize)
|
---|
3804 | context.fill()
|
---|
3805 |
|
---|
3806 | return True
|
---|
3807 |
|
---|
3808 | def _setExpectedFromY(self, y):
|
---|
3809 | """Set the expected weight from the given Y-coordinate."""
|
---|
3810 | level = (self._rectangleInnerBottom - y) / \
|
---|
3811 | (self._rectangleInnerBottom - self._rectangleInnerTop)
|
---|
3812 | level = min(1.0, max(0.0, level))
|
---|
3813 | self._expectedButton.set_value(level * self.capacity)
|
---|
3814 |
|
---|
3815 | def _buttonPressed(self, tankFigure, event):
|
---|
3816 | """Called when a button is pressed in the figure.
|
---|
3817 |
|
---|
3818 | The expected level will be set there."""
|
---|
3819 | if self._enabled and event.button==1:
|
---|
3820 | self._setExpectedFromY(event.y)
|
---|
3821 |
|
---|
3822 | def _motionNotify(self, tankFigure, event):
|
---|
3823 | """Called when the mouse pointer moves within the area of a tank figure."""
|
---|
3824 | if self._enabled and event.state==Gdk.ModifierType.BUTTON1_MASK:
|
---|
3825 | self._setExpectedFromY(event.y)
|
---|
3826 |
|
---|
3827 | def _scrolled(self, tankFigure, event):
|
---|
3828 | """Called when a scroll event is received."""
|
---|
3829 | if self._enabled:
|
---|
3830 | increment = 1 if event.state==Gdk.ModifierType.CONTROL_MASK \
|
---|
3831 | else 100 if event.state==Gdk.ModifierType.SHIFT_MASK \
|
---|
3832 | else 10 if event.state==0 else 0
|
---|
3833 | if increment!=0:
|
---|
3834 | if event.direction==Gdk.ScrollDirection.DOWN:
|
---|
3835 | increment *= -1
|
---|
3836 | self._expectedButton.spin(Gtk.SpinType.USER_DEFINED, increment)
|
---|
3837 |
|
---|
3838 | def _expectedChanged(self, spinButton):
|
---|
3839 | """Called when the expected value has changed."""
|
---|
3840 | self.expectedWeight = spinButton.get_value_as_int()
|
---|
3841 | self._redraw()
|
---|
3842 |
|
---|
3843 | #-----------------------------------------------------------------------------
|
---|
3844 |
|
---|
3845 | class FuelPage(Page):
|
---|
3846 | """The page containing the fuel tank filling."""
|
---|
3847 | _pumpStep = 0.02
|
---|
3848 |
|
---|
3849 | def __init__(self, wizard):
|
---|
3850 | """Construct the page."""
|
---|
3851 | super(FuelPage, self).__init__(wizard, "fuel",
|
---|
3852 | xstr("fuel_title"),
|
---|
3853 | xstr("fuel_help_pre") +
|
---|
3854 | xstr("fuel_help_post"),
|
---|
3855 | completedHelp = xstr("fuel_chelp"))
|
---|
3856 |
|
---|
3857 | self._fuelTanks = []
|
---|
3858 | self._fuelTable = None
|
---|
3859 | self._fuelAlignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
3860 | xscale = 0.0, yscale = 1.0)
|
---|
3861 | self.setMainWidget(self._fuelAlignment)
|
---|
3862 |
|
---|
3863 | tankData = [(tank, 2500, 3900) for tank in acft.mostFuelTanks]
|
---|
3864 | self._setupTanks(tankData)
|
---|
3865 |
|
---|
3866 | self.addCancelFlightButton()
|
---|
3867 |
|
---|
3868 | self._backButton = self.addPreviousButton(clicked = self._backClicked)
|
---|
3869 | self._button = self.addNextButton(clicked = self._forwardClicked)
|
---|
3870 |
|
---|
3871 | self._pumpIndex = 0
|
---|
3872 |
|
---|
3873 | def activate(self):
|
---|
3874 | """Activate the page."""
|
---|
3875 | self._setupTanks(self._wizard._fuelData)
|
---|
3876 |
|
---|
3877 | aircraft = self._wizard.gui.flight.aircraft
|
---|
3878 | minLandingFuel = aircraft.minLandingFuel
|
---|
3879 | recommendedLandingFuel = aircraft.recommendedLandingFuel
|
---|
3880 |
|
---|
3881 | middleHelp = "" if minLandingFuel is None else \
|
---|
3882 | (xstr("fuel_help_min") % (minLandingFuel,)) \
|
---|
3883 | if recommendedLandingFuel is None else \
|
---|
3884 | (xstr("fuel_help_min_rec") % (minLandingFuel,
|
---|
3885 | recommendedLandingFuel))
|
---|
3886 | self.setHelp(xstr("fuel_help_pre") + middleHelp + xstr("fuel_help_post"))
|
---|
3887 |
|
---|
3888 | def finalize(self):
|
---|
3889 | """Finalize the page."""
|
---|
3890 | for fuelTank in self._fuelTanks:
|
---|
3891 | fuelTank.disable()
|
---|
3892 |
|
---|
3893 | def _backClicked(self, button):
|
---|
3894 | """Called when the Back button is pressed."""
|
---|
3895 | self.goBack()
|
---|
3896 |
|
---|
3897 | def _forwardClicked(self, button):
|
---|
3898 | """Called when the forward button is clicked."""
|
---|
3899 | if not self._completed:
|
---|
3900 | self._pumpIndex = 0
|
---|
3901 | self._wizard.gui.beginBusy(xstr("fuel_pump_busy"))
|
---|
3902 | self._pump()
|
---|
3903 | elif self._wizard.usingSimBrief:
|
---|
3904 | self._wizard.jumpPage("takeoff")
|
---|
3905 | else:
|
---|
3906 | self._wizard.jumpPage("briefing1")
|
---|
3907 |
|
---|
3908 | def _setupTanks(self, tankData):
|
---|
3909 | """Setup the tanks for the given data."""
|
---|
3910 | numTanks = len(tankData)
|
---|
3911 | if self._fuelTable is not None:
|
---|
3912 | self._fuelAlignment.remove(self._fuelTable)
|
---|
3913 |
|
---|
3914 | self._fuelTanks = []
|
---|
3915 | self._fuelTable = Gtk.Grid()
|
---|
3916 | self._fuelTable.set_column_homogeneous(True)
|
---|
3917 | self._fuelTable.set_row_spacing(4)
|
---|
3918 | self._fuelTable.set_column_spacing(16 if numTanks<5 else 0)
|
---|
3919 | index = 0
|
---|
3920 | for (tank, current, capacity) in tankData:
|
---|
3921 | fuelTank = FuelTank(tank,
|
---|
3922 | xstr("fuel_tank_" +
|
---|
3923 | const.fuelTank2string(tank)),
|
---|
3924 | capacity, current)
|
---|
3925 | self._fuelTanks.append(fuelTank)
|
---|
3926 |
|
---|
3927 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 1.0,
|
---|
3928 | xscale = 1.0, yscale = 0.0)
|
---|
3929 | alignment.add(fuelTank.label)
|
---|
3930 | self._fuelTable.attach(alignment,
|
---|
3931 | index*(1 if numTanks<5 else 2), 0,
|
---|
3932 | 1 if numTanks<5 else 3, 1)
|
---|
3933 |
|
---|
3934 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
3935 | xscale = 0.0, yscale = 1.0)
|
---|
3936 | alignment.add(fuelTank)
|
---|
3937 | self._fuelTable.attach(alignment,
|
---|
3938 | index*(1 if numTanks<5 else 2) +
|
---|
3939 | (0 if numTanks<5 else 1), 1, 1, 1)
|
---|
3940 |
|
---|
3941 |
|
---|
3942 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
3943 | xscale = 1.0, yscale = 0.0)
|
---|
3944 | alignment.add(fuelTank.expectedButton)
|
---|
3945 |
|
---|
3946 | self._fuelTable.attach(alignment,
|
---|
3947 | index* (1 if numTanks<5 else 2),
|
---|
3948 | 2 if (index%2)==0 or numTanks<5 else 3,
|
---|
3949 | 1 if numTanks<5 else 3, 1)
|
---|
3950 |
|
---|
3951 | index += 1
|
---|
3952 |
|
---|
3953 | self._fuelAlignment.add(self._fuelTable)
|
---|
3954 | self.show_all()
|
---|
3955 |
|
---|
3956 | def _pump(self):
|
---|
3957 | """Perform one step of pumping.
|
---|
3958 |
|
---|
3959 | It is checked, if the current tank's contents are of the right
|
---|
3960 | quantity. If not, it is filled one step further to the desired
|
---|
3961 | contents. Otherwise the next tank is started. If all tanks are are
|
---|
3962 | filled, the next page is selected."""
|
---|
3963 | numTanks = len(self._fuelTanks)
|
---|
3964 |
|
---|
3965 | fuelTank = None
|
---|
3966 | while self._pumpIndex < numTanks:
|
---|
3967 | fuelTank = self._fuelTanks[self._pumpIndex]
|
---|
3968 | if fuelTank.isCorrect():
|
---|
3969 | self._pumpIndex += 1
|
---|
3970 | fuelTank = None
|
---|
3971 | else:
|
---|
3972 | break
|
---|
3973 |
|
---|
3974 | if fuelTank is None:
|
---|
3975 | self._wizard.gui.endBusy()
|
---|
3976 | if self._wizard.usingSimBrief:
|
---|
3977 | self._wizard.gui.startMonitoring()
|
---|
3978 | self._wizard.jumpPage("takeoff")
|
---|
3979 | else:
|
---|
3980 | bookedFlight = self._wizard._bookedFlight
|
---|
3981 | self._wizard.gui.beginBusy(xstr("route_down_notams"))
|
---|
3982 | self._wizard.gui.webHandler.getNOTAMs(self._notamsCallback,
|
---|
3983 | bookedFlight.departureICAO,
|
---|
3984 | bookedFlight.arrivalICAO)
|
---|
3985 | startSound(const.SOUND_NOTAM)
|
---|
3986 | else:
|
---|
3987 | currentLevel = fuelTank.currentWeight / fuelTank.capacity
|
---|
3988 | expectedLevel = fuelTank.expectedWeight / fuelTank.capacity
|
---|
3989 | if currentLevel<expectedLevel:
|
---|
3990 | currentLevel += FuelPage._pumpStep
|
---|
3991 | if currentLevel>expectedLevel: currentLevel = expectedLevel
|
---|
3992 | else:
|
---|
3993 | currentLevel -= FuelPage._pumpStep
|
---|
3994 | if currentLevel<expectedLevel: currentLevel = expectedLevel
|
---|
3995 | fuelTank.setCurrent(currentLevel * fuelTank.capacity)
|
---|
3996 | self._wizard.gui.simulator.setFuelLevel([(fuelTank.fuelTank,
|
---|
3997 | currentLevel)])
|
---|
3998 | GObject.timeout_add(50, self._pump)
|
---|
3999 |
|
---|
4000 | def _notamsCallback(self, returned, result):
|
---|
4001 | """Callback for the NOTAMs."""
|
---|
4002 | GObject.idle_add(self._handleNOTAMs, returned, result)
|
---|
4003 |
|
---|
4004 | def _handleNOTAMs(self, returned, result):
|
---|
4005 | """Handle the NOTAMs."""
|
---|
4006 | if returned:
|
---|
4007 | self._wizard._departureNOTAMs = result.departureNOTAMs
|
---|
4008 | self._wizard._arrivalNOTAMs = result.arrivalNOTAMs
|
---|
4009 | else:
|
---|
4010 | self._wizard._departureNOTAMs = None
|
---|
4011 | self._wizard._arrivalNOTAMs = None
|
---|
4012 |
|
---|
4013 | bookedFlight = self._wizard._bookedFlight
|
---|
4014 | self._wizard.gui.beginBusy(xstr("route_down_metars"))
|
---|
4015 | self._wizard.gui.webHandler.getMETARs(self._metarsCallback,
|
---|
4016 | [bookedFlight.departureICAO,
|
---|
4017 | bookedFlight.arrivalICAO])
|
---|
4018 |
|
---|
4019 | def _metarsCallback(self, returned, result):
|
---|
4020 | """Callback for the METARs."""
|
---|
4021 | GObject.idle_add(self._handleMETARs, returned, result)
|
---|
4022 |
|
---|
4023 | def _handleMETARs(self, returned, result):
|
---|
4024 | """Handle the METARs."""
|
---|
4025 | self._wizard._departureMETAR = None
|
---|
4026 | self._wizard._arrivalMETAR = None
|
---|
4027 | bookedFlight = self._wizard._bookedFlight
|
---|
4028 | if returned:
|
---|
4029 | if bookedFlight.departureICAO in result.metars:
|
---|
4030 | self._wizard._departureMETAR = result.metars[bookedFlight.departureICAO]
|
---|
4031 | if bookedFlight.arrivalICAO in result.metars:
|
---|
4032 | self._wizard._arrivalMETAR = result.metars[bookedFlight.arrivalICAO]
|
---|
4033 |
|
---|
4034 | self._wizard.gui.endBusy()
|
---|
4035 | self._backButton.set_sensitive(True)
|
---|
4036 | self._button.set_sensitive(True)
|
---|
4037 | self._wizard.nextPage()
|
---|
4038 |
|
---|
4039 | #-----------------------------------------------------------------------------
|
---|
4040 |
|
---|
4041 | class BriefingPage(Page):
|
---|
4042 | """Page for the briefing."""
|
---|
4043 | def __init__(self, wizard, departure):
|
---|
4044 | """Construct the briefing page."""
|
---|
4045 | self._departure = departure
|
---|
4046 |
|
---|
4047 | number = 1 if departure else 2
|
---|
4048 |
|
---|
4049 | title = xstr("briefing_title") % (number,
|
---|
4050 | xstr("briefing_departure")
|
---|
4051 | if departure
|
---|
4052 | else xstr("briefing_arrival"))
|
---|
4053 | super(BriefingPage, self).__init__(wizard,
|
---|
4054 | "briefing%d" % (number,),
|
---|
4055 | title, xstr("briefing_help"),
|
---|
4056 | completedHelp = xstr("briefing_chelp"))
|
---|
4057 |
|
---|
4058 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
4059 | xscale = 1.0, yscale = 1.0)
|
---|
4060 |
|
---|
4061 | mainBox = Gtk.VBox()
|
---|
4062 | alignment.add(mainBox)
|
---|
4063 | self.setMainWidget(alignment)
|
---|
4064 |
|
---|
4065 | self._notamsFrame = Gtk.Frame()
|
---|
4066 | self._notamsFrame.set_label(xstr("briefing_notams_init"))
|
---|
4067 | scrolledWindow = Gtk.ScrolledWindow()
|
---|
4068 | scrolledWindow.set_size_request(-1, 128)
|
---|
4069 | # FIXME: these constants should be in common
|
---|
4070 | scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC,
|
---|
4071 | Gtk.PolicyType.AUTOMATIC)
|
---|
4072 | self._notams = Gtk.TextView()
|
---|
4073 | self._notams.set_editable(False)
|
---|
4074 | self._notams.set_accepts_tab(False)
|
---|
4075 | self._notams.set_wrap_mode(Gtk.WrapMode.WORD)
|
---|
4076 | scrolledWindow.add(self._notams)
|
---|
4077 | alignment = Gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
4078 | xscale = 1.0, yscale = 1.0)
|
---|
4079 | alignment.set_padding(padding_top = 4, padding_bottom = 0,
|
---|
4080 | padding_left = 0, padding_right = 0)
|
---|
4081 | alignment.add(scrolledWindow)
|
---|
4082 | self._notamsFrame.add(alignment)
|
---|
4083 | mainBox.pack_start(self._notamsFrame, True, True, 4)
|
---|
4084 |
|
---|
4085 | self._metarFrame = Gtk.Frame()
|
---|
4086 | self._metarFrame.set_label(xstr("briefing_metar_init"))
|
---|
4087 | scrolledWindow = Gtk.ScrolledWindow()
|
---|
4088 | scrolledWindow.set_size_request(-1, 32)
|
---|
4089 | scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC,
|
---|
4090 | Gtk.PolicyType.AUTOMATIC)
|
---|
4091 |
|
---|
4092 | self._updatingMETAR = False
|
---|
4093 |
|
---|
4094 | self._metar = Gtk.TextView()
|
---|
4095 | self._metar.set_accepts_tab(False)
|
---|
4096 | self._metar.set_wrap_mode(Gtk.WrapMode.WORD)
|
---|
4097 | self._metar.get_buffer().connect("changed", self._metarChanged)
|
---|
4098 | self._metar.get_buffer().connect_after("insert-text", self._metarInserted)
|
---|
4099 | scrolledWindow.add(self._metar)
|
---|
4100 | alignment = Gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
4101 | xscale = 1.0, yscale = 1.0)
|
---|
4102 | alignment.set_padding(padding_top = 4, padding_bottom = 0,
|
---|
4103 | padding_left = 0, padding_right = 0)
|
---|
4104 | alignment.add(scrolledWindow)
|
---|
4105 | self._metarFrame.add(alignment)
|
---|
4106 | mainBox.pack_start(self._metarFrame, True, True, 4)
|
---|
4107 | self.metarEdited = False
|
---|
4108 |
|
---|
4109 | self.addCancelFlightButton()
|
---|
4110 |
|
---|
4111 | self.addPreviousButton(clicked = self._backClicked)
|
---|
4112 | self._button = self.addNextButton(clicked = self._forwardClicked)
|
---|
4113 |
|
---|
4114 | @property
|
---|
4115 | def metar(self):
|
---|
4116 | """Get the METAR on the page."""
|
---|
4117 | buffer = self._metar.get_buffer()
|
---|
4118 | return buffer.get_text(buffer.get_start_iter(),
|
---|
4119 | buffer.get_end_iter(), True)
|
---|
4120 |
|
---|
4121 | def setMETAR(self, metar):
|
---|
4122 | """Set the METAR."""
|
---|
4123 | self._metar.get_buffer().set_text(metar)
|
---|
4124 | self.metarEdited = False
|
---|
4125 |
|
---|
4126 | def changeMETAR(self, metar):
|
---|
4127 | """Change the METAR as a result of an edit on one of the other
|
---|
4128 | pages."""
|
---|
4129 | self._updatingMETAR = True
|
---|
4130 | self._metar.get_buffer().set_text(metar)
|
---|
4131 | self._updatingMETAR = False
|
---|
4132 |
|
---|
4133 | self._updateButton()
|
---|
4134 | self.metarEdited = True
|
---|
4135 |
|
---|
4136 | def activate(self):
|
---|
4137 | """Activate the page."""
|
---|
4138 | if not self._departure:
|
---|
4139 | self._button.set_label(xstr("briefing_button"))
|
---|
4140 | self._button.set_has_tooltip(False)
|
---|
4141 | self._button.set_use_stock(False)
|
---|
4142 |
|
---|
4143 | bookedFlight = self._wizard._bookedFlight
|
---|
4144 |
|
---|
4145 | icao = bookedFlight.departureICAO if self._departure \
|
---|
4146 | else bookedFlight.arrivalICAO
|
---|
4147 | notams = self._wizard._departureNOTAMs if self._departure \
|
---|
4148 | else self._wizard._arrivalNOTAMs
|
---|
4149 | metar = self._wizard._departureMETAR if self._departure \
|
---|
4150 | else self._wizard._arrivalMETAR
|
---|
4151 |
|
---|
4152 | self._notamsFrame.set_label(xstr("briefing_notams_template") % (icao,))
|
---|
4153 | buffer = self._notams.get_buffer()
|
---|
4154 | if notams is None:
|
---|
4155 | buffer.set_text(xstr("briefing_notams_failed"))
|
---|
4156 | elif not notams:
|
---|
4157 | buffer.set_text(xstr("briefing_notams_missing"))
|
---|
4158 | else:
|
---|
4159 | s = ""
|
---|
4160 | for notam in notams:
|
---|
4161 | s += str(notam)
|
---|
4162 | s += "-------------------- * --------------------\n"
|
---|
4163 | buffer.set_text(s)
|
---|
4164 |
|
---|
4165 | self._metarFrame.set_label(xstr("briefing_metar_template") % (icao,))
|
---|
4166 | buffer = self._metar.get_buffer()
|
---|
4167 | self._updatingMETAR = True
|
---|
4168 | if metar is None:
|
---|
4169 | buffer.set_text("")
|
---|
4170 | self.setHelp(xstr("briefing_help_nometar"))
|
---|
4171 | else:
|
---|
4172 | buffer.set_text(metar)
|
---|
4173 | self._updatingMETAR = False
|
---|
4174 | self._updateButton()
|
---|
4175 |
|
---|
4176 | label = self._metarFrame.get_label_widget()
|
---|
4177 | label.set_use_underline(True)
|
---|
4178 | label.set_mnemonic_widget(self._metar)
|
---|
4179 |
|
---|
4180 | self.metarEdited = False
|
---|
4181 |
|
---|
4182 | def _backClicked(self, button):
|
---|
4183 | """Called when the Back button is pressed."""
|
---|
4184 | self.goBack()
|
---|
4185 |
|
---|
4186 | def _forwardClicked(self, button):
|
---|
4187 | """Called when the forward button is clicked."""
|
---|
4188 | if not self._departure:
|
---|
4189 | if not self._completed:
|
---|
4190 | self._wizard.gui.startMonitoring()
|
---|
4191 | self._button.set_label(xstr("button_next"))
|
---|
4192 | self._button.set_tooltip_text(xstr("button_next_tooltip"))
|
---|
4193 | self.complete()
|
---|
4194 |
|
---|
4195 | self._wizard.nextPage()
|
---|
4196 |
|
---|
4197 | def _metarChanged(self, buffer):
|
---|
4198 | """Called when the METAR has changed."""
|
---|
4199 | print("BriefingPage.metarChanged", self._updatingMETAR)
|
---|
4200 | if not self._updatingMETAR:
|
---|
4201 | self.metarEdited = True
|
---|
4202 | self._updateButton()
|
---|
4203 | metar = buffer.get_text(buffer.get_start_iter(),
|
---|
4204 | buffer.get_end_iter(), True)
|
---|
4205 | self._wizard.metarChanged(metar, self)
|
---|
4206 |
|
---|
4207 | def _metarInserted(self, textBuffer, iter, text, length):
|
---|
4208 | """Called when new characters are inserted into the METAR.
|
---|
4209 |
|
---|
4210 | It uppercases all characters."""
|
---|
4211 | print("BriefingPage.metarInserted", self._updatingMETAR)
|
---|
4212 | if not self._updatingMETAR:
|
---|
4213 | self._updatingMETAR = True
|
---|
4214 |
|
---|
4215 | iter1 = iter.copy()
|
---|
4216 | iter1.backward_chars(length)
|
---|
4217 | textBuffer.delete(iter, iter1)
|
---|
4218 |
|
---|
4219 | textBuffer.insert(iter, text.upper())
|
---|
4220 |
|
---|
4221 | self._updatingMETAR = False
|
---|
4222 |
|
---|
4223 | def _updateButton(self):
|
---|
4224 | """Update the sensitivity of the Next button based on the contents of
|
---|
4225 | the METAR field."""
|
---|
4226 | buffer = self._metar.get_buffer()
|
---|
4227 | self._button.set_sensitive(buffer.get_text(buffer.get_start_iter(),
|
---|
4228 | buffer.get_end_iter(),
|
---|
4229 | True)!="")
|
---|
4230 |
|
---|
4231 |
|
---|
4232 | #-----------------------------------------------------------------------------
|
---|
4233 |
|
---|
4234 | class TakeoffPage(Page):
|
---|
4235 | """Page for entering the takeoff data."""
|
---|
4236 | def __init__(self, wizard):
|
---|
4237 | """Construct the takeoff page."""
|
---|
4238 | super(TakeoffPage, self).__init__(wizard, "takeoff",
|
---|
4239 | xstr("takeoff_title"),
|
---|
4240 | xstr("takeoff_help"),
|
---|
4241 | completedHelp = xstr("takeoff_chelp"))
|
---|
4242 |
|
---|
4243 | self._forwardAllowed = False
|
---|
4244 |
|
---|
4245 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
4246 | xscale = 0.0, yscale = 0.0)
|
---|
4247 |
|
---|
4248 | table = Gtk.Table(9, 24)
|
---|
4249 | table.set_row_spacings(4)
|
---|
4250 | table.set_col_spacings(16)
|
---|
4251 | table.set_homogeneous(False)
|
---|
4252 | alignment.add(table)
|
---|
4253 | self.setMainWidget(alignment)
|
---|
4254 |
|
---|
4255 | row = 0
|
---|
4256 |
|
---|
4257 | label = Gtk.Label(xstr("takeoff_metar"))
|
---|
4258 | label.set_use_underline(True)
|
---|
4259 | label.set_alignment(0.0, 0.5)
|
---|
4260 | table.attach(label, 0, 1, row, row+1)
|
---|
4261 |
|
---|
4262 | self._metar = Gtk.Entry()
|
---|
4263 | self._metar.set_width_chars(40)
|
---|
4264 | self._metar.set_tooltip_text(xstr("takeoff_metar_tooltip"))
|
---|
4265 | self._metar.connect("changed", self._metarChanged)
|
---|
4266 | self._metar.get_buffer().connect_after("inserted-text", self._metarInserted)
|
---|
4267 | table.attach(self._metar, 1, 24, row, row+1)
|
---|
4268 | label.set_mnemonic_widget(self._metar)
|
---|
4269 |
|
---|
4270 | self._updatingMETAR = False
|
---|
4271 |
|
---|
4272 | row += 1
|
---|
4273 |
|
---|
4274 | label = Gtk.Label(xstr("takeoff_runway"))
|
---|
4275 | label.set_use_underline(True)
|
---|
4276 | label.set_alignment(0.0, 0.5)
|
---|
4277 | table.attach(label, 0, 1, row, row+1)
|
---|
4278 |
|
---|
4279 | self._runway = Gtk.Entry()
|
---|
4280 | self._runway.set_width_chars(10)
|
---|
4281 | self._runway.set_tooltip_text(xstr("takeoff_runway_tooltip"))
|
---|
4282 | self._runway.connect("changed", self._upperChanged)
|
---|
4283 | table.attach(self._runway, 1, 3, row, row+1)
|
---|
4284 | label.set_mnemonic_widget(self._runway)
|
---|
4285 |
|
---|
4286 | row += 1
|
---|
4287 |
|
---|
4288 | label = Gtk.Label(xstr("takeoff_sid"))
|
---|
4289 | label.set_use_underline(True)
|
---|
4290 | label.set_alignment(0.0, 0.5)
|
---|
4291 | table.attach(label, 0, 1, row, row+1)
|
---|
4292 |
|
---|
4293 | self._sid = Gtk.ComboBox.new_with_model_and_entry(comboModel)
|
---|
4294 |
|
---|
4295 | self._sid.set_entry_text_column(0)
|
---|
4296 | self._sid.get_child().set_width_chars(10)
|
---|
4297 | self._sid.set_tooltip_text(xstr("takeoff_sid_tooltip"))
|
---|
4298 | self._sid.connect("changed", self._upperChangedComboBox)
|
---|
4299 | table.attach(self._sid, 1, 3, row, row+1)
|
---|
4300 | label.set_mnemonic_widget(self._sid)
|
---|
4301 |
|
---|
4302 | row += 1
|
---|
4303 |
|
---|
4304 | label = Gtk.Label(xstr("takeoff_v1"))
|
---|
4305 | label.set_use_markup(True)
|
---|
4306 | label.set_use_underline(True)
|
---|
4307 | label.set_alignment(0.0, 0.5)
|
---|
4308 | table.attach(label, 0, 1, row, row+1)
|
---|
4309 |
|
---|
4310 | self._v1 = IntegerEntry()
|
---|
4311 | self._v1.set_width_chars(4)
|
---|
4312 | self._v1.set_tooltip_markup(xstr("takeoff_v1_tooltip_knots"))
|
---|
4313 | self._v1.connect("integer-changed", self._valueChanged)
|
---|
4314 | table.attach(self._v1, 2, 3, row, row+1)
|
---|
4315 | label.set_mnemonic_widget(self._v1)
|
---|
4316 |
|
---|
4317 | self._v1Unit = Gtk.Label(xstr("label_knots"))
|
---|
4318 | self._v1Unit.set_alignment(0.0, 0.5)
|
---|
4319 | table.attach(self._v1Unit, 3, 4, row, row+1)
|
---|
4320 |
|
---|
4321 | row += 1
|
---|
4322 |
|
---|
4323 | label = Gtk.Label(xstr("takeoff_vr"))
|
---|
4324 | label.set_use_markup(True)
|
---|
4325 | label.set_use_underline(True)
|
---|
4326 | label.set_alignment(0.0, 0.5)
|
---|
4327 | table.attach(label, 0, 1, row, row+1)
|
---|
4328 |
|
---|
4329 | self._vr = IntegerEntry()
|
---|
4330 | self._vr.set_width_chars(4)
|
---|
4331 | self._vr.set_tooltip_markup(xstr("takeoff_vr_tooltip_knots"))
|
---|
4332 | self._vr.connect("integer-changed", self._valueChanged)
|
---|
4333 | table.attach(self._vr, 2, 3, row, row+1)
|
---|
4334 | label.set_mnemonic_widget(self._vr)
|
---|
4335 |
|
---|
4336 | self._vrUnit = Gtk.Label(xstr("label_knots"))
|
---|
4337 | self._vrUnit.set_alignment(0.0, 0.5)
|
---|
4338 | table.attach(self._vrUnit, 3, 4, row, row+1)
|
---|
4339 |
|
---|
4340 | row += 1
|
---|
4341 |
|
---|
4342 | label = Gtk.Label(xstr("takeoff_v2"))
|
---|
4343 | label.set_use_markup(True)
|
---|
4344 | label.set_use_underline(True)
|
---|
4345 | label.set_alignment(0.0, 0.5)
|
---|
4346 | table.attach(label, 0, 1, row, row+1)
|
---|
4347 |
|
---|
4348 | self._v2 = IntegerEntry()
|
---|
4349 | self._v2.set_width_chars(4)
|
---|
4350 | self._v2.set_tooltip_markup(xstr("takeoff_v2_tooltip_knots"))
|
---|
4351 | self._v2.connect("integer-changed", self._valueChanged)
|
---|
4352 | table.attach(self._v2, 2, 3, row, row+1)
|
---|
4353 | label.set_mnemonic_widget(self._v2)
|
---|
4354 |
|
---|
4355 | self._v2Unit = Gtk.Label(xstr("label_knots"))
|
---|
4356 | self._v2Unit.set_alignment(0.0, 0.5)
|
---|
4357 | table.attach(self._v2Unit, 3, 4, row, row+1)
|
---|
4358 |
|
---|
4359 | row += 1
|
---|
4360 |
|
---|
4361 | self._derateType = acft.DERATE_NONE
|
---|
4362 |
|
---|
4363 | self._derateLabel = Gtk.Label()
|
---|
4364 | self._derateLabel.set_use_underline(True)
|
---|
4365 | self._derateLabel.set_markup(xstr("takeoff_derate_tupolev"))
|
---|
4366 | self._derateLabel.set_alignment(0.0, 0.5)
|
---|
4367 | table.attach(self._derateLabel, 0, 1, row, row+1)
|
---|
4368 |
|
---|
4369 | self._derate = Gtk.Alignment()
|
---|
4370 | table.attach(self._derate, 2, 4, row, row+1)
|
---|
4371 | self._derateWidget = None
|
---|
4372 | self._derateEntry = None
|
---|
4373 | self._derateUnit = None
|
---|
4374 | self._derateButtons = None
|
---|
4375 |
|
---|
4376 | row += 1
|
---|
4377 |
|
---|
4378 | self._antiIceOn = Gtk.CheckButton(xstr("takeoff_antiice"))
|
---|
4379 | self._antiIceOn.set_use_underline(True)
|
---|
4380 | self._antiIceOn.set_tooltip_text(xstr("takeoff_antiice_tooltip"))
|
---|
4381 | table.attach(self._antiIceOn, 2, 4, row, row+1)
|
---|
4382 |
|
---|
4383 | row += 1
|
---|
4384 |
|
---|
4385 | self._rto = Gtk.CheckButton(xstr("takeoff_rto"))
|
---|
4386 | self._rto.set_use_underline(True)
|
---|
4387 | self._rto.set_tooltip_text(xstr("takeoff_rto_tooltip"))
|
---|
4388 | self._rto.connect("toggled", self._rtoToggled)
|
---|
4389 | table.attach(self._rto, 2, 4, row, row+1, ypadding = 8)
|
---|
4390 |
|
---|
4391 | self.addCancelFlightButton()
|
---|
4392 |
|
---|
4393 | self.addPreviousButton(clicked = self._backClicked)
|
---|
4394 |
|
---|
4395 | self._button = self.addNextButton(clicked = self._forwardClicked)
|
---|
4396 |
|
---|
4397 | self._active = False
|
---|
4398 |
|
---|
4399 | @property
|
---|
4400 | def runway(self):
|
---|
4401 | """Get the runway."""
|
---|
4402 | return self._runway.get_text()
|
---|
4403 |
|
---|
4404 | @property
|
---|
4405 | def sid(self):
|
---|
4406 | """Get the SID."""
|
---|
4407 | text = self._sid.get_child().get_text()
|
---|
4408 | return text if self._sid.get_active()!=0 and text and text!="N/A" \
|
---|
4409 | else None
|
---|
4410 |
|
---|
4411 | @property
|
---|
4412 | def v1(self):
|
---|
4413 | """Get the v1 speed."""
|
---|
4414 | return self._v1.get_int()
|
---|
4415 |
|
---|
4416 | @property
|
---|
4417 | def vr(self):
|
---|
4418 | """Get the vr speed."""
|
---|
4419 | return self._vr.get_int()
|
---|
4420 |
|
---|
4421 | @property
|
---|
4422 | def v2(self):
|
---|
4423 | """Get the v2 speed."""
|
---|
4424 | return self._v2.get_int()
|
---|
4425 |
|
---|
4426 | @property
|
---|
4427 | def derate(self):
|
---|
4428 | """Get the derate value, if any."""
|
---|
4429 | if self._derateWidget is None:
|
---|
4430 | return None
|
---|
4431 | if self._derateType==acft.DERATE_BOEING:
|
---|
4432 | derate = self._derateEntry.get_text()
|
---|
4433 | return derate if derate else None
|
---|
4434 | elif self._derateType==acft.DERATE_EPR:
|
---|
4435 | derate = self._derateWidget.get_text()
|
---|
4436 | return derate if derate else None
|
---|
4437 | elif self._derateType==acft.DERATE_TUPOLEV:
|
---|
4438 | return acft.DERATE_TUPOLEV_NOMINAL \
|
---|
4439 | if self._derateButtons[0].get_active() \
|
---|
4440 | else acft.DERATE_TUPOLEV_TAKEOFF
|
---|
4441 | elif self._derateType==acft.DERATE_B462:
|
---|
4442 | return self._derateWidget.get_active()
|
---|
4443 | else:
|
---|
4444 | return None
|
---|
4445 |
|
---|
4446 | @property
|
---|
4447 | def antiIceOn(self):
|
---|
4448 | """Get whether the anti-ice system has been turned on."""
|
---|
4449 | return self._antiIceOn.get_active()
|
---|
4450 |
|
---|
4451 | @antiIceOn.setter
|
---|
4452 | def antiIceOn(self, value):
|
---|
4453 | """Set the anti-ice indicator."""
|
---|
4454 | self._antiIceOn.set_active(value)
|
---|
4455 |
|
---|
4456 | @property
|
---|
4457 | def rtoIndicated(self):
|
---|
4458 | """Get whether the pilot has indicated if there was an RTO."""
|
---|
4459 | return self._rto.get_active()
|
---|
4460 |
|
---|
4461 | def activate(self):
|
---|
4462 | """Activate the page."""
|
---|
4463 | print("TakeoffPage.activate")
|
---|
4464 |
|
---|
4465 | self._updatingMETAR = True
|
---|
4466 | self._metar.get_buffer().set_text(self._wizard.departureMETAR, -1)
|
---|
4467 | self._updatingMETAR = False
|
---|
4468 |
|
---|
4469 | if self._wizard.takeoffRunway is None:
|
---|
4470 | self._runway.set_text("")
|
---|
4471 | else:
|
---|
4472 | self._runway.set_text(self._wizard.takeoffRunway)
|
---|
4473 | self._runway.set_sensitive(True)
|
---|
4474 | self._sid.set_active(0)
|
---|
4475 | self._sid.set_sensitive(True)
|
---|
4476 | self._v1.set_int(None)
|
---|
4477 | self._v1.set_sensitive(True)
|
---|
4478 | self._vr.set_int(None)
|
---|
4479 | self._vr.set_sensitive(True)
|
---|
4480 | self._v2.set_int(None)
|
---|
4481 | self._v2.set_sensitive(True)
|
---|
4482 |
|
---|
4483 | i18nSpeedUnit = self._wizard.gui.flight.getI18NSpeedUnit()
|
---|
4484 | speedUnit = xstr("label" + i18nSpeedUnit)
|
---|
4485 | self._v1Unit.set_text(speedUnit)
|
---|
4486 | self._vrUnit.set_text(speedUnit)
|
---|
4487 | self._v2Unit.set_text(speedUnit)
|
---|
4488 |
|
---|
4489 | self._v1.set_tooltip_markup(xstr("takeoff_v1_tooltip" + i18nSpeedUnit))
|
---|
4490 | self._vr.set_tooltip_markup(xstr("takeoff_vr_tooltip" + i18nSpeedUnit))
|
---|
4491 | self._v2.set_tooltip_markup(xstr("takeoff_v2_tooltip" + i18nSpeedUnit))
|
---|
4492 |
|
---|
4493 | self._derateType = self._wizard.gui.flight.aircraft.derateType
|
---|
4494 |
|
---|
4495 | self._setupDerateWidget()
|
---|
4496 |
|
---|
4497 | self._rto.set_active(False)
|
---|
4498 | self._rto.set_sensitive(False)
|
---|
4499 |
|
---|
4500 | self._button.set_sensitive(False)
|
---|
4501 | self._forwardAllowed = False
|
---|
4502 |
|
---|
4503 | self._active = True
|
---|
4504 |
|
---|
4505 | def allowForward(self):
|
---|
4506 | """Allow going to the next page."""
|
---|
4507 | print("TakeoffPage.allowForward")
|
---|
4508 | self._forwardAllowed = True
|
---|
4509 | self._updateForwardButton()
|
---|
4510 |
|
---|
4511 | def reset(self):
|
---|
4512 | """Reset the page if the wizard is reset."""
|
---|
4513 | print("TakeoffPage.reset")
|
---|
4514 |
|
---|
4515 | super(TakeoffPage, self).reset()
|
---|
4516 | self._v1.reset()
|
---|
4517 | self._vr.reset()
|
---|
4518 | self._v2.reset()
|
---|
4519 | self._hasDerate = False
|
---|
4520 | self._antiIceOn.set_active(False)
|
---|
4521 | self._active = False
|
---|
4522 |
|
---|
4523 | def setRTOEnabled(self, enabled):
|
---|
4524 | """Set the RTO checkbox enabled or disabled."""
|
---|
4525 | if not enabled:
|
---|
4526 | self._rto.set_active(False)
|
---|
4527 | self._rto.set_sensitive(enabled)
|
---|
4528 |
|
---|
4529 | def changeMETAR(self, metar):
|
---|
4530 | """Change the METAR as a result of an edit on one of the other
|
---|
4531 | pages."""
|
---|
4532 | if self._active:
|
---|
4533 | print("TakeoffPage.changeMETAR")
|
---|
4534 | self._updatingMETAR = True
|
---|
4535 | self._metar.get_buffer().set_text(metar, -1)
|
---|
4536 | self._updatingMETAR = False
|
---|
4537 |
|
---|
4538 | self._updateForwardButton()
|
---|
4539 |
|
---|
4540 | def _updateForwardButton(self):
|
---|
4541 | """Update the sensitivity of the forward button based on some conditions."""
|
---|
4542 | sensitive = self._forwardAllowed and \
|
---|
4543 | self._metar.get_text()!="" and \
|
---|
4544 | self._runway.get_text()!="" and \
|
---|
4545 | self.sid is not None and \
|
---|
4546 | self.v1 is not None and \
|
---|
4547 | self.vr is not None and \
|
---|
4548 | self.v2 is not None and \
|
---|
4549 | self.v1 <= self.vr and \
|
---|
4550 | self.vr <= self.v2 and \
|
---|
4551 | (self._derateType==acft.DERATE_NONE or
|
---|
4552 | self.derate is not None)
|
---|
4553 |
|
---|
4554 | print("TakeoffPage._updateForwardButton: forwardAllowed:", self._forwardAllowed, ", sensitive:", sensitive)
|
---|
4555 | if self._forwardAllowed:
|
---|
4556 | print(" METAR: ", self._metar.get_text())
|
---|
4557 | print(" runway: ", self._runway.get_text())
|
---|
4558 | print(" SID:", self.sid)
|
---|
4559 | print(" V1:", self.v1)
|
---|
4560 | print(" VR:", self.vr)
|
---|
4561 | print(" V2:", self.v2)
|
---|
4562 | print(" derateType:", self._derateType)
|
---|
4563 | print(" derate:", self.derate)
|
---|
4564 |
|
---|
4565 | self._button.set_sensitive(sensitive)
|
---|
4566 |
|
---|
4567 | def _valueChanged(self, widget, arg = None):
|
---|
4568 | """Called when the value of some widget has changed."""
|
---|
4569 | print("TakeoffPage._valueChanged")
|
---|
4570 |
|
---|
4571 | self._updateForwardButton()
|
---|
4572 |
|
---|
4573 | def _upperChanged(self, entry, arg = None):
|
---|
4574 | """Called when the value of some entry widget has changed and the value
|
---|
4575 | should be converted to uppercase."""
|
---|
4576 | print("TakeoffPage._upperChanged")
|
---|
4577 | entry.set_text(entry.get_text().upper())
|
---|
4578 | self._valueChanged(entry, arg)
|
---|
4579 |
|
---|
4580 | def _upperChangedComboBox(self, comboBox):
|
---|
4581 | """Called for combo box widgets that must be converted to uppercase."""
|
---|
4582 | entry = comboBox.get_child()
|
---|
4583 | if comboBox.get_active()==-1:
|
---|
4584 | entry.set_text(entry.get_text().upper())
|
---|
4585 | self._valueChanged(entry)
|
---|
4586 |
|
---|
4587 | def _derateChanged(self, entry):
|
---|
4588 | """Called when the value of the derate is changed."""
|
---|
4589 | print("TakeoffPage._derateChanged")
|
---|
4590 | self._updateForwardButton()
|
---|
4591 |
|
---|
4592 | def _rtoToggled(self, button):
|
---|
4593 | """Called when the RTO check button is toggled."""
|
---|
4594 | self._wizard.rtoToggled(button.get_active())
|
---|
4595 |
|
---|
4596 | def _backClicked(self, button):
|
---|
4597 | """Called when the Back button is pressed."""
|
---|
4598 | self.goBack()
|
---|
4599 |
|
---|
4600 | def _forwardClicked(self, button):
|
---|
4601 | """Called when the forward button is clicked."""
|
---|
4602 | aircraft = self._wizard.gui.flight.aircraft
|
---|
4603 | aircraft.updateV1R2()
|
---|
4604 | if self.derate is not None:
|
---|
4605 | aircraft.updateDerate()
|
---|
4606 | aircraft.updateTakeoffAntiIce()
|
---|
4607 | self._wizard.nextPage()
|
---|
4608 |
|
---|
4609 | def _setupDerateWidget(self):
|
---|
4610 | """Setup the derate widget."""
|
---|
4611 | if self._derateWidget is not None:
|
---|
4612 | self._derate.remove(self._derateWidget)
|
---|
4613 |
|
---|
4614 | if self._derateType==acft.DERATE_BOEING:
|
---|
4615 | self._derateLabel.set_text(xstr("takeoff_derate_boeing"))
|
---|
4616 | self._derateLabel.set_use_underline(True)
|
---|
4617 | self._derateLabel.set_sensitive(True)
|
---|
4618 |
|
---|
4619 | self._derateEntry = Gtk.Entry()
|
---|
4620 | self._derateEntry.set_width_chars(7)
|
---|
4621 | self._derateEntry.set_tooltip_text(xstr("takeoff_derate_boeing_tooltip"))
|
---|
4622 | self._derateEntry.set_alignment(1.0)
|
---|
4623 | self._derateEntry.connect("changed", self._derateChanged)
|
---|
4624 | self._derateLabel.set_mnemonic_widget(self._derateEntry)
|
---|
4625 |
|
---|
4626 | self._derateUnit = Gtk.Label("%")
|
---|
4627 | self._derateUnit.set_alignment(0.0, 0.5)
|
---|
4628 |
|
---|
4629 | self._derateWidget = Gtk.Table(3, 1)
|
---|
4630 | self._derateWidget.set_row_spacings(4)
|
---|
4631 | self._derateWidget.set_col_spacings(16)
|
---|
4632 | self._derateWidget.set_homogeneous(False)
|
---|
4633 |
|
---|
4634 | self._derateWidget.attach(self._derateEntry, 0, 2, 0, 1)
|
---|
4635 | self._derateWidget.attach(self._derateUnit, 2, 3, 0, 1)
|
---|
4636 |
|
---|
4637 | self._derate.add(self._derateWidget)
|
---|
4638 | elif self._derateType==acft.DERATE_EPR:
|
---|
4639 | self._derateLabel.set_text("_EPR:")
|
---|
4640 | self._derateLabel.set_use_underline(True)
|
---|
4641 | self._derateLabel.set_sensitive(True)
|
---|
4642 |
|
---|
4643 | self._derateWidget = Gtk.Entry()
|
---|
4644 | self._derateWidget.set_width_chars(7)
|
---|
4645 | self._derateWidget.set_tooltip_text(xstr("takeoff_derate_epr_tooltip"))
|
---|
4646 | self._derateWidget.set_alignment(1.0)
|
---|
4647 | self._derateWidget.connect("changed", self._derateChanged)
|
---|
4648 | self._derateLabel.set_mnemonic_widget(self._derateWidget)
|
---|
4649 |
|
---|
4650 | self._derate.add(self._derateWidget)
|
---|
4651 | elif self._derateType==acft.DERATE_TUPOLEV:
|
---|
4652 | self._derateLabel.set_text(xstr("takeoff_derate_tupolev"))
|
---|
4653 | self._derateLabel.set_use_underline(True)
|
---|
4654 | self._derateLabel.set_sensitive(True)
|
---|
4655 |
|
---|
4656 | nominal = Gtk.RadioButton.\
|
---|
4657 | new_with_label_from_widget(None,
|
---|
4658 | xstr("takeoff_derate_tupolev_nominal"))
|
---|
4659 | nominal.set_use_underline(True)
|
---|
4660 | nominal.set_tooltip_text(xstr("takeoff_derate_tupolev_nominal_tooltip"))
|
---|
4661 | nominal.connect("toggled", self._derateChanged)
|
---|
4662 |
|
---|
4663 | takeoff = Gtk.RadioButton.\
|
---|
4664 | new_with_label_from_widget(nominal,
|
---|
4665 | xstr("takeoff_derate_tupolev_takeoff"))
|
---|
4666 |
|
---|
4667 | takeoff.set_use_underline(True)
|
---|
4668 | takeoff.set_tooltip_text(xstr("takeoff_derate_tupolev_takeoff_tooltip"))
|
---|
4669 | takeoff.connect("toggled", self._derateChanged)
|
---|
4670 |
|
---|
4671 | self._derateButtons = [nominal, takeoff]
|
---|
4672 |
|
---|
4673 | self._derateWidget = Gtk.HBox()
|
---|
4674 | self._derateWidget.pack_start(nominal, False, False, 4)
|
---|
4675 | self._derateWidget.pack_start(takeoff, False, False, 4)
|
---|
4676 |
|
---|
4677 | self._derate.add(self._derateWidget)
|
---|
4678 | elif self._derateType==acft.DERATE_B462:
|
---|
4679 | self._derateLabel.set_text("")
|
---|
4680 |
|
---|
4681 | self._derateWidget = Gtk.CheckButton(xstr("takeoff_derate_b462"))
|
---|
4682 | self._derateWidget.set_tooltip_text(xstr("takeoff_derate_b462_tooltip"))
|
---|
4683 | self._derateWidget.set_use_underline(True)
|
---|
4684 | self._derate.add(self._derateWidget)
|
---|
4685 | else:
|
---|
4686 | self._derateWidget = None
|
---|
4687 | self._derateLabel.set_text("")
|
---|
4688 | self._derateLabel.set_sensitive(False)
|
---|
4689 |
|
---|
4690 | def _metarChanged(self, entry):
|
---|
4691 | """Called when the METAR has changed."""
|
---|
4692 | print("TakeoffPage.metarChanged", self._updatingMETAR)
|
---|
4693 | if not self._updatingMETAR:
|
---|
4694 | self._updateForwardButton()
|
---|
4695 | self._wizard.metarChanged(entry.get_text(), self)
|
---|
4696 |
|
---|
4697 | def _metarInserted(self, buffer, position, text, length):
|
---|
4698 | """Called when new characters are inserted into the METAR.
|
---|
4699 |
|
---|
4700 | It uppercases all characters."""
|
---|
4701 | print("TakeoffPage.metarInserted", self._updatingMETAR)
|
---|
4702 | if not self._updatingMETAR:
|
---|
4703 | self._updatingMETAR = True
|
---|
4704 |
|
---|
4705 | buffer.delete_text(position, length)
|
---|
4706 | buffer.insert_text(position, text.upper(), length)
|
---|
4707 |
|
---|
4708 | self._updatingMETAR = False
|
---|
4709 |
|
---|
4710 | #-----------------------------------------------------------------------------
|
---|
4711 |
|
---|
4712 | class CruisePage(Page):
|
---|
4713 | """The page containing the flight level that might change during flight."""
|
---|
4714 | def __init__(self, wizard):
|
---|
4715 | """Construct the page."""
|
---|
4716 | super(CruisePage, self).__init__(wizard, "cruise",
|
---|
4717 | xstr("cruise_title"),
|
---|
4718 | xstr("cruise_help"))
|
---|
4719 |
|
---|
4720 | self._loggable = False
|
---|
4721 | self._loggedCruiseLevel = 240
|
---|
4722 | self._activated = False
|
---|
4723 |
|
---|
4724 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.0,
|
---|
4725 | xscale = 0.0, yscale = 1.0)
|
---|
4726 |
|
---|
4727 | mainBox = Gtk.VBox()
|
---|
4728 | alignment.add(mainBox)
|
---|
4729 | self.setMainWidget(alignment)
|
---|
4730 |
|
---|
4731 | alignment = Gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
4732 | xscale = 0.0, yscale = 0.0)
|
---|
4733 | mainBox.pack_start(alignment, False, False, 16)
|
---|
4734 |
|
---|
4735 | levelBox = Gtk.HBox()
|
---|
4736 |
|
---|
4737 | label = Gtk.Label(xstr("route_level"))
|
---|
4738 | label.set_use_underline(True)
|
---|
4739 | levelBox.pack_start(label, True, True, 0)
|
---|
4740 |
|
---|
4741 | self._cruiseLevel = Gtk.SpinButton()
|
---|
4742 | self._cruiseLevel.set_increments(step = 10, page = 100)
|
---|
4743 | self._cruiseLevel.set_range(min = 50, max = 500)
|
---|
4744 | self._cruiseLevel.set_tooltip_text(xstr("cruise_route_level_tooltip"))
|
---|
4745 | self._cruiseLevel.set_numeric(True)
|
---|
4746 | self._cruiseLevel.connect("value-changed", self._cruiseLevelChanged)
|
---|
4747 | label.set_mnemonic_widget(self._cruiseLevel)
|
---|
4748 |
|
---|
4749 | levelBox.pack_start(self._cruiseLevel, False, False, 8)
|
---|
4750 |
|
---|
4751 | self._updateButton = Gtk.Button(xstr("cruise_route_level_update"));
|
---|
4752 | self._updateButton.set_use_underline(True)
|
---|
4753 | self._updateButton.set_tooltip_text(xstr("cruise_route_level_update_tooltip"))
|
---|
4754 | self._updateButton.connect("clicked", self._updateButtonClicked)
|
---|
4755 |
|
---|
4756 | levelBox.pack_start(self._updateButton, False, False, 16)
|
---|
4757 |
|
---|
4758 | mainBox.pack_start(levelBox, False, False, 0)
|
---|
4759 |
|
---|
4760 | alignment = Gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
4761 | xscale = 0.0, yscale = 1.0)
|
---|
4762 | mainBox.pack_start(alignment, True, True, 0)
|
---|
4763 |
|
---|
4764 | self.addCancelFlightButton()
|
---|
4765 |
|
---|
4766 | self._backButton = self.addPreviousButton(clicked = self._backClicked)
|
---|
4767 | self._button = self.addNextButton(clicked = self._forwardClicked)
|
---|
4768 |
|
---|
4769 | @property
|
---|
4770 | def activated(self):
|
---|
4771 | """Determine if the page is already activated or not."""
|
---|
4772 | return self._activated
|
---|
4773 |
|
---|
4774 | @property
|
---|
4775 | def cruiseLevel(self):
|
---|
4776 | """Get the cruise level."""
|
---|
4777 | return self._loggedCruiseLevel
|
---|
4778 |
|
---|
4779 | @property
|
---|
4780 | def loggableCruiseLevel(self):
|
---|
4781 | """Get the cruise level which should be logged."""
|
---|
4782 | return self._cruiseLevel.get_value_as_int()
|
---|
4783 |
|
---|
4784 | def setLoggable(self, loggable):
|
---|
4785 | """Set whether the cruise altitude can be logged."""
|
---|
4786 | self._loggable = loggable
|
---|
4787 | self._updateButtons()
|
---|
4788 |
|
---|
4789 | def activate(self):
|
---|
4790 | """Setup the route from the booked flight."""
|
---|
4791 | self._loggedCruiseLevel = self._wizard.filedCruiseLevel
|
---|
4792 | self._cruiseLevel.set_value(self._loggedCruiseLevel)
|
---|
4793 | self._activated = True
|
---|
4794 |
|
---|
4795 | def reset(self):
|
---|
4796 | """Reset the page."""
|
---|
4797 | self._loggable = False
|
---|
4798 | self._activated = False
|
---|
4799 | super(CruisePage, self).reset()
|
---|
4800 |
|
---|
4801 | def _updateButtons(self):
|
---|
4802 | """Update the sensitivity of the buttons."""
|
---|
4803 | self._updateButton.set_sensitive(self._loggable and
|
---|
4804 | self.loggableCruiseLevel!=
|
---|
4805 | self._loggedCruiseLevel)
|
---|
4806 |
|
---|
4807 | def _cruiseLevelChanged(self, spinButton):
|
---|
4808 | """Called when the cruise level has changed."""
|
---|
4809 | self._updateButtons()
|
---|
4810 |
|
---|
4811 | def _updateButtonClicked(self, button):
|
---|
4812 | """Called when the update button is clicked."""
|
---|
4813 | if self._wizard.cruiseLevelChanged():
|
---|
4814 | self._loggedCruiseLevel = self.loggableCruiseLevel
|
---|
4815 | self._updateButtons()
|
---|
4816 |
|
---|
4817 | def _backClicked(self, button):
|
---|
4818 | """Called when the Back button is pressed."""
|
---|
4819 | self.goBack()
|
---|
4820 |
|
---|
4821 | def _forwardClicked(self, button):
|
---|
4822 | """Called when the Forward button is clicked."""
|
---|
4823 | self._wizard.nextPage()
|
---|
4824 |
|
---|
4825 | #-----------------------------------------------------------------------------
|
---|
4826 |
|
---|
4827 | class LandingPage(Page):
|
---|
4828 | """Page for entering landing data."""
|
---|
4829 | def __init__(self, wizard):
|
---|
4830 | """Construct the landing page."""
|
---|
4831 | super(LandingPage, self).__init__(wizard, "landing",
|
---|
4832 | xstr("landing_title"),
|
---|
4833 | xstr("landing_help"),
|
---|
4834 | completedHelp = xstr("landing_chelp"))
|
---|
4835 |
|
---|
4836 | self._flightEnded = False
|
---|
4837 |
|
---|
4838 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
4839 | xscale = 0.0, yscale = 0.0)
|
---|
4840 |
|
---|
4841 | table = Gtk.Table(7, 24)
|
---|
4842 | table.set_row_spacings(4)
|
---|
4843 | table.set_col_spacings(16)
|
---|
4844 | table.set_homogeneous(False)
|
---|
4845 | alignment.add(table)
|
---|
4846 | self.setMainWidget(alignment)
|
---|
4847 |
|
---|
4848 | row = 0
|
---|
4849 |
|
---|
4850 | label = Gtk.Label(xstr("landing_metar"))
|
---|
4851 | label.set_use_underline(True)
|
---|
4852 | label.set_alignment(0.0, 0.5)
|
---|
4853 | table.attach(label, 1, 2, row, row+1)
|
---|
4854 |
|
---|
4855 | self._metar = Gtk.Entry()
|
---|
4856 | self._metar.set_width_chars(40)
|
---|
4857 | self._metar.set_tooltip_text(xstr("landing_metar_tooltip"))
|
---|
4858 | self._metar.connect("changed", self._metarChanged)
|
---|
4859 | self._metar.get_buffer().connect_after("inserted-text", self._metarInserted)
|
---|
4860 | table.attach(self._metar, 2, 24, row, row+1)
|
---|
4861 | label.set_mnemonic_widget(self._metar)
|
---|
4862 |
|
---|
4863 | self._updatingMETAR = False
|
---|
4864 |
|
---|
4865 | row += 1
|
---|
4866 |
|
---|
4867 | label = Gtk.Label(xstr("landing_star"))
|
---|
4868 | label.set_use_underline(True)
|
---|
4869 | label.set_alignment(0.0, 0.5)
|
---|
4870 | table.attach(label, 1, 2, row, row + 1)
|
---|
4871 |
|
---|
4872 | self._star = Gtk.ComboBox.new_with_model_and_entry(comboModel)
|
---|
4873 |
|
---|
4874 | self._star.set_entry_text_column(0)
|
---|
4875 | self._star.get_child().set_width_chars(10)
|
---|
4876 | self._star.set_tooltip_text(xstr("landing_star_tooltip"))
|
---|
4877 | self._star.connect("changed", self._upperChangedComboBox)
|
---|
4878 | self._star.set_sensitive(False)
|
---|
4879 | table.attach(self._star, 2, 4, row, row + 1)
|
---|
4880 | label.set_mnemonic_widget(self._star)
|
---|
4881 |
|
---|
4882 | row += 1
|
---|
4883 |
|
---|
4884 | label = Gtk.Label(xstr("landing_transition"))
|
---|
4885 | label.set_use_underline(True)
|
---|
4886 | label.set_alignment(0.0, 0.5)
|
---|
4887 | table.attach(label, 1, 2, row, row + 1)
|
---|
4888 |
|
---|
4889 | self._transition = Gtk.ComboBox.new_with_model_and_entry(comboModel)
|
---|
4890 |
|
---|
4891 | self._transition.set_entry_text_column(0)
|
---|
4892 | self._transition.get_child().set_width_chars(10)
|
---|
4893 | self._transition.set_tooltip_text(xstr("landing_transition_tooltip"))
|
---|
4894 | self._transition.connect("changed", self._upperChangedComboBox)
|
---|
4895 | self._transition.set_sensitive(False)
|
---|
4896 | table.attach(self._transition, 2, 4, row, row + 1)
|
---|
4897 | label.set_mnemonic_widget(self._transition)
|
---|
4898 |
|
---|
4899 | row += 1
|
---|
4900 |
|
---|
4901 | label = Gtk.Label(xstr("landing_runway"))
|
---|
4902 | label.set_use_underline(True)
|
---|
4903 | label.set_alignment(0.0, 0.5)
|
---|
4904 | table.attach(label, 1, 2, row, row + 1)
|
---|
4905 |
|
---|
4906 | self._runway = Gtk.Entry()
|
---|
4907 | self._runway.set_width_chars(10)
|
---|
4908 | self._runway.set_tooltip_text(xstr("landing_runway_tooltip"))
|
---|
4909 | self._runway.connect("changed", self._upperChanged)
|
---|
4910 | table.attach(self._runway, 2, 4, row, row + 1)
|
---|
4911 | label.set_mnemonic_widget(self._runway)
|
---|
4912 |
|
---|
4913 | row += 1
|
---|
4914 |
|
---|
4915 | label = Gtk.Label(xstr("landing_approach"))
|
---|
4916 | label.set_use_underline(True)
|
---|
4917 | label.set_alignment(0.0, 0.5)
|
---|
4918 | table.attach(label, 1, 2, row, row + 1)
|
---|
4919 |
|
---|
4920 | self._approachType = Gtk.Entry()
|
---|
4921 | self._approachType.set_width_chars(10)
|
---|
4922 | self._approachType.set_tooltip_text(xstr("landing_approach_tooltip"))
|
---|
4923 | self._approachType.connect("changed", self._upperChanged)
|
---|
4924 | table.attach(self._approachType, 2, 4, row, row + 1)
|
---|
4925 | label.set_mnemonic_widget(self._approachType)
|
---|
4926 |
|
---|
4927 | row += 1
|
---|
4928 |
|
---|
4929 | label = Gtk.Label(xstr("landing_vref"))
|
---|
4930 | label.set_use_markup(True)
|
---|
4931 | label.set_use_underline(True)
|
---|
4932 | label.set_alignment(0.0, 0.5)
|
---|
4933 | table.attach(label, 1, 2, row, row + 1)
|
---|
4934 |
|
---|
4935 | self._vref = IntegerEntry()
|
---|
4936 | self._vref.set_width_chars(5)
|
---|
4937 | self._vref.set_tooltip_markup(xstr("landing_vref_tooltip_knots"))
|
---|
4938 | self._vref.connect("integer-changed", self._vrefChanged)
|
---|
4939 | table.attach(self._vref, 3, 4, row, row + 1)
|
---|
4940 | label.set_mnemonic_widget(self._vref)
|
---|
4941 |
|
---|
4942 | self._vrefUnit = Gtk.Label(xstr("label_knots"))
|
---|
4943 | table.attach(self._vrefUnit, 4, 5, row, row + 1)
|
---|
4944 |
|
---|
4945 | row += 1
|
---|
4946 |
|
---|
4947 | self._antiIceOn = Gtk.CheckButton(xstr("landing_antiice"))
|
---|
4948 | self._antiIceOn.set_use_underline(True)
|
---|
4949 | self._antiIceOn.set_tooltip_text(xstr("landing_antiice_tooltip"))
|
---|
4950 | table.attach(self._antiIceOn, 3, 5, row, row + 1)
|
---|
4951 |
|
---|
4952 | self.addCancelFlightButton()
|
---|
4953 |
|
---|
4954 | self.addPreviousButton(clicked = self._backClicked)
|
---|
4955 |
|
---|
4956 | self._button = self.addNextButton(clicked = self._forwardClicked)
|
---|
4957 |
|
---|
4958 | self._active = False
|
---|
4959 |
|
---|
4960 | @property
|
---|
4961 | def star(self):
|
---|
4962 | """Get the STAR or None if none entered."""
|
---|
4963 | text = self._star.get_child().get_text()
|
---|
4964 | return text if self._star.get_active()!=0 and text and text!="N/A" \
|
---|
4965 | else None
|
---|
4966 |
|
---|
4967 | @property
|
---|
4968 | def transition(self):
|
---|
4969 | """Get the transition or None if none entered."""
|
---|
4970 | text = self._transition.get_child().get_text()
|
---|
4971 | return text if self._transition.get_active()!=0 and text and text!="N/A" \
|
---|
4972 | else None
|
---|
4973 |
|
---|
4974 | @property
|
---|
4975 | def approachType(self):
|
---|
4976 | """Get the approach type."""
|
---|
4977 | return self._approachType.get_text()
|
---|
4978 |
|
---|
4979 | @property
|
---|
4980 | def runway(self):
|
---|
4981 | """Get the runway."""
|
---|
4982 | return self._runway.get_text()
|
---|
4983 |
|
---|
4984 | @property
|
---|
4985 | def vref(self):
|
---|
4986 | """Return the landing reference speed."""
|
---|
4987 | return self._vref.get_int()
|
---|
4988 |
|
---|
4989 | @property
|
---|
4990 | def antiIceOn(self):
|
---|
4991 | """Get whether the anti-ice system has been turned on."""
|
---|
4992 | return self._antiIceOn.get_active()
|
---|
4993 |
|
---|
4994 | @antiIceOn.setter
|
---|
4995 | def antiIceOn(self, value):
|
---|
4996 | """Set the anti-ice indicator."""
|
---|
4997 | self._antiIceOn.set_active(value)
|
---|
4998 |
|
---|
4999 | def reset(self):
|
---|
5000 | """Reset the page if the wizard is reset."""
|
---|
5001 | super(LandingPage, self).reset()
|
---|
5002 | self._vref.reset()
|
---|
5003 | self._antiIceOn.set_active(False)
|
---|
5004 | self._flightEnded = False
|
---|
5005 | self._active = False
|
---|
5006 |
|
---|
5007 | def activate(self):
|
---|
5008 | """Called when the page is activated."""
|
---|
5009 | self._updatingMETAR = True
|
---|
5010 | self._metar.get_buffer().set_text(self._wizard.arrivalMETAR, -1)
|
---|
5011 | self._updatingMETAR = False
|
---|
5012 |
|
---|
5013 | self._star.set_active(0)
|
---|
5014 | self._star.set_sensitive(True)
|
---|
5015 |
|
---|
5016 | self._transition.set_active(0)
|
---|
5017 | self._transition.set_sensitive(True)
|
---|
5018 |
|
---|
5019 | if self._wizard.landingRunway is None:
|
---|
5020 | self._runway.set_text("")
|
---|
5021 | else:
|
---|
5022 | self._runway.set_text(self._wizard.landingRunway)
|
---|
5023 | self._runway.set_sensitive(True)
|
---|
5024 |
|
---|
5025 | self._approachType.set_text("")
|
---|
5026 | self._approachType.set_sensitive(True)
|
---|
5027 |
|
---|
5028 | self._vref.set_int(None)
|
---|
5029 | self._vref.set_sensitive(True)
|
---|
5030 |
|
---|
5031 | i18nSpeedUnit = self._wizard.gui.flight.getI18NSpeedUnit()
|
---|
5032 | speedUnit = xstr("label" + i18nSpeedUnit)
|
---|
5033 | self._vrefUnit.set_text(speedUnit)
|
---|
5034 |
|
---|
5035 | self._vref.set_tooltip_markup(xstr("landing_vref_tooltip" +
|
---|
5036 | i18nSpeedUnit))
|
---|
5037 |
|
---|
5038 | self._updateForwardButton()
|
---|
5039 |
|
---|
5040 | self._active = True
|
---|
5041 |
|
---|
5042 | def flightEnded(self):
|
---|
5043 | """Called when the flight has ended."""
|
---|
5044 | super(LandingPage, self).flightEnded()
|
---|
5045 | self._flightEnded = True
|
---|
5046 | self._updateForwardButton()
|
---|
5047 |
|
---|
5048 | def changeMETAR(self, metar):
|
---|
5049 | """Change the METAR as a result of an edit on one of the other
|
---|
5050 | pages."""
|
---|
5051 | if self._active:
|
---|
5052 | print("LandingPage.changeMETAR")
|
---|
5053 | self._updatingMETAR = True
|
---|
5054 | self._metar.get_buffer().set_text(metar, -1)
|
---|
5055 | self._updatingMETAR = False
|
---|
5056 |
|
---|
5057 | self._updateForwardButton()
|
---|
5058 |
|
---|
5059 | def _updateForwardButton(self):
|
---|
5060 | """Update the sensitivity of the forward button."""
|
---|
5061 | sensitive = self._flightEnded and \
|
---|
5062 | self._metar.get_text()!="" and \
|
---|
5063 | (self.star is not None or
|
---|
5064 | self.transition is not None) and \
|
---|
5065 | self._runway.get_text()!="" and \
|
---|
5066 | self._approachType.get_text()!="" and \
|
---|
5067 | self.vref is not None
|
---|
5068 | self._button.set_sensitive(sensitive)
|
---|
5069 |
|
---|
5070 | def _upperChanged(self, entry):
|
---|
5071 | """Called for entry widgets that must be converted to uppercase."""
|
---|
5072 | entry.set_text(entry.get_text().upper())
|
---|
5073 | self._updateForwardButton()
|
---|
5074 |
|
---|
5075 | def _upperChangedComboBox(self, comboBox):
|
---|
5076 | """Called for combo box widgets that must be converted to uppercase."""
|
---|
5077 | if comboBox.get_active()==-1:
|
---|
5078 | entry = comboBox.get_child()
|
---|
5079 | entry.set_text(entry.get_text().upper())
|
---|
5080 | self._updateForwardButton()
|
---|
5081 |
|
---|
5082 | def _vrefChanged(self, widget, value):
|
---|
5083 | """Called when the Vref has changed."""
|
---|
5084 | self._updateForwardButton()
|
---|
5085 |
|
---|
5086 | def _backClicked(self, button):
|
---|
5087 | """Called when the Back button is pressed."""
|
---|
5088 | self.goBack()
|
---|
5089 |
|
---|
5090 | def _forwardClicked(self, button):
|
---|
5091 | """Called when the forward button is clicked."""
|
---|
5092 | wizard = self._wizard
|
---|
5093 |
|
---|
5094 | aircraft = wizard.gui.flight.aircraft
|
---|
5095 | aircraft.updateVRef()
|
---|
5096 | aircraft.updateLandingAntiIce()
|
---|
5097 | if wizard.gui.config.onlineGateSystem and \
|
---|
5098 | wizard.loggedIn and not self._completed and \
|
---|
5099 | wizard.bookedFlight.arrivalICAO=="LHBP" and \
|
---|
5100 | not wizard.entranceExam:
|
---|
5101 | wizard.getFleet(callback = self._fleetRetrieved, force = True)
|
---|
5102 | elif wizard.entranceExam:
|
---|
5103 | self._handleEntranceExamDone()
|
---|
5104 | else:
|
---|
5105 | wizard.nextPage()
|
---|
5106 |
|
---|
5107 | def _fleetRetrieved(self, fleet):
|
---|
5108 | """Callback for the fleet retrieval."""
|
---|
5109 | self._wizard.nextPage()
|
---|
5110 |
|
---|
5111 | def _metarChanged(self, entry):
|
---|
5112 | """Called when the METAR has changed."""
|
---|
5113 | print("LandingPage.metarChanged", self._updatingMETAR)
|
---|
5114 | if not self._updatingMETAR:
|
---|
5115 | self._updateForwardButton()
|
---|
5116 | self._wizard.metarChanged(entry.get_text(), self)
|
---|
5117 |
|
---|
5118 | def _metarInserted(self, buffer, position, text, length):
|
---|
5119 | """Called when new characters are inserted into the METAR.
|
---|
5120 |
|
---|
5121 | It uppercases all characters."""
|
---|
5122 | print("LandingPage.metarInserted", self._updatingMETAR)
|
---|
5123 | if not self._updatingMETAR:
|
---|
5124 | self._updatingMETAR = True
|
---|
5125 |
|
---|
5126 | buffer.delete_text(position, length)
|
---|
5127 | buffer.insert_text(position, text.upper(), length)
|
---|
5128 |
|
---|
5129 | self._updatingMETAR = False
|
---|
5130 |
|
---|
5131 | def _handleEntranceExamDone(self):
|
---|
5132 | """Handle the end of the entrance exam.
|
---|
5133 |
|
---|
5134 | If the there was a NO-GO fault, notify the user that exam is a failure
|
---|
5135 | and take them back to the student page. Otherwise congratulate, update
|
---|
5136 | the database to reflect that the exam has been taken and go back to the
|
---|
5137 | student page."""
|
---|
5138 | self._wizard.jumpPage("chkfinish")
|
---|
5139 |
|
---|
5140 | #-----------------------------------------------------------------------------
|
---|
5141 |
|
---|
5142 | class PIREPSaveHelper(object):
|
---|
5143 | """A helper to use for saving PIREPs."""
|
---|
5144 | def __init__(self, wizard):
|
---|
5145 | """Construct the helper."""
|
---|
5146 | super(PIREPSaveHelper, self).__init__()
|
---|
5147 |
|
---|
5148 | self._wizard = wizard
|
---|
5149 |
|
---|
5150 | self._lastSavePath = None
|
---|
5151 | self._savePIREPDialog = None
|
---|
5152 |
|
---|
5153 | def addButton(self, page):
|
---|
5154 | """Add a button to save the PIREP to the given page."""
|
---|
5155 | return page.addButton(xstr("finish_save"), sensitive = False,
|
---|
5156 | clicked = self._saveClicked,
|
---|
5157 | tooltip = xstr("finish_save_tooltip"),
|
---|
5158 | clickedArg = page)
|
---|
5159 |
|
---|
5160 | def autoSavePIREP(self, page):
|
---|
5161 | """Perform the automatic saving of the PIREP."""
|
---|
5162 | self._lastSavePath = os.path.join(self._wizard.gui.config.pirepDirectory,
|
---|
5163 | self._getDefaultPIREPName())
|
---|
5164 | self._lastSavePath = self._lastSavePath
|
---|
5165 | self._savePIREP(page, automatic = True)
|
---|
5166 |
|
---|
5167 | def _getDefaultPIREPName(self):
|
---|
5168 | """Get the default name of the PIREP."""
|
---|
5169 | gui = self._wizard.gui
|
---|
5170 |
|
---|
5171 | bookedFlight = gui.bookedFlight
|
---|
5172 | tm = time.gmtime()
|
---|
5173 |
|
---|
5174 | pilotID = self._wizard.pilotID
|
---|
5175 | if pilotID: pilotID += " "
|
---|
5176 | return "%s%s %02d%02d %s-%s.pirep" % \
|
---|
5177 | (pilotID, str(bookedFlight.departureTime.date()),
|
---|
5178 | tm.tm_hour, tm.tm_min,
|
---|
5179 | bookedFlight.departureICAO, bookedFlight.arrivalICAO)
|
---|
5180 |
|
---|
5181 | def _saveClicked(self, button, page):
|
---|
5182 | """Called when the Save PIREP button is clicked."""
|
---|
5183 | gui = self._wizard.gui
|
---|
5184 |
|
---|
5185 | fileName = self._getDefaultPIREPName()
|
---|
5186 |
|
---|
5187 | dialog = self._getSaveDialog()
|
---|
5188 |
|
---|
5189 | if self._lastSavePath is None:
|
---|
5190 | pirepDirectory = gui.config.pirepDirectory
|
---|
5191 | if pirepDirectory is not None:
|
---|
5192 | dialog.set_current_folder(pirepDirectory)
|
---|
5193 | else:
|
---|
5194 | dialog.set_current_folder(os.path.dirname(self._lastSavePath))
|
---|
5195 |
|
---|
5196 | dialog.set_current_name(fileName)
|
---|
5197 | result = dialog.run()
|
---|
5198 | dialog.hide()
|
---|
5199 |
|
---|
5200 | if result==Gtk.ResponseType.OK:
|
---|
5201 | self._lastSavePath = dialog.get_filename()
|
---|
5202 | self._savePIREP(page)
|
---|
5203 |
|
---|
5204 | def _savePIREP(self, page, automatic = False):
|
---|
5205 | """Perform the saving of the PIREP."""
|
---|
5206 |
|
---|
5207 | gui = self._wizard.gui
|
---|
5208 |
|
---|
5209 | if automatic:
|
---|
5210 | gui.beginBusy(xstr("finish_autosave_busy"))
|
---|
5211 |
|
---|
5212 | pirep = PIREP(gui.flight)
|
---|
5213 | error = pirep.save(self._lastSavePath)
|
---|
5214 |
|
---|
5215 | if automatic:
|
---|
5216 | gui.endBusy()
|
---|
5217 |
|
---|
5218 | if error:
|
---|
5219 | type = Gtk.MessageType.ERROR
|
---|
5220 | message = xstr("finish_save_failed")
|
---|
5221 | secondary = xstr("finish_save_failed_sec") % (error,)
|
---|
5222 | else:
|
---|
5223 | type = Gtk.MessageType.INFO
|
---|
5224 | message = xstr("finish_save_done")
|
---|
5225 | if automatic:
|
---|
5226 | secondary = xstr("finish_save_done_sec") % (self._lastSavePath,)
|
---|
5227 | else:
|
---|
5228 | secondary = None
|
---|
5229 | page.setPIREPSaved()
|
---|
5230 |
|
---|
5231 | dialog = Gtk.MessageDialog(parent = gui.mainWindow,
|
---|
5232 | type = type, message_format = message)
|
---|
5233 | dialog.add_button(xstr("button_ok"), Gtk.ResponseType.OK)
|
---|
5234 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
5235 | if secondary is not None:
|
---|
5236 | dialog.format_secondary_markup(secondary)
|
---|
5237 |
|
---|
5238 | dialog.run()
|
---|
5239 | dialog.hide()
|
---|
5240 |
|
---|
5241 | def _getSaveDialog(self):
|
---|
5242 | """Get the PIREP saving dialog.
|
---|
5243 |
|
---|
5244 | If it does not exist yet, create it."""
|
---|
5245 | if self._savePIREPDialog is None:
|
---|
5246 | gui = self._wizard.gui
|
---|
5247 | dialog = Gtk.FileChooserDialog(title = WINDOW_TITLE_BASE + " - " +
|
---|
5248 | xstr("finish_save_title"),
|
---|
5249 | action = Gtk.FileChooserAction.SAVE,
|
---|
5250 | buttons = (Gtk.STOCK_CANCEL,
|
---|
5251 | Gtk.ResponseType.CANCEL,
|
---|
5252 | Gtk.STOCK_OK, Gtk.ResponseType.OK),
|
---|
5253 | parent = gui.mainWindow)
|
---|
5254 | dialog.set_modal(True)
|
---|
5255 | dialog.set_do_overwrite_confirmation(True)
|
---|
5256 |
|
---|
5257 | filter = Gtk.FileFilter()
|
---|
5258 | filter.set_name(xstr("file_filter_pireps"))
|
---|
5259 | filter.add_pattern("*.pirep")
|
---|
5260 | dialog.add_filter(filter)
|
---|
5261 |
|
---|
5262 | filter = Gtk.FileFilter()
|
---|
5263 | filter.set_name(xstr("file_filter_all"))
|
---|
5264 | filter.add_pattern("*.*")
|
---|
5265 | dialog.add_filter(filter)
|
---|
5266 |
|
---|
5267 | self._savePIREPDialog = dialog
|
---|
5268 |
|
---|
5269 | return self._savePIREPDialog
|
---|
5270 |
|
---|
5271 | #-----------------------------------------------------------------------------
|
---|
5272 |
|
---|
5273 | class FinishPage(Page):
|
---|
5274 | """Flight finish page."""
|
---|
5275 | def __init__(self, wizard, saveHelper):
|
---|
5276 | """Construct the finish page."""
|
---|
5277 | help = xstr("finish_help") + xstr("finish_help_goodtime")
|
---|
5278 | super(FinishPage, self).__init__(wizard, "finish",
|
---|
5279 | xstr("finish_title"), help)
|
---|
5280 |
|
---|
5281 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
5282 | xscale = 0.0, yscale = 0.0)
|
---|
5283 |
|
---|
5284 | table = Gtk.Table(10, 2)
|
---|
5285 | table.set_row_spacings(4)
|
---|
5286 | table.set_col_spacings(16)
|
---|
5287 | table.set_homogeneous(False)
|
---|
5288 | alignment.add(table)
|
---|
5289 | self.setMainWidget(alignment)
|
---|
5290 |
|
---|
5291 | row = 0
|
---|
5292 |
|
---|
5293 | labelAlignment = Gtk.Alignment(xalign=1.0, xscale=0.0)
|
---|
5294 | label = Gtk.Label(xstr("finish_rating"))
|
---|
5295 | labelAlignment.add(label)
|
---|
5296 | table.attach(labelAlignment, 0, 1, row, row+1)
|
---|
5297 |
|
---|
5298 | labelAlignment = Gtk.Alignment(xalign=0.0, xscale=0.0)
|
---|
5299 | self._flightRating = Gtk.Label()
|
---|
5300 | self._flightRating.set_width_chars(8)
|
---|
5301 | self._flightRating.set_alignment(0.0, 0.5)
|
---|
5302 | self._flightRating.set_use_markup(True)
|
---|
5303 | labelAlignment.add(self._flightRating)
|
---|
5304 | table.attach(labelAlignment, 1, 2, row, row+1)
|
---|
5305 |
|
---|
5306 | row += 1
|
---|
5307 |
|
---|
5308 | labelAlignment = Gtk.Alignment(xalign=1.0, xscale=0.0)
|
---|
5309 | label = Gtk.Label(xstr("finish_dep_time"))
|
---|
5310 | labelAlignment.add(label)
|
---|
5311 | table.attach(labelAlignment, 0, 1, row, row+1)
|
---|
5312 |
|
---|
5313 | labelAlignment = Gtk.Alignment(xalign=0.0, xscale=0.0)
|
---|
5314 | self._depTime = Gtk.Label()
|
---|
5315 | self._depTime.set_width_chars(13)
|
---|
5316 | self._depTime.set_alignment(0.0, 0.5)
|
---|
5317 | self._depTime.set_use_markup(True)
|
---|
5318 | self._depTime.set_tooltip_markup(xstr("finish_dep_time_tooltip"))
|
---|
5319 | labelAlignment.add(self._depTime)
|
---|
5320 | table.attach(labelAlignment, 1, 2, row, row+1)
|
---|
5321 |
|
---|
5322 | row += 1
|
---|
5323 |
|
---|
5324 | labelAlignment = Gtk.Alignment(xalign=1.0, xscale=0.0)
|
---|
5325 | label = Gtk.Label(xstr("finish_flight_time"))
|
---|
5326 | labelAlignment.add(label)
|
---|
5327 | table.attach(labelAlignment, 0, 1, row, row+1)
|
---|
5328 |
|
---|
5329 | labelAlignment = Gtk.Alignment(xalign=0.0, xscale=0.0)
|
---|
5330 | self._flightTime = Gtk.Label()
|
---|
5331 | self._flightTime.set_width_chars(10)
|
---|
5332 | self._flightTime.set_alignment(0.0, 0.5)
|
---|
5333 | self._flightTime.set_use_markup(True)
|
---|
5334 | labelAlignment.add(self._flightTime)
|
---|
5335 | table.attach(labelAlignment, 1, 2, row, row+1)
|
---|
5336 |
|
---|
5337 | row += 1
|
---|
5338 |
|
---|
5339 | labelAlignment = Gtk.Alignment(xalign=1.0, xscale=0.0)
|
---|
5340 | label = Gtk.Label(xstr("finish_block_time"))
|
---|
5341 | labelAlignment.add(label)
|
---|
5342 | table.attach(labelAlignment, 0, 1, row, row+1)
|
---|
5343 |
|
---|
5344 | labelAlignment = Gtk.Alignment(xalign=0.0, xscale=0.0)
|
---|
5345 | self._blockTime = Gtk.Label()
|
---|
5346 | self._blockTime.set_width_chars(10)
|
---|
5347 | self._blockTime.set_alignment(0.0, 0.5)
|
---|
5348 | self._blockTime.set_use_markup(True)
|
---|
5349 | labelAlignment.add(self._blockTime)
|
---|
5350 | table.attach(labelAlignment, 1, 2, row, row+1)
|
---|
5351 |
|
---|
5352 | row += 1
|
---|
5353 |
|
---|
5354 | labelAlignment = Gtk.Alignment(xalign=1.0, xscale=0.0)
|
---|
5355 | label = Gtk.Label(xstr("finish_arr_time"))
|
---|
5356 | labelAlignment.add(label)
|
---|
5357 | table.attach(labelAlignment, 0, 1, row, row+1)
|
---|
5358 |
|
---|
5359 | labelAlignment = Gtk.Alignment(xalign=0.0, xscale=0.0)
|
---|
5360 | self._arrTime = Gtk.Label()
|
---|
5361 | self._arrTime.set_width_chars(13)
|
---|
5362 | self._arrTime.set_alignment(0.0, 0.5)
|
---|
5363 | self._arrTime.set_use_markup(True)
|
---|
5364 | self._arrTime.set_tooltip_markup(xstr("finish_arr_time_tooltip"))
|
---|
5365 | labelAlignment.add(self._arrTime)
|
---|
5366 | table.attach(labelAlignment, 1, 2, row, row+1)
|
---|
5367 |
|
---|
5368 | row += 1
|
---|
5369 |
|
---|
5370 | labelAlignment = Gtk.Alignment(xalign=1.0, xscale=0.0)
|
---|
5371 | label = Gtk.Label(xstr("finish_distance"))
|
---|
5372 | labelAlignment.add(label)
|
---|
5373 | table.attach(labelAlignment, 0, 1, row, row+1)
|
---|
5374 |
|
---|
5375 | labelAlignment = Gtk.Alignment(xalign=0.0, xscale=0.0)
|
---|
5376 | self._distanceFlown = Gtk.Label()
|
---|
5377 | self._distanceFlown.set_width_chars(10)
|
---|
5378 | self._distanceFlown.set_alignment(0.0, 0.5)
|
---|
5379 | self._distanceFlown.set_use_markup(True)
|
---|
5380 | labelAlignment.add(self._distanceFlown)
|
---|
5381 | table.attach(labelAlignment, 1, 2, row, row+1)
|
---|
5382 |
|
---|
5383 | row += 1
|
---|
5384 |
|
---|
5385 | labelAlignment = Gtk.Alignment(xalign=1.0, xscale=0.0)
|
---|
5386 | label = Gtk.Label(xstr("finish_fuel"))
|
---|
5387 | labelAlignment.add(label)
|
---|
5388 | table.attach(labelAlignment, 0, 1, row, row+1)
|
---|
5389 |
|
---|
5390 | labelAlignment = Gtk.Alignment(xalign=0.0, xscale=0.0)
|
---|
5391 | self._fuelUsed = Gtk.Label()
|
---|
5392 | self._fuelUsed.set_width_chars(10)
|
---|
5393 | self._fuelUsed.set_alignment(0.0, 0.5)
|
---|
5394 | self._fuelUsed.set_use_markup(True)
|
---|
5395 | labelAlignment.add(self._fuelUsed)
|
---|
5396 | table.attach(labelAlignment, 1, 2, row, row+1)
|
---|
5397 |
|
---|
5398 | row += 1
|
---|
5399 |
|
---|
5400 | labelAlignment = Gtk.Alignment(xalign = 1.0, xscale = 0.0,
|
---|
5401 | yalign = 0.5, yscale = 0.0)
|
---|
5402 | label = Gtk.Label(xstr("finish_type"))
|
---|
5403 | label.set_use_underline(True)
|
---|
5404 | labelAlignment.add(label)
|
---|
5405 | table.attach(labelAlignment, 0, 1, row, row+1)
|
---|
5406 |
|
---|
5407 | self._onlineFlight = Gtk.CheckButton(xstr("finish_online"))
|
---|
5408 | self._onlineFlight.set_use_underline(True)
|
---|
5409 | self._onlineFlight.set_tooltip_text(xstr("finish_online_tooltip"))
|
---|
5410 | onlineFlightAlignment = Gtk.Alignment(xalign=0.0, xscale=0.0)
|
---|
5411 | onlineFlightAlignment.add(self._onlineFlight)
|
---|
5412 | table.attach(onlineFlightAlignment, 1, 2, row, row + 1)
|
---|
5413 |
|
---|
5414 | row += 1
|
---|
5415 |
|
---|
5416 | labelAlignment = Gtk.Alignment(xalign = 1.0, xscale = 0.0,
|
---|
5417 | yalign = 0.5, yscale = 0.0)
|
---|
5418 | self._gateLabel = Gtk.Label(xstr("finish_gate"))
|
---|
5419 | self._gateLabel.set_use_underline(True)
|
---|
5420 | labelAlignment.add(self._gateLabel)
|
---|
5421 | table.attach(labelAlignment, 0, 1, row, row+1)
|
---|
5422 |
|
---|
5423 | self._gatesModel = Gtk.ListStore(str)
|
---|
5424 |
|
---|
5425 | self._gate = Gtk.ComboBox(model = self._gatesModel)
|
---|
5426 | renderer = Gtk.CellRendererText()
|
---|
5427 | self._gate.pack_start(renderer, True)
|
---|
5428 | self._gate.add_attribute(renderer, "text", 0)
|
---|
5429 | self._gate.set_tooltip_text(xstr("finish_gate_tooltip"))
|
---|
5430 | self._gate.connect("changed", self._gateChanged)
|
---|
5431 | gateAlignment = Gtk.Alignment(xalign=0.0, xscale=1.0)
|
---|
5432 | gateAlignment.add(self._gate)
|
---|
5433 | table.attach(gateAlignment, 1, 2, row, row+1)
|
---|
5434 | self._gateLabel.set_mnemonic_widget(self._gate)
|
---|
5435 |
|
---|
5436 | self.addButton(xstr("finish_newFlight"),
|
---|
5437 | sensitive = True,
|
---|
5438 | clicked = self._newFlightClicked,
|
---|
5439 | tooltip = xstr("finish_newFlight_tooltip"),
|
---|
5440 | padding = 16)
|
---|
5441 |
|
---|
5442 | self.addPreviousButton(clicked = self._backClicked)
|
---|
5443 |
|
---|
5444 | self._saveHelper = saveHelper
|
---|
5445 | self._saveButton = saveHelper.addButton(self)
|
---|
5446 |
|
---|
5447 | self._tooBigTimeDifference = False
|
---|
5448 | self._deferredAutoSave = False
|
---|
5449 | self._pirepSaved = False
|
---|
5450 | self._pirepSent = False
|
---|
5451 |
|
---|
5452 | self._sendButton = self.addButton(xstr("sendPIREP"), default = True,
|
---|
5453 | sensitive = False,
|
---|
5454 | clicked = self._sendClicked,
|
---|
5455 | tooltip = xstr("sendPIREP_tooltip"))
|
---|
5456 |
|
---|
5457 | # self._formatTime(datetime.datetime(1970, 1, 1, 0, 10), 10*60.0)
|
---|
5458 | # self._formatTime(datetime.datetime(1970, 1, 1, 0, 10), 20*60.0)
|
---|
5459 | # self._formatTime(datetime.datetime(1970, 1, 1, 0, 10), 0*60.0)
|
---|
5460 | # self._formatTime(datetime.datetime(1970, 1, 1, 0, 10), (23*60.0+50)*60.0)
|
---|
5461 | # self._formatTime(datetime.datetime(1970, 1, 1, 1, 0), (1*60.0+5)*60.0)
|
---|
5462 | # self._formatTime(datetime.datetime(1970, 1, 1, 1, 0), (0*60.0+50)*60.0)
|
---|
5463 | # self._formatTime(datetime.datetime(1970, 1, 1, 23, 55), (0*60.0+5)*60.0)
|
---|
5464 | # self._formatTime(datetime.datetime(1970, 1, 1, 23, 55), (23*60.0+45)*60.0)
|
---|
5465 |
|
---|
5466 | @property
|
---|
5467 | def online(self):
|
---|
5468 | """Get whether the flight was an online flight or not."""
|
---|
5469 | return self._onlineFlight.get_active()
|
---|
5470 |
|
---|
5471 | def activate(self):
|
---|
5472 | """Activate the page."""
|
---|
5473 | self._deferredAutoSave = False
|
---|
5474 | self._pirepSaved = False
|
---|
5475 | self._pirepSent = False
|
---|
5476 |
|
---|
5477 | flight = self._wizard.gui._flight
|
---|
5478 | rating = flight.logger.getRating()
|
---|
5479 | if rating<0:
|
---|
5480 | self._flightRating.set_markup('<b><span foreground="red">NO GO</span></b>')
|
---|
5481 | else:
|
---|
5482 | self._flightRating.set_markup("<b>%.1f %%</b>" % (rating,))
|
---|
5483 |
|
---|
5484 | flightLength = flight.flightTimeEnd - flight.flightTimeStart
|
---|
5485 | self._flightTime.set_markup("<b>%s</b>" % \
|
---|
5486 | (util.getTimeIntervalString(flightLength),))
|
---|
5487 |
|
---|
5488 | blockLength = flight.blockTimeEnd - flight.blockTimeStart
|
---|
5489 | self._blockTime.set_markup("<b>%s</b>" % \
|
---|
5490 | (util.getTimeIntervalString(blockLength),))
|
---|
5491 |
|
---|
5492 | self._distanceFlown.set_markup("<b>%.2f NM</b>" % \
|
---|
5493 | (flight.flownDistance,))
|
---|
5494 |
|
---|
5495 | self._fuelUsed.set_markup("<b>%.0f kg</b>" % \
|
---|
5496 | (flight.startFuel - flight.endFuel,))
|
---|
5497 |
|
---|
5498 | self._onlineFlight.set_active(self._wizard.loggedIn)
|
---|
5499 |
|
---|
5500 | self._gatesModel.clear()
|
---|
5501 | if self._wizard.gui.config.onlineGateSystem and \
|
---|
5502 | self._wizard.loggedIn and \
|
---|
5503 | self._wizard.bookedFlight.arrivalICAO=="LHBP" and \
|
---|
5504 | not self._wizard.entranceExam:
|
---|
5505 | occupiedGateNumbers = self._wizard._fleet.getOccupiedGateNumbers()
|
---|
5506 | for gate in lhbpGates.gates:
|
---|
5507 | if gate.isAvailable(lhbpGates, occupiedGateNumbers):
|
---|
5508 | self._gatesModel.append([gate.number])
|
---|
5509 | self._gateLabel.set_sensitive(True)
|
---|
5510 | self._gate.set_sensitive(True)
|
---|
5511 | self._gate.set_active(-1)
|
---|
5512 | else:
|
---|
5513 | self._gateLabel.set_sensitive(False)
|
---|
5514 | self._gate.set_sensitive(False)
|
---|
5515 |
|
---|
5516 | self._updateTimes()
|
---|
5517 |
|
---|
5518 | def updateButtons(self):
|
---|
5519 | """Update the sensitivity state of the buttons."""
|
---|
5520 | gui = self._wizard.gui
|
---|
5521 | faultsExplained = gui.faultsFullyExplained
|
---|
5522 | timesCorrect = not self._tooBigTimeDifference or \
|
---|
5523 | gui.hasComments or gui.hasDelayCode
|
---|
5524 | sensitive = gui.flight is not None and \
|
---|
5525 | gui.flight.stage==const.STAGE_END and \
|
---|
5526 | (self._gatesModel.get_iter_first() is None or
|
---|
5527 | self._gate.get_active()>=0) and \
|
---|
5528 | faultsExplained and timesCorrect
|
---|
5529 |
|
---|
5530 | self._updateHelp(faultsExplained, timesCorrect)
|
---|
5531 |
|
---|
5532 | wasSensitive = self._saveButton.get_sensitive()
|
---|
5533 |
|
---|
5534 | if gui.config.pirepAutoSave and sensitive and not wasSensitive:
|
---|
5535 | if gui.isWizardActive():
|
---|
5536 | self._saveHelper.autoSavePIREP(self)
|
---|
5537 | else:
|
---|
5538 | self._deferredAutoSave = True
|
---|
5539 |
|
---|
5540 | if not sensitive:
|
---|
5541 | self._deferredAutoSave = False
|
---|
5542 |
|
---|
5543 | self._saveButton.set_sensitive(sensitive)
|
---|
5544 | self._sendButton.set_sensitive(sensitive and
|
---|
5545 | self._wizard.bookedFlight.id is not None)
|
---|
5546 |
|
---|
5547 | def grabDefault(self):
|
---|
5548 | """If the page has a default button, make it the default one."""
|
---|
5549 | super(FinishPage, self).grabDefault()
|
---|
5550 | if self._deferredAutoSave:
|
---|
5551 | self._saveHelper.autoSavePIREP(self)
|
---|
5552 | self._deferredAutoSave = False
|
---|
5553 |
|
---|
5554 | def setPIREPSaved(self):
|
---|
5555 | """Mark the PIREP as saved."""
|
---|
5556 | self._pirepSaved = True
|
---|
5557 |
|
---|
5558 | def _backClicked(self, button):
|
---|
5559 | """Called when the Back button is pressed."""
|
---|
5560 | self.goBack()
|
---|
5561 |
|
---|
5562 | def _gateChanged(self, comboBox):
|
---|
5563 | """Called when the arrival gate has changed."""
|
---|
5564 | self.updateButtons()
|
---|
5565 |
|
---|
5566 | def _newFlightClicked(self, button):
|
---|
5567 | """Called when the new flight button is clicked."""
|
---|
5568 | gui = self._wizard.gui
|
---|
5569 | if not self._pirepSent and not self._pirepSaved:
|
---|
5570 | dialog = Gtk.MessageDialog(parent = gui.mainWindow,
|
---|
5571 | type = Gtk.MessageType.QUESTION,
|
---|
5572 | message_format = xstr("finish_newFlight_question"))
|
---|
5573 |
|
---|
5574 | dialog.add_button(xstr("button_no"), Gtk.ResponseType.NO)
|
---|
5575 | dialog.add_button(xstr("button_yes"), Gtk.ResponseType.YES)
|
---|
5576 |
|
---|
5577 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
5578 | result = dialog.run()
|
---|
5579 | dialog.hide()
|
---|
5580 | if result!=Gtk.ResponseType.YES:
|
---|
5581 | return
|
---|
5582 |
|
---|
5583 | gui.reset()
|
---|
5584 |
|
---|
5585 | def _sendClicked(self, button):
|
---|
5586 | """Called when the Send button is clicked."""
|
---|
5587 | pirep = PIREP(self._wizard.gui.flight)
|
---|
5588 | self._wizard.gui.sendPIREP(pirep,
|
---|
5589 | callback = self._handlePIREPSent)
|
---|
5590 |
|
---|
5591 | def _handlePIREPSent(self, returned, result):
|
---|
5592 | """Callback for the PIREP sending result."""
|
---|
5593 | self._pirepSent = returned and result.success
|
---|
5594 | if self._wizard.gui.config.onlineGateSystem and \
|
---|
5595 | self._wizard.loggedIn and not self._wizard.entranceExam and \
|
---|
5596 | returned and result.success:
|
---|
5597 | bookedFlight = self._wizard.bookedFlight
|
---|
5598 | if bookedFlight.arrivalICAO=="LHBP":
|
---|
5599 | iter = self._gate.get_active_iter()
|
---|
5600 | gateNumber = None if iter is None \
|
---|
5601 | else self._gatesModel.get_value(iter, 0)
|
---|
5602 |
|
---|
5603 | status = const.PLANE_PARKING if gateNumber is None \
|
---|
5604 | else const.PLANE_HOME
|
---|
5605 | else:
|
---|
5606 | gateNumber = None
|
---|
5607 | status = const.PLANE_AWAY
|
---|
5608 |
|
---|
5609 | self._wizard.updatePlane(self._planeUpdated,
|
---|
5610 | bookedFlight.tailNumber,
|
---|
5611 | status, gateNumber = gateNumber)
|
---|
5612 |
|
---|
5613 | def _planeUpdated(self, success):
|
---|
5614 | """Callback for the plane updating."""
|
---|
5615 | pass
|
---|
5616 |
|
---|
5617 | def _formatTime(self, scheduledTime, realTimestamp, warningError):
|
---|
5618 | """Format the departure or arrival time based on the given data as a
|
---|
5619 | markup for a label."""
|
---|
5620 | (warning, error) = warningError
|
---|
5621 | realTime = time.gmtime(realTimestamp)
|
---|
5622 |
|
---|
5623 | if warning:
|
---|
5624 | colour = "red" if error else "orange"
|
---|
5625 | markupBegin = '<span foreground="%s">' % (colour,)
|
---|
5626 | markupEnd = '</span>'
|
---|
5627 | else:
|
---|
5628 | markupBegin = markupEnd = ""
|
---|
5629 |
|
---|
5630 | markup = "<b>%s%02d:%02d [%02d:%02d]%s</b>" % \
|
---|
5631 | (markupBegin,
|
---|
5632 | realTime.tm_hour, realTime.tm_min,
|
---|
5633 | scheduledTime.hour, scheduledTime.minute,
|
---|
5634 | markupEnd)
|
---|
5635 |
|
---|
5636 | return markup
|
---|
5637 |
|
---|
5638 | def _updateTimes(self):
|
---|
5639 | """Format the flight times and the help text according to the flight
|
---|
5640 | type.
|
---|
5641 |
|
---|
5642 | The buttons are also updated.
|
---|
5643 | """
|
---|
5644 | flight = self._wizard.gui._flight
|
---|
5645 | bookedFlight = flight.bookedFlight
|
---|
5646 |
|
---|
5647 | (departureWarning, departureError) = flight.blockTimeStartWrong
|
---|
5648 | (arrivalWarning, arrivalError) = flight.blockTimeEndWrong
|
---|
5649 |
|
---|
5650 | if bookedFlight.flightType==const.FLIGHTTYPE_VIP:
|
---|
5651 | departureError = arrivalError = False
|
---|
5652 |
|
---|
5653 | self._tooBigTimeDifference = departureError and arrivalError
|
---|
5654 |
|
---|
5655 | self._depTime.set_markup(self._formatTime(bookedFlight.departureTime,
|
---|
5656 | flight.blockTimeStart,
|
---|
5657 | (departureWarning,
|
---|
5658 | departureError)))
|
---|
5659 |
|
---|
5660 | self._arrTime.set_markup(self._formatTime(bookedFlight.arrivalTime,
|
---|
5661 | flight.blockTimeEnd,
|
---|
5662 | (arrivalWarning,
|
---|
5663 | arrivalError)))
|
---|
5664 |
|
---|
5665 | self.updateButtons()
|
---|
5666 |
|
---|
5667 | def _updateHelp(self, faultsExplained, timesCorrect):
|
---|
5668 | """Update the help text according to the actual situation."""
|
---|
5669 | if not faultsExplained:
|
---|
5670 | self.setHelp(xstr("finish_help") + xstr("finish_help_faults"))
|
---|
5671 | elif not timesCorrect:
|
---|
5672 | self.setHelp(xstr("finish_help") + xstr("finish_help_wrongtime"))
|
---|
5673 | else:
|
---|
5674 | self.setHelp(xstr("finish_help") + xstr("finish_help_goodtime"))
|
---|
5675 |
|
---|
5676 |
|
---|
5677 | #-----------------------------------------------------------------------------
|
---|
5678 |
|
---|
5679 | class CheckFlightFinishPage(Page):
|
---|
5680 | """Finish page for a check flight."""
|
---|
5681 | def __init__(self, wizard, saveHelper):
|
---|
5682 | """Construct the check flight finish page."""
|
---|
5683 | super(CheckFlightFinishPage, self).__init__(wizard,
|
---|
5684 | "chkfinish",
|
---|
5685 | xstr("chkfinish_title"),
|
---|
5686 | "")
|
---|
5687 |
|
---|
5688 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
5689 | xscale = 1.0, yscale = 1.0)
|
---|
5690 | self._label = Gtk.Label()
|
---|
5691 | alignment.add(self._label)
|
---|
5692 |
|
---|
5693 | self.setMainWidget(alignment)
|
---|
5694 |
|
---|
5695 | self._saveHelper = saveHelper
|
---|
5696 | self._saveButton = saveHelper.addButton(self)
|
---|
5697 |
|
---|
5698 | self._button = self.addNextButton(sensitive = False,
|
---|
5699 | clicked = self._forwardClicked)
|
---|
5700 |
|
---|
5701 | def activate(self):
|
---|
5702 | """Activate the page."""
|
---|
5703 | wizard = self._wizard
|
---|
5704 | loginResult = wizard.loginResult
|
---|
5705 | gui = wizard.gui
|
---|
5706 | rating = gui.flight.logger.getRating()
|
---|
5707 |
|
---|
5708 | if rating>=0:
|
---|
5709 | loginResult.checkFlightStatus = True
|
---|
5710 |
|
---|
5711 | firstOfficer = \
|
---|
5712 | loginResult.entryExamPassed and loginResult.checkFlightStatus
|
---|
5713 |
|
---|
5714 | if firstOfficer:
|
---|
5715 | loginResult.rank = "FO"
|
---|
5716 |
|
---|
5717 | if rating<0:
|
---|
5718 | mainMessage = xstr("chkfinish_failed")
|
---|
5719 | else:
|
---|
5720 | mainMessage = xstr("chkfinish_passed_begin")
|
---|
5721 | if firstOfficer:
|
---|
5722 | mainMessage += xstr("chkfinish_passed_fo")
|
---|
5723 | mainMessage += xstr("chkfinish_passed_end")
|
---|
5724 |
|
---|
5725 | if firstOfficer:
|
---|
5726 | nextMessage = xstr("chkfinish_next")
|
---|
5727 | else:
|
---|
5728 | nextMessage = xstr("chkfinish_next_student_begin")
|
---|
5729 | if not loginResult.entryExamPassed and \
|
---|
5730 | not loginResult.checkFlightStatus:
|
---|
5731 | nextMessage += xstr("chkfinish_next_student_nothing")
|
---|
5732 | elif loginResult.entryExamPassed and \
|
---|
5733 | not loginResult.checkFlightStatus:
|
---|
5734 | nextMessage += xstr("chkfinish_next_student_no_flight")
|
---|
5735 | elif not loginResult.entryExamPassed and \
|
---|
5736 | loginResult.checkFlightStatus:
|
---|
5737 | nextMessage += xstr("chkfinish_next_student_no_exam")
|
---|
5738 |
|
---|
5739 | self._label.set_text(mainMessage +
|
---|
5740 | xstr("chkfinish_savepirep") +
|
---|
5741 | nextMessage)
|
---|
5742 | self._label.set_use_markup(True)
|
---|
5743 | self._label.set_alignment(0.5, 0.0)
|
---|
5744 |
|
---|
5745 | self._saveButton.set_sensitive(True)
|
---|
5746 | self._button.set_sensitive(True)
|
---|
5747 |
|
---|
5748 | def _forwardClicked(self, button):
|
---|
5749 | """Jump to the student page if there are some tasks to do,
|
---|
5750 | or to the flight selection page, if the pilot is allowed to perform
|
---|
5751 | MAVA flights."""
|
---|
5752 | wizard = self._wizard
|
---|
5753 | gui = wizard.gui
|
---|
5754 |
|
---|
5755 | loginResult = wizard.loginResult
|
---|
5756 | if loginResult.checkFlightStatus:
|
---|
5757 | gui.beginBusy(xstr("chkfinish_updateweb_busy"))
|
---|
5758 | gui.webHandler.setCheckFlightPassed(self._checkFlightPassedSetCallback,
|
---|
5759 | wizard.checkFlightAircraftType)
|
---|
5760 | else:
|
---|
5761 | self._resetGUI()
|
---|
5762 |
|
---|
5763 | def _checkFlightPassedSetCallback(self, returned, result):
|
---|
5764 | """Called when the check flight status has been set."""
|
---|
5765 | GObject.idle_add(self._checkFlightPassedSet, returned, result)
|
---|
5766 |
|
---|
5767 | def _checkFlightPassedSet(self, returned, result):
|
---|
5768 | """Handle the result of an attempt to set the check flight status."""
|
---|
5769 | gui = self._wizard.gui
|
---|
5770 |
|
---|
5771 | gui.endBusy()
|
---|
5772 |
|
---|
5773 | if returned:
|
---|
5774 | self._resetGUI()
|
---|
5775 | else:
|
---|
5776 | dialog = Gtk.MessageDialog(parent = gui.mainWindow,
|
---|
5777 | type = Gtk.MessageType.ERROR,
|
---|
5778 | message_format =
|
---|
5779 | xstr("chkfinish_passedset_failed"))
|
---|
5780 | dialog.set_title(WINDOW_TITLE_BASE + " - " +
|
---|
5781 | xstr("chkfinish_passedset_failed_title"))
|
---|
5782 | dialog.format_secondary_markup(xstr("chkfinish_passedset_failed_secondary"))
|
---|
5783 |
|
---|
5784 | dialog.add_button(xstr("button_ok"), 0)
|
---|
5785 |
|
---|
5786 | dialog.run()
|
---|
5787 | dialog.hide()
|
---|
5788 |
|
---|
5789 | def _resetGUI(self):
|
---|
5790 | """Reset the GUI."""
|
---|
5791 | gui = self._wizard.gui
|
---|
5792 | gui.reset()
|
---|
5793 |
|
---|
5794 | #-----------------------------------------------------------------------------
|
---|
5795 |
|
---|
5796 | class Wizard(Gtk.VBox):
|
---|
5797 | """The flight wizard."""
|
---|
5798 | def __init__(self, gui):
|
---|
5799 | """Construct the wizard."""
|
---|
5800 | super(Wizard, self).__init__()
|
---|
5801 |
|
---|
5802 | self.gui = gui
|
---|
5803 |
|
---|
5804 | self._pages = []
|
---|
5805 | self._currentPage = None
|
---|
5806 |
|
---|
5807 | self._loginPage = LoginPage(self)
|
---|
5808 | self._pages.append(self._loginPage)
|
---|
5809 | self._flightSelectionPage = FlightSelectionPage(self)
|
---|
5810 | self._pages.append(self._flightSelectionPage)
|
---|
5811 | self._pages.append(GateSelectionPage(self))
|
---|
5812 | self._pages.append(RegisterPage(self))
|
---|
5813 | self._studentPage = StudentPage(self)
|
---|
5814 | self._pages.append(self._studentPage)
|
---|
5815 | self._pages.append(ConnectPage(self))
|
---|
5816 | self._payloadPage = PayloadPage(self)
|
---|
5817 | self._pages.append(self._payloadPage)
|
---|
5818 | self._payloadIndex = len(self._pages)
|
---|
5819 | self._pages.append(TimePage(self))
|
---|
5820 | self._routePage = RoutePage(self)
|
---|
5821 | self._pages.append(self._routePage)
|
---|
5822 | self._simBriefSetupPage = SimBriefSetupPage(self)
|
---|
5823 | self._pages.append(self._simBriefSetupPage)
|
---|
5824 | self._simBriefingPage = SimBriefingPage(self)
|
---|
5825 | self._pages.append(self._simBriefingPage)
|
---|
5826 | self._pages.append(FuelPage(self))
|
---|
5827 | self._departureBriefingPage = BriefingPage(self, True)
|
---|
5828 | self._pages.append(self._departureBriefingPage)
|
---|
5829 | self._arrivalBriefingPage = BriefingPage(self, False)
|
---|
5830 | self._pages.append(self._arrivalBriefingPage)
|
---|
5831 | self._arrivalBriefingIndex = len(self._pages)
|
---|
5832 | self._takeoffPage = TakeoffPage(self)
|
---|
5833 | self._pages.append(self._takeoffPage)
|
---|
5834 | self._cruisePage = CruisePage(self)
|
---|
5835 | self._pages.append(self._cruisePage)
|
---|
5836 | self._landingPage = LandingPage(self)
|
---|
5837 | self._pages.append(self._landingPage)
|
---|
5838 |
|
---|
5839 | pirepSaveHelper = PIREPSaveHelper(self)
|
---|
5840 |
|
---|
5841 | self._finishPage = FinishPage(self, pirepSaveHelper)
|
---|
5842 | self._pages.append(self._finishPage)
|
---|
5843 | self._pages.append(CheckFlightFinishPage(self, pirepSaveHelper))
|
---|
5844 |
|
---|
5845 | self._requestedWidth = None
|
---|
5846 | self._requestedHeight = None
|
---|
5847 |
|
---|
5848 | self.connect("size-allocate", self._sizeAllocate)
|
---|
5849 |
|
---|
5850 | for page in self._pages:
|
---|
5851 | page.show_all()
|
---|
5852 | page.setStyle()
|
---|
5853 |
|
---|
5854 | self._initialize()
|
---|
5855 | self._allocateSize()
|
---|
5856 |
|
---|
5857 | def _sizeAllocate(self, widget, allocation):
|
---|
5858 | if self._requestedWidth is not None and \
|
---|
5859 | self._requestedHeight is not None:
|
---|
5860 | return
|
---|
5861 |
|
---|
5862 | (maxWidth, maxHeight) = self._allocateSize()
|
---|
5863 |
|
---|
5864 | self._requestedWidth = maxWidth
|
---|
5865 | self._requestedHeight = maxHeight
|
---|
5866 |
|
---|
5867 | def _allocateSize(self):
|
---|
5868 | """Perform the real size allocation."""
|
---|
5869 |
|
---|
5870 | if self._currentPage is not None:
|
---|
5871 | self.remove(self._pages[self._currentPage])
|
---|
5872 |
|
---|
5873 | maxWidth = 0
|
---|
5874 | maxHeight = 0
|
---|
5875 | for page in self._pages:
|
---|
5876 | self.add(page)
|
---|
5877 | self.show_all()
|
---|
5878 | pageSizeRequest = page.size_request()
|
---|
5879 | width = pageSizeRequest.width
|
---|
5880 | height = pageSizeRequest.height
|
---|
5881 | maxWidth = max(maxWidth, width)
|
---|
5882 | maxHeight = max(maxHeight, height)
|
---|
5883 | self.remove(page)
|
---|
5884 |
|
---|
5885 | if self._currentPage is not None:
|
---|
5886 | self.add(self._pages[self._currentPage])
|
---|
5887 |
|
---|
5888 | self.set_size_request(maxWidth, maxHeight)
|
---|
5889 |
|
---|
5890 | return (maxWidth, maxHeight)
|
---|
5891 |
|
---|
5892 | @property
|
---|
5893 | def pilotID(self):
|
---|
5894 | """Get the pilot ID, if given."""
|
---|
5895 | return self._loginPage.pilotID
|
---|
5896 |
|
---|
5897 | @property
|
---|
5898 | def entranceExam(self):
|
---|
5899 | """Get whether an entrance exam is about to be taken."""
|
---|
5900 | return self._loginResult is not None and self._loginResult.rank=="STU"
|
---|
5901 |
|
---|
5902 | @property
|
---|
5903 | def loggedIn(self):
|
---|
5904 | """Indicate if there was a successful login."""
|
---|
5905 | return self._loginResult is not None
|
---|
5906 |
|
---|
5907 | @property
|
---|
5908 | def loginResult(self):
|
---|
5909 | """Get the login result."""
|
---|
5910 | return self._loginResult
|
---|
5911 |
|
---|
5912 | @property
|
---|
5913 | def checkFlightAircraftType(self):
|
---|
5914 | """Get the type of the aircraft used to perform the check flight."""
|
---|
5915 | return self._studentPage.aircraftType
|
---|
5916 |
|
---|
5917 | def setCurrentPage(self, index, finalize = False, fromPageShift = None):
|
---|
5918 | """Set the current page to the one with the given index.
|
---|
5919 |
|
---|
5920 | @param fromPageShift if given, the relative index of one of the
|
---|
5921 | previous pages that should be used as the from-page of the next
|
---|
5922 | page. E.g. if fromPageShift is 1, the previous page will be the
|
---|
5923 | from-page."""
|
---|
5924 | assert index < len(self._pages)
|
---|
5925 |
|
---|
5926 | fromPage = self._currentPage
|
---|
5927 | if fromPage is not None:
|
---|
5928 | page = self._pages[fromPage]
|
---|
5929 | if finalize and not page._completed:
|
---|
5930 | page.complete()
|
---|
5931 | self.remove(page)
|
---|
5932 | if fromPageShift is not None:
|
---|
5933 | fromPage -= fromPageShift
|
---|
5934 |
|
---|
5935 | self._currentPage = index
|
---|
5936 | page = self._pages[index]
|
---|
5937 | self.add(page)
|
---|
5938 | if page._fromPage is None:
|
---|
5939 | page._fromPage = fromPage
|
---|
5940 | page.initialize()
|
---|
5941 | self.show_all()
|
---|
5942 | if fromPage is not None:
|
---|
5943 | self.grabDefault()
|
---|
5944 |
|
---|
5945 | @property
|
---|
5946 | def bookedFlight(self):
|
---|
5947 | """Get the booked flight selected."""
|
---|
5948 | return self._bookedFlight
|
---|
5949 |
|
---|
5950 | @property
|
---|
5951 | def numCockpitCrew(self):
|
---|
5952 | """Get the number of cockpit crew members."""
|
---|
5953 | return self._payloadPage.numCockpitCrew
|
---|
5954 |
|
---|
5955 | @property
|
---|
5956 | def numCabinCrew(self):
|
---|
5957 | """Get the number of cabin crew members."""
|
---|
5958 | return self._payloadPage.numCabinCrew
|
---|
5959 |
|
---|
5960 | @property
|
---|
5961 | def numPassengers(self):
|
---|
5962 | """Get the number of passengers."""
|
---|
5963 | return self._payloadPage.numPassengers
|
---|
5964 |
|
---|
5965 | @property
|
---|
5966 | def numChildren(self):
|
---|
5967 | """Get the number of child passengers."""
|
---|
5968 | return self._payloadPage.numChildren
|
---|
5969 |
|
---|
5970 | @property
|
---|
5971 | def numInfants(self):
|
---|
5972 | """Get the number of infant passengers."""
|
---|
5973 | return self._payloadPage.numInfants
|
---|
5974 |
|
---|
5975 | @property
|
---|
5976 | def bagWeight(self):
|
---|
5977 | """Get the baggage weight."""
|
---|
5978 | return self._payloadPage.bagWeight
|
---|
5979 |
|
---|
5980 | @property
|
---|
5981 | def cargoWeight(self):
|
---|
5982 | """Get the cargo weight."""
|
---|
5983 | return self._payloadPage.cargoWeight
|
---|
5984 |
|
---|
5985 | @property
|
---|
5986 | def mailWeight(self):
|
---|
5987 | """Get the mail weight."""
|
---|
5988 | return self._payloadPage.mailWeight
|
---|
5989 |
|
---|
5990 | @property
|
---|
5991 | def zfw(self):
|
---|
5992 | """Get the calculated ZFW value."""
|
---|
5993 | return 0 if self._bookedFlight is None \
|
---|
5994 | else self._payloadPage.calculateZFW()
|
---|
5995 |
|
---|
5996 | @property
|
---|
5997 | def filedCruiseLevel(self):
|
---|
5998 | """Get the filed cruise level."""
|
---|
5999 | return self._routePage.filedCruiseLevel
|
---|
6000 |
|
---|
6001 | @property
|
---|
6002 | def filedCruiseAltitude(self):
|
---|
6003 | """Get the filed cruise altitude."""
|
---|
6004 | return self._routePage.filedCruiseLevel * 100
|
---|
6005 |
|
---|
6006 | @property
|
---|
6007 | def cruiseAltitude(self):
|
---|
6008 | """Get the cruise altitude."""
|
---|
6009 | level = self._cruisePage.cruiseLevel if self._cruisePage.activated \
|
---|
6010 | else self._routePage.filedCruiseLevel
|
---|
6011 | return level * 100
|
---|
6012 |
|
---|
6013 | @property
|
---|
6014 | def loggableCruiseAltitude(self):
|
---|
6015 | """Get the cruise altitude that can be logged."""
|
---|
6016 | if self._cruisePage.activated:
|
---|
6017 | return self._cruisePage.loggableCruiseLevel * 100
|
---|
6018 | else:
|
---|
6019 | return 0
|
---|
6020 |
|
---|
6021 | @property
|
---|
6022 | def route(self):
|
---|
6023 | """Get the route."""
|
---|
6024 | return self._routePage.route
|
---|
6025 |
|
---|
6026 | @property
|
---|
6027 | def alternate(self):
|
---|
6028 | """Get the ICAO code of the alternate airport."""
|
---|
6029 | return self._routePage.alternate
|
---|
6030 |
|
---|
6031 | @property
|
---|
6032 | def departureMETAR(self):
|
---|
6033 | """Get the METAR of the departure airport."""
|
---|
6034 | return self._departureBriefingPage.metar
|
---|
6035 |
|
---|
6036 | @property
|
---|
6037 | def arrivalMETAR(self):
|
---|
6038 | """Get the METAR of the arrival airport."""
|
---|
6039 | return self._arrivalBriefingPage.metar
|
---|
6040 |
|
---|
6041 | @property
|
---|
6042 | def departureRunway(self):
|
---|
6043 | """Get the departure runway."""
|
---|
6044 | return self._takeoffPage.runway
|
---|
6045 |
|
---|
6046 | @property
|
---|
6047 | def sid(self):
|
---|
6048 | """Get the SID."""
|
---|
6049 | return self._takeoffPage.sid
|
---|
6050 |
|
---|
6051 | @property
|
---|
6052 | def v1(self):
|
---|
6053 | """Get the V1 speed."""
|
---|
6054 | return self._takeoffPage.v1
|
---|
6055 |
|
---|
6056 | @property
|
---|
6057 | def vr(self):
|
---|
6058 | """Get the Vr speed."""
|
---|
6059 | return self._takeoffPage.vr
|
---|
6060 |
|
---|
6061 | @property
|
---|
6062 | def v2(self):
|
---|
6063 | """Get the V2 speed."""
|
---|
6064 | return self._takeoffPage.v2
|
---|
6065 |
|
---|
6066 | @property
|
---|
6067 | def derate(self):
|
---|
6068 | """Get the derate value."""
|
---|
6069 | return self._takeoffPage.derate
|
---|
6070 |
|
---|
6071 | @property
|
---|
6072 | def takeoffAntiIceOn(self):
|
---|
6073 | """Get whether the anti-ice system was on during take-off."""
|
---|
6074 | return self._takeoffPage.antiIceOn
|
---|
6075 |
|
---|
6076 | @takeoffAntiIceOn.setter
|
---|
6077 | def takeoffAntiIceOn(self, value):
|
---|
6078 | """Set anti-ice on indicator."""
|
---|
6079 | self._takeoffPage.antiIceOn = value
|
---|
6080 |
|
---|
6081 | @property
|
---|
6082 | def rtoIndicated(self):
|
---|
6083 | """Get whether the pilot has indicated that an RTO has occured."""
|
---|
6084 | return self._takeoffPage.rtoIndicated
|
---|
6085 |
|
---|
6086 | @property
|
---|
6087 | def arrivalRunway(self):
|
---|
6088 | """Get the arrival runway."""
|
---|
6089 | return self._landingPage.runway
|
---|
6090 |
|
---|
6091 | @property
|
---|
6092 | def star(self):
|
---|
6093 | """Get the STAR."""
|
---|
6094 | return self._landingPage.star
|
---|
6095 |
|
---|
6096 | @property
|
---|
6097 | def transition(self):
|
---|
6098 | """Get the transition."""
|
---|
6099 | return self._landingPage.transition
|
---|
6100 |
|
---|
6101 | @property
|
---|
6102 | def approachType(self):
|
---|
6103 | """Get the approach type."""
|
---|
6104 | return self._landingPage.approachType
|
---|
6105 |
|
---|
6106 | @property
|
---|
6107 | def vref(self):
|
---|
6108 | """Get the Vref speed."""
|
---|
6109 | return self._landingPage.vref
|
---|
6110 |
|
---|
6111 | @property
|
---|
6112 | def landingAntiIceOn(self):
|
---|
6113 | """Get whether the anti-ice system was on during landing."""
|
---|
6114 | return self._landingPage.antiIceOn
|
---|
6115 |
|
---|
6116 | @landingAntiIceOn.setter
|
---|
6117 | def landingAntiIceOn(self, value):
|
---|
6118 | """Set anti-ice on indicator."""
|
---|
6119 | self._landingPage.antiIceOn = value
|
---|
6120 |
|
---|
6121 | @property
|
---|
6122 | def flightType(self):
|
---|
6123 | """Get the flight type."""
|
---|
6124 | return self._finishPage.flightType
|
---|
6125 |
|
---|
6126 | @property
|
---|
6127 | def online(self):
|
---|
6128 | """Get whether the flight was online or not."""
|
---|
6129 | return self._finishPage.online
|
---|
6130 |
|
---|
6131 | @property
|
---|
6132 | def usingSimBrief(self):
|
---|
6133 | """Indicate if we are using a SimBrief briefing or not."""
|
---|
6134 | return self._usingSimBrief
|
---|
6135 |
|
---|
6136 | @usingSimBrief.setter
|
---|
6137 | def usingSimBrief(self, x):
|
---|
6138 | """Set whether we are using a SimBrief briefing or not."""
|
---|
6139 | self._usingSimBrief = x
|
---|
6140 |
|
---|
6141 | def nextPage(self, finalize = True):
|
---|
6142 | """Go to the next page."""
|
---|
6143 | nextPageID = self._pages[self._currentPage].nextPageID
|
---|
6144 | self.jumpPage(1 if nextPageID is None else nextPageID, finalize)
|
---|
6145 |
|
---|
6146 | def jumpPage(self, countOrID, finalize = True, fromPageShift = None):
|
---|
6147 | """Go to the page which is 'count' pages after the current one."""
|
---|
6148 | if isinstance(countOrID, str):
|
---|
6149 | targetIndex = self._getIndexOf(countOrID)
|
---|
6150 | else:
|
---|
6151 | targetIndex = self._currentPage + countOrID
|
---|
6152 | self.setCurrentPage(targetIndex,
|
---|
6153 | finalize = finalize, fromPageShift = fromPageShift)
|
---|
6154 |
|
---|
6155 | def grabDefault(self):
|
---|
6156 | """Make the default button of the current page the default."""
|
---|
6157 | self._pages[self._currentPage].grabDefault()
|
---|
6158 |
|
---|
6159 | def connected(self, fsType, descriptor):
|
---|
6160 | """Called when the connection could be made to the simulator."""
|
---|
6161 | self.nextPage()
|
---|
6162 |
|
---|
6163 | def reset(self, loginResult):
|
---|
6164 | """Resets the wizard to go back to the login page."""
|
---|
6165 | self._initialize(keepLoginResult = loginResult is None,
|
---|
6166 | loginResult = loginResult)
|
---|
6167 |
|
---|
6168 | def setStage(self, stage):
|
---|
6169 | """Set the flight stage to the given one."""
|
---|
6170 | if stage!=const.STAGE_END:
|
---|
6171 | self._cruisePage.setLoggable(Flight.canLogCruiseAltitude(stage))
|
---|
6172 |
|
---|
6173 | if stage==const.STAGE_TAKEOFF:
|
---|
6174 | self._takeoffPage.allowForward()
|
---|
6175 | elif stage==const.STAGE_LANDING:
|
---|
6176 | if not self._arrivalBriefingPage.metarEdited:
|
---|
6177 | print("Downloading arrival METAR again")
|
---|
6178 | self.gui.webHandler.getMETARs(self._arrivalMETARCallback,
|
---|
6179 | [self._bookedFlight.arrivalICAO])
|
---|
6180 |
|
---|
6181 | elif stage==const.STAGE_END:
|
---|
6182 | for page in self._pages:
|
---|
6183 | page.flightEnded()
|
---|
6184 |
|
---|
6185 | def _initialize(self, keepLoginResult = False, loginResult = None):
|
---|
6186 | """Initialize the wizard."""
|
---|
6187 | if not keepLoginResult:
|
---|
6188 | self._loginResult = loginResult
|
---|
6189 |
|
---|
6190 | self._loginCallback = None
|
---|
6191 |
|
---|
6192 | self._fleet = None
|
---|
6193 | self._fleetCallback = None
|
---|
6194 |
|
---|
6195 | self._bookedFlight = None
|
---|
6196 | self._departureGate = "-"
|
---|
6197 | self._fuelData = None
|
---|
6198 | self._departureNOTAMs = None
|
---|
6199 | self._departureMETAR = None
|
---|
6200 | self._arrivalNOTAMs = None
|
---|
6201 | self._arrivalMETAR = None
|
---|
6202 | self._usingSimBrief = None
|
---|
6203 | self.takeoffRunway = None
|
---|
6204 | self.landingRunway = None
|
---|
6205 |
|
---|
6206 | firstPage = 0 if self._loginResult is None else 1
|
---|
6207 | for page in self._pages[firstPage:]:
|
---|
6208 | page.reset()
|
---|
6209 |
|
---|
6210 | self.setCurrentPage(firstPage)
|
---|
6211 | #self.setCurrentPage(10)
|
---|
6212 |
|
---|
6213 | def login(self, callback, pilotID, password):
|
---|
6214 | """Called when the login button was clicked."""
|
---|
6215 | self._loginCallback = callback
|
---|
6216 | if pilotID is None:
|
---|
6217 | loginResult = self._loginResult
|
---|
6218 | assert loginResult is not None and loginResult.loggedIn
|
---|
6219 | pilotID = loginResult.pilotID
|
---|
6220 | password = loginResult.password
|
---|
6221 | busyMessage = xstr("reload_busy")
|
---|
6222 | else:
|
---|
6223 | self._loginResult = None
|
---|
6224 | busyMessage = xstr("login_busy")
|
---|
6225 |
|
---|
6226 | self.gui.beginBusy(busyMessage)
|
---|
6227 |
|
---|
6228 | self.gui.webHandler.login(self._loginResultCallback,
|
---|
6229 | pilotID, password)
|
---|
6230 |
|
---|
6231 | def reloadFlights(self, callback):
|
---|
6232 | """Reload the flights from the MAVA server."""
|
---|
6233 | self.login(callback, None, None)
|
---|
6234 |
|
---|
6235 | def addFlight(self, bookedFlight):
|
---|
6236 | """Add the given booked flight to the flight selection page."""
|
---|
6237 | self._flightSelectionPage.addFlight(bookedFlight)
|
---|
6238 |
|
---|
6239 | def reflyFlight(self, bookedFlight):
|
---|
6240 | """Add the given booked flight to the flight selection page."""
|
---|
6241 | self._removePendingFlight(bookedFlight)
|
---|
6242 | self._flightSelectionPage._reflyFlight(bookedFlight)
|
---|
6243 |
|
---|
6244 | def deleteFlight(self, bookedFlight):
|
---|
6245 | """Remove the given flight from the pending flight list."""
|
---|
6246 | self._removePendingFlight(bookedFlight)
|
---|
6247 | self._flightSelectionPage._updatePending()
|
---|
6248 |
|
---|
6249 | def cancelFlight(self, reloadCallback):
|
---|
6250 | """Cancel the flight.
|
---|
6251 |
|
---|
6252 | If it is an entry exam flight, we go back to the student page.
|
---|
6253 | Otherwise we reload the flights."""
|
---|
6254 | if self.entranceExam:
|
---|
6255 | self.reset(None)
|
---|
6256 | self.jumpPage("student")
|
---|
6257 | else:
|
---|
6258 | self.reloadFlights(reloadCallback)
|
---|
6259 |
|
---|
6260 | def cruiseLevelChanged(self):
|
---|
6261 | """Called when the cruise level is changed."""
|
---|
6262 | return self.gui.cruiseLevelChanged()
|
---|
6263 |
|
---|
6264 | def metarChanged(self, metar, originator):
|
---|
6265 | """Called when a METER is changed on on of the pages.
|
---|
6266 |
|
---|
6267 | originator is the page that originated the changed. It will be used to
|
---|
6268 | determine which METAR (departure or arrival) has changed."""
|
---|
6269 | metar = metar.upper()
|
---|
6270 | if originator in [self._departureBriefingPage, self._takeoffPage]:
|
---|
6271 | self.departureMETARChanged(metar, originator)
|
---|
6272 | else:
|
---|
6273 | self.arrivalMETARChanged(metar, originator)
|
---|
6274 |
|
---|
6275 | def departureMETARChanged(self, metar, originator):
|
---|
6276 | """Called when the departure METAR has been edited on one of the
|
---|
6277 | pages.
|
---|
6278 |
|
---|
6279 | originator is the page that originated the change. It will not be
|
---|
6280 | called to set the METAR, while others will be."""
|
---|
6281 | for page in [self._departureBriefingPage, self._takeoffPage]:
|
---|
6282 | if page is not originator:
|
---|
6283 | page.changeMETAR(metar)
|
---|
6284 |
|
---|
6285 | def arrivalMETARChanged(self, metar, originator):
|
---|
6286 | """Called when the arrival METAR has been edited on one of the
|
---|
6287 | pages.
|
---|
6288 |
|
---|
6289 | originator is the page that originated the change. It will not be
|
---|
6290 | called to set the METAR, while others will be."""
|
---|
6291 | for page in [self._arrivalBriefingPage, self._landingPage]:
|
---|
6292 | if page is not originator:
|
---|
6293 | page.changeMETAR(metar)
|
---|
6294 |
|
---|
6295 | def _removePendingFlight(self, flight):
|
---|
6296 | """Remove the given pending flight from the login result."""
|
---|
6297 | for flights in [self._loginResult.reportedFlights,
|
---|
6298 | self._loginResult.rejectedFlights]:
|
---|
6299 | for f in flights:
|
---|
6300 | if f.id==flight.id:
|
---|
6301 | flights.remove(f)
|
---|
6302 | return
|
---|
6303 |
|
---|
6304 | def _loginResultCallback(self, returned, result):
|
---|
6305 | """The login result callback, called in the web handler's thread."""
|
---|
6306 | GObject.idle_add(self._handleLoginResult, returned, result)
|
---|
6307 |
|
---|
6308 | def _handleLoginResult(self, returned, result):
|
---|
6309 | """Handle the login result."""
|
---|
6310 | self.gui.endBusy()
|
---|
6311 | isReload = self._loginResult is not None
|
---|
6312 | if returned:
|
---|
6313 | if result.loggedIn:
|
---|
6314 | self._loginResult = result
|
---|
6315 | self.gui.loginSuccessful()
|
---|
6316 | else:
|
---|
6317 | if isReload:
|
---|
6318 | message = xstr("reload_failed")
|
---|
6319 | else:
|
---|
6320 | message = xstr("login_entranceExam_invalid"
|
---|
6321 | if self.entranceExam else
|
---|
6322 | xstr("login_invalid"))
|
---|
6323 | dialog = Gtk.MessageDialog(parent = self.gui.mainWindow,
|
---|
6324 | type = Gtk.MessageType.ERROR,
|
---|
6325 | message_format = message)
|
---|
6326 | dialog.add_button(xstr("button_ok"), Gtk.ResponseType.OK)
|
---|
6327 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
6328 | if isReload:
|
---|
6329 | secondary = xstr("reload_failed_sec")
|
---|
6330 | else:
|
---|
6331 | secondary = xstr("login_entranceExam_invalid_sec"
|
---|
6332 | if self.entranceExam else
|
---|
6333 | xstr("login_invalid_sec"))
|
---|
6334 | dialog.format_secondary_markup(secondary)
|
---|
6335 | dialog.run()
|
---|
6336 | dialog.hide()
|
---|
6337 | else:
|
---|
6338 | message = xstr("reload_failconn") if isReload \
|
---|
6339 | else xstr("login_failconn")
|
---|
6340 | dialog = Gtk.MessageDialog(parent = self.gui.mainWindow,
|
---|
6341 | type = Gtk.MessageType.ERROR,
|
---|
6342 | message_format = message)
|
---|
6343 | dialog.add_button(xstr("button_ok"), Gtk.ResponseType.OK)
|
---|
6344 | dialog.set_title(WINDOW_TITLE_BASE)
|
---|
6345 | secondary = xstr("reload_failconn_sec") if isReload \
|
---|
6346 | else xstr("login_failconn_sec")
|
---|
6347 | dialog.format_secondary_markup(secondary)
|
---|
6348 |
|
---|
6349 | dialog.run()
|
---|
6350 | dialog.hide()
|
---|
6351 |
|
---|
6352 | callback = self._loginCallback
|
---|
6353 | self._loginCallback = None
|
---|
6354 | callback(returned, result)
|
---|
6355 |
|
---|
6356 | def getFleet(self, callback, force = False):
|
---|
6357 | """Get the fleet via the GUI and call the given callback."""
|
---|
6358 | self._fleetCallback = callback
|
---|
6359 | self.gui.getFleet(callback = self._fleetRetrieved, force = force)
|
---|
6360 |
|
---|
6361 | def _fleetRetrieved(self, fleet):
|
---|
6362 | """Callback for the fleet retrieval."""
|
---|
6363 | self._fleet = fleet
|
---|
6364 | if self._fleetCallback is not None:
|
---|
6365 | self._fleetCallback(fleet)
|
---|
6366 | self._fleetCallback = None
|
---|
6367 |
|
---|
6368 | def updatePlane(self, callback, tailNumber, status, gateNumber = None):
|
---|
6369 | """Update the given plane's gate information."""
|
---|
6370 | self.gui.updatePlane(tailNumber, status, gateNumber = gateNumber,
|
---|
6371 | callback = callback)
|
---|
6372 |
|
---|
6373 | def updateRTO(self):
|
---|
6374 | """Update the RTO state.
|
---|
6375 |
|
---|
6376 | The RTO checkbox will be enabled if the flight has an RTO state and the
|
---|
6377 | comments field contains some text."""
|
---|
6378 | flight = self.gui.flight
|
---|
6379 | rtoEnabled = flight is not None and flight.hasRTO and \
|
---|
6380 | self.gui.hasComments
|
---|
6381 | self._takeoffPage.setRTOEnabled(rtoEnabled)
|
---|
6382 |
|
---|
6383 | def commentsChanged(self):
|
---|
6384 | """Called when the comments have changed."""
|
---|
6385 | self.updateRTO()
|
---|
6386 | self._finishPage.updateButtons()
|
---|
6387 |
|
---|
6388 | def delayCodesChanged(self):
|
---|
6389 | """Called when the delay codes have changed."""
|
---|
6390 | self._finishPage.updateButtons()
|
---|
6391 |
|
---|
6392 | def faultExplanationsChanged(self):
|
---|
6393 | """Called when the faults and their explanations have changed."""
|
---|
6394 | self._finishPage.updateButtons()
|
---|
6395 |
|
---|
6396 | def rtoToggled(self, indicated):
|
---|
6397 | """Called when the RTO indication has changed."""
|
---|
6398 | self.gui.rtoToggled(indicated)
|
---|
6399 |
|
---|
6400 | def _connectSimulator(self, simulatorType):
|
---|
6401 | """Connect to the simulator."""
|
---|
6402 | self.gui.connectSimulator(self._bookedFlight, simulatorType)
|
---|
6403 |
|
---|
6404 | def _arrivalMETARCallback(self, returned, result):
|
---|
6405 | """Called when the METAR of the arrival airport is retrieved."""
|
---|
6406 | GObject.idle_add(self._handleArrivalMETAR, returned, result)
|
---|
6407 |
|
---|
6408 | def _handleArrivalMETAR(self, returned, result):
|
---|
6409 | """Called when the METAR of the arrival airport is retrieved."""
|
---|
6410 | icao = self._bookedFlight.arrivalICAO
|
---|
6411 | if returned and icao in result.metars:
|
---|
6412 | metar = result.metars[icao]
|
---|
6413 | if metar!="":
|
---|
6414 | self._arrivalBriefingPage.setMETAR(metar)
|
---|
6415 |
|
---|
6416 | def _getIndexOf(self, pageID):
|
---|
6417 | """Get the index for the given page ID.
|
---|
6418 |
|
---|
6419 | It is an assertion failure if the ID is not found."""
|
---|
6420 | for index in range(0, len(self._pages)):
|
---|
6421 | page = self._pages[index]
|
---|
6422 | if page.id==pageID:
|
---|
6423 | return index
|
---|
6424 | assert False
|
---|
6425 |
|
---|
6426 | #-----------------------------------------------------------------------------
|
---|