Changeset 754:8547ad78cc29


Ignore:
Timestamp:
01/06/16 13:36:31 (8 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

The pages now have a textual identifier and can be referenced with it (re #286)

File:
1 edited

Legend:

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

    r753 r754  
    6262class Page(gtk.Alignment):
    6363    """A page in the flight wizard."""
    64     def __init__(self, wizard, title, help, completedHelp = None):
     64    def __init__(self, wizard, id, title, help, completedHelp = None):
    6565        """Construct the page."""
    6666        super(Page, self).__init__(xalign = 0.0, yalign = 0.0,
     
    140140
    141141        self._wizard = wizard
     142        self._id = id
     143        self._nextPageID = None
    142144
    143145        self._cancelFlightButton = None
     
    145147        self._completed = False
    146148        self._fromPage = None
     149
     150    @property
     151    def id(self):
     152        """Get the identifier of the page."""
     153        return self._id
     154
     155    @property
     156    def nextPageID(self):
     157        """Get the identifier of the next page, if set."""
     158        return self._nextPageID
     159
     160    @nextPageID.setter
     161    def nextPageID(self, nextPageID):
     162        """Set the identifier of the next page."""
     163        self._nextPageID = nextPageID
    147164
    148165    def setMainWidget(self, widget):
     
    278295    def __init__(self, wizard):
    279296        """Construct the login page."""
    280         super(LoginPage, self).__init__(wizard, xstr("login"),
    281                                         xstr("loginHelp"))
     297        super(LoginPage, self).__init__(wizard, "login",
     298                                        xstr("login"), xstr("loginHelp"))
    282299
    283300        alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
     
    393410    def _registerClicked(self, button):
    394411        """Called when the Register button was clicked."""
    395         self._wizard.jumpPage(3)
     412        self._wizard.jumpPage("register")
    396413
    397414    def _offlineClicked(self, button):
     
    432449        help = xstr("flightsel_help")
    433450        completedHelp = xstr("flightsel_chelp")
    434         super(FlightSelectionPage, self).__init__(wizard, xstr("flightsel_title"),
     451        super(FlightSelectionPage, self).__init__(wizard, "flightsel",
     452                                                  xstr("flightsel_title"),
    435453                                                  help, completedHelp = completedHelp)
    436454
     
    612630        """Called when the forward button was clicked."""
    613631        if self._completed:
    614             self._wizard.jumpPage(self._nextDistance, finalize = False)
     632            self._wizard.jumpPage(self._nextID, finalize = False)
    615633        else:
    616634            self._flightSelected()
     
    667685                                         const.PLANE_AWAY)
    668686        else:
    669             self._nextDistance = 4
    670             self._wizard.jumpPage(4)
     687            self._nextID = "connect"
     688            self._wizard.jumpPage("connect")
    671689
    672690    def _fleetRetrieved(self, fleet):
    673691        """Called when the fleet has been retrieved."""
    674692        if fleet is None:
    675             self._nextDistance = 4
    676             self._wizard.jumpPage(4)
     693            self._nextID = "connect"
     694            self._wizard.jumpPage("connect")
    677695        else:
    678696            plane = fleet[self._wizard._bookedFlight.tailNumber]
    679697            if plane is None:
    680                 self._nextDistance = 4
    681                 self._wizard.jumpPage(4)
     698                self._nextID = "connect"
     699                self._wizard.jumpPage("connect")
    682700            elif plane.gateNumber is not None and \
    683701                 not fleet.isGateConflicting(plane):
    684702                self._wizard._departureGate = plane.gateNumber
    685                 self._nextDistance = 4
    686                 self._wizard.jumpPage(4)
     703                self._nextID = "connect"
     704                self._wizard.jumpPage("connect")
    687705            else:
    688                 self._nextDistance = 1
    689                 self._wizard.nextPage()
     706                self._nextID = "gatesel"
     707                self._wizard.jumpPage("gatesel")
    690708
    691709    def _planeUpdated(self, success):
    692710        """Callback for the plane updating."""
    693         self._nextDistance = 4
    694         self._wizard.jumpPage(4)
     711        self._nextID = "connect"
     712        self._wizard.jumpPage("connect")
    695713
    696714    def _getSaveDialog(self):
     
    795813    def __init__(self, wizard):
    796814        """Construct the gate selection page."""
    797         super(GateSelectionPage, self).__init__(wizard, xstr("gatesel_title"),
     815        super(GateSelectionPage, self).__init__(wizard, "gatesel",
     816                                                xstr("gatesel_title"),
    798817                                                xstr("gatesel_help"))
    799818
     
    858877            self._gateSelected()
    859878        else:
    860             self._wizard.jumpPage(3)
     879            self._wizard.jumpPage("connect")
    861880
    862881    def _rowActivated(self, flightList, path, column):
     
    880899        """Callback for the plane updating call."""
    881900        if success is None or success:
    882             self._wizard.jumpPage(3)
     901            self._wizard.jumpPage("connect")
    883902        else:
    884903            dialog = gtk.MessageDialog(parent = self._wizard.gui.mainWindow,
     
    896915        """Called when the fleet has been retrieved."""
    897916        if fleet is None:
    898             self._wizard.jumpPage(3)
     917            self._wizard.jumpPage("connect")
    899918        else:
    900919            self.activate()
     
    916935    def __init__(self, wizard):
    917936        """Construct the registration page."""
    918         super(RegisterPage, self).__init__(wizard, xstr("register_title"),
     937        super(RegisterPage, self).__init__(wizard, "register",
     938                                           xstr("register_title"),
    919939                                           xstr("register_help"))
    920940
     
    11701190    def __init__(self, wizard):
    11711191        """Construct the student page."""
    1172         super(StudentPage, self).__init__(wizard, xstr("student_title"),
     1192        super(StudentPage, self).__init__(wizard, "student",
     1193                                          xstr("student_title"),
    11731194                                          xstr("student_help"))
    11741195
     
    11831204               "Then press the Connect button to connect to the simulator."
    11841205        completedHelp = "The basic data of your flight can be read below."
    1185         super(ConnectPage, self).__init__(wizard, xstr("connect_title"),
     1206        super(ConnectPage, self).__init__(wizard, "connect",
     1207                                          xstr("connect_title"),
    11861208                                          xstr("connect_help"),
    11871209                                          completedHelp = xstr("connect_chelp"))
     
    13661388    def __init__(self, wizard):
    13671389        """Construct the page."""
    1368         super(PayloadPage, self).__init__(wizard, xstr("payload_title"),
     1390        super(PayloadPage, self).__init__(wizard, "payload",
     1391                                          xstr("payload_title"),
    13691392                                          xstr("payload_help"),
    13701393                                          completedHelp = xstr("payload_chelp"))
     
    15931616    current time from the flight simulator."""
    15941617    def __init__(self, wizard):
    1595         super(TimePage, self).__init__(wizard, xstr("time_title"),
     1618        super(TimePage, self).__init__(wizard, "time",
     1619                                       xstr("time_title"),
    15961620                                       xstr("time_help"),
    15971621                                       completedHelp = xstr("time_chelp"))
     
    17141738    def __init__(self, wizard):
    17151739        """Construct the page."""
    1716         super(RoutePage, self).__init__(wizard, xstr("route_title"),
     1740        super(RoutePage, self).__init__(wizard, "route",
     1741                                        xstr("route_title"),
    17171742                                        xstr("route_help"),
    17181743                                        completedHelp = xstr("route_chelp"))
     
    18821907        if self._wizard.gui.config.useSimBrief and \
    18831908           self._wizard.usingSimBrief is not False:
    1884             self._wizard.nextPage()
     1909            self._wizard.jumpPage("simbrief_setup")
    18851910        else:
    18861911            self._wizard.usingSimBrief = False
    1887             self._wizard.jumpPage(3)
     1912            self._wizard.jumpPage("fuel")
    18881913
    18891914#-----------------------------------------------------------------------------
     
    20442069        """Construct the setup page."""
    20452070
    2046         super(SimBriefSetupPage, self).__init__(wizard,
     2071        super(SimBriefSetupPage, self).__init__(wizard, "simbrief_setup",
    20472072                                                xstr("simbrief_setup_title"),
    20482073                                                xstr("simbrief_setup_help"),
     
    23632388
    23642389                self._wizard.usingSimBrief = False
    2365                 self._wizard.jumpPage(2, fromPageShift = 1)
     2390                self._wizard.jumpPage("fuel", fromPageShift = 1)
    23662391
    23672392    def _getPlan(self):
     
    24482473        """Construct the setup page."""
    24492474
    2450         super(SimBriefingPage, self).__init__(wizard,
     2475        super(SimBriefingPage, self).__init__(wizard, "simbrief_result",
    24512476                                              xstr("simbrief_result_title"), "")
    24522477
     
    27042729    def __init__(self, wizard):
    27052730        """Construct the page."""
    2706         super(FuelPage, self).__init__(wizard, xstr("fuel_title"),
     2731        super(FuelPage, self).__init__(wizard, "fuel",
     2732                                       xstr("fuel_title"),
    27072733                                       xstr("fuel_help_pre") +
    27082734                                       xstr("fuel_help_post"),
     
    27562782            self._pump()
    27572783        elif self._wizard.usingSimBrief:
    2758             self._wizard.jumpPage(3)
     2784            self._wizard.jumpPage("takeoff")
    27592785        else:
    2760             self._wizard.nextPage()
     2786            self._wizard.jumpPage("briefing1")
    27612787
    27622788    def _setupTanks(self, tankData):
     
    28042830            if self._wizard.usingSimBrief:
    28052831                self._wizard.gui.startMonitoring()
    2806                 self._wizard.jumpPage(3)
     2832                self._wizard.jumpPage("takeoff")
    28072833            else:
    28082834                bookedFlight = self._wizard._bookedFlight
     
    28732899        self._departure = departure
    28742900
    2875         title = xstr("briefing_title") % (1 if departure else 2,
     2901        number = 1 if departure else 2
     2902
     2903        title = xstr("briefing_title") % (number,
    28762904                                          xstr("briefing_departure")
    28772905                                          if departure
    28782906                                          else xstr("briefing_arrival"))
    2879         super(BriefingPage, self).__init__(wizard, title, xstr("briefing_help"),
     2907        super(BriefingPage, self).__init__(wizard,
     2908                                           "briefing%d" % (number,),
     2909                                           title, xstr("briefing_help"),
    28802910                                           completedHelp = xstr("briefing_chelp"))
    28812911
     
    30643094    def __init__(self, wizard):
    30653095        """Construct the takeoff page."""
    3066         super(TakeoffPage, self).__init__(wizard, xstr("takeoff_title"),
     3096        super(TakeoffPage, self).__init__(wizard, "takeoff",
     3097                                          xstr("takeoff_title"),
    30673098                                          xstr("takeoff_help"),
    30683099                                          completedHelp = xstr("takeoff_chelp"))
     
    35523583    def __init__(self, wizard):
    35533584        """Construct the page."""
    3554         super(CruisePage, self).__init__(wizard, xstr("cruise_title"),
     3585        super(CruisePage, self).__init__(wizard, "cruise",
     3586                                         xstr("cruise_title"),
    35553587                                         xstr("cruise_help"))
    35563588
     
    36663698    def __init__(self, wizard):
    36673699        """Construct the landing page."""
    3668         super(LandingPage, self).__init__(wizard, xstr("landing_title"),
     3700        super(LandingPage, self).__init__(wizard, "landing",
     3701                                          xstr("landing_title"),
    36693702                                          xstr("landing_help"),
    36703703                                          completedHelp = xstr("landing_chelp"))
     
    39804013        """Construct the finish page."""
    39814014        help = xstr("finish_help") + xstr("finish_help_goodtime")
    3982         super(FinishPage, self).__init__(wizard, xstr("finish_title"), help)
     4015        super(FinishPage, self).__init__(wizard, "finish",
     4016                                         xstr("finish_title"), help)
    39834017
    39844018        alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
     
    48354869    def nextPage(self, finalize = True):
    48364870        """Go to the next page."""
    4837         self.jumpPage(1, finalize)
    4838 
    4839     def jumpPage(self, count, finalize = True, fromPageShift = None):
     4871        nextPageID = self._pages[self._currentPage].nextPageID
     4872        self.jumpPage(1 if nextPageID is None else nextPageID, finalize)
     4873
     4874    def jumpPage(self, countOrID, finalize = True, fromPageShift = None):
    48404875        """Go to the page which is 'count' pages after the current one."""
    4841         self.setCurrentPage(self._currentPage + count,
     4876        if isinstance(countOrID, str):
     4877            targetIndex = self._getIndexOf(countOrID)
     4878        else:
     4879            targetIndex = self._currentPage + countOrID
     4880        self.setCurrentPage(targetIndex,
    48424881                            finalize = finalize, fromPageShift = fromPageShift)
    48434882
     
    50715110                self._arrivalBriefingPage.setMETAR(metar)
    50725111
     5112    def _getIndexOf(self, pageID):
     5113        """Get the index for the given page ID.
     5114
     5115        It is an assertion failure if the ID is not found."""
     5116        for index in range(0, len(self._pages)):
     5117            page = self._pages[index]
     5118            if page.id==pageID:
     5119                return index
     5120        assert False
     5121
    50735122#-----------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.