[pygtk] Callbacks
Walter Leibbrandt
walter at translate.org.za
Wed Mar 11 22:31:09 WST 2009
Hi,
Maybe I should just let some code do the talking. See attached script.
The button's "clicked" handler adds an "x" to the entry. The toggle
button uses handler_(un)block_by_func() on addx_clicked so that it is
only enabled if the toggle button is active. Note that
handler_(un)block_by_func() was called on btn, seeing as that is the
widget to which the handler is connected.
This is quite an exciting discovery for myself too. Seeing as its in
GObject and not in Glade, I can use this with my custom widgets too and
need not keep signal dictionaries anymore! :)
P.S. In this context "handler" means the function/method connected to a
signal.
Peyman wrote:
> Hi Walter
>
> I am running into problems using it. To use
> handler_bloc_by_func(callable) you have to pass callable: a callable
> python object. I have tried using the widget itself, and it's callback
> functions, but neither is working. What exactly do i have to pass as a
> parameter. You made reference to passing the "handler" to it.
>
> Cheers
>
>
>
> Peyman Askari
>
> On 11 Mar 2009, at 12:53, Walter Leibbrandt wrote:
>
>> Hi,
>>
>> It seems that this has been asked before:
>> http://osdir.com/ml/gnome.gtk+.python/2003-04/msg00089.html
>>
>> Short answer: no, it doesn't seem like you can. I have, however,
>> found the handler_block_by_func() and handler_unblock_by_func()
>> methods of gobject.GObject. Although I haven't tested this yet, it
>> seems from the docs
>> (http://library.gnome.org/devel/pygobject/stable/class-gobject.html#method-gobject--handler-block-by-func)
>> that you can simply pass your handler to it to (un)block it from
>> being called.
>>
>> Let me know how/if it works.
>>
>> HTH,
>>
>> Peyman wrote:
>>> I realize that once you call connect() it returns the handle_id. But
>>> if glade is doing this for me, are the handle id's stored somewhere?
>>> Surely there has to be a widget.get_handle_id('callback_function')
>>> method. I can't seem to find anything on this over the net though.
>>
>> --
>> Walter Leibbrandt http://translate.org.za/blogs/walter
>> Software Developer +27 12 460 1095 (w)
>> Translate.org.za
>>
>> Recent blogs:
>> * Firefox-style button with a pop-up menu
>> http://www.translate.org.za/blogs/walter/en/content/firefox-style-button-pop-menu
>>
>> * Virtaal's MVCisation
>> * Things that changed the way I code
>>
>>
>
--
Walter Leibbrandt http://translate.org.za/blogs/walter
Software Developer +27 12 460 1095 (w)
Translate.org.za
Recent blogs:
* Firefox-style button with a pop-up menu
http://www.translate.org.za/blogs/walter/en/content/firefox-style-button-pop-menu
* Virtaal's MVCisation
* Things that changed the way I code
-------------- next part --------------
A non-text attachment was scrubbed...
Name: handlers_test.py
Type: text/x-python
Size: 589 bytes
Desc: not available
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20090311/fbbf50b0/attachment-0001.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gui.glade
Type: application/x-glade
Size: 1654 bytes
Desc: not available
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20090311/fbbf50b0/attachment-0001.bin
More information about the pygtk
mailing list