1
# Copyright (C) 2008 Valmantas Paliksa <walmis at balticum-tv dot lt>
2
# Copyright (C) 2008 Tadas Dailyda <tadas at dailyda dot com>
4
# Licensed under the GNU General Public License Version 3
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
1
from blueman.Functions import *
20
2
from blueman.plugins.AppletPlugin import AppletPlugin
4
from gi.repository import GObject
5
from gi.repository import Gtk
25
8
class Menu(AppletPlugin):
26
__depends__ = ["StatusIcon"]
27
__description__ = _("Provides a menu for the applet and an API for other plugins to manipulate it")
28
__icon__ = "menu-editor"
30
__unloadable__ = False
32
def on_load(self, applet):
35
self.Applet.Plugins.StatusIcon.connect("popup-menu", self.on_popup_menu)
37
self.__plugins_loaded = False
40
self.__menu = gtk.Menu()
42
def on_popup_menu(self, status_icon, button, activate_time):
43
self.__menu.popup(None, None, gtk.status_icon_position_menu,
44
button, activate_time, status_icon)
47
self.__menuitems.sort(lambda a, b: cmp(a[0], b[0]))
51
self.__menu.remove(child)
52
self.__menu.foreach(each)
54
def __load_items(self):
55
for item in self.__menuitems:
56
self.__menu.append(item[1])
60
def Register(self, owner, item, priority, show=True):
61
self.__menuitems.append((priority, item, show, owner))
62
if self.__plugins_loaded:
68
def Unregister(self, owner):
69
for i in reversed(self.__menuitems):
70
priority, item, show, orig_owner = i
71
if orig_owner == owner:
72
self.__menu.remove(item)
73
self.__menuitems.remove(i)
75
def on_plugins_loaded(self):
76
self.__plugins_loaded = True
9
__depends__ = ["StatusIcon"]
10
__description__ = _("Provides a menu for the applet and an API for other plugins to manipulate it")
11
__icon__ = "menu-editor"
13
__unloadable__ = False
15
def on_load(self, applet):
18
self.Applet.Plugins.StatusIcon.connect("popup-menu", self.on_popup_menu)
20
self.__plugins_loaded = False
23
self.__menu = Gtk.Menu()
25
def on_popup_menu(self, status_icon, button, activate_time):
26
self.__menu.popup(None, None, Gtk.StatusIcon.position_menu,
27
status_icon, button, activate_time)
30
self.__menuitems.sort(lambda a, b: cmp(a[0], b[0]))
34
self.__menu.remove(child)
36
self.__menu.foreach(each, None)
38
def __load_items(self):
39
for item in self.__menuitems:
40
self.__menu.append(item[1])
44
def Register(self, owner, item, priority, show=True):
45
self.__menuitems.append((priority, item, show, owner))
46
if self.__plugins_loaded:
52
def Unregister(self, owner):
53
for i in reversed(self.__menuitems):
54
priority, item, show, orig_owner = i
55
if orig_owner == owner:
56
self.__menu.remove(item)
57
self.__menuitems.remove(i)
59
def on_plugins_loaded(self):
60
self.__plugins_loaded = True