source: src/mlx/gui/flight.py@ 74:1aba83981490

Last change on this file since 74:1aba83981490 was 73:0108dbf6b53f, checked in by István Váradi <ivaradi@…>, 13 years ago

The gate selection page has a back button

File size: 57.5 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 button = self.addButton(gtk.STOCK_GO_BACK)
413 button.set_use_stock(True)
414 button.connect("clicked", self._backClicked)
415
416 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
417 self._button.set_use_stock(True)
418 self._button.set_sensitive(False)
419 self._button.connect("clicked", self._forwardClicked)
420
421 def activate(self):
422 """Fill the gate list."""
423 self._listStore.clear()
424 self._gateList.set_sensitive(True)
425 occupiedGateNumbers = self._wizard._fleet.getOccupiedGateNumbers()
426 for gateNumber in const.lhbpGateNumbers:
427 if gateNumber not in occupiedGateNumbers:
428 self._listStore.append([gateNumber])
429
430 def finalize(self):
431 """Finalize the page."""
432 self._gateList.set_sensitive(False)
433
434 def _selectionChanged(self, selection):
435 """Called when the selection is changed."""
436 self._button.set_sensitive(selection.count_selected_rows()==1)
437
438 def _backClicked(self, button):
439 """Called when the Back button is pressed."""
440 self.goBack()
441
442 def _forwardClicked(self, button):
443 """Called when the forward button is clicked."""
444 if not self._finalized:
445 selection = self._gateList.get_selection()
446 (listStore, iter) = selection.get_selected()
447 (gateNumber,) = listStore.get(iter, 0)
448
449 self._wizard._departureGate = gateNumber
450
451 #self._wizard._updatePlane(self._planeUpdated,
452 # self._wizard._bookedFlight.tailNumber,
453 # const.PLANE_HOME,
454 # gateNumber)
455
456 self._wizard.nextPage()
457
458 def _planeUpdated(self, success):
459 """Callback for the plane updating call."""
460 if success is None or success:
461 self._wizard.nextPage()
462 else:
463 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
464 buttons = BUTTONSTYPE_OK,
465 message_format = "Gate conflict detected again")
466 dialog.format_secondary_markup("Try to select a different gate.")
467 dialog.run()
468 dialog.hide()
469
470 self._wizard._getFleet(self._fleetRetrieved)
471
472 def _fleetRetrieved(self, fleet):
473 """Called when the fleet has been retrieved."""
474 if fleet is None:
475 self._wizard.nextPage()
476 else:
477 self.activate()
478
479#-----------------------------------------------------------------------------
480
481class ConnectPage(Page):
482 """Page which displays the departure airport and gate (if at LHBP)."""
483 def __init__(self, wizard):
484 """Construct the connect page."""
485 help = "The flight begins at the airport given below.\n" \
486 "Park your aircraft there, at the gate below, if given.\n\n" \
487 "Then press the Connect button to connect to the simulator."
488 super(ConnectPage, self).__init__(wizard,
489 "Connect to the simulator",
490 help)
491
492 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
493 xscale = 0.0, yscale = 0.0)
494
495 table = gtk.Table(2, 2)
496 table.set_row_spacings(4)
497 table.set_col_spacings(16)
498 table.set_homogeneous(True)
499 alignment.add(table)
500 self.setMainWidget(alignment)
501
502 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
503 label = gtk.Label("ICAO code:")
504 labelAlignment.add(label)
505 table.attach(labelAlignment, 0, 1, 0, 1)
506
507 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
508 self._departureICAO = gtk.Label()
509 self._departureICAO.set_width_chars(5)
510 self._departureICAO.set_alignment(0.0, 0.5)
511 labelAlignment.add(self._departureICAO)
512 table.attach(labelAlignment, 1, 2, 0, 1)
513
514 labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
515 label = gtk.Label("Gate:")
516 labelAlignment.add(label)
517 table.attach(labelAlignment, 0, 1, 1, 2)
518
519 labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
520 self._departureGate = gtk.Label()
521 self._departureGate.set_width_chars(5)
522 self._departureGate.set_alignment(0.0, 0.5)
523 labelAlignment.add(self._departureGate)
524 table.attach(labelAlignment, 1, 2, 1, 2)
525
526 button = self.addButton(gtk.STOCK_GO_BACK)
527 button.set_use_stock(True)
528 button.connect("clicked", self._backClicked)
529
530 self._button = self.addButton("_Connect", default = True)
531 self._button.set_use_underline(True)
532 self._clickedID = self._button.connect("clicked", self._connectClicked)
533
534 def activate(self):
535 """Setup the departure information."""
536 self._button.set_label("_Connect")
537 self._button.set_use_underline(True)
538 self._button.disconnect(self._clickedID)
539 self._clickedID = self._button.connect("clicked", self._connectClicked)
540
541 icao = self._wizard._bookedFlight.departureICAO
542 self._departureICAO.set_markup("<b>" + icao + "</b>")
543 gate = self._wizard._departureGate
544 if gate!="-":
545 gate = "<b>" + gate + "</b>"
546 self._departureGate.set_markup(gate)
547
548 def finalize(self):
549 """Finalize the page."""
550 self._button.set_label(gtk.STOCK_GO_FORWARD)
551 self._button.set_use_stock(True)
552 self._button.disconnect(self._clickedID)
553 self._clickedID = self._button.connect("clicked", self._forwardClicked)
554
555 def _backClicked(self, button):
556 """Called when the Back button is pressed."""
557 self.goBack()
558
559 def _connectClicked(self, button):
560 """Called when the Connect button is pressed."""
561 self._wizard._connectSimulator()
562
563 def _forwardClicked(self, button):
564 """Called when the Forward button is pressed."""
565 self._wizard.nextPage()
566
567#-----------------------------------------------------------------------------
568
569class PayloadPage(Page):
570 """Page to allow setting up the payload."""
571 def __init__(self, wizard):
572 """Construct the page."""
573 help = "The briefing contains the weights below.\n" \
574 "Setup the cargo weight here and the payload weight in the simulator.\n\n" \
575 "You can also check here what the simulator reports as ZFW."
576
577 super(PayloadPage, self).__init__(wizard, "Payload", help)
578
579 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
580 xscale = 0.0, yscale = 0.0)
581
582 table = gtk.Table(7, 3)
583 table.set_row_spacings(4)
584 table.set_col_spacings(16)
585 table.set_homogeneous(False)
586 alignment.add(table)
587 self.setMainWidget(alignment)
588
589 label = gtk.Label("Crew:")
590 label.set_alignment(0.0, 0.5)
591 table.attach(label, 0, 1, 0, 1)
592
593 self._numCrew = gtk.Label()
594 self._numCrew.set_width_chars(6)
595 self._numCrew.set_alignment(1.0, 0.5)
596 table.attach(self._numCrew, 1, 2, 0, 1)
597
598 label = gtk.Label("Passengers:")
599 label.set_alignment(0.0, 0.5)
600 table.attach(label, 0, 1, 1, 2)
601
602 self._numPassengers = gtk.Label()
603 self._numPassengers.set_width_chars(6)
604 self._numPassengers.set_alignment(1.0, 0.5)
605 table.attach(self._numPassengers, 1, 2, 1, 2)
606
607 label = gtk.Label("Baggage:")
608 label.set_alignment(0.0, 0.5)
609 table.attach(label, 0, 1, 2, 3)
610
611 self._bagWeight = gtk.Label()
612 self._bagWeight.set_width_chars(6)
613 self._bagWeight.set_alignment(1.0, 0.5)
614 table.attach(self._bagWeight, 1, 2, 2, 3)
615
616 table.attach(gtk.Label("kg"), 2, 3, 2, 3)
617
618 label = gtk.Label("_Cargo:")
619 label.set_use_underline(True)
620 label.set_alignment(0.0, 0.5)
621 table.attach(label, 0, 1, 3, 4)
622
623 self._cargoWeight = gtk.Entry()
624 self._cargoWeight.set_width_chars(6)
625 self._cargoWeight.set_alignment(1.0)
626 self._cargoWeight.connect("changed", self._cargoWeightChanged)
627 self._cargoWeight.set_tooltip_text("The weight of the cargo for your flight.")
628 table.attach(self._cargoWeight, 1, 2, 3, 4)
629 self._cargoWeightValue = 0
630 label.set_mnemonic_widget(self._cargoWeight)
631
632 table.attach(gtk.Label("kg"), 2, 3, 3, 4)
633
634 label = gtk.Label("Mail:")
635 label.set_alignment(0.0, 0.5)
636 table.attach(label, 0, 1, 4, 5)
637
638 self._mailWeight = gtk.Label()
639 self._mailWeight.set_width_chars(6)
640 self._mailWeight.set_alignment(1.0, 0.5)
641 table.attach(self._mailWeight, 1, 2, 4, 5)
642
643 table.attach(gtk.Label("kg"), 2, 3, 4, 5)
644
645 label = gtk.Label("<b>Calculated ZFW:</b>")
646 label.set_alignment(0.0, 0.5)
647 label.set_use_markup(True)
648 table.attach(label, 0, 1, 5, 6)
649
650 self._calculatedZFW = gtk.Label()
651 self._calculatedZFW.set_width_chars(6)
652 self._calculatedZFW.set_alignment(1.0, 0.5)
653 table.attach(self._calculatedZFW, 1, 2, 5, 6)
654
655 table.attach(gtk.Label("kg"), 2, 3, 5, 6)
656
657 self._zfwButton = gtk.Button("_ZFW from FS:")
658 self._zfwButton.set_use_underline(True)
659 self._zfwButton.connect("clicked", self._zfwRequested)
660 table.attach(self._zfwButton, 0, 1, 6, 7)
661
662 self._simulatorZFW = gtk.Label("-")
663 self._simulatorZFW.set_width_chars(6)
664 self._simulatorZFW.set_alignment(1.0, 0.5)
665 table.attach(self._simulatorZFW, 1, 2, 6, 7)
666 self._simulatorZFWValue = None
667
668 table.attach(gtk.Label("kg"), 2, 3, 6, 7)
669
670 self._backButton = self.addButton(gtk.STOCK_GO_BACK)
671 self._backButton.set_use_stock(True)
672 self._backButton.connect("clicked", self._backClicked)
673
674 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
675 self._button.set_use_stock(True)
676 self._button.connect("clicked", self._forwardClicked)
677
678 def activate(self):
679 """Setup the information."""
680 bookedFlight = self._wizard._bookedFlight
681 self._numCrew.set_text(str(bookedFlight.numCrew))
682 self._numPassengers.set_text(str(bookedFlight.numPassengers))
683 self._bagWeight.set_text(str(bookedFlight.bagWeight))
684 self._cargoWeightValue = bookedFlight.cargoWeight
685 self._cargoWeight.set_text(str(bookedFlight.cargoWeight))
686 self._cargoWeight.set_sensitive(True)
687 self._mailWeight.set_text(str(bookedFlight.mailWeight))
688 self._zfwButton.set_sensitive(True)
689 self._updateCalculatedZFW()
690
691 def finalize(self):
692 """Finalize the payload page."""
693 self._cargoWeight.set_sensitive(False)
694 self._zfwButton.set_sensitive(False)
695
696 def _calculateZFW(self):
697 """Calculate the ZFW value."""
698 zfw = self._wizard.gui._flight.aircraft.dow
699 bookedFlight = self._wizard._bookedFlight
700 zfw += (bookedFlight.numCrew + bookedFlight.numPassengers) * 82
701 zfw += bookedFlight.bagWeight
702 zfw += self._cargoWeightValue
703 zfw += bookedFlight.mailWeight
704 return zfw
705
706 def _updateCalculatedZFW(self):
707 """Update the calculated ZFW"""
708 zfw = self._calculateZFW()
709
710 markupBegin = "<b>"
711 markupEnd = "</b>"
712 if self._simulatorZFWValue is not None and \
713 PayloadChecker.isZFWFaulty(self._simulatorZFWValue, zfw):
714 markupBegin += '<span foreground="red">'
715 markupEnd = "</span>" + markupEnd
716 self._calculatedZFW.set_markup(markupBegin + str(zfw) + markupEnd)
717
718 def _cargoWeightChanged(self, entry):
719 """Called when the cargo weight has changed."""
720 text = self._cargoWeight.get_text()
721 if text=="":
722 self._cargoWeightValue = 0
723 else:
724 try:
725 self._cargoWeightValue = int(text)
726 except:
727 self._cargoWeight.set_text(str(self._cargoWeightValue))
728 self._updateCalculatedZFW()
729
730 def _zfwRequested(self, button):
731 """Called when the ZFW is requested from the simulator."""
732 self._zfwButton.set_sensitive(False)
733 self._backButton.set_sensitive(False)
734 self._button.set_sensitive(False)
735 gui = self._wizard.gui
736 gui.beginBusy("Querying ZFW...")
737 gui.simulator.requestZFW(self._handleZFW)
738
739 def _handleZFW(self, zfw):
740 """Called when the ZFW value is retrieved."""
741 gobject.idle_add(self._processZFW, zfw)
742
743 def _processZFW(self, zfw):
744 """Process the given ZFW value received from the simulator."""
745 self._wizard.gui.endBusy()
746 self._zfwButton.set_sensitive(True)
747 self._backButton.set_sensitive(True)
748 self._button.set_sensitive(True)
749 self._simulatorZFWValue = zfw
750 self._simulatorZFW.set_text("%.0f" % (zfw,))
751 self._updateCalculatedZFW()
752
753 def _forwardClicked(self, button):
754 """Called when the forward button is clicked."""
755 if not self._finalized:
756 self._wizard._zfw = self._calculateZFW()
757 self._wizard.nextPage()
758
759 def _backClicked(self, button):
760 """Called when the Back button is pressed."""
761 self.goBack()
762
763#-----------------------------------------------------------------------------
764
765class TimePage(Page):
766 """Page displaying the departure and arrival times and allows querying the
767 current time from the flight simulator."""
768 def __init__(self, wizard):
769 help = "The departure and arrival times are displayed below in UTC.\n\n" \
770 "You can also query the current UTC time from the simulator.\n" \
771 "Ensure that you have enough time to properly prepare for the flight."
772
773 super(TimePage, self).__init__(wizard, "Time", help)
774
775 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
776 xscale = 0.0, yscale = 0.0)
777
778 table = gtk.Table(3, 2)
779 table.set_row_spacings(4)
780 table.set_col_spacings(16)
781 table.set_homogeneous(False)
782 alignment.add(table)
783 self.setMainWidget(alignment)
784
785 label = gtk.Label("Departure:")
786 label.set_alignment(0.0, 0.5)
787 table.attach(label, 0, 1, 0, 1)
788
789 self._departure = gtk.Label()
790 self._departure.set_alignment(0.0, 0.5)
791 table.attach(self._departure, 1, 2, 0, 1)
792
793 label = gtk.Label("Arrival:")
794 label.set_alignment(0.0, 0.5)
795 table.attach(label, 0, 1, 1, 2)
796
797 self._arrival = gtk.Label()
798 self._arrival.set_alignment(0.0, 0.5)
799 table.attach(self._arrival, 1, 2, 1, 2)
800
801 self._timeButton = gtk.Button("_Time from FS:")
802 self._timeButton.set_use_underline(True)
803 self._timeButton.connect("clicked", self._timeRequested)
804 table.attach(self._timeButton, 0, 1, 2, 3)
805
806 self._simulatorTime = gtk.Label("-")
807 self._simulatorTime.set_alignment(0.0, 0.5)
808 table.attach(self._simulatorTime, 1, 2, 2, 3)
809
810 self._backButton = self.addButton(gtk.STOCK_GO_BACK)
811 self._backButton.set_use_stock(True)
812 self._backButton.connect("clicked", self._backClicked)
813
814 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
815 self._button.set_use_stock(True)
816 self._button.connect("clicked", self._forwardClicked)
817
818 def activate(self):
819 """Activate the page."""
820 self._timeButton.set_sensitive(True)
821 bookedFlight = self._wizard._bookedFlight
822 self._departure.set_text(str(bookedFlight.departureTime.time()))
823 self._arrival.set_text(str(bookedFlight.arrivalTime.time()))
824
825 def finalize(self):
826 """Finalize the page."""
827 self._timeButton.set_sensitive(False)
828
829 def _timeRequested(self, button):
830 """Request the time from the simulator."""
831 self._timeButton.set_sensitive(False)
832 self._backButton.set_sensitive(False)
833 self._button.set_sensitive(False)
834 self._wizard.gui.beginBusy("Querying time...")
835 self._wizard.gui.simulator.requestTime(self._handleTime)
836
837 def _handleTime(self, timestamp):
838 """Handle the result of a time retrieval."""
839 gobject.idle_add(self._processTime, timestamp)
840
841 def _processTime(self, timestamp):
842 """Process the given time."""
843 self._wizard.gui.endBusy()
844 self._timeButton.set_sensitive(True)
845 self._backButton.set_sensitive(True)
846 self._button.set_sensitive(True)
847 tm = time.gmtime(timestamp)
848 t = datetime.time(tm.tm_hour, tm.tm_min, tm.tm_sec)
849 self._simulatorTime.set_text(str(t))
850
851 ts = tm.tm_hour * 3600 + tm.tm_min * 60 + tm.tm_sec
852 dt = self._wizard._bookedFlight.departureTime.time()
853 dts = dt.hour * 3600 + dt.minute * 60 + dt.second
854 diff = dts-ts
855
856 markupBegin = ""
857 markupEnd = ""
858 if diff < 0:
859 markupBegin = '<b><span foreground="red">'
860 markupEnd = '</span></b>'
861 elif diff < 3*60 or diff > 30*60:
862 markupBegin = '<b><span foreground="orange">'
863 markupEnd = '</span></b>'
864
865 self._departure.set_markup(markupBegin + str(dt) + markupEnd)
866
867 def _backClicked(self, button):
868 """Called when the Back button is pressed."""
869 self.goBack()
870
871 def _forwardClicked(self, button):
872 """Called when the forward button is clicked."""
873 self._wizard.nextPage()
874
875#-----------------------------------------------------------------------------
876
877class RoutePage(Page):
878 """The page containing the route and the flight level."""
879 def __init__(self, wizard):
880 help = "Set your cruise flight level below, and\n" \
881 "if necessary, edit the flight plan."
882
883 super(RoutePage, self).__init__(wizard, "Route", help)
884
885 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
886 xscale = 0.0, yscale = 0.0)
887
888 mainBox = gtk.VBox()
889 alignment.add(mainBox)
890 self.setMainWidget(alignment)
891
892 levelBox = gtk.HBox()
893
894 label = gtk.Label("_Cruise level")
895 label.set_use_underline(True)
896 levelBox.pack_start(label, True, True, 0)
897
898 self._cruiseLevel = gtk.SpinButton()
899 self._cruiseLevel.set_increments(step = 10, page = 100)
900 self._cruiseLevel.set_range(min = 50, max = 500)
901 self._cruiseLevel.set_value(240)
902 self._cruiseLevel.set_tooltip_text("The cruise flight level.")
903 self._cruiseLevel.set_numeric(True)
904 self._cruiseLevel.connect("value-changed", self._cruiseLevelChanged)
905 label.set_mnemonic_widget(self._cruiseLevel)
906
907 levelBox.pack_start(self._cruiseLevel, False, False, 8)
908
909 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
910 xscale = 0.0, yscale = 0.0)
911 alignment.add(levelBox)
912
913 mainBox.pack_start(alignment, False, False, 0)
914
915
916 routeBox = gtk.VBox()
917
918 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
919 xscale = 0.0, yscale = 0.0)
920 label = gtk.Label("_Route")
921 label.set_use_underline(True)
922 alignment.add(label)
923 routeBox.pack_start(alignment, True, True, 0)
924
925 routeWindow = gtk.ScrolledWindow()
926 routeWindow.set_size_request(400, 80)
927 routeWindow.set_shadow_type(gtk.ShadowType.IN if pygobject
928 else gtk.SHADOW_IN)
929 routeWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
930 else gtk.POLICY_AUTOMATIC,
931 gtk.PolicyType.AUTOMATIC if pygobject
932 else gtk.POLICY_AUTOMATIC)
933
934 self._route = gtk.TextView()
935 self._route.set_tooltip_text("The planned flight route.")
936 self._route.get_buffer().connect("changed", self._routeChanged)
937 routeWindow.add(self._route)
938
939 label.set_mnemonic_widget(self._route)
940 routeBox.pack_start(routeWindow, True, True, 0)
941
942 mainBox.pack_start(routeBox, True, True, 8)
943
944 self._backButton = self.addButton(gtk.STOCK_GO_BACK)
945 self._backButton.set_use_stock(True)
946 self._backButton.connect("clicked", self._backClicked)
947
948 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
949 self._button.set_use_stock(True)
950 self._button.connect("clicked", self._forwardClicked)
951
952 def activate(self):
953 """Setup the route from the booked flight."""
954 self._route.set_sensitive(True)
955 self._cruiseLevel.set_sensitive(True)
956 self._route.get_buffer().set_text(self._wizard._bookedFlight.route)
957 self._updateForwardButton()
958
959 def finalize(self):
960 """Finalize the page."""
961 self._route.set_sensitive(False)
962 self._cruiseLevel.set_sensitive(False)
963
964 def _getRoute(self):
965 """Get the text of the route."""
966 buffer = self._route.get_buffer()
967 return buffer.get_text(buffer.get_start_iter(),
968 buffer.get_end_iter(), True)
969
970 def _updateForwardButton(self):
971 """Update the sensitivity of the forward button."""
972 self._button.set_sensitive(self._cruiseLevel.get_value_as_int()>=50 and \
973 self._getRoute()!="")
974
975 def _cruiseLevelChanged(self, spinButton):
976 """Called when the cruise level has changed."""
977 self._updateForwardButton()
978
979 def _routeChanged(self, textBuffer):
980 """Called when the route has changed."""
981 self._updateForwardButton()
982
983 def _backClicked(self, button):
984 """Called when the Back button is pressed."""
985 self.goBack()
986
987 def _forwardClicked(self, button):
988 """Called when the Forward button is clicked."""
989 if self._finalized:
990 self._wizard.nextPage()
991 else:
992 self._wizard._cruiseAltitude = self._cruiseLevel.get_value_as_int() * 100
993 self._wizard._route = self._getRoute()
994
995 self._backButton.set_sensitive(False)
996 self._button.set_sensitive(False)
997 self._cruiseLevel.set_sensitive(False)
998 self._route.set_sensitive(False)
999
1000 bookedFlight = self._wizard._bookedFlight
1001 self._wizard.gui.beginBusy("Downloading NOTAMs...")
1002 self._wizard.gui.webHandler.getNOTAMs(self._notamsCallback,
1003 bookedFlight.departureICAO,
1004 bookedFlight.arrivalICAO)
1005
1006 def _notamsCallback(self, returned, result):
1007 """Callback for the NOTAMs."""
1008 gobject.idle_add(self._handleNOTAMs, returned, result)
1009
1010 def _handleNOTAMs(self, returned, result):
1011 """Handle the NOTAMs."""
1012 if returned:
1013 self._wizard._departureNOTAMs = result.departureNOTAMs
1014 self._wizard._arrivalNOTAMs = result.arrivalNOTAMs
1015 else:
1016 self._wizard._departureNOTAMs = None
1017 self._wizard._arrivalNOTAMs = None
1018
1019 bookedFlight = self._wizard._bookedFlight
1020 self._wizard.gui.beginBusy("Downloading METARs...")
1021 self._wizard.gui.webHandler.getMETARs(self._metarsCallback,
1022 [bookedFlight.departureICAO,
1023 bookedFlight.arrivalICAO])
1024
1025 def _metarsCallback(self, returned, result):
1026 """Callback for the METARs."""
1027 gobject.idle_add(self._handleMETARs, returned, result)
1028
1029 def _handleMETARs(self, returned, result):
1030 """Handle the METARs."""
1031 self._wizard._departureMETAR = None
1032 self._wizard._arrivalMETAR = None
1033 bookedFlight = self._wizard._bookedFlight
1034 if returned:
1035 if bookedFlight.departureICAO in result.metars:
1036 self._wizard._departureMETAR = result.metars[bookedFlight.departureICAO]
1037 if bookedFlight.arrivalICAO in result.metars:
1038 self._wizard._arrivalMETAR = result.metars[bookedFlight.arrivalICAO]
1039
1040 self._wizard.gui.endBusy()
1041 self._backButton.set_sensitive(True)
1042 self._button.set_sensitive(True)
1043 self._wizard.nextPage()
1044
1045#-----------------------------------------------------------------------------
1046
1047class BriefingPage(Page):
1048 """Page for the briefing."""
1049 def __init__(self, wizard, departure):
1050 """Construct the briefing page."""
1051 self._departure = departure
1052
1053 title = "Briefing (%d/2): %s" % (1 if departure else 2,
1054 "departure" if departure
1055 else "arrival")
1056
1057 help = "Read carefully the NOTAMs and METAR below."
1058
1059 super(BriefingPage, self).__init__(wizard, title, help)
1060
1061 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
1062 xscale = 1.0, yscale = 1.0)
1063
1064 mainBox = gtk.VBox()
1065 alignment.add(mainBox)
1066 self.setMainWidget(alignment)
1067
1068 self._notamsFrame = gtk.Frame()
1069 self._notamsFrame.set_label("LHBP NOTAMs")
1070 scrolledWindow = gtk.ScrolledWindow()
1071 scrolledWindow.set_size_request(-1, 128)
1072 scrolledWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
1073 else gtk.POLICY_AUTOMATIC,
1074 gtk.PolicyType.AUTOMATIC if pygobject
1075 else gtk.POLICY_AUTOMATIC)
1076 self._notams = gtk.TextView()
1077 self._notams.set_editable(False)
1078 self._notams.set_accepts_tab(False)
1079 self._notams.set_wrap_mode(gtk.WrapMode.WORD if pygobject else gtk.WRAP_WORD)
1080 scrolledWindow.add(self._notams)
1081 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
1082 xscale = 1.0, yscale = 1.0)
1083 alignment.set_padding(padding_top = 4, padding_bottom = 0,
1084 padding_left = 0, padding_right = 0)
1085 alignment.add(scrolledWindow)
1086 self._notamsFrame.add(alignment)
1087 mainBox.pack_start(self._notamsFrame, True, True, 4)
1088
1089 self._metarFrame = gtk.Frame()
1090 self._metarFrame.set_label("LHBP METAR")
1091 scrolledWindow = gtk.ScrolledWindow()
1092 scrolledWindow.set_size_request(-1, 32)
1093 scrolledWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
1094 else gtk.POLICY_AUTOMATIC,
1095 gtk.PolicyType.AUTOMATIC if pygobject
1096 else gtk.POLICY_AUTOMATIC)
1097 self._metar = gtk.TextView()
1098 self._metar.set_editable(False)
1099 self._metar.set_accepts_tab(False)
1100 self._metar.set_wrap_mode(gtk.WrapMode.WORD if pygobject else gtk.WRAP_WORD)
1101 scrolledWindow.add(self._metar)
1102 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
1103 xscale = 1.0, yscale = 1.0)
1104 alignment.set_padding(padding_top = 4, padding_bottom = 0,
1105 padding_left = 0, padding_right = 0)
1106 alignment.add(scrolledWindow)
1107 self._metarFrame.add(alignment)
1108 mainBox.pack_start(self._metarFrame, True, True, 4)
1109
1110 button = self.addButton(gtk.STOCK_GO_BACK)
1111 button.set_use_stock(True)
1112 button.connect("clicked", self._backClicked)
1113
1114 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
1115 self._button.set_use_stock(True)
1116 self._button.connect("clicked", self._forwardClicked)
1117
1118 def activate(self):
1119 """Activate the page."""
1120 if not self._departure:
1121 self._button.set_label("I have read the briefing and am ready to fly!")
1122 self._button.set_use_stock(False)
1123
1124 bookedFlight = self._wizard._bookedFlight
1125
1126 icao = bookedFlight.departureICAO if self._departure \
1127 else bookedFlight.arrivalICAO
1128 notams = self._wizard._departureNOTAMs if self._departure \
1129 else self._wizard._arrivalNOTAMs
1130 metar = self._wizard._departureMETAR if self._departure \
1131 else self._wizard._arrivalMETAR
1132
1133 self._notamsFrame.set_label(icao + " NOTAMs")
1134 buffer = self._notams.get_buffer()
1135 if notams is None:
1136 buffer.set_text("Could not download NOTAMs")
1137 else:
1138 s = ""
1139 for notam in notams:
1140 s += str(notam.begin)
1141 if notam.end is not None:
1142 s += " - " + str(notam.end)
1143 elif notam.permanent:
1144 s += " - PERMANENT"
1145 s += "\n"
1146 if notam.repeatCycle:
1147 s += "Repeat cycle: " + notam.repeatCycle + "\n"
1148 s += notam.notice + "\n"
1149 s += "-------------------- * --------------------\n"
1150 buffer.set_text(s)
1151
1152 self._metarFrame.set_label(icao + " METAR")
1153 buffer = self._metar.get_buffer()
1154 if metar is None:
1155 buffer.set_text("Could not download METAR")
1156 else:
1157 buffer.set_text(metar)
1158
1159 def finalize(self):
1160 """Finalize the page."""
1161 if not self._departure:
1162 self._button.set_use_stock(True)
1163 self._button.set_label(gtk.STOCK_GO_FORWARD)
1164
1165 def _backClicked(self, button):
1166 """Called when the Back button is pressed."""
1167 self.goBack()
1168
1169 def _forwardClicked(self, button):
1170 """Called when the forward button is clicked."""
1171 if not self._departure:
1172 if not self._finalized:
1173 self._wizard.gui.startMonitoring()
1174 self.finalize()
1175 self._finalized = True
1176
1177 self._wizard.nextPage()
1178
1179#-----------------------------------------------------------------------------
1180
1181class TakeoffPage(Page):
1182 """Page for entering the takeoff data."""
1183 def __init__(self, wizard):
1184 """Construct the takeoff page."""
1185 help = "Enter the runway and SID used, as well as the speeds."
1186
1187 super(TakeoffPage, self).__init__(wizard, "Takeoff", help)
1188
1189 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
1190 xscale = 0.0, yscale = 0.0)
1191
1192 table = gtk.Table(5, 3)
1193 table.set_row_spacings(4)
1194 table.set_col_spacings(16)
1195 table.set_homogeneous(False)
1196 alignment.add(table)
1197 self.setMainWidget(alignment)
1198
1199 label = gtk.Label("Run_way:")
1200 label.set_use_underline(True)
1201 label.set_alignment(0.0, 0.5)
1202 table.attach(label, 0, 1, 0, 1)
1203
1204 self._runway = gtk.Entry()
1205 self._runway.set_width_chars(10)
1206 self._runway.set_tooltip_text("The runway the takeoff is performed from.")
1207 self._runway.connect("changed", self._updateForwardButton)
1208 table.attach(self._runway, 1, 2, 0, 1)
1209 label.set_mnemonic_widget(self._runway)
1210
1211 label = gtk.Label("_SID:")
1212 label.set_use_underline(True)
1213 label.set_alignment(0.0, 0.5)
1214 table.attach(label, 0, 1, 1, 2)
1215
1216 self._sid = gtk.Entry()
1217 self._sid.set_width_chars(10)
1218 self._sid.set_tooltip_text("The Standard Instrument Deparature procedure followed.")
1219 self._sid.connect("changed", self._updateForwardButton)
1220 table.attach(self._sid, 1, 2, 1, 2)
1221 label.set_mnemonic_widget(self._sid)
1222
1223 label = gtk.Label("V<sub>_1</sub>:")
1224 label.set_use_markup(True)
1225 label.set_use_underline(True)
1226 label.set_alignment(0.0, 0.5)
1227 table.attach(label, 0, 1, 2, 3)
1228
1229 self._v1 = gtk.SpinButton()
1230 self._v1.set_increments(step = 1, page = 10)
1231 self._v1.set_range(min = 50, max = 300)
1232 self._v1.set_value(100)
1233 self._v1.set_numeric(True)
1234 self._v1.set_tooltip_markup("The takeoff decision speed in knots.")
1235 self._v1.connect("changed", self._updateForwardButton)
1236 table.attach(self._v1, 1, 2, 2, 3)
1237 label.set_mnemonic_widget(self._v1)
1238
1239 table.attach(gtk.Label("knots"), 2, 3, 2, 3)
1240
1241 label = gtk.Label("V<sub>_r</sub>:")
1242 label.set_use_markup(True)
1243 label.set_use_underline(True)
1244 label.set_alignment(0.0, 0.5)
1245 table.attach(label, 0, 1, 3, 4)
1246
1247 self._vr = gtk.SpinButton()
1248 self._vr.set_increments(step = 1, page = 10)
1249 self._vr.set_range(min = 50, max = 300)
1250 self._vr.set_value(110)
1251 self._vr.set_numeric(True)
1252 self._vr.set_tooltip_markup("The takeoff rotation speed in knots.")
1253 self._vr.connect("changed", self._updateForwardButton)
1254 table.attach(self._vr, 1, 2, 3, 4)
1255 label.set_mnemonic_widget(self._vr)
1256
1257 table.attach(gtk.Label("knots"), 2, 3, 3, 4)
1258
1259 label = gtk.Label("V<sub>_2</sub>:")
1260 label.set_use_markup(True)
1261 label.set_use_underline(True)
1262 label.set_alignment(0.0, 0.5)
1263 table.attach(label, 0, 1, 4, 5)
1264
1265 self._v2 = gtk.SpinButton()
1266 self._v2.set_increments(step = 1, page = 10)
1267 self._v2.set_range(min = 50, max = 300)
1268 self._v2.set_value(120)
1269 self._v2.set_numeric(True)
1270 self._v2.set_tooltip_markup("The takeoff safety speed in knots.")
1271 self._v2.connect("changed", self._updateForwardButton)
1272 table.attach(self._v2, 1, 2, 4, 5)
1273 label.set_mnemonic_widget(self._v2)
1274
1275 table.attach(gtk.Label("knots"), 2, 3, 4, 5)
1276
1277 button = self.addButton(gtk.STOCK_GO_BACK)
1278 button.set_use_stock(True)
1279 button.connect("clicked", self._backClicked)
1280
1281 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
1282 self._button.set_use_stock(True)
1283 self._button.connect("clicked", self._forwardClicked)
1284
1285 def activate(self):
1286 """Activate the page."""
1287 self._runway.set_text("")
1288 self._runway.set_sensitive(True)
1289 self._sid.set_text("")
1290 self._sid.set_sensitive(True)
1291 self._v1.set_sensitive(True)
1292 self._vr.set_sensitive(True)
1293 self._v2.set_sensitive(True)
1294 self._updateForwardButton()
1295
1296 def finalize(self):
1297 """Finalize the page."""
1298 self._runway.set_sensitive(False)
1299 self._sid.set_sensitive(False)
1300 self._v1.set_sensitive(False)
1301 self._vr.set_sensitive(False)
1302 self._v2.set_sensitive(False)
1303
1304 flight = self._wizard.gui.flight
1305 flight.v1 = self._v1.get_value_as_int()
1306 flight.vr = self._vr.get_value_as_int()
1307 flight.v2 = self._v2.get_value_as_int()
1308
1309 def _updateForwardButton(self, widget = None):
1310 """Update the Forward buttons sensitivity."""
1311 self._button.set_sensitive(self._runway.get_text()!="" and
1312 self._sid.get_text()!="" and
1313 self._v1.get_value_as_int()<=self._vr.get_value_as_int() and
1314 self._vr.get_value_as_int()<=self._v2.get_value_as_int())
1315
1316 def _backClicked(self, button):
1317 """Called when the Back button is pressed."""
1318 self.goBack()
1319
1320 def _forwardClicked(self, button):
1321 """Called when the forward button is clicked."""
1322 #self._wizard.nextPage()
1323
1324#-----------------------------------------------------------------------------
1325
1326class Wizard(gtk.VBox):
1327 """The flight wizard."""
1328 def __init__(self, gui):
1329 """Construct the wizard."""
1330 super(Wizard, self).__init__()
1331
1332 self.gui = gui
1333
1334 self._pages = []
1335 self._currentPage = None
1336
1337 self._pages.append(LoginPage(self))
1338 self._pages.append(FlightSelectionPage(self))
1339 self._pages.append(GateSelectionPage(self))
1340 self._pages.append(ConnectPage(self))
1341 self._pages.append(PayloadPage(self))
1342 self._pages.append(TimePage(self))
1343 self._pages.append(RoutePage(self))
1344 self._pages.append(BriefingPage(self, True))
1345 self._pages.append(BriefingPage(self, False))
1346 self._pages.append(TakeoffPage(self))
1347
1348 maxWidth = 0
1349 maxHeight = 0
1350 for page in self._pages:
1351 page.show_all()
1352 pageSizeRequest = page.size_request()
1353 width = pageSizeRequest.width if pygobject else pageSizeRequest[0]
1354 height = pageSizeRequest.height if pygobject else pageSizeRequest[1]
1355 maxWidth = max(maxWidth, width)
1356 maxHeight = max(maxHeight, height)
1357 maxWidth += 16
1358 maxHeight += 32
1359 self.set_size_request(maxWidth, maxHeight)
1360
1361 self._initialize()
1362
1363 @property
1364 def loginResult(self):
1365 """Get the login result."""
1366 return self._loginResult
1367
1368 def setCurrentPage(self, index, finalize = False):
1369 """Set the current page to the one with the given index."""
1370 assert index < len(self._pages)
1371
1372 fromPage = self._currentPage
1373 if fromPage is not None:
1374 page = self._pages[fromPage]
1375 if finalize and not page._finalized:
1376 page.finalize()
1377 page._finalized = True
1378 self.remove(page)
1379
1380 self._currentPage = index
1381 page = self._pages[index]
1382 self.add(page)
1383 if page._fromPage is None:
1384 page._fromPage = fromPage
1385 page.activate()
1386 self.show_all()
1387 if fromPage is not None:
1388 self.grabDefault()
1389
1390 def nextPage(self, finalize = True):
1391 """Go to the next page."""
1392 self.jumpPage(1, finalize)
1393
1394 def jumpPage(self, count, finalize = True):
1395 """Go to the page which is 'count' pages after the current one."""
1396 self.setCurrentPage(self._currentPage + count, finalize = finalize)
1397
1398 def grabDefault(self):
1399 """Make the default button of the current page the default."""
1400 self._pages[self._currentPage].grabDefault()
1401
1402 def connected(self, fsType, descriptor):
1403 """Called when the connection could be made to the simulator."""
1404 self.nextPage()
1405
1406 def connectionFailed(self):
1407 """Called when the connection could not be made to the simulator."""
1408 self._initialize()
1409
1410 def disconnected(self):
1411 """Called when we have disconnected from the simulator."""
1412 self._initialize()
1413
1414 def _initialize(self):
1415 """Initialize the wizard."""
1416 self._fleet = None
1417 self._fleetCallback = None
1418 self._updatePlaneCallback = None
1419
1420 self._loginResult = None
1421 self._bookedFlight = None
1422 self._departureGate = "-"
1423 self._zfw = None
1424 self._cruiseAltitude = None
1425 self._route = None
1426 self._departureNOTAMs = None
1427 self._departureMETAR = None
1428 self._arrivalNOTAMs = None
1429 self._arrivalMETAR = None
1430
1431 for page in self._pages:
1432 page.reset()
1433
1434 self.setCurrentPage(0)
1435
1436 def _getFleet(self, callback, force = False):
1437 """Get the fleet, if needed.
1438
1439 callback is function that will be called, when the feet is retrieved,
1440 or the retrieval fails. It should have a single argument that will
1441 receive the fleet object on success, None otherwise.
1442 """
1443 if self._fleet is not None and not force:
1444 callback(self._fleet)
1445
1446 self.gui.beginBusy("Retrieving fleet...")
1447 self._fleetCallback = callback
1448 self.gui.webHandler.getFleet(self._fleetResultCallback)
1449
1450 def _fleetResultCallback(self, returned, result):
1451 """Called when the fleet has been queried."""
1452 gobject.idle_add(self._handleFleetResult, returned, result)
1453
1454 def _handleFleetResult(self, returned, result):
1455 """Handle the fleet result."""
1456 self.gui.endBusy()
1457 if returned:
1458 self._fleet = result.fleet
1459 else:
1460 self._fleet = None
1461
1462 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
1463 buttons = BUTTONSTYPE_OK,
1464 message_format =
1465 "Failed to retrieve the information on "
1466 "the fleet.")
1467 dialog.run()
1468 dialog.hide()
1469
1470 self._fleetCallback(self._fleet)
1471
1472 def _updatePlane(self, callback, tailNumber, status, gateNumber = None):
1473 """Update the given plane's gate information."""
1474 self.gui.beginBusy("Updating plane status...")
1475 self._updatePlaneCallback = callback
1476 self.gui.webHandler.updatePlane(self._updatePlaneResultCallback,
1477 tailNumber, status, gateNumber)
1478
1479 def _updatePlaneResultCallback(self, returned, result):
1480 """Callback for the plane updating operation."""
1481 gobject.idle_add(self._handleUpdatePlaneResult, returned, result)
1482
1483 def _handleUpdatePlaneResult(self, returned, result):
1484 """Handle the result of a plane update operation."""
1485 self.gui.endBusy()
1486 if returned:
1487 success = result.success
1488 else:
1489 success = None
1490
1491 dialog = gtk.MessageDialog(type = MESSAGETYPE_ERROR,
1492 buttons = BUTTONSTYPE_OK,
1493 message_format =
1494 "Failed to update the statuis of "
1495 "the airplane.")
1496 dialog.run()
1497 dialog.hide()
1498
1499 self._updatePlaneCallback(success)
1500
1501 def _connectSimulator(self):
1502 """Connect to the simulator."""
1503 self.gui.connectSimulator(self._bookedFlight.aircraftType)
1504
1505#-----------------------------------------------------------------------------
1506
Note: See TracBrowser for help on using the repository browser.