Changeset 208:22ff615383e9
- Timestamp:
- 05/31/12 14:59:58 (12 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/gui/flight.py
r201 r208 107 107 108 108 def addButton(self, label, default = False, sensitive = True, 109 tooltip = None, clicked = None ):109 tooltip = None, clicked = None, padding = 4): 110 110 """Add a button with the given label. 111 111 112 112 Return the button object created.""" 113 113 button = gtk.Button(label) 114 self._buttonBox.pack_start(button, False, False, 4)114 self._buttonBox.pack_start(button, False, False, padding) 115 115 button.set_use_underline(True) 116 116 if default: … … 124 124 return button 125 125 126 def addCancelFlightButton(self): 127 """Add the 'Cancel flight' button to the page.""" 128 return self.addButton(xstr("button_cancelFlight"), 129 sensitive = True, 130 tooltip = xstr("button_cancelFlight_tooltip"), 131 clicked = self._cancelFlight, 132 padding = 16) 133 126 134 def addPreviousButton(self, sensitive = True, clicked = None): 127 135 """Add the 'Next' button to the page.""" … … 191 199 192 200 self._wizard.setCurrentPage(self._fromPage, finalize = False) 201 202 def _cancelFlight(self, button): 203 """Called when the Cancel flight button is clicked.""" 204 self._wizard.gui.cancelFlight() 193 205 194 206 #----------------------------------------------------------------------------- … … 279 291 contains text. 280 292 281 The entrance exam checkbox is sens tive only, if the pilot ID is not293 The entrance exam checkbox is sensitive only, if the pilot ID is not 282 294 empty.""" 283 295 pilotID = self._pilotID.get_text() … … 292 304 def _loginClicked(self, button): 293 305 """Called when the login button was clicked.""" 294 gui = self._wizard.gui 295 gui.beginBusy(xstr("login_busy")) 296 gui.webHandler.login(self._loginResultCallback, 297 self._pilotID.get_text(), 298 self._password.get_text(), 299 entranceExam = self.entranceExam) 300 301 def _loginResultCallback(self, returned, result): 302 """The login result callback, called in the web handler's thread.""" 303 gobject.idle_add(self._handleLoginResult, returned, result) 306 self._wizard.login(self._handleLoginResult, 307 self._pilotID.get_text(), 308 self._password.get_text(), 309 self.entranceExam) 304 310 305 311 def _handleLoginResult(self, returned, result): 306 312 """Handle the login result.""" 307 self._wizard.gui.endBusy()308 313 self._loginButton.set_sensitive(True) 309 if returned: 310 if result.loggedIn: 311 config = self._wizard.gui.config 312 313 config.pilotID = self._pilotID.get_text() 314 315 rememberPassword = self._rememberButton.get_active() 316 config.password = self._password.get_text() if rememberPassword \ 317 else "" 318 319 config.rememberPassword = rememberPassword 320 321 config.save() 322 self._wizard._loginResult = result 323 self._wizard.nextPage() 324 else: 325 message = xstr("login_entranceExam_invalid" 326 if self.entranceExam else 327 xstr("login_invalid")) 328 dialog = gtk.MessageDialog(parent = self._wizard.gui.mainWindow, 329 type = MESSAGETYPE_ERROR, 330 message_format = message) 331 dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK) 332 dialog.set_title(WINDOW_TITLE_BASE) 333 secondary = xstr("login_entranceExam_invalid_sec" 334 if self.entranceExam else 335 xstr("login_invalid_sec")) 336 dialog.format_secondary_markup(secondary) 337 dialog.run() 338 dialog.hide() 339 else: 340 dialog = gtk.MessageDialog(parent = self._wizard.gui.mainWindow, 341 type = MESSAGETYPE_ERROR, 342 message_format = xstr("login_failconn")) 343 dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK) 344 dialog.set_title(WINDOW_TITLE_BASE) 345 dialog.format_secondary_markup(xstr("login_failconn_sec")) 346 347 dialog.run() 348 dialog.hide() 314 if returned and result.loggedIn: 315 config = self._wizard.gui.config 316 317 config.pilotID = self._pilotID.get_text() 318 319 rememberPassword = self._rememberButton.get_active() 320 config.password = result.password if rememberPassword else "" 321 322 config.rememberPassword = rememberPassword 323 324 config.save() 325 self._wizard.nextPage() 349 326 350 327 #----------------------------------------------------------------------------- … … 398 375 self.setMainWidget(alignment) 399 376 377 self._refreshButton = self.addButton(xstr("flightsel_refresh"), 378 sensitive = True, 379 clicked = self._refreshClicked, 380 tooltip = xstr("flightsel_refresh_tooltip")) 381 400 382 self._loadButton = self.addButton(xstr("flightsel_load"), 401 383 sensitive = True, … … 412 394 """Fill the flight list.""" 413 395 self._flightList.set_sensitive(True) 396 self._loadButton.set_sensitive(True) 397 self._refreshButton.set_sensitive(True) 398 self._buildFlights() 399 400 def finalize(self): 401 """Finalize the page.""" 402 self._flightList.set_sensitive(False) 403 self._loadButton.set_sensitive(False) 404 self._refreshButton.set_sensitive(False) 405 406 def _buildFlights(self): 407 """Rebuild the flights from the login result.""" 414 408 self._flights = [] 415 409 self._listStore.clear() 416 410 for flight in self._wizard.loginResult.flights: 417 411 self._addFlight(flight) 418 419 def finalize(self):420 """Finalize the page."""421 self._flightList.set_sensitive(False)422 412 423 413 def _addFlight(self, flight): … … 428 418 flight.departureICAO, 429 419 flight.arrivalICAO]) 420 421 def _refreshClicked(self, button): 422 """Called when the refresh button is clicked.""" 423 self._wizard.reloadFlights(self._refreshCallback) 424 425 def _refreshCallback(self, returned, result): 426 """Callback for the refresh.""" 427 if returned and result.loggedIn: 428 self._buildFlights() 430 429 431 430 def _selectionChanged(self, selection): … … 581 580 self.setMainWidget(alignment) 582 581 582 self.addCancelFlightButton() 583 583 584 self.addPreviousButton(clicked = self._backClicked) 584 585 … … 729 730 table.attach(labelAlignment, 1, 2, 4, 5) 730 731 732 self.addCancelFlightButton() 733 731 734 self.addPreviousButton(clicked = self._backClicked) 732 735 … … 879 882 table.attach(gtk.Label("kg"), 2, 3, 6, 7) 880 883 884 self.addCancelFlightButton() 881 885 self._backButton = self.addPreviousButton(clicked = self._backClicked) 882 886 self._button = self.addNextButton(clicked = self._forwardClicked) … … 1009 1013 table.attach(self._simulatorTime, 1, 2, 2, 3) 1010 1014 1015 self.addCancelFlightButton() 1016 1011 1017 self._backButton = self.addPreviousButton(clicked = self._backClicked) 1012 1018 self._button = self.addNextButton(clicked = self._forwardClicked) … … 1282 1288 tankData = ((2500, 3900),) * len(tanks) 1283 1289 self._setupTanks(tanks, tankData) 1290 1291 self.addCancelFlightButton() 1284 1292 1285 1293 self._backButton = self.addPreviousButton(clicked = self._backClicked) … … 1443 1451 1444 1452 mainBox.pack_start(routeBox, True, True, 8) 1453 1454 self.addCancelFlightButton() 1445 1455 1446 1456 self._backButton = self.addPreviousButton(clicked = self._backClicked) … … 1630 1640 self.metarEdited = False 1631 1641 1642 self.addCancelFlightButton() 1643 1632 1644 self.addPreviousButton(clicked = self._backClicked) 1633 1645 self._button = self.addNextButton(clicked = self._forwardClicked) … … 1824 1836 table.attach(gtk.Label(xstr("label_knots")), 3, 4, 4, 5) 1825 1837 1838 self.addCancelFlightButton() 1839 1826 1840 self.addPreviousButton(clicked = self._backClicked) 1827 1841 … … 2006 2020 table.attach(gtk.Label(xstr("label_knots")), 4, 5, 5, 6) 2007 2021 2022 self.addCancelFlightButton() 2023 2008 2024 self.addPreviousButton(clicked = self._backClicked) 2009 2025 … … 2281 2297 self._gateLabel.set_mnemonic_widget(self._gate) 2282 2298 2299 self.addButton(xstr("finish_newFlight"), 2300 sensitive = True, 2301 clicked = self._newFlightClicked, 2302 tooltip = xstr("finish_newFlight_tooltip"), 2303 padding = 16) 2304 2283 2305 self.addPreviousButton(clicked = self._backClicked) 2284 2306 … … 2289 2311 self._savePIREPDialog = None 2290 2312 self._lastSavePath = None 2313 2314 self._pirepSaved = False 2315 self._pirepSent = False 2291 2316 2292 2317 self._sendButton = self.addButton(xstr("sendPIREP"), default = True, … … 2308 2333 def activate(self): 2309 2334 """Activate the page.""" 2335 self._pirepSaved = False 2336 self._pirepSent = False 2337 2310 2338 flight = self._wizard.gui._flight 2311 2339 rating = flight.logger.getRating() … … 2369 2397 self._updateButtons() 2370 2398 2399 def _newFlightClicked(self, button): 2400 """Called when the new flight button is clicked.""" 2401 gui = self._wizard.gui 2402 if not self._pirepSent and not self._pirepSaved: 2403 dialog = gtk.MessageDialog(parent = gui.mainWindow, 2404 type = MESSAGETYPE_QUESTION, 2405 message_format = xstr("finish_newFlight_question")) 2406 2407 dialog.add_button(xstr("button_no"), RESPONSETYPE_NO) 2408 dialog.add_button(xstr("button_yes"), RESPONSETYPE_YES) 2409 2410 dialog.set_title(WINDOW_TITLE_BASE) 2411 result = dialog.run() 2412 dialog.hide() 2413 if result!=RESPONSETYPE_YES: 2414 return 2415 2416 gui.reset() 2417 2371 2418 def _saveClicked(self, button): 2372 2419 """Called when the Save PIREP button is clicked.""" … … 2405 2452 message = xstr("finish_save_done") 2406 2453 secondary = None 2454 self._pirepSaved = True 2407 2455 else: 2408 2456 type = MESSAGETYPE_ERROR … … 2459 2507 def _handlePIREPSent(self, returned, result): 2460 2508 """Callback for the PIREP sending result.""" 2509 self._pirepSent = returned and result.success 2461 2510 if self._wizard.gui.config.onlineGateSystem and \ 2462 2511 not self._wizard.entranceExam and \ … … 2683 2732 self.nextPage() 2684 2733 2685 def reset(self ):2734 def reset(self, loginResult): 2686 2735 """Resets the wizard to go back to the login page.""" 2687 self._initialize() 2736 self._initialize(keepLoginResult = loginResult is None, 2737 loginResult = loginResult) 2688 2738 2689 2739 def setStage(self, stage): … … 2700 2750 self._landingPage.flightEnded() 2701 2751 2702 def _initialize(self ):2752 def _initialize(self, keepLoginResult = False, loginResult = None): 2703 2753 """Initialize the wizard.""" 2754 if not keepLoginResult: 2755 self._loginResult = loginResult 2756 2757 self._loginCallback = None 2758 2704 2759 self._fleet = None 2705 2760 self._fleetCallback = None 2706 2761 2707 self._loginResult = None2708 2762 self._bookedFlight = None 2709 2763 self._departureGate = "-" … … 2714 2768 self._arrivalMETAR = None 2715 2769 2716 for page in self._pages: 2770 firstPage = 0 if self._loginResult is None else 1 2771 for page in self._pages[firstPage:]: 2717 2772 page.reset() 2718 2773 2719 self.setCurrentPage(0) 2774 self.setCurrentPage(firstPage) 2775 2776 def login(self, callback, pilotID, password, entranceExam): 2777 """Called when the login button was clicked.""" 2778 self._loginCallback = callback 2779 if pilotID is None: 2780 loginResult = self._loginResult 2781 assert loginResult is not None and loginResult.loggedIn 2782 pilotID = loginResult.pilotID 2783 password = loginResult.password 2784 entranceExam = loginResult.entranceExam 2785 busyMessage = xstr("reload_busy") 2786 else: 2787 self._loginResult = None 2788 busyMessage = xstr("login_busy") 2789 2790 self.gui.beginBusy(busyMessage) 2791 2792 self.gui.webHandler.login(self._loginResultCallback, 2793 pilotID, password, 2794 entranceExam = entranceExam) 2795 2796 def reloadFlights(self, callback): 2797 """Reload the flights from the MAVA server.""" 2798 self.login(callback, None, None, None) 2799 2800 def _loginResultCallback(self, returned, result): 2801 """The login result callback, called in the web handler's thread.""" 2802 gobject.idle_add(self._handleLoginResult, returned, result) 2803 2804 def _handleLoginResult(self, returned, result): 2805 """Handle the login result.""" 2806 self.gui.endBusy() 2807 isReload = self._loginResult is not None 2808 if returned: 2809 if result.loggedIn: 2810 self._loginResult = result 2811 else: 2812 if isReload: 2813 message = xstr("reload_failed") 2814 else: 2815 message = xstr("login_entranceExam_invalid" 2816 if self.entranceExam else 2817 xstr("login_invalid")) 2818 dialog = gtk.MessageDialog(parent = self.gui.mainWindow, 2819 type = MESSAGETYPE_ERROR, 2820 message_format = message) 2821 dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK) 2822 dialog.set_title(WINDOW_TITLE_BASE) 2823 if isReload: 2824 secondary = xstr("reload_failed_sec") 2825 else: 2826 secondary = xstr("login_entranceExam_invalid_sec" 2827 if self.entranceExam else 2828 xstr("login_invalid_sec")) 2829 dialog.format_secondary_markup(secondary) 2830 dialog.run() 2831 dialog.hide() 2832 else: 2833 message = xstr("reload_failconn") if isReload \ 2834 else xstr("login_failconn") 2835 dialog = gtk.MessageDialog(parent = self.gui.mainWindow, 2836 type = MESSAGETYPE_ERROR, 2837 message_format = message) 2838 dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK) 2839 dialog.set_title(WINDOW_TITLE_BASE) 2840 secondary = xstr("reload_failconn_sec") if isReload \ 2841 else xstr("login_failconn_sec") 2842 dialog.format_secondary_markup(secondary) 2843 2844 dialog.run() 2845 dialog.hide() 2846 2847 callback = self._loginCallback 2848 self._loginCallback = None 2849 callback(returned, result) 2720 2850 2721 2851 def getFleet(self, callback, force = False): -
src/mlx/gui/gui.py
r204 r208 402 402 self._flightInfo.enable() 403 403 404 def cancelFlight(self): 405 """Cancel the current file, if the user confirms it.""" 406 dialog = gtk.MessageDialog(parent = self._mainWindow, 407 type = MESSAGETYPE_QUESTION, 408 message_format = xstr("cancelFlight_question")) 409 410 dialog.add_button(xstr("button_no"), RESPONSETYPE_NO) 411 dialog.add_button(xstr("button_yes"), RESPONSETYPE_YES) 412 413 dialog.set_title(WINDOW_TITLE_BASE) 414 result = dialog.run() 415 dialog.hide() 416 417 if result==RESPONSETYPE_YES: 418 self.reset() 419 404 420 def reset(self): 405 421 """Reset the GUI.""" … … 412 428 self._weightHelp.reset() 413 429 self._weightHelp.disable() 414 self._wizard.reset()415 430 self._notebook.set_current_page(0) 416 431 417 432 self._logView.get_buffer().set_text("") 433 434 self._wizard.reloadFlights(self._handleReloadResult) 435 436 def _handleReloadResult(self, returned, result): 437 """Handle the result of the reloading of the flights.""" 438 self._wizard.reset(result if returned and result.loggedIn else None) 418 439 419 440 def _disconnect(self, closingMessage = None, duration = 3): -
src/mlx/i18n.py
r199 r208 157 157 self.add("button_no", "_No") 158 158 self.add("button_browse", "Browse...") 159 self.add("button_cancelFlight", "Cancel flight") 159 160 160 161 self.add("menu_file", "File") … … 245 246 "see the debug log for details.") 246 247 248 self.add("reload_busy", "Reloading flights...") 249 self.add("reload_failed", 250 "Your pilot ID and password failed this time.") 251 self.add("reload_failed_sec", 252 "This must be some problem with the MAVA website " 253 "(or you are fired), using your old list of flights.") 254 self.add("reload_failconn", 255 "Failed to communicate with the MAVA website.") 256 self.add("reload_failconn_sec", 257 "Your previously downloaded list of flights will be used.") 258 259 self.add("cancelFlight_question", 260 "Are you sure to cancel the flight?") 261 247 262 self.add("button_next", "_Next") 248 263 self.add("button_next_tooltip", "Click to go to the next page.") 249 264 self.add("button_previous", "_Previous") 250 265 self.add("button_previous_tooltip", "Click to go to the previous page.") 266 self.add("button_cancelFlight_tooltip", 267 "Click to cancel the current flight and go back to the flight selection page.") 251 268 252 269 self.add("flightsel_title", "Flight selection") … … 257 274 self.add("flightsel_from", "From") 258 275 self.add("flightsel_to", "To") 276 self.add("flightsel_refresh", "_Refresh flights") 277 self.add("flightsel_refresh_tooltip", 278 "Click here to refresh the list of flights from the MAVA website.") 259 279 self.add("flightsel_load", "L_oad flight from file") 260 280 self.add("flightsel_load_tooltip", … … 478 498 self.add("finish_gate_tooltip", 479 499 "Select the gate or stand at which you have arrived to LHBP.") 500 self.add("finish_newFlight", "_New flight...") 501 self.add("finish_newFlight_tooltip", 502 "Click here to start a new flight.") 503 self.add("finish_newFlight_question", 504 "You have neither saved nor sent your PIREP. " 505 "Are you sure to start a new flight?") 480 506 self.add("finish_save", "Sa_ve PIREP...") 481 507 self.add("finish_save_tooltip", … … 959 985 "részletesebb információt találsz a debug naplóban.") 960 986 987 self.add("reload_busy", "Járatok újratöltése...") 988 self.add("reload_failed", 989 "Ezúttal nem működött az azonosítód és a jelszavad.") 990 self.add("reload_failed_sec", 991 "Ez minden bizonnyal a MAVA website hibája " 992 "(hacsak nem rúgtak ki), így használom a régi járatlistát.") 993 self.add("reload_failconn", 994 "Nem sikerült kommunikálni a MAVA honlappal.") 995 self.add("reload_failconn_sec", 996 "A korábban letöltött járatlistát használom.") 997 961 998 self.add("button_next", "_Előre") 962 999 self.add("button_next_tooltip", -
src/mlx/soundsched.py
r200 r208 194 194 const.STAGE_TAKEOFF, 195 195 extraCondition = lambda flight, state: 196 state.landingLightsOn or state.g s>80,196 state.landingLightsOn or state.groundSpeed>80, 197 197 considerHotkey = False)) 198 198 self._sounds.append(SimpleSound(const.SOUND_CRUISE, const.STAGE_CRUISE)) -
src/mlx/web.py
r205 r208 468 468 if result.loggedIn: 469 469 result.pilotID = self._pilotID 470 result.password = self._password 470 471 result.flights = [] 471 472 # FIXME: this may not be the correct behaviour
Note:
See TracChangeset
for help on using the changeset viewer.