[pygtk] spinbutton set value and signal

Steve McClure smcclure at racemi.com
Thu Nov 6 23:10:15 WST 2008


On Nov 6, 2008, at 4:07 AM, Frédéric wrote:

>
> Le 6/11/2008, "Raúl Núñez de Arenas Coronado" <raul at dervishd.net> a
> écrit:
>
>> The call to "set_value()" emits the signal, but it won't be handled
>> until the next iteration of the GTK+ main loop, so if you do the
>> "stop_emission()" just after "set_value()", the signal just emited by
>> the "set_value()" call will be cancelled. If you call it before, the
>> signal won't be cancelled.
>>
>> It's very easy to test: add the call after your current "set_value()"
>> code and see if it works. You will be adding only one line of code,  
>> so
>> if it doesn't work (the docs are not very detailed...) you won't have
>> done big modifications to your code.
>
> I tried, but it does not work. In fact, I have a global GUI refresh
> method, called in my spinbutton handler. I call the stop_emission()
> method after that global refresh, where I have several set_value(),
> set_text() and so. As far as I understand, the stop_emission() call  
> will
> block only the first set_value() emited signal?

In the older GTK 1.x there was a  
widget.emit_stop_by_name('signal_name') call you could stop exactly  
the signal you wanted to ignore.  I just checked the FAQ and that call  
is still there so you could block set-value explicitly.  See http://pygtk.org/docs/pygobject/class-gobject.html
>
>
> When entering in a signal callback and calling a set_value() method,  
> is
> the value-changed signal emited/handled immediatly, or only at the end
> of the callback, after it returns?

I believe it is added to the queue of signals to be emitted, but the  
emission doesn't actually take place until you get back to the main  
loop processing. That is really how the stop methods are able to work.

>
>
>> Anyway, if you are going to use Glade a lot in your projects, try  
>> your
>> best to find a way of getting the handler_id. This message says it is
>> not possible, but it's from 2003 and maybe things have changed
>> http://osdir.com/ml/gnome.gtk+.python/2003-04/msg00092.html
>
> Didn't find a way yet :o(

And neither did I.  I just added them manually and moved on.   
Something like this:

self._handler_id = entryWid.connect('insert_text', self.on_insert_text)

Then during modification of the widget:

entryWid.signal_handler_block(self._handler_id)
entryWid.insert_text(allowed_new_text)
entryWid.signal_handler_unblock(self._handler_id)

>
>
>
> --
>   Frédéric
> _______________________________________________
> pygtk mailing list   pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>

--
Steve McClure
smcclure at racemi.com



More information about the pygtk mailing list