source: src/mlx/gui/statusicon.py@ 35:d32890325137

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

Hiding after minimizing seems to work now

File size: 4.0 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 _showHideToggled(self, menuitem):
86 """Called when the show/hide menu item is toggled."""
87 if self._selfToggling:
88 self._selfToggling = False
89 elif self._showHideMenuItem.get_active():
90 self._gui.showMainWindow()
91 else:
92 self._gui.hideMainWindow()
93
94 def _updateFlightStatus(self):
95 """Update the flight status."""
96 stage = "-" if self._stage is None else const.stage2string(self._stage)
97
98 if self._noGoReason is None:
99 rating = "%.0f%%" % (self._rating,)
100 else:
101 rating = self._noGoReason
102
103 if appIndicator:
104 self._stageMenuItem.set_label("Stage: %s" % (stage,))
105 self._ratingMenuItem.set_label("Rating: %s" % (rating,))
106 else:
107 if self._noGoReason is not None:
108 rating = '<span foreground="red">' + rating + '</span>'
109 markup = "MAVA Logger X %s\n\nStage: %s\nRating: %s" %\
110 (const.VERSION, stage, rating)
111 self._statusIcon.set_tooltip_markup(markup)
Note: See TracBrowser for help on using the repository browser.