Re: gtkcellrenderercombo
| From: | kksou | Date: | Mon, 25 Sep 2006 03:56:19 +0000 |
| Subject: | Re: gtkcellrenderercombo | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-7266@lists.php.net to get a copy of this message | ||
Hi Sven,
You didn't include some of your other codes. So it's hard to tell what went
wrong.
But I've included a sample code that uses GtkCellRendererCombo below. You
might want to compare with yours and see which part is the missing link.
If you're interested to know how to process after user has selected a value
from the combobox, I've also written another sample code here:
http://www.kksou.com/php-gtk2/articles/use-GtkCellRendererCombo---Part-2---process-combobox.php
<?php
$window = new GtkWindow();
$window->set_size_request(400, 200);
$window->connect_simple('destroy', array('Gtk','main_quit'));
$window->add($vbox = new GtkVBox());
// display title
$title = new GtkLabel("Using GtkCellRendererCombo - Part 1 (Setup)");
$title->modify_font(new PangoFontDescription("Times New Roman Italic 10"));
$title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff"));
$title->set_size_request(-1, 40);
$vbox->pack_start($title, 0, 0);
$vbox->pack_start(new GtkLabel(), 0, 0); // add a small gap between the
title and scroll_win
// Set up a scroll window
$scrolled_win = &new GtkScrolledWindow();
$scrolled_win->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
$vbox->pack_start($scrolled_win);
// the 2D table
$data = array(
array('row0', 'item 1', 2, 3.1),
array('row1', 'item 4', 5, 6.21),
array('row2', 'item 7', 8, 9.36),
array('row3', 'item 10', 11, 12.4),
array('row4', 'item 13', 14, 15.5),
array('row5', 'item 16', 17, 18.6),
array('row6', 'item 19', 20, 21.73));
display_table ($scrolled_win, $data);
function display_table($scrolled_win, $data) {
// Creates the list store
$model = new GtkListStore(Gtk::TYPE_STRING, Gtk::TYPE_STRING,
Gtk::TYPE_LONG, Gtk::TYPE_DOUBLE, Gtk::TYPE_STRING);
$field_header = array('Row #', 'Description', 'Qty',
'Price');
// Creates the view to display the list store
$view = new GtkTreeView($model);
$scrolled_win->add($view);
// Creates columns
for ($col=0; $col<count($field_header); ++$col) {
$cell_renderer = new GtkCellRendererText();
$column = new GtkTreeViewColumn($field_header[$col], $cell_renderer,
'text', $col);
$view->append_column($column);
}
// Set up the combobox
$cell_renderer = new GtkCellRendererCombo(); // create a new combobox
renderer
$category = new GtkListStore(Gtk::TYPE_STRING); // create a liststore to
store the categories
$list = array('grp 1', 'grp 2', 'grp 3', 'grp 4'); //
pre-defined
categories
foreach($list as $choice) {
$category->append(array($choice)); // stuff them in the model
}
$cell_renderer->set_property('model', $category); // note 1
$cell_renderer->set_property('text-column', 0); // '0' refers to the 1st
col in $category
$cell_renderer->set_property('editable', true); // allow user to change
value
$cell_renderer->set_property('has-entry', true); // note 2
$column = new GtkTreeViewColumn('Category', $cell_renderer, 'text', 4);
// create a column for category
$view->append_column($column); // and add it to the tree view
// pupulates the data
for ($row=0; $row<count($data); ++$row) { // note our $data only
contains value for columns 0 to 3
$values = array();
for ($col=0; $col<count($data[$row]); ++$col) {
$values[] = $data[$row][$col];
}
$values[] = ''; // set category to be '' first
$model->append($values); // stuff the values into the data model
}
}
$window->show_all();
Gtk::main();
?>
Sample output:
http://www.kksou.com/php-gtk2/gif/0034.gif
Have included a bit more explanation here:
http://www.kksou.com/php-gtk2/articles/use-GtkCellRendererCombo---Part-1---setup.php
--
View this message in context: http://www.nabble.com/gtkcellrenderercombo-tf2326083.html#a6479938
Sent from the Php - GTK - General mailing list archive at Nabble.com.