source: src/mlx/gui/statusicon.py@ 544:781b62c20c0d

Last change on this file since 544:781b62c20c0d was 544:781b62c20c0d, checked in by István Váradi <ivaradi@…>, 11 years ago

The empty menu items are created with a non-empty default label so that they appear

File size: 6.7 KB
RevLine 
[29]1
2from common import *
3
[31]4import mlx.const as const
[114]5from mlx.i18n import xstr
[31]6
[29]7#-------------------------------------------------------------------------------
8
[300]9## @package mlx.gui.statusicon
10#
11# The status icon.
12#
13# This module implements that status icon displayed on the Windows or the GNOME
14# taskbar, or whatever the place for status icons is called in the used
15# environment. It works with both the more modern appindicator interface
16# (mainly found on Ubuntu), if that is available, or with the older status icon
17# support in Gtk (which is used on Windows as well). In this latter case, the
18# icon has a tooltip with the flight stage and rating information, while these
19# data are placed into the menu in case of appindicator.
20
21#-------------------------------------------------------------------------------
22
[32]23class StatusIcon(FlightStatusHandler):
[29]24 """The class handling the status icon."""
25 def __init__(self, iconDirectory, gui):
26 """Construct the status icon."""
[32]27 super(StatusIcon, self).__init__()
28
[29]29 self._gui = gui
[35]30 self._selfToggling = False
[31]31
[29]32 menu = gtk.Menu()
33
[31]34 if appIndicator:
[544]35 self._stageMenuItem = gtk.MenuItem("-")
[31]36 self._stageMenuItem.show()
37 menu.append(self._stageMenuItem)
38
[544]39 self._ratingMenuItem = gtk.MenuItem("-")
[31]40 self._ratingMenuItem.show()
41 menu.append(self._ratingMenuItem)
42
43 separator = gtk.SeparatorMenuItem()
44 separator.show()
45 menu.append(separator)
46
[544]47 self._showHideMenuItem = gtk.CheckMenuItem()
48 self._showHideMenuItem.set_label(xstr("statusicon_showmain"))
[29]49 self._showHideMenuItem.set_active(True)
50 self._showHideMenuItem.connect("toggled", self._showHideToggled)
[544]51 self._showHideMenuItem.show()
52 menu.append(self._showHideMenuItem)
[29]53
[544]54 self._showMonitorMenuItem = gtk.CheckMenuItem()
55 self._showMonitorMenuItem.set_label(xstr("statusicon_showmonitor"))
[77]56 self._showMonitorMenuItem.set_active(False)
57 self._showMonitorMenuItem.connect("toggled", self._showMonitorToggled)
[544]58 self._showMonitorMenuItem.show()
59 menu.append(self._showMonitorMenuItem)
[77]60
61 separator = gtk.SeparatorMenuItem()
62 separator.show()
63 menu.append(separator)
64
[544]65 self._quitMenuItem = gtk.MenuItem()
66 self._quitMenuItem.set_label(xstr("statusicon_quit"))
67 self._quitMenuItem.show()
[76]68 self._quitMenuItem.connect("activate", self._gui._quit)
[544]69 menu.append(self._quitMenuItem)
[76]70
[544]71 menu.show()
[29]72
73 iconFile = os.path.join(iconDirectory, "logo.ico")
74
75 if appIndicator:
76 if pygobject:
77 indicator = appindicator.Indicator.new ("mava-logger-x", iconFile,
78 appindicator.IndicatorCategory.APPLICATION_STATUS)
79 indicator.set_status (appindicator.IndicatorStatus.ACTIVE)
80 else:
81 indicator = appindicator.Indicator ("mava-logger-x", iconFile,
82 appindicator.CATEGORY_APPLICATION_STATUS)
83 indicator.set_status (appindicator.STATUS_ACTIVE)
84
85 indicator.set_menu(menu)
86 self._indicator = indicator
87 else:
88 def popup_menu(status, button, time):
89 menu.popup(None, None, gtk.status_icon_position_menu,
90 button, time, status)
91
92 statusIcon = gtk.StatusIcon()
93 statusIcon.set_from_file(iconFile)
94 statusIcon.set_visible(True)
95 statusIcon.connect('popup-menu', popup_menu)
96 statusIcon.connect('activate',
97 lambda status: self._gui.toggleMainWindow())
98 self._statusIcon = statusIcon
[32]99
100 self._updateFlightStatus()
[29]101
102 def mainWindowHidden(self):
103 """Called when the main window is hidden."""
[35]104 if self._showHideMenuItem.get_active():
105 self._selfToggling = True
106 self._showHideMenuItem.set_active(False)
[29]107
108 def mainWindowShown(self):
109 """Called when the main window is shown."""
[35]110 if not self._showHideMenuItem.get_active():
111 self._selfToggling = True
112 self._showHideMenuItem.set_active(True)
[31]113
[77]114 def monitorWindowHidden(self):
115 """Called when the monitor window is hidden."""
116 if self._showMonitorMenuItem.get_active():
117 self._selfToggling = True
118 self._showMonitorMenuItem.set_active(False)
119
120 def monitorWindowShown(self):
121 """Called when the monitor window is shown."""
122 if not self._showMonitorMenuItem.get_active():
123 self._selfToggling = True
124 self._showMonitorMenuItem.set_active(True)
125
[38]126 def destroy(self):
127 """Hide and destroy the status icon."""
128 if appIndicator:
129 if pygobject:
130 self._indicator.set_status(appindicator.IndicatorStatus.PASSIVE)
131 else:
132 self._indicator.set_status(appindicator.STATUS_PASSIVE)
133 else:
134 self._statusIcon.set_visible(False)
[544]135
[29]136 def _showHideToggled(self, menuitem):
137 """Called when the show/hide menu item is toggled."""
[35]138 if self._selfToggling:
139 self._selfToggling = False
140 elif self._showHideMenuItem.get_active():
[29]141 self._gui.showMainWindow()
142 else:
143 self._gui.hideMainWindow()
[31]144
[77]145 def _showMonitorToggled(self, menuitem):
146 """Called when the show/hide monitor window menu item is toggled."""
147 if self._selfToggling:
148 self._selfToggling = False
149 elif self._showMonitorMenuItem.get_active():
150 self._gui.showMonitorWindow()
151 else:
152 self._gui.hideMonitorWindow()
153
[32]154 def _updateFlightStatus(self):
155 """Update the flight status."""
[128]156 stage = u"-" if self._stage is None \
[114]157 else xstr("flight_stage_" + const.stage2string(self._stage))
[544]158
[31]159 if self._noGoReason is None:
[404]160 rating = "%.1f%%" % (self._rating,)
[31]161 else:
[32]162 rating = self._noGoReason
[31]163
[32]164 if appIndicator:
[128]165 self._stageMenuItem.set_label("%s: %s" % \
166 (xstr("statusicon_stage"),
167 stage))
168 self._ratingMenuItem.set_label("%s: %s" % \
169 (xstr("statusicon_rating"),
170 rating))
[32]171 else:
172 if self._noGoReason is not None:
173 rating = '<span foreground="red">' + rating + '</span>'
[128]174 markup = u"MAVA Logger X %s\n\n%s: %s\n%s: %s" %\
[114]175 (const.VERSION, xstr("statusicon_stage"), stage,
176 xstr("statusicon_rating"), rating)
[32]177 self._statusIcon.set_tooltip_markup(markup)
Note: See TracBrowser for help on using the repository browser.