version=pmwiki-1.0.5 newline=² text=[[include:Main/CodeTable]]set_title('ListStoreExample');² $this->connect_simple('destroy', array('gtk', 'main_quit'));² $this->set_position(Gtk::WIN_POS_CENTER);² $this->set_size_request(600, 300);²² $vbox = new GtkVbox(); ² $this->add($vbox);²² # a label on top² $label = new GtkLabel("Gtk ListStore Example");² $vbox->pack_start($label, false, false);²²² # a scrolled windows² $sw = new GtkScrolledWindow();² $sw->set_shadow_type(Gtk::SHADOW_ETCHED_IN);² $sw->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);²² $vbox->pack_start($sw);²² $model = $this->_create_model();² $tree_view = new GtkTreeView($model);² $tree_view->set_rules_hint(true);² $tree_view->set_search_column(COLUMN_DESCRIPTION);²² $sw->add($tree_view);²² $this->_add_colums($tree_view);² $this->show_all();² }²² function _create_model(){² global $data;²² $list_store = new GtkListStore(Gtk::TYPE_BOOLEAN, Gtk::TYPE_STRING, Gtk::TYPE_STRING, Gtk::TYPE_STRING);²² foreach($data as $rec){² $list_store->append($rec);² }²² return $list_store;² }²² function fixed_toggled($cell, $path, $model){² # get toggled iter² $iter = $model->get_iter((int)$path);² $fixed = $model->get_value($iter, COLUMN_FIXED);² ² # do something with the value² $fixed = ! $fixed;² echo "path = $path\n";² # set new value² $model->set($iter, COLUMN_FIXED, $fixed);² }²² function _add_colums($tree_view){² $model = $tree_view->get_model();²² $renderer = new GtkCellRendererToggle();² $renderer->connect('toggled', array($this, 'fixed_toggled') , $model);²² # $column = new GtkTreeViewColumn('Fixed', $renderer, $active=COLUMN_FIXED);² $column = new GtkTreeViewColumn("Fixed", $renderer, "active", COLUMN_FIXED);²² # set this column to a fixed sizing(of 50 pixels)² $column->set_sizing(Gtk::TREE_VIEW_COLUMN_FIXED);² $column->set_fixed_width(50);² ² $tree_view->append_column($column);²² # column for bug numbers² $column = new GtkTreeViewColumn('Bug Number', new GtkCellRendererText(), "text", COLUMN_NUMBER);² $column->set_sort_column_id(COLUMN_NUMBER);² $tree_view->append_column($column);²² # columns for severities² $column = new GtkTreeViewColumn('Severity', new GtkCellRendererText(), 'text', COLUMN_SEVERITY);² $column->set_sort_column_id(COLUMN_SEVERITY);² $tree_view->append_column($column);²² # column for description² $column = new GtkTreeViewColumn('Description', new GtkCellRendererText(), 'text', COLUMN_DESCRIPTION);² $column->set_sort_column_id(COLUMN_DESCRIPTION);² $tree_view->append_column($column);²² }²}² ²new ListStoreExample();²Gtk::main();²²²?>[[include:Main/CodeTableEnd]]²²!!! usefull links²* http://www.writingup.com/phpgtk2/0033_a_data_store_for_the_gtkcombobox²* http://www.writingup.com/phpgtk2/0027_introduction_to_the_gtktreeview_part_2²* http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/index.html² time=1157643280 diff:1157643280:1157643280:=1,131c1²< [[include:Main/CodeTable]]set_title('ListStoreExample');²< $this->connect_simple('destroy', array('gtk', 'main_quit'));²< $this->set_position(Gtk::WIN_POS_CENTER);²< $this->set_size_request(600, 300);²< ²< $vbox = new GtkVbox(); ²< $this->add($vbox);²< ²< # a label on top²< $label = new GtkLabel("Gtk ListStore Example");²< $vbox->pack_start($label, false, false);²< ²< ²< # a scrolled windows²< $sw = new GtkScrolledWindow();²< $sw->set_shadow_type(Gtk::SHADOW_ETCHED_IN);²< $sw->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);²< ²< $vbox->pack_start($sw);²< ²< $model = $this->_create_model();²< $tree_view = new GtkTreeView($model);²< $tree_view->set_rules_hint(true);²< $tree_view->set_search_column(COLUMN_DESCRIPTION);²< ²< $sw->add($tree_view);²< ²< $this->_add_colums($tree_view);²< $this->show_all();²< }²< ²< function _create_model(){²< global $data;²< ²< $list_store = new GtkListStore(Gtk::TYPE_BOOLEAN, Gtk::TYPE_STRING, Gtk::TYPE_STRING, Gtk::TYPE_STRING);²< ²< foreach($data as $rec){²< $list_store->append($rec);²< }²< ²< return $list_store;²< }²< ²< function fixed_toggled($cell, $path, $model){²< # get toggled iter²< $iter = $model->get_iter((int)$path);²< $fixed = $model->get_value($iter, COLUMN_FIXED);²< ²< # do something with the value²< $fixed = ! $fixed;²< echo "path = $path\n";²< # set new value²< $model->set($iter, COLUMN_FIXED, $fixed);²< }²< ²< function _add_colums($tree_view){²< $model = $tree_view->get_model();²< ²< $renderer = new GtkCellRendererToggle();²< $renderer->connect('toggled', array($this, 'fixed_toggled') , $model);²< ²< # $column = new GtkTreeViewColumn('Fixed', $renderer, $active=COLUMN_FIXED);²< $column = new GtkTreeViewColumn("Fixed", $renderer, "active", COLUMN_FIXED);²< ²< # set this column to a fixed sizing(of 50 pixels)²< $column->set_sizing(Gtk::TREE_VIEW_COLUMN_FIXED);²< $column->set_fixed_width(50);²< ²< $tree_view->append_column($column);²< ²< # column for bug numbers²< $column = new GtkTreeViewColumn('Bug Number', new GtkCellRendererText(), "text", COLUMN_NUMBER);²< $column->set_sort_column_id(COLUMN_NUMBER);²< $tree_view->append_column($column);²< ²< # columns for severities²< $column = new GtkTreeViewColumn('Severity', new GtkCellRendererText(), 'text', COLUMN_SEVERITY);²< $column->set_sort_column_id(COLUMN_SEVERITY);²< $tree_view->append_column($column);²< ²< # column for description²< $column = new GtkTreeViewColumn('Description', new GtkCellRendererText(), 'text', COLUMN_DESCRIPTION);²< $column->set_sort_column_id(COLUMN_DESCRIPTION);²< $tree_view->append_column($column);²< ²< }²< }²< ²< new ListStoreExample();²< Gtk::main();²< ²< ²< ?>[[include:Main/CodeTableEnd]]²< ²< !!! usefull links²< * http://www.writingup.com/phpgtk2/0033_a_data_store_for_the_gtkcombobox²< * http://www.writingup.com/phpgtk2/0027_introduction_to_the_gtktreeview_part_2²< * http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/index.html²---²> Describe GtkTreeViewListStore here.²\ No newline at end of file² author=Marc Quinton author:1157643280=Marc Quinton host:1157643280=143.196.162.107 name=CodeSnippets.GtkTreeViewListStore host=143.196.162.107 agent=Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041217 rev=1