[pygtk] configure_events for a table in an eventbox
Darren Hart
darren at dvhart.com
Tue Aug 14 15:24:51 WST 2007
I'm trying to create a widget that lists checkbuttons with labels in a
tabular format that will adjust it's layout as the window is resized. I am
currently using a table widget and have a working resize() method.
Unfortunately, I haven't been able to capture any kind of a resize event
other than size_allocate() which unfortunately caused an endless loop since
my resize()ing the table caused another size_allocate() call, etc etc.
Reading the docs suggest that what I want to use is a configure_event
handler and that table is one of those special widgets with no XWindow of
it's own, that therefor will not receive configure_events. I added my table
to an eventbox as mentioned in one of the tutorials, but I am not receiving
any configure events there either. I tried adding the button_press_event
for a sanity check, and it is working fine. I expect that the configure
event should occur when I resize my main window and the table expands as
it's container does (the column spacing increases).
I am using libglade to build the interface, and am experimenting with
aggregation (vs. inheritance) for my object model. To connect the signals,
the WidgetWrapper base class calls: signal_autoconnect(self) on the newly
constructed aggregate widget (and this is working well for the other
widgets, as well as for the button_press_event handler in this widget).
I've removed some superfluous code from the following example for clarity
(and it certainly isn't usable without all the requisite other classes). I
did confirm that "on_configure_event" is the name I gave the handler in
glade, and I even tried connecting it manually via widget.connect() with the
same results.
Can someone offer some insight as to what I might be doing wrong? Is my
entire approach just not appropriate for pygtk?
Thanks,
# Class aggregrating EventBox and Table to list contexts for tasks
class ContextTable(WidgetWrapper):
# widget: the eventbox
def __init__(self, widget, contexts):
WidgetWrapper.__init__(self, widget)
self.table =3D gtk.Table()
self.widget.add(self.table)
self.table.show()
self.context_cbs =3D {}
for c in contexts:
cb =3D gtk.CheckButton(c)
cb.connect("toggled", self.on_checkbutton_toggled)
self.context_cbs[context] =3D cb
widget.add_events(gtk.gdk.STRUCTURE_MASK)
widget.add_events(gtk.gdk.BUTTON_PRESS_MASK)
print "Events: ", widget.get_property("events")
self.resize()
def resize(self):
# determine the widest cell needed and remove table children as we
go
max_width =3D 0
for c, cb in self.context_cbs.iteritems():
w =3D cb.size_request()[0]
if w > max_width:
max_width =3D w
if cb.parent:
self.table.remove(cb)
# resize it
pitch =3D self.widget.allocation.width / max_width
self.table.resize(pitch, len(self.context_cbs)/pitch + 1)
pitch =3D self.table.get_property("n-rows")
i=3D0
for c, cb in self.context_cbs.iteritems():
x =3D i % pitch
y =3D i / pitch
self.table.attach(cb, x, x+1, y, y+1)
cb.show()
i =3D i + 1
# eventbox callbacks
# this callback never get's called
def on_configure_event(self, widget, event):
print "EVENT: ", event
print "event.width: ", event.width
return True
# debug only, deleteme when configure_events are working
# this callback works
def on_button_press_event(self, event, other):
print "Button pressed"
self.resize()
return True
-- =
Darren Hart
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20070814/53910992/at=
tachment.htm
More information about the pygtk
mailing list