1 | # Implementation of the status icon
|
---|
2 |
|
---|
3 | #-------------------------------------------------------------------------------
|
---|
4 |
|
---|
5 | from common import *
|
---|
6 |
|
---|
7 | #-------------------------------------------------------------------------------
|
---|
8 |
|
---|
9 | class StatusIcon(object):
|
---|
10 | """The class handling the status icon."""
|
---|
11 | def __init__(self, iconDirectory, gui):
|
---|
12 | """Construct the status icon."""
|
---|
13 | self._gui = gui
|
---|
14 |
|
---|
15 | menu = gtk.Menu()
|
---|
16 |
|
---|
17 | self._showHideMenuItem = gtk.CheckMenuItem()
|
---|
18 | self._showHideMenuItem.set_label("Show main window")
|
---|
19 | self._showHideMenuItem.set_active(True)
|
---|
20 | self._showHideMenuItem.connect("toggled", self._showHideToggled)
|
---|
21 | self._showHideMenuItem.show()
|
---|
22 | menu.append(self._showHideMenuItem)
|
---|
23 |
|
---|
24 | menu.show()
|
---|
25 |
|
---|
26 | iconFile = os.path.join(iconDirectory, "logo.ico")
|
---|
27 |
|
---|
28 | if appIndicator:
|
---|
29 | if pygobject:
|
---|
30 | indicator = appindicator.Indicator.new ("mava-logger-x", iconFile,
|
---|
31 | appindicator.IndicatorCategory.APPLICATION_STATUS)
|
---|
32 | indicator.set_status (appindicator.IndicatorStatus.ACTIVE)
|
---|
33 | else:
|
---|
34 | indicator = appindicator.Indicator ("mava-logger-x", iconFile,
|
---|
35 | appindicator.CATEGORY_APPLICATION_STATUS)
|
---|
36 | indicator.set_status (appindicator.STATUS_ACTIVE)
|
---|
37 |
|
---|
38 | indicator.set_menu(menu)
|
---|
39 | self._indicator = indicator
|
---|
40 | self._usingIndicator = True
|
---|
41 | else:
|
---|
42 | def popup_menu(status, button, time):
|
---|
43 | menu.popup(None, None, gtk.status_icon_position_menu,
|
---|
44 | button, time, status)
|
---|
45 |
|
---|
46 | statusIcon = gtk.StatusIcon()
|
---|
47 | statusIcon.set_from_file(iconFile)
|
---|
48 | statusIcon.set_tooltip_markup("MAVA Logger X")
|
---|
49 | statusIcon.set_visible(True)
|
---|
50 | statusIcon.connect('popup-menu', popup_menu)
|
---|
51 | statusIcon.connect('activate',
|
---|
52 | lambda status: self._gui.toggleMainWindow())
|
---|
53 | self._statusIcon = statusIcon
|
---|
54 | self._usingIndicator = False
|
---|
55 |
|
---|
56 | def mainWindowHidden(self):
|
---|
57 | """Called when the main window is hidden."""
|
---|
58 | self._showHideMenuItem.set_active(False)
|
---|
59 |
|
---|
60 | def mainWindowShown(self):
|
---|
61 | """Called when the main window is shown."""
|
---|
62 | self._showHideMenuItem.set_active(True)
|
---|
63 |
|
---|
64 | def _showHideToggled(self, menuitem):
|
---|
65 | """Called when the show/hide menu item is toggled."""
|
---|
66 | if self._showHideMenuItem.get_active():
|
---|
67 | self._gui.showMainWindow()
|
---|
68 | else:
|
---|
69 | self._gui.hideMainWindow()
|
---|