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