On Thu, 15 Mar 2001, Prabhu Ramachandran wrote:
> hi,
>
> This might be a stupid question, but I have spend hours playing with
> things, looking at docs etc. Basically, I want to capture a
> configure_event for some Gtk widget that I derive a class from. I
> find that apart from the GtDrawingArea none of the other widgets are
> able to emit the 'configure_event'. Each widget seems to have its own
> quirks. I did do a
>
> self.add_events (GDK.ALL_EVENTS_MASK)
>
> so that it can handle all events. Attached at the end is the code.
> Change TESTWID at the top to look at the events that the particular
> widget can handle.
>
> Would appreciate if someone could explain why it behaves like this.
> Believe me, I have looked far and wide for explanations! I am not on
> the pyGtk list so please CC me in on any messages.
>
> I am sorry that this mail is long, I thought that the code might be
> useful to some folks.
Well, given that not all widgets have their own windows (GtkLabels come to
mind), using configure_event is not the most reliable signal.
I would recommend using the size_allocate signal, which is used in the
geometry management code of GTK. This signal takes a single argument -- a
GtkAllocation structure. Unfortunately, this signal argument is just
marked as a pointer in the gtk code, so is inaccessible to python (pygtk
just hands you an opaque cobject).
To get around this, connect to size_allocate with connect_after, so that
your handler gets called after the class handler (which sets the
widget->allocation pointer), and use the get_allocation() method I added
for accessing the allocation. So your code may look like this:
def size_allocate(widget, allocation):
x, y, width, height = widget.get_allocation()
# do what you want here
widget.connect_after("size_allocate", size_allocate)
James.
--
Email: [EMAIL PROTECTED]
WWW: http://www.daa.com.au/~james/
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk