[Sugar-devel] Idea about palettes with gtk3

Marco Pesenti Gritti marco at marcopg.org
Fri Oct 28 14:13:26 EDT 2011


Hey,

we was discussing at the hackfest today how to fixup palettes to work
in gtk3. I looked more into the GtkMenuShell code on the train and I
had an idea. It seems like GtkMenuShell basically gets access to all
the enter/leave events while it's active (because of the grab and some
local forwarding through gtk_widget_event). And we can get the actual
widget that was entered/left using Gtk.get_event_widget. You can see
this by running the attached code snippet.

So the palette could be a standard GtkMenu. The icon would popup() on
enter. The palette would listen to those events and popdown/popup
things depending if we are on the icon, the palette, another icon for
the palette in the same group, a submenu of the palette.

Marco

---

#!/usr/bin/env python

from gi.repository import Gtk

class MyMenu(Gtk.Menu):
    __gtype_name__ = 'MyMenu'

    def __init__(self):
        super(Gtk.Menu, self).__init__()

    def do_enter_notify_event(self, event):
        print "enter %s" % Gtk.get_event_widget(event)

    def do_leave_notify_event(self, event):
        print "leave %s" % Gtk.get_event_widget(event)

class MenusApp:
    def __init__(self):
        self.window = Gtk.Window()
        self.window.connect('destroy', Gtk.main_quit)

        box = Gtk.HBox()
        self.window.add(box)

        self.menu = MyMenu()

        menuitem = Gtk.RadioMenuItem(label="Item1")
        self.menu.append(menuitem)

        submenu = MyMenu()

        menuitem = Gtk.RadioMenuItem(label="Item1")
        submenu.append(menuitem)

        menuitem = Gtk.MenuItem(label='Submenu')
        menuitem.set_submenu(submenu)
        self.menu.append(menuitem)

        submenu.show_all()
        self.menu.show_all()

        button = Gtk.Button("Click me")
        button.connect('clicked', self.clicked_cb)
        box.pack_start(button, False, True, 0)

        self.window.show_all()

    def clicked_cb(self, button):
        self.menu.popup(None, None, None, None, 0, 0)

app = MenusApp()
Gtk.main()


More information about the Sugar-devel mailing list