~ubuntu-branches/ubuntu/oneiric/cairo-dock-plug-ins/oneiric-updates

« back to all changes in this revision

Viewing changes to Dbus/interfaces/python/CDApplet.py

  • Committer: Kees Cook
  • Date: 2011-08-11 23:17:39 UTC
  • mfrom: (20.1.1 cairo-dock-plug-ins)
  • Revision ID: kees@outflux.net-20110811231739-cteedan51tmdg77v
Tags: 2.4.0~0beta2-0ubuntu1
releasing version 2.4.0~0beta2-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# This is a part of the external demo applet for Cairo-Dock
 
1
# This is a part of the external applets for Cairo-Dock
2
2
# Copyright : (C) 2010-2011 by Fabounet
3
3
# E-mail : fabounet@glx-dock.org
4
4
#
24
24
import ConfigParser
25
25
import gobject
26
26
import glib
 
27
import gettext
27
28
import dbus
28
29
from dbus.mainloop.glib import DBusGMainLoop
29
30
 
30
31
DBusGMainLoop(set_as_default=True)
31
32
 
 
33
INSTALL_PREFIX = os.path.abspath("..")  # applets are launched from their install directory, so ".." is the folder containing all applets.
 
34
 
 
35
GETTEXT_NAME = 'cairo-dock-plugins-extra'
 
36
LOCALE_DIR = INSTALL_PREFIX + '/locale'  # user version of /usr/share/locale
 
37
gettext.textdomain(GETTEXT_NAME)
 
38
gettext.bind_textdomain_codeset (GETTEXT_NAME, 'UTF-8');
 
39
gettext.bindtextdomain(GETTEXT_NAME, LOCALE_DIR)
 
40
_ = lambda x: gettext.dgettext(GETTEXT_NAME,x)
 
41
 
32
42
####################
33
43
### Applet class ###
34
44
####################
35
45
class CDApplet:
36
46
        
 
47
        #############
 
48
        ### Enums ###
 
49
        #############
 
50
        # orientation
37
51
        BOTTOM = 0
38
52
        TOP    = 1
39
53
        RIGHT  = 2
40
54
        LEFT   = 3
41
 
        
 
55
        # container type
42
56
        DOCK    = 0
43
57
        DESKLET = 1
44
 
        
 
58
        # emblem position
45
59
        UPPER_LEFT  = 0
46
60
        LOWER_RIGHT = 1
47
61
        LOWER_LEFT  = 2
48
62
        UPPER_RIGHT = 3
49
63
        MIDDLE      = 4
50
 
        
 
64
        # menu item types
51
65
        MENU_ENTRY        = 0
52
66
        MENU_SUB_MENU     = 1
53
67
        MENU_SEPARATOR    = 2
54
68
        MENU_CHECKBOX     = 3
55
69
        MENU_RADIO_BUTTON = 4
56
 
 
 
70
        # main menu ID
57
71
        MAIN_MENU_ID = 0
58
 
        
 
72
        # dialog key pressed
59
73
        DIALOG_KEY_ENTER = -1
60
74
        DIALOG_KEY_ESCAPE = -2
61
75
        
 
76
        #####################
 
77
        ### INIT AND DBUS ###
 
78
        #####################
 
79
        
62
80
        def __init__(self):
