Re: GtkAdjustment and GtkSpinButton question



On Wednesday, August 13, 2003, at 07:56 PM, Matthew Weier OPhinney wrote:

Here's what I've got going. I'm pulling data from an XML file using
XML::DOM. To ensure that I'm getting integers to pass to
Gtk2::SpinButton's max and min values, I'm using something like:

    my $min = int($node->getAttribute('min'));
    my $max = int($node->getAttribute('max'));
    my $val = $option->{int_value}; # this is already an integer
    my $step = $node->getAttribute('step');

    ($step) ? $step = int($step) : $step = 1;

    my $spin = Gtk2:SpinButton->new_with_range($min, $max, $step);
    $spin->set_value($val);

And that's not working. I've even setup some print statements to make
sure that it's getting proper values (it is), but the value isn't being
set.

Oddly enough, if I set the value *later*, i.e. after it's been
manipulated, it *will* take. Go figure.

Any ideas?

i can't reproduce your problem unless the value i try to set is outside the range of min and max.

this test program:

-=-=-=-
use Gtk2 -init;

$win = Gtk2::Window->new;
$win->signal_connect (delete_event => sub {Gtk2->main_quit; 1});
$win->set_border_width (16);

$vbox = Gtk2::VBox->new;
$vbox->pack_start (Gtk2::Label->new ("wait, this wednesday?"), 1, 1, 0);

$spin = Gtk2::SpinButton->new_with_range (10, 50, 5);
$spin->signal_connect (value_changed => sub {print $_[0]->get_value."\n";});
$spin->set_value (25);
print "after set_value\n";

$vbox->pack_start ($spin, 1, 1, 0);
$win->add ($vbox);
$win->show_all;
Gtk2->main;
-=-=-=-

prints out

 25
 after set_value

so it sets the new value before the widget is shown (as expected, because an adjustment doesn't need to be displayed to change its value).

if i supply 5 to set_value instead of 25, the number doesn't print out, as though the callback doesn't run, and the value is set to 10, which is the minval.

you set up print statements to see that the correct values were getting in --- where were they? what kinds of values were they?


(I should probably upgrade to 0.92 to see if the error still happens
there... I'm on 0.90 -- unless no changes have been made to this
portion...)

according to cvsweb, neither GtkSpinButton.xs nor GtkAdjustment.xs has changed in two months. in fact, the majority of files in Gtk2 has not changed since the copyright notices that were added in 0.20.




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