Ignore:
Timestamp:
04/24/16 12:50:26 (8 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

The check flight can also be performed and the registration logic is hopefully complete (re #285)

File:
1 edited

Legend:

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

    r764 r769  
    169169
    170170    def addButton(self, label, default = False, sensitive = True,
    171                   tooltip = None, clicked = None, padding = 4):
     171                  tooltip = None, clicked = None, padding = 4,
     172                  clickedArg = None):
    172173        """Add a button with the given label.
    173174
     
    183184            button.set_tooltip_text(tooltip)
    184185        if clicked is not None:
    185             button.connect("clicked", clicked)
     186            if clickedArg is None:
     187                button.connect("clicked", clicked)
     188            else:
     189                button.connect("clicked", clicked, clickedArg)
    186190        return button
    187191
     
    13761380                                          xstr("student_help"))
    13771381
     1382
     1383        self._getEntryExamStatusCancelled = False
     1384
    13781385        alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
    13791386                                  xscale = 0.5, yscale = 0.0)
    13801387
    1381         table = gtk.Table(2, 2)
     1388        table = gtk.Table(6, 4)
    13821389        table.set_row_spacings(4)
    1383         table.set_col_spacings(32)
     1390        table.set_col_spacings(0)
    13841391        table.set_homogeneous(False)
    13851392        alignment.add(table)
     
    13911398                                       xscale=0.0, yscale = 0.0)
    13921399        label = gtk.Label(xstr("student_entry_exam_status"))
     1400        label.set_alignment(0.0, 0.5)
    13931401        labelAlignment.add(label)
    1394         table.attach(labelAlignment, 0, 1, row, row + 1, xoptions = 0)
     1402        labelAlignment.resize_children()
     1403        table.attach(labelAlignment, 0, 1, row, row + 1, xoptions = FILL)
    13951404
    13961405        alignment = gtk.Alignment(xalign=0.0, yalign = 0.5,
     
    14001409        self._entryExamStatus.set_alignment(0.0, 0.5)
    14011410        alignment.add(self._entryExamStatus)
    1402         table.attach(alignment, 1, 2, row, row + 1)
     1411        alignment.resize_children()
     1412        table.attach(alignment, 1, 4, row, row + 1)
    14031413
    14041414        row += 1
     
    14111421
    14121422        buttonAlignment.add(button)
    1413         table.attach(buttonAlignment, 0, 2, row, row + 1,
     1423        table.attach(buttonAlignment, 0, 4, row, row + 1, xoptions = FILL,
    14141424                     ypadding = 4)
     1425
     1426        row += 3
     1427
     1428        labelAlignment = gtk.Alignment(xalign=0.0, yalign = 0.5,
     1429                                       xscale=0.0, yscale = 0.0)
     1430        label = gtk.Label(xstr("student_check_flight_status"))
     1431        labelAlignment.add(label)
     1432        table.attach(labelAlignment, 0, 1, row, row + 1, xoptions = FILL)
     1433
     1434        alignment = gtk.Alignment(xalign=0.0, yalign = 0.5,
     1435                                  xscale=1.0, yscale = 0.0)
     1436        self._checkFlightStatus = gtk.Label()
     1437        self._checkFlightStatus.set_use_markup(True)
     1438        self._checkFlightStatus.set_alignment(0.0, 0.5)
     1439        alignment.add(self._checkFlightStatus)
     1440        table.attach(alignment, 1, 4, row, row + 1)
     1441
     1442        row += 1
     1443
     1444        alignment = gtk.Alignment(xalign=0.0, xscale=1.0)
     1445
     1446        hbox = gtk.HBox()
     1447        hbox.set_homogeneous(False)
     1448        hbox.set_spacing(0)
     1449
     1450        aircraftTypesModel = gtk.ListStore(str, int)
     1451        for aircraftType in web.BookedFlight.checkFlightTypes:
     1452            aircraftTypesModel.append([aircraftNames[aircraftType],
     1453                                       aircraftType])
     1454
     1455        aircraftTypeAlignment = gtk.Alignment(xalign = 0.0, xscale = 1.0)
     1456
     1457        self._aircraftType = gtk.ComboBox(model = aircraftTypesModel)
     1458        renderer = gtk.CellRendererText()
     1459        self._aircraftType.pack_start(renderer, True)
     1460        self._aircraftType.add_attribute(renderer, "text", 0)
     1461        self._aircraftType.set_tooltip_text(xstr("student_check_flight_type_tooltip"))
     1462        self._aircraftType.set_active(0)
     1463
     1464        aircraftTypeAlignment.add(self._aircraftType)
     1465
     1466        hbox.pack_start(aircraftTypeAlignment, False, False, 0)
     1467
     1468        buttonAlignment = gtk.Alignment(xalign=0.0, xscale=1.0)
     1469        button = self._checkFlightButton = gtk.Button(xstr("student_check_flight"))
     1470        button.set_use_underline(True)
     1471        button.connect("clicked", self._checkFlightClicked)
     1472        button.set_tooltip_text(xstr("student_check_flight_tooltip"))
     1473
     1474        hbox.pack_start(button, True, True, 0)
     1475
     1476        alignment.add(hbox)
     1477        table.attach(alignment, 0, 4, row, row + 1, xoptions = FILL)
     1478
     1479    @property
     1480    def aircraftType(self):
     1481        """Get the type of the aircraft used to perform the check flight."""
     1482        index = self._aircraftType.get_active()
     1483        return self._aircraftType.get_model()[index][1]
    14151484
    14161485    def activate(self):
    14171486        """Activate the student page."""
     1487        print "StudentPage.activate"
     1488        self._getEntryExamStatusCancelled = False
     1489
    14181490        loginResult = self._wizard.loginResult
    14191491        self._entryExamLink = loginResult.entryExamLink
    14201492
    14211493        self._updateEntryExamStatus(loginResult.entryExamPassed)
    1422 
    14231494        self._getEntryExamStatus()
     1495
     1496        # FIXME: call with real value
     1497        self._updateCheckFlightStatus(self._wizard.loginResult.checkFlightStatus)
     1498
     1499    def finalize(self):
     1500        """Finalize the page."""
     1501        print "StudentPage.finalize"
     1502        self._getEntryExamStatusCancelled = True
    14241503
    14251504    def _entryExamClicked(self, button):
     
    14291508    def _getEntryExamStatus(self):
    14301509        """Initiate the query of the entry exam status after the interval."""
    1431         gobject.timeout_add(StudentPage._entryExamStatusQueryInterval,
    1432                             lambda: self._wizard.gui.webHandler. \
    1433                             getEntryExamStatus(self._entryExamStatusCallback))
     1510        if not self._getEntryExamStatusCancelled:
     1511            gobject.timeout_add(StudentPage._entryExamStatusQueryInterval,
     1512                                lambda: self._wizard.gui.webHandler. \
     1513                                getEntryExamStatus(self._entryExamStatusCallback))
    14341514
    14351515    def _entryExamStatusCallback(self, returned, result):
     
    14401520        """Called when the entry exam status is availabe."""
    14411521        print "_handleEntryExamStatus", returned, result
    1442         if returned:
     1522        if returned and not self._getEntryExamStatusCancelled:
    14431523            self._entryExamLink = result.entryExamLink
    14441524            self._updateEntryExamStatus(result.entryExamPassed)
    1445             self._getEntryExamStatus()
     1525            if result.madeFO:
     1526                self._madeFO()
     1527            else:
     1528                self._getEntryExamStatus()
    14461529
    14471530    def _updateEntryExamStatus(self, passed):
     
    14521535        self._entryExamStatus.set_use_markup(True)
    14531536        self._entryExamButton.set_sensitive(not passed)
     1537
     1538    def _checkFlightClicked(self, button):
     1539        """Called when the check flight button is clicked."""
     1540        aircraftType = self.aircraftType
     1541        self._wizard._bookedFlight = \
     1542            web.BookedFlight.forCheckFlight(aircraftType)
     1543        self._wizard.gui.enableFlightInfo(aircraftType)
     1544        self._wizard.jumpPage("connect")
     1545
     1546    def _updateCheckFlightStatus(self, passed):
     1547        """Update the status of the check flight."""
     1548        self._aircraftType.set_sensitive(not passed)
     1549        self._checkFlightStatus.set_text(xstr("student_check_flight_passed")
     1550                                         if passed else
     1551                                         xstr("student_check_flight_not_passed"))
     1552        self._checkFlightStatus.set_use_markup(True)
     1553        self._checkFlightButton.set_sensitive(not passed)
     1554
     1555    def _madeFO(self):
     1556        """Handle the event when the pilot has become a first officer."""
     1557        wizard = self._wizard
     1558        loginResult = wizard.loginResult
     1559        loginResult.rank = "FO"
     1560
     1561        gui = wizard.gui
     1562
     1563        dialog = gtk.MessageDialog(parent = gui.mainWindow,
     1564                                   type = MESSAGETYPE_INFO,
     1565                                   message_format = xstr("student_fo"))
     1566
     1567        dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK)
     1568        dialog.set_title(WINDOW_TITLE_BASE)
     1569        secondary = xstr("student_fo_secondary")
     1570        dialog.format_secondary_markup(secondary)
     1571        dialog.run()
     1572        dialog.hide()
     1573
     1574        gui.reset()
    14541575
    14551576#-----------------------------------------------------------------------------
     
    15751696        self.addCancelFlightButton()
    15761697
    1577         self.addPreviousButton(clicked = self._backClicked)
     1698        self._previousButton = \
     1699          self.addPreviousButton(clicked = self._backClicked)
    15781700
    15791701        self._button = self.addButton(xstr("button_connect"), default = True,
     
    16091731            self._selectMSFS.set_active(config.defaultMSFS)
    16101732            self._selectXPlane.set_active(not config.defaultMSFS)
     1733
     1734        self._previousButton.set_sensitive(not self._wizard.entranceExam)
    16111735
    16121736    def finalize(self):
     
    21252249        alternate = self._alternate.get_text()
    21262250        self._button.set_sensitive(cruiseLevel>=50 and self._getRoute()!="" and
    2127                                    len(alternate)==4)
     2251                                   (len(alternate)==4 or self._wizard.entranceExam))
    21282252
    21292253    def _cruiseLevelChanged(self, *arg):
     
    42244348    def _forwardClicked(self, button):
    42254349        """Called when the forward button is clicked."""
    4226         aircraft = self._wizard.gui.flight.aircraft
     4350        wizard = self._wizard
     4351
     4352        aircraft = wizard.gui.flight.aircraft
    42274353        aircraft.updateVRef()
    42284354        aircraft.updateLandingAntiIce()
    4229         if self._wizard.gui.config.onlineGateSystem and \
    4230            self._wizard.loggedIn and not self._completed and \
    4231            self._wizard.bookedFlight.arrivalICAO=="LHBP" and \
    4232            not self._wizard.entranceExam:
    4233             self._wizard.getFleet(callback = self._fleetRetrieved,
    4234                                   force = True)
     4355        if wizard.gui.config.onlineGateSystem and \
     4356           wizard.loggedIn and not self._completed and \
     4357           wizard.bookedFlight.arrivalICAO=="LHBP" and \
     4358           not wizard.entranceExam:
     4359            wizard.getFleet(callback = self._fleetRetrieved, force = True)
     4360        elif wizard.entranceExam:
     4361            self._handleEntranceExamDone()
    42354362        else:
    4236             self._wizard.nextPage()
     4363            wizard.nextPage()
    42374364
    42384365    def _fleetRetrieved(self, fleet):
     
    42604387            self._updatingMETAR = False
    42614388
     4389    def _handleEntranceExamDone(self):
     4390        """Handle the end of the entrance exam.
     4391
     4392        If the there was a NO-GO fault, notify the user that exam is a failure
     4393        and take them back to the student page. Otherwise congratulate, update
     4394        the database to reflect that the exam has been taken and go back to the
     4395        student page."""
     4396        self._wizard.jumpPage("chkfinish")
     4397
     4398#-----------------------------------------------------------------------------
     4399
     4400class PIREPSaveHelper(object):
     4401    """A helper to use for saving PIREPs."""
     4402    def __init__(self, wizard):
     4403        """Construct the helper."""
     4404        super(PIREPSaveHelper, self).__init__()
     4405
     4406        self._wizard = wizard
     4407
     4408        self._lastSavePath = None
     4409        self._savePIREPDialog = None
     4410
     4411    def addButton(self, page):
     4412        """Add a button to save the PIREP to the given page."""
     4413        return page.addButton(xstr("finish_save"), sensitive = False,
     4414                              clicked = self._saveClicked,
     4415                              tooltip = xstr("finish_save_tooltip"),
     4416                              clickedArg = page)
     4417
     4418    def autoSavePIREP(self):
     4419        """Perform the automatic saving of the PIREP."""
     4420        self._lastSavePath = os.path.join(self._wizard.gui.config.pirepDirectory,
     4421                                          self._getDefaultPIREPName())
     4422        self._lastSavePath = text2unicode(self._lastSavePath)
     4423        self._savePIREP(automatic = True)
     4424
     4425    def _getDefaultPIREPName(self):
     4426        """Get the default name of the PIREP."""
     4427        gui = self._wizard.gui
     4428
     4429        bookedFlight = gui.bookedFlight
     4430        tm = time.gmtime()
     4431
     4432        pilotID = self._wizard.pilotID
     4433        if pilotID: pilotID += " "
     4434        return "%s%s %02d%02d %s-%s.pirep" % \
     4435               (pilotID, str(bookedFlight.departureTime.date()),
     4436                tm.tm_hour, tm.tm_min,
     4437                bookedFlight.departureICAO, bookedFlight.arrivalICAO)
     4438
     4439    def _saveClicked(self, button, page):
     4440        """Called when the Save PIREP button is clicked."""
     4441        gui = self._wizard.gui
     4442
     4443        fileName = self._getDefaultPIREPName()
     4444
     4445        dialog = self._getSaveDialog()
     4446
     4447        if self._lastSavePath is None:
     4448            pirepDirectory = gui.config.pirepDirectory
     4449            if pirepDirectory is not None:
     4450                dialog.set_current_folder(pirepDirectory)
     4451        else:
     4452            dialog.set_current_folder(os.path.dirname(self._lastSavePath))
     4453
     4454        dialog.set_current_name(fileName)
     4455        result = dialog.run()
     4456        dialog.hide()
     4457
     4458        if result==RESPONSETYPE_OK:
     4459            self._lastSavePath = text2unicode(dialog.get_filename())
     4460            self._savePIREP(page)
     4461
     4462    def _savePIREP(self, page, automatic = False):
     4463        """Perform the saving of the PIREP."""
     4464
     4465        gui = self._wizard.gui
     4466
     4467        if automatic:
     4468            gui.beginBusy(xstr("finish_autosave_busy"))
     4469
     4470        pirep = PIREP(gui.flight)
     4471        error = pirep.save(self._lastSavePath)
     4472
     4473        if automatic:
     4474            gui.endBusy()
     4475
     4476        if error:
     4477            type = MESSAGETYPE_ERROR
     4478            message = xstr("finish_save_failed")
     4479            secondary = xstr("finish_save_failed_sec") % (text2unicode(error),)
     4480        else:
     4481            type = MESSAGETYPE_INFO
     4482            message = xstr("finish_save_done")
     4483            if automatic:
     4484                secondary = xstr("finish_save_done_sec") % (self._lastSavePath,)
     4485            else:
     4486                secondary = None
     4487            page.setPIREPSaved()
     4488
     4489        dialog = gtk.MessageDialog(parent = gui.mainWindow,
     4490                                   type = type, message_format = message)
     4491        dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK)
     4492        dialog.set_title(WINDOW_TITLE_BASE)
     4493        if secondary is not None:
     4494            dialog.format_secondary_markup(secondary)
     4495
     4496        dialog.run()
     4497        dialog.hide()
     4498
     4499        return pirepSaved
     4500
     4501    def _getSaveDialog(self):
     4502        """Get the PIREP saving dialog.
     4503
     4504        If it does not exist yet, create it."""
     4505        if self._savePIREPDialog is None:
     4506            gui = self._wizard.gui
     4507            dialog = gtk.FileChooserDialog(title = WINDOW_TITLE_BASE + " - " +
     4508                                           xstr("finish_save_title"),
     4509                                           action = FILE_CHOOSER_ACTION_SAVE,
     4510                                           buttons = (gtk.STOCK_CANCEL,
     4511                                                      RESPONSETYPE_CANCEL,
     4512                                                      gtk.STOCK_OK, RESPONSETYPE_OK),
     4513                                           parent = gui.mainWindow)
     4514            dialog.set_modal(True)
     4515            dialog.set_do_overwrite_confirmation(True)
     4516
     4517            filter = gtk.FileFilter()
     4518            filter.set_name(xstr("file_filter_pireps"))
     4519            filter.add_pattern("*.pirep")
     4520            dialog.add_filter(filter)
     4521
     4522            filter = gtk.FileFilter()
     4523            filter.set_name(xstr("file_filter_all"))
     4524            filter.add_pattern("*.*")
     4525            dialog.add_filter(filter)
     4526
     4527            self._savePIREPDialog = dialog
     4528
     4529        return self._savePIREPDialog
     4530
    42624531#-----------------------------------------------------------------------------
    42634532
     
    42694538                     ("flighttype_charter", const.FLIGHTTYPE_CHARTER) ]
    42704539
    4271     def __init__(self, wizard):
     4540    def __init__(self, wizard, saveHelper):
    42724541        """Construct the finish page."""
    42734542        help = xstr("finish_help") + xstr("finish_help_goodtime")
     
    44564725        self.addPreviousButton(clicked = self._backClicked)
    44574726
    4458         self._saveButton = self.addButton(xstr("finish_save"),
    4459                                           sensitive = False,
    4460                                           clicked = self._saveClicked,
    4461                                           tooltip = xstr("finish_save_tooltip"))
    4462         self._savePIREPDialog = None
    4463         self._lastSavePath = None
     4727        self._saveHelper = saveHelper
     4728        self._saveButton = saveHelper.addButton(self)
    44644729
    44654730        self._tooBigTimeDifference = False
     
    45614826        if gui.config.pirepAutoSave and sensitive and not wasSensitive:
    45624827            if gui.isWizardActive():
    4563                 self._autoSavePIREP()
     4828                self._saveHelper.autoSavePIREP()
    45644829            else:
    45654830                self._deferredAutoSave = True
     
    45764841        super(FinishPage, self).grabDefault()
    45774842        if self._deferredAutoSave:
    4578             self._autoSavePIREP()
     4843            self._saveHelper.autoSavePIREP()
    45794844            self._deferredAutoSave = False
    45804845
    4581     def _autoSavePIREP(self):
    4582         """Perform the automatic saving of the PIREP."""
    4583         self._lastSavePath = os.path.join(self._wizard.gui.config.pirepDirectory,
    4584                                           self._getDefaultPIREPName())
    4585         self._lastSavePath = text2unicode(self._lastSavePath)
    4586         self._savePIREP(automatic = True)
     4846    def setPIREPSaved(self):
     4847        """Mark the PIREP as saved."""
     4848        self._pirepSaved = True
    45874849
    45884850    def _backClicked(self, button):
     
    46164878
    46174879        gui.reset()
    4618 
    4619     def _getDefaultPIREPName(self):
    4620         """Get the default name of the PIREP."""
    4621         gui = self._wizard.gui
    4622 
    4623         bookedFlight = gui.bookedFlight
    4624         tm = time.gmtime()
    4625 
    4626         pilotID = self._wizard.pilotID
    4627         if pilotID: pilotID += " "
    4628         return "%s%s %02d%02d %s-%s.pirep" % \
    4629                (pilotID, str(bookedFlight.departureTime.date()),
    4630                 tm.tm_hour, tm.tm_min,
    4631                 bookedFlight.departureICAO, bookedFlight.arrivalICAO)
    4632 
    4633 
    4634     def _saveClicked(self, button):
    4635         """Called when the Save PIREP button is clicked."""
    4636         gui = self._wizard.gui
    4637 
    4638         fileName = self._getDefaultPIREPName()
    4639 
    4640         dialog = self._getSaveDialog()
    4641 
    4642         if self._lastSavePath is None:
    4643             pirepDirectory = gui.config.pirepDirectory
    4644             if pirepDirectory is not None:
    4645                 dialog.set_current_folder(pirepDirectory)
    4646         else:
    4647             dialog.set_current_folder(os.path.dirname(self._lastSavePath))
    4648 
    4649         dialog.set_current_name(fileName)
    4650         result = dialog.run()
    4651         dialog.hide()
    4652 
    4653         if result==RESPONSETYPE_OK:
    4654             self._lastSavePath = text2unicode(dialog.get_filename())
    4655             self._savePIREP()
    4656 
    4657     def _savePIREP(self, automatic = False):
    4658         """Perform the saving of the PIREP."""
    4659 
    4660         gui = self._wizard.gui
    4661 
    4662         if automatic:
    4663             gui.beginBusy(xstr("finish_autosave_busy"))
    4664 
    4665         pirep = PIREP(gui.flight)
    4666         error = pirep.save(self._lastSavePath)
    4667 
    4668         if automatic:
    4669             gui.endBusy()
    4670 
    4671         if error:
    4672             type = MESSAGETYPE_ERROR
    4673             message = xstr("finish_save_failed")
    4674             secondary = xstr("finish_save_failed_sec") % (text2unicode(error),)
    4675         else:
    4676             type = MESSAGETYPE_INFO
    4677             message = xstr("finish_save_done")
    4678             if automatic:
    4679                 secondary = xstr("finish_save_done_sec") % (self._lastSavePath,)
    4680             else:
    4681                 secondary = None
    4682             self._pirepSaved = True
    4683 
    4684         dialog = gtk.MessageDialog(parent = gui.mainWindow,
    4685                                    type = type, message_format = message)
    4686         dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK)
    4687         dialog.set_title(WINDOW_TITLE_BASE)
    4688         if secondary is not None:
    4689             dialog.format_secondary_markup(secondary)
    4690 
    4691         dialog.run()
    4692         dialog.hide()
    4693 
    4694     def _getSaveDialog(self):
    4695         """Get the PIREP saving dialog.
    4696 
    4697         If it does not exist yet, create it."""
    4698         if self._savePIREPDialog is None:
    4699             gui = self._wizard.gui
    4700             dialog = gtk.FileChooserDialog(title = WINDOW_TITLE_BASE + " - " +
    4701                                            xstr("finish_save_title"),
    4702                                            action = FILE_CHOOSER_ACTION_SAVE,
    4703                                            buttons = (gtk.STOCK_CANCEL,
    4704                                                       RESPONSETYPE_CANCEL,
    4705                                                       gtk.STOCK_OK, RESPONSETYPE_OK),
    4706                                            parent = gui.mainWindow)
    4707             dialog.set_modal(True)
    4708             dialog.set_do_overwrite_confirmation(True)
    4709 
    4710             filter = gtk.FileFilter()
    4711             filter.set_name(xstr("file_filter_pireps"))
    4712             filter.add_pattern("*.pirep")
    4713             dialog.add_filter(filter)
    4714 
    4715             filter = gtk.FileFilter()
    4716             filter.set_name(xstr("file_filter_all"))
    4717             filter.add_pattern("*.*")
    4718             dialog.add_filter(filter)
    4719 
    4720             self._savePIREPDialog = dialog
    4721 
    4722         return self._savePIREPDialog
    4723 
    47244880
    47254881    def _sendClicked(self, button):
     
    48164972#-----------------------------------------------------------------------------
    48174973
     4974class CheckFlightFinishPage(Page):
     4975    """Finish page for a check flight."""
     4976    def __init__(self, wizard, saveHelper):
     4977        """Construct the check flight finish page."""
     4978        super(CheckFlightFinishPage, self).__init__(wizard,
     4979                                                    "chkfinish",
     4980                                                    xstr("chkfinish_title"),
     4981                                                    "")
     4982
     4983        alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
     4984                                  xscale = 1.0, yscale = 1.0)
     4985        self._label = gtk.Label()
     4986        alignment.add(self._label)
     4987
     4988        self.setMainWidget(alignment)
     4989
     4990        self._saveHelper = saveHelper
     4991        self._saveButton = saveHelper.addButton(self)
     4992
     4993        self._button = self.addNextButton(sensitive = False,
     4994                                          clicked =  self._forwardClicked)
     4995
     4996    def activate(self):
     4997        """Activate the page."""
     4998        wizard = self._wizard
     4999        loginResult = wizard.loginResult
     5000        gui = wizard.gui
     5001        rating = gui.flight.logger.getRating()
     5002
     5003        if rating>=0:
     5004            loginResult.checkFlightStatus = True
     5005
     5006        firstOfficer = \
     5007          loginResult.entryExamPassed and loginResult.checkFlightStatus
     5008
     5009        if firstOfficer:
     5010            loginResult.rank = "FO"
     5011
     5012        if rating<0:
     5013            mainMessage = xstr("chkfinish_failed")
     5014        else:
     5015            mainMessage = xstr("chkfinish_passed_begin")
     5016            if firstOfficer:
     5017                mainMessage += xstr("chkfinish_passed_fo")
     5018            mainMessage += xstr("chkfinish_passed_end")
     5019
     5020        if firstOfficer:
     5021            nextMessage = xstr("chkfinish_next")
     5022        else:
     5023            nextMessage = xstr("chkfinish_next_student_begin")
     5024            if not loginResult.entryExamPassed and \
     5025               not loginResult.checkFlightStatus:
     5026                nextMessage += xstr("chkfinish_next_student_nothing")
     5027            elif loginResult.entryExamPassed and \
     5028                 not loginResult.checkFlightStatus:
     5029                nextMessage += xstr("chkfinish_next_student_no_flight")
     5030            elif not loginResult.entryExamPassed and \
     5031                 loginResult.checkFlightStatus:
     5032                nextMessage += xstr("chkfinish_next_student_no_exam")
     5033
     5034        self._label.set_text(mainMessage +
     5035                             xstr("chkfinish_savepirep") +
     5036                             nextMessage)
     5037        self._label.set_use_markup(True)
     5038        self._label.set_alignment(0.5, 0.0)
     5039
     5040        self._saveButton.set_sensitive(True)
     5041        self._button.set_sensitive(True)
     5042
     5043    def _forwardClicked(self, button):
     5044        """Jump to the student page if there are some tasks to do,
     5045        or to the flight selection page, if the pilot is allowed to perform
     5046        MAVA flights."""
     5047        wizard = self._wizard
     5048        gui = wizard.gui
     5049
     5050        loginResult = wizard.loginResult
     5051        if loginResult.checkFlightStatus:
     5052            gui.beginBusy(xstr("chkfinish_updateweb_busy"))
     5053            gui.webHandler.setCheckFlightPassed(self._checkFlightPassedSetCallback,
     5054                                                wizard.checkFlightAircraftType)
     5055        else:
     5056            self._resetGUI()
     5057
     5058    def _checkFlightPassedSetCallback(self, returned, result):
     5059        """Called when the check flight status has been set."""
     5060        gobject.idle_add(self._checkFlightPassedSet, returned, result)
     5061
     5062    def _checkFlightPassedSet(self, returned, result):
     5063        """Handle the result of an attempt to set the check flight status."""
     5064        gui = self._wizard.gui
     5065
     5066        gui.endBusy()
     5067
     5068        if returned:
     5069            self._resetGUI()
     5070        else:
     5071            dialog = gtk.MessageDialog(parent = gui.mainWindow,
     5072                                       type = MESSAGETYPE_ERROR,
     5073                                       message_format =
     5074                                       xstr("chkfinish_passedset_failed"))
     5075            dialog.set_title(WINDOW_TITLE_BASE + " - " +
     5076                             xstr("chkfinish_passedset_failed_title"))
     5077            dialog.format_secondary_markup(xstr("chkfinish_passedset_failed_secondary"))
     5078
     5079            dialog.add_button(xstr("button_ok"), 0)
     5080
     5081            dialog.run()
     5082            dialog.hide()
     5083
     5084    def _resetGUI(self):
     5085        """Reset the GUI."""
     5086        gui = self._wizard.gui
     5087        gui.reset()
     5088
     5089#-----------------------------------------------------------------------------
     5090
    48185091class Wizard(gtk.VBox):
    48195092    """The flight wizard."""
     
    48325105        self._pages.append(GateSelectionPage(self))
    48335106        self._pages.append(RegisterPage(self))
    4834         self._pages.append(StudentPage(self))
     5107        self._studentPage = StudentPage(self)
     5108        self._pages.append(self._studentPage)
    48355109        self._pages.append(ConnectPage(self))
    48365110        self._payloadPage = PayloadPage(self)
     
    48565130        self._landingPage = LandingPage(self)
    48575131        self._pages.append(self._landingPage)
    4858         self._finishPage = FinishPage(self)
     5132
     5133        pirepSaveHelper = PIREPSaveHelper(self)
     5134
     5135        self._finishPage = FinishPage(self, pirepSaveHelper)
    48595136        self._pages.append(self._finishPage)
     5137        self._pages.append(CheckFlightFinishPage(self, pirepSaveHelper))
    48605138
    48615139        self._requestedWidth = None
     
    49165194        """Get the login result."""
    49175195        return self._loginResult
     5196
     5197    @property
     5198    def checkFlightAircraftType(self):
     5199        """Get the type of the aircraft used to perform the check flight."""
     5200        return self._studentPage.aircraftType
    49185201
    49195202    def setCurrentPage(self, index, finalize = False, fromPageShift = None):
     
    52185501    def reloadFlights(self, callback):
    52195502        """Reload the flights from the MAVA server."""
    5220         self.login(callback, None, None, None)
     5503        self.login(callback, None, None)
     5504
     5505    def cancelFlight(self, reloadCallback):
     5506        """Cancel the flight.
     5507
     5508        If it is an entry exam flight, we go back to the student page.
     5509        Otherwise we reload the flights."""
     5510        if self.entranceExam:
     5511            self.reset(None)
     5512            self.jumpPage("student")
     5513        else:
     5514            self.reloadFlights(reloadCallback)
    52215515
    52225516    def cruiseLevelChanged(self):
Note: See TracChangeset for help on using the changeset viewer.