source: src/mlx/gui/flight.py@ 97:f885322fb296

Last change on this file since 97:f885322fb296 was 97:f885322fb296, checked in by István Váradi <ivaradi@…>, 12 years ago

The PIREP can be created and sent.

File size: 82.3 KB
RevLine 
[42]1# The flight handling "wizard"
2
3from mlx.gui.common import *
4
[51]5import mlx.const as const
6import mlx.fs as fs
[60]7from mlx.checks import PayloadChecker
[89]8import mlx.util as util
[97]9from mlx.pirep import PIREP
[51]10
[61]11import datetime
12import time
13
[78]14#------------------------------------------------------------------------------
15
16acftTypeNames = { const.AIRCRAFT_B736: "Boeing 737-600",
17 const.AIRCRAFT_B737: "Boeing 737-700",
18 const.AIRCRAFT_B738: "Boeing 737-800",
19 const.AIRCRAFT_DH8D: "Bombardier Dash 8-Q400",
20 const.AIRCRAFT_B733: "Boeing 737-300",
21 const.AIRCRAFT_B734: "Boeing 737-400",
22 const.AIRCRAFT_B735: "Boeing 737-500",
23 const.AIRCRAFT_B762: "Boeing 767-200",
24 const.AIRCRAFT_B763: "Boeing 767-300",
25 const.AIRCRAFT_CRJ2: "Bombardier CRJ200",
26 const.AIRCRAFT_F70: "Fokker 70",
27 const.AIRCRAFT_DC3: "Lisunov Li-2",
28 const.AIRCRAFT_T134: "Tupolev Tu-134",
29 const.AIRCRAFT_T154: "Tupolev Tu-154",
30 const.AIRCRAFT_YK40: "Yakovlev Yak-40" }
31
[42]32#-----------------------------------------------------------------------------
33
[44]34class Page(gtk.Alignment):
[42]35 """A page in the flight wizard."""
[94]36 def __init__(self, wizard, title, help, completedHelp = None):
[42]37 """Construct the page."""
[44]38 super(Page, self).__init__(xalign = 0.0, yalign = 0.0,
39 xscale = 1.0, yscale = 1.0)
40 self.set_padding(padding_top = 4, padding_bottom = 4,
41 padding_left = 12, padding_right = 12)
42
43 frame = gtk.Frame()
44 self.add(frame)
45
46 style = self.get_style() if pygobject else self.rc_get_style()
47
48 self._vbox = gtk.VBox()
[48]49 self._vbox.set_homogeneous(False)
[44]50 frame.add(self._vbox)
51
52 eventBox = gtk.EventBox()
53 eventBox.modify_bg(0, style.bg[3])
54
55 alignment = gtk.Alignment(xalign = 0.0, xscale = 0.0)
56
57 label = gtk.Label(title)
58 label.modify_fg(0, style.fg[3])
59 label.modify_font(pango.FontDescription("bold 24"))
60 alignment.set_padding(padding_top = 4, padding_bottom = 4,
61 padding_left = 6, padding_right = 0)
62
63 alignment.add(label)
64 eventBox.add(alignment)
65
66 self._vbox.pack_start(eventBox, False, False, 0)
67
[79]68 mainBox = gtk.VBox()
[48]69
70 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
71 xscale = 1.0, yscale = 1.0)
72 alignment.set_padding(padding_top = 16, padding_bottom = 16,
73 padding_left = 16, padding_right = 16)
[79]74 alignment.add(mainBox)
[48]75 self._vbox.pack_start(alignment, True, True, 0)
76
77 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.0,
[94]78 xscale = 0.0, yscale = 0.0)
[50]79 alignment.set_padding(padding_top = 0, padding_bottom = 16,
80 padding_left = 0, padding_right = 0)
[48]81
[94]82 self._help = help
83 self._completedHelp = completedHelp
84
85 if self._completedHelp is None or \
86 len(help.splitlines())>=len(completedHelp.splitlines()):
87 longerHelp = help
88 else:
89 longerHelp = completedHelp
90
91 self._helpLabel = gtk.Label(completedHelp)
92 # FIXME: should be a constant in common
93 self._helpLabel.set_justify(gtk.Justification.CENTER if pygobject
94 else gtk.JUSTIFY_CENTER)
95 self._helpLabel.set_use_markup(True)
96 alignment.add(self._helpLabel)
[79]97 mainBox.pack_start(alignment, False, False, 0)
[44]98
99 self._mainAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
[48]100 xscale = 1.0, yscale = 1.0)
[79]101 mainBox.pack_start(self._mainAlignment, True, True, 0)
[48]102
103 buttonAlignment = gtk.Alignment(xalign = 1.0, xscale=0.0, yscale = 0.0)
[44]104 buttonAlignment.set_padding(padding_top = 4, padding_bottom = 10,
105 padding_left = 16, padding_right = 16)
106
[70]107 self._buttonBox = gtk.HBox()
108 self._buttonBox.set_homogeneous(False)
[46]109 self._defaultButton = None
[44]110 buttonAlignment.add(self._buttonBox)
111
112 self._vbox.pack_start(buttonAlignment, False, False, 0)
113
[42]114 self._wizard = wizard
115
[94]116 self._completed = False
[70]117 self._fromPage = None
118
[44]119 def setMainWidget(self, widget):
120 """Set the given widget as the main one."""
121 self._mainAlignment.add(widget)
122
[46]123 def addButton(self, label, default = False):
[44]124 """Add a button with the given label.
125
126 Return the button object created."""
127 button = gtk.Button(label)
[70]128 self._buttonBox.pack_start(button, False, False, 4)
[48]129 button.set_use_underline(True)
[46]130 if default:
131 button.set_can_default(True)
132 self._defaultButton = button
[44]133 return button
134
[94]135 def initialize(self):
136 """Initialize the page.
137
138 It sets up the primary help, and calls the activate() function."""
139 self._helpLabel.set_markup(self._help)
140 self._helpLabel.set_sensitive(True)
141 self.activate()
142
[48]143 def activate(self):
144 """Called when this page becomes active.
145
146 This default implementation does nothing."""
147 pass
148
[94]149 def complete(self):
150 """Called when the page is completed.
151
152 It greys out/changes the help text and then calls finalize()."""
153 self.finalize()
154 if self._completedHelp is None:
155 self._helpLabel.set_sensitive(False)
156 else:
157 self._helpLabel.set_markup(self._completedHelp)
158 self._completed = True
159
[70]160 def finalize(self):
161 """Called when the page is finalized."""
162 pass
163
[46]164 def grabDefault(self):
165 """If the page has a default button, make it the default one."""
166 if self._defaultButton is not None:
167 self._defaultButton.grab_default()
[67]168
169 def reset(self):
170 """Reset the page if the wizard is reset."""
[94]171 self._completed = False
[70]172 self._fromPage = None
173
174 def goBack(self):
175 """Go to the page we were invoked from."""
176 assert self._fromPage is not None
177
178 self._wizard.setCurrentPage(self._fromPage, finalize = False)
[46]179
[42]180#-----------------------------------------------------------------------------
181
182class LoginPage(Page):
183 """The login page."""
184 def __init__(self, wizard):
185 """Construct the login page."""
[44]186 help = "Enter your MAVA pilot's ID and password to\n" \
187 "log in to the MAVA website and download\n" \
188 "your booked flights."
189 super(LoginPage, self).__init__(wizard, "Login", help)
[42]190
[48]191 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
192 xscale = 0.0, yscale = 0.0)
193
[45]194 table = gtk.Table(2, 3)
[42]195 table.set_row_spacings(4)
196 table.set_col_spacings(32)
[48]197 alignment.add(table)
198 self.setMainWidget(alignment)
[42]199
200 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
[45]201 label = gtk.Label("Pilot _ID:")
202 label.set_use_underline(True)
203 labelAlignment.add(label)
[42]204 table.attach(labelAlignment, 0, 1, 0, 1)
205
206 self._pilotID = gtk.Entry()
207 self._pilotID.connect("changed", self._setLoginButton)
[45]208 self._pilotID.set_tooltip_text("Enter your MAVA pilot's ID. This "
209 "usually starts with a "
210 "'P' followed by 3 digits.")
[42]211 table.attach(self._pilotID, 1, 2, 0, 1)
[45]212 label.set_mnemonic_widget(self._pilotID)
[42]213
214 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
[45]215 label = gtk.Label("_Password:")
216 label.set_use_underline(True)
217 labelAlignment.add(label)
[42]218 table.attach(labelAlignment, 0, 1, 1, 2)
219
220 self._password = gtk.Entry()
221 self._password.set_visibility(False)
222 self._password.connect("changed", self._setLoginButton)
[45]223 self._password.set_tooltip_text("Enter the password for your pilot's ID")
[42]224 table.attach(self._password, 1, 2, 1, 2)
[45]225 label.set_mnemonic_widget(self._password)
[42]226
[45]227 self._rememberButton = gtk.CheckButton("_Remember password")
228 self._rememberButton.set_use_underline(True)
229 self._rememberButton.set_tooltip_text("If checked, your password will "
230 "be stored, so that you should "
231 "not have to enter it every time. "
232 "Note, however, that the password "
233 "is stored as text, and anybody "
234 "who can access your files will "
235 "be able to read it.")
236 table.attach(self._rememberButton, 1, 2, 2, 3, ypadding = 8)
237
[46]238 self._loginButton = self.addButton("_Login", default = True)
[42]239 self._loginButton.set_sensitive(False)
240 self._loginButton.connect("clicked", self._loginClicked)
[92]241 self._loginButton.set_tooltip_text("Click to log in.")
242
243 def activate(self):
244 """Activate the page."""
[42]245 config = self._wizard.gui.config
246 self._pilotID.set_text(config.pilotID)
247 self._password.set_text(config.password)
[45]248 self._rememberButton.set_active(config.rememberPassword)
[42]249
250 def _setLoginButton(self, entry):
251 """Set the login button's sensitivity.
252
253 The button is sensitive only if both the pilot ID and the password
254 fields contain values."""
255 self._loginButton.set_sensitive(self._pilotID.get_text()!="" and
256 self._password.get_text()!="")
257
258 def _loginClicked(self, button):
259 """Called when the login button was clicked."""
[70]260 self._loginButton.set_sensitive(False)
261 gui = self._wizard.gui
262 gui.beginBusy("Logging in...")
263 gui.webHandler.login(self._loginResultCallback,
264 self._pilotID.get_text(),
265 self._password.get_text())
[42]266
267 def _loginResultCallback(self, returned, result):
268 """The login result callback, called in the web handler's thread."""
269 gobject.idle_add(self._handleLoginResult, returned, result)
270
271 def _handleLoginResult(self, returned, result):
272 """Handle the login result."""
[49]273 self._wizard.gui.endBusy()
[70]274 self._loginButton.set_sensitive(True)
[42]275 if returned:
276 if result.loggedIn:
277 config = self._wizard.gui.config
[45]278
[42]279 config.pilotID = self._pilotID.get_text()
[45]280
281 rememberPassword = self._rememberButton.get_active()
282 config.password = self._password.get_text() if rememberPassword \
283 else ""
284
285 config.rememberPassword = rememberPassword
286
[43]287 config.save()
[48]288 self._wizard._loginResult = result
[42]289 self._wizard.nextPage()
290 else:
291 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
292 buttons = BUTTONSTYPE_OK,
293 message_format =
294 "Invalid pilot's ID or password.")
295 dialog.format_secondary_markup("Check the ID and try to reenter"
296 " the password.")
297 dialog.run()
298 dialog.hide()
299 else:
300 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
301 buttons = BUTTONSTYPE_OK,
302 message_format =
303 "Failed to connect to the MAVA website.")
304 dialog.format_secondary_markup("Try again in a few minutes.")
305 dialog.run()
306 dialog.hide()
307
308#-----------------------------------------------------------------------------
309
310class FlightSelectionPage(Page):
311 """The page to select the flight."""
312 def __init__(self, wizard):
313 """Construct the flight selection page."""
[94]314 help = "Select the flight you want to perform."
315 completedHelp = "You have selected the flight highlighted below."
[44]316 super(FlightSelectionPage, self).__init__(wizard, "Flight selection",
[94]317 help, completedHelp = completedHelp)
[48]318
319
320 self._listStore = gtk.ListStore(str, str, str, str)
321 self._flightList = gtk.TreeView(self._listStore)
322 column = gtk.TreeViewColumn("Flight no.", gtk.CellRendererText(),
323 text = 1)
324 column.set_expand(True)
325 self._flightList.append_column(column)
326 column = gtk.TreeViewColumn("Departure time [UTC]", gtk.CellRendererText(),
327 text = 0)
328 column.set_expand(True)
329 self._flightList.append_column(column)
330 column = gtk.TreeViewColumn("From", gtk.CellRendererText(),
331 text = 2)
332 column.set_expand(True)
333 self._flightList.append_column(column)
334 column = gtk.TreeViewColumn("To", gtk.CellRendererText(),
335 text = 3)
336 column.set_expand(True)
337 self._flightList.append_column(column)
338
339 flightSelection = self._flightList.get_selection()
340 flightSelection.connect("changed", self._selectionChanged)
341
342 scrolledWindow = gtk.ScrolledWindow()
343 scrolledWindow.add(self._flightList)
344 scrolledWindow.set_size_request(400, -1)
345 scrolledWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
346 else gtk.POLICY_AUTOMATIC,
[69]347 gtk.PolicyType.AUTOMATIC if pygobject
348 else gtk.POLICY_AUTOMATIC)
[62]349 scrolledWindow.set_shadow_type(gtk.ShadowType.IN if pygobject
350 else gtk.SHADOW_IN)
[48]351
352 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.0, xscale = 0.0, yscale = 1.0)
353 alignment.add(scrolledWindow)
354
355 self.setMainWidget(alignment)
356
357 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
358 self._button.set_use_stock(True)
359 self._button.set_sensitive(False)
[51]360 self._button.connect("clicked", self._forwardClicked)
[48]361
362 def activate(self):
363 """Fill the flight list."""
[70]364 self._flightList.set_sensitive(True)
365 self._listStore.clear()
366 for flight in self._wizard.loginResult.flights:
367 self._listStore.append([str(flight.departureTime),
368 flight.callsign,
369 flight.departureICAO,
370 flight.arrivalICAO])
371
372 def finalize(self):
373 """Finalize the page."""
374 self._flightList.set_sensitive(False)
[48]375
376 def _selectionChanged(self, selection):
377 """Called when the selection is changed."""
378 self._button.set_sensitive(selection.count_selected_rows()==1)
[42]379
[51]380 def _forwardClicked(self, button):
381 """Called when the forward button was clicked."""
[94]382 if self._completed:
[70]383 self._wizard.jumpPage(self._nextDistance, finalize = False)
384 else:
385 selection = self._flightList.get_selection()
386 (listStore, iter) = selection.get_selected()
387 path = listStore.get_path(iter)
388 [index] = path.get_indices() if pygobject else path
[51]389
[70]390 flight = self._wizard.loginResult.flights[index]
391 self._wizard._bookedFlight = flight
[93]392 # FIXME: with PyGObject this call causes error messages to
393 # appear on the standard output
394 self._wizard.gui.enableFlightInfo()
[51]395
[70]396 self._updateDepartureGate()
[51]397
398 def _updateDepartureGate(self):
399 """Update the departure gate for the booked flight."""
400 flight = self._wizard._bookedFlight
401 if flight.departureICAO=="LHBP":
402 self._wizard._getFleet(self._fleetRetrieved)
403 else:
[70]404 self._nextDistance = 2
[51]405 self._wizard.jumpPage(2)
406
407 def _fleetRetrieved(self, fleet):
408 """Called when the fleet has been retrieved."""
409 if fleet is None:
[70]410 self._nextDistance = 2
[51]411 self._wizard.jumpPage(2)
412 else:
413 plane = fleet[self._wizard._bookedFlight.tailNumber]
414 if plane is None:
[70]415 self._nextDistance = 2
[51]416 self._wizard.jumpPage(2)
[70]417 elif plane.gateNumber is not None and \
418 not fleet.isGateConflicting(plane):
[51]419 self._wizard._departureGate = plane.gateNumber
[70]420 self._nextDistance = 2
[51]421 self._wizard.jumpPage(2)
422 else:
[70]423 self._nextDistance = 1
[51]424 self._wizard.nextPage()
425
426#-----------------------------------------------------------------------------
427
428class GateSelectionPage(Page):
429 """Page to select a free gate at LHBP.
430
431 This page should be displayed only if we have fleet information!."""
432 def __init__(self, wizard):
433 """Construct the gate selection page."""
434 help = "The airplane's gate position is invalid.\n\n" \
435 "Select the gate from which you\n" \
436 "would like to begin the flight."
437 super(GateSelectionPage, self).__init__(wizard,
438 "LHBP gate selection",
439 help)
440
441 self._listStore = gtk.ListStore(str)
442 self._gateList = gtk.TreeView(self._listStore)
443 column = gtk.TreeViewColumn(None, gtk.CellRendererText(),
444 text = 0)
445 column.set_expand(True)
446 self._gateList.append_column(column)
447 self._gateList.set_headers_visible(False)
448
449 gateSelection = self._gateList.get_selection()
450 gateSelection.connect("changed", self._selectionChanged)
451
452 scrolledWindow = gtk.ScrolledWindow()
453 scrolledWindow.add(self._gateList)
454 scrolledWindow.set_size_request(50, -1)
455 scrolledWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
456 else gtk.POLICY_AUTOMATIC,
[69]457 gtk.PolicyType.AUTOMATIC if pygobject
458 else gtk.POLICY_AUTOMATIC)
[62]459 scrolledWindow.set_shadow_type(gtk.ShadowType.IN if pygobject
460 else gtk.SHADOW_IN)
[51]461
462 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.0, xscale = 0.0, yscale = 1.0)
463 alignment.add(scrolledWindow)
464
465 self.setMainWidget(alignment)
466
[73]467 button = self.addButton(gtk.STOCK_GO_BACK)
468 button.set_use_stock(True)
469 button.connect("clicked", self._backClicked)
470
[51]471 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
472 self._button.set_use_stock(True)
473 self._button.set_sensitive(False)
474 self._button.connect("clicked", self._forwardClicked)
475
476 def activate(self):
477 """Fill the gate list."""
478 self._listStore.clear()
[70]479 self._gateList.set_sensitive(True)
[51]480 occupiedGateNumbers = self._wizard._fleet.getOccupiedGateNumbers()
481 for gateNumber in const.lhbpGateNumbers:
482 if gateNumber not in occupiedGateNumbers:
483 self._listStore.append([gateNumber])
484
[70]485 def finalize(self):
486 """Finalize the page."""
487 self._gateList.set_sensitive(False)
488
[51]489 def _selectionChanged(self, selection):
490 """Called when the selection is changed."""
491 self._button.set_sensitive(selection.count_selected_rows()==1)
492
[73]493 def _backClicked(self, button):
494 """Called when the Back button is pressed."""
495 self.goBack()
496
[51]497 def _forwardClicked(self, button):
498 """Called when the forward button is clicked."""
[94]499 if not self._completed:
[70]500 selection = self._gateList.get_selection()
501 (listStore, iter) = selection.get_selected()
502 (gateNumber,) = listStore.get(iter, 0)
[51]503
[70]504 self._wizard._departureGate = gateNumber
[51]505
[70]506 #self._wizard._updatePlane(self._planeUpdated,
507 # self._wizard._bookedFlight.tailNumber,
508 # const.PLANE_HOME,
509 # gateNumber)
510
[58]511 self._wizard.nextPage()
[51]512
513 def _planeUpdated(self, success):
514 """Callback for the plane updating call."""
515 if success is None or success:
516 self._wizard.nextPage()
517 else:
518 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
519 buttons = BUTTONSTYPE_OK,
520 message_format = "Gate conflict detected again")
521 dialog.format_secondary_markup("Try to select a different gate.")
522 dialog.run()
523 dialog.hide()
524
525 self._wizard._getFleet(self._fleetRetrieved)
526
527 def _fleetRetrieved(self, fleet):
528 """Called when the fleet has been retrieved."""
529 if fleet is None:
530 self._wizard.nextPage()
531 else:
532 self.activate()
533
534#-----------------------------------------------------------------------------
535
536class ConnectPage(Page):
537 """Page which displays the departure airport and gate (if at LHBP)."""
538 def __init__(self, wizard):
539 """Construct the connect page."""
[78]540 help = "Load the aircraft below into the simulator and park it\n" \
541 "at the given airport, at the gate below, if present.\n\n" \
[51]542 "Then press the Connect button to connect to the simulator."
[94]543 completedHelp = "The basic data of your flight can be read below."
[51]544 super(ConnectPage, self).__init__(wizard,
545 "Connect to the simulator",
[94]546 help, completedHelp = completedHelp)
[51]547
548 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
549 xscale = 0.0, yscale = 0.0)
550
[78]551 table = gtk.Table(5, 2)
[51]552 table.set_row_spacings(4)
553 table.set_col_spacings(16)
554 table.set_homogeneous(True)
555 alignment.add(table)
556 self.setMainWidget(alignment)
557
558 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
[78]559 label = gtk.Label("Flight number:")
[51]560 labelAlignment.add(label)
561 table.attach(labelAlignment, 0, 1, 0, 1)
562
563 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
[78]564 self._flightNumber = gtk.Label()
[82]565 self._flightNumber.set_width_chars(7)
[78]566 self._flightNumber.set_alignment(0.0, 0.5)
567 labelAlignment.add(self._flightNumber)
568 table.attach(labelAlignment, 1, 2, 0, 1)
569
570 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
571 label = gtk.Label("Aircraft:")
572 labelAlignment.add(label)
573 table.attach(labelAlignment, 0, 1, 1, 2)
574
575 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
576 self._aircraft = gtk.Label()
577 self._aircraft.set_width_chars(25)
578 self._aircraft.set_alignment(0.0, 0.5)
579 labelAlignment.add(self._aircraft)
580 table.attach(labelAlignment, 1, 2, 1, 2)
581
582 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
583 label = gtk.Label("Tail number:")
584 labelAlignment.add(label)
585 table.attach(labelAlignment, 0, 1, 2, 3)
586
587 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
588 self._tailNumber = gtk.Label()
[80]589 self._tailNumber.set_width_chars(10)
[78]590 self._tailNumber.set_alignment(0.0, 0.5)
591 labelAlignment.add(self._tailNumber)
592 table.attach(labelAlignment, 1, 2, 2, 3)
593
594 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
595 label = gtk.Label("Airport:")
596 labelAlignment.add(label)
597 table.attach(labelAlignment, 0, 1, 3, 4)
598
599 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
[51]600 self._departureICAO = gtk.Label()
[80]601 self._departureICAO.set_width_chars(6)
[51]602 self._departureICAO.set_alignment(0.0, 0.5)
603 labelAlignment.add(self._departureICAO)
[78]604 table.attach(labelAlignment, 1, 2, 3, 4)
[51]605
606 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
607 label = gtk.Label("Gate:")
608 labelAlignment.add(label)
[78]609 table.attach(labelAlignment, 0, 1, 4, 5)
[51]610
611 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
612 self._departureGate = gtk.Label()
613 self._departureGate.set_width_chars(5)
614 self._departureGate.set_alignment(0.0, 0.5)
615 labelAlignment.add(self._departureGate)
[78]616 table.attach(labelAlignment, 1, 2, 4, 5)
[51]617
[70]618 button = self.addButton(gtk.STOCK_GO_BACK)
619 button.set_use_stock(True)
620 button.connect("clicked", self._backClicked)
621
[51]622 self._button = self.addButton("_Connect", default = True)
623 self._button.set_use_underline(True)
[70]624 self._clickedID = self._button.connect("clicked", self._connectClicked)
[51]625
626 def activate(self):
[60]627 """Setup the departure information."""
[70]628 self._button.set_label("_Connect")
629 self._button.set_use_underline(True)
630 self._button.disconnect(self._clickedID)
631 self._clickedID = self._button.connect("clicked", self._connectClicked)
[78]632
633 bookedFlight = self._wizard._bookedFlight
634
635 self._flightNumber.set_markup("<b>" + bookedFlight.callsign + "</b>")
636
637 aircraftType = acftTypeNames[bookedFlight.aircraftType]
638 self._aircraft.set_markup("<b>" + aircraftType + "</b>")
[70]639
[78]640 self._tailNumber.set_markup("<b>" + bookedFlight.tailNumber + "</b>")
641
642 icao = bookedFlight.departureICAO
[51]643 self._departureICAO.set_markup("<b>" + icao + "</b>")
644 gate = self._wizard._departureGate
645 if gate!="-":
646 gate = "<b>" + gate + "</b>"
647 self._departureGate.set_markup(gate)
648
[70]649 def finalize(self):
650 """Finalize the page."""
651 self._button.set_label(gtk.STOCK_GO_FORWARD)
652 self._button.set_use_stock(True)
653 self._button.disconnect(self._clickedID)
654 self._clickedID = self._button.connect("clicked", self._forwardClicked)
655
656 def _backClicked(self, button):
657 """Called when the Back button is pressed."""
658 self.goBack()
659
[51]660 def _connectClicked(self, button):
661 """Called when the Connect button is pressed."""
662 self._wizard._connectSimulator()
663
[70]664 def _forwardClicked(self, button):
665 """Called when the Forward button is pressed."""
666 self._wizard.nextPage()
667
[42]668#-----------------------------------------------------------------------------
669
[59]670class PayloadPage(Page):
671 """Page to allow setting up the payload."""
672 def __init__(self, wizard):
673 """Construct the page."""
674 help = "The briefing contains the weights below.\n" \
[60]675 "Setup the cargo weight here and the payload weight in the simulator.\n\n" \
676 "You can also check here what the simulator reports as ZFW."
[94]677 completedHelp = "You can see the weights in the briefing\n" \
678 "and the cargo weight you have selected below.\n\n" \
679 "You can also query the ZFW reported by the simulator."
680 super(PayloadPage, self).__init__(wizard, "Payload", help,
681 completedHelp = completedHelp)
[59]682
[60]683 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
684 xscale = 0.0, yscale = 0.0)
685
686 table = gtk.Table(7, 3)
687 table.set_row_spacings(4)
688 table.set_col_spacings(16)
689 table.set_homogeneous(False)
690 alignment.add(table)
691 self.setMainWidget(alignment)
692
693 label = gtk.Label("Crew:")
694 label.set_alignment(0.0, 0.5)
695 table.attach(label, 0, 1, 0, 1)
696
697 self._numCrew = gtk.Label()
698 self._numCrew.set_width_chars(6)
699 self._numCrew.set_alignment(1.0, 0.5)
700 table.attach(self._numCrew, 1, 2, 0, 1)
701
702 label = gtk.Label("Passengers:")
703 label.set_alignment(0.0, 0.5)
704 table.attach(label, 0, 1, 1, 2)
705
706 self._numPassengers = gtk.Label()
707 self._numPassengers.set_width_chars(6)
708 self._numPassengers.set_alignment(1.0, 0.5)
709 table.attach(self._numPassengers, 1, 2, 1, 2)
710
711 label = gtk.Label("Baggage:")
712 label.set_alignment(0.0, 0.5)
713 table.attach(label, 0, 1, 2, 3)
714
715 self._bagWeight = gtk.Label()
716 self._bagWeight.set_width_chars(6)
717 self._bagWeight.set_alignment(1.0, 0.5)
718 table.attach(self._bagWeight, 1, 2, 2, 3)
719
720 table.attach(gtk.Label("kg"), 2, 3, 2, 3)
721
722 label = gtk.Label("_Cargo:")
723 label.set_use_underline(True)
724 label.set_alignment(0.0, 0.5)
725 table.attach(label, 0, 1, 3, 4)
726
[84]727 self._cargoWeight = IntegerEntry(defaultValue = 0)
[60]728 self._cargoWeight.set_width_chars(6)
[84]729 self._cargoWeight.connect("integer-changed", self._cargoWeightChanged)
[60]730 self._cargoWeight.set_tooltip_text("The weight of the cargo for your flight.")
731 table.attach(self._cargoWeight, 1, 2, 3, 4)
732 label.set_mnemonic_widget(self._cargoWeight)
733
734 table.attach(gtk.Label("kg"), 2, 3, 3, 4)
735
736 label = gtk.Label("Mail:")
737 label.set_alignment(0.0, 0.5)
738 table.attach(label, 0, 1, 4, 5)
739
740 self._mailWeight = gtk.Label()
741 self._mailWeight.set_width_chars(6)
742 self._mailWeight.set_alignment(1.0, 0.5)
743 table.attach(self._mailWeight, 1, 2, 4, 5)
744
745 table.attach(gtk.Label("kg"), 2, 3, 4, 5)
746
747 label = gtk.Label("<b>Calculated ZFW:</b>")
748 label.set_alignment(0.0, 0.5)
749 label.set_use_markup(True)
750 table.attach(label, 0, 1, 5, 6)
751
752 self._calculatedZFW = gtk.Label()
753 self._calculatedZFW.set_width_chars(6)
754 self._calculatedZFW.set_alignment(1.0, 0.5)
755 table.attach(self._calculatedZFW, 1, 2, 5, 6)
756
757 table.attach(gtk.Label("kg"), 2, 3, 5, 6)
758
[70]759 self._zfwButton = gtk.Button("_ZFW from FS:")
760 self._zfwButton.set_use_underline(True)
761 self._zfwButton.connect("clicked", self._zfwRequested)
762 table.attach(self._zfwButton, 0, 1, 6, 7)
[60]763
764 self._simulatorZFW = gtk.Label("-")
765 self._simulatorZFW.set_width_chars(6)
766 self._simulatorZFW.set_alignment(1.0, 0.5)
767 table.attach(self._simulatorZFW, 1, 2, 6, 7)
768 self._simulatorZFWValue = None
769
770 table.attach(gtk.Label("kg"), 2, 3, 6, 7)
771
[70]772 self._backButton = self.addButton(gtk.STOCK_GO_BACK)
773 self._backButton.set_use_stock(True)
774 self._backButton.connect("clicked", self._backClicked)
775
[60]776 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
777 self._button.set_use_stock(True)
778 self._button.connect("clicked", self._forwardClicked)
779
[97]780 @property
781 def cargoWeight(self):
782 """Get the cargo weight entered."""
783 return self._cargoWeight.get_int()
784
[60]785 def activate(self):
786 """Setup the information."""
787 bookedFlight = self._wizard._bookedFlight
788 self._numCrew.set_text(str(bookedFlight.numCrew))
789 self._numPassengers.set_text(str(bookedFlight.numPassengers))
790 self._bagWeight.set_text(str(bookedFlight.bagWeight))
[84]791 self._cargoWeight.set_int(bookedFlight.cargoWeight)
[70]792 self._cargoWeight.set_sensitive(True)
[60]793 self._mailWeight.set_text(str(bookedFlight.mailWeight))
[92]794 self._simulatorZFW.set_text("-")
795 self._simulatorZFWValue = None
[70]796 self._zfwButton.set_sensitive(True)
[60]797 self._updateCalculatedZFW()
[59]798
[70]799 def finalize(self):
800 """Finalize the payload page."""
801 self._cargoWeight.set_sensitive(False)
802
[84]803 def calculateZFW(self):
[60]804 """Calculate the ZFW value."""
805 zfw = self._wizard.gui._flight.aircraft.dow
806 bookedFlight = self._wizard._bookedFlight
807 zfw += (bookedFlight.numCrew + bookedFlight.numPassengers) * 82
808 zfw += bookedFlight.bagWeight
[84]809 zfw += self._cargoWeight.get_int()
[60]810 zfw += bookedFlight.mailWeight
811 return zfw
812
813 def _updateCalculatedZFW(self):
814 """Update the calculated ZFW"""
[84]815 zfw = self.calculateZFW()
[60]816
817 markupBegin = "<b>"
818 markupEnd = "</b>"
819 if self._simulatorZFWValue is not None and \
820 PayloadChecker.isZFWFaulty(self._simulatorZFWValue, zfw):
821 markupBegin += '<span foreground="red">'
822 markupEnd = "</span>" + markupEnd
823 self._calculatedZFW.set_markup(markupBegin + str(zfw) + markupEnd)
824
[84]825 def _cargoWeightChanged(self, entry, weight):
[60]826 """Called when the cargo weight has changed."""
827 self._updateCalculatedZFW()
828
[59]829 def _zfwRequested(self, button):
830 """Called when the ZFW is requested from the simulator."""
[70]831 self._zfwButton.set_sensitive(False)
832 self._backButton.set_sensitive(False)
833 self._button.set_sensitive(False)
834 gui = self._wizard.gui
835 gui.beginBusy("Querying ZFW...")
836 gui.simulator.requestZFW(self._handleZFW)
[59]837
838 def _handleZFW(self, zfw):
839 """Called when the ZFW value is retrieved."""
[60]840 gobject.idle_add(self._processZFW, zfw)
[59]841
[60]842 def _processZFW(self, zfw):
843 """Process the given ZFW value received from the simulator."""
[61]844 self._wizard.gui.endBusy()
[70]845 self._zfwButton.set_sensitive(True)
846 self._backButton.set_sensitive(True)
847 self._button.set_sensitive(True)
[60]848 self._simulatorZFWValue = zfw
849 self._simulatorZFW.set_text("%.0f" % (zfw,))
850 self._updateCalculatedZFW()
851
852 def _forwardClicked(self, button):
853 """Called when the forward button is clicked."""
854 self._wizard.nextPage()
[70]855
856 def _backClicked(self, button):
857 """Called when the Back button is pressed."""
858 self.goBack()
[60]859
[59]860#-----------------------------------------------------------------------------
861
[61]862class TimePage(Page):
863 """Page displaying the departure and arrival times and allows querying the
864 current time from the flight simulator."""
865 def __init__(self, wizard):
866 help = "The departure and arrival times are displayed below in UTC.\n\n" \
867 "You can also query the current UTC time from the simulator.\n" \
868 "Ensure that you have enough time to properly prepare for the flight."
[94]869 completedHelp = "The departure and arrival times are displayed below in UTC.\n\n" \
870 "You can also query the current UTC time from the simulator.\n"
871 super(TimePage, self).__init__(wizard, "Time", help,
872 completedHelp = completedHelp)
[61]873
874 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
875 xscale = 0.0, yscale = 0.0)
876
877 table = gtk.Table(3, 2)
878 table.set_row_spacings(4)
879 table.set_col_spacings(16)
880 table.set_homogeneous(False)
881 alignment.add(table)
882 self.setMainWidget(alignment)
883
884 label = gtk.Label("Departure:")
885 label.set_alignment(0.0, 0.5)
886 table.attach(label, 0, 1, 0, 1)
887
888 self._departure = gtk.Label()
889 self._departure.set_alignment(0.0, 0.5)
890 table.attach(self._departure, 1, 2, 0, 1)
891
892 label = gtk.Label("Arrival:")
893 label.set_alignment(0.0, 0.5)
894 table.attach(label, 0, 1, 1, 2)
895
896 self._arrival = gtk.Label()
897 self._arrival.set_alignment(0.0, 0.5)
898 table.attach(self._arrival, 1, 2, 1, 2)
899
[70]900 self._timeButton = gtk.Button("_Time from FS:")
901 self._timeButton.set_use_underline(True)
902 self._timeButton.connect("clicked", self._timeRequested)
903 table.attach(self._timeButton, 0, 1, 2, 3)
[61]904
905 self._simulatorTime = gtk.Label("-")
906 self._simulatorTime.set_alignment(0.0, 0.5)
907 table.attach(self._simulatorTime, 1, 2, 2, 3)
908
[70]909 self._backButton = self.addButton(gtk.STOCK_GO_BACK)
910 self._backButton.set_use_stock(True)
911 self._backButton.connect("clicked", self._backClicked)
912
[61]913 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
914 self._button.set_use_stock(True)
915 self._button.connect("clicked", self._forwardClicked)
916
917 def activate(self):
918 """Activate the page."""
[70]919 self._timeButton.set_sensitive(True)
[61]920 bookedFlight = self._wizard._bookedFlight
921 self._departure.set_text(str(bookedFlight.departureTime.time()))
922 self._arrival.set_text(str(bookedFlight.arrivalTime.time()))
[92]923 self._simulatorTime.set_text("-")
[61]924
925 def _timeRequested(self, button):
926 """Request the time from the simulator."""
[70]927 self._timeButton.set_sensitive(False)
928 self._backButton.set_sensitive(False)
929 self._button.set_sensitive(False)
[61]930 self._wizard.gui.beginBusy("Querying time...")
931 self._wizard.gui.simulator.requestTime(self._handleTime)
932
933 def _handleTime(self, timestamp):
934 """Handle the result of a time retrieval."""
935 gobject.idle_add(self._processTime, timestamp)
936
937 def _processTime(self, timestamp):
938 """Process the given time."""
939 self._wizard.gui.endBusy()
[70]940 self._timeButton.set_sensitive(True)
941 self._backButton.set_sensitive(True)
942 self._button.set_sensitive(True)
[61]943 tm = time.gmtime(timestamp)
944 t = datetime.time(tm.tm_hour, tm.tm_min, tm.tm_sec)
945 self._simulatorTime.set_text(str(t))
946
947 ts = tm.tm_hour * 3600 + tm.tm_min * 60 + tm.tm_sec
948 dt = self._wizard._bookedFlight.departureTime.time()
949 dts = dt.hour * 3600 + dt.minute * 60 + dt.second
950 diff = dts-ts
951
952 markupBegin = ""
953 markupEnd = ""
954 if diff < 0:
955 markupBegin = '<b><span foreground="red">'
956 markupEnd = '</span></b>'
957 elif diff < 3*60 or diff > 30*60:
958 markupBegin = '<b><span foreground="orange">'
959 markupEnd = '</span></b>'
960
961 self._departure.set_markup(markupBegin + str(dt) + markupEnd)
962
[70]963 def _backClicked(self, button):
964 """Called when the Back button is pressed."""
965 self.goBack()
966
[61]967 def _forwardClicked(self, button):
968 """Called when the forward button is clicked."""
969 self._wizard.nextPage()
970
971#-----------------------------------------------------------------------------
972
[62]973class RoutePage(Page):
974 """The page containing the route and the flight level."""
975 def __init__(self, wizard):
976 help = "Set your cruise flight level below, and\n" \
977 "if necessary, edit the flight plan."
[94]978 completedHelp = "If necessary, you can modify the cruise level and\n" \
979 "the flight plan below during flight.\n" \
980 "If so, please, add a comment on why " \
981 "the modification became necessary."
982 super(RoutePage, self).__init__(wizard, "Route", help,
983 completedHelp = completedHelp)
[62]984
985 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
986 xscale = 0.0, yscale = 0.0)
987
988 mainBox = gtk.VBox()
989 alignment.add(mainBox)
990 self.setMainWidget(alignment)
991
992 levelBox = gtk.HBox()
993
994 label = gtk.Label("_Cruise level")
995 label.set_use_underline(True)
996 levelBox.pack_start(label, True, True, 0)
997
998 self._cruiseLevel = gtk.SpinButton()
999 self._cruiseLevel.set_increments(step = 10, page = 100)
1000 self._cruiseLevel.set_range(min = 50, max = 500)
1001 self._cruiseLevel.set_tooltip_text("The cruise flight level.")
1002 self._cruiseLevel.set_numeric(True)
1003 self._cruiseLevel.connect("value-changed", self._cruiseLevelChanged)
[97]1004 label.set_mnemonic_widget(self._cruiseLevel)
1005 self._filedCruiseLevel = 240
[62]1006
1007 levelBox.pack_start(self._cruiseLevel, False, False, 8)
1008
1009 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
1010 xscale = 0.0, yscale = 0.0)
1011 alignment.add(levelBox)
1012
1013 mainBox.pack_start(alignment, False, False, 0)
1014
1015
1016 routeBox = gtk.VBox()
1017
1018 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
1019 xscale = 0.0, yscale = 0.0)
1020 label = gtk.Label("_Route")
1021 label.set_use_underline(True)
1022 alignment.add(label)
1023 routeBox.pack_start(alignment, True, True, 0)
1024
1025 routeWindow = gtk.ScrolledWindow()
1026 routeWindow.set_size_request(400, 80)
1027 routeWindow.set_shadow_type(gtk.ShadowType.IN if pygobject
1028 else gtk.SHADOW_IN)
[69]1029 routeWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
1030 else gtk.POLICY_AUTOMATIC,
1031 gtk.PolicyType.AUTOMATIC if pygobject
1032 else gtk.POLICY_AUTOMATIC)
[62]1033
1034 self._route = gtk.TextView()
1035 self._route.set_tooltip_text("The planned flight route.")
1036 self._route.get_buffer().connect("changed", self._routeChanged)
1037 routeWindow.add(self._route)
1038
1039 label.set_mnemonic_widget(self._route)
1040 routeBox.pack_start(routeWindow, True, True, 0)
1041
1042 mainBox.pack_start(routeBox, True, True, 8)
1043
[70]1044 self._backButton = self.addButton(gtk.STOCK_GO_BACK)
1045 self._backButton.set_use_stock(True)
1046 self._backButton.connect("clicked", self._backClicked)
1047
[62]1048 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
1049 self._button.set_use_stock(True)
1050 self._button.connect("clicked", self._forwardClicked)
1051
[84]1052 @property
[97]1053 def filedCruiseLevel(self):
1054 """Get the filed cruise level."""
1055 return self._filedCruiseLevel
1056
1057 @property
[84]1058 def cruiseLevel(self):
1059 """Get the cruise level."""
1060 return self._cruiseLevel.get_value_as_int()
1061
[97]1062 @property
1063 def route(self):
1064 """Get the route."""
1065 return self._getRoute()
1066
[62]1067 def activate(self):
1068 """Setup the route from the booked flight."""
[92]1069 self._cruiseLevel.set_value(240)
[97]1070 self._filedCruiseLevel = 240
[62]1071 self._route.get_buffer().set_text(self._wizard._bookedFlight.route)
1072 self._updateForwardButton()
1073
1074 def _getRoute(self):
1075 """Get the text of the route."""
1076 buffer = self._route.get_buffer()
1077 return buffer.get_text(buffer.get_start_iter(),
1078 buffer.get_end_iter(), True)
1079
1080 def _updateForwardButton(self):
1081 """Update the sensitivity of the forward button."""
1082 self._button.set_sensitive(self._cruiseLevel.get_value_as_int()>=50 and \
[68]1083 self._getRoute()!="")
[62]1084
1085 def _cruiseLevelChanged(self, spinButton):
1086 """Called when the cruise level has changed."""
1087 self._updateForwardButton()
1088
1089 def _routeChanged(self, textBuffer):
1090 """Called when the route has changed."""
1091 self._updateForwardButton()
1092
[70]1093 def _backClicked(self, button):
1094 """Called when the Back button is pressed."""
1095 self.goBack()
1096
[62]1097 def _forwardClicked(self, button):
1098 """Called when the Forward button is clicked."""
[94]1099 if self._completed:
[70]1100 self._wizard.nextPage()
1101 else:
1102 bookedFlight = self._wizard._bookedFlight
[97]1103 self._filedCruiseLevel = self.cruiseLevel
[70]1104 self._wizard.gui.beginBusy("Downloading NOTAMs...")
1105 self._wizard.gui.webHandler.getNOTAMs(self._notamsCallback,
1106 bookedFlight.departureICAO,
1107 bookedFlight.arrivalICAO)
[64]1108
1109 def _notamsCallback(self, returned, result):
1110 """Callback for the NOTAMs."""
1111 gobject.idle_add(self._handleNOTAMs, returned, result)
1112
1113 def _handleNOTAMs(self, returned, result):
1114 """Handle the NOTAMs."""
1115 if returned:
1116 self._wizard._departureNOTAMs = result.departureNOTAMs
1117 self._wizard._arrivalNOTAMs = result.arrivalNOTAMs
[67]1118 else:
1119 self._wizard._departureNOTAMs = None
1120 self._wizard._arrivalNOTAMs = None
[64]1121
[67]1122 bookedFlight = self._wizard._bookedFlight
1123 self._wizard.gui.beginBusy("Downloading METARs...")
1124 self._wizard.gui.webHandler.getMETARs(self._metarsCallback,
1125 [bookedFlight.departureICAO,
1126 bookedFlight.arrivalICAO])
1127
1128 def _metarsCallback(self, returned, result):
1129 """Callback for the METARs."""
1130 gobject.idle_add(self._handleMETARs, returned, result)
1131
1132 def _handleMETARs(self, returned, result):
1133 """Handle the METARs."""
1134 self._wizard._departureMETAR = None
1135 self._wizard._arrivalMETAR = None
1136 bookedFlight = self._wizard._bookedFlight
1137 if returned:
1138 if bookedFlight.departureICAO in result.metars:
1139 self._wizard._departureMETAR = result.metars[bookedFlight.departureICAO]
1140 if bookedFlight.arrivalICAO in result.metars:
1141 self._wizard._arrivalMETAR = result.metars[bookedFlight.arrivalICAO]
1142
1143 self._wizard.gui.endBusy()
[70]1144 self._backButton.set_sensitive(True)
1145 self._button.set_sensitive(True)
[62]1146 self._wizard.nextPage()
1147
1148#-----------------------------------------------------------------------------
1149
[67]1150class BriefingPage(Page):
1151 """Page for the briefing."""
1152 def __init__(self, wizard, departure):
1153 """Construct the briefing page."""
1154 self._departure = departure
1155
[69]1156 title = "Briefing (%d/2): %s" % (1 if departure else 2,
1157 "departure" if departure
1158 else "arrival")
[67]1159
[94]1160 help = "Read carefully the NOTAMs and METAR below.\n\n" \
1161 "You can edit the METAR if your simulator or network\n" \
1162 "provides different weather."
1163 completedHelp = "If your simulator or network provides a different\n" \
1164 "weather, you can edit the METAR below."
1165 super(BriefingPage, self).__init__(wizard, title, help,
1166 completedHelp = completedHelp)
[64]1167
1168 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
1169 xscale = 1.0, yscale = 1.0)
1170
1171 mainBox = gtk.VBox()
1172 alignment.add(mainBox)
1173 self.setMainWidget(alignment)
1174
[67]1175 self._notamsFrame = gtk.Frame()
1176 self._notamsFrame.set_label("LHBP NOTAMs")
[64]1177 scrolledWindow = gtk.ScrolledWindow()
[67]1178 scrolledWindow.set_size_request(-1, 128)
[94]1179 # FIXME: these constants should be in common
[69]1180 scrolledWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
1181 else gtk.POLICY_AUTOMATIC,
1182 gtk.PolicyType.AUTOMATIC if pygobject
1183 else gtk.POLICY_AUTOMATIC)
[67]1184 self._notams = gtk.TextView()
1185 self._notams.set_editable(False)
1186 self._notams.set_accepts_tab(False)
1187 self._notams.set_wrap_mode(gtk.WrapMode.WORD if pygobject else gtk.WRAP_WORD)
1188 scrolledWindow.add(self._notams)
1189 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
1190 xscale = 1.0, yscale = 1.0)
1191 alignment.set_padding(padding_top = 4, padding_bottom = 0,
1192 padding_left = 0, padding_right = 0)
1193 alignment.add(scrolledWindow)
1194 self._notamsFrame.add(alignment)
1195 mainBox.pack_start(self._notamsFrame, True, True, 4)
1196
1197 self._metarFrame = gtk.Frame()
1198 self._metarFrame.set_label("LHBP METAR")
1199 scrolledWindow = gtk.ScrolledWindow()
1200 scrolledWindow.set_size_request(-1, 32)
[69]1201 scrolledWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
1202 else gtk.POLICY_AUTOMATIC,
1203 gtk.PolicyType.AUTOMATIC if pygobject
1204 else gtk.POLICY_AUTOMATIC)
[67]1205 self._metar = gtk.TextView()
1206 self._metar.set_accepts_tab(False)
1207 self._metar.set_wrap_mode(gtk.WrapMode.WORD if pygobject else gtk.WRAP_WORD)
1208 scrolledWindow.add(self._metar)
1209 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
1210 xscale = 1.0, yscale = 1.0)
1211 alignment.set_padding(padding_top = 4, padding_bottom = 0,
1212 padding_left = 0, padding_right = 0)
1213 alignment.add(scrolledWindow)
1214 self._metarFrame.add(alignment)
1215 mainBox.pack_start(self._metarFrame, True, True, 4)
[64]1216
[70]1217 button = self.addButton(gtk.STOCK_GO_BACK)
1218 button.set_use_stock(True)
1219 button.connect("clicked", self._backClicked)
1220
[64]1221 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
1222 self._button.set_use_stock(True)
1223 self._button.connect("clicked", self._forwardClicked)
1224
[97]1225 @property
1226 def metar(self):
1227 """Get the METAR on the page."""
1228 buffer = self._metar.get_buffer()
1229 return buffer.get_text(buffer.get_start_iter(),
1230 buffer.get_end_iter(), True)
1231
[64]1232 def activate(self):
1233 """Activate the page."""
[70]1234 if not self._departure:
1235 self._button.set_label("I have read the briefing and am ready to fly!")
1236 self._button.set_use_stock(False)
1237
1238 bookedFlight = self._wizard._bookedFlight
[67]1239
[70]1240 icao = bookedFlight.departureICAO if self._departure \
1241 else bookedFlight.arrivalICAO
1242 notams = self._wizard._departureNOTAMs if self._departure \
1243 else self._wizard._arrivalNOTAMs
1244 metar = self._wizard._departureMETAR if self._departure \
1245 else self._wizard._arrivalMETAR
[64]1246
[70]1247 self._notamsFrame.set_label(icao + " NOTAMs")
1248 buffer = self._notams.get_buffer()
1249 if notams is None:
1250 buffer.set_text("Could not download NOTAMs")
[92]1251 elif not notams:
1252 buffer.set_text("Could not download NOTAM for this airport")
[70]1253 else:
1254 s = ""
1255 for notam in notams:
1256 s += str(notam.begin)
1257 if notam.end is not None:
1258 s += " - " + str(notam.end)
1259 elif notam.permanent:
1260 s += " - PERMANENT"
1261 s += "\n"
1262 if notam.repeatCycle:
1263 s += "Repeat cycle: " + notam.repeatCycle + "\n"
1264 s += notam.notice + "\n"
1265 s += "-------------------- * --------------------\n"
1266 buffer.set_text(s)
[67]1267
[70]1268 self._metarFrame.set_label(icao + " METAR")
1269 buffer = self._metar.get_buffer()
1270 if metar is None:
1271 buffer.set_text("Could not download METAR")
1272 else:
1273 buffer.set_text(metar)
[67]1274
[70]1275 def _backClicked(self, button):
1276 """Called when the Back button is pressed."""
1277 self.goBack()
1278
[67]1279 def _forwardClicked(self, button):
[64]1280 """Called when the forward button is clicked."""
[70]1281 if not self._departure:
[94]1282 if not self._completed:
[70]1283 self._wizard.gui.startMonitoring()
[86]1284 self._button.set_use_stock(True)
1285 self._button.set_label(gtk.STOCK_GO_FORWARD)
[94]1286 self.complete()
[71]1287
1288 self._wizard.nextPage()
1289
1290#-----------------------------------------------------------------------------
1291
1292class TakeoffPage(Page):
1293 """Page for entering the takeoff data."""
1294 def __init__(self, wizard):
1295 """Construct the takeoff page."""
1296 help = "Enter the runway and SID used, as well as the speeds."
[94]1297 completedHelp = "The runway, SID and takeoff speeds logged can be seen below."
[71]1298
[94]1299 super(TakeoffPage, self).__init__(wizard, "Takeoff", help,
1300 completedHelp = completedHelp)
[71]1301
1302 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
1303 xscale = 0.0, yscale = 0.0)
1304
[84]1305 table = gtk.Table(5, 4)
[71]1306 table.set_row_spacings(4)
1307 table.set_col_spacings(16)
1308 table.set_homogeneous(False)
1309 alignment.add(table)
1310 self.setMainWidget(alignment)
1311
1312 label = gtk.Label("Run_way:")
1313 label.set_use_underline(True)
1314 label.set_alignment(0.0, 0.5)
1315 table.attach(label, 0, 1, 0, 1)
1316
1317 self._runway = gtk.Entry()
1318 self._runway.set_width_chars(10)
1319 self._runway.set_tooltip_text("The runway the takeoff is performed from.")
[84]1320 table.attach(self._runway, 1, 3, 0, 1)
[71]1321 label.set_mnemonic_widget(self._runway)
1322
1323 label = gtk.Label("_SID:")
1324 label.set_use_underline(True)
1325 label.set_alignment(0.0, 0.5)
1326 table.attach(label, 0, 1, 1, 2)
1327
1328 self._sid = gtk.Entry()
1329 self._sid.set_width_chars(10)
[75]1330 self._sid.set_tooltip_text("The name of the Standard Instrument Deparature procedure followed.")
[84]1331 table.attach(self._sid, 1, 3, 1, 2)
[71]1332 label.set_mnemonic_widget(self._sid)
1333
1334 label = gtk.Label("V<sub>_1</sub>:")
1335 label.set_use_markup(True)
1336 label.set_use_underline(True)
1337 label.set_alignment(0.0, 0.5)
1338 table.attach(label, 0, 1, 2, 3)
1339
[84]1340 self._v1 = IntegerEntry()
[86]1341 self._v1.set_width_chars(4)
[71]1342 self._v1.set_tooltip_markup("The takeoff decision speed in knots.")
[84]1343 table.attach(self._v1, 2, 3, 2, 3)
[71]1344 label.set_mnemonic_widget(self._v1)
1345
[84]1346 table.attach(gtk.Label("knots"), 3, 4, 2, 3)
[71]1347
[86]1348 label = gtk.Label("V<sub>_R</sub>:")
[71]1349 label.set_use_markup(True)
1350 label.set_use_underline(True)
1351 label.set_alignment(0.0, 0.5)
1352 table.attach(label, 0, 1, 3, 4)
1353
[84]1354 self._vr = IntegerEntry()
[86]1355 self._vr.set_width_chars(4)
[71]1356 self._vr.set_tooltip_markup("The takeoff rotation speed in knots.")
[84]1357 table.attach(self._vr, 2, 3, 3, 4)
[71]1358 label.set_mnemonic_widget(self._vr)
1359
[84]1360 table.attach(gtk.Label("knots"), 3, 4, 3, 4)
[71]1361
1362 label = gtk.Label("V<sub>_2</sub>:")
1363 label.set_use_markup(True)
1364 label.set_use_underline(True)
1365 label.set_alignment(0.0, 0.5)
1366 table.attach(label, 0, 1, 4, 5)
1367
[84]1368 self._v2 = IntegerEntry()
[86]1369 self._v2.set_width_chars(4)
[71]1370 self._v2.set_tooltip_markup("The takeoff safety speed in knots.")
[84]1371 table.attach(self._v2, 2, 3, 4, 5)
[71]1372 label.set_mnemonic_widget(self._v2)
1373
[84]1374 table.attach(gtk.Label("knots"), 3, 4, 4, 5)
[71]1375
1376 button = self.addButton(gtk.STOCK_GO_BACK)
1377 button.set_use_stock(True)
1378 button.connect("clicked", self._backClicked)
1379
1380 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
1381 self._button.set_use_stock(True)
1382 self._button.connect("clicked", self._forwardClicked)
1383
[84]1384 @property
[97]1385 def runway(self):
1386 """Get the runway."""
1387 return self._runway.get_text()
1388
1389 @property
1390 def sid(self):
1391 """Get the SID."""
1392 return self._sid.get_text()
1393
1394 @property
[84]1395 def v1(self):
1396 """Get the v1 speed."""
1397 return self._v1.get_int()
1398
1399 @property
1400 def vr(self):
1401 """Get the vr speed."""
1402 return self._vr.get_int()
1403
1404 @property
1405 def v2(self):
1406 """Get the v2 speed."""
1407 return self._v2.get_int()
1408
[71]1409 def activate(self):
1410 """Activate the page."""
[72]1411 self._runway.set_text("")
[71]1412 self._runway.set_sensitive(True)
[72]1413 self._sid.set_text("")
[71]1414 self._sid.set_sensitive(True)
[84]1415 self._v1.set_int(None)
[71]1416 self._v1.set_sensitive(True)
[86]1417 self._vr.set_int(None)
[71]1418 self._vr.set_sensitive(True)
[86]1419 self._v2.set_int(None)
[71]1420 self._v2.set_sensitive(True)
[84]1421 self._button.set_sensitive(False)
[71]1422
[84]1423 def freezeValues(self):
1424 """Freeze the values on the page, and enable the forward button."""
[71]1425 self._runway.set_sensitive(False)
1426 self._sid.set_sensitive(False)
1427 self._v1.set_sensitive(False)
1428 self._vr.set_sensitive(False)
1429 self._v2.set_sensitive(False)
[84]1430 self._button.set_sensitive(True)
1431
[71]1432 def _backClicked(self, button):
1433 """Called when the Back button is pressed."""
1434 self.goBack()
1435
1436 def _forwardClicked(self, button):
1437 """Called when the forward button is clicked."""
[75]1438 self._wizard.nextPage()
1439
1440#-----------------------------------------------------------------------------
1441
1442class LandingPage(Page):
1443 """Page for entering landing data."""
1444 def __init__(self, wizard):
1445 """Construct the landing page."""
1446 help = "Enter the STAR and/or transition, runway,\n" \
[86]1447 "approach type and V<sub>Ref</sub> used."
[94]1448 completedHelp = "The STAR and/or transition, runway, approach\n" \
1449 "type and V<sub>Ref</sub> logged can be seen below."
[75]1450
[94]1451 super(LandingPage, self).__init__(wizard, "Landing", help,
1452 completedHelp = completedHelp)
[75]1453
[88]1454 self._flightEnded = False
1455
[75]1456 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
1457 xscale = 0.0, yscale = 0.0)
1458
[86]1459 table = gtk.Table(5, 5)
[75]1460 table.set_row_spacings(4)
1461 table.set_col_spacings(16)
1462 table.set_homogeneous(False)
1463 alignment.add(table)
1464 self.setMainWidget(alignment)
1465
1466 self._starButton = gtk.CheckButton()
1467 self._starButton.connect("clicked", self._starButtonClicked)
1468 table.attach(self._starButton, 0, 1, 0, 1)
1469
1470 label = gtk.Label("_STAR:")
1471 label.set_use_underline(True)
1472 label.set_alignment(0.0, 0.5)
1473 table.attach(label, 1, 2, 0, 1)
1474
1475 self._star = gtk.Entry()
1476 self._star.set_width_chars(10)
1477 self._star.set_tooltip_text("The name of Standard Terminal Arrival Route followed.")
1478 self._star.connect("changed", self._updateForwardButton)
1479 self._star.set_sensitive(False)
[86]1480 table.attach(self._star, 2, 4, 0, 1)
[75]1481 label.set_mnemonic_widget(self._starButton)
1482
1483 self._transitionButton = gtk.CheckButton()
1484 self._transitionButton.connect("clicked", self._transitionButtonClicked)
1485 table.attach(self._transitionButton, 0, 1, 1, 2)
1486
1487 label = gtk.Label("_Transition:")
1488 label.set_use_underline(True)
1489 label.set_alignment(0.0, 0.5)
1490 table.attach(label, 1, 2, 1, 2)
1491
1492 self._transition = gtk.Entry()
1493 self._transition.set_width_chars(10)
1494 self._transition.set_tooltip_text("The name of transition executed or VECTORS if vectored by ATC.")
1495 self._transition.connect("changed", self._updateForwardButton)
1496 self._transition.set_sensitive(False)
[86]1497 table.attach(self._transition, 2, 4, 1, 2)
[75]1498 label.set_mnemonic_widget(self._transitionButton)
1499
1500 label = gtk.Label("Run_way:")
1501 label.set_use_underline(True)
1502 label.set_alignment(0.0, 0.5)
1503 table.attach(label, 1, 2, 2, 3)
1504
1505 self._runway = gtk.Entry()
1506 self._runway.set_width_chars(10)
1507 self._runway.set_tooltip_text("The runway the landing is performed on.")
1508 self._runway.connect("changed", self._updateForwardButton)
[86]1509 table.attach(self._runway, 2, 4, 2, 3)
[75]1510 label.set_mnemonic_widget(self._runway)
1511
1512 label = gtk.Label("_Approach type:")
1513 label.set_use_underline(True)
1514 label.set_alignment(0.0, 0.5)
1515 table.attach(label, 1, 2, 3, 4)
1516
1517 self._approachType = gtk.Entry()
1518 self._approachType.set_width_chars(10)
1519 self._approachType.set_tooltip_text("The type of the approach, e.g. ILS or VISUAL.")
[76]1520 self._approachType.connect("changed", self._updateForwardButton)
[86]1521 table.attach(self._approachType, 2, 4, 3, 4)
[75]1522 label.set_mnemonic_widget(self._approachType)
1523
[86]1524 label = gtk.Label("V<sub>_Ref</sub>:")
[75]1525 label.set_use_markup(True)
1526 label.set_use_underline(True)
1527 label.set_alignment(0.0, 0.5)
1528 table.attach(label, 1, 2, 5, 6)
1529
[86]1530 self._vref = IntegerEntry()
1531 self._vref.set_width_chars(5)
[75]1532 self._vref.set_tooltip_markup("The approach reference speed in knots.")
[86]1533 self._vref.connect("integer-changed", self._vrefChanged)
1534 table.attach(self._vref, 3, 4, 5, 6)
[75]1535 label.set_mnemonic_widget(self._vref)
1536
[86]1537 table.attach(gtk.Label("knots"), 4, 5, 5, 6)
[75]1538
1539 button = self.addButton(gtk.STOCK_GO_BACK)
1540 button.set_use_stock(True)
1541 button.connect("clicked", self._backClicked)
1542
1543 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
1544 self._button.set_use_stock(True)
1545 self._button.connect("clicked", self._forwardClicked)
1546
[76]1547 # These are needed for correct size calculations
1548 self._starButton.set_active(True)
1549 self._transitionButton.set_active(True)
1550
[86]1551 @property
[97]1552 def star(self):
1553 """Get the STAR or None if none entered."""
1554 return self._star.get_text() if self._starButton.get_active() else None
1555
1556 @property
1557 def transition(self):
1558 """Get the transition or None if none entered."""
1559 return self._transition.get_text() \
1560 if self._transitionButton.get_active() else None
1561
1562 @property
1563 def approachType(self):
1564 """Get the approach type."""
1565 return self._approachType.get_text()
1566
1567 @property
1568 def runway(self):
1569 """Get the runway."""
1570 return self._runway.get_text()
1571
1572 @property
[86]1573 def vref(self):
1574 """Return the landing reference speed."""
1575 return self._vref.get_int()
1576
[75]1577 def activate(self):
1578 """Called when the page is activated."""
1579 self._starButton.set_sensitive(True)
1580 self._starButton.set_active(False)
1581 self._star.set_text("")
1582
1583 self._transitionButton.set_sensitive(True)
1584 self._transitionButton.set_active(False)
1585 self._transition.set_text("")
1586
1587 self._runway.set_text("")
1588 self._runway.set_sensitive(True)
1589
1590 self._approachType.set_text("")
1591 self._approachType.set_sensitive(True)
1592
[86]1593 self._vref.set_int(None)
[75]1594 self._vref.set_sensitive(True)
1595
1596 self._updateForwardButton()
1597
[88]1598 def flightEnded(self):
1599 """Called when the flight has ended."""
1600 self._flightEnded = True
1601 self._updateForwardButton()
1602
[75]1603 def finalize(self):
1604 """Finalize the page."""
1605 self._starButton.set_sensitive(False)
1606 self._star.set_sensitive(False)
1607
1608 self._transitionButton.set_sensitive(False)
1609 self._transition.set_sensitive(False)
1610
1611 self._runway.set_sensitive(False)
1612
1613 self._approachType.set_sensitive(False)
1614
1615 self._vref.set_sensitive(False)
[96]1616 self._wizard.gui.flight.aircraft.updateVRef()
[89]1617 # FIXME: Perhaps a separate initialize() call which would set up
[96]1618 # defaults? -> use reset()
[89]1619 self._flightEnded = False
[75]1620
1621 def _starButtonClicked(self, button):
1622 """Called when the STAR button is clicked."""
1623 active = button.get_active()
1624 self._star.set_sensitive(active)
1625 if active:
1626 self._star.grab_focus()
1627 self._updateForwardButton()
1628
1629 def _transitionButtonClicked(self, button):
1630 """Called when the Transition button is clicked."""
1631 active = button.get_active()
1632 self._transition.set_sensitive(active)
1633 if active:
1634 self._transition.grab_focus()
[86]1635 self._updateForwardButton()
[75]1636
1637 def _updateForwardButton(self, widget = None):
1638 """Update the sensitivity of the forward button."""
[88]1639 sensitive = self._flightEnded and \
1640 (self._starButton.get_active() or \
[75]1641 self._transitionButton.get_active()) and \
1642 (self._star.get_text()!="" or
1643 not self._starButton.get_active()) and \
1644 (self._transition.get_text()!="" or
1645 not self._transitionButton.get_active()) and \
1646 self._runway.get_text()!="" and \
[86]1647 self._approachType.get_text()!="" and \
1648 self.vref is not None
[75]1649 self._button.set_sensitive(sensitive)
1650
[86]1651 def _vrefChanged(self, widget, value):
1652 """Called when the Vref has changed."""
1653 self._updateForwardButton()
1654
[75]1655 def _backClicked(self, button):
1656 """Called when the Back button is pressed."""
1657 self.goBack()
1658
1659 def _forwardClicked(self, button):
1660 """Called when the forward button is clicked."""
[89]1661 self._wizard.nextPage()
1662
1663#-----------------------------------------------------------------------------
1664
1665class FinishPage(Page):
1666 """Flight finish page."""
[97]1667 _flightTypes = [ ("scheduled", const.FLIGHTTYPE_SCHEDULED),
1668 ("old-timer", const.FLIGHTTYPE_OLDTIMER),
1669 ("VIP", const.FLIGHTTYPE_VIP),
1670 ("charter", const.FLIGHTTYPE_CHARTER) ]
1671
[89]1672 def __init__(self, wizard):
1673 """Construct the finish page."""
1674 help = "There are some statistics about your flight below.\n\n" \
1675 "Review the data, also on earlier pages, and if you are\n" \
1676 "satisfied, you can save or send your PIREP."
1677
1678 super(FinishPage, self).__init__(wizard, "Finish", help)
1679
1680 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
1681 xscale = 0.0, yscale = 0.0)
1682
[96]1683 table = gtk.Table(7, 2)
[89]1684 table.set_row_spacings(4)
1685 table.set_col_spacings(16)
[96]1686 table.set_homogeneous(False)
[89]1687 alignment.add(table)
1688 self.setMainWidget(alignment)
1689
1690 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
1691 label = gtk.Label("Flight rating:")
1692 labelAlignment.add(label)
1693 table.attach(labelAlignment, 0, 1, 0, 1)
1694
1695 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
1696 self._flightRating = gtk.Label()
1697 self._flightRating.set_width_chars(7)
1698 self._flightRating.set_alignment(0.0, 0.5)
1699 self._flightRating.set_use_markup(True)
1700 labelAlignment.add(self._flightRating)
1701 table.attach(labelAlignment, 1, 2, 0, 1)
1702
1703 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
1704 label = gtk.Label("Flight time:")
1705 labelAlignment.add(label)
1706 table.attach(labelAlignment, 0, 1, 1, 2)
1707
1708 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
1709 self._flightTime = gtk.Label()
1710 self._flightTime.set_width_chars(10)
1711 self._flightTime.set_alignment(0.0, 0.5)
1712 self._flightTime.set_use_markup(True)
1713 labelAlignment.add(self._flightTime)
1714 table.attach(labelAlignment, 1, 2, 1, 2)
1715
1716 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
1717 label = gtk.Label("Block time:")
1718 labelAlignment.add(label)
1719 table.attach(labelAlignment, 0, 1, 2, 3)
1720
1721 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
1722 self._blockTime = gtk.Label()
1723 self._blockTime.set_width_chars(10)
1724 self._blockTime.set_alignment(0.0, 0.5)
1725 self._blockTime.set_use_markup(True)
1726 labelAlignment.add(self._blockTime)
1727 table.attach(labelAlignment, 1, 2, 2, 3)
1728
1729 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
1730 label = gtk.Label("Distance flown:")
1731 labelAlignment.add(label)
1732 table.attach(labelAlignment, 0, 1, 3, 4)
1733
1734 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
1735 self._distanceFlown = gtk.Label()
1736 self._distanceFlown.set_width_chars(10)
1737 self._distanceFlown.set_alignment(0.0, 0.5)
1738 self._distanceFlown.set_use_markup(True)
1739 labelAlignment.add(self._distanceFlown)
1740 table.attach(labelAlignment, 1, 2, 3, 4)
1741
1742 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
1743 label = gtk.Label("Fuel used:")
1744 labelAlignment.add(label)
1745 table.attach(labelAlignment, 0, 1, 4, 5)
1746
1747 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
1748 self._fuelUsed = gtk.Label()
1749 self._fuelUsed.set_width_chars(10)
1750 self._fuelUsed.set_alignment(0.0, 0.5)
1751 self._fuelUsed.set_use_markup(True)
1752 labelAlignment.add(self._fuelUsed)
1753 table.attach(labelAlignment, 1, 2, 4, 5)
1754
[96]1755 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
1756 label = gtk.Label("_Type:")
1757 label.set_use_underline(True)
1758 labelAlignment.add(label)
1759 table.attach(labelAlignment, 0, 1, 5, 6)
1760
1761 flightTypeModel = gtk.ListStore(str, int)
[97]1762 for (name, type) in FinishPage._flightTypes:
1763 flightTypeModel.append([name, type])
[96]1764
1765 self._flightType = gtk.ComboBox(model = flightTypeModel)
1766 renderer = gtk.CellRendererText()
1767 self._flightType.pack_start(renderer, True)
1768 self._flightType.add_attribute(renderer, "text", 0)
1769 self._flightType.set_tooltip_text("Select the type of the flight.")
1770 self._flightType.set_active(0)
1771 self._flightType.connect("changed", self._flightTypeChanged)
1772 flightTypeAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
1773 flightTypeAlignment.add(self._flightType)
1774 table.attach(flightTypeAlignment, 1, 2, 5, 6)
1775 label.set_mnemonic_widget(self._flightType)
1776
1777 self._onlineFlight = gtk.CheckButton("_Online flight")
1778 self._onlineFlight.set_use_underline(True)
1779 self._onlineFlight.set_tooltip_text("Check if your flight was online, uncheck otherwise.")
1780 onlineFlightAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
1781 onlineFlightAlignment.add(self._onlineFlight)
1782 table.attach(onlineFlightAlignment, 1, 2, 6, 7)
1783
[94]1784 button = self.addButton(gtk.STOCK_GO_BACK)
1785 button.set_use_stock(True)
1786 button.connect("clicked", self._backClicked)
1787
[89]1788 self._saveButton = self.addButton("S_ave PIREP...")
1789 self._saveButton.set_use_underline(True)
[94]1790 self._saveButton.set_sensitive(False)
[89]1791 #self._saveButton.connect("clicked", self._saveClicked)
1792
1793 self._sendButton = self.addButton("_Send PIREP...", True)
1794 self._sendButton.set_use_underline(True)
[94]1795 self._sendButton.set_sensitive(False)
[97]1796 self._sendButton.connect("clicked", self._sendClicked)
1797
1798 @property
1799 def flightType(self):
1800 """Get the flight type."""
1801 index = self._flightType.get_active()
1802 return None if index<0 else self._flightType.get_model()[index][1]
1803
1804 @property
1805 def online(self):
1806 """Get whether the flight was an online flight or not."""
1807 return self._onlineFlight.get_active()
[89]1808
1809 def activate(self):
1810 """Activate the page."""
1811 flight = self._wizard.gui._flight
1812 rating = flight.logger.getRating()
1813 if rating<0:
1814 self._flightRating.set_markup('<b><span foreground="red">NO GO</span></b>')
1815 else:
1816 self._flightRating.set_markup("<b>%.1f %%</b>" % (rating,))
1817
1818 flightLength = flight.flightTimeEnd - flight.flightTimeStart
1819 self._flightTime.set_markup("<b>%s</b>" % \
1820 (util.getTimeIntervalString(flightLength),))
1821
1822 blockLength = flight.blockTimeEnd - flight.blockTimeStart
1823 self._blockTime.set_markup("<b>%s</b>" % \
1824 (util.getTimeIntervalString(blockLength),))
1825
1826 self._distanceFlown.set_markup("<b>%.2f NM</b>" % \
1827 (flight.flownDistance,))
1828
1829 self._fuelUsed.set_markup("<b>%.0f kg</b>" % \
1830 (flight.endFuel - flight.startFuel,))
[64]1831
[96]1832 self._flightType.set_active(-1)
1833 self._onlineFlight.set_active(True)
1834
[94]1835 def _backClicked(self, button):
1836 """Called when the Back button is pressed."""
1837 self.goBack()
[96]1838
1839 def _flightTypeChanged(self, comboBox):
1840 """Called when the flight type has changed."""
1841 index = self._flightType.get_active()
1842 flightTypeIsValid = index>=0
[97]1843 #self._saveButton.set_sensitive(flightTypeIsValid)
[96]1844 self._sendButton.set_sensitive(flightTypeIsValid)
[97]1845
1846 def _sendClicked(self, button):
1847 """Called when the Send button is clicked."""
1848 pirep = PIREP(self._wizard.gui)
1849 gui = self._wizard.gui
1850 gui.beginBusy("Sending PIREP...")
1851 gui.webHandler.sendPIREP(self._pirepSentCallback, pirep)
1852
1853 def _pirepSentCallback(self, returned, result):
1854 """Callback for the PIREP sending result."""
1855 gobject.idle_add(self._handlePIREPSent, returned, result)
1856
1857 def _handlePIREPSent(self, returned, result):
1858 """Callback for the PIREP sending result."""
1859 self._wizard.gui.endBusy()
1860 secondaryMarkup = None
1861 type = MESSAGETYPE_ERROR
1862 if returned:
1863 if result.success:
1864 type = MESSAGETYPE_INFO
1865 messageFormat = "The PIREP was sent successfully."
1866 secondaryMarkup = "Await the thorough scrutiny from our PIREP correctors! :)"
1867 elif result.alreadyFlown:
1868 messageFormat = "The PIREP for this flight has already been sent!"
1869 secondaryMarkup = "You may clear the old PIREP on the MAVA website."
1870 elif result.notAvailable:
1871 messageFormat = "This flight is not available anymore!"
1872 else:
1873 messageFormat = "The MAVA website returned with an unknown error."
1874 secondaryMarkup = "See the debug log for more information."
1875 else:
1876 print "PIREP sending failed", result
1877 messageFormat = "Could not send the PIREP to the MAVA website."
1878 secondaryMarkup = "This can be a network problem, in which case\n" \
1879 "you may try again later. Or it can be a bug;\n" \
1880 "see the debug log for more information."
1881
1882 dialog = gtk.MessageDialog(type = type, buttons = BUTTONSTYPE_OK,
1883 message_format = messageFormat)
1884 if secondaryMarkup is not None:
1885 dialog.format_secondary_markup(secondaryMarkup)
1886
1887 dialog.run()
1888 dialog.hide()
[94]1889
[64]1890#-----------------------------------------------------------------------------
1891
[42]1892class Wizard(gtk.VBox):
1893 """The flight wizard."""
1894 def __init__(self, gui):
1895 """Construct the wizard."""
1896 super(Wizard, self).__init__()
1897
1898 self.gui = gui
1899
1900 self._pages = []
1901 self._currentPage = None
1902
1903 self._pages.append(LoginPage(self))
1904 self._pages.append(FlightSelectionPage(self))
[51]1905 self._pages.append(GateSelectionPage(self))
1906 self._pages.append(ConnectPage(self))
[84]1907 self._payloadPage = PayloadPage(self)
1908 self._pages.append(self._payloadPage)
[61]1909 self._pages.append(TimePage(self))
[84]1910 self._routePage = RoutePage(self)
1911 self._pages.append(self._routePage)
[97]1912 self._departureBriefingPage = BriefingPage(self, True)
1913 self._pages.append(self._departureBriefingPage)
1914 self._arrivalBriefingPage = BriefingPage(self, False)
1915 self._pages.append(self._arrivalBriefingPage)
[84]1916 self._takeoffPage = TakeoffPage(self)
1917 self._pages.append(self._takeoffPage)
[86]1918 self._landingPage = LandingPage(self)
1919 self._pages.append(self._landingPage)
[97]1920 self._finishPage = FinishPage(self)
1921 self._pages.append(self._finishPage)
[67]1922
[51]1923 maxWidth = 0
1924 maxHeight = 0
1925 for page in self._pages:
1926 page.show_all()
1927 pageSizeRequest = page.size_request()
1928 width = pageSizeRequest.width if pygobject else pageSizeRequest[0]
1929 height = pageSizeRequest.height if pygobject else pageSizeRequest[1]
1930 maxWidth = max(maxWidth, width)
1931 maxHeight = max(maxHeight, height)
1932 maxWidth += 16
1933 maxHeight += 32
1934 self.set_size_request(maxWidth, maxHeight)
1935
[59]1936 self._initialize()
[51]1937
[48]1938 @property
1939 def loginResult(self):
1940 """Get the login result."""
1941 return self._loginResult
1942
[70]1943 def setCurrentPage(self, index, finalize = False):
[42]1944 """Set the current page to the one with the given index."""
1945 assert index < len(self._pages)
[70]1946
1947 fromPage = self._currentPage
1948 if fromPage is not None:
1949 page = self._pages[fromPage]
[94]1950 if finalize and not page._completed:
1951 page.complete()
[70]1952 self.remove(page)
[42]1953
1954 self._currentPage = index
[70]1955 page = self._pages[index]
1956 self.add(page)
1957 if page._fromPage is None:
1958 page._fromPage = fromPage
[94]1959 page.initialize()
[42]1960 self.show_all()
[72]1961 if fromPage is not None:
1962 self.grabDefault()
[42]1963
[84]1964 @property
[97]1965 def bookedFlight(self):
1966 """Get the booked flight selected."""
1967 return self._bookedFlight
1968
1969 @property
1970 def cargoWeight(self):
1971 """Get the calculated ZFW value."""
1972 return self._payloadPage.cargoWeight
1973
1974 @property
[84]1975 def zfw(self):
1976 """Get the calculated ZFW value."""
1977 return 0 if self._bookedFlight is None \
1978 else self._payloadPage.calculateZFW()
1979
1980 @property
[97]1981 def filedCruiseAltitude(self):
1982 """Get the filed cruise altitude."""
1983 return self._routePage.filedCruiseLevel * 100
1984
1985 @property
[84]1986 def cruiseAltitude(self):
1987 """Get the cruise altitude."""
1988 return self._routePage.cruiseLevel * 100
1989
1990 @property
[97]1991 def route(self):
1992 """Get the route."""
1993 return self._routePage.route
1994
1995 @property
1996 def departureMETAR(self):
1997 """Get the METAR of the departure airport."""
1998 return self._departureBriefingPage.metar
1999
2000 @property
2001 def arrivalMETAR(self):
2002 """Get the METAR of the arrival airport."""
2003 return self._arrivalBriefingPage.metar
2004
2005 @property
2006 def departureRunway(self):
2007 """Get the departure runway."""
2008 return self._takeoffPage.runway
2009
2010 @property
2011 def sid(self):
2012 """Get the SID."""
2013 return self._takeoffPage.sid
2014
2015 @property
[84]2016 def v1(self):
2017 """Get the V1 speed."""
[86]2018 return self._takeoffPage.v1
[84]2019
2020 @property
2021 def vr(self):
2022 """Get the Vr speed."""
[86]2023 return self._takeoffPage.vr
[84]2024
2025 @property
2026 def v2(self):
2027 """Get the V2 speed."""
[86]2028 return self._takeoffPage.v2
2029
2030 @property
[97]2031 def arrivalRunway(self):
2032 """Get the arrival runway."""
2033 return self._landingPage.runway
2034
2035 @property
2036 def star(self):
2037 """Get the STAR."""
2038 return self._landingPage.star
2039
2040 @property
2041 def transition(self):
2042 """Get the transition."""
2043 return self._landingPage.transition
2044
2045 @property
2046 def approachType(self):
2047 """Get the approach type."""
2048 return self._landingPage.approachType
2049
2050 @property
[86]2051 def vref(self):
2052 """Get the Vref speed."""
2053 return self._landingPage.vref
[84]2054
[97]2055 @property
2056 def flightType(self):
2057 """Get the flight type."""
2058 return self._finishPage.flightType
2059
2060 @property
2061 def online(self):
2062 """Get whether the flight was online or not."""
2063 return self._finishPage.online
2064
[70]2065 def nextPage(self, finalize = True):
[42]2066 """Go to the next page."""
[70]2067 self.jumpPage(1, finalize)
[51]2068
[70]2069 def jumpPage(self, count, finalize = True):
[51]2070 """Go to the page which is 'count' pages after the current one."""
[70]2071 self.setCurrentPage(self._currentPage + count, finalize = finalize)
[46]2072
2073 def grabDefault(self):
2074 """Make the default button of the current page the default."""
2075 self._pages[self._currentPage].grabDefault()
[51]2076
[59]2077 def connected(self, fsType, descriptor):
2078 """Called when the connection could be made to the simulator."""
2079 self.nextPage()
2080
[91]2081 def reset(self):
2082 """Resets the wizard to go back to the login page."""
[59]2083 self._initialize()
2084
[84]2085 def setStage(self, stage):
2086 """Set the flight stage to the given one."""
2087 if stage==const.STAGE_TAKEOFF:
2088 self._takeoffPage.freezeValues()
[88]2089 elif stage==const.STAGE_END:
2090 self._landingPage.flightEnded()
[84]2091
[59]2092 def _initialize(self):
2093 """Initialize the wizard."""
2094 self._fleet = None
2095 self._fleetCallback = None
2096 self._updatePlaneCallback = None
2097
2098 self._loginResult = None
2099 self._bookedFlight = None
2100 self._departureGate = "-"
[64]2101 self._departureNOTAMs = None
[67]2102 self._departureMETAR = None
[64]2103 self._arrivalNOTAMs = None
[67]2104 self._arrivalMETAR = None
2105
2106 for page in self._pages:
2107 page.reset()
[62]2108
[59]2109 self.setCurrentPage(0)
2110
[51]2111 def _getFleet(self, callback, force = False):
2112 """Get the fleet, if needed.
2113
2114 callback is function that will be called, when the feet is retrieved,
2115 or the retrieval fails. It should have a single argument that will
2116 receive the fleet object on success, None otherwise.
2117 """
2118 if self._fleet is not None and not force:
2119 callback(self._fleet)
2120
2121 self.gui.beginBusy("Retrieving fleet...")
2122 self._fleetCallback = callback
2123 self.gui.webHandler.getFleet(self._fleetResultCallback)
2124
2125 def _fleetResultCallback(self, returned, result):
2126 """Called when the fleet has been queried."""
2127 gobject.idle_add(self._handleFleetResult, returned, result)
2128
2129 def _handleFleetResult(self, returned, result):
2130 """Handle the fleet result."""
2131 self.gui.endBusy()
2132 if returned:
2133 self._fleet = result.fleet
2134 else:
2135 self._fleet = None
2136
2137 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
2138 buttons = BUTTONSTYPE_OK,
2139 message_format =
2140 "Failed to retrieve the information on "
2141 "the fleet.")
2142 dialog.run()
2143 dialog.hide()
2144
2145 self._fleetCallback(self._fleet)
2146
2147 def _updatePlane(self, callback, tailNumber, status, gateNumber = None):
2148 """Update the given plane's gate information."""
2149 self.gui.beginBusy("Updating plane status...")
2150 self._updatePlaneCallback = callback
2151 self.gui.webHandler.updatePlane(self._updatePlaneResultCallback,
2152 tailNumber, status, gateNumber)
2153
2154 def _updatePlaneResultCallback(self, returned, result):
2155 """Callback for the plane updating operation."""
2156 gobject.idle_add(self._handleUpdatePlaneResult, returned, result)
2157
2158 def _handleUpdatePlaneResult(self, returned, result):
2159 """Handle the result of a plane update operation."""
2160 self.gui.endBusy()
2161 if returned:
2162 success = result.success
2163 else:
2164 success = None
2165
2166 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
2167 buttons = BUTTONSTYPE_OK,
2168 message_format =
2169 "Failed to update the statuis of "
2170 "the airplane.")
2171 dialog.run()
2172 dialog.hide()
2173
2174 self._updatePlaneCallback(success)
2175
2176 def _connectSimulator(self):
2177 """Connect to the simulator."""
[59]2178 self.gui.connectSimulator(self._bookedFlight.aircraftType)
[42]2179
2180#-----------------------------------------------------------------------------
2181
Note: See TracBrowser for help on using the repository browser.