CodeSnippets.GtkTreeViewListStore 9.2 KB

123456789101112
  1. version=pmwiki-1.0.5
  2. newline=²
  3. text=[[include:Main/CodeTable]]<?php²#²# example from python gtk demo : list_store.py²#²²define('COLUMN_FIXED', 0);²define('COLUMN_NUMBER', 1);²define('COLUMN_SEVERITY', 2);²define('COLUMN_DESCRIPTION', 3);²²²$data = array(² array(False, 60482, 'Normal', 'scrollable notebooks and hidden tabs'),² array(False, 60620, 'Critical', 'gdk_window_clear_area(gdkwindow-win32.c) is not thread-safe'),² array(False, 50214, 'Major', 'Xft support does not clean up correctly'),² array(True, 52877, 'Major', 'GtkFileSelection needs a refresh method. '),² array(False, 56070, 'Normal', "Can't click button after setting in sensitive"),² array(True, 56355, 'Normal', 'GtkLabel - Not all changes propagate correctly'),² array(False, 50055, 'Normal', 'Rework width/height computations for TreeView'),² array(False, 58278, 'Normal', "gtk_dialog_set_response_sensitive() doesn't work"),² array(False, 55767, 'Normal', 'Getters for all setters'),² array(False, 56925, 'Normal', 'Gtkcalender size'),² array(False, 56221, 'Normal', 'Selectable label needs right-click copy menu'),² array(True, 50939, 'Normal', 'Add shift clicking to GtkTextView'),² array(False, 6112, 'Enhancement', 'netscape-like collapsable toolbars'),² array(False, 1, 'Normal', 'First bug :=)')²);²²class ListStoreExample extends GtkWindow²{² function __construct()² {² parent::__construct();² $this->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²
  4. time=1157643280
  5. diff:1157643280:1157643280:=1,131c1²< [[include:Main/CodeTable]]<?php²< #²< # example from python gtk demo : list_store.py²< #²< ²< define('COLUMN_FIXED', 0);²< define('COLUMN_NUMBER', 1);²< define('COLUMN_SEVERITY', 2);²< define('COLUMN_DESCRIPTION', 3);²< ²< ²< $data = array(²< array(False, 60482, 'Normal', 'scrollable notebooks and hidden tabs'),²< array(False, 60620, 'Critical', 'gdk_window_clear_area(gdkwindow-win32.c) is not thread-safe'),²< array(False, 50214, 'Major', 'Xft support does not clean up correctly'),²< array(True, 52877, 'Major', 'GtkFileSelection needs a refresh method. '),²< array(False, 56070, 'Normal', "Can't click button after setting in sensitive"),²< array(True, 56355, 'Normal', 'GtkLabel - Not all changes propagate correctly'),²< array(False, 50055, 'Normal', 'Rework width/height computations for TreeView'),²< array(False, 58278, 'Normal', "gtk_dialog_set_response_sensitive() doesn't work"),²< array(False, 55767, 'Normal', 'Getters for all setters'),²< array(False, 56925, 'Normal', 'Gtkcalender size'),²< array(False, 56221, 'Normal', 'Selectable label needs right-click copy menu'),²< array(True, 50939, 'Normal', 'Add shift clicking to GtkTextView'),²< array(False, 6112, 'Enhancement', 'netscape-like collapsable toolbars'),²< array(False, 1, 'Normal', 'First bug :=)')²< );²< ²< class ListStoreExample extends GtkWindow²< {²< function __construct()²< {²< parent::__construct();²< $this->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²
  6. author=Marc Quinton
  7. author:1157643280=Marc Quinton
  8. host:1157643280=143.196.162.107
  9. name=CodeSnippets.GtkTreeViewListStore
  10. host=143.196.162.107
  11. agent=Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041217
  12. rev=1