Exemple #1
0
<?php

//Create new store with two columns
$store = new GtkListStore(Gobject::TYPE_STRING, Gobject::TYPE_LONG);
//insert the rows at different positions
$store->insert(1, array('Tokio', 34100000));
$store->insert(0, array('Mexico city', 22650000));
//use the iterator to set the data after insertion
$iter = $store->insert(1);
$store->set($iter, 0, 'Seoul', 1, 22250000);
$iter = $listStore->append(array('Crisscott T-Shirts', 10, 19.95));
$iter = $listStore->prepend(array('PHP-GTK Bumper Stickers', 37, 1.99));
$iter = $listStore->prepend(array('Pro PHP-GTK', 23, 44.95));
/**
 * Weird issue 1:
 * When the array is initialized to another array first
 * there is not problem, but if the array is created inside
 * the call to insert, it fails with the following message:

(listing9-3.php:1918): GLib-GObject-WARNING **: gvalue.c:89: cannot initialize GValue with type `gdouble', the value has already been initialized as `(null)'
PHP Warning:  PHP-GTK internal error: unsupported type (null) in /home/scott/authoring/Apress/chapter9/listing9-3.php on line 23
PHP Warning:  Cannot set row: type of element 2 does not match the model in /home/scott/authoring/Apress/chapter9/listing9-3.php on line 23

(listing9-3.php:1918): GLib-GObject-CRITICAL **: g_value_unset: assertion `G_IS_VALUE (value)' failed
*/
$iter = $listStore->insert(2, array('Crisscott Pencils', 18, 0.99));
// Comment the above line and uncomment these two to test.
//$tmp = array('Crisscott Pencils', 18, .99);
//$iter = $listStore->insert(2, $tmp);
/**
 * Weird issue 2:
 * If insert is called twice, weird issue 1 is not a problem.
 * Uncomment the two following lines to test. 
 * Make sure weird issue 1 is commented just to isolate the
 * issue.
 */
//$iter = $listStore->insert(2, array('Crisscott Pencils', 18, .99));
//$iter = $listStore->insert(3, array('Crisscott Pens', 18, .99));
// Create a veiw to show the list.
$view = new GtkTreeView();
$view->set_model($listStore);
Exemple #3
0
<?php

$store = new GtkListStore(Gobject::TYPE_STRING, Gobject::TYPE_LONG);
//insert the rows at different positions
$tokio = $store->insert(0, array('Tokio', 34100000));
$mexico = $store->insert(1, array('Mexico city', 22650000));
//we swap so that mexico is first
$store->swap($tokio, $mexico);
//show the list
function echoRow($store, $path, $iter)
{
    echo $store->get_value($iter, 0) . "\r\n";
}
$store->foreach('echoRow');
Exemple #4
0
<?php

$store = new GtkListStore(Gobject::TYPE_STRING, Gobject::TYPE_LONG);
$tokio = $store->insert(0, array('Tokio', 34100000));
$mexico = $store->insert(1, array('Mexico city', 22650000));
$seoul = $store->insert(2, array('Seoul', 22250000));
//move Seoul before Mexico
$store->move_before($seoul, $mexico);
//show the list
function echoRow($store, $path, $iter)
{
    echo $store->get_value($iter, 0) . "\r\n";
}
$store->foreach('echoRow');