GtkSpinButton Constructor

GtkSpinButton Constructor

GtkSpinButton ([ GtkAdjustment adjustment = NULL , [double climb_rate = 0.0 , [int digits = 0 ]]]);

Although the first parameter adjustment is optional, you will find it impossible to create a working GtkSpinButton without harnessing it to an appropriately defined GtkAdjustment, as the first five parameters of the adjustment need to be set for the spinbutton widget to operate. You may either associate the adjustment at this point, or use the set_adjustment() or configure() method at a later point in your script.

climb_rate refers to the speed of the spin, rather than its incremental value. Its default setting is 0.0, which runs the internal timer at 20ms per increment (following a 200ms start from the button press). If you intend using this parameter, the value given needs to be fairly high in order for it to make an appreciable difference.

The digits parameter controls the number of decimal places displayed.

Example 40. Creating a GtkSpinButton calendar.

<?php

dl('php_gtk.' . (strstr(PHP_OS, 'WIN') ? 'dll' : 'so'));

function collect($d, $m, $y) {
  echo $d->get_value_as_int(). "-" .$m->get_value_as_int(). 
"-" .$y->get_value_as_int()."\n";
  flush();
}

$window = &new GtkWindow();
$window->set_position(GTK_WIN_POS_CENTER);
$window->connect_object('destroy', array('gtk', 'main_quit'));

$vbox = &new GtkVBox(false, 5);
$window->add($vbox);

$hbox = &new GtkHBox(false, 5);
$hbox->set_border_width(5);
$vbox->add($hbox);

$daylabel = &new GtkLabel("Day:");
$hbox->pack_start($daylabel, false);

$day = date("d");
$dayadj = &new GtkAdjustment($day, 1.0, 31.0, 1.0, 7.0, 0.0);
$dayspin = &new GtkSpinButton($dayadj);
$dayspin->set_wrap(true);
$hbox->pack_start($dayspin, false);

$monthlabel = &new GtkLabel("Month:");
$hbox->pack_start($monthlabel, false);

$month = date("m");
$monthadj = &new GtkAdjustment($month, 1.0, 12.0, 1.0, 3.0, 0.0);
$monthspin = &new GtkSpinButton($monthadj);
$monthspin->set_wrap(true);
$hbox->pack_start($monthspin, false);

$yearlabel = &new GtkLabel("Year:");
$hbox->pack_start($yearlabel, false);

$year = date("Y");
$yearadj = &new GtkAdjustment($year, $year-90, $year+10, 1.0, 5.0, 0.0);
$yearspin = &new GtkSpinButton($yearadj);
$yearspin->set_usize(55, 0);
$hbox->pack_start($yearspin, false);

$button = &new GtkButton("Collect data");
$button->connect_object('clicked', 'collect', $dayspin, $monthspin, 
$yearspin);
$vbox->add($button);

$vbox->show_all();
$hbox->show_all();
$window->show_all();

gtk::main();

?>
See also: GtkAdjustment's "value-changed" signal.

© Copyright 2003-2023 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.