24
24
import ConfigParser
28
29
from dbus.mainloop.glib import DBusGMainLoop
30
31
DBusGMainLoop(set_as_default=True)
33
INSTALL_PREFIX = os.path.abspath("..") # applets are launched from their install directory, so ".." is the folder containing all applets.
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)
32
42
####################
33
43
### Applet class ###
34
44
####################
55
69
MENU_RADIO_BUTTON = 4
59
73
DIALOG_KEY_ENTER = -1
60
74
DIALOG_KEY_ESCAPE = -2
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:
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
82
101
self._get_config()
83
102
self._connect_to_dock()
104
def _connect_to_dock(self):
105
# get our applet on the bus.
106
bus = dbus.SessionBus()
108
applet_object = bus.get_object("org.cairodock.CairoDock", self.cBusPath)
110
print ">>> object '"+self.cBusPath+"' can't be found on the bus, exit.\nMake sure that Cairo-Dock is running"
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)
86
134
""" start the applet and enter the main loop; we never get out of this function """
215
266
keyfile.read(self.cConfFile)
216
267
self.get_config(keyfile)
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()
223
applet_object = bus.get_object("org.cairodock.CairoDock", self.cBusPath)
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"
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)