~gnome15-team/gnome15/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python
 
#        +-----------------------------------------------------------------------------+
#        | GPL                                                                         |
#        +-----------------------------------------------------------------------------+
#        | Copyright (c) Brett Smith <tanktarta@blueyonder.co.uk>                      |
#        |                                                                             |
#        | This program is free software; you can redistribute it and/or               |
#        | modify it under the terms of the GNU General Public License                 |
#        | as published by the Free Software Foundation; either version 2              |
#        | of the License, or (at your option) any later version.                      |
#        |                                                                             |
#        | This program is distributed in the hope that it will be useful,             |
#        | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
#        | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
#        | GNU General Public License for more details.                                |
#        |                                                                             |
#        | You should have received a copy of the GNU General Public License           |
#        | along with this program; if not, write to the Free Software                 |
#        | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
#        +-----------------------------------------------------------------------------+

'''
Provides a panel indicator that can be used to control and monitor the Gnome15
desktop service (g15-desktop-service). It will display a list of currently active
screens on activation, and allow the configuration UI to be launched (g15-config)
'''


import sys
import pygtk
pygtk.require('2.0')
import gtk
import os
import gconf
import traceback
from threading import RLock

# Logging
import logging
logging.basicConfig()
logger = logging.getLogger()

# Allow running from local path
path = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), "..", "gnome15", "src", "main", "python")
if os.path.exists(path):
    sys.path.insert(0, path)
    
# This block MUST be before the imports of the gnome15 modules
import dbus
import gobject
gobject.threads_init()
import dbus
from dbus.mainloop.glib import DBusGMainLoop
from dbus.mainloop.glib import threads_init
threads_init()
DBusGMainLoop(set_as_default=True)

import gnome15.g15globals as g15globals
import gnome15.g15service as g15service
import gnome15.g15screen as g15screen
import gnome15.g15util as g15util
import gnome15.g15desktop as g15desktop

class G15SystemTray(g15desktop.G15GtkMenuPanelComponent):
    
    def __init__(self):      
        self.prefs_menu = gtk.Menu()
        g15desktop.G15GtkMenuPanelComponent.__init__(self)
        
    def create_component(self):
        self.status_icon = gtk.StatusIcon()
        
        self.status_icon.connect('popup-menu', self._on_popup_menu)
        self.status_icon.connect('activate', self._on_activate)
        self.status_icon.connect('scroll_event', self.scroll_event)
        
    def clear_attention(self):
        self.remove_attention_menu_item()
        self.status_icon.set_from_pixbuf(self.normal_icon)
        self.status_icon.set_tooltip("")
        self.status_icon.set_visible(not self.conf_client.get_bool("/apps/gnome15/indicate_only_on_error"))
        
    def attention(self, message=None):
        self.status_icon.set_visible(True)
        self.status_icon.set_from_pixbuf(self.attention_icon)
        self.status_icon.set_tooltip(message if message != None else self.default_message)
        
    def _on_popup_menu(self, status, button, time):
        self.prefs_menu.popup(None, None, None, button, time)
        
    def _on_activate(self, status):
        if len(self.menu.get_children()) > 0:
            self.menu.popup(None, None, None, 1, gtk.get_current_event_time())
        
    def add_service_item(self, item):
        self._append_item(item, self.prefs_menu)   
             
    def add_start_desktop_service(self):
        g15desktop.G15GtkMenuPanelComponent.add_start_desktop_service(self)
        self.add_service_item(gtk.MenuItem())
        
    def rebuild_desktop_component(self):
        g15desktop.G15GtkMenuPanelComponent.rebuild_desktop_component(self)
        if len(self.devices)> 1:
            self.add_service_item(gtk.MenuItem())  
        item = gtk.MenuItem("Properties")
        item.connect("activate", self.show_configuration)
        self.add_service_item(item)        
        item = gtk.MenuItem("About")
        item.connect("activate", self.about_info)
        self.add_service_item(item)        
        self.status_icon.menu = self.prefs_menu
        
        self.prefs_menu.show_all()
        
    def icons_changed(self):
        self.normal_icon = gtk.gdk.pixbuf_new_from_file_at_size(g15util.get_icon_path([ "logitech-g-keyboard-applet", "logitech-g-keyboard-panel" ]), self.status_icon.get_size(), self.status_icon.get_size())
        self.attention_icon = gtk.gdk.pixbuf_new_from_file_at_size(g15util.get_icon_path([ "logitech-g-keyboard-error-panel", "logitech-g-keyboard-error-applet" ]), self.status_icon.get_size(), self.status_icon.get_size())
    
# run it in a gtk window
if __name__ == "__main__":
    try :
        import setproctitle
        setproctitle.setproctitle(os.path.basename(os.path.abspath(sys.argv[0])))
    except:
        pass
    
    if g15desktop.get_desktop() == "gnome-shell":
        sys.stderr.write("System Tray is not recommended in GNOME Shell, use the GNOME Shell extension instead (if you have version 3.4 or above)")
    
    tray = G15SystemTray()
    tray.start_service()
    gtk.main()