| 1 |
#!/usr/bin/env python3 |
| 2 |
# A simple test case. |
| 3 |
|
| 4 |
from gi.repository import Unity, Gio, GObject, Dbusmenu |
| 5 |
|
| 6 |
loop = GObject.MainLoop() |
| 7 |
|
| 8 |
# Pretend to be Firefox for the sake of the example |
| 9 |
|
| 10 |
launcher = Unity.LauncherEntry.get_for_desktop_id ("firefox.desktop") |
| 11 |
|
| 12 |
# Show a count of 123 on the icon |
| 13 |
|
| 14 |
launcher.set_property("count", 123) |
| 15 |
|
| 16 |
launcher.set_property("count_visible", True) |
| 17 |
|
| 18 |
# Set progress to 40% |
| 19 |
|
| 20 |
launcher.set_property("progress", 0.40) |
| 21 |
|
| 22 |
launcher.set_property("progress_visible", True) |
| 23 |
|
| 24 |
|
| 25 |
#launcher.set_property("emblem", "play") |
| 26 |
|
| 27 |
#launcher.set_property("emblem_visible", True) |
| 28 |
|
| 29 |
|
| 30 |
# We also want a quicklist |
| 31 |
|
| 32 |
def on_item_selected(self, menuitem, index): |
| 33 |
print("selected",index) |
| 34 |
|
| 35 |
ql = Dbusmenu.Menuitem.new () |
| 36 |
|
| 37 |
item1 = Dbusmenu.Menuitem.new () |
| 38 |
|
| 39 |
item1.property_set (Dbusmenu.MENUITEM_PROP_LABEL, "Item 1") |
| 40 |
|
| 41 |
item1.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, True) |
| 42 |
|
| 43 |
item1.connect ("item-activated", on_item_selected, 1) |
| 44 |
|
| 45 |
item2 = Dbusmenu.Menuitem.new () |
| 46 |
|
| 47 |
item2.property_set (Dbusmenu.MENUITEM_PROP_LABEL, "Item 2") |
| 48 |
|
| 49 |
item2.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, True) |
| 50 |
|
| 51 |
item2.connect ("item-activated", on_item_selected, 2) |
| 52 |
|
| 53 |
ql.child_append (item1) |
| 54 |
|
| 55 |
ql.child_append (item2) |
| 56 |
|
| 57 |
launcher.set_property("quicklist", ql) |
| 58 |
|
| 59 |
n = 3 |
| 60 |
prev_item = item2 |
| 61 |
|
| 62 |
def update_urgency(): |
| 63 |
global prev_item, n |
| 64 |
if launcher.get_property("urgent"): |
| 65 |
print("Removing urgent flag") |
| 66 |
launcher.set_property("urgent", False) |
| 67 |
else: |
| 68 |
print("setting urgent flag") |
| 69 |
launcher.set_property("urgent", True) |
| 70 |
|
| 71 |
if prev_item == None: |
| 72 |
item = Dbusmenu.Menuitem.new () |
| 73 |
|
| 74 |
item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, "Item "+str(n)) |
| 75 |
|
| 76 |
item.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, True) |
| 77 |
|
| 78 |
item.connect ("item-activated", on_item_selected, n) |
| 79 |
ql.child_append (item) |
| 80 |
prev_item = item |
| 81 |
else: |
| 82 |
ql.child_delete (prev_item) |
| 83 |
prev_item = None |
| 84 |
item1.property_set (Dbusmenu.MENUITEM_PROP_LABEL, "Item 1 (%d)"%n) |
| 85 |
n = n+1 |
| 86 |
|
| 87 |
return True |
| 88 |
|
| 89 |
GObject.timeout_add_seconds(4, update_urgency) |
| 90 |
|
| 91 |
loop.run() |