[pygtk] Setting value of gtk.SpinButton without triggering the "value-changed" event.

Osmo Maatta osmoma at gmail.com
Sat Nov 22 05:52:46 WST 2008


Hello and thanks for the answers for both Daniel and Paul.

I chose to use the signal blocking/unblocking method.
I now add a new data attribute "value-changed-signal" to the spin 
button. The data value contains the signal handler id which I can later 
read and use. The code looks like this:

        adj = gtk.Adjustment(orig_width, 1, orig_width, 1, 50, 0)
        self.width_spin = gtk.SpinButton(adj, climb_rate=0.0, digits=0)
        self.width_spin.show()
        self.width_spin.set_numeric(True)

        # Save the signal handler to "value-changed-signal" attribute.
        self.width_spin.set_data("value-changed-signal", 
self.width_spin.connect("value-changed", 
self.image_size_changed_callback, None))


and later in...

def some_function()
     # Block signals
    
 self.width_spin.handler_block(self.width_spin.get_data("value-changed-signal"))
     self.width_spin.set_value(some_value)
     # Unblock signals
    
 self.width_spin.handler_unblock(self.width_spin.get_data("value-changed-signal"))

Ok, thanks for now :-)
Osmo Antero

Daniel Hernández Bahr wrote:
> I guess you can always do:
> self.width_spin.freeze_child_notify()
> self.width_spin.set_value(some_value)
> self.width_spin.thaw_child_notify()
>
> cheers
> ----- Original Message -----
> From: "Osmo Maatta" <osmoma at gmail.com>
> To: pygtk at daa.com.au
> Sent: Friday, November 21, 2008 2:52:53 PM (GMT-0500) Auto-Detected
> Subject: [pygtk] Setting value of gtk.SpinButton without triggering 
> the "value-changed" event.
>
> Hello,
>
> I need to change the self.width_spin (gtk.SpinButton) value, but in 
> some cases I do not want the changed event to fire. How do I set the 
> value?  This is my code:
>
>         adj = gtk.Adjustment(orig_width, 1, orig_width, 1, 50, 0)
>         self.width_spin = gtk.SpinButton(adj, climb_rate=0.0, digits=0)
>         self.width_spin.show()
>         self.width_spin.set_numeric(True)
>         self.width_spin.connect(*"value-changed"*, 
> self.image_size_changed_callback, "width")
>         hbox1.pack_start(self.width_spin, False, False, 0)
>
> This call will trigger the *"value-changed"* event so I want to avoid it.
>     self.width_spin.set_value(some_value)
>
> gtk.SpinButton is derived from gtk.Entry, so if I could grab the entry 
> field from gtk.SpinButton so it may be possible to write:
> entry.set_data("value", some_value)
>
> Do you know how to do this right?
>
> Am writing a filter/resize/and scale plugin in Python for my 
> screendump program http://bildr.no/view/291282. Screendump is written 
> in GTK and c.
>
> TIA
>   Osmo Antero (moma)
>   Oslo
>
> _______________________________________________ pygtk mailing list 
> pygtk at daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the 
> PyGTK FAQ: http://faq.pygtk.org/
>
> -- 
> Daniel Hernández Bahr
> Universidad de las Ciencias Informáticas.
>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20081121/7626c660/attachment-0001.htm 


More information about the pygtk mailing list