Re: Gtk2::CellRendererSpinButton-Z

On Mar 6, 2006, at 3:57 PM, zentara wrote:

Here is a working package, for the

It sets initial value, updates itself, and sets
new initial value at each edit.

I use a package global to hold the current value,
and if anyone knows a better way, my ears are open. :-)

You don't need the global at all. You pass the new value through the "new value" parameter of the edited signal. The cell renderer should not alter its own value --- that's for client code to do, if desired, in the "edited" callback. (Definitely "if desired" -- imagine a situation in which the SpinButton is used in a TreeView using a custom TreeModel, whose data actually reflects state elsewhere in the system. In this situation, having the CellRenderer set the value directly on the model may be quite bad. This is always left for the client code to perform.)

I simply removed from your new code all lines that refer to $cur_val, and it all works as expected. In fact, if you press Enter in the spinbutton after editing, the 'edited' signal gets emitted twice --- once explictly from key-press-event., and again from focus-out-event as the cell editor is being destroyed.

The original code required you to press "Enter" to "commit" the value, and allowed you to press "Esc" to cancel changing it. If you don't care about the distinction, then you don't even need to handle "Enter" specially, and can just rely on the focus-out-event.

    my ($self, $pspec, $val) = @_;
    $self->{ $pspec->get_name  } = $val;

# set the initial editing value
 if ($pspec->get_name eq 'value') {
        $cur_val = $val;

After you remove the global, you have a SET_PROPERTY which is merely a perl implementation of what the XS code already does.

And then mama would throw the live crawdads in the boilin' water. And one day I decided I'd make my own crawdads. So I threw the crawdads in the pot, but without any water. It was just like makin' popcorn.
   -- Ear-bending cellmate, "Raising Arizona"

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]