source: src/mlx/gui/flight.py@ 71:2dba0ba6cd1b

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

Added the takeoff page.

File size: 56.4 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
1169 self._wizard.nextPage()
1170
1171#-----------------------------------------------------------------------------
1172
1173class TakeoffPage(Page):
1174 """Page for entering the takeoff data."""
1175 def __init__(self, wizard):
1176 """Construct the takeoff page."""
1177 help = "Enter the runway and SID used, as well as the speeds."
1178
1179 super(TakeoffPage, self).__init__(wizard, "Takeoff", help)
1180
1181 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
1182 xscale = 0.0, yscale = 0.0)
1183
1184 table = gtk.Table(5, 3)
1185 table.set_row_spacings(4)
1186 table.set_col_spacings(16)
1187 table.set_homogeneous(False)
1188 alignment.add(table)
1189 self.setMainWidget(alignment)
1190
1191 label = gtk.Label("Run_way:")
1192 label.set_use_underline(True)
1193 label.set_alignment(0.0, 0.5)
1194 table.attach(label, 0, 1, 0, 1)
1195
1196 self._runway = gtk.Entry()
1197 self._runway.set_width_chars(10)
1198 self._runway.set_tooltip_text("The runway the takeoff is performed from.")
1199 table.attach(self._runway, 1, 2, 0, 1)
1200 label.set_mnemonic_widget(self._runway)
1201
1202 label = gtk.Label("_SID:")
1203 label.set_use_underline(True)
1204 label.set_alignment(0.0, 0.5)
1205 table.attach(label, 0, 1, 1, 2)
1206
1207 self._sid = gtk.Entry()
1208 self._sid.set_width_chars(10)
1209 self._sid.set_tooltip_text("The Standard Instrument Deparature procedure followed.")
1210 table.attach(self._sid, 1, 2, 1, 2)
1211 label.set_mnemonic_widget(self._sid)
1212
1213 label = gtk.Label("V<sub>_1</sub>:")
1214 label.set_use_markup(True)
1215 label.set_use_underline(True)
1216 label.set_alignment(0.0, 0.5)
1217 table.attach(label, 0, 1, 2, 3)
1218
1219 self._v1 = gtk.SpinButton()
1220 self._v1.set_increments(step = 1, page = 10)
1221 self._v1.set_range(min = 50, max = 300)
1222 self._v1.set_value(100)
1223 self._v1.set_numeric(True)
1224 self._v1.set_tooltip_markup("The takeoff decision speed in knots.")
1225 table.attach(self._v1, 1, 2, 2, 3)
1226 label.set_mnemonic_widget(self._v1)
1227
1228 table.attach(gtk.Label("knots"), 2, 3, 2, 3)
1229
1230 label = gtk.Label("V<sub>_r</sub>:")
1231 label.set_use_markup(True)
1232 label.set_use_underline(True)
1233 label.set_alignment(0.0, 0.5)
1234 table.attach(label, 0, 1, 3, 4)
1235
1236 self._vr = gtk.SpinButton()
1237 self._vr.set_increments(step = 1, page = 10)
1238 self._vr.set_range(min = 50, max = 300)
1239 self._vr.set_value(110)
1240 self._vr.set_numeric(True)
1241 self._vr.set_tooltip_markup("The takeoff rotation speed in knots.")
1242 table.attach(self._vr, 1, 2, 3, 4)
1243 label.set_mnemonic_widget(self._vr)
1244
1245 table.attach(gtk.Label("knots"), 2, 3, 3, 4)
1246
1247 label = gtk.Label("V<sub>_2</sub>:")
1248 label.set_use_markup(True)
1249 label.set_use_underline(True)
1250 label.set_alignment(0.0, 0.5)
1251 table.attach(label, 0, 1, 4, 5)
1252
1253 self._v2 = gtk.SpinButton()
1254 self._v2.set_increments(step = 1, page = 10)
1255 self._v2.set_range(min = 50, max = 300)
1256 self._v2.set_value(120)
1257 self._v2.set_numeric(True)
1258 self._v2.set_tooltip_markup("The takeoff safety speed in knots.")
1259 table.attach(self._v2, 1, 2, 4, 5)
1260 label.set_mnemonic_widget(self._v2)
1261
1262 table.attach(gtk.Label("knots"), 2, 3, 4, 5)
1263
1264 button = self.addButton(gtk.STOCK_GO_BACK)
1265 button.set_use_stock(True)
1266 button.connect("clicked", self._backClicked)
1267
1268 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
1269 self._button.set_use_stock(True)
1270 self._button.connect("clicked", self._forwardClicked)
1271
1272 def activate(self):
1273 """Activate the page."""
1274 self._runway.set_sensitive(True)
1275 self._sid.set_sensitive(True)
1276 self._v1.set_sensitive(True)
1277 self._vr.set_sensitive(True)
1278 self._v2.set_sensitive(True)
1279
1280 def finalize(self):
1281 """Finalize the page."""
1282 self._runway.set_sensitive(False)
1283 self._sid.set_sensitive(False)
1284 self._v1.set_sensitive(False)
1285 self._vr.set_sensitive(False)
1286 self._v2.set_sensitive(False)
1287
1288 flight = self._wizard.gui.flight
1289 flight.v1 = self._v1.get_value_as_int()
1290 flight.vr = self._vr.get_value_as_int()
1291 flight.v2 = self._v2.get_value_as_int()
1292
1293 def _backClicked(self, button):
1294 """Called when the Back button is pressed."""
1295 self.goBack()
1296
1297 def _forwardClicked(self, button):
1298 """Called when the forward button is clicked."""
1299 #self._wizard.nextPage()
1300
1301#-----------------------------------------------------------------------------
1302
1303class Wizard(gtk.VBox):
1304 """The flight wizard."""
1305 def __init__(self, gui):
1306 """Construct the wizard."""
1307 super(Wizard, self).__init__()
1308
1309 self.gui = gui
1310
1311 self._pages = []
1312 self._currentPage = None
1313
1314 self._pages.append(LoginPage(self))
1315 self._pages.append(FlightSelectionPage(self))
1316 self._pages.append(GateSelectionPage(self))
1317 self._pages.append(ConnectPage(self))
1318 self._pages.append(PayloadPage(self))
1319 self._pages.append(TimePage(self))
1320 self._pages.append(RoutePage(self))
1321 self._pages.append(BriefingPage(self, True))
1322 self._pages.append(BriefingPage(self, False))
1323 self._pages.append(TakeoffPage(self))
1324
1325 maxWidth = 0
1326 maxHeight = 0
1327 for page in self._pages:
1328 page.show_all()
1329 pageSizeRequest = page.size_request()
1330 width = pageSizeRequest.width if pygobject else pageSizeRequest[0]
1331 height = pageSizeRequest.height if pygobject else pageSizeRequest[1]
1332 maxWidth = max(maxWidth, width)
1333 maxHeight = max(maxHeight, height)
1334 maxWidth += 16
1335 maxHeight += 32
1336 self.set_size_request(maxWidth, maxHeight)
1337
1338 self._initialize()
1339
1340 @property
1341 def loginResult(self):
1342 """Get the login result."""
1343 return self._loginResult
1344
1345 def setCurrentPage(self, index, finalize = False):
1346 """Set the current page to the one with the given index."""
1347 assert index < len(self._pages)
1348
1349 fromPage = self._currentPage
1350 if fromPage is not None:
1351 page = self._pages[fromPage]
1352 if finalize and not page._finalized:
1353 page.finalize()
1354 page._finalized = True
1355 self.remove(page)
1356
1357 self._currentPage = index
1358 page = self._pages[index]
1359 self.add(page)
1360 if page._fromPage is None:
1361 page._fromPage = fromPage
1362 page.activate()
1363 self.grabDefault()
1364 self.show_all()
1365
1366 def nextPage(self, finalize = True):
1367 """Go to the next page."""
1368 self.jumpPage(1, finalize)
1369
1370 def jumpPage(self, count, finalize = True):
1371 """Go to the page which is 'count' pages after the current one."""
1372 self.setCurrentPage(self._currentPage + count, finalize = finalize)
1373
1374 def grabDefault(self):
1375 """Make the default button of the current page the default."""
1376 self._pages[self._currentPage].grabDefault()
1377
1378 def connected(self, fsType, descriptor):
1379 """Called when the connection could be made to the simulator."""
1380 self.nextPage()
1381
1382 def connectionFailed(self):
1383 """Called when the connection could not be made to the simulator."""
1384 self._initialize()
1385
1386 def disconnected(self):
1387 """Called when we have disconnected from the simulator."""
1388 self._initialize()
1389
1390 def _initialize(self):
1391 """Initialize the wizard."""
1392 self._fleet = None
1393 self._fleetCallback = None
1394 self._updatePlaneCallback = None
1395
1396 self._loginResult = None
1397 self._bookedFlight = None
1398 self._departureGate = "-"
1399 self._zfw = None
1400 self._cruiseAltitude = None
1401 self._route = None
1402 self._departureNOTAMs = None
1403 self._departureMETAR = None
1404 self._arrivalNOTAMs = None
1405 self._arrivalMETAR = None
1406
1407 for page in self._pages:
1408 page.reset()
1409
1410 self.setCurrentPage(0)
1411
1412 def _getFleet(self, callback, force = False):
1413 """Get the fleet, if needed.
1414
1415 callback is function that will be called, when the feet is retrieved,
1416 or the retrieval fails. It should have a single argument that will
1417 receive the fleet object on success, None otherwise.
1418 """
1419 if self._fleet is not None and not force:
1420 callback(self._fleet)
1421
1422 self.gui.beginBusy("Retrieving fleet...")
1423 self._fleetCallback = callback
1424 self.gui.webHandler.getFleet(self._fleetResultCallback)
1425
1426 def _fleetResultCallback(self, returned, result):
1427 """Called when the fleet has been queried."""
1428 gobject.idle_add(self._handleFleetResult, returned, result)
1429
1430 def _handleFleetResult(self, returned, result):
1431 """Handle the fleet result."""
1432 self.gui.endBusy()
1433 if returned:
1434 self._fleet = result.fleet
1435 else:
1436 self._fleet = None
1437
1438 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
1439 buttons = BUTTONSTYPE_OK,
1440 message_format =
1441 "Failed to retrieve the information on "
1442 "the fleet.")
1443 dialog.run()
1444 dialog.hide()
1445
1446 self._fleetCallback(self._fleet)
1447
1448 def _updatePlane(self, callback, tailNumber, status, gateNumber = None):
1449 """Update the given plane's gate information."""
1450 self.gui.beginBusy("Updating plane status...")
1451 self._updatePlaneCallback = callback
1452 self.gui.webHandler.updatePlane(self._updatePlaneResultCallback,
1453 tailNumber, status, gateNumber)
1454
1455 def _updatePlaneResultCallback(self, returned, result):
1456 """Callback for the plane updating operation."""
1457 gobject.idle_add(self._handleUpdatePlaneResult, returned, result)
1458
1459 def _handleUpdatePlaneResult(self, returned, result):
1460 """Handle the result of a plane update operation."""
1461 self.gui.endBusy()
1462 if returned:
1463 success = result.success
1464 else:
1465 success = None
1466
1467 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
1468 buttons = BUTTONSTYPE_OK,
1469 message_format =
1470 "Failed to update the statuis of "
1471 "the airplane.")
1472 dialog.run()
1473 dialog.hide()
1474
1475 self._updatePlaneCallback(success)
1476
1477 def _connectSimulator(self):
1478 """Connect to the simulator."""
1479 self.gui.connectSimulator(self._bookedFlight.aircraftType)
1480
1481#-----------------------------------------------------------------------------
1482
Note: See TracBrowser for help on using the repository browser.