source: src/mlx/gui/flight.py@ 78:31c23c6721d1

Last change on this file since 78:31c23c6721d1 was 78:31c23c6721d1, checked in by István Váradi <ivaradi@…>, 13 years ago

Added some further data to the connect page

File size: 66.8 KB
Line 
1# The flight handling "wizard"
2
3from mlx.gui.common import *
4
5import mlx.const as const
6import mlx.fs as fs
7from mlx.checks import PayloadChecker
8
9import datetime
10import time
11
12#------------------------------------------------------------------------------
13
14acftTypeNames = { const.AIRCRAFT_B736: "Boeing 737-600",
15 const.AIRCRAFT_B737: "Boeing 737-700",
16 const.AIRCRAFT_B738: "Boeing 737-800",
17 const.AIRCRAFT_DH8D: "Bombardier Dash 8-Q400",
18 const.AIRCRAFT_B733: "Boeing 737-300",
19 const.AIRCRAFT_B734: "Boeing 737-400",
20 const.AIRCRAFT_B735: "Boeing 737-500",
21 const.AIRCRAFT_B762: "Boeing 767-200",
22 const.AIRCRAFT_B763: "Boeing 767-300",
23 const.AIRCRAFT_CRJ2: "Bombardier CRJ200",
24 const.AIRCRAFT_F70: "Fokker 70",
25 const.AIRCRAFT_DC3: "Lisunov Li-2",
26 const.AIRCRAFT_T134: "Tupolev Tu-134",
27 const.AIRCRAFT_T154: "Tupolev Tu-154",
28 const.AIRCRAFT_YK40: "Yakovlev Yak-40" }
29
30#-----------------------------------------------------------------------------
31
32class Page(gtk.Alignment):
33 """A page in the flight wizard."""
34 def __init__(self, wizard, title, help):
35 """Construct the page."""
36 super(Page, self).__init__(xalign = 0.0, yalign = 0.0,
37 xscale = 1.0, yscale = 1.0)
38 self.set_padding(padding_top = 4, padding_bottom = 4,
39 padding_left = 12, padding_right = 12)
40
41 frame = gtk.Frame()
42 self.add(frame)
43
44 style = self.get_style() if pygobject else self.rc_get_style()
45
46 self._vbox = gtk.VBox()
47 self._vbox.set_homogeneous(False)
48 frame.add(self._vbox)
49
50 eventBox = gtk.EventBox()
51 eventBox.modify_bg(0, style.bg[3])
52
53 alignment = gtk.Alignment(xalign = 0.0, xscale = 0.0)
54
55 label = gtk.Label(title)
56 label.modify_fg(0, style.fg[3])
57 label.modify_font(pango.FontDescription("bold 24"))
58 alignment.set_padding(padding_top = 4, padding_bottom = 4,
59 padding_left = 6, padding_right = 0)
60
61 alignment.add(label)
62 eventBox.add(alignment)
63
64 self._vbox.pack_start(eventBox, False, False, 0)
65
66 table = gtk.Table(3, 1)
67 table.set_homogeneous(False)
68
69 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
70 xscale = 1.0, yscale = 1.0)
71 alignment.set_padding(padding_top = 16, padding_bottom = 16,
72 padding_left = 16, padding_right = 16)
73 alignment.add(table)
74 self._vbox.pack_start(alignment, True, True, 0)
75
76 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.0,
77 xscale = 0, yscale = 0.0)
78 alignment.set_padding(padding_top = 0, padding_bottom = 16,
79 padding_left = 0, padding_right = 0)
80
81 label = gtk.Label(help)
82 label.set_justify(gtk.Justification.CENTER if pygobject
83 else gtk.JUSTIFY_CENTER)
84 label.set_use_markup(True)
85 alignment.add(label)
86 table.attach(alignment, 0, 1, 0, 1)
87
88 self._mainAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
89 xscale = 1.0, yscale = 1.0)
90 table.attach(self._mainAlignment, 0, 1, 1, 3)
91
92 buttonAlignment = gtk.Alignment(xalign = 1.0, xscale=0.0, yscale = 0.0)
93 buttonAlignment.set_padding(padding_top = 4, padding_bottom = 10,
94 padding_left = 16, padding_right = 16)
95
96 self._buttonBox = gtk.HBox()
97 self._buttonBox.set_homogeneous(False)
98 self._defaultButton = None
99 buttonAlignment.add(self._buttonBox)
100
101 self._vbox.pack_start(buttonAlignment, False, False, 0)
102
103 self._wizard = wizard
104
105 self._finalized = False
106 self._fromPage = None
107
108 def setMainWidget(self, widget):
109 """Set the given widget as the main one."""
110 self._mainAlignment.add(widget)
111
112 def addButton(self, label, default = False):
113 """Add a button with the given label.
114
115 Return the button object created."""
116 button = gtk.Button(label)
117 self._buttonBox.pack_start(button, False, False, 4)
118 button.set_use_underline(True)
119 if default:
120 button.set_can_default(True)
121 self._defaultButton = button
122 return button
123
124 def activate(self):
125 """Called when this page becomes active.
126
127 This default implementation does nothing."""
128 pass
129
130 def finalize(self):
131 """Called when the page is finalized."""
132 pass
133
134 def grabDefault(self):
135 """If the page has a default button, make it the default one."""
136 if self._defaultButton is not None:
137 self._defaultButton.grab_default()
138
139 def reset(self):
140 """Reset the page if the wizard is reset."""
141 self._finalized = False
142 self._fromPage = None
143
144 def goBack(self):
145 """Go to the page we were invoked from."""
146 assert self._fromPage is not None
147
148 self._wizard.setCurrentPage(self._fromPage, finalize = False)
149
150#-----------------------------------------------------------------------------
151
152class LoginPage(Page):
153 """The login page."""
154 def __init__(self, wizard):
155 """Construct the login page."""
156 help = "Enter your MAVA pilot's ID and password to\n" \
157 "log in to the MAVA website and download\n" \
158 "your booked flights."
159 super(LoginPage, self).__init__(wizard, "Login", help)
160
161 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
162 xscale = 0.0, yscale = 0.0)
163
164 table = gtk.Table(2, 3)
165 table.set_row_spacings(4)
166 table.set_col_spacings(32)
167 alignment.add(table)
168 self.setMainWidget(alignment)
169
170 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
171 label = gtk.Label("Pilot _ID:")
172 label.set_use_underline(True)
173 labelAlignment.add(label)
174 table.attach(labelAlignment, 0, 1, 0, 1)
175
176 self._pilotID = gtk.Entry()
177 self._pilotID.connect("changed", self._setLoginButton)
178 self._pilotID.set_tooltip_text("Enter your MAVA pilot's ID. This "
179 "usually starts with a "
180 "'P' followed by 3 digits.")
181 table.attach(self._pilotID, 1, 2, 0, 1)
182 label.set_mnemonic_widget(self._pilotID)
183
184 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
185 label = gtk.Label("_Password:")
186 label.set_use_underline(True)
187 labelAlignment.add(label)
188 table.attach(labelAlignment, 0, 1, 1, 2)
189
190 self._password = gtk.Entry()
191 self._password.set_visibility(False)
192 self._password.connect("changed", self._setLoginButton)
193 self._password.set_tooltip_text("Enter the password for your pilot's ID")
194 table.attach(self._password, 1, 2, 1, 2)
195 label.set_mnemonic_widget(self._password)
196
197 self._rememberButton = gtk.CheckButton("_Remember password")
198 self._rememberButton.set_use_underline(True)
199 self._rememberButton.set_tooltip_text("If checked, your password will "
200 "be stored, so that you should "
201 "not have to enter it every time. "
202 "Note, however, that the password "
203 "is stored as text, and anybody "
204 "who can access your files will "
205 "be able to read it.")
206 table.attach(self._rememberButton, 1, 2, 2, 3, ypadding = 8)
207
208 self._loginButton = self.addButton("_Login", default = True)
209 self._loginButton.set_sensitive(False)
210 self._loginButton.connect("clicked", self._loginClicked)
211 self._loginButton.set_tooltip_text("Click to log in.")
212
213 config = self._wizard.gui.config
214 self._pilotID.set_text(config.pilotID)
215 self._password.set_text(config.password)
216 self._rememberButton.set_active(config.rememberPassword)
217
218 def _setLoginButton(self, entry):
219 """Set the login button's sensitivity.
220
221 The button is sensitive only if both the pilot ID and the password
222 fields contain values."""
223 self._loginButton.set_sensitive(self._pilotID.get_text()!="" and
224 self._password.get_text()!="")
225
226 def _loginClicked(self, button):
227 """Called when the login button was clicked."""
228 self._loginButton.set_sensitive(False)
229 gui = self._wizard.gui
230 gui.beginBusy("Logging in...")
231 gui.webHandler.login(self._loginResultCallback,
232 self._pilotID.get_text(),
233 self._password.get_text())
234
235 def _loginResultCallback(self, returned, result):
236 """The login result callback, called in the web handler's thread."""
237 gobject.idle_add(self._handleLoginResult, returned, result)
238
239 def _handleLoginResult(self, returned, result):
240 """Handle the login result."""
241 self._wizard.gui.endBusy()
242 self._loginButton.set_sensitive(True)
243 if returned:
244 if result.loggedIn:
245 config = self._wizard.gui.config
246
247 config.pilotID = self._pilotID.get_text()
248
249 rememberPassword = self._rememberButton.get_active()
250 config.password = self._password.get_text() if rememberPassword \
251 else ""
252
253 config.rememberPassword = rememberPassword
254
255 config.save()
256 self._wizard._loginResult = result
257 self._wizard.nextPage()
258 else:
259 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
260 buttons = BUTTONSTYPE_OK,
261 message_format =
262 "Invalid pilot's ID or password.")
263 dialog.format_secondary_markup("Check the ID and try to reenter"
264 " the password.")
265 dialog.run()
266 dialog.hide()
267 else:
268 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
269 buttons = BUTTONSTYPE_OK,
270 message_format =
271 "Failed to connect to the MAVA website.")
272 dialog.format_secondary_markup("Try again in a few minutes.")
273 dialog.run()
274 dialog.hide()
275
276#-----------------------------------------------------------------------------
277
278class FlightSelectionPage(Page):
279 """The page to select the flight."""
280 def __init__(self, wizard):
281 """Construct the flight selection page."""
282 super(FlightSelectionPage, self).__init__(wizard, "Flight selection",
283 "Select the flight you want "
284 "to perform.")
285
286
287 self._listStore = gtk.ListStore(str, str, str, str)
288 self._flightList = gtk.TreeView(self._listStore)
289 column = gtk.TreeViewColumn("Flight no.", gtk.CellRendererText(),
290 text = 1)
291 column.set_expand(True)
292 self._flightList.append_column(column)
293 column = gtk.TreeViewColumn("Departure time [UTC]", gtk.CellRendererText(),
294 text = 0)
295 column.set_expand(True)
296 self._flightList.append_column(column)
297 column = gtk.TreeViewColumn("From", gtk.CellRendererText(),
298 text = 2)
299 column.set_expand(True)
300 self._flightList.append_column(column)
301 column = gtk.TreeViewColumn("To", gtk.CellRendererText(),
302 text = 3)
303 column.set_expand(True)
304 self._flightList.append_column(column)
305
306 flightSelection = self._flightList.get_selection()
307 flightSelection.connect("changed", self._selectionChanged)
308
309 scrolledWindow = gtk.ScrolledWindow()
310 scrolledWindow.add(self._flightList)
311 scrolledWindow.set_size_request(400, -1)
312 scrolledWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
313 else gtk.POLICY_AUTOMATIC,
314 gtk.PolicyType.AUTOMATIC if pygobject
315 else gtk.POLICY_AUTOMATIC)
316 scrolledWindow.set_shadow_type(gtk.ShadowType.IN if pygobject
317 else gtk.SHADOW_IN)
318
319 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.0, xscale = 0.0, yscale = 1.0)
320 alignment.add(scrolledWindow)
321
322 self.setMainWidget(alignment)
323
324 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
325 self._button.set_use_stock(True)
326 self._button.set_sensitive(False)
327 self._button.connect("clicked", self._forwardClicked)
328
329 def activate(self):
330 """Fill the flight list."""
331 self._flightList.set_sensitive(True)
332 self._listStore.clear()
333 for flight in self._wizard.loginResult.flights:
334 self._listStore.append([str(flight.departureTime),
335 flight.callsign,
336 flight.departureICAO,
337 flight.arrivalICAO])
338
339 def finalize(self):
340 """Finalize the page."""
341 self._flightList.set_sensitive(False)
342
343 def _selectionChanged(self, selection):
344 """Called when the selection is changed."""
345 self._button.set_sensitive(selection.count_selected_rows()==1)
346
347 def _forwardClicked(self, button):
348 """Called when the forward button was clicked."""
349 if self._finalized:
350 self._wizard.jumpPage(self._nextDistance, finalize = False)
351 else:
352 selection = self._flightList.get_selection()
353 (listStore, iter) = selection.get_selected()
354 path = listStore.get_path(iter)
355 [index] = path.get_indices() if pygobject else path
356
357 flight = self._wizard.loginResult.flights[index]
358 self._wizard._bookedFlight = flight
359
360 self._updateDepartureGate()
361
362 def _updateDepartureGate(self):
363 """Update the departure gate for the booked flight."""
364 flight = self._wizard._bookedFlight
365 if flight.departureICAO=="LHBP":
366 self._wizard._getFleet(self._fleetRetrieved)
367 else:
368 self._nextDistance = 2
369 self._wizard.jumpPage(2)
370
371 def _fleetRetrieved(self, fleet):
372 """Called when the fleet has been retrieved."""
373 if fleet is None:
374 self._nextDistance = 2
375 self._wizard.jumpPage(2)
376 else:
377 plane = fleet[self._wizard._bookedFlight.tailNumber]
378 if plane is None:
379 self._nextDistance = 2
380 self._wizard.jumpPage(2)
381 elif plane.gateNumber is not None and \
382 not fleet.isGateConflicting(plane):
383 self._wizard._departureGate = plane.gateNumber
384 self._nextDistance = 2
385 self._wizard.jumpPage(2)
386 else:
387 self._nextDistance = 1
388 self._wizard.nextPage()
389
390#-----------------------------------------------------------------------------
391
392class GateSelectionPage(Page):
393 """Page to select a free gate at LHBP.
394
395 This page should be displayed only if we have fleet information!."""
396 def __init__(self, wizard):
397 """Construct the gate selection page."""
398 help = "The airplane's gate position is invalid.\n\n" \
399 "Select the gate from which you\n" \
400 "would like to begin the flight."
401 super(GateSelectionPage, self).__init__(wizard,
402 "LHBP gate selection",
403 help)
404
405 self._listStore = gtk.ListStore(str)
406 self._gateList = gtk.TreeView(self._listStore)
407 column = gtk.TreeViewColumn(None, gtk.CellRendererText(),
408 text = 0)
409 column.set_expand(True)
410 self._gateList.append_column(column)
411 self._gateList.set_headers_visible(False)
412
413 gateSelection = self._gateList.get_selection()
414 gateSelection.connect("changed", self._selectionChanged)
415
416 scrolledWindow = gtk.ScrolledWindow()
417 scrolledWindow.add(self._gateList)
418 scrolledWindow.set_size_request(50, -1)
419 scrolledWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
420 else gtk.POLICY_AUTOMATIC,
421 gtk.PolicyType.AUTOMATIC if pygobject
422 else gtk.POLICY_AUTOMATIC)
423 scrolledWindow.set_shadow_type(gtk.ShadowType.IN if pygobject
424 else gtk.SHADOW_IN)
425
426 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.0, xscale = 0.0, yscale = 1.0)
427 alignment.add(scrolledWindow)
428
429 self.setMainWidget(alignment)
430
431 button = self.addButton(gtk.STOCK_GO_BACK)
432 button.set_use_stock(True)
433 button.connect("clicked", self._backClicked)
434
435 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
436 self._button.set_use_stock(True)
437 self._button.set_sensitive(False)
438 self._button.connect("clicked", self._forwardClicked)
439
440 def activate(self):
441 """Fill the gate list."""
442 self._listStore.clear()
443 self._gateList.set_sensitive(True)
444 occupiedGateNumbers = self._wizard._fleet.getOccupiedGateNumbers()
445 for gateNumber in const.lhbpGateNumbers:
446 if gateNumber not in occupiedGateNumbers:
447 self._listStore.append([gateNumber])
448
449 def finalize(self):
450 """Finalize the page."""
451 self._gateList.set_sensitive(False)
452
453 def _selectionChanged(self, selection):
454 """Called when the selection is changed."""
455 self._button.set_sensitive(selection.count_selected_rows()==1)
456
457 def _backClicked(self, button):
458 """Called when the Back button is pressed."""
459 self.goBack()
460
461 def _forwardClicked(self, button):
462 """Called when the forward button is clicked."""
463 if not self._finalized:
464 selection = self._gateList.get_selection()
465 (listStore, iter) = selection.get_selected()
466 (gateNumber,) = listStore.get(iter, 0)
467
468 self._wizard._departureGate = gateNumber
469
470 #self._wizard._updatePlane(self._planeUpdated,
471 # self._wizard._bookedFlight.tailNumber,
472 # const.PLANE_HOME,
473 # gateNumber)
474
475 self._wizard.nextPage()
476
477 def _planeUpdated(self, success):
478 """Callback for the plane updating call."""
479 if success is None or success:
480 self._wizard.nextPage()
481 else:
482 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
483 buttons = BUTTONSTYPE_OK,
484 message_format = "Gate conflict detected again")
485 dialog.format_secondary_markup("Try to select a different gate.")
486 dialog.run()
487 dialog.hide()
488
489 self._wizard._getFleet(self._fleetRetrieved)
490
491 def _fleetRetrieved(self, fleet):
492 """Called when the fleet has been retrieved."""
493 if fleet is None:
494 self._wizard.nextPage()
495 else:
496 self.activate()
497
498#-----------------------------------------------------------------------------
499
500class ConnectPage(Page):
501 """Page which displays the departure airport and gate (if at LHBP)."""
502 def __init__(self, wizard):
503 """Construct the connect page."""
504 help = "Load the aircraft below into the simulator and park it\n" \
505 "at the given airport, at the gate below, if present.\n\n" \
506 "Then press the Connect button to connect to the simulator."
507 super(ConnectPage, self).__init__(wizard,
508 "Connect to the simulator",
509 help)
510
511 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
512 xscale = 0.0, yscale = 0.0)
513
514 table = gtk.Table(5, 2)
515 table.set_row_spacings(4)
516 table.set_col_spacings(16)
517 table.set_homogeneous(True)
518 alignment.add(table)
519 self.setMainWidget(alignment)
520
521 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
522 label = gtk.Label("Flight number:")
523 labelAlignment.add(label)
524 table.attach(labelAlignment, 0, 1, 0, 1)
525
526 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
527 self._flightNumber = gtk.Label()
528 self._flightNumber.set_width_chars(6)
529 self._flightNumber.set_alignment(0.0, 0.5)
530 labelAlignment.add(self._flightNumber)
531 table.attach(labelAlignment, 1, 2, 0, 1)
532
533 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
534 label = gtk.Label("Aircraft:")
535 labelAlignment.add(label)
536 table.attach(labelAlignment, 0, 1, 1, 2)
537
538 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
539 self._aircraft = gtk.Label()
540 self._aircraft.set_width_chars(25)
541 self._aircraft.set_alignment(0.0, 0.5)
542 labelAlignment.add(self._aircraft)
543 table.attach(labelAlignment, 1, 2, 1, 2)
544
545 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
546 label = gtk.Label("Tail number:")
547 labelAlignment.add(label)
548 table.attach(labelAlignment, 0, 1, 2, 3)
549
550 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
551 self._tailNumber = gtk.Label()
552 self._tailNumber.set_width_chars(6)
553 self._tailNumber.set_alignment(0.0, 0.5)
554 labelAlignment.add(self._tailNumber)
555 table.attach(labelAlignment, 1, 2, 2, 3)
556
557 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
558 label = gtk.Label("Airport:")
559 labelAlignment.add(label)
560 table.attach(labelAlignment, 0, 1, 3, 4)
561
562 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
563 self._departureICAO = gtk.Label()
564 self._departureICAO.set_width_chars(5)
565 self._departureICAO.set_alignment(0.0, 0.5)
566 labelAlignment.add(self._departureICAO)
567 table.attach(labelAlignment, 1, 2, 3, 4)
568
569 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
570 label = gtk.Label("Gate:")
571 labelAlignment.add(label)
572 table.attach(labelAlignment, 0, 1, 4, 5)
573
574 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
575 self._departureGate = gtk.Label()
576 self._departureGate.set_width_chars(5)
577 self._departureGate.set_alignment(0.0, 0.5)
578 labelAlignment.add(self._departureGate)
579 table.attach(labelAlignment, 1, 2, 4, 5)
580
581 button = self.addButton(gtk.STOCK_GO_BACK)
582 button.set_use_stock(True)
583 button.connect("clicked", self._backClicked)
584
585 self._button = self.addButton("_Connect", default = True)
586 self._button.set_use_underline(True)
587 self._clickedID = self._button.connect("clicked", self._connectClicked)
588
589 def activate(self):
590 """Setup the departure information."""
591 self._button.set_label("_Connect")
592 self._button.set_use_underline(True)
593 self._button.disconnect(self._clickedID)
594 self._clickedID = self._button.connect("clicked", self._connectClicked)
595
596 bookedFlight = self._wizard._bookedFlight
597
598 self._flightNumber.set_markup("<b>" + bookedFlight.callsign + "</b>")
599
600 aircraftType = acftTypeNames[bookedFlight.aircraftType]
601 self._aircraft.set_markup("<b>" + aircraftType + "</b>")
602
603 self._tailNumber.set_markup("<b>" + bookedFlight.tailNumber + "</b>")
604
605 icao = bookedFlight.departureICAO
606 self._departureICAO.set_markup("<b>" + icao + "</b>")
607 gate = self._wizard._departureGate
608 if gate!="-":
609 gate = "<b>" + gate + "</b>"
610 self._departureGate.set_markup(gate)
611
612 def finalize(self):
613 """Finalize the page."""
614 self._button.set_label(gtk.STOCK_GO_FORWARD)
615 self._button.set_use_stock(True)
616 self._button.disconnect(self._clickedID)
617 self._clickedID = self._button.connect("clicked", self._forwardClicked)
618
619 def _backClicked(self, button):
620 """Called when the Back button is pressed."""
621 self.goBack()
622
623 def _connectClicked(self, button):
624 """Called when the Connect button is pressed."""
625 self._wizard._connectSimulator()
626
627 def _forwardClicked(self, button):
628 """Called when the Forward button is pressed."""
629 self._wizard.nextPage()
630
631#-----------------------------------------------------------------------------
632
633class PayloadPage(Page):
634 """Page to allow setting up the payload."""
635 def __init__(self, wizard):
636 """Construct the page."""
637 help = "The briefing contains the weights below.\n" \
638 "Setup the cargo weight here and the payload weight in the simulator.\n\n" \
639 "You can also check here what the simulator reports as ZFW."
640
641 super(PayloadPage, self).__init__(wizard, "Payload", help)
642
643 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
644 xscale = 0.0, yscale = 0.0)
645
646 table = gtk.Table(7, 3)
647 table.set_row_spacings(4)
648 table.set_col_spacings(16)
649 table.set_homogeneous(False)
650 alignment.add(table)
651 self.setMainWidget(alignment)
652
653 label = gtk.Label("Crew:")
654 label.set_alignment(0.0, 0.5)
655 table.attach(label, 0, 1, 0, 1)
656
657 self._numCrew = gtk.Label()
658 self._numCrew.set_width_chars(6)
659 self._numCrew.set_alignment(1.0, 0.5)
660 table.attach(self._numCrew, 1, 2, 0, 1)
661
662 label = gtk.Label("Passengers:")
663 label.set_alignment(0.0, 0.5)
664 table.attach(label, 0, 1, 1, 2)
665
666 self._numPassengers = gtk.Label()
667 self._numPassengers.set_width_chars(6)
668 self._numPassengers.set_alignment(1.0, 0.5)
669 table.attach(self._numPassengers, 1, 2, 1, 2)
670
671 label = gtk.Label("Baggage:")
672 label.set_alignment(0.0, 0.5)
673 table.attach(label, 0, 1, 2, 3)
674
675 self._bagWeight = gtk.Label()
676 self._bagWeight.set_width_chars(6)
677 self._bagWeight.set_alignment(1.0, 0.5)
678 table.attach(self._bagWeight, 1, 2, 2, 3)
679
680 table.attach(gtk.Label("kg"), 2, 3, 2, 3)
681
682 label = gtk.Label("_Cargo:")
683 label.set_use_underline(True)
684 label.set_alignment(0.0, 0.5)
685 table.attach(label, 0, 1, 3, 4)
686
687 self._cargoWeight = gtk.Entry()
688 self._cargoWeight.set_width_chars(6)
689 self._cargoWeight.set_alignment(1.0)
690 self._cargoWeight.connect("changed", self._cargoWeightChanged)
691 self._cargoWeight.set_tooltip_text("The weight of the cargo for your flight.")
692 table.attach(self._cargoWeight, 1, 2, 3, 4)
693 self._cargoWeightValue = 0
694 label.set_mnemonic_widget(self._cargoWeight)
695
696 table.attach(gtk.Label("kg"), 2, 3, 3, 4)
697
698 label = gtk.Label("Mail:")
699 label.set_alignment(0.0, 0.5)
700 table.attach(label, 0, 1, 4, 5)
701
702 self._mailWeight = gtk.Label()
703 self._mailWeight.set_width_chars(6)
704 self._mailWeight.set_alignment(1.0, 0.5)
705 table.attach(self._mailWeight, 1, 2, 4, 5)
706
707 table.attach(gtk.Label("kg"), 2, 3, 4, 5)
708
709 label = gtk.Label("<b>Calculated ZFW:</b>")
710 label.set_alignment(0.0, 0.5)
711 label.set_use_markup(True)
712 table.attach(label, 0, 1, 5, 6)
713
714 self._calculatedZFW = gtk.Label()
715 self._calculatedZFW.set_width_chars(6)
716 self._calculatedZFW.set_alignment(1.0, 0.5)
717 table.attach(self._calculatedZFW, 1, 2, 5, 6)
718
719 table.attach(gtk.Label("kg"), 2, 3, 5, 6)
720
721 self._zfwButton = gtk.Button("_ZFW from FS:")
722 self._zfwButton.set_use_underline(True)
723 self._zfwButton.connect("clicked", self._zfwRequested)
724 table.attach(self._zfwButton, 0, 1, 6, 7)
725
726 self._simulatorZFW = gtk.Label("-")
727 self._simulatorZFW.set_width_chars(6)
728 self._simulatorZFW.set_alignment(1.0, 0.5)
729 table.attach(self._simulatorZFW, 1, 2, 6, 7)
730 self._simulatorZFWValue = None
731
732 table.attach(gtk.Label("kg"), 2, 3, 6, 7)
733
734 self._backButton = self.addButton(gtk.STOCK_GO_BACK)
735 self._backButton.set_use_stock(True)
736 self._backButton.connect("clicked", self._backClicked)
737
738 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
739 self._button.set_use_stock(True)
740 self._button.connect("clicked", self._forwardClicked)
741
742 def activate(self):
743 """Setup the information."""
744 bookedFlight = self._wizard._bookedFlight
745 self._numCrew.set_text(str(bookedFlight.numCrew))
746 self._numPassengers.set_text(str(bookedFlight.numPassengers))
747 self._bagWeight.set_text(str(bookedFlight.bagWeight))
748 self._cargoWeightValue = bookedFlight.cargoWeight
749 self._cargoWeight.set_text(str(bookedFlight.cargoWeight))
750 self._cargoWeight.set_sensitive(True)
751 self._mailWeight.set_text(str(bookedFlight.mailWeight))
752 self._zfwButton.set_sensitive(True)
753 self._updateCalculatedZFW()
754
755 def finalize(self):
756 """Finalize the payload page."""
757 self._cargoWeight.set_sensitive(False)
758 self._zfwButton.set_sensitive(False)
759
760 def _calculateZFW(self):
761 """Calculate the ZFW value."""
762 zfw = self._wizard.gui._flight.aircraft.dow
763 bookedFlight = self._wizard._bookedFlight
764 zfw += (bookedFlight.numCrew + bookedFlight.numPassengers) * 82
765 zfw += bookedFlight.bagWeight
766 zfw += self._cargoWeightValue
767 zfw += bookedFlight.mailWeight
768 return zfw
769
770 def _updateCalculatedZFW(self):
771 """Update the calculated ZFW"""
772 zfw = self._calculateZFW()
773
774 markupBegin = "<b>"
775 markupEnd = "</b>"
776 if self._simulatorZFWValue is not None and \
777 PayloadChecker.isZFWFaulty(self._simulatorZFWValue, zfw):
778 markupBegin += '<span foreground="red">'
779 markupEnd = "</span>" + markupEnd
780 self._calculatedZFW.set_markup(markupBegin + str(zfw) + markupEnd)
781
782 def _cargoWeightChanged(self, entry):
783 """Called when the cargo weight has changed."""
784 text = self._cargoWeight.get_text()
785 if text=="":
786 self._cargoWeightValue = 0
787 else:
788 try:
789 self._cargoWeightValue = int(text)
790 except:
791 self._cargoWeight.set_text(str(self._cargoWeightValue))
792 self._updateCalculatedZFW()
793
794 def _zfwRequested(self, button):
795 """Called when the ZFW is requested from the simulator."""
796 self._zfwButton.set_sensitive(False)
797 self._backButton.set_sensitive(False)
798 self._button.set_sensitive(False)
799 gui = self._wizard.gui
800 gui.beginBusy("Querying ZFW...")
801 gui.simulator.requestZFW(self._handleZFW)
802
803 def _handleZFW(self, zfw):
804 """Called when the ZFW value is retrieved."""
805 gobject.idle_add(self._processZFW, zfw)
806
807 def _processZFW(self, zfw):
808 """Process the given ZFW value received from the simulator."""
809 self._wizard.gui.endBusy()
810 self._zfwButton.set_sensitive(True)
811 self._backButton.set_sensitive(True)
812 self._button.set_sensitive(True)
813 self._simulatorZFWValue = zfw
814 self._simulatorZFW.set_text("%.0f" % (zfw,))
815 self._updateCalculatedZFW()
816
817 def _forwardClicked(self, button):
818 """Called when the forward button is clicked."""
819 if not self._finalized:
820 self._wizard._zfw = self._calculateZFW()
821 self._wizard.nextPage()
822
823 def _backClicked(self, button):
824 """Called when the Back button is pressed."""
825 self.goBack()
826
827#-----------------------------------------------------------------------------
828
829class TimePage(Page):
830 """Page displaying the departure and arrival times and allows querying the
831 current time from the flight simulator."""
832 def __init__(self, wizard):
833 help = "The departure and arrival times are displayed below in UTC.\n\n" \
834 "You can also query the current UTC time from the simulator.\n" \
835 "Ensure that you have enough time to properly prepare for the flight."
836
837 super(TimePage, self).__init__(wizard, "Time", help)
838
839 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
840 xscale = 0.0, yscale = 0.0)
841
842 table = gtk.Table(3, 2)
843 table.set_row_spacings(4)
844 table.set_col_spacings(16)
845 table.set_homogeneous(False)
846 alignment.add(table)
847 self.setMainWidget(alignment)
848
849 label = gtk.Label("Departure:")
850 label.set_alignment(0.0, 0.5)
851 table.attach(label, 0, 1, 0, 1)
852
853 self._departure = gtk.Label()
854 self._departure.set_alignment(0.0, 0.5)
855 table.attach(self._departure, 1, 2, 0, 1)
856
857 label = gtk.Label("Arrival:")
858 label.set_alignment(0.0, 0.5)
859 table.attach(label, 0, 1, 1, 2)
860
861 self._arrival = gtk.Label()
862 self._arrival.set_alignment(0.0, 0.5)
863 table.attach(self._arrival, 1, 2, 1, 2)
864
865 self._timeButton = gtk.Button("_Time from FS:")
866 self._timeButton.set_use_underline(True)
867 self._timeButton.connect("clicked", self._timeRequested)
868 table.attach(self._timeButton, 0, 1, 2, 3)
869
870 self._simulatorTime = gtk.Label("-")
871 self._simulatorTime.set_alignment(0.0, 0.5)
872 table.attach(self._simulatorTime, 1, 2, 2, 3)
873
874 self._backButton = self.addButton(gtk.STOCK_GO_BACK)
875 self._backButton.set_use_stock(True)
876 self._backButton.connect("clicked", self._backClicked)
877
878 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
879 self._button.set_use_stock(True)
880 self._button.connect("clicked", self._forwardClicked)
881
882 def activate(self):
883 """Activate the page."""
884 self._timeButton.set_sensitive(True)
885 bookedFlight = self._wizard._bookedFlight
886 self._departure.set_text(str(bookedFlight.departureTime.time()))
887 self._arrival.set_text(str(bookedFlight.arrivalTime.time()))
888
889 def finalize(self):
890 """Finalize the page."""
891 self._timeButton.set_sensitive(False)
892
893 def _timeRequested(self, button):
894 """Request the time from the simulator."""
895 self._timeButton.set_sensitive(False)
896 self._backButton.set_sensitive(False)
897 self._button.set_sensitive(False)
898 self._wizard.gui.beginBusy("Querying time...")
899 self._wizard.gui.simulator.requestTime(self._handleTime)
900
901 def _handleTime(self, timestamp):
902 """Handle the result of a time retrieval."""
903 gobject.idle_add(self._processTime, timestamp)
904
905 def _processTime(self, timestamp):
906 """Process the given time."""
907 self._wizard.gui.endBusy()
908 self._timeButton.set_sensitive(True)
909 self._backButton.set_sensitive(True)
910 self._button.set_sensitive(True)
911 tm = time.gmtime(timestamp)
912 t = datetime.time(tm.tm_hour, tm.tm_min, tm.tm_sec)
913 self._simulatorTime.set_text(str(t))
914
915 ts = tm.tm_hour * 3600 + tm.tm_min * 60 + tm.tm_sec
916 dt = self._wizard._bookedFlight.departureTime.time()
917 dts = dt.hour * 3600 + dt.minute * 60 + dt.second
918 diff = dts-ts
919
920 markupBegin = ""
921 markupEnd = ""
922 if diff < 0:
923 markupBegin = '<b><span foreground="red">'
924 markupEnd = '</span></b>'
925 elif diff < 3*60 or diff > 30*60:
926 markupBegin = '<b><span foreground="orange">'
927 markupEnd = '</span></b>'
928
929 self._departure.set_markup(markupBegin + str(dt) + markupEnd)
930
931 def _backClicked(self, button):
932 """Called when the Back button is pressed."""
933 self.goBack()
934
935 def _forwardClicked(self, button):
936 """Called when the forward button is clicked."""
937 self._wizard.nextPage()
938
939#-----------------------------------------------------------------------------
940
941class RoutePage(Page):
942 """The page containing the route and the flight level."""
943 def __init__(self, wizard):
944 help = "Set your cruise flight level below, and\n" \
945 "if necessary, edit the flight plan."
946
947 super(RoutePage, self).__init__(wizard, "Route", help)
948
949 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
950 xscale = 0.0, yscale = 0.0)
951
952 mainBox = gtk.VBox()
953 alignment.add(mainBox)
954 self.setMainWidget(alignment)
955
956 levelBox = gtk.HBox()
957
958 label = gtk.Label("_Cruise level")
959 label.set_use_underline(True)
960 levelBox.pack_start(label, True, True, 0)
961
962 self._cruiseLevel = gtk.SpinButton()
963 self._cruiseLevel.set_increments(step = 10, page = 100)
964 self._cruiseLevel.set_range(min = 50, max = 500)
965 self._cruiseLevel.set_value(240)
966 self._cruiseLevel.set_tooltip_text("The cruise flight level.")
967 self._cruiseLevel.set_numeric(True)
968 self._cruiseLevel.connect("value-changed", self._cruiseLevelChanged)
969 label.set_mnemonic_widget(self._cruiseLevel)
970
971 levelBox.pack_start(self._cruiseLevel, False, False, 8)
972
973 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
974 xscale = 0.0, yscale = 0.0)
975 alignment.add(levelBox)
976
977 mainBox.pack_start(alignment, False, False, 0)
978
979
980 routeBox = gtk.VBox()
981
982 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
983 xscale = 0.0, yscale = 0.0)
984 label = gtk.Label("_Route")
985 label.set_use_underline(True)
986 alignment.add(label)
987 routeBox.pack_start(alignment, True, True, 0)
988
989 routeWindow = gtk.ScrolledWindow()
990 routeWindow.set_size_request(400, 80)
991 routeWindow.set_shadow_type(gtk.ShadowType.IN if pygobject
992 else gtk.SHADOW_IN)
993 routeWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
994 else gtk.POLICY_AUTOMATIC,
995 gtk.PolicyType.AUTOMATIC if pygobject
996 else gtk.POLICY_AUTOMATIC)
997
998 self._route = gtk.TextView()
999 self._route.set_tooltip_text("The planned flight route.")
1000 self._route.get_buffer().connect("changed", self._routeChanged)
1001 routeWindow.add(self._route)
1002
1003 label.set_mnemonic_widget(self._route)
1004 routeBox.pack_start(routeWindow, True, True, 0)
1005
1006 mainBox.pack_start(routeBox, True, True, 8)
1007
1008 self._backButton = self.addButton(gtk.STOCK_GO_BACK)
1009 self._backButton.set_use_stock(True)
1010 self._backButton.connect("clicked", self._backClicked)
1011
1012 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
1013 self._button.set_use_stock(True)
1014 self._button.connect("clicked", self._forwardClicked)
1015
1016 def activate(self):
1017 """Setup the route from the booked flight."""
1018 self._route.set_sensitive(True)
1019 self._cruiseLevel.set_sensitive(True)
1020 self._route.get_buffer().set_text(self._wizard._bookedFlight.route)
1021 self._updateForwardButton()
1022
1023 def finalize(self):
1024 """Finalize the page."""
1025 self._route.set_sensitive(False)
1026 self._cruiseLevel.set_sensitive(False)
1027
1028 def _getRoute(self):
1029 """Get the text of the route."""
1030 buffer = self._route.get_buffer()
1031 return buffer.get_text(buffer.get_start_iter(),
1032 buffer.get_end_iter(), True)
1033
1034 def _updateForwardButton(self):
1035 """Update the sensitivity of the forward button."""
1036 self._button.set_sensitive(self._cruiseLevel.get_value_as_int()>=50 and \
1037 self._getRoute()!="")
1038
1039 def _cruiseLevelChanged(self, spinButton):
1040 """Called when the cruise level has changed."""
1041 self._updateForwardButton()
1042
1043 def _routeChanged(self, textBuffer):
1044 """Called when the route has changed."""
1045 self._updateForwardButton()
1046
1047 def _backClicked(self, button):
1048 """Called when the Back button is pressed."""
1049 self.goBack()
1050
1051 def _forwardClicked(self, button):
1052 """Called when the Forward button is clicked."""
1053 if self._finalized:
1054 self._wizard.nextPage()
1055 else:
1056 self._wizard._cruiseAltitude = self._cruiseLevel.get_value_as_int() * 100
1057 self._wizard._route = self._getRoute()
1058
1059 self._backButton.set_sensitive(False)
1060 self._button.set_sensitive(False)
1061 self._cruiseLevel.set_sensitive(False)
1062 self._route.set_sensitive(False)
1063
1064 bookedFlight = self._wizard._bookedFlight
1065 self._wizard.gui.beginBusy("Downloading NOTAMs...")
1066 self._wizard.gui.webHandler.getNOTAMs(self._notamsCallback,
1067 bookedFlight.departureICAO,
1068 bookedFlight.arrivalICAO)
1069
1070 def _notamsCallback(self, returned, result):
1071 """Callback for the NOTAMs."""
1072 gobject.idle_add(self._handleNOTAMs, returned, result)
1073
1074 def _handleNOTAMs(self, returned, result):
1075 """Handle the NOTAMs."""
1076 if returned:
1077 self._wizard._departureNOTAMs = result.departureNOTAMs
1078 self._wizard._arrivalNOTAMs = result.arrivalNOTAMs
1079 else:
1080 self._wizard._departureNOTAMs = None
1081 self._wizard._arrivalNOTAMs = None
1082
1083 bookedFlight = self._wizard._bookedFlight
1084 self._wizard.gui.beginBusy("Downloading METARs...")
1085 self._wizard.gui.webHandler.getMETARs(self._metarsCallback,
1086 [bookedFlight.departureICAO,
1087 bookedFlight.arrivalICAO])
1088
1089 def _metarsCallback(self, returned, result):
1090 """Callback for the METARs."""
1091 gobject.idle_add(self._handleMETARs, returned, result)
1092
1093 def _handleMETARs(self, returned, result):
1094 """Handle the METARs."""
1095 self._wizard._departureMETAR = None
1096 self._wizard._arrivalMETAR = None
1097 bookedFlight = self._wizard._bookedFlight
1098 if returned:
1099 if bookedFlight.departureICAO in result.metars:
1100 self._wizard._departureMETAR = result.metars[bookedFlight.departureICAO]
1101 if bookedFlight.arrivalICAO in result.metars:
1102 self._wizard._arrivalMETAR = result.metars[bookedFlight.arrivalICAO]
1103
1104 self._wizard.gui.endBusy()
1105 self._backButton.set_sensitive(True)
1106 self._button.set_sensitive(True)
1107 self._wizard.nextPage()
1108
1109#-----------------------------------------------------------------------------
1110
1111class BriefingPage(Page):
1112 """Page for the briefing."""
1113 def __init__(self, wizard, departure):
1114 """Construct the briefing page."""
1115 self._departure = departure
1116
1117 title = "Briefing (%d/2): %s" % (1 if departure else 2,
1118 "departure" if departure
1119 else "arrival")
1120
1121 help = "Read carefully the NOTAMs and METAR below."
1122
1123 super(BriefingPage, self).__init__(wizard, title, help)
1124
1125 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
1126 xscale = 1.0, yscale = 1.0)
1127
1128 mainBox = gtk.VBox()
1129 alignment.add(mainBox)
1130 self.setMainWidget(alignment)
1131
1132 self._notamsFrame = gtk.Frame()
1133 self._notamsFrame.set_label("LHBP NOTAMs")
1134 scrolledWindow = gtk.ScrolledWindow()
1135 scrolledWindow.set_size_request(-1, 128)
1136 scrolledWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
1137 else gtk.POLICY_AUTOMATIC,
1138 gtk.PolicyType.AUTOMATIC if pygobject
1139 else gtk.POLICY_AUTOMATIC)
1140 self._notams = gtk.TextView()
1141 self._notams.set_editable(False)
1142 self._notams.set_accepts_tab(False)
1143 self._notams.set_wrap_mode(gtk.WrapMode.WORD if pygobject else gtk.WRAP_WORD)
1144 scrolledWindow.add(self._notams)
1145 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
1146 xscale = 1.0, yscale = 1.0)
1147 alignment.set_padding(padding_top = 4, padding_bottom = 0,
1148 padding_left = 0, padding_right = 0)
1149 alignment.add(scrolledWindow)
1150 self._notamsFrame.add(alignment)
1151 mainBox.pack_start(self._notamsFrame, True, True, 4)
1152
1153 self._metarFrame = gtk.Frame()
1154 self._metarFrame.set_label("LHBP METAR")
1155 scrolledWindow = gtk.ScrolledWindow()
1156 scrolledWindow.set_size_request(-1, 32)
1157 scrolledWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
1158 else gtk.POLICY_AUTOMATIC,
1159 gtk.PolicyType.AUTOMATIC if pygobject
1160 else gtk.POLICY_AUTOMATIC)
1161 self._metar = gtk.TextView()
1162 self._metar.set_editable(False)
1163 self._metar.set_accepts_tab(False)
1164 self._metar.set_wrap_mode(gtk.WrapMode.WORD if pygobject else gtk.WRAP_WORD)
1165 scrolledWindow.add(self._metar)
1166 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
1167 xscale = 1.0, yscale = 1.0)
1168 alignment.set_padding(padding_top = 4, padding_bottom = 0,
1169 padding_left = 0, padding_right = 0)
1170 alignment.add(scrolledWindow)
1171 self._metarFrame.add(alignment)
1172 mainBox.pack_start(self._metarFrame, True, True, 4)
1173
1174 button = self.addButton(gtk.STOCK_GO_BACK)
1175 button.set_use_stock(True)
1176 button.connect("clicked", self._backClicked)
1177
1178 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
1179 self._button.set_use_stock(True)
1180 self._button.connect("clicked", self._forwardClicked)
1181
1182 def activate(self):
1183 """Activate the page."""
1184 if not self._departure:
1185 self._button.set_label("I have read the briefing and am ready to fly!")
1186 self._button.set_use_stock(False)
1187
1188 bookedFlight = self._wizard._bookedFlight
1189
1190 icao = bookedFlight.departureICAO if self._departure \
1191 else bookedFlight.arrivalICAO
1192 notams = self._wizard._departureNOTAMs if self._departure \
1193 else self._wizard._arrivalNOTAMs
1194 metar = self._wizard._departureMETAR if self._departure \
1195 else self._wizard._arrivalMETAR
1196
1197 self._notamsFrame.set_label(icao + " NOTAMs")
1198 buffer = self._notams.get_buffer()
1199 if notams is None:
1200 buffer.set_text("Could not download NOTAMs")
1201 else:
1202 s = ""
1203 for notam in notams:
1204 s += str(notam.begin)
1205 if notam.end is not None:
1206 s += " - " + str(notam.end)
1207 elif notam.permanent:
1208 s += " - PERMANENT"
1209 s += "\n"
1210 if notam.repeatCycle:
1211 s += "Repeat cycle: " + notam.repeatCycle + "\n"
1212 s += notam.notice + "\n"
1213 s += "-------------------- * --------------------\n"
1214 buffer.set_text(s)
1215
1216 self._metarFrame.set_label(icao + " METAR")
1217 buffer = self._metar.get_buffer()
1218 if metar is None:
1219 buffer.set_text("Could not download METAR")
1220 else:
1221 buffer.set_text(metar)
1222
1223 def finalize(self):
1224 """Finalize the page."""
1225 if not self._departure:
1226 self._button.set_use_stock(True)
1227 self._button.set_label(gtk.STOCK_GO_FORWARD)
1228
1229 def _backClicked(self, button):
1230 """Called when the Back button is pressed."""
1231 self.goBack()
1232
1233 def _forwardClicked(self, button):
1234 """Called when the forward button is clicked."""
1235 if not self._departure:
1236 if not self._finalized:
1237 self._wizard.gui.startMonitoring()
1238 self.finalize()
1239 self._finalized = True
1240
1241 self._wizard.nextPage()
1242
1243#-----------------------------------------------------------------------------
1244
1245class TakeoffPage(Page):
1246 """Page for entering the takeoff data."""
1247 def __init__(self, wizard):
1248 """Construct the takeoff page."""
1249 help = "Enter the runway and SID used, as well as the speeds."
1250
1251 super(TakeoffPage, self).__init__(wizard, "Takeoff", help)
1252
1253 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
1254 xscale = 0.0, yscale = 0.0)
1255
1256 table = gtk.Table(5, 3)
1257 table.set_row_spacings(4)
1258 table.set_col_spacings(16)
1259 table.set_homogeneous(False)
1260 alignment.add(table)
1261 self.setMainWidget(alignment)
1262
1263 label = gtk.Label("Run_way:")
1264 label.set_use_underline(True)
1265 label.set_alignment(0.0, 0.5)
1266 table.attach(label, 0, 1, 0, 1)
1267
1268 self._runway = gtk.Entry()
1269 self._runway.set_width_chars(10)
1270 self._runway.set_tooltip_text("The runway the takeoff is performed from.")
1271 self._runway.connect("changed", self._updateForwardButton)
1272 table.attach(self._runway, 1, 2, 0, 1)
1273 label.set_mnemonic_widget(self._runway)
1274
1275 label = gtk.Label("_SID:")
1276 label.set_use_underline(True)
1277 label.set_alignment(0.0, 0.5)
1278 table.attach(label, 0, 1, 1, 2)
1279
1280 self._sid = gtk.Entry()
1281 self._sid.set_width_chars(10)
1282 self._sid.set_tooltip_text("The name of the Standard Instrument Deparature procedure followed.")
1283 self._sid.connect("changed", self._updateForwardButton)
1284 table.attach(self._sid, 1, 2, 1, 2)
1285 label.set_mnemonic_widget(self._sid)
1286
1287 label = gtk.Label("V<sub>_1</sub>:")
1288 label.set_use_markup(True)
1289 label.set_use_underline(True)
1290 label.set_alignment(0.0, 0.5)
1291 table.attach(label, 0, 1, 2, 3)
1292
1293 self._v1 = gtk.SpinButton()
1294 self._v1.set_increments(step = 1, page = 10)
1295 self._v1.set_range(min = 50, max = 300)
1296 self._v1.set_value(100)
1297 self._v1.set_numeric(True)
1298 self._v1.set_tooltip_markup("The takeoff decision speed in knots.")
1299 self._v1.connect("changed", self._updateForwardButton)
1300 table.attach(self._v1, 1, 2, 2, 3)
1301 label.set_mnemonic_widget(self._v1)
1302
1303 table.attach(gtk.Label("knots"), 2, 3, 2, 3)
1304
1305 label = gtk.Label("V<sub>_r</sub>:")
1306 label.set_use_markup(True)
1307 label.set_use_underline(True)
1308 label.set_alignment(0.0, 0.5)
1309 table.attach(label, 0, 1, 3, 4)
1310
1311 self._vr = gtk.SpinButton()
1312 self._vr.set_increments(step = 1, page = 10)
1313 self._vr.set_range(min = 50, max = 300)
1314 self._vr.set_value(110)
1315 self._vr.set_numeric(True)
1316 self._vr.set_tooltip_markup("The takeoff rotation speed in knots.")
1317 self._vr.connect("changed", self._updateForwardButton)
1318 table.attach(self._vr, 1, 2, 3, 4)
1319 label.set_mnemonic_widget(self._vr)
1320
1321 table.attach(gtk.Label("knots"), 2, 3, 3, 4)
1322
1323 label = gtk.Label("V<sub>_2</sub>:")
1324 label.set_use_markup(True)
1325 label.set_use_underline(True)
1326 label.set_alignment(0.0, 0.5)
1327 table.attach(label, 0, 1, 4, 5)
1328
1329 self._v2 = gtk.SpinButton()
1330 self._v2.set_increments(step = 1, page = 10)
1331 self._v2.set_range(min = 50, max = 300)
1332 self._v2.set_value(120)
1333 self._v2.set_numeric(True)
1334 self._v2.set_tooltip_markup("The takeoff safety speed in knots.")
1335 self._v2.connect("changed", self._updateForwardButton)
1336 table.attach(self._v2, 1, 2, 4, 5)
1337 label.set_mnemonic_widget(self._v2)
1338
1339 table.attach(gtk.Label("knots"), 2, 3, 4, 5)
1340
1341 button = self.addButton(gtk.STOCK_GO_BACK)
1342 button.set_use_stock(True)
1343 button.connect("clicked", self._backClicked)
1344
1345 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
1346 self._button.set_use_stock(True)
1347 self._button.connect("clicked", self._forwardClicked)
1348
1349 def activate(self):
1350 """Activate the page."""
1351 self._runway.set_text("")
1352 self._runway.set_sensitive(True)
1353 self._sid.set_text("")
1354 self._sid.set_sensitive(True)
1355 self._v1.set_sensitive(True)
1356 self._vr.set_sensitive(True)
1357 self._v2.set_sensitive(True)
1358 self._updateForwardButton()
1359
1360 def finalize(self):
1361 """Finalize the page."""
1362 self._runway.set_sensitive(False)
1363 self._sid.set_sensitive(False)
1364 self._v1.set_sensitive(False)
1365 self._vr.set_sensitive(False)
1366 self._v2.set_sensitive(False)
1367
1368 flight = self._wizard.gui.flight
1369 flight.v1 = self._v1.get_value_as_int()
1370 flight.vr = self._vr.get_value_as_int()
1371 flight.v2 = self._v2.get_value_as_int()
1372
1373 def _updateForwardButton(self, widget = None):
1374 """Update the Forward buttons sensitivity."""
1375 self._button.set_sensitive(self._runway.get_text()!="" and
1376 self._sid.get_text()!="" and
1377 self._v1.get_value_as_int()<=self._vr.get_value_as_int() and
1378 self._vr.get_value_as_int()<=self._v2.get_value_as_int())
1379
1380 def _backClicked(self, button):
1381 """Called when the Back button is pressed."""
1382 self.goBack()
1383
1384 def _forwardClicked(self, button):
1385 """Called when the forward button is clicked."""
1386 self._wizard.nextPage()
1387
1388#-----------------------------------------------------------------------------
1389
1390class LandingPage(Page):
1391 """Page for entering landing data."""
1392 def __init__(self, wizard):
1393 """Construct the landing page."""
1394 help = "Enter the STAR and/or transition, runway,\n" \
1395 "approach type and V<sub>ref</sub> used."
1396
1397 super(LandingPage, self).__init__(wizard, "Landing", help)
1398
1399 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
1400 xscale = 0.0, yscale = 0.0)
1401
1402 table = gtk.Table(5, 4)
1403 table.set_row_spacings(4)
1404 table.set_col_spacings(16)
1405 table.set_homogeneous(False)
1406 alignment.add(table)
1407 self.setMainWidget(alignment)
1408
1409 self._starButton = gtk.CheckButton()
1410 self._starButton.connect("clicked", self._starButtonClicked)
1411 table.attach(self._starButton, 0, 1, 0, 1)
1412
1413 label = gtk.Label("_STAR:")
1414 label.set_use_underline(True)
1415 label.set_alignment(0.0, 0.5)
1416 table.attach(label, 1, 2, 0, 1)
1417
1418 self._star = gtk.Entry()
1419 self._star.set_width_chars(10)
1420 self._star.set_tooltip_text("The name of Standard Terminal Arrival Route followed.")
1421 self._star.connect("changed", self._updateForwardButton)
1422 self._star.set_sensitive(False)
1423 table.attach(self._star, 2, 3, 0, 1)
1424 label.set_mnemonic_widget(self._starButton)
1425
1426 self._transitionButton = gtk.CheckButton()
1427 self._transitionButton.connect("clicked", self._transitionButtonClicked)
1428 table.attach(self._transitionButton, 0, 1, 1, 2)
1429
1430 label = gtk.Label("_Transition:")
1431 label.set_use_underline(True)
1432 label.set_alignment(0.0, 0.5)
1433 table.attach(label, 1, 2, 1, 2)
1434
1435 self._transition = gtk.Entry()
1436 self._transition.set_width_chars(10)
1437 self._transition.set_tooltip_text("The name of transition executed or VECTORS if vectored by ATC.")
1438 self._transition.connect("changed", self._updateForwardButton)
1439 self._transition.set_sensitive(False)
1440 table.attach(self._transition, 2, 3, 1, 2)
1441 label.set_mnemonic_widget(self._transitionButton)
1442
1443 label = gtk.Label("Run_way:")
1444 label.set_use_underline(True)
1445 label.set_alignment(0.0, 0.5)
1446 table.attach(label, 1, 2, 2, 3)
1447
1448 self._runway = gtk.Entry()
1449 self._runway.set_width_chars(10)
1450 self._runway.set_tooltip_text("The runway the landing is performed on.")
1451 self._runway.connect("changed", self._updateForwardButton)
1452 table.attach(self._runway, 2, 3, 2, 3)
1453 label.set_mnemonic_widget(self._runway)
1454
1455 label = gtk.Label("_Approach type:")
1456 label.set_use_underline(True)
1457 label.set_alignment(0.0, 0.5)
1458 table.attach(label, 1, 2, 3, 4)
1459
1460 self._approachType = gtk.Entry()
1461 self._approachType.set_width_chars(10)
1462 self._approachType.set_tooltip_text("The type of the approach, e.g. ILS or VISUAL.")
1463 self._approachType.connect("changed", self._updateForwardButton)
1464 table.attach(self._approachType, 2, 3, 3, 4)
1465 label.set_mnemonic_widget(self._approachType)
1466
1467 label = gtk.Label("V<sub>_ref</sub>:")
1468 label.set_use_markup(True)
1469 label.set_use_underline(True)
1470 label.set_alignment(0.0, 0.5)
1471 table.attach(label, 1, 2, 5, 6)
1472
1473 self._vref = gtk.SpinButton()
1474 self._vref.set_increments(step = 1, page = 10)
1475 self._vref.set_range(min = 50, max = 300)
1476 self._vref.set_value(140)
1477 self._vref.set_numeric(True)
1478 self._vref.set_tooltip_markup("The approach reference speed in knots.")
1479 table.attach(self._vref, 2, 3, 5, 6)
1480 label.set_mnemonic_widget(self._vref)
1481
1482 table.attach(gtk.Label("knots"), 3, 4, 5, 6)
1483
1484 button = self.addButton(gtk.STOCK_GO_BACK)
1485 button.set_use_stock(True)
1486 button.connect("clicked", self._backClicked)
1487
1488 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
1489 self._button.set_use_stock(True)
1490 self._button.connect("clicked", self._forwardClicked)
1491
1492 # These are needed for correct size calculations
1493 self._starButton.set_active(True)
1494 self._transitionButton.set_active(True)
1495
1496 def activate(self):
1497 """Called when the page is activated."""
1498 self._starButton.set_sensitive(True)
1499 self._starButton.set_active(False)
1500 self._star.set_text("")
1501
1502 self._transitionButton.set_sensitive(True)
1503 self._transitionButton.set_active(False)
1504 self._transition.set_text("")
1505
1506 self._runway.set_text("")
1507 self._runway.set_sensitive(True)
1508
1509 self._approachType.set_text("")
1510 self._approachType.set_sensitive(True)
1511
1512 self._vref.set_value(140)
1513 self._vref.set_sensitive(True)
1514
1515 self._updateForwardButton()
1516
1517 def finalize(self):
1518 """Finalize the page."""
1519 self._starButton.set_sensitive(False)
1520 self._star.set_sensitive(False)
1521
1522 self._transitionButton.set_sensitive(False)
1523 self._transition.set_sensitive(False)
1524
1525 self._runway.set_sensitive(False)
1526
1527 self._approachType.set_sensitive(False)
1528
1529 self._vref.set_sensitive(False)
1530
1531 def _starButtonClicked(self, button):
1532 """Called when the STAR button is clicked."""
1533 active = button.get_active()
1534 self._star.set_sensitive(active)
1535 if active:
1536 self._star.grab_focus()
1537 self._updateForwardButton()
1538
1539 def _transitionButtonClicked(self, button):
1540 """Called when the Transition button is clicked."""
1541 active = button.get_active()
1542 self._transition.set_sensitive(active)
1543 if active:
1544 self._transition.grab_focus()
1545 self._updateForwardButton()
1546
1547 def _updateForwardButton(self, widget = None):
1548 """Update the sensitivity of the forward button."""
1549 sensitive = (self._starButton.get_active() or \
1550 self._transitionButton.get_active()) and \
1551 (self._star.get_text()!="" or
1552 not self._starButton.get_active()) and \
1553 (self._transition.get_text()!="" or
1554 not self._transitionButton.get_active()) and \
1555 self._runway.get_text()!="" and \
1556 self._approachType.get_text()!=""
1557 self._button.set_sensitive(sensitive)
1558
1559 def _backClicked(self, button):
1560 """Called when the Back button is pressed."""
1561 self.goBack()
1562
1563 def _forwardClicked(self, button):
1564 """Called when the forward button is clicked."""
1565 #self._wizard.nextPage()
1566 self.finalize()
1567
1568#-----------------------------------------------------------------------------
1569
1570class Wizard(gtk.VBox):
1571 """The flight wizard."""
1572 def __init__(self, gui):
1573 """Construct the wizard."""
1574 super(Wizard, self).__init__()
1575
1576 self.gui = gui
1577
1578 self._pages = []
1579 self._currentPage = None
1580
1581 self._pages.append(LoginPage(self))
1582 self._pages.append(FlightSelectionPage(self))
1583 self._pages.append(GateSelectionPage(self))
1584 self._pages.append(ConnectPage(self))
1585 self._pages.append(PayloadPage(self))
1586 self._pages.append(TimePage(self))
1587 self._pages.append(RoutePage(self))
1588 self._pages.append(BriefingPage(self, True))
1589 self._pages.append(BriefingPage(self, False))
1590 self._pages.append(TakeoffPage(self))
1591 self._pages.append(LandingPage(self))
1592
1593 maxWidth = 0
1594 maxHeight = 0
1595 for page in self._pages:
1596 page.show_all()
1597 pageSizeRequest = page.size_request()
1598 width = pageSizeRequest.width if pygobject else pageSizeRequest[0]
1599 height = pageSizeRequest.height if pygobject else pageSizeRequest[1]
1600 maxWidth = max(maxWidth, width)
1601 maxHeight = max(maxHeight, height)
1602 maxWidth += 16
1603 maxHeight += 32
1604 self.set_size_request(maxWidth, maxHeight)
1605
1606 self._initialize()
1607
1608 @property
1609 def loginResult(self):
1610 """Get the login result."""
1611 return self._loginResult
1612
1613 def setCurrentPage(self, index, finalize = False):
1614 """Set the current page to the one with the given index."""
1615 assert index < len(self._pages)
1616
1617 fromPage = self._currentPage
1618 if fromPage is not None:
1619 page = self._pages[fromPage]
1620 if finalize and not page._finalized:
1621 page.finalize()
1622 page._finalized = True
1623 self.remove(page)
1624
1625 self._currentPage = index
1626 page = self._pages[index]
1627 self.add(page)
1628 if page._fromPage is None:
1629 page._fromPage = fromPage
1630 page.activate()
1631 self.show_all()
1632 if fromPage is not None:
1633 self.grabDefault()
1634
1635 def nextPage(self, finalize = True):
1636 """Go to the next page."""
1637 self.jumpPage(1, finalize)
1638
1639 def jumpPage(self, count, finalize = True):
1640 """Go to the page which is 'count' pages after the current one."""
1641 self.setCurrentPage(self._currentPage + count, finalize = finalize)
1642
1643 def grabDefault(self):
1644 """Make the default button of the current page the default."""
1645 self._pages[self._currentPage].grabDefault()
1646
1647 def connected(self, fsType, descriptor):
1648 """Called when the connection could be made to the simulator."""
1649 self.nextPage()
1650
1651 def connectionFailed(self):
1652 """Called when the connection could not be made to the simulator."""
1653 self._initialize()
1654
1655 def disconnected(self):
1656 """Called when we have disconnected from the simulator."""
1657 self._initialize()
1658
1659 def _initialize(self):
1660 """Initialize the wizard."""
1661 self._fleet = None
1662 self._fleetCallback = None
1663 self._updatePlaneCallback = None
1664
1665 self._loginResult = None
1666 self._bookedFlight = None
1667 self._departureGate = "-"
1668 self._zfw = None
1669 self._cruiseAltitude = None
1670 self._route = None
1671 self._departureNOTAMs = None
1672 self._departureMETAR = None
1673 self._arrivalNOTAMs = None
1674 self._arrivalMETAR = None
1675
1676 for page in self._pages:
1677 page.reset()
1678
1679 self.setCurrentPage(0)
1680
1681 def _getFleet(self, callback, force = False):
1682 """Get the fleet, if needed.
1683
1684 callback is function that will be called, when the feet is retrieved,
1685 or the retrieval fails. It should have a single argument that will
1686 receive the fleet object on success, None otherwise.
1687 """
1688 if self._fleet is not None and not force:
1689 callback(self._fleet)
1690
1691 self.gui.beginBusy("Retrieving fleet...")
1692 self._fleetCallback = callback
1693 self.gui.webHandler.getFleet(self._fleetResultCallback)
1694
1695 def _fleetResultCallback(self, returned, result):
1696 """Called when the fleet has been queried."""
1697 gobject.idle_add(self._handleFleetResult, returned, result)
1698
1699 def _handleFleetResult(self, returned, result):
1700 """Handle the fleet result."""
1701 self.gui.endBusy()
1702 if returned:
1703 self._fleet = result.fleet
1704 else:
1705 self._fleet = None
1706
1707 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
1708 buttons = BUTTONSTYPE_OK,
1709 message_format =
1710 "Failed to retrieve the information on "
1711 "the fleet.")
1712 dialog.run()
1713 dialog.hide()
1714
1715 self._fleetCallback(self._fleet)
1716
1717 def _updatePlane(self, callback, tailNumber, status, gateNumber = None):
1718 """Update the given plane's gate information."""
1719 self.gui.beginBusy("Updating plane status...")
1720 self._updatePlaneCallback = callback
1721 self.gui.webHandler.updatePlane(self._updatePlaneResultCallback,
1722 tailNumber, status, gateNumber)
1723
1724 def _updatePlaneResultCallback(self, returned, result):
1725 """Callback for the plane updating operation."""
1726 gobject.idle_add(self._handleUpdatePlaneResult, returned, result)
1727
1728 def _handleUpdatePlaneResult(self, returned, result):
1729 """Handle the result of a plane update operation."""
1730 self.gui.endBusy()
1731 if returned:
1732 success = result.success
1733 else:
1734 success = None
1735
1736 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
1737 buttons = BUTTONSTYPE_OK,
1738 message_format =
1739 "Failed to update the statuis of "
1740 "the airplane.")
1741 dialog.run()
1742 dialog.hide()
1743
1744 self._updatePlaneCallback(success)
1745
1746 def _connectSimulator(self):
1747 """Connect to the simulator."""
1748 self.gui.connectSimulator(self._bookedFlight.aircraftType)
1749
1750#-----------------------------------------------------------------------------
1751
Note: See TracBrowser for help on using the repository browser.