Changeset 70:64fb5caf4cad


Ignore:
Timestamp:
04/09/12 08:55:12 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Implemented two-way navigation between the wizard pages.

Location:
src/mlx/gui
Files:
3 edited

Legend:

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

    r69 r70  
    7575                                    padding_left = 16, padding_right = 16)
    7676
    77         self._buttonBox = gtk.HButtonBox()
     77        self._buttonBox = gtk.HBox()
     78        self._buttonBox.set_homogeneous(False)
    7879        self._defaultButton = None
    7980        buttonAlignment.add(self._buttonBox)
     
    8283
    8384        self._wizard = wizard
     85
     86        self._finalized = False
     87        self._fromPage = None
    8488
    8589    def setMainWidget(self, widget):
     
    9296        Return the button object created."""
    9397        button = gtk.Button(label)
    94         self._buttonBox.add(button)
     98        self._buttonBox.pack_start(button, False, False, 4)
    9599        button.set_use_underline(True)
    96100        if default:
     
    105109        pass
    106110
     111    def finalize(self):
     112        """Called when the page is finalized."""
     113        pass
     114
    107115    def grabDefault(self):
    108116        """If the page has a default button, make it the default one."""
     
    112120    def reset(self):
    113121        """Reset the page if the wizard is reset."""
    114         pass
     122        self._finalized = False
     123        self._fromPage = None
     124
     125    def goBack(self):
     126        """Go to the page we were invoked from."""
     127        assert self._fromPage is not None
     128       
     129        self._wizard.setCurrentPage(self._fromPage, finalize = False)
    115130   
    116131#-----------------------------------------------------------------------------
     
    192207    def _loginClicked(self, button):
    193208        """Called when the login button was clicked."""
    194         self._wizard.gui.beginBusy("Logging in...")
    195         self._wizard.gui.webHandler.login(self._loginResultCallback,
    196                                           self._pilotID.get_text(),
    197                                           self._password.get_text())
     209        self._loginButton.set_sensitive(False)
     210        gui = self._wizard.gui
     211        gui.beginBusy("Logging in...")
     212        gui.webHandler.login(self._loginResultCallback,
     213                            self._pilotID.get_text(),
     214                            self._password.get_text())
    198215
    199216    def _loginResultCallback(self, returned, result):
     
    204221        """Handle the login result."""
    205222        self._wizard.gui.endBusy()
     223        self._loginButton.set_sensitive(True)
    206224        if returned:
    207225            if result.loggedIn:
     
    290308        self._button.connect("clicked", self._forwardClicked)
    291309
    292         self._activated = False
    293 
    294310    def activate(self):
    295311        """Fill the flight list."""
    296         if not self._activated:
    297             for flight in self._wizard.loginResult.flights:
    298                 self._listStore.append([str(flight.departureTime),
    299                                         flight.callsign,
    300                                         flight.departureICAO,
    301                                         flight.arrivalICAO])
    302             self._activated = True
     312        self._flightList.set_sensitive(True)
     313        self._listStore.clear()
     314        for flight in self._wizard.loginResult.flights:
     315            self._listStore.append([str(flight.departureTime),
     316                                    flight.callsign,
     317                                    flight.departureICAO,
     318                                    flight.arrivalICAO])
     319
     320    def finalize(self):
     321        """Finalize the page."""
     322        self._flightList.set_sensitive(False)
    303323
    304324    def _selectionChanged(self, selection):
     
    308328    def _forwardClicked(self, button):
    309329        """Called when the forward button was clicked."""
    310         selection = self._flightList.get_selection()
    311         (listStore, iter) = selection.get_selected()
    312         path = listStore.get_path(iter)
    313         [index] = path.get_indices() if pygobject else path
    314 
    315         flight = self._wizard.loginResult.flights[index]
    316         self._wizard._bookedFlight = flight
    317 
    318         self._updateDepartureGate()
     330        if self._finalized:
     331            self._wizard.jumpPage(self._nextDistance, finalize = False)
     332        else:
     333            selection = self._flightList.get_selection()
     334            (listStore, iter) = selection.get_selected()
     335            path = listStore.get_path(iter)
     336            [index] = path.get_indices() if pygobject else path
     337
     338            flight = self._wizard.loginResult.flights[index]
     339            self._wizard._bookedFlight = flight
     340
     341            self._updateDepartureGate()
    319342       
    320343    def _updateDepartureGate(self):
     
    324347            self._wizard._getFleet(self._fleetRetrieved)
    325348        else:
     349            self._nextDistance = 2
    326350            self._wizard.jumpPage(2)
    327351
     
    329353        """Called when the fleet has been retrieved."""
    330354        if fleet is None:
     355            self._nextDistance = 2
    331356            self._wizard.jumpPage(2)
    332357        else:
    333358            plane = fleet[self._wizard._bookedFlight.tailNumber]
    334359            if plane is None:
     360                self._nextDistance = 2
    335361                self._wizard.jumpPage(2)
    336            
    337             if plane.gateNumber is not None and \
    338                not fleet.isGateConflicting(plane):
     362            elif plane.gateNumber is not None and \
     363                 not fleet.isGateConflicting(plane):
    339364                self._wizard._departureGate = plane.gateNumber
     365                self._nextDistance = 2
    340366                self._wizard.jumpPage(2)
    341367            else:
     368                self._nextDistance = 1
    342369                self._wizard.nextPage()
    343370       
     
    391418        """Fill the gate list."""
    392419        self._listStore.clear()
     420        self._gateList.set_sensitive(True)
    393421        occupiedGateNumbers = self._wizard._fleet.getOccupiedGateNumbers()
    394422        for gateNumber in const.lhbpGateNumbers:
     
    396424                self._listStore.append([gateNumber])
    397425
     426    def finalize(self):
     427        """Finalize the page."""
     428        self._gateList.set_sensitive(False)
     429
    398430    def _selectionChanged(self, selection):
    399431        """Called when the selection is changed."""
     
    402434    def _forwardClicked(self, button):
    403435        """Called when the forward button is clicked."""
    404         selection = self._gateList.get_selection()
    405         (listStore, iter) = selection.get_selected()
    406         (gateNumber,) = listStore.get(iter, 0)
    407 
    408         self._wizard._departureGate = gateNumber
    409 
    410         #self._wizard._updatePlane(self._planeUpdated,
    411         #                          self._wizard._bookedFlight.tailNumber,
    412         #                          const.PLANE_HOME,
    413         #                          gateNumber)
     436        if not self._finalized:
     437            selection = self._gateList.get_selection()
     438            (listStore, iter) = selection.get_selected()
     439            (gateNumber,) = listStore.get(iter, 0)
     440
     441            self._wizard._departureGate = gateNumber
     442
     443            #self._wizard._updatePlane(self._planeUpdated,
     444            #                          self._wizard._bookedFlight.tailNumber,
     445            #                          const.PLANE_HOME,
     446            #                          gateNumber)
     447       
    414448        self._wizard.nextPage()
    415449
     
    482516        table.attach(labelAlignment, 1, 2, 1, 2)
    483517
     518        button = self.addButton(gtk.STOCK_GO_BACK)
     519        button.set_use_stock(True)
     520        button.connect("clicked", self._backClicked)
     521
    484522        self._button = self.addButton("_Connect", default = True)
    485523        self._button.set_use_underline(True)
    486         self._button.connect("clicked", self._connectClicked)
     524        self._clickedID = self._button.connect("clicked", self._connectClicked)
    487525
    488526    def activate(self):
    489527        """Setup the departure information."""
     528        self._button.set_label("_Connect")
     529        self._button.set_use_underline(True)
     530        self._button.disconnect(self._clickedID)
     531        self._clickedID = self._button.connect("clicked", self._connectClicked)
     532       
    490533        icao = self._wizard._bookedFlight.departureICAO
    491534        self._departureICAO.set_markup("<b>" + icao + "</b>")
     
    495538        self._departureGate.set_markup(gate)
    496539
     540    def finalize(self):
     541        """Finalize the page."""
     542        self._button.set_label(gtk.STOCK_GO_FORWARD)
     543        self._button.set_use_stock(True)
     544        self._button.disconnect(self._clickedID)
     545        self._clickedID = self._button.connect("clicked", self._forwardClicked)
     546
     547    def _backClicked(self, button):
     548        """Called when the Back button is pressed."""
     549        self.goBack()
     550
    497551    def _connectClicked(self, button):
    498552        """Called when the Connect button is pressed."""
    499553        self._wizard._connectSimulator()
     554
     555    def _forwardClicked(self, button):
     556        """Called when the Forward button is pressed."""
     557        self._wizard.nextPage()
    500558
    501559#-----------------------------------------------------------------------------
     
    589647        table.attach(gtk.Label("kg"), 2, 3, 5, 6)
    590648
    591         button = gtk.Button("_ZFW from FS:")
    592         button.set_use_underline(True)
    593         button.connect("clicked", self._zfwRequested)
    594         table.attach(button, 0, 1, 6, 7)
     649        self._zfwButton = gtk.Button("_ZFW from FS:")
     650        self._zfwButton.set_use_underline(True)
     651        self._zfwButton.connect("clicked", self._zfwRequested)
     652        table.attach(self._zfwButton, 0, 1, 6, 7)
    595653
    596654        self._simulatorZFW = gtk.Label("-")
     
    601659
    602660        table.attach(gtk.Label("kg"), 2, 3, 6, 7)
     661
     662        self._backButton = self.addButton(gtk.STOCK_GO_BACK)
     663        self._backButton.set_use_stock(True)
     664        self._backButton.connect("clicked", self._backClicked)
    603665
    604666        self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
     
    614676        self._cargoWeightValue = bookedFlight.cargoWeight
    615677        self._cargoWeight.set_text(str(bookedFlight.cargoWeight))
     678        self._cargoWeight.set_sensitive(True)
    616679        self._mailWeight.set_text(str(bookedFlight.mailWeight))
     680        self._zfwButton.set_sensitive(True)
    617681        self._updateCalculatedZFW()
     682
     683    def finalize(self):
     684        """Finalize the payload page."""
     685        self._cargoWeight.set_sensitive(False)
     686        self._zfwButton.set_sensitive(False)
    618687
    619688    def _calculateZFW(self):
     
    653722    def _zfwRequested(self, button):
    654723        """Called when the ZFW is requested from the simulator."""
    655         self._wizard.gui.beginBusy("Querying ZFW...")
    656         self._wizard.gui.simulator.requestZFW(self._handleZFW)
     724        self._zfwButton.set_sensitive(False)
     725        self._backButton.set_sensitive(False)
     726        self._button.set_sensitive(False)
     727        gui = self._wizard.gui
     728        gui.beginBusy("Querying ZFW...")
     729        gui.simulator.requestZFW(self._handleZFW)
    657730
    658731    def _handleZFW(self, zfw):
     
    663736        """Process the given ZFW value received from the simulator."""
    664737        self._wizard.gui.endBusy()
     738        self._zfwButton.set_sensitive(True)
     739        self._backButton.set_sensitive(True)
     740        self._button.set_sensitive(True)
    665741        self._simulatorZFWValue = zfw
    666742        self._simulatorZFW.set_text("%.0f" % (zfw,))
     
    669745    def _forwardClicked(self, button):
    670746        """Called when the forward button is clicked."""
    671         self._wizard._zfw = self._calculateZFW()
     747        if not self._finalized:
     748            self._wizard._zfw = self._calculateZFW()
    672749        self._wizard.nextPage()
     750
     751    def _backClicked(self, button):
     752        """Called when the Back button is pressed."""
     753        self.goBack()
    673754       
    674755#-----------------------------------------------------------------------------
     
    710791        table.attach(self._arrival, 1, 2, 1, 2)
    711792
    712         button = gtk.Button("_Time from FS:")
    713         button.set_use_underline(True)
    714         button.connect("clicked", self._timeRequested)
    715         table.attach(button, 0, 1, 2, 3)
     793        self._timeButton = gtk.Button("_Time from FS:")
     794        self._timeButton.set_use_underline(True)
     795        self._timeButton.connect("clicked", self._timeRequested)
     796        table.attach(self._timeButton, 0, 1, 2, 3)
    716797
    717798        self._simulatorTime = gtk.Label("-")
     
    719800        table.attach(self._simulatorTime, 1, 2, 2, 3)
    720801
     802        self._backButton = self.addButton(gtk.STOCK_GO_BACK)
     803        self._backButton.set_use_stock(True)
     804        self._backButton.connect("clicked", self._backClicked)
     805
    721806        self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
    722807        self._button.set_use_stock(True)
     
    725810    def activate(self):
    726811        """Activate the page."""
     812        self._timeButton.set_sensitive(True)
    727813        bookedFlight = self._wizard._bookedFlight
    728814        self._departure.set_text(str(bookedFlight.departureTime.time()))
    729815        self._arrival.set_text(str(bookedFlight.arrivalTime.time()))
    730816
     817    def finalize(self):
     818        """Finalize the page."""
     819        self._timeButton.set_sensitive(False)
     820
    731821    def _timeRequested(self, button):
    732822        """Request the time from the simulator."""
     823        self._timeButton.set_sensitive(False)
     824        self._backButton.set_sensitive(False)
     825        self._button.set_sensitive(False)
    733826        self._wizard.gui.beginBusy("Querying time...")
    734827        self._wizard.gui.simulator.requestTime(self._handleTime)
     
    741834        """Process the given time."""
    742835        self._wizard.gui.endBusy()
     836        self._timeButton.set_sensitive(True)
     837        self._backButton.set_sensitive(True)
     838        self._button.set_sensitive(True)
    743839        tm = time.gmtime(timestamp)
    744840        t = datetime.time(tm.tm_hour, tm.tm_min, tm.tm_sec)
     
    761857        self._departure.set_markup(markupBegin + str(dt) + markupEnd)
    762858
     859    def _backClicked(self, button):
     860        """Called when the Back button is pressed."""
     861        self.goBack()
     862       
    763863    def _forwardClicked(self, button):
    764864        """Called when the forward button is clicked."""
     
    834934        mainBox.pack_start(routeBox, True, True, 8)
    835935
     936        self._backButton = self.addButton(gtk.STOCK_GO_BACK)
     937        self._backButton.set_use_stock(True)
     938        self._backButton.connect("clicked", self._backClicked)
     939
    836940        self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
    837941        self._button.set_use_stock(True)
     
    840944    def activate(self):
    841945        """Setup the route from the booked flight."""
     946        self._route.set_sensitive(True)
     947        self._cruiseLevel.set_sensitive(True)
    842948        self._route.get_buffer().set_text(self._wizard._bookedFlight.route)
    843949        self._updateForwardButton()
     950
     951    def finalize(self):
     952        """Finalize the page."""
     953        self._route.set_sensitive(False)
     954        self._cruiseLevel.set_sensitive(False)
    844955
    845956    def _getRoute(self):
     
    862973        self._updateForwardButton()
    863974
     975    def _backClicked(self, button):
     976        """Called when the Back button is pressed."""
     977        self.goBack()
     978       
    864979    def _forwardClicked(self, button):
    865980        """Called when the Forward button is clicked."""
    866         self._wizard._cruiseAltitude = self._cruiseLevel.get_value_as_int() * 100
    867         self._wizard._route = self._getRoute()
    868 
    869         bookedFlight = self._wizard._bookedFlight
    870         self._wizard.gui.beginBusy("Downloading NOTAMs...")
    871         self._wizard.gui.webHandler.getNOTAMs(self._notamsCallback,
    872                                               bookedFlight.departureICAO,
    873                                               bookedFlight.arrivalICAO)
     981        if self._finalized:
     982            self._wizard.nextPage()
     983        else:
     984            self._wizard._cruiseAltitude = self._cruiseLevel.get_value_as_int() * 100
     985            self._wizard._route = self._getRoute()
     986
     987            self._backButton.set_sensitive(False)
     988            self._button.set_sensitive(False)
     989            self._cruiseLevel.set_sensitive(False)
     990            self._route.set_sensitive(False)
     991
     992            bookedFlight = self._wizard._bookedFlight
     993            self._wizard.gui.beginBusy("Downloading NOTAMs...")
     994            self._wizard.gui.webHandler.getNOTAMs(self._notamsCallback,
     995                                                  bookedFlight.departureICAO,
     996                                                  bookedFlight.arrivalICAO)
    874997
    875998    def _notamsCallback(self, returned, result):
     
    9081031
    9091032        self._wizard.gui.endBusy()
     1033        self._backButton.set_sensitive(True)
     1034        self._button.set_sensitive(True)
    9101035        self._wizard.nextPage()
    9111036
     
    9171042        """Construct the briefing page."""
    9181043        self._departure = departure
    919         self._activated = False
    9201044       
    9211045        title = "Briefing (%d/2): %s" % (1 if departure else 2,
     
    9761100        mainBox.pack_start(self._metarFrame, True, True, 4)
    9771101
     1102        button = self.addButton(gtk.STOCK_GO_BACK)
     1103        button.set_use_stock(True)
     1104        button.connect("clicked", self._backClicked)
     1105
    9781106        self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
    9791107        self._button.set_use_stock(True)
     
    9821110    def activate(self):
    9831111        """Activate the page."""
    984         if self._activated:
    985             if not self._departure:
    986                 self._button.set_label(gtk.STOCK_GO_FORWARD)
    987                 self._button.set_use_stock(True)
     1112        if not self._departure:
     1113            self._button.set_label("I have read the briefing and am ready to fly!")
     1114            self._button.set_use_stock(False)
     1115
     1116        bookedFlight = self._wizard._bookedFlight
     1117
     1118        icao = bookedFlight.departureICAO if self._departure \
     1119               else bookedFlight.arrivalICAO
     1120        notams = self._wizard._departureNOTAMs if self._departure \
     1121                 else self._wizard._arrivalNOTAMs
     1122        metar = self._wizard._departureMETAR if self._departure \
     1123                 else self._wizard._arrivalMETAR
     1124
     1125        self._notamsFrame.set_label(icao + " NOTAMs")
     1126        buffer = self._notams.get_buffer()
     1127        if notams is None:
     1128            buffer.set_text("Could not download NOTAMs")
    9881129        else:
    989             if not self._departure:
    990                 self._button.set_label("I have read the briefing and am ready to fly!")
    991                 self._button.set_use_stock(False)
    992 
    993             bookedFlight = self._wizard._bookedFlight
    994 
    995             icao = bookedFlight.departureICAO if self._departure \
    996                    else bookedFlight.arrivalICAO
    997             notams = self._wizard._departureNOTAMs if self._departure \
    998                      else self._wizard._arrivalNOTAMs
    999             metar = self._wizard._departureMETAR if self._departure \
    1000                      else self._wizard._arrivalMETAR
    1001 
    1002             self._notamsFrame.set_label(icao + " NOTAMs")
    1003             buffer = self._notams.get_buffer()
    1004             if notams is None:
    1005                 buffer.set_text("Could not download NOTAMs")
    1006             else:
    1007                 s = ""
    1008                 for notam in notams:
    1009                     s += str(notam.begin)
    1010                     if notam.end is not None:
    1011                         s += " - " + str(notam.end)
    1012                     elif notam.permanent:
    1013                         s += " - PERMANENT"
    1014                     s += "\n"
    1015                     if notam.repeatCycle:
    1016                         s += "Repeat cycle: " + notam.repeatCycle + "\n"
    1017                     s += notam.notice + "\n"
    1018                     s += "-------------------- * --------------------\n"
    1019                 buffer.set_text(s)
    1020 
    1021             self._metarFrame.set_label(icao + " METAR")
    1022             buffer = self._metar.get_buffer()
    1023             if metar is None:
    1024                 buffer.set_text("Could not download METAR")
    1025             else:
    1026                 buffer.set_text(metar)
    1027 
    1028             self._activated = True
    1029 
    1030     def reset(self):
    1031         """Reset the page if the wizard is reset."""
    1032         super(BriefingPage, self).reset()
    1033         self._activated = False
    1034 
     1130            s = ""
     1131            for notam in notams:
     1132                s += str(notam.begin)
     1133                if notam.end is not None:
     1134                    s += " - " + str(notam.end)
     1135                elif notam.permanent:
     1136                    s += " - PERMANENT"
     1137                s += "\n"
     1138                if notam.repeatCycle:
     1139                    s += "Repeat cycle: " + notam.repeatCycle + "\n"
     1140                s += notam.notice + "\n"
     1141                s += "-------------------- * --------------------\n"
     1142            buffer.set_text(s)
     1143
     1144        self._metarFrame.set_label(icao + " METAR")
     1145        buffer = self._metar.get_buffer()
     1146        if metar is None:
     1147            buffer.set_text("Could not download METAR")
     1148        else:
     1149            buffer.set_text(metar)
     1150
     1151    def finalize(self):
     1152        """Finalize the page."""
     1153        if not self._departure:
     1154            self._button.set_use_stock(True)
     1155            self._button.set_label(gtk.STOCK_GO_FORWARD)
     1156
     1157    def _backClicked(self, button):
     1158        """Called when the Back button is pressed."""
     1159        self.goBack()
     1160       
    10351161    def _forwardClicked(self, button):
    10361162        """Called when the forward button is clicked."""
    1037         self._wizard.nextPage()
     1163        if not self._departure:
     1164            if not self._finalized:
     1165                self._wizard.gui.startMonitoring()
     1166                self.finalize()
     1167                self._finalized = True
     1168        else:
     1169            self._wizard.nextPage()
    10381170
    10391171#-----------------------------------------------------------------------------
     
    10801212        return self._loginResult
    10811213
    1082     def setCurrentPage(self, index):
     1214    def setCurrentPage(self, index, finalize = False):
    10831215        """Set the current page to the one with the given index."""
    10841216        assert index < len(self._pages)
    1085        
    1086         if self._currentPage is not None:
    1087             self.remove(self._pages[self._currentPage])
     1217
     1218        fromPage = self._currentPage
     1219        if fromPage is not None:
     1220            page = self._pages[fromPage]
     1221            if finalize and not page._finalized:
     1222                page.finalize()
     1223                page._finalized = True
     1224            self.remove(page)
    10881225
    10891226        self._currentPage = index
    1090         self.add(self._pages[index])
    1091         self._pages[index].activate()
     1227        page = self._pages[index]
     1228        self.add(page)
     1229        if page._fromPage is None:
     1230            page._fromPage = fromPage
     1231            page.activate()
     1232        self.grabDefault()
    10921233        self.show_all()
    10931234
    1094     def nextPage(self):
     1235    def nextPage(self, finalize = True):
    10951236        """Go to the next page."""
    1096         self.jumpPage(1)
    1097 
    1098     def jumpPage(self, count):
     1237        self.jumpPage(1, finalize)
     1238
     1239    def jumpPage(self, count, finalize = True):
    10991240        """Go to the page which is 'count' pages after the current one."""
    1100         self.setCurrentPage(self._currentPage + count)
    1101         self.grabDefault()
     1241        self.setCurrentPage(self._currentPage + count, finalize = finalize)
    11021242
    11031243    def grabDefault(self):
  • src/mlx/gui/gui.py

    r59 r70  
    394394            self._flight.zfw = self._zfwSpinButton.get_value_as_int()
    395395           
    396             self._simulator.startMonitoring()
    397             self._monitoring = True
     396            self.startMonitoring()
    398397        else:
    399398            self.resetFlightStatus()
     
    408407
    409408        self._statusbar.updateConnection(self._connecting, self._connected)
     409
     410    def startMonitoring(self):
     411        """Start monitoring."""
     412        self._simulator.startMonitoring()
     413        self._monitoring = True
     414
     415    def stopMonitoring(self):
     416        """Stop monitoring."""
     417        self._simulator.stoptMonitoring()
     418        self._monitoring = False
    410419
    411420    def _buildSetupFrame(self):
  • src/mlx/gui/statusbar.py

    r59 r70  
    6262
    6363        self._ratingLabel = gtk.Label()
    64         self._ratingLabel.set_width_chars(10)
     64        self._ratingLabel.set_width_chars(12)
    6565        self._ratingLabel.set_tooltip_text("The flight rating")
    6666        self._ratingLabel.set_alignment(0.0, 0.5)
     
    8585        """Update the busy state."""
    8686        self._busyLabel.set_text("" if message is None else message)
    87    
     87
    8888    def _drawConnState(self, connStateArea, eventOrContext):
    8989        """Draw the connection state."""       
Note: See TracChangeset for help on using the changeset viewer.