Re: [Sugar-devel] Idea about palettes with gtk3

2011-10-29 Thread Benjamin Berg
Hello,

On Fri, 2011-10-28 at 19:13 +0100, Marco Pesenti Gritti wrote:
> 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.

This looks perfect. By simply overriding the events on the Palette/Menu,
we can implement any behaviour that we want.

I am thinking of doing the override inside the palette group, as we
could easily check whether the user is hovering on top of another
palette/menu invoker, and switch right away.

It does not work with current pygobject introspection because of some
broken performance work that was done, where chaining up to the original
event handler does not work properly. Tomeu has got a simple fix for
this already though, it will require more work to not regress with
regard to the performance.

Benjamin

___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


[Sugar-devel] Idea about palettes with gtk3

2011-10-28 Thread Marco Pesenti Gritti
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()
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel