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 = gtk.Table()
        self.widget.add(self.table)
        self.table.show()
        self.context_cbs = {}

        for c in contexts:
            cb = gtk.CheckButton(c)
            cb.connect("toggled", self.on_checkbutton_toggled)
            self.context_cbs[context] = 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 = 0
        for c, cb in self.context_cbs.iteritems():
            w = cb.size_request()[0]
            if w > max_width:
                max_width = w
            if cb.parent:
                self.table.remove(cb)

        # resize it
        pitch = self.widget.allocation.width / max_width
        self.table.resize(pitch, len(self.context_cbs)/pitch + 1)

        pitch = self.table.get_property("n-rows")
        i=0
        for c, cb in self.context_cbs.iteritems():
            x = i % pitch
            y = i / pitch
            self.table.attach(cb, x, x+1, y, y+1)
            cb.show()
            i = 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
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to