-
$window = new GtkWindow();$window->connect_simple('destroy', array('Gtk','main_quit'));$window->set_size_request(400, 200);$window->add($vbox = new GtkVBox());// 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',true, 2, 3.1),array('row1', 'item 1',true, 20, 6.21),array('row2', 'item 1',true, 8, 9.36),array('row3', 'item 1',true, 11, 12.4),array('row4', 'item 1',true, 5, 15.5),array('row5', 'item 1',true, 17, 18.6),array('row6', 'item 1',true, 20, 21.73));display_table ($scrolled_win, $data);$window->show_all();Gtk::main();function display_table($scrolled_win, $data) {global $model, $view;$model = new GtkListStore(Gtk::TYPE_STRING, Gtk::TYPE_STRING, GTK::TYPE_BOOLEAN,Gtk::TYPE_LONG, Gtk::TYPE_DOUBLE);$field_header = array('Row #','Description', 'check', 'Qty', 'Price');$field_justification = array(0,0, 0, 0.5, 1);$modelsort = new GtkTreeModelSort($model); // note 1$view = new GtkTreeView($modelsort); // note 3$scrolled_win->add($view);// Creates the columnsfor ($col=0; $colif ($field_header[$col] == 'check') {$render = new GtkCellRendererToggle();$render->set_property('activatable', true);$render->connect('toggled', 'on_toggle',$modelsort);$column = new GtkTreeViewColumn($field_header[$col],$render,'active',$col);$column->set_alignment($field_justification[$col]);}else{$cell_renderer = new GtkCellRendererText();$cell_renderer->set_property("xalign", $field_justification[$col]);$column = new GtkTreeViewColumn($field_header[$col], $cell_renderer, 'text', $col);$column->set_alignment($field_justification[$col]);$column->set_sort_column_id($col);}$view->append_column($column);}// pupulates the datafor ($row=0; $row$values = array();for ($col=0; $col$values[] = $data[$row][$col];}$model->append($values);}}//function for checkboxfunction on_toggle($renderer, $row, $modelsort) {$sortiter = $modelsort->get_iter($row);$model = $modelsort -> get_model();$iter = $modelsort -> convert_iter_to_child_iter($sortiter);$model->set($iter, 2,!$model->get_value($iter, 2));}
PermaLink to this entry https://pastebin.co.uk/10168
Posted by paranomos Fri 9th Feb 2007 16:10 - Syntax is None/text - 330 views
Download | New Post | Modify | Hide line numbers
Posted by paranomos Fri 9th Feb 2007 16:10 - Syntax is None/text - 330 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
Description:
when description column is sorted and try to press the checkbox weired things
happen
when description column is sorted and try to press the checkbox weired things
happen
Comments: 0