Changeset 383:fcb9932b14ee for src/mlx


Ignore:
Timestamp:
12/21/12 15:44:59 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Added the new Cruise page where the cruise level can be modified (#160)

Location:
src/mlx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/flight.py

    r365 r383  
    2424    It is also the hub for the other main objects participating in the handling of
    2525    the flight."""
     26    @staticmethod
     27    def canLogCruiseAltitude(stage):
     28        """Determine if the cruise altitude can be logged in the given
     29        stage."""
     30        return stage in [const.STAGE_CRUISE, const.STAGE_DESCENT,
     31                         const.STAGE_LANDING]
     32
    2633    def __init__(self, logger, gui):
    2734        """Construct the flight."""
     
    414421    def cruiseLevelChanged(self):
    415422        """Called when the cruise level hass changed."""
    416         if self._stage in [const.STAGE_CRUISE, const.STAGE_DESCENT,
    417                            const.STAGE_LANDING]:
     423        if self.canLogCruiseAltitude(self._stage):
    418424            message = "Cruise altitude modified to %d feet" % \
    419                       (self.cruiseAltitude,)
     425                      (self._gui.loggableCruiseAltitude,)
    420426            self.logger.message(self.aircraft.timestamp, message)
     427            return True
     428        else:
     429            return False
    421430
    422431    def _updateFlownDistance(self, currentState):
  • src/mlx/gui/flight.py

    r349 r383  
    55import mlx.fs as fs
    66import mlx.acft as acft
     7from mlx.flight import Flight
    78from mlx.checks import PayloadChecker
    89import mlx.util as util
     
    16551656        self._cruiseLevel.connect("value-changed", self._cruiseLevelChanged)
    16561657        label.set_mnemonic_widget(self._cruiseLevel)
    1657         self._filedCruiseLevel = 240
    16581658
    16591659        levelBox.pack_start(self._cruiseLevel, False, False, 8)
     
    17061706    def filedCruiseLevel(self):
    17071707        """Get the filed cruise level."""
    1708         return self._filedCruiseLevel
    1709 
    1710     @property
    1711     def cruiseLevel(self):
    1712         """Get the cruise level."""
    17131708        return self._cruiseLevel.get_value_as_int()
    17141709
     
    17211716        """Setup the route from the booked flight."""
    17221717        self._cruiseLevel.set_value(240)
    1723         self._filedCruiseLevel = 240
    17241718        self._route.get_buffer().set_text(self._wizard._bookedFlight.route)
    17251719        self._updateForwardButton()
     
    17391733        """Called when the cruise level has changed."""
    17401734        self._updateForwardButton()
    1741         self._wizard.cruiseLevelChanged()
    17421735
    17431736    def _routeChanged(self, textBuffer):
     
    17711764        else:
    17721765            bookedFlight = self._wizard._bookedFlight
    1773             self._filedCruiseLevel = self.cruiseLevel
    17741766            self._wizard.gui.beginBusy(xstr("route_down_notams"))
    17751767            self._wizard.gui.webHandler.getNOTAMs(self._notamsCallback,
     
    22122204#-----------------------------------------------------------------------------
    22132205
     2206class CruisePage(Page):
     2207    """The page containing the flight level that might change during flight."""
     2208    def __init__(self, wizard):
     2209        """Construct the page."""
     2210        super(CruisePage, self).__init__(wizard, xstr("cruise_title"),
     2211                                         xstr("cruise_help"))
     2212
     2213        self._loggable = False
     2214        self._loggedCruiseLevel = 240
     2215        self._activated = False
     2216
     2217        alignment = gtk.Alignment(xalign = 0.5, yalign = 0.0,
     2218                                  xscale = 0.0, yscale = 1.0)
     2219
     2220        mainBox = gtk.VBox()
     2221        alignment.add(mainBox)
     2222        self.setMainWidget(alignment)
     2223
     2224        alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
     2225                                  xscale = 0.0, yscale = 0.0)
     2226        mainBox.pack_start(alignment, False, False, 16)
     2227
     2228        levelBox = gtk.HBox()
     2229
     2230        label = gtk.Label(xstr("route_level"))
     2231        label.set_use_underline(True)
     2232        levelBox.pack_start(label, True, True, 0)
     2233
     2234        self._cruiseLevel = gtk.SpinButton()
     2235        self._cruiseLevel.set_increments(step = 10, page = 100)
     2236        self._cruiseLevel.set_range(min = 50, max = 500)
     2237        self._cruiseLevel.set_tooltip_text(xstr("cruise_route_level_tooltip"))
     2238        self._cruiseLevel.set_numeric(True)
     2239        self._cruiseLevel.connect("value-changed", self._cruiseLevelChanged)
     2240        label.set_mnemonic_widget(self._cruiseLevel)
     2241
     2242        levelBox.pack_start(self._cruiseLevel, False, False, 8)
     2243
     2244        self._updateButton = gtk.Button(xstr("cruise_route_level_update"));
     2245        self._updateButton.set_use_underline(True)
     2246        self._updateButton.set_tooltip_text(xstr("cruise_route_level_update_tooltip"))
     2247        self._updateButton.connect("clicked", self._updateButtonClicked)
     2248
     2249        levelBox.pack_start(self._updateButton, False, False, 16)
     2250
     2251        mainBox.pack_start(levelBox, False, False, 0)
     2252
     2253        alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
     2254                                  xscale = 0.0, yscale = 1.0)
     2255        mainBox.pack_start(alignment, True, True, 0)
     2256
     2257        self.addCancelFlightButton()
     2258
     2259        self._backButton = self.addPreviousButton(clicked = self._backClicked)
     2260        self._button = self.addNextButton(clicked = self._forwardClicked)
     2261
     2262    @property
     2263    def activated(self):
     2264        """Determine if the page is already activated or not."""
     2265        return self._activated
     2266
     2267    @property
     2268    def cruiseLevel(self):
     2269        """Get the cruise level."""
     2270        return self._loggedCruiseLevel
     2271
     2272    @property
     2273    def loggableCruiseLevel(self):
     2274        """Get the cruise level which should be logged."""
     2275        return self._cruiseLevel.get_value_as_int()
     2276
     2277    def setLoggable(self, loggable):
     2278        """Set whether the cruise altitude can be logged."""
     2279        self._loggable = loggable
     2280        self._updateButtons()
     2281
     2282    def activate(self):
     2283        """Setup the route from the booked flight."""
     2284        self._loggedCruiseLevel = self._wizard.filedCruiseLevel
     2285        self._cruiseLevel.set_value(self._loggedCruiseLevel)
     2286        self._activated = True
     2287
     2288    def reset(self):
     2289        """Reset the page."""
     2290        self._loggable = False
     2291        self._activated = False
     2292        super(CruisePage, self).reset()
     2293
     2294    def _updateButtons(self):
     2295        """Update the sensitivity of the buttons."""
     2296        self._updateButton.set_sensitive(self._loggable and
     2297                                         self.loggableCruiseLevel!=
     2298                                         self._loggedCruiseLevel)
     2299
     2300    def _cruiseLevelChanged(self, spinButton):
     2301        """Called when the cruise level has changed."""
     2302        self._updateButtons()
     2303
     2304    def _updateButtonClicked(self, button):
     2305        """Called when the update button is clicked."""
     2306        if self._wizard.cruiseLevelChanged():
     2307            self._loggedCruiseLevel = self.loggableCruiseLevel
     2308            self._updateButtons()
     2309
     2310    def _backClicked(self, button):
     2311        """Called when the Back button is pressed."""
     2312        self.goBack()
     2313
     2314    def _forwardClicked(self, button):
     2315        """Called when the Forward button is clicked."""
     2316        self._wizard.nextPage()
     2317
     2318#-----------------------------------------------------------------------------
     2319
    22142320class LandingPage(Page):
    22152321    """Page for entering landing data."""
     
    28482954        self._takeoffPage = TakeoffPage(self)
    28492955        self._pages.append(self._takeoffPage)
     2956        self._cruisePage = CruisePage(self)
     2957        self._pages.append(self._cruisePage)
    28502958        self._landingPage = LandingPage(self)
    28512959        self._pages.append(self._landingPage)
     
    29473055
    29483056    @property
     3057    def filedCruiseLevel(self):
     3058        """Get the filed cruise level."""
     3059        return self._routePage.filedCruiseLevel
     3060
     3061    @property
    29493062    def filedCruiseAltitude(self):
    29503063        """Get the filed cruise altitude."""
     
    29543067    def cruiseAltitude(self):
    29553068        """Get the cruise altitude."""
    2956         return self._routePage.cruiseLevel * 100
     3069        level = self._cruisePage.cruiseLevel if self._cruisePage.activated \
     3070                else self._routePage.filedCruiseLevel
     3071        return level * 100
     3072
     3073    @property
     3074    def loggableCruiseAltitude(self):
     3075        """Get the cruise altitude that can be logged."""
     3076        if self._cruisePage.activated:
     3077            return self._cruisePage.loggableCruiseLevel * 100
     3078        else:
     3079            return 0
    29573080
    29583081    @property
     
    30593182    def setStage(self, stage):
    30603183        """Set the flight stage to the given one."""
     3184        if stage!=const.STAGE_END:
     3185            self._cruisePage.setLoggable(Flight.canLogCruiseAltitude(stage))
     3186
    30613187        if stage==const.STAGE_TAKEOFF:
    30623188            self._takeoffPage.allowForward()
     
    31213247    def cruiseLevelChanged(self):
    31223248        """Called when the cruise level is changed."""
    3123         self.gui.cruiseLevelChanged()
     3249        return self.gui.cruiseLevelChanged()
    31243250
    31253251    def _loginResultCallback(self, returned, result):
  • src/mlx/gui/gui.py

    r349 r383  
    263263
    264264    @property
     265    def loggableCruiseAltitude(self):
     266        """Get the cruise altitude that can be logged."""
     267        return self._wizard.loggableCruiseAltitude
     268
     269    @property
    265270    def route(self):
    266271        """Get the flight route."""
     
    890895        """Called when the cruise level is changed in the flight wizard."""
    891896        if self._flight is not None:
    892             self._flight.cruiseLevelChanged()
     897            return self._flight.cruiseLevelChanged()
     898        else:
     899            return False
    893900
    894901    def _buildMenuBar(self, accelGroup):
Note: See TracChangeset for help on using the changeset viewer.