~ubuntu-branches/ubuntu/vivid/blueman/vivid-proposed

« back to all changes in this revision

Viewing changes to blueman/plugins/applet/Menu.py

  • Committer: Package Import Robot
  • Author(s): Artur Rona
  • Date: 2014-12-24 18:33:36 UTC
  • mfrom: (2.3.8 sid)
  • Revision ID: package-import@ubuntu.com-20141224183336-cyb82ot0y8tz8flq
Tags: 1.99~alpha1-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - debian/patches/01_dont_autostart_lxde.patch:
    + Don't autostart the applet in LXDE.
  - debian/patches/03_filemanager_fix.patch:
    + Add support for more filemanagers.
* debian/patches/02_dont_crash_on_non-bluetooth_card.patch:
  - Dropped, no longer applicable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Valmantas Paliksa <walmis at balticum-tv dot lt>
2
 
# Copyright (C) 2008 Tadas Dailyda <tadas at dailyda dot com>
3
 
#
4
 
# Licensed under the GNU General Public License Version 3
5
 
#
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.
10
 
#
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.
15
 
#
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/>.
18
 
19
1
from blueman.Functions import *
20
2
from blueman.plugins.AppletPlugin import AppletPlugin
21
3
 
22
 
import gobject
23
 
import gtk
 
4
from gi.repository import GObject
 
5
from gi.repository import Gtk
 
6
 
24
7
 
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"
29
 
        __author__ = "Walmis"
30
 
        __unloadable__ = False
31
 
        
32
 
        def on_load(self, applet):
33
 
                self.Applet = applet
34
 
                
35
 
                self.Applet.Plugins.StatusIcon.connect("popup-menu", self.on_popup_menu)
36
 
                
37
 
                self.__plugins_loaded = False
38
 
                
39
 
                self.__menuitems = []
40
 
                self.__menu = gtk.Menu()
41
 
                
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)             
45
 
        
46
 
        def __sort(self):
47
 
                self.__menuitems.sort(lambda a, b: cmp(a[0], b[0]))
48
 
                
49
 
        def __clear(self):
50
 
                def each(child):
51
 
                        self.__menu.remove(child)
52
 
                self.__menu.foreach(each)       
53
 
        
54
 
        def __load_items(self):
55
 
                for item in self.__menuitems:
56
 
                        self.__menu.append(item[1])
57
 
                        if item[2]:
58
 
                                item[1].show()          
59
 
        
60
 
        def Register(self, owner, item, priority, show=True):
61
 
                self.__menuitems.append((priority, item, show, owner))
62
 
                if self.__plugins_loaded:
63
 
                        self.__sort()
64
 
                        self.__clear()
65
 
                        self.__load_items()
66
 
                        
67
 
                
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)
74
 
                
75
 
        def on_plugins_loaded(self):
76
 
                self.__plugins_loaded = True
77
 
                self.__sort()
78
 
                self.__load_items()
79
 
                
80
 
        def get_menu(self):
81
 
                return self.__menu
82
 
                
83
 
                        
84
 
 
 
9
    __depends__ = ["StatusIcon"]
 
10
    __description__ = _("Provides a menu for the applet and an API for other plugins to manipulate it")
 
11
    __icon__ = "menu-editor"
 
12
    __author__ = "Walmis"
 
13
    __unloadable__ = False
 
14
 
 
15
    def on_load(self, applet):
 
16
        self.Applet = applet
 
17
 
 
18
        self.Applet.Plugins.StatusIcon.connect("popup-menu", self.on_popup_menu)
 
19
 
 
20
        self.__plugins_loaded = False
 
21
 
 
22
        self.__menuitems = []
 
23
        self.__menu = Gtk.Menu()
 
24
 
 
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)
 
28
 
 
29
    def __sort(self):
 
30
        self.__menuitems.sort(lambda a, b: cmp(a[0], b[0]))
 
31
 
 
32
    def __clear(self):
 
33
        def each(child, _):
 
34
            self.__menu.remove(child)
 
35
 
 
36
        self.__menu.foreach(each, None)
 
37
 
 
38
    def __load_items(self):
 
39
        for item in self.__menuitems:
 
40
            self.__menu.append(item[1])
 
41
            if item[2]:
 
42
                item[1].show()
 
43
 
 
44
    def Register(self, owner, item, priority, show=True):
 
45
        self.__menuitems.append((priority, item, show, owner))
 
46
        if self.__plugins_loaded:
 
47
            self.__sort()
 
48
            self.__clear()
 
49
            self.__load_items()
 
50
 
 
51
 
 
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)
 
58
 
 
59
    def on_plugins_loaded(self):
 
60
        self.__plugins_loaded = True
 
61
        self.__sort()
 
62
        self.__load_items()
 
63
 
 
64
    def get_menu(self):
 
65
        return self.__menu