19

Putting any gtk.Widget inside a gtk.Menu works, somewhat, by putting an empty gtk.MenuItem in first. It doesn't seem to be reliable - but it basically works. With an appindicator.Indicator, it doesn't work. The entry just stays empty. Even if you set the child[border_size] to 32, for example.

The only widget that works is a gtk.Label (plus the MenuItem, ImageMenuItem and so on of course).

Now the Me Menu has got a gtk.Entry in it, so it must surely be possible to do this Properly. How do I do it?

Here's some example code to explain what I'm on about:

    self.item = gtk.MenuItem()
    self.item.add(gtk.Label("hello world!"))
    self.menu.append(self.item)

The above code works, this however doesn't:

    self.item = gtk.MenuItem()
    self.item.add(gtk.Entry())
    self.menu.append(self.item)

Where self.menu is an appindicator.Indicator, if it were a gtk.Menu, the Entry would be at least displayed.

Here's some working code:

import gtk
import appindicator

class AppIndicator (object):

    def __init__(self):
        self.ind = appindicator.Indicator("hello world client",
            "distributor-logo", appindicator.CATEGORY_APPLICATION_STATUS)
        self.ind.set_status (appindicator.STATUS_ACTIVE)
        self.menu = gtk.Menu()
        item = gtk.MenuItem()

        item.add(gtk.Label("hello world"))
        # item.add(gtk.Entry())

        self.menu.append(item)
        self.menu.show_all()
        self.ind.set_menu(self.menu)


indicator = AppIndicator()
gtk.main()
3
  • As @MarcoCeppi reminded me, yes - this isn't supposed to work. I'm just hoping and dreaming, maybe it can. Since the Me Menu does something seemingly similar. Dec 6, 2010 at 14:47
  • 1
    I'm pretty sure that the Me Menu makes use of libido (Indicator Display Objects) to do that. See: launchpad.net/ido In particular, idoentrymenuitem.c (bazaar.launchpad.net/~canonical-dx-team/ido/trunk/annotate/…). Unfortunately, I don't think there are python bindings. You might want to ask on the ayatana-dev email list. Dec 21, 2010 at 16:22
  • Did you find out how to do this? I am facing the same problem. Thanks. Oct 6, 2013 at 16:22

2 Answers 2

8

The Application Indicator menu support is based on D-Bus menus, which are limited in what they support - they only support basic menu functionality, not more exotic things such as arbitrary widgets.

One significant roadblock to them ever supporting such things is the fact that the application indicator menu is rendered by a different process, the application indicator process, so your program doesn't have access to directly draw anything on it. Overcoming this would require either supporting something like X-Embed in D-Bus menus or allowing all of GTK to work over D-Bus.

3

The sound indicator in Ubuntu has sliders for the volume and I wondered how that is possible. After a look in the code it seems there are GtkMenus which can be filled via dbus meanwhile: https://developer.ubuntu.com/api/devel/ubuntu-12.04/c/dbusmenugtk/index.html

But I don't know how to use them. Wanted to write a sound indicator where I can control the volume per-app just like pavucontrol can do it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .