[29] | 1 | # Implementation of the status icon
|
---|
| 2 |
|
---|
| 3 | #-------------------------------------------------------------------------------
|
---|
| 4 |
|
---|
| 5 | from common import *
|
---|
| 6 |
|
---|
[31] | 7 | import mlx.const as const
|
---|
| 8 |
|
---|
[29] | 9 | #-------------------------------------------------------------------------------
|
---|
| 10 |
|
---|
[32] | 11 | class StatusIcon(FlightStatusHandler):
|
---|
[29] | 12 | """The class handling the status icon."""
|
---|
| 13 | def __init__(self, iconDirectory, gui):
|
---|
| 14 | """Construct the status icon."""
|
---|
[32] | 15 | super(StatusIcon, self).__init__()
|
---|
| 16 |
|
---|
[29] | 17 | self._gui = gui
|
---|
[31] | 18 |
|
---|
[29] | 19 | menu = gtk.Menu()
|
---|
| 20 |
|
---|
[31] | 21 | if appIndicator:
|
---|
| 22 | self._stageMenuItem = gtk.MenuItem()
|
---|
| 23 | self._stageMenuItem.show()
|
---|
| 24 | menu.append(self._stageMenuItem)
|
---|
| 25 |
|
---|
| 26 | self._ratingMenuItem = gtk.MenuItem()
|
---|
| 27 | self._ratingMenuItem.show()
|
---|
| 28 | menu.append(self._ratingMenuItem)
|
---|
| 29 |
|
---|
| 30 | separator = gtk.SeparatorMenuItem()
|
---|
| 31 | separator.show()
|
---|
| 32 | menu.append(separator)
|
---|
| 33 |
|
---|
[29] | 34 | self._showHideMenuItem = gtk.CheckMenuItem()
|
---|
| 35 | self._showHideMenuItem.set_label("Show main window")
|
---|
| 36 | self._showHideMenuItem.set_active(True)
|
---|
| 37 | self._showHideMenuItem.connect("toggled", self._showHideToggled)
|
---|
| 38 | self._showHideMenuItem.show()
|
---|
| 39 | menu.append(self._showHideMenuItem)
|
---|
| 40 |
|
---|
| 41 | menu.show()
|
---|
| 42 |
|
---|
| 43 | iconFile = os.path.join(iconDirectory, "logo.ico")
|
---|
| 44 |
|
---|
| 45 | if appIndicator:
|
---|
| 46 | if pygobject:
|
---|
| 47 | indicator = appindicator.Indicator.new ("mava-logger-x", iconFile,
|
---|
| 48 | appindicator.IndicatorCategory.APPLICATION_STATUS)
|
---|
| 49 | indicator.set_status (appindicator.IndicatorStatus.ACTIVE)
|
---|
| 50 | else:
|
---|
| 51 | indicator = appindicator.Indicator ("mava-logger-x", iconFile,
|
---|
| 52 | appindicator.CATEGORY_APPLICATION_STATUS)
|
---|
| 53 | indicator.set_status (appindicator.STATUS_ACTIVE)
|
---|
| 54 |
|
---|
| 55 | indicator.set_menu(menu)
|
---|
| 56 | self._indicator = indicator
|
---|
| 57 | else:
|
---|
| 58 | def popup_menu(status, button, time):
|
---|
| 59 | menu.popup(None, None, gtk.status_icon_position_menu,
|
---|
| 60 | button, time, status)
|
---|
| 61 |
|
---|
| 62 | statusIcon = gtk.StatusIcon()
|
---|
| 63 | statusIcon.set_from_file(iconFile)
|
---|
| 64 | statusIcon.set_visible(True)
|
---|
| 65 | statusIcon.connect('popup-menu', popup_menu)
|
---|
| 66 | statusIcon.connect('activate',
|
---|
| 67 | lambda status: self._gui.toggleMainWindow())
|
---|
| 68 | self._statusIcon = statusIcon
|
---|
[32] | 69 |
|
---|
| 70 | self._updateFlightStatus()
|
---|
[29] | 71 |
|
---|
| 72 | def mainWindowHidden(self):
|
---|
| 73 | """Called when the main window is hidden."""
|
---|
| 74 | self._showHideMenuItem.set_active(False)
|
---|
| 75 |
|
---|
| 76 | def mainWindowShown(self):
|
---|
| 77 | """Called when the main window is shown."""
|
---|
| 78 | self._showHideMenuItem.set_active(True)
|
---|
[31] | 79 |
|
---|
[29] | 80 | def _showHideToggled(self, menuitem):
|
---|
| 81 | """Called when the show/hide menu item is toggled."""
|
---|
| 82 | if self._showHideMenuItem.get_active():
|
---|
| 83 | self._gui.showMainWindow()
|
---|
| 84 | else:
|
---|
| 85 | self._gui.hideMainWindow()
|
---|
[31] | 86 |
|
---|
[32] | 87 | def _updateFlightStatus(self):
|
---|
| 88 | """Update the flight status."""
|
---|
| 89 | stage = "-" if self._stage is None else const.stage2string(self._stage)
|
---|
| 90 |
|
---|
[31] | 91 | if self._noGoReason is None:
|
---|
| 92 | rating = "%.0f%%" % (self._rating,)
|
---|
| 93 | else:
|
---|
[32] | 94 | rating = self._noGoReason
|
---|
[31] | 95 |
|
---|
[32] | 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)
|
---|