I have been trying to work on a custom launcher for virtualbox in 11.04 that will show running vm count, as well as update a quicklist dynamically to have options to operate on the installed vms. I have been using python to try this using the Example Code here as an example: https://wiki.ubuntu.com/Unity/LauncherAPI.

The custom quicklist populates and calls commands correctly when it is first initialized. However after the GObject timeout callback occurs the second time if I try to then configure the quicklist again for the launcher, the list does not change and the items in the launcher are no longer ran and the signal doesn't appear to be called.

The following is the python script I have so far for this

from gi.repository import Unity, Gio, GObject, Dbusmenu
from cStringIO import StringIO
import sys, os, commands, subprocess, re, traceback

loop = GObject.MainLoop()

launcher = Unity.LauncherEntry.get_for_desktop_id ("virtualbox-ose" + ".desktop")

def menu_start_headless(a, b, name):
    print "Starting: " + name
    os.popen3("/usr/bin/vboxheadless -startvm \"" + name + "\"")

def menu_stop_headless(a, b, name):
    # poweroff and restore current vm
    string = "/usr/bin/vboxmanage controlvm \"" + name + "\" poweroff && /usr/bin/vboxmanage snapshot \"" + name + "\" restorecurrent"
    print "Calling: " + string
    os.popen3(string)

def update_quicklist():
    ql = Dbusmenu.Menuitem.new()

    output = commands.getoutput("/usr/bin/vboxmanage list vms | /bin/sed -r 's/(\ \S*$)|(\")//g'").splitlines()
    i = 0
    while i < len(output):
        item = Dbusmenu.Menuitem.new()
        name = output[i]
        item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, name)
        item.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, True)
        item.connect ("item-activated", menu_start_headless, name)
        ql.child_append (item)
        print "Added child: " + str(item)

        i = i + 1
        pass

    output = commands.getoutput("/usr/bin/vboxmanage list runningvms | /bin/sed -r 's/(\ \S*$)|(\")//g'").splitlines()
    i = 0
    while i < len(output):
        item = Dbusmenu.Menuitem.new()
        name = output[i]
        item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, "Stop and Restore: " + name)
        item.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, True)
        item.connect ("item-activated", menu_stop_headless, name)
        ql.child_append (item)
        print "Added child stop: " + str(item)

        i = i + 1
        pass

    # Activate quicklist
    launcher.set_property("quicklist", ql)
    if i > 0:
        launcher.set_property("count", i)
        launcher.set_property("count_visible", True)
    else:
        launcher.set_property("count", 0)
        launcher.set_property("count_visible", False)

def get_updates():
    update_quicklist()
    return True

# Call tab updates
GObject.timeout_add_seconds(5, get_updates)

loop.run()

Also to note the count is properly updated, and it just seems to be the quicklist having troubles. If I start or stop a vm behind the scenes the count is properly updated or hidden as applicable.

I have tried finding any documentation on dynamic quicklist or examples of this done. However the stuff I could all find are either done statically through a .desktop launcher or done statically by calling libunity and just doing it once at initialization usually (mainly by scowering Bilal Akhtar's branches).

Is there something I am doing incorrectly or should be doing? Or can a quicklist in this fashion only be populated once?


Update

I reduced this to a much simpler test case that just uses a placeholder test.desktop and test.py that shows the problem I am seeing

test.desktop

[Desktop Entry]  
Encoding=UTF-8  
Name=Test  
Comment=Test  
Terminal=false  
Type=Application  
Categories=GNOME;Application;Development;  
StartupNotify=true  

unity-test.py

from gi.repository import Unity, Gio, GObject, Dbusmenu
from cStringIO import StringIO
import sys, os, commands, subprocess, re, traceback

loop = GObject.MainLoop()

launcher = Unity.LauncherEntry.get_for_desktop_id ("test" + ".desktop")
i = 0

def listener(a, b):
    print "Method Called"

def update_quicklist():
    global i
    ql = Dbusmenu.Menuitem.new()
    item = Dbusmenu.Menuitem.new()
    item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, "test: " + str(i))
    item.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, True)
    item.connect("item-activated", listener)
    ql.child_append (item)

    # Activate quicklist
    launcher.set_property("quicklist", ql)
    launcher.set_property("count", i)
    launcher.set_property("count_visible", True)

    i = i + 1
    return True

# Call tab updates
GObject.timeout_add_seconds(5, update_quicklist)

loop.run()
  • You can just drap the test.desktop to the unity bar.
  • Then run unity-test.py in a terminal to see stdout.

After the first iteration the test.desktop icon will show a count of 0. If you open the quicklist it will show test: 0. If you click on test: 0 it will print a message of "Method Called" in the terminal. This is what I would expect.

When the next iteration occurs though and changes the icon count to anything higher than 0, then the quicklist still still shows test: 0 and clicking it does nothing. I would expect it to say test: and when clicked it should say "Method Called".

I hope that makes it easier to understand what I am trying to explain/ask.


Update 2

I installed Ubuntu 11.10 and it has different behavior. The quicklist updates properly, which is what I want. But instead it trades a different bug. Once the script is killed the quicklist is removed but the counter is not removed (which 11.04 does properly). Also then when I try to restart the script the counter works properly but then the quicklist no longer functions at all. I have to either remove the desktop launcher or reboot for the quicklist to function properly again.

So it seems to be a different bug on both versions.

link|improve this question
1  
If updating the distro/packages solved or changed the behaviour of the issue you should file bug reports to the developers to help them out sort this issue. – Bruno Pereira Jan 24 at 13:29
OP are you still looking for an answer? – blueXrider Feb 26 at 4:32
feedback

closed as off topic by fossfreedom Feb 28 at 9:43

Questions on Ask Ubuntu - Stack Exchange are expected to generally relate to Ubuntu, within the scope defined in the faq.

Browse other questions tagged or ask your own question.