source: src/mlx/gui/statusicon.py@ 51:f0f99ac21935

Last change on this file since 51:f0f99ac21935 was 38:08f7e6592452, checked in by István Váradi <ivaradi@…>, 13 years ago

The status icon is now hidden properly when the program quits, and made restarting nicer

File size: 4.4 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 menu.show()
43
44 iconFile = os.path.join(iconDirectory, "logo.ico")
45
46 if appIndicator:
47 if pygobject:
48 indicator = appindicator.Indicator.new ("mava-logger-x", iconFile,
49 appindicator.IndicatorCategory.APPLICATION_STATUS)
50 indicator.set_status (appindicator.IndicatorStatus.ACTIVE)
51 else:
52 indicator = appindicator.Indicator ("mava-logger-x", iconFile,
53 appindicator.CATEGORY_APPLICATION_STATUS)
54 indicator.set_status (appindicator.STATUS_ACTIVE)
55
56 indicator.set_menu(menu)
57 self._indicator = indicator
58 else:
59 def popup_menu(status, button, time):
60 menu.popup(None, None, gtk.status_icon_position_menu,
61 button, time, status)
62
63 statusIcon = gtk.StatusIcon()
64 statusIcon.set_from_file(iconFile)
65 statusIcon.set_visible(True)
66 statusIcon.connect('popup-menu', popup_menu)
67 statusIcon.connect('activate',
68 lambda status: self._gui.toggleMainWindow())
69 self._statusIcon = statusIcon
70
71 self._updateFlightStatus()
72
73 def mainWindowHidden(self):
74 """Called when the main window is hidden."""
75 if self._showHideMenuItem.get_active():
76 self._selfToggling = True
77 self._showHideMenuItem.set_active(False)
78
79 def mainWindowShown(self):
80 """Called when the main window is shown."""
81 if not self._showHideMenuItem.get_active():
82 self._selfToggling = True
83 self._showHideMenuItem.set_active(True)
84
85 def destroy(self):
86 """Hide and destroy the status icon."""
87 if appIndicator:
88 if pygobject:
89 self._indicator.set_status(appindicator.IndicatorStatus.PASSIVE)
90 else:
91 self._indicator.set_status(appindicator.STATUS_PASSIVE)
92 else:
93 self._statusIcon.set_visible(False)
94
95 def _showHideToggled(self, menuitem):
96 """Called when the show/hide menu item is toggled."""
97 if self._selfToggling:
98 self._selfToggling = False
99 elif self._showHideMenuItem.get_active():
100 self._gui.showMainWindow()
101 else:
102 self._gui.hideMainWindow()
103
104 def _updateFlightStatus(self):
105 """Update the flight status."""
106 stage = "-" if self._stage is None else const.stage2string(self._stage)
107
108 if self._noGoReason is None:
109 rating = "%.0f%%" % (self._rating,)
110 else:
111 rating = self._noGoReason
112
113 if appIndicator:
114 self._stageMenuItem.set_label("Stage: %s" % (stage,))
115 self._ratingMenuItem.set_label("Rating: %s" % (rating,))
116 else:
117 if self._noGoReason is not None:
118 rating = '<span foreground="red">' + rating + '</span>'
119 markup = "MAVA Logger X %s\n\nStage: %s\nRating: %s" %\
120 (const.VERSION, stage, rating)
121 self._statusIcon.set_tooltip_markup(markup)
Note: See TracBrowser for help on using the repository browser.