source: src/mlx/gui/flight.py@ 70:64fb5caf4cad

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

Implemented two-way navigation between the wizard pages.

File size: 51.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
14class Page(gtk.Alignment):
15 """A page in the flight wizard."""
16 def __init__(self, wizard, title, help):
17 """Construct the page."""
18 super(Page, self).__init__(xalign = 0.0, yalign = 0.0,
19 xscale = 1.0, yscale = 1.0)
20 self.set_padding(padding_top = 4, padding_bottom = 4,
21 padding_left = 12, padding_right = 12)
22
23 frame = gtk.Frame()
24 self.add(frame)
25
26 style = self.get_style() if pygobject else self.rc_get_style()
27
28 self._vbox = gtk.VBox()
29 self._vbox.set_homogeneous(False)
30 frame.add(self._vbox)
31
32 eventBox = gtk.EventBox()
33 eventBox.modify_bg(0, style.bg[3])
34
35 alignment = gtk.Alignment(xalign = 0.0, xscale = 0.0)
36
37 label = gtk.Label(title)
38 label.modify_fg(0, style.fg[3])
39 label.modify_font(pango.FontDescription("bold 24"))
40 alignment.set_padding(padding_top = 4, padding_bottom = 4,
41 padding_left = 6, padding_right = 0)
42
43 alignment.add(label)
44 eventBox.add(alignment)
45
46 self._vbox.pack_start(eventBox, False, False, 0)
47
48 table = gtk.Table(3, 1)
49 table.set_homogeneous(False)
50
51 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
52 xscale = 1.0, yscale = 1.0)
53 alignment.set_padding(padding_top = 16, padding_bottom = 16,
54 padding_left = 16, padding_right = 16)
55 alignment.add(table)
56 self._vbox.pack_start(alignment, True, True, 0)
57
58 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.0,
59 xscale = 0, yscale = 0.0)
60 alignment.set_padding(padding_top = 0, padding_bottom = 16,
61 padding_left = 0, padding_right = 0)
62
63 label = gtk.Label(help)
64 label.set_justify(gtk.Justification.CENTER if pygobject
65 else gtk.JUSTIFY_CENTER)
66 alignment.add(label)
67 table.attach(alignment, 0, 1, 0, 1)
68
69 self._mainAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
70 xscale = 1.0, yscale = 1.0)
71 table.attach(self._mainAlignment, 0, 1, 1, 3)
72
73 buttonAlignment = gtk.Alignment(xalign = 1.0, xscale=0.0, yscale = 0.0)
74 buttonAlignment.set_padding(padding_top = 4, padding_bottom = 10,
75 padding_left = 16, padding_right = 16)
76
77 self._buttonBox = gtk.HBox()
78 self._buttonBox.set_homogeneous(False)
79 self._defaultButton = None
80 buttonAlignment.add(self._buttonBox)
81
82 self._vbox.pack_start(buttonAlignment, False, False, 0)
83
84 self._wizard = wizard
85
86 self._finalized = False
87 self._fromPage = None
88
89 def setMainWidget(self, widget):
90 """Set the given widget as the main one."""
91 self._mainAlignment.add(widget)
92
93 def addButton(self, label, default = False):
94 """Add a button with the given label.
95
96 Return the button object created."""
97 button = gtk.Button(label)
98 self._buttonBox.pack_start(button, False, False, 4)
99 button.set_use_underline(True)
100 if default:
101 button.set_can_default(True)
102 self._defaultButton = button
103 return button
104
105 def activate(self):
106 """Called when this page becomes active.
107
108 This default implementation does nothing."""
109 pass
110
111 def finalize(self):
112 """Called when the page is finalized."""
113 pass
114
115 def grabDefault(self):
116 """If the page has a default button, make it the default one."""
117 if self._defaultButton is not None:
118 self._defaultButton.grab_default()
119
120 def reset(self):
121 """Reset the page if the wizard is reset."""
122 self._finalized = False
123 self._fromPage = None
124
125 def goBack(self):
126 """Go to the page we were invoked from."""
127 assert self._fromPage is not None
128
129 self._wizard.setCurrentPage(self._fromPage, finalize = False)
130
131#-----------------------------------------------------------------------------
132
133class LoginPage(Page):
134 """The login page."""
135 def __init__(self, wizard):
136 """Construct the login page."""
137 help = "Enter your MAVA pilot's ID and password to\n" \
138 "log in to the MAVA website and download\n" \
139 "your booked flights."
140 super(LoginPage, self).__init__(wizard, "Login", help)
141
142 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
143 xscale = 0.0, yscale = 0.0)
144
145 table = gtk.Table(2, 3)
146 table.set_row_spacings(4)
147 table.set_col_spacings(32)
148 alignment.add(table)
149 self.setMainWidget(alignment)
150
151 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
152 label = gtk.Label("Pilot _ID:")
153 label.set_use_underline(True)
154 labelAlignment.add(label)
155 table.attach(labelAlignment, 0, 1, 0, 1)
156
157 self._pilotID = gtk.Entry()
158 self._pilotID.connect("changed", self._setLoginButton)
159 self._pilotID.set_tooltip_text("Enter your MAVA pilot's ID. This "
160 "usually starts with a "
161 "'P' followed by 3 digits.")
162 table.attach(self._pilotID, 1, 2, 0, 1)
163 label.set_mnemonic_widget(self._pilotID)
164
165 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
166 label = gtk.Label("_Password:")
167 label.set_use_underline(True)
168 labelAlignment.add(label)
169 table.attach(labelAlignment, 0, 1, 1, 2)
170
171 self._password = gtk.Entry()
172 self._password.set_visibility(False)
173 self._password.connect("changed", self._setLoginButton)
174 self._password.set_tooltip_text("Enter the password for your pilot's ID")
175 table.attach(self._password, 1, 2, 1, 2)
176 label.set_mnemonic_widget(self._password)
177
178 self._rememberButton = gtk.CheckButton("_Remember password")
179 self._rememberButton.set_use_underline(True)
180 self._rememberButton.set_tooltip_text("If checked, your password will "
181 "be stored, so that you should "
182 "not have to enter it every time. "
183 "Note, however, that the password "
184 "is stored as text, and anybody "
185 "who can access your files will "
186 "be able to read it.")
187 table.attach(self._rememberButton, 1, 2, 2, 3, ypadding = 8)
188
189 self._loginButton = self.addButton("_Login", default = True)
190 self._loginButton.set_sensitive(False)
191 self._loginButton.connect("clicked", self._loginClicked)
192 self._loginButton.set_tooltip_text("Click to log in.")
193
194 config = self._wizard.gui.config
195 self._pilotID.set_text(config.pilotID)
196 self._password.set_text(config.password)
197 self._rememberButton.set_active(config.rememberPassword)
198
199 def _setLoginButton(self, entry):
200 """Set the login button's sensitivity.
201
202 The button is sensitive only if both the pilot ID and the password
203 fields contain values."""
204 self._loginButton.set_sensitive(self._pilotID.get_text()!="" and
205 self._password.get_text()!="")
206
207 def _loginClicked(self, button):
208 """Called when the login button was clicked."""
209 self._loginButton.set_sensitive(False)
210 gui = self._wizard.gui
211 gui.beginBusy("Logging in...")
212 gui.webHandler.login(self._loginResultCallback,
213 self._pilotID.get_text(),
214 self._password.get_text())
215
216 def _loginResultCallback(self, returned, result):
217 """The login result callback, called in the web handler's thread."""
218 gobject.idle_add(self._handleLoginResult, returned, result)
219
220 def _handleLoginResult(self, returned, result):
221 """Handle the login result."""
222 self._wizard.gui.endBusy()
223 self._loginButton.set_sensitive(True)
224 if returned:
225 if result.loggedIn:
226 config = self._wizard.gui.config
227
228 config.pilotID = self._pilotID.get_text()
229
230 rememberPassword = self._rememberButton.get_active()
231 config.password = self._password.get_text() if rememberPassword \
232 else ""
233
234 config.rememberPassword = rememberPassword
235
236 config.save()
237 self._wizard._loginResult = result
238 self._wizard.nextPage()
239 else:
240 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
241 buttons = BUTTONSTYPE_OK,
242 message_format =
243 "Invalid pilot's ID or password.")
244 dialog.format_secondary_markup("Check the ID and try to reenter"
245 " the password.")
246 dialog.run()
247 dialog.hide()
248 else:
249 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
250 buttons = BUTTONSTYPE_OK,
251 message_format =
252 "Failed to connect to the MAVA website.")
253 dialog.format_secondary_markup("Try again in a few minutes.")
254 dialog.run()
255 dialog.hide()
256
257#-----------------------------------------------------------------------------
258
259class FlightSelectionPage(Page):
260 """The page to select the flight."""
261 def __init__(self, wizard):
262 """Construct the flight selection page."""
263 super(FlightSelectionPage, self).__init__(wizard, "Flight selection",
264 "Select the flight you want "
265 "to perform.")
266
267
268 self._listStore = gtk.ListStore(str, str, str, str)
269 self._flightList = gtk.TreeView(self._listStore)
270 column = gtk.TreeViewColumn("Flight no.", gtk.CellRendererText(),
271 text = 1)
272 column.set_expand(True)
273 self._flightList.append_column(column)
274 column = gtk.TreeViewColumn("Departure time [UTC]", gtk.CellRendererText(),
275 text = 0)
276 column.set_expand(True)
277 self._flightList.append_column(column)
278 column = gtk.TreeViewColumn("From", gtk.CellRendererText(),
279 text = 2)
280 column.set_expand(True)
281 self._flightList.append_column(column)
282 column = gtk.TreeViewColumn("To", gtk.CellRendererText(),
283 text = 3)
284 column.set_expand(True)
285 self._flightList.append_column(column)
286
287 flightSelection = self._flightList.get_selection()
288 flightSelection.connect("changed", self._selectionChanged)
289
290 scrolledWindow = gtk.ScrolledWindow()
291 scrolledWindow.add(self._flightList)
292 scrolledWindow.set_size_request(400, -1)
293 scrolledWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
294 else gtk.POLICY_AUTOMATIC,
295 gtk.PolicyType.AUTOMATIC if pygobject
296 else gtk.POLICY_AUTOMATIC)
297 scrolledWindow.set_shadow_type(gtk.ShadowType.IN if pygobject
298 else gtk.SHADOW_IN)
299
300 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.0, xscale = 0.0, yscale = 1.0)
301 alignment.add(scrolledWindow)
302
303 self.setMainWidget(alignment)
304
305 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
306 self._button.set_use_stock(True)
307 self._button.set_sensitive(False)
308 self._button.connect("clicked", self._forwardClicked)
309
310 def activate(self):
311 """Fill the flight list."""
312 self._flightList.set_sensitive(True)
313 self._listStore.clear()
314 for flight in self._wizard.loginResult.flights:
315 self._listStore.append([str(flight.departureTime),
316 flight.callsign,
317 flight.departureICAO,
318 flight.arrivalICAO])
319
320 def finalize(self):
321 """Finalize the page."""
322 self._flightList.set_sensitive(False)
323
324 def _selectionChanged(self, selection):
325 """Called when the selection is changed."""
326 self._button.set_sensitive(selection.count_selected_rows()==1)
327
328 def _forwardClicked(self, button):
329 """Called when the forward button was clicked."""
330 if self._finalized:
331 self._wizard.jumpPage(self._nextDistance, finalize = False)
332 else:
333 selection = self._flightList.get_selection()
334 (listStore, iter) = selection.get_selected()
335 path = listStore.get_path(iter)
336 [index] = path.get_indices() if pygobject else path
337
338 flight = self._wizard.loginResult.flights[index]
339 self._wizard._bookedFlight = flight
340
341 self._updateDepartureGate()
342
343 def _updateDepartureGate(self):
344 """Update the departure gate for the booked flight."""
345 flight = self._wizard._bookedFlight
346 if flight.departureICAO=="LHBP":
347 self._wizard._getFleet(self._fleetRetrieved)
348 else:
349 self._nextDistance = 2
350 self._wizard.jumpPage(2)
351
352 def _fleetRetrieved(self, fleet):
353 """Called when the fleet has been retrieved."""
354 if fleet is None:
355 self._nextDistance = 2
356 self._wizard.jumpPage(2)
357 else:
358 plane = fleet[self._wizard._bookedFlight.tailNumber]
359 if plane is None:
360 self._nextDistance = 2
361 self._wizard.jumpPage(2)
362 elif plane.gateNumber is not None and \
363 not fleet.isGateConflicting(plane):
364 self._wizard._departureGate = plane.gateNumber
365 self._nextDistance = 2
366 self._wizard.jumpPage(2)
367 else:
368 self._nextDistance = 1
369 self._wizard.nextPage()
370
371#-----------------------------------------------------------------------------
372
373class GateSelectionPage(Page):
374 """Page to select a free gate at LHBP.
375
376 This page should be displayed only if we have fleet information!."""
377 def __init__(self, wizard):
378 """Construct the gate selection page."""
379 help = "The airplane's gate position is invalid.\n\n" \
380 "Select the gate from which you\n" \
381 "would like to begin the flight."
382 super(GateSelectionPage, self).__init__(wizard,
383 "LHBP gate selection",
384 help)
385
386 self._listStore = gtk.ListStore(str)
387 self._gateList = gtk.TreeView(self._listStore)
388 column = gtk.TreeViewColumn(None, gtk.CellRendererText(),
389 text = 0)
390 column.set_expand(True)
391 self._gateList.append_column(column)
392 self._gateList.set_headers_visible(False)
393
394 gateSelection = self._gateList.get_selection()
395 gateSelection.connect("changed", self._selectionChanged)
396
397 scrolledWindow = gtk.ScrolledWindow()
398 scrolledWindow.add(self._gateList)
399 scrolledWindow.set_size_request(50, -1)
400 scrolledWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
401 else gtk.POLICY_AUTOMATIC,
402 gtk.PolicyType.AUTOMATIC if pygobject
403 else gtk.POLICY_AUTOMATIC)
404 scrolledWindow.set_shadow_type(gtk.ShadowType.IN if pygobject
405 else gtk.SHADOW_IN)
406
407 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.0, xscale = 0.0, yscale = 1.0)
408 alignment.add(scrolledWindow)
409
410 self.setMainWidget(alignment)
411
412 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
413 self._button.set_use_stock(True)
414 self._button.set_sensitive(False)
415 self._button.connect("clicked", self._forwardClicked)
416
417 def activate(self):
418 """Fill the gate list."""
419 self._listStore.clear()
420 self._gateList.set_sensitive(True)
421 occupiedGateNumbers = self._wizard._fleet.getOccupiedGateNumbers()
422 for gateNumber in const.lhbpGateNumbers:
423 if gateNumber not in occupiedGateNumbers:
424 self._listStore.append([gateNumber])
425
426 def finalize(self):
427 """Finalize the page."""
428 self._gateList.set_sensitive(False)
429
430 def _selectionChanged(self, selection):
431 """Called when the selection is changed."""
432 self._button.set_sensitive(selection.count_selected_rows()==1)
433
434 def _forwardClicked(self, button):
435 """Called when the forward button is clicked."""
436 if not self._finalized:
437 selection = self._gateList.get_selection()
438 (listStore, iter) = selection.get_selected()
439 (gateNumber,) = listStore.get(iter, 0)
440
441 self._wizard._departureGate = gateNumber
442
443 #self._wizard._updatePlane(self._planeUpdated,
444 # self._wizard._bookedFlight.tailNumber,
445 # const.PLANE_HOME,
446 # gateNumber)
447
448 self._wizard.nextPage()
449
450 def _planeUpdated(self, success):
451 """Callback for the plane updating call."""
452 if success is None or success:
453 self._wizard.nextPage()
454 else:
455 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
456 buttons = BUTTONSTYPE_OK,
457 message_format = "Gate conflict detected again")
458 dialog.format_secondary_markup("Try to select a different gate.")
459 dialog.run()
460 dialog.hide()
461
462 self._wizard._getFleet(self._fleetRetrieved)
463
464 def _fleetRetrieved(self, fleet):
465 """Called when the fleet has been retrieved."""
466 if fleet is None:
467 self._wizard.nextPage()
468 else:
469 self.activate()
470
471#-----------------------------------------------------------------------------
472
473class ConnectPage(Page):
474 """Page which displays the departure airport and gate (if at LHBP)."""
475 def __init__(self, wizard):
476 """Construct the connect page."""
477 help = "The flight begins at the airport given below.\n" \
478 "Park your aircraft there, at the gate below, if given.\n\n" \
479 "Then press the Connect button to connect to the simulator."
480 super(ConnectPage, self).__init__(wizard,
481 "Connect to the simulator",
482 help)
483
484 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
485 xscale = 0.0, yscale = 0.0)
486
487 table = gtk.Table(2, 2)
488 table.set_row_spacings(4)
489 table.set_col_spacings(16)
490 table.set_homogeneous(True)
491 alignment.add(table)
492 self.setMainWidget(alignment)
493
494 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
495 label = gtk.Label("ICAO code:")
496 labelAlignment.add(label)
497 table.attach(labelAlignment, 0, 1, 0, 1)
498
499 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
500 self._departureICAO = gtk.Label()
501 self._departureICAO.set_width_chars(5)
502 self._departureICAO.set_alignment(0.0, 0.5)
503 labelAlignment.add(self._departureICAO)
504 table.attach(labelAlignment, 1, 2, 0, 1)
505
506 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
507 label = gtk.Label("Gate:")
508 labelAlignment.add(label)
509 table.attach(labelAlignment, 0, 1, 1, 2)
510
511 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
512 self._departureGate = gtk.Label()
513 self._departureGate.set_width_chars(5)
514 self._departureGate.set_alignment(0.0, 0.5)
515 labelAlignment.add(self._departureGate)
516 table.attach(labelAlignment, 1, 2, 1, 2)
517
518 button = self.addButton(gtk.STOCK_GO_BACK)
519 button.set_use_stock(True)
520 button.connect("clicked", self._backClicked)
521
522 self._button = self.addButton("_Connect", default = True)
523 self._button.set_use_underline(True)
524 self._clickedID = self._button.connect("clicked", self._connectClicked)
525
526 def activate(self):
527 """Setup the departure information."""
528 self._button.set_label("_Connect")
529 self._button.set_use_underline(True)
530 self._button.disconnect(self._clickedID)
531 self._clickedID = self._button.connect("clicked", self._connectClicked)
532
533 icao = self._wizard._bookedFlight.departureICAO
534 self._departureICAO.set_markup("<b>" + icao + "</b>")
535 gate = self._wizard._departureGate
536 if gate!="-":
537 gate = "<b>" + gate + "</b>"
538 self._departureGate.set_markup(gate)
539
540 def finalize(self):
541 """Finalize the page."""
542 self._button.set_label(gtk.STOCK_GO_FORWARD)
543 self._button.set_use_stock(True)
544 self._button.disconnect(self._clickedID)
545 self._clickedID = self._button.connect("clicked", self._forwardClicked)
546
547 def _backClicked(self, button):
548 """Called when the Back button is pressed."""
549 self.goBack()
550
551 def _connectClicked(self, button):
552 """Called when the Connect button is pressed."""
553 self._wizard._connectSimulator()
554
555 def _forwardClicked(self, button):
556 """Called when the Forward button is pressed."""
557 self._wizard.nextPage()
558
559#-----------------------------------------------------------------------------
560
561class PayloadPage(Page):
562 """Page to allow setting up the payload."""
563 def __init__(self, wizard):
564 """Construct the page."""
565 help = "The briefing contains the weights below.\n" \
566 "Setup the cargo weight here and the payload weight in the simulator.\n\n" \
567 "You can also check here what the simulator reports as ZFW."
568
569 super(PayloadPage, self).__init__(wizard, "Payload", help)
570
571 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
572 xscale = 0.0, yscale = 0.0)
573
574 table = gtk.Table(7, 3)
575 table.set_row_spacings(4)
576 table.set_col_spacings(16)
577 table.set_homogeneous(False)
578 alignment.add(table)
579 self.setMainWidget(alignment)
580
581 label = gtk.Label("Crew:")
582 label.set_alignment(0.0, 0.5)
583 table.attach(label, 0, 1, 0, 1)
584
585 self._numCrew = gtk.Label()
586 self._numCrew.set_width_chars(6)
587 self._numCrew.set_alignment(1.0, 0.5)
588 table.attach(self._numCrew, 1, 2, 0, 1)
589
590 label = gtk.Label("Passengers:")
591 label.set_alignment(0.0, 0.5)
592 table.attach(label, 0, 1, 1, 2)
593
594 self._numPassengers = gtk.Label()
595 self._numPassengers.set_width_chars(6)
596 self._numPassengers.set_alignment(1.0, 0.5)
597 table.attach(self._numPassengers, 1, 2, 1, 2)
598
599 label = gtk.Label("Baggage:")
600 label.set_alignment(0.0, 0.5)
601 table.attach(label, 0, 1, 2, 3)
602
603 self._bagWeight = gtk.Label()
604 self._bagWeight.set_width_chars(6)
605 self._bagWeight.set_alignment(1.0, 0.5)
606 table.attach(self._bagWeight, 1, 2, 2, 3)
607
608 table.attach(gtk.Label("kg"), 2, 3, 2, 3)
609
610 label = gtk.Label("_Cargo:")
611 label.set_use_underline(True)
612 label.set_alignment(0.0, 0.5)
613 table.attach(label, 0, 1, 3, 4)
614
615 self._cargoWeight = gtk.Entry()
616 self._cargoWeight.set_width_chars(6)
617 self._cargoWeight.set_alignment(1.0)
618 self._cargoWeight.connect("changed", self._cargoWeightChanged)
619 self._cargoWeight.set_tooltip_text("The weight of the cargo for your flight.")
620 table.attach(self._cargoWeight, 1, 2, 3, 4)
621 self._cargoWeightValue = 0
622 label.set_mnemonic_widget(self._cargoWeight)
623
624 table.attach(gtk.Label("kg"), 2, 3, 3, 4)
625
626 label = gtk.Label("Mail:")
627 label.set_alignment(0.0, 0.5)
628 table.attach(label, 0, 1, 4, 5)
629
630 self._mailWeight = gtk.Label()
631 self._mailWeight.set_width_chars(6)
632 self._mailWeight.set_alignment(1.0, 0.5)
633 table.attach(self._mailWeight, 1, 2, 4, 5)
634
635 table.attach(gtk.Label("kg"), 2, 3, 4, 5)
636
637 label = gtk.Label("<b>Calculated ZFW:</b>")
638 label.set_alignment(0.0, 0.5)
639 label.set_use_markup(True)
640 table.attach(label, 0, 1, 5, 6)
641
642 self._calculatedZFW = gtk.Label()
643 self._calculatedZFW.set_width_chars(6)
644 self._calculatedZFW.set_alignment(1.0, 0.5)
645 table.attach(self._calculatedZFW, 1, 2, 5, 6)
646
647 table.attach(gtk.Label("kg"), 2, 3, 5, 6)
648
649 self._zfwButton = gtk.Button("_ZFW from FS:")
650 self._zfwButton.set_use_underline(True)
651 self._zfwButton.connect("clicked", self._zfwRequested)
652 table.attach(self._zfwButton, 0, 1, 6, 7)
653
654 self._simulatorZFW = gtk.Label("-")
655 self._simulatorZFW.set_width_chars(6)
656 self._simulatorZFW.set_alignment(1.0, 0.5)
657 table.attach(self._simulatorZFW, 1, 2, 6, 7)
658 self._simulatorZFWValue = None
659
660 table.attach(gtk.Label("kg"), 2, 3, 6, 7)
661
662 self._backButton = self.addButton(gtk.STOCK_GO_BACK)
663 self._backButton.set_use_stock(True)
664 self._backButton.connect("clicked", self._backClicked)
665
666 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
667 self._button.set_use_stock(True)
668 self._button.connect("clicked", self._forwardClicked)
669
670 def activate(self):
671 """Setup the information."""
672 bookedFlight = self._wizard._bookedFlight
673 self._numCrew.set_text(str(bookedFlight.numCrew))
674 self._numPassengers.set_text(str(bookedFlight.numPassengers))
675 self._bagWeight.set_text(str(bookedFlight.bagWeight))
676 self._cargoWeightValue = bookedFlight.cargoWeight
677 self._cargoWeight.set_text(str(bookedFlight.cargoWeight))
678 self._cargoWeight.set_sensitive(True)
679 self._mailWeight.set_text(str(bookedFlight.mailWeight))
680 self._zfwButton.set_sensitive(True)
681 self._updateCalculatedZFW()
682
683 def finalize(self):
684 """Finalize the payload page."""
685 self._cargoWeight.set_sensitive(False)
686 self._zfwButton.set_sensitive(False)
687
688 def _calculateZFW(self):
689 """Calculate the ZFW value."""
690 zfw = self._wizard.gui._flight.aircraft.dow
691 bookedFlight = self._wizard._bookedFlight
692 zfw += (bookedFlight.numCrew + bookedFlight.numPassengers) * 82
693 zfw += bookedFlight.bagWeight
694 zfw += self._cargoWeightValue
695 zfw += bookedFlight.mailWeight
696 return zfw
697
698 def _updateCalculatedZFW(self):
699 """Update the calculated ZFW"""
700 zfw = self._calculateZFW()
701
702 markupBegin = "<b>"
703 markupEnd = "</b>"
704 if self._simulatorZFWValue is not None and \
705 PayloadChecker.isZFWFaulty(self._simulatorZFWValue, zfw):
706 markupBegin += '<span foreground="red">'
707 markupEnd = "</span>" + markupEnd
708 self._calculatedZFW.set_markup(markupBegin + str(zfw) + markupEnd)
709
710 def _cargoWeightChanged(self, entry):
711 """Called when the cargo weight has changed."""
712 text = self._cargoWeight.get_text()
713 if text=="":
714 self._cargoWeightValue = 0
715 else:
716 try:
717 self._cargoWeightValue = int(text)
718 except:
719 self._cargoWeight.set_text(str(self._cargoWeightValue))
720 self._updateCalculatedZFW()
721
722 def _zfwRequested(self, button):
723 """Called when the ZFW is requested from the simulator."""
724 self._zfwButton.set_sensitive(False)
725 self._backButton.set_sensitive(False)
726 self._button.set_sensitive(False)
727 gui = self._wizard.gui
728 gui.beginBusy("Querying ZFW...")
729 gui.simulator.requestZFW(self._handleZFW)
730
731 def _handleZFW(self, zfw):
732 """Called when the ZFW value is retrieved."""
733 gobject.idle_add(self._processZFW, zfw)
734
735 def _processZFW(self, zfw):
736 """Process the given ZFW value received from the simulator."""
737 self._wizard.gui.endBusy()
738 self._zfwButton.set_sensitive(True)
739 self._backButton.set_sensitive(True)
740 self._button.set_sensitive(True)
741 self._simulatorZFWValue = zfw
742 self._simulatorZFW.set_text("%.0f" % (zfw,))
743 self._updateCalculatedZFW()
744
745 def _forwardClicked(self, button):
746 """Called when the forward button is clicked."""
747 if not self._finalized:
748 self._wizard._zfw = self._calculateZFW()
749 self._wizard.nextPage()
750
751 def _backClicked(self, button):
752 """Called when the Back button is pressed."""
753 self.goBack()
754
755#-----------------------------------------------------------------------------
756
757class TimePage(Page):
758 """Page displaying the departure and arrival times and allows querying the
759 current time from the flight simulator."""
760 def __init__(self, wizard):
761 help = "The departure and arrival times are displayed below in UTC.\n\n" \
762 "You can also query the current UTC time from the simulator.\n" \
763 "Ensure that you have enough time to properly prepare for the flight."
764
765 super(TimePage, self).__init__(wizard, "Time", help)
766
767 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
768 xscale = 0.0, yscale = 0.0)
769
770 table = gtk.Table(3, 2)
771 table.set_row_spacings(4)
772 table.set_col_spacings(16)
773 table.set_homogeneous(False)
774 alignment.add(table)
775 self.setMainWidget(alignment)
776
777 label = gtk.Label("Departure:")
778 label.set_alignment(0.0, 0.5)
779 table.attach(label, 0, 1, 0, 1)
780
781 self._departure = gtk.Label()
782 self._departure.set_alignment(0.0, 0.5)
783 table.attach(self._departure, 1, 2, 0, 1)
784
785 label = gtk.Label("Arrival:")
786 label.set_alignment(0.0, 0.5)
787 table.attach(label, 0, 1, 1, 2)
788
789 self._arrival = gtk.Label()
790 self._arrival.set_alignment(0.0, 0.5)
791 table.attach(self._arrival, 1, 2, 1, 2)
792
793 self._timeButton = gtk.Button("_Time from FS:")
794 self._timeButton.set_use_underline(True)
795 self._timeButton.connect("clicked", self._timeRequested)
796 table.attach(self._timeButton, 0, 1, 2, 3)
797
798 self._simulatorTime = gtk.Label("-")
799 self._simulatorTime.set_alignment(0.0, 0.5)
800 table.attach(self._simulatorTime, 1, 2, 2, 3)
801
802 self._backButton = self.addButton(gtk.STOCK_GO_BACK)
803 self._backButton.set_use_stock(True)
804 self._backButton.connect("clicked", self._backClicked)
805
806 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
807 self._button.set_use_stock(True)
808 self._button.connect("clicked", self._forwardClicked)
809
810 def activate(self):
811 """Activate the page."""
812 self._timeButton.set_sensitive(True)
813 bookedFlight = self._wizard._bookedFlight
814 self._departure.set_text(str(bookedFlight.departureTime.time()))
815 self._arrival.set_text(str(bookedFlight.arrivalTime.time()))
816
817 def finalize(self):
818 """Finalize the page."""
819 self._timeButton.set_sensitive(False)
820
821 def _timeRequested(self, button):
822 """Request the time from the simulator."""
823 self._timeButton.set_sensitive(False)
824 self._backButton.set_sensitive(False)
825 self._button.set_sensitive(False)
826 self._wizard.gui.beginBusy("Querying time...")
827 self._wizard.gui.simulator.requestTime(self._handleTime)
828
829 def _handleTime(self, timestamp):
830 """Handle the result of a time retrieval."""
831 gobject.idle_add(self._processTime, timestamp)
832
833 def _processTime(self, timestamp):
834 """Process the given time."""
835 self._wizard.gui.endBusy()
836 self._timeButton.set_sensitive(True)
837 self._backButton.set_sensitive(True)
838 self._button.set_sensitive(True)
839 tm = time.gmtime(timestamp)
840 t = datetime.time(tm.tm_hour, tm.tm_min, tm.tm_sec)
841 self._simulatorTime.set_text(str(t))
842
843 ts = tm.tm_hour * 3600 + tm.tm_min * 60 + tm.tm_sec
844 dt = self._wizard._bookedFlight.departureTime.time()
845 dts = dt.hour * 3600 + dt.minute * 60 + dt.second
846 diff = dts-ts
847
848 markupBegin = ""
849 markupEnd = ""
850 if diff < 0:
851 markupBegin = '<b><span foreground="red">'
852 markupEnd = '</span></b>'
853 elif diff < 3*60 or diff > 30*60:
854 markupBegin = '<b><span foreground="orange">'
855 markupEnd = '</span></b>'
856
857 self._departure.set_markup(markupBegin + str(dt) + markupEnd)
858
859 def _backClicked(self, button):
860 """Called when the Back button is pressed."""
861 self.goBack()
862
863 def _forwardClicked(self, button):
864 """Called when the forward button is clicked."""
865 self._wizard.nextPage()
866
867#-----------------------------------------------------------------------------
868
869class RoutePage(Page):
870 """The page containing the route and the flight level."""
871 def __init__(self, wizard):
872 help = "Set your cruise flight level below, and\n" \
873 "if necessary, edit the flight plan."
874
875 super(RoutePage, self).__init__(wizard, "Route", help)
876
877 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
878 xscale = 0.0, yscale = 0.0)
879
880 mainBox = gtk.VBox()
881 alignment.add(mainBox)
882 self.setMainWidget(alignment)
883
884 levelBox = gtk.HBox()
885
886 label = gtk.Label("_Cruise level")
887 label.set_use_underline(True)
888 levelBox.pack_start(label, True, True, 0)
889
890 self._cruiseLevel = gtk.SpinButton()
891 self._cruiseLevel.set_increments(step = 10, page = 100)
892 self._cruiseLevel.set_range(min = 50, max = 500)
893 self._cruiseLevel.set_value(240)
894 self._cruiseLevel.set_tooltip_text("The cruise flight level.")
895 self._cruiseLevel.set_numeric(True)
896 self._cruiseLevel.connect("value-changed", self._cruiseLevelChanged)
897 label.set_mnemonic_widget(self._cruiseLevel)
898
899 levelBox.pack_start(self._cruiseLevel, False, False, 8)
900
901 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
902 xscale = 0.0, yscale = 0.0)
903 alignment.add(levelBox)
904
905 mainBox.pack_start(alignment, False, False, 0)
906
907
908 routeBox = gtk.VBox()
909
910 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
911 xscale = 0.0, yscale = 0.0)
912 label = gtk.Label("_Route")
913 label.set_use_underline(True)
914 alignment.add(label)
915 routeBox.pack_start(alignment, True, True, 0)
916
917 routeWindow = gtk.ScrolledWindow()
918 routeWindow.set_size_request(400, 80)
919 routeWindow.set_shadow_type(gtk.ShadowType.IN if pygobject
920 else gtk.SHADOW_IN)
921 routeWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
922 else gtk.POLICY_AUTOMATIC,
923 gtk.PolicyType.AUTOMATIC if pygobject
924 else gtk.POLICY_AUTOMATIC)
925
926 self._route = gtk.TextView()
927 self._route.set_tooltip_text("The planned flight route.")
928 self._route.get_buffer().connect("changed", self._routeChanged)
929 routeWindow.add(self._route)
930
931 label.set_mnemonic_widget(self._route)
932 routeBox.pack_start(routeWindow, True, True, 0)
933
934 mainBox.pack_start(routeBox, True, True, 8)
935
936 self._backButton = self.addButton(gtk.STOCK_GO_BACK)
937 self._backButton.set_use_stock(True)
938 self._backButton.connect("clicked", self._backClicked)
939
940 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
941 self._button.set_use_stock(True)
942 self._button.connect("clicked", self._forwardClicked)
943
944 def activate(self):
945 """Setup the route from the booked flight."""
946 self._route.set_sensitive(True)
947 self._cruiseLevel.set_sensitive(True)
948 self._route.get_buffer().set_text(self._wizard._bookedFlight.route)
949 self._updateForwardButton()
950
951 def finalize(self):
952 """Finalize the page."""
953 self._route.set_sensitive(False)
954 self._cruiseLevel.set_sensitive(False)
955
956 def _getRoute(self):
957 """Get the text of the route."""
958 buffer = self._route.get_buffer()
959 return buffer.get_text(buffer.get_start_iter(),
960 buffer.get_end_iter(), True)
961
962 def _updateForwardButton(self):
963 """Update the sensitivity of the forward button."""
964 self._button.set_sensitive(self._cruiseLevel.get_value_as_int()>=50 and \
965 self._getRoute()!="")
966
967 def _cruiseLevelChanged(self, spinButton):
968 """Called when the cruise level has changed."""
969 self._updateForwardButton()
970
971 def _routeChanged(self, textBuffer):
972 """Called when the route has changed."""
973 self._updateForwardButton()
974
975 def _backClicked(self, button):
976 """Called when the Back button is pressed."""
977 self.goBack()
978
979 def _forwardClicked(self, button):
980 """Called when the Forward button is clicked."""
981 if self._finalized:
982 self._wizard.nextPage()
983 else:
984 self._wizard._cruiseAltitude = self._cruiseLevel.get_value_as_int() * 100
985 self._wizard._route = self._getRoute()
986
987 self._backButton.set_sensitive(False)
988 self._button.set_sensitive(False)
989 self._cruiseLevel.set_sensitive(False)
990 self._route.set_sensitive(False)
991
992 bookedFlight = self._wizard._bookedFlight
993 self._wizard.gui.beginBusy("Downloading NOTAMs...")
994 self._wizard.gui.webHandler.getNOTAMs(self._notamsCallback,
995 bookedFlight.departureICAO,
996 bookedFlight.arrivalICAO)
997
998 def _notamsCallback(self, returned, result):
999 """Callback for the NOTAMs."""
1000 gobject.idle_add(self._handleNOTAMs, returned, result)
1001
1002 def _handleNOTAMs(self, returned, result):
1003 """Handle the NOTAMs."""
1004 if returned:
1005 self._wizard._departureNOTAMs = result.departureNOTAMs
1006 self._wizard._arrivalNOTAMs = result.arrivalNOTAMs
1007 else:
1008 self._wizard._departureNOTAMs = None
1009 self._wizard._arrivalNOTAMs = None
1010
1011 bookedFlight = self._wizard._bookedFlight
1012 self._wizard.gui.beginBusy("Downloading METARs...")
1013 self._wizard.gui.webHandler.getMETARs(self._metarsCallback,
1014 [bookedFlight.departureICAO,
1015 bookedFlight.arrivalICAO])
1016
1017 def _metarsCallback(self, returned, result):
1018 """Callback for the METARs."""
1019 gobject.idle_add(self._handleMETARs, returned, result)
1020
1021 def _handleMETARs(self, returned, result):
1022 """Handle the METARs."""
1023 self._wizard._departureMETAR = None
1024 self._wizard._arrivalMETAR = None
1025 bookedFlight = self._wizard._bookedFlight
1026 if returned:
1027 if bookedFlight.departureICAO in result.metars:
1028 self._wizard._departureMETAR = result.metars[bookedFlight.departureICAO]
1029 if bookedFlight.arrivalICAO in result.metars:
1030 self._wizard._arrivalMETAR = result.metars[bookedFlight.arrivalICAO]
1031
1032 self._wizard.gui.endBusy()
1033 self._backButton.set_sensitive(True)
1034 self._button.set_sensitive(True)
1035 self._wizard.nextPage()
1036
1037#-----------------------------------------------------------------------------
1038
1039class BriefingPage(Page):
1040 """Page for the briefing."""
1041 def __init__(self, wizard, departure):
1042 """Construct the briefing page."""
1043 self._departure = departure
1044
1045 title = "Briefing (%d/2): %s" % (1 if departure else 2,
1046 "departure" if departure
1047 else "arrival")
1048
1049 help = "Read carefully the NOTAMs and METAR below."
1050
1051 super(BriefingPage, self).__init__(wizard, title, help)
1052
1053 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
1054 xscale = 1.0, yscale = 1.0)
1055
1056 mainBox = gtk.VBox()
1057 alignment.add(mainBox)
1058 self.setMainWidget(alignment)
1059
1060 self._notamsFrame = gtk.Frame()
1061 self._notamsFrame.set_label("LHBP NOTAMs")
1062 scrolledWindow = gtk.ScrolledWindow()
1063 scrolledWindow.set_size_request(-1, 128)
1064 scrolledWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
1065 else gtk.POLICY_AUTOMATIC,
1066 gtk.PolicyType.AUTOMATIC if pygobject
1067 else gtk.POLICY_AUTOMATIC)
1068 self._notams = gtk.TextView()
1069 self._notams.set_editable(False)
1070 self._notams.set_accepts_tab(False)
1071 self._notams.set_wrap_mode(gtk.WrapMode.WORD if pygobject else gtk.WRAP_WORD)
1072 scrolledWindow.add(self._notams)
1073 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
1074 xscale = 1.0, yscale = 1.0)
1075 alignment.set_padding(padding_top = 4, padding_bottom = 0,
1076 padding_left = 0, padding_right = 0)
1077 alignment.add(scrolledWindow)
1078 self._notamsFrame.add(alignment)
1079 mainBox.pack_start(self._notamsFrame, True, True, 4)
1080
1081 self._metarFrame = gtk.Frame()
1082 self._metarFrame.set_label("LHBP METAR")
1083 scrolledWindow = gtk.ScrolledWindow()
1084 scrolledWindow.set_size_request(-1, 32)
1085 scrolledWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
1086 else gtk.POLICY_AUTOMATIC,
1087 gtk.PolicyType.AUTOMATIC if pygobject
1088 else gtk.POLICY_AUTOMATIC)
1089 self._metar = gtk.TextView()
1090 self._metar.set_editable(False)
1091 self._metar.set_accepts_tab(False)
1092 self._metar.set_wrap_mode(gtk.WrapMode.WORD if pygobject else gtk.WRAP_WORD)
1093 scrolledWindow.add(self._metar)
1094 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
1095 xscale = 1.0, yscale = 1.0)
1096 alignment.set_padding(padding_top = 4, padding_bottom = 0,
1097 padding_left = 0, padding_right = 0)
1098 alignment.add(scrolledWindow)
1099 self._metarFrame.add(alignment)
1100 mainBox.pack_start(self._metarFrame, True, True, 4)
1101
1102 button = self.addButton(gtk.STOCK_GO_BACK)
1103 button.set_use_stock(True)
1104 button.connect("clicked", self._backClicked)
1105
1106 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
1107 self._button.set_use_stock(True)
1108 self._button.connect("clicked", self._forwardClicked)
1109
1110 def activate(self):
1111 """Activate the page."""
1112 if not self._departure:
1113 self._button.set_label("I have read the briefing and am ready to fly!")
1114 self._button.set_use_stock(False)
1115
1116 bookedFlight = self._wizard._bookedFlight
1117
1118 icao = bookedFlight.departureICAO if self._departure \
1119 else bookedFlight.arrivalICAO
1120 notams = self._wizard._departureNOTAMs if self._departure \
1121 else self._wizard._arrivalNOTAMs
1122 metar = self._wizard._departureMETAR if self._departure \
1123 else self._wizard._arrivalMETAR
1124
1125 self._notamsFrame.set_label(icao + " NOTAMs")
1126 buffer = self._notams.get_buffer()
1127 if notams is None:
1128 buffer.set_text("Could not download NOTAMs")
1129 else:
1130 s = ""
1131 for notam in notams:
1132 s += str(notam.begin)
1133 if notam.end is not None:
1134 s += " - " + str(notam.end)
1135 elif notam.permanent:
1136 s += " - PERMANENT"
1137 s += "\n"
1138 if notam.repeatCycle:
1139 s += "Repeat cycle: " + notam.repeatCycle + "\n"
1140 s += notam.notice + "\n"
1141 s += "-------------------- * --------------------\n"
1142 buffer.set_text(s)
1143
1144 self._metarFrame.set_label(icao + " METAR")
1145 buffer = self._metar.get_buffer()
1146 if metar is None:
1147 buffer.set_text("Could not download METAR")
1148 else:
1149 buffer.set_text(metar)
1150
1151 def finalize(self):
1152 """Finalize the page."""
1153 if not self._departure:
1154 self._button.set_use_stock(True)
1155 self._button.set_label(gtk.STOCK_GO_FORWARD)
1156
1157 def _backClicked(self, button):
1158 """Called when the Back button is pressed."""
1159 self.goBack()
1160
1161 def _forwardClicked(self, button):
1162 """Called when the forward button is clicked."""
1163 if not self._departure:
1164 if not self._finalized:
1165 self._wizard.gui.startMonitoring()
1166 self.finalize()
1167 self._finalized = True
1168 else:
1169 self._wizard.nextPage()
1170
1171#-----------------------------------------------------------------------------
1172
1173class Wizard(gtk.VBox):
1174 """The flight wizard."""
1175 def __init__(self, gui):
1176 """Construct the wizard."""
1177 super(Wizard, self).__init__()
1178
1179 self.gui = gui
1180
1181 self._pages = []
1182 self._currentPage = None
1183
1184 self._pages.append(LoginPage(self))
1185 self._pages.append(FlightSelectionPage(self))
1186 self._pages.append(GateSelectionPage(self))
1187 self._pages.append(ConnectPage(self))
1188 self._pages.append(PayloadPage(self))
1189 self._pages.append(TimePage(self))
1190 self._pages.append(RoutePage(self))
1191 self._pages.append(BriefingPage(self, True))
1192 self._pages.append(BriefingPage(self, False))
1193
1194 maxWidth = 0
1195 maxHeight = 0
1196 for page in self._pages:
1197 page.show_all()
1198 pageSizeRequest = page.size_request()
1199 width = pageSizeRequest.width if pygobject else pageSizeRequest[0]
1200 height = pageSizeRequest.height if pygobject else pageSizeRequest[1]
1201 maxWidth = max(maxWidth, width)
1202 maxHeight = max(maxHeight, height)
1203 maxWidth += 16
1204 maxHeight += 32
1205 self.set_size_request(maxWidth, maxHeight)
1206
1207 self._initialize()
1208
1209 @property
1210 def loginResult(self):
1211 """Get the login result."""
1212 return self._loginResult
1213
1214 def setCurrentPage(self, index, finalize = False):
1215 """Set the current page to the one with the given index."""
1216 assert index < len(self._pages)
1217
1218 fromPage = self._currentPage
1219 if fromPage is not None:
1220 page = self._pages[fromPage]
1221 if finalize and not page._finalized:
1222 page.finalize()
1223 page._finalized = True
1224 self.remove(page)
1225
1226 self._currentPage = index
1227 page = self._pages[index]
1228 self.add(page)
1229 if page._fromPage is None:
1230 page._fromPage = fromPage
1231 page.activate()
1232 self.grabDefault()
1233 self.show_all()
1234
1235 def nextPage(self, finalize = True):
1236 """Go to the next page."""
1237 self.jumpPage(1, finalize)
1238
1239 def jumpPage(self, count, finalize = True):
1240 """Go to the page which is 'count' pages after the current one."""
1241 self.setCurrentPage(self._currentPage + count, finalize = finalize)
1242
1243 def grabDefault(self):
1244 """Make the default button of the current page the default."""
1245 self._pages[self._currentPage].grabDefault()
1246
1247 def connected(self, fsType, descriptor):
1248 """Called when the connection could be made to the simulator."""
1249 self.nextPage()
1250
1251 def connectionFailed(self):
1252 """Called when the connection could not be made to the simulator."""
1253 self._initialize()
1254
1255 def disconnected(self):
1256 """Called when we have disconnected from the simulator."""
1257 self._initialize()
1258
1259 def _initialize(self):
1260 """Initialize the wizard."""
1261 self._fleet = None
1262 self._fleetCallback = None
1263 self._updatePlaneCallback = None
1264
1265 self._loginResult = None
1266 self._bookedFlight = None
1267 self._departureGate = "-"
1268 self._zfw = None
1269 self._cruiseAltitude = None
1270 self._route = None
1271 self._departureNOTAMs = None
1272 self._departureMETAR = None
1273 self._arrivalNOTAMs = None
1274 self._arrivalMETAR = None
1275
1276 for page in self._pages:
1277 page.reset()
1278
1279 self.setCurrentPage(0)
1280
1281 def _getFleet(self, callback, force = False):
1282 """Get the fleet, if needed.
1283
1284 callback is function that will be called, when the feet is retrieved,
1285 or the retrieval fails. It should have a single argument that will
1286 receive the fleet object on success, None otherwise.
1287 """
1288 if self._fleet is not None and not force:
1289 callback(self._fleet)
1290
1291 self.gui.beginBusy("Retrieving fleet...")
1292 self._fleetCallback = callback
1293 self.gui.webHandler.getFleet(self._fleetResultCallback)
1294
1295 def _fleetResultCallback(self, returned, result):
1296 """Called when the fleet has been queried."""
1297 gobject.idle_add(self._handleFleetResult, returned, result)
1298
1299 def _handleFleetResult(self, returned, result):
1300 """Handle the fleet result."""
1301 self.gui.endBusy()
1302 if returned:
1303 self._fleet = result.fleet
1304 else:
1305 self._fleet = None
1306
1307 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
1308 buttons = BUTTONSTYPE_OK,
1309 message_format =
1310 "Failed to retrieve the information on "
1311 "the fleet.")
1312 dialog.run()
1313 dialog.hide()
1314
1315 self._fleetCallback(self._fleet)
1316
1317 def _updatePlane(self, callback, tailNumber, status, gateNumber = None):
1318 """Update the given plane's gate information."""
1319 self.gui.beginBusy("Updating plane status...")
1320 self._updatePlaneCallback = callback
1321 self.gui.webHandler.updatePlane(self._updatePlaneResultCallback,
1322 tailNumber, status, gateNumber)
1323
1324 def _updatePlaneResultCallback(self, returned, result):
1325 """Callback for the plane updating operation."""
1326 gobject.idle_add(self._handleUpdatePlaneResult, returned, result)
1327
1328 def _handleUpdatePlaneResult(self, returned, result):
1329 """Handle the result of a plane update operation."""
1330 self.gui.endBusy()
1331 if returned:
1332 success = result.success
1333 else:
1334 success = None
1335
1336 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
1337 buttons = BUTTONSTYPE_OK,
1338 message_format =
1339 "Failed to update the statuis of "
1340 "the airplane.")
1341 dialog.run()
1342 dialog.hide()
1343
1344 self._updatePlaneCallback(success)
1345
1346 def _connectSimulator(self):
1347 """Connect to the simulator."""
1348 self.gui.connectSimulator(self._bookedFlight.aircraftType)
1349
1350#-----------------------------------------------------------------------------
1351
Note: See TracBrowser for help on using the repository browser.