Changeset 32:46c1a12f72d1 for src/mlx
- Timestamp:
- 02/25/12 15:49:27 (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx/gui
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/gui/common.py
r29 r32 28 28 import cairo 29 29 30 #------------------------------------------------------------------------------ 31 32 class 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 2 2 3 3 from statusicon import StatusIcon 4 from statusbar import Statusbar 4 5 from mlx.gui.common import * 5 6 … … 10 11 import mlx.acft as acft 11 12 12 import math13 13 import time 14 14 … … 64 64 logFrame.set_border_width(8) 65 65 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 67 72 win.show_all() 68 73 … … 82 87 """Called when we have connected to the simulator.""" 83 88 self._connected = True 84 self._updateConnState()85 89 self._logger.untimedMessage("Connected to the simulator %s" % (descriptor,)) 90 gobject.idle_add(self._statusbar.updateConnection, 91 self._connecting, self._connected) 86 92 87 93 def disconnected(self): 88 94 """Called when we have disconnected from the simulator.""" 89 95 self._connected = False 90 self._updateConnState()91 96 self._logger.untimedMessage("Disconnected from the simulator") 97 gobject.idle_add(self._statusbar.updateConnection, 98 self._connecting, self._connected) 92 99 93 100 def write(self, msg): … … 101 108 def resetFlightStatus(self): 102 109 """Reset the status of the flight.""" 110 self._statusbar.resetFlightStatus() 103 111 self._statusIcon.resetFlightStatus() 104 112 … … 109 117 def _setStage(self, stage): 110 118 """Set the stage of the flight.""" 119 self._statusbar.setStage(stage) 111 120 self._statusIcon.setStage(stage) 112 121 … … 117 126 def _setRating(self, rating): 118 127 """Set the rating of the flight.""" 128 self._statusbar.setRating(rating) 119 129 self._statusIcon.setRating(rating) 120 130 … … 125 135 def _setNoGo(self, reason): 126 136 """Set the rating of the flight.""" 137 self._statusbar.setNoGo(reason) 127 138 self._statusIcon.setNoGo(reason) 128 139 … … 156 167 self.showMainWindow() 157 168 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.width172 height = connStateArea.get_allocated_height() if pygobject \173 else connStateArea.allocation.height174 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 182 169 def _connectToggled(self, button): 183 170 """Callback for the connection button.""" … … 211 198 self._flight = None 212 199 213 self._ updateConnState()200 self._statusbar.updateConnection(self._connecting, self._connected) 214 201 215 202 def _buildSetupFrame(self): … … 299 286 300 287 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)320 288 321 289 setupBox.pack_start(gtk.VSeparator(), False, False, 8) -
src/mlx/gui/statusicon.py
r31 r32 9 9 #------------------------------------------------------------------------------- 10 10 11 class StatusIcon( object):11 class StatusIcon(FlightStatusHandler): 12 12 """The class handling the status icon.""" 13 13 def __init__(self, iconDirectory, gui): 14 14 """Construct the status icon.""" 15 super(StatusIcon, self).__init__() 16 15 17 self._gui = gui 16 18 17 self._stage = None18 self._rating = 10019 self._noGoReason = None20 21 19 menu = gtk.Menu() 22 20 23 21 if appIndicator: 24 22 self._stageMenuItem = gtk.MenuItem() 25 self._stageMenuItem.set_label("Stage: -")26 23 self._stageMenuItem.show() 27 24 menu.append(self._stageMenuItem) 28 25 29 26 self._ratingMenuItem = gtk.MenuItem() 30 self._ratingMenuItem.set_label("Rating: 100%")31 27 self._ratingMenuItem.show() 32 28 menu.append(self._ratingMenuItem) … … 71 67 lambda status: self._gui.toggleMainWindow()) 72 68 self._statusIcon = statusIcon 73 self._setTooltip() 69 70 self._updateFlightStatus() 74 71 75 72 def mainWindowHidden(self): … … 81 78 self._showHideMenuItem.set_active(True) 82 79 83 def resetFlightStatus(self):84 """Reset the status of the flight."""85 if not appIndicator:86 self._statusIcon.set_blinking(False)87 self._noGoReason = None88 self.setStage(None)89 self.setRating(100)90 91 def setStage(self, stage):92 """Set the stage of the flight."""93 self._stage = stage94 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 return105 self._rating = rating106 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 return117 118 self._noGoReason = reason119 if appIndicator:120 self._ratingMenuItem.set_label("Rating: %s" % (reason,))121 else:122 self._setTooltip()123 self._statusIcon.set_blinking(True)124 125 80 def _showHideToggled(self, menuitem): 126 81 """Called when the show/hide menu item is toggled.""" … … 130 85 self._gui.hideMainWindow() 131 86 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 134 91 if self._noGoReason is None: 135 92 rating = "%.0f%%" % (self._rating,) 136 93 else: 137 rating = '<span foreground="red">' + self._noGoReason + '</span>'94 rating = self._noGoReason 138 95 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.