Changeset 31:c9ed7a60bf3b


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

Various information about the flight is displayed in the status icon's tooltip or menu

Location:
src/mlx
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/flight.py

    r30 r31  
    2929        self._gui = gui
    3030
     31        gui.resetFlightStatus()
     32
    3133        self.cruiseAltitude = None
    3234        self.flareTimeFromFS = False
     
    5759            self._stage = stage
    5860            self.logger.stage(timestamp, stage)
     61            self._gui.setStage(stage)
    5962            if stage==const.STAGE_END:
    6063                with self._endCondition:
     
    7275        the report comes from."""
    7376        self.logger.fault(faultID, timestamp, what, score)
     77        self._gui.setRating(self.logger.getRating())
    7478
    7579    def handleNoGo(self, faultID, timestamp, what, shortReason):
    7680        """Handle a No-Go fault."""
    7781        self.logger.noGo(faultID, timestamp, what)
     82        self._gui.setNoGo(shortReason)
    7883
    7984    def flareStarted(self, flareStart, flareStartFS):
  • src/mlx/gui/gui.py

    r30 r31  
    9999        gobject.idle_add(self._setData, state)
    100100
     101    def resetFlightStatus(self):
     102        """Reset the status of the flight."""
     103        self._statusIcon.resetFlightStatus()
     104
     105    def setStage(self, stage):
     106        """Set the stage of the flight."""
     107        gobject.idle_add(self._setStage, stage)
     108
     109    def _setStage(self, stage):
     110        """Set the stage of the flight."""
     111        self._statusIcon.setStage(stage)
     112
     113    def setRating(self, rating):
     114        """Set the rating of the flight."""
     115        gobject.idle_add(self._setRating, rating)
     116
     117    def _setRating(self, rating):
     118        """Set the rating of the flight."""
     119        self._statusIcon.setRating(rating)
     120
     121    def setNoGo(self, reason):
     122        """Set the rating of the flight to No-Go with the given reason."""
     123        gobject.idle_add(self._setNoGo, reason)
     124
     125    def _setNoGo(self, reason):
     126        """Set the rating of the flight."""
     127        self._statusIcon.setNoGo(reason)
     128
    101129    def _handleMainWindowState(self, window, event):
    102130        """Hande a change in the state of the window"""
     
    177205            self._simulator.startMonitoring()
    178206        else:
     207            self.resetFlightStatus()
    179208            self._connecting = False
    180209            self._simulator.stopMonitoring()
  • src/mlx/gui/statusicon.py

    r29 r31  
    44
    55from common import *
     6
     7import mlx.const as const
    68
    79#-------------------------------------------------------------------------------
     
    1214        """Construct the status icon."""
    1315        self._gui = gui
     16
     17        self._stage = None
     18        self._rating = 100
     19        self._noGoReason = None
    1420       
    1521        menu = gtk.Menu()
     22
     23        if appIndicator:
     24            self._stageMenuItem = gtk.MenuItem()
     25            self._stageMenuItem.set_label("Stage: -")
     26            self._stageMenuItem.show()
     27            menu.append(self._stageMenuItem)
     28
     29            self._ratingMenuItem = gtk.MenuItem()
     30            self._ratingMenuItem.set_label("Rating: 100%")
     31            self._ratingMenuItem.show()
     32            menu.append(self._ratingMenuItem)
     33
     34            separator = gtk.SeparatorMenuItem()
     35            separator.show()
     36            menu.append(separator)
    1637
    1738        self._showHideMenuItem = gtk.CheckMenuItem() 
     
    3859            indicator.set_menu(menu)
    3960            self._indicator = indicator
    40             self._usingIndicator = True
    4161        else:
    4262            def popup_menu(status, button, time):
     
    4666            statusIcon = gtk.StatusIcon()
    4767            statusIcon.set_from_file(iconFile)
    48             statusIcon.set_tooltip_markup("MAVA Logger X")
    4968            statusIcon.set_visible(True)
    5069            statusIcon.connect('popup-menu', popup_menu)
     
    5271                               lambda status: self._gui.toggleMainWindow())
    5372            self._statusIcon = statusIcon
    54             self._usingIndicator = False
     73            self._setTooltip()
    5574
    5675    def mainWindowHidden(self):
     
    6180        """Called when the main window is shown."""
    6281        self._showHideMenuItem.set_active(True)
     82
     83    def resetFlightStatus(self):
     84        """Reset the status of the flight."""
     85        if not appIndicator:
     86            self._statusIcon.set_blinking(False)
     87        self._noGoReason = None
     88        self.setStage(None)
     89        self.setRating(100)
    6390       
     91    def setStage(self, stage):
     92        """Set the stage of the flight."""
     93        self._stage = stage
     94        if appIndicator:
     95            label = "Stage: %s" % ("-" if self._stage is None \
     96                                   else (const.stage2string(stage),))
     97            self._stageMenuItem.set_label(label)
     98        else:
     99            self._setTooltip()
     100
     101    def setRating(self, rating):
     102        """Set the rating to the given value."""
     103        if rating==self._rating:
     104            return
     105        self._rating = rating
     106
     107        if appIndicator:
     108            if self._noGoReason is None:
     109                self._ratingMenuItem.set_label("Rating: %.0f%%" % (rating,))
     110            else:
     111                self._setTooltip()
     112
     113    def setNoGo(self, reason):
     114        """Set a No-Go condition with the given reason."""
     115        if self._noGoReason is not None:
     116            return
     117
     118        self._noGoReason = reason
     119        if appIndicator:
     120            self._ratingMenuItem.set_label("Rating: %s" % (reason,))
     121        else:
     122            self._setTooltip()
     123            self._statusIcon.set_blinking(True)
     124
    64125    def _showHideToggled(self, menuitem):
    65126        """Called when the show/hide menu item is toggled."""
     
    68129        else:
    69130            self._gui.hideMainWindow()
     131
     132    def _setTooltip(self):
     133        """Set the tooltip of the status icon."""
     134        if self._noGoReason is None:
     135            rating = "%.0f%%" % (self._rating,)
     136        else:
     137            rating = '<span foreground="red">' + self._noGoReason + '</span>'
     138
     139        markup = "MAVA Logger X %s\n\nStage: %s\nRating: %s" %\
     140                 (const.VERSION, ("-" if self._stage is None else
     141                                  const.stage2string(self._stage)),
     142                  rating)
     143       
     144        self._statusIcon.set_tooltip_markup(markup)
     145       
  • src/mlx/logger.py

    r30 r31  
    6565        self.message(timestamp, "--- %s ---" % (s,))
    6666        if stage==const.STAGE_END:
    67             totalScore = 100
    68             for (id, score) in self._faults.iteritems():
    69                 totalScore -= score
    70             self.untimedMessage("Score: %.0f" % (totalScore,))
     67            self.untimedMessage("Rating: %.0f" % (self.getRating(),))
    7168       
    7269    def fault(self, faultID, timestamp, what, score):
     
    9087        self.fault(faultID, timestamp, what, Logger.NO_GO_SCORE)
    9188
    92     def getScore(self):
    93         """Get the score of the flight so far."""
     89    def getRating(self):
     90        """Get the rating of the flight so far."""
    9491        totalScore = 100
    9592        for (id, score) in self._faults.iteritems():
Note: See TracChangeset for help on using the changeset viewer.