63
81
                """ initialize the applet. Must be called by any class that inheritates from it.
64
82
                It defines the following:
74
92
                self.loop = None
75
93
                self._bEnded = False
76
94
                self._cMenuIconId = None
77
 
                self.cAppletName = sys.argv[0][2:]
 
95
                self.cAppletName = sys.argv[0][2:]  # the command is ./applet_name
78
96
                self.cBusPath = sys.argv[2]
79
97
                self.cConfFile = sys.argv[3]
80
98
                self.cParentAppName = sys.argv[4]
 
99
                self.cShareDataDir = INSTALL_PREFIX + '/' + self.cAppletName
81
100
                
82
101
                self._get_config()
83
102
                self._connect_to_dock()
84
103
        
 
104
        def _connect_to_dock(self):
 
105
                # get our applet on the bus.
 
106
                bus = dbus.SessionBus()
 
107
                try:
 
108
                        applet_object = bus.get_object("org.cairodock.CairoDock", self.cBusPath)
 
109
                except:
 
110
                        print ">>> object '"+self.cBusPath+"' can't be found on the bus, exit.\nMake sure that Cairo-Dock is running"
 
111
                        sys.exit(2)
 
112
                self.icon = dbus.Interface(applet_object, "org.cairodock.CairoDock.applet")  # this object represents our icon inside the dock or a desklet.
 
113
                sub_icons_object = bus.get_object("org.cairodock.CairoDock", self.cBusPath+"/sub_icons")
 
114
                self.sub_icons = dbus.Interface(sub_icons_object, "org.cairodock.CairoDock.subapplet")  # this object represents the list of icons contained in our sub-dock, or in our desklet. We'll add them one by one later, giving them a unique ID, which will be used to identify each of them.
 
115
                # connect to signals.
 
116
                self.icon.connect_to_signal("on_click", self.on_click)  # when the user left-clicks on our icon.
 
117
                self.icon.connect_to_signal("on_middle_click", self.on_middle_click)  # when the user middle-clicks on our icon.
 
118
                self.icon.connect_to_signal("on_build_menu", self._on_build_menu)  # when the user right-clicks on our applet (which builds the menu)
 
119
                self.icon.connect_to_signal("on_menu_select", self._on_menu_select)  # when the user selects an entry of this menu.
 
120
                self.icon.connect_to_signal("on_scroll", self.on_scroll)  # when the user scroll up or down on our icon.
 
121
                self.icon.connect_to_signal("on_drop_data", self.on_drop_data)  # when the user drops something on our icon.
 
122
                self.icon.connect_to_signal("on_answer_dialog", self.on_answer_dialog)  # when the user answer a question.
 
123
                self.icon.connect_to_signal("on_shortkey", self.on_shortkey)  # when the user press the shortkey.
 
124
                self.icon.connect_to_signal("on_change_focus", self.on_change_focus)  # when the window's focus changes.
 
125
                self.icon.connect_to_signal("on_stop_module", self._on_stop)  # when the user deactivate our applet (or the DBus plug-in, or when the Cairo-Dock is stopped).
 
126
                self.icon.connect_to_signal("on_reload_module", self._on_reload)  # when the user changes something in our config, or when the desklet is resized (with no change in the config).
 
127
                self.sub_icons.connect_to_signal("on_click_sub_icon", self.on_click_sub_icon)  # when the user left-clicks on a sub-icon.
 
128
                self.sub_icons.connect_to_signal("on_middle_click_sub_icon", self.on_middle_click_sub_icon)
 
129
                self.sub_icons.connect_to_signal("on_scroll_sub_icon", self.on_scroll_sub_icon)
 
130
                self.sub_icons.connect_to_signal("on_build_menu_sub_icon", self._on_build_menu_sub_icon)
 
131
                self.sub_icons.connect_to_signal("on_drop_data_sub_icon", self.on_drop_data_sub_icon)
 
132
        
85
133
        def run(self):
86
134
                """ start the applet and enter the main loop; we never get out of this function """
87
135
                self.begin()
94
142
        ##################################
95
143
        ### callbacks on the main icon ###
96
144
        ##################################
 
145
        
97
146
        def on_click(self,iState):
98
147
                """ action on click """
99
148
                pass
148
197
        ##################################
149
198
        ### callbacks on the sub-icons ###
150
199
        ##################################
 
200
        
151
201
        def on_click_sub_icon(self, iState, cIconID):
152
202
                """ action on click on one of our sub-icons"""
153
203
                pass
183
233
        ###############################
184
234
        ### callbacks on the applet ###
185
235
        ###############################
 
236
        
186
237
        def begin(self):
187
238
                """ action when the applet is started """
188
239
                pass
215
266
                keyfile.read(self.cConfFile)
216
267
                self.get_config(keyfile)
217
268
        
218
 
        def _connect_to_dock(self):
219
 
                # get our applet on the bus.
220
 
                #~ applet_path = "/org/cairodock/CairoDock/"+self.cAppletName  # path where our object is stored on the bus.
221
 
                bus = dbus.SessionBus()
222
 
                try:
223
 
                        applet_object = bus.get_object("org.cairodock.CairoDock", self.cBusPath)
224
 
                except:
225
 
                        print ">>> object '"+self.cBusPath+"' can't be found on the bus, exit.\nMake sure that the 'Dbus' plug-in is activated in Cairo-Dock"
226
 
                        sys.exit(2)
227
 
                self.icon = dbus.Interface(applet_object, "org.cairodock.CairoDock.applet")  # this object represents our icon inside the dock or a desklet.
228
 
                sub_icons_object = bus.get_object("org.cairodock.CairoDock", self.cBusPath+"/sub_icons")
229
 
                self.sub_icons = dbus.Interface(sub_icons_object, "org.cairodock.CairoDock.subapplet")  # this object represents the list of icons contained in our sub-dock, or in our desklet. We'll add them one by one later, giving them a unique ID, which will be used to identify each of them.
230
 
                # connect to signals.
231
 
                self.icon.connect_to_signal("on_click", self.on_click)  # when the user left-clicks on our icon.
232
 
                self.icon.connect_to_signal("on_middle_click", self.on_middle_click)  # when the user middle-clicks on our icon.
233
 
                self.icon.connect_to_signal("on_build_menu", self._on_build_menu)  # when the user right-clicks on our applet (which builds the menu)
234
 
                self.icon.connect_to_signal("on_menu_select", self._on_menu_select)  # when the user selects an entry of this menu.
235
 
                self.icon.connect_to_signal("on_scroll", self.on_scroll)  # when the user scroll up or down on our icon.
236
 
                self.icon.connect_to_signal("on_drop_data", self.on_drop_data)  # when the user drops something on our icon.
237
 
                self.icon.connect_to_signal("on_answer_dialog", self.on_answer_dialog)  # when the user answer a question.
238
 
                self.icon.connect_to_signal("on_shortkey", self.on_shortkey)  # when the user press the shortkey.
239
 
                self.icon.connect_to_signal("on_change_focus", self.on_change_focus)  # when the window's focus changes.
240
 
                self.icon.connect_to_signal("on_stop_module", self._on_stop)  # when the user deactivate our applet (or the DBus plug-in, or when the Cairo-Dock is stopped).
241
 
                self.icon.connect_to_signal("on_reload_module", self._on_reload)  # when the user changes something in our config, or when the desklet is resized (with no change in the config).
242
 
                self.sub_icons.connect_to_signal("on_click_sub_icon", self.on_click_sub_icon)  # when the user left-clicks on a sub-icon.
243
 
                self.sub_icons.connect_to_signal("on_middle_click_sub_icon", self.on_middle_click_sub_icon)
244
 
                self.sub_icons.connect_to_signal("on_scroll_sub_icon", self.on_scroll_sub_icon)
245
 
                self.sub_icons.connect_to_signal("on_build_menu_sub_icon", self._on_build_menu_sub_icon)
246
 
                self.sub_icons.connect_to_signal("on_drop_data_sub_icon", self.on_drop_data_sub_icon)