Changeset 208:22ff615383e9


Ignore:
Timestamp:
05/31/12 14:59:58 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

It is now possible to cancel a flight and to start a new one at the end and also to refresh the list of flights.

Location:
src/mlx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/gui/flight.py

    r201 r208  
    107107
    108108    def addButton(self, label, default = False, sensitive = True,
    109                   tooltip = None, clicked = None):
     109                  tooltip = None, clicked = None, padding = 4):
    110110        """Add a button with the given label.
    111111
    112112        Return the button object created."""
    113113        button = gtk.Button(label)
    114         self._buttonBox.pack_start(button, False, False, 4)
     114        self._buttonBox.pack_start(button, False, False, padding)
    115115        button.set_use_underline(True)
    116116        if default:
     
    124124        return button
    125125
     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
    126134    def addPreviousButton(self, sensitive = True, clicked = None):
    127135        """Add the 'Next' button to the page."""
     
    191199       
    192200        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()
    193205   
    194206#-----------------------------------------------------------------------------
     
    279291        contains text.
    280292
    281         The entrance exam checkbox is senstive only, if the pilot ID is not
     293        The entrance exam checkbox is sensitive only, if the pilot ID is not
    282294        empty."""
    283295        pilotID = self._pilotID.get_text()
     
    292304    def _loginClicked(self, button):
    293305        """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)
    304310
    305311    def _handleLoginResult(self, returned, result):
    306312        """Handle the login result."""
    307         self._wizard.gui.endBusy()
    308313        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()
    349326
    350327#-----------------------------------------------------------------------------
     
    398375        self.setMainWidget(alignment)
    399376
     377        self._refreshButton = self.addButton(xstr("flightsel_refresh"),
     378                                             sensitive = True,
     379                                             clicked = self._refreshClicked,
     380                                             tooltip = xstr("flightsel_refresh_tooltip"))
     381
    400382        self._loadButton = self.addButton(xstr("flightsel_load"),
    401383                                          sensitive = True,
     
    412394        """Fill the flight list."""
    413395        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."""
    414408        self._flights = []
    415409        self._listStore.clear()
    416410        for flight in self._wizard.loginResult.flights:
    417411            self._addFlight(flight)
    418            
    419     def finalize(self):
    420         """Finalize the page."""
    421         self._flightList.set_sensitive(False)
    422412
    423413    def _addFlight(self, flight):
     
    428418                                flight.departureICAO,
    429419                                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()
    430429
    431430    def _selectionChanged(self, selection):
     
    581580        self.setMainWidget(alignment)       
    582581
     582        self.addCancelFlightButton()
     583
    583584        self.addPreviousButton(clicked = self._backClicked)
    584585       
     
    729730        table.attach(labelAlignment, 1, 2, 4, 5)
    730731
     732        self.addCancelFlightButton()
     733
    731734        self.addPreviousButton(clicked = self._backClicked)
    732735
     
    879882        table.attach(gtk.Label("kg"), 2, 3, 6, 7)
    880883
     884        self.addCancelFlightButton()
    881885        self._backButton = self.addPreviousButton(clicked = self._backClicked)
    882886        self._button = self.addNextButton(clicked = self._forwardClicked)
     
    10091013        table.attach(self._simulatorTime, 1, 2, 2, 3)
    10101014
     1015        self.addCancelFlightButton()
     1016
    10111017        self._backButton = self.addPreviousButton(clicked = self._backClicked)
    10121018        self._button = self.addNextButton(clicked = self._forwardClicked)
     
    12821288        tankData = ((2500, 3900),) * len(tanks)
    12831289        self._setupTanks(tanks, tankData)
     1290
     1291        self.addCancelFlightButton()
    12841292
    12851293        self._backButton = self.addPreviousButton(clicked = self._backClicked)
     
    14431451
    14441452        mainBox.pack_start(routeBox, True, True, 8)
     1453
     1454        self.addCancelFlightButton()
    14451455
    14461456        self._backButton = self.addPreviousButton(clicked = self._backClicked)       
     
    16301640        self.metarEdited = False
    16311641
     1642        self.addCancelFlightButton()
     1643
    16321644        self.addPreviousButton(clicked = self._backClicked)
    16331645        self._button = self.addNextButton(clicked = self._forwardClicked)
     
    18241836        table.attach(gtk.Label(xstr("label_knots")), 3, 4, 4, 5)
    18251837
     1838        self.addCancelFlightButton()
     1839
    18261840        self.addPreviousButton(clicked = self._backClicked)
    18271841
     
    20062020        table.attach(gtk.Label(xstr("label_knots")), 4, 5, 5, 6)
    20072021
     2022        self.addCancelFlightButton()
     2023
    20082024        self.addPreviousButton(clicked = self._backClicked)
    20092025
     
    22812297        self._gateLabel.set_mnemonic_widget(self._gate)
    22822298
     2299        self.addButton(xstr("finish_newFlight"),
     2300                       sensitive = True,
     2301                       clicked = self._newFlightClicked,
     2302                       tooltip = xstr("finish_newFlight_tooltip"),
     2303                       padding = 16)
     2304
    22832305        self.addPreviousButton(clicked = self._backClicked)
    22842306
     
    22892311        self._savePIREPDialog = None
    22902312        self._lastSavePath = None
     2313
     2314        self._pirepSaved = False
     2315        self._pirepSent = False
    22912316       
    22922317        self._sendButton = self.addButton(xstr("sendPIREP"), default = True,
     
    23082333    def activate(self):
    23092334        """Activate the page."""
     2335        self._pirepSaved = False
     2336        self._pirepSent = False
     2337
    23102338        flight = self._wizard.gui._flight
    23112339        rating = flight.logger.getRating()
     
    23692397        self._updateButtons()
    23702398
     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
    23712418    def _saveClicked(self, button):
    23722419        """Called when the Save PIREP button is clicked."""
     
    24052452                message = xstr("finish_save_done")
    24062453                secondary = None
     2454                self._pirepSaved = True
    24072455            else:
    24082456                type = MESSAGETYPE_ERROR
     
    24592507    def _handlePIREPSent(self, returned, result):
    24602508        """Callback for the PIREP sending result."""
     2509        self._pirepSent = returned and result.success
    24612510        if self._wizard.gui.config.onlineGateSystem and \
    24622511           not self._wizard.entranceExam and \
     
    26832732        self.nextPage()
    26842733
    2685     def reset(self):
     2734    def reset(self, loginResult):
    26862735        """Resets the wizard to go back to the login page."""
    2687         self._initialize()
     2736        self._initialize(keepLoginResult = loginResult is None,
     2737                         loginResult = loginResult)
    26882738
    26892739    def setStage(self, stage):
     
    27002750            self._landingPage.flightEnded()
    27012751
    2702     def _initialize(self):
     2752    def _initialize(self, keepLoginResult = False, loginResult = None):
    27032753        """Initialize the wizard."""
     2754        if not keepLoginResult:
     2755            self._loginResult = loginResult
     2756
     2757        self._loginCallback = None
     2758
    27042759        self._fleet = None
    27052760        self._fleetCallback = None
    27062761       
    2707         self._loginResult = None
    27082762        self._bookedFlight = None
    27092763        self._departureGate = "-"
     
    27142768        self._arrivalMETAR = None
    27152769
    2716         for page in self._pages:
     2770        firstPage = 0 if self._loginResult is None else 1
     2771        for page in self._pages[firstPage:]:
    27172772            page.reset()
    27182773       
    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)
    27202850
    27212851    def getFleet(self, callback, force = False):
  • src/mlx/gui/gui.py

    r204 r208  
    402402        self._flightInfo.enable()
    403403
     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
    404420    def reset(self):
    405421        """Reset the GUI."""
     
    412428        self._weightHelp.reset()
    413429        self._weightHelp.disable()
    414         self._wizard.reset()
    415430        self._notebook.set_current_page(0)
    416431
    417432        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)
    418439
    419440    def _disconnect(self, closingMessage = None, duration = 3):
  • src/mlx/i18n.py

    r199 r208  
    157157        self.add("button_no", "_No")
    158158        self.add("button_browse", "Browse...")
     159        self.add("button_cancelFlight", "Cancel flight")
    159160       
    160161        self.add("menu_file", "File")
     
    245246                 "see the debug log for details.")
    246247
     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
    247262        self.add("button_next", "_Next")
    248263        self.add("button_next_tooltip", "Click to go to the next page.")
    249264        self.add("button_previous", "_Previous")
    250265        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.")
    251268
    252269        self.add("flightsel_title", "Flight selection")
     
    257274        self.add("flightsel_from", "From")
    258275        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.")
    259279        self.add("flightsel_load", "L_oad flight from file")
    260280        self.add("flightsel_load_tooltip",
     
    478498        self.add("finish_gate_tooltip",
    479499                 "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?")
    480506        self.add("finish_save", "Sa_ve PIREP...")
    481507        self.add("finish_save_tooltip",
     
    959985                 "részletesebb információt találsz a debug naplóban.")
    960986       
     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
    961998        self.add("button_next", "_Előre")
    962999        self.add("button_next_tooltip",
  • src/mlx/soundsched.py

    r200 r208  
    194194                                        const.STAGE_TAKEOFF,
    195195                                        extraCondition = lambda flight, state:
    196                                         state.landingLightsOn or state.gs>80,
     196                                        state.landingLightsOn or state.groundSpeed>80,
    197197                                        considerHotkey = False))
    198198        self._sounds.append(SimpleSound(const.SOUND_CRUISE, const.STAGE_CRUISE))
  • src/mlx/web.py

    r205 r208  
    468468        if result.loggedIn:
    469469            result.pilotID = self._pilotID
     470            result.password = self._password
    470471            result.flights = []
    471472            # FIXME: this may not be the correct behaviour
Note: See TracChangeset for help on using the changeset viewer.