source: src/mlx/gui/statusicon.py@ 102:c0dca4531619

Last change on this file since 102:c0dca4531619 was 77:cc8b178b8102, checked in by István Váradi <ivaradi@…>, 13 years ago

The monitoring window is now separate window

File size: 5.9 KB
Line 
1# Implementation of the status icon
2
3#-------------------------------------------------------------------------------
4
5from common import *
6
7import mlx.const as const
8
9#-------------------------------------------------------------------------------
10
11class StatusIcon(FlightStatusHandler):
12 """The class handling the status icon."""
13 def __init__(self, iconDirectory, gui):
14 """Construct the status icon."""
15 super(StatusIcon, self).__init__()
16
17 self._gui = gui
18 self._selfToggling = False
19
20 menu = gtk.Menu()
21
22 if appIndicator:
23 self._stageMenuItem = gtk.MenuItem()
24 self._stageMenuItem.show()
25 menu.append(self._stageMenuItem)
26
27 self._ratingMenuItem = gtk.MenuItem()
28 self._ratingMenuItem.show()
29 menu.append(self._ratingMenuItem)
30
31 separator = gtk.SeparatorMenuItem()
32 separator.show()
33 menu.append(separator)
34
35 self._showHideMenuItem = gtk.CheckMenuItem()
36 self._showHideMenuItem.set_label("Show main window")
37 self._showHideMenuItem.set_active(True)
38 self._showHideMenuItem.connect("toggled", self._showHideToggled)
39 self._showHideMenuItem.show()
40 menu.append(self._showHideMenuItem)
41
42 self._showMonitorMenuItem = gtk.CheckMenuItem()
43 self._showMonitorMenuItem.set_label("Show monitor window")
44 self._showMonitorMenuItem.set_active(False)
45 self._showMonitorMenuItem.connect("toggled", self._showMonitorToggled)
46 self._showMonitorMenuItem.show()
47 menu.append(self._showMonitorMenuItem)
48
49 separator = gtk.SeparatorMenuItem()
50 separator.show()
51 menu.append(separator)
52
53 self._quitMenuItem = gtk.MenuItem()
54 self._quitMenuItem.set_label("Quit")
55 self._quitMenuItem.show()
56 self._quitMenuItem.connect("activate", self._gui._quit)
57 menu.append(self._quitMenuItem)
58
59 menu.show()
60
61 iconFile = os.path.join(iconDirectory, "logo.ico")
62
63 if appIndicator:
64 if pygobject:
65 indicator = appindicator.Indicator.new ("mava-logger-x", iconFile,
66 appindicator.IndicatorCategory.APPLICATION_STATUS)
67 indicator.set_status (appindicator.IndicatorStatus.ACTIVE)
68 else:
69 indicator = appindicator.Indicator ("mava-logger-x", iconFile,
70 appindicator.CATEGORY_APPLICATION_STATUS)
71 indicator.set_status (appindicator.STATUS_ACTIVE)
72
73 indicator.set_menu(menu)
74 self._indicator = indicator
75 else:
76 def popup_menu(status, button, time):
77 menu.popup(None, None, gtk.status_icon_position_menu,
78 button, time, status)
79
80 statusIcon = gtk.StatusIcon()
81 statusIcon.set_from_file(iconFile)
82 statusIcon.set_visible(True)
83 statusIcon.connect('popup-menu', popup_menu)
84 statusIcon.connect('activate',
85 lambda status: self._gui.toggleMainWindow())
86 self._statusIcon = statusIcon
87
88 self._updateFlightStatus()
89
90 def mainWindowHidden(self):
91 """Called when the main window is hidden."""
92 if self._showHideMenuItem.get_active():
93 self._selfToggling = True
94 self._showHideMenuItem.set_active(False)
95
96 def mainWindowShown(self):
97 """Called when the main window is shown."""
98 if not self._showHideMenuItem.get_active():
99 self._selfToggling = True
100 self._showHideMenuItem.set_active(True)
101
102 def monitorWindowHidden(self):
103 """Called when the monitor window is hidden."""
104 if self._showMonitorMenuItem.get_active():
105 self._selfToggling = True
106 self._showMonitorMenuItem.set_active(False)
107
108 def monitorWindowShown(self):
109 """Called when the monitor window is shown."""
110 if not self._showMonitorMenuItem.get_active():
111 self._selfToggling = True
112 self._showMonitorMenuItem.set_active(True)
113
114 def destroy(self):
115 """Hide and destroy the status icon."""
116 if appIndicator:
117 if pygobject:
118 self._indicator.set_status(appindicator.IndicatorStatus.PASSIVE)
119 else:
120 self._indicator.set_status(appindicator.STATUS_PASSIVE)
121 else:
122 self._statusIcon.set_visible(False)
123
124 def _showHideToggled(self, menuitem):
125 """Called when the show/hide menu item is toggled."""
126 if self._selfToggling:
127 self._selfToggling = False
128 elif self._showHideMenuItem.get_active():
129 self._gui.showMainWindow()
130 else:
131 self._gui.hideMainWindow()
132
133 def _showMonitorToggled(self, menuitem):
134 """Called when the show/hide monitor window menu item is toggled."""
135 if self._selfToggling:
136 self._selfToggling = False
137 elif self._showMonitorMenuItem.get_active():
138 self._gui.showMonitorWindow()
139 else:
140 self._gui.hideMonitorWindow()
141
142 def _updateFlightStatus(self):
143 """Update the flight status."""
144 stage = "-" if self._stage is None else const.stage2string(self._stage)
145
146 if self._noGoReason is None:
147 rating = "%.0f%%" % (self._rating,)
148 else:
149 rating = self._noGoReason
150
151 if appIndicator:
152 self._stageMenuItem.set_label("Stage: %s" % (stage,))
153 self._ratingMenuItem.set_label("Rating: %s" % (rating,))
154 else:
155 if self._noGoReason is not None:
156 rating = '<span foreground="red">' + rating + '</span>'
157 markup = "MAVA Logger X %s\n\nStage: %s\nRating: %s" %\
158 (const.VERSION, stage, rating)
159 self._statusIcon.set_tooltip_markup(markup)
Note: See TracBrowser for help on using the repository browser.