2
### We assume the name of this applet is "demo_python"
3
### Copy this folder into ~/.config/cairo-dock/third-party.
4
### In the folder we have :
5
### demo_python (the executable script), demo_python.conf (the default config file), "icon" (the default icon of the applet) and "preview" (a preview of this applet)
14
from dbus.mainloop.glib import DBusGMainLoop
17
### let's connect to the dock. ###
18
DBusGMainLoop(set_as_default=True)
19
bus = dbus.SessionBus()
21
dock_object = bus.get_object("org.cairodock.CairoDock",
22
"/org/cairodock/CairoDock")
23
except dbus.DBusException:
24
print "Cairo-Dock not found on bus (did you activate its 'DBus' plug-in ?)"
26
dock = dbus.Interface(dock_object, "org.cairodock.CairoDock")
29
### let's register our applet ! ###
30
applet_name=os.path.basename(os.path.abspath("."))
31
applet_share_data_dir=os.path.abspath(".")
32
print ">>> registering our applet..."
33
dock.RegisterNewModule(applet_name,
34
"This is a distant applet\nIt simulates a counter:\n Scroll up/down to increase/decrease the counter,\n Click/middle-click to increase/decrease the counter by 10\n Drop some text to set it as the label.",
36
3, # category "accessories"
37
applet_share_data_dir)
38
print ">>> applet registered."
40
### get our applet ! (if it doesn't exist, it means the user does not want to use it, so we quit) ###
42
applet_object = bus.get_object("org.cairodock.CairoDock",
43
"/org/cairodock/CairoDock/"+applet_name)
44
except dbus.DBusException:
45
print ">>> the '"+applet_name+"' module has not been started"
47
myIcon = dbus.Interface(applet_object, "org.cairodock.CairoDock.applet")
49
### we'll have a sub-docks, so we also get the sub-icons object ###
50
sub_icons_object = bus.get_object("org.cairodock.CairoDock",
51
"/org/cairodock/CairoDock/"+applet_name+"/sub_icons")
52
mySubIcons = dbus.Interface(sub_icons_object, "org.cairodock.CairoDock.subapplet")
57
# register to the notifications on our applet
59
myIcon.connect_to_signal("on_click", action_on_click)
60
myIcon.connect_to_signal("on_middle_click", action_on_middle_click)
61
myIcon.connect_to_signal("on_build_menu", action_on_build_menu)
62
myIcon.connect_to_signal("on_menu_select", action_on_menu_select)
63
myIcon.connect_to_signal("on_scroll", action_on_scroll)
64
myIcon.connect_to_signal("on_drop_data", action_on_drop_data)
65
myIcon.connect_to_signal("on_init_module", action_on_init)
66
myIcon.connect_to_signal("on_stop_module", action_on_stop)
67
myIcon.connect_to_signal("on_reload_module", action_on_reload)
68
mySubIcons.connect_to_signal("on_click_sub_icon", on_click_sub_icon)
73
#dock.UnregisterModule(applet_name)
81
################################################
82
### Add your own code to the functions below ###
83
################################################
88
def action_on_click(iState):
92
myIcon.SetQuickInfo(format(count, "d"))
93
myIcon.RenderValues([count/100.])
95
def action_on_middle_click():
97
print ">>> middle clic !"
99
myIcon.SetQuickInfo(format(count, "d"))
100
myIcon.RenderValues([count/100.])
102
def action_on_build_menu():
103
print ">>> build menu !"
104
myIcon.PopulateMenu(["set min value", "set medium value", "set max value"])
106
def action_on_menu_select(iNumEntry):
108
print ">>> choice",iNumEntry,"has been selected !"
115
myIcon.SetQuickInfo(format(count, "d"))
116
myIcon.RenderValues([count/100.])
118
def action_on_scroll(bScrollUp):
125
myIcon.SetQuickInfo(format(count, "d"))
126
myIcon.RenderValues([count/100.])
128
def action_on_drop_data(cReceivedData):
129
print ">>> received",cReceivedData
130
myIcon.SetLabel(cReceivedData)
133
def on_click_sub_icon(iState, cIconID):
135
print "clic on the sub-icon '"+cIconID+"' !"
138
def action_on_init():
140
print ">>> our module is started"
142
myIcon.ShowDialog("I'm connected to Cairo-Dock !", 4)
143
myIcon.SetQuickInfo(format(count, "d"))
144
myIcon.AddDataRenderer("gauge", 1, "Turbo-night")
145
myIcon.RenderValues([0.])
146
mySubIcons.AddSubIcons(["icon 1", "firefox-3.0", "id1", "icon 2", "trash", "id2", "icon 3", "thunderbird", "id3", "icon 4", "nautilus", "id4"])
147
mySubIcons.RemoveSubIcon("id2")
148
mySubIcons.SetQuickInfo("1", "id1")
149
mySubIcons.SetQuickInfo("2", "id2")
150
mySubIcons.SetQuickInfo("3", "id3")
151
mySubIcons.SetQuickInfo("4", "id4")
153
def action_on_stop():
155
print ">>> our module is stopped"
159
def action_on_reload(bConfigHasChanged):
160
print ">>> our module is reloaded"
161
if bConfigHasChanged:
162
print ">>> and our config has changed"
163
myIcon.AddDataRenderer("gauge", 1, "Turbo-night")
164
myIcon.RenderValues([count/100.])
165
mySubIcons.RemoveSubIcon("any")
166
mySubIcons.AddSubIcons(["icon 1", "firefox-3.0", "echo pouet", "icon 2", "trash", "abc", "icon 3", "thunderbird", "def"])
170
if __name__ == '__main__':