source: src/mlx/gui/statusicon.py@ 76:f5b2b0022cdf

Last change on this file since 76:f5b2b0022cdf was 76:f5b2b0022cdf, checked in by István Váradi <ivaradi@…>, 12 years ago

Added a Quit option to the status icon's menu and a confirmation dialog.

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