Changeset 32:46c1a12f72d1


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

Implemented the status bar.

Location:
src/mlx/gui
Files:
1 added
3 edited

Legend:

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

    r29 r32  
    2828import cairo
    2929
     30#------------------------------------------------------------------------------
     31
     32class FlightStatusHandler(object):
     33    """Base class for objects that handle the flight status in some way."""
     34    def __init__(self):
     35        self._stage = None
     36        self._rating = 100
     37        self._noGoReason = None
     38
     39    def resetFlightStatus(self):
     40        """Reset the flight status."""
     41        self._stage = None
     42        self._rating = 100
     43        self._noGoReason = None
     44        self._updateFlightStatus()
     45       
     46    def setStage(self, stage):
     47        """Set the stage of the flight."""
     48        if stage!=self._stage:
     49            self._stage = stage
     50            self._updateFlightStatus()
     51
     52    def setRating(self, rating):
     53        """Set the rating to the given value."""
     54        if rating!=self._rating:
     55            self._rating = rating
     56            if self._noGoReason is None:
     57                self._updateFlightStatus()
     58
     59    def setNoGo(self, reason):
     60        """Set a No-Go condition with the given reason."""
     61        if self._noGoReason is None:
     62            self._noGoReason = reason
     63            self._updateFlightStatus()
     64
     65#------------------------------------------------------------------------------
  • src/mlx/gui/gui.py

    r31 r32  
    22
    33from statusicon import StatusIcon
     4from statusbar import Statusbar
    45from mlx.gui.common import *
    56
     
    1011import mlx.acft as acft
    1112
    12 import math
    1313import time
    1414
     
    6464        logFrame.set_border_width(8)
    6565        mainVBox.pack_start(logFrame, True, True, 0)
    66        
     66
     67        mainVBox.pack_start(gtk.HSeparator(), False, False, 0)
     68
     69        self._statusbar = Statusbar()
     70        mainVBox.pack_start(self._statusbar, False, False, 0)
     71
    6772        win.show_all()       
    6873
     
    8287        """Called when we have connected to the simulator."""
    8388        self._connected = True
    84         self._updateConnState()
    8589        self._logger.untimedMessage("Connected to the simulator %s" % (descriptor,))
     90        gobject.idle_add(self._statusbar.updateConnection,
     91                         self._connecting, self._connected)
    8692       
    8793    def disconnected(self):
    8894        """Called when we have disconnected from the simulator."""
    8995        self._connected = False
    90         self._updateConnState()
    9196        self._logger.untimedMessage("Disconnected from the simulator")
     97        gobject.idle_add(self._statusbar.updateConnection,
     98                         self._connecting, self._connected)
    9299
    93100    def write(self, msg):
     
    101108    def resetFlightStatus(self):
    102109        """Reset the status of the flight."""
     110        self._statusbar.resetFlightStatus()
    103111        self._statusIcon.resetFlightStatus()
    104112
     
    109117    def _setStage(self, stage):
    110118        """Set the stage of the flight."""
     119        self._statusbar.setStage(stage)
    111120        self._statusIcon.setStage(stage)
    112121
     
    117126    def _setRating(self, rating):
    118127        """Set the rating of the flight."""
     128        self._statusbar.setRating(rating)
    119129        self._statusIcon.setRating(rating)
    120130
     
    125135    def _setNoGo(self, reason):
    126136        """Set the rating of the flight."""
     137        self._statusbar.setNoGo(reason)
    127138        self._statusIcon.setNoGo(reason)
    128139
     
    156167            self.showMainWindow()
    157168           
    158     def _drawConnState(self, connStateArea, eventOrContext):
    159         """Draw the connection state."""
    160         context = eventOrContext if pygobject else connStateArea.window.cairo_create()
    161 
    162         if self._connecting:
    163             if self._connected:
    164                 context.set_source_rgb(0.0, 1.0, 0.0)
    165             else:
    166                 context.set_source_rgb(1.0, 0.0, 0.0)
    167         else:
    168             context.set_source_rgb(0.75, 0.75, 0.75)
    169 
    170         width = connStateArea.get_allocated_width() if pygobject \
    171                 else connStateArea.allocation.width
    172         height = connStateArea.get_allocated_height() if pygobject \
    173                  else connStateArea.allocation.height
    174         context.arc(width/2, height/2, 8, 0, 2*math.pi)
    175 
    176         context.fill()
    177 
    178     def _updateConnState(self):
    179         """Initiate the updating of the connection state icon."""
    180         self._connStateArea.queue_draw()
    181 
    182169    def _connectToggled(self, button):
    183170        """Callback for the connection button."""
     
    211198            self._flight = None
    212199
    213         self._updateConnState()
     200        self._statusbar.updateConnection(self._connecting, self._connected)
    214201
    215202    def _buildSetupFrame(self):
     
    299286
    300287        setupBox.pack_start(self._connectButton, False, False, 0)
    301 
    302         setupBox.pack_start(gtk.VSeparator(), False, False, 8)   
    303 
    304         self._connStateArea = gtk.DrawingArea()
    305         self._connStateArea.set_size_request(16, 16)
    306         self._connStateArea.set_tooltip_markup('The state of the connection.\n'
    307                                                '<span foreground="grey">Grey</span> means idle.\n'
    308                                                '<span foreground="red">Red</span> means trying to connect.\n'
    309                                                '<span foreground="green">Green</span> means connected.')
    310 
    311         if pygobject:
    312             self._connStateArea.connect("draw", self._drawConnState)
    313         else:
    314             self._connStateArea.connect("expose_event", self._drawConnState)
    315 
    316         alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5)
    317         alignment.add(self._connStateArea)
    318 
    319         setupBox.pack_start(alignment, False, False, 8)
    320288
    321289        setupBox.pack_start(gtk.VSeparator(), False, False, 8)   
  • src/mlx/gui/statusicon.py

    r31 r32  
    99#-------------------------------------------------------------------------------
    1010
    11 class StatusIcon(object):
     11class StatusIcon(FlightStatusHandler):
    1212    """The class handling the status icon."""
    1313    def __init__(self, iconDirectory, gui):
    1414        """Construct the status icon."""
     15        super(StatusIcon, self).__init__()
     16
    1517        self._gui = gui
    1618
    17         self._stage = None
    18         self._rating = 100
    19         self._noGoReason = None
    20        
    2119        menu = gtk.Menu()
    2220
    2321        if appIndicator:
    2422            self._stageMenuItem = gtk.MenuItem()
    25             self._stageMenuItem.set_label("Stage: -")
    2623            self._stageMenuItem.show()
    2724            menu.append(self._stageMenuItem)
    2825
    2926            self._ratingMenuItem = gtk.MenuItem()
    30             self._ratingMenuItem.set_label("Rating: 100%")
    3127            self._ratingMenuItem.show()
    3228            menu.append(self._ratingMenuItem)
     
    7167                               lambda status: self._gui.toggleMainWindow())
    7268            self._statusIcon = statusIcon
    73             self._setTooltip()
     69
     70        self._updateFlightStatus()
    7471
    7572    def mainWindowHidden(self):
     
    8178        self._showHideMenuItem.set_active(True)
    8279
    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)
    90        
    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 
    12580    def _showHideToggled(self, menuitem):
    12681        """Called when the show/hide menu item is toggled."""
     
    13085            self._gui.hideMainWindow()
    13186
    132     def _setTooltip(self):
    133         """Set the tooltip of the status icon."""
     87    def _updateFlightStatus(self):
     88        """Update the flight status."""
     89        stage = "-" if self._stage is None else const.stage2string(self._stage)
     90       
    13491        if self._noGoReason is None:
    13592            rating = "%.0f%%" % (self._rating,)
    13693        else:
    137             rating = '<span foreground="red">' + self._noGoReason + '</span>'
     94            rating = self._noGoReason
    13895
    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        
     96        if appIndicator:
     97            self._stageMenuItem.set_label("Stage: %s" % (stage,))
     98            self._ratingMenuItem.set_label("Rating: %s" % (rating,))
     99        else:
     100            if self._noGoReason is not None:
     101                rating = '<span foreground="red">' + rating + '</span>'
     102            markup = "MAVA Logger X %s\n\nStage: %s\nRating: %s" %\
     103                     (const.VERSION, stage, rating)
     104            self._statusIcon.set_tooltip_markup(markup)
Note: See TracChangeset for help on using the changeset viewer.