18 lines
12 KiB
Text
18 lines
12 KiB
Text
version=pmwiki-1.0.5
|
|
newline=²
|
|
text=!!! code usage :²²[[include:Main/CodeTable]]<?php²²include_once('PhpGtkListStore.php');²²# --------------------------------------------- your data and classes --------------------------------------------------²²$data_model = array(² array(² 'name' => 'Fixed',² 'render' => 'toggle', # toggle, text, progress, combo² 'type' => Gtk::TYPE_BOOLEAN, # Gtk::TYPE_STRING, Gtk::TYPE_DOUBLE, GdkPixbuf::gtype, Gtk::TYPE_BOOLEAN, ²² 'callback' => 'fixed_toggled',² 'callback_event' => 'toggled'² ),² array(² 'name' => 'Bug Number',² 'render' => 'text',² 'type' => Gtk::TYPE_STRING² ),² array(² 'name' => 'Severity',² 'render' => 'text',² 'type' => Gtk::TYPE_STRING² ),² array(² 'name' => 'Description',² 'render' => 'text',² 'type' => Gtk::TYPE_STRING² )²);²²$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 PhpGtkListStore{² function __construct($data_model, $data){² parent::__construct($data_model, $data);²² $this->set_title('PhpGtkListStore');² $this->connect_simple('destroy', array('gtk', 'main_quit'));² $this->set_position(Gtk::WIN_POS_CENTER);² $this->set_size_request(600, 300);²² # $this->tree_view->set_rules_hint(true);² # $this->tree_view->set_search_column(COLUMN_DESCRIPTION);²² }²² function fixed_toggled($cell, $path, $context){² list($model, $col) = $context;²² # get toggled iter² $iter = $model->get_iter((int)$path);² $fixed = $model->get_value($iter, $col);² ² # do something with the value² $fixed = ! $fixed;²² # set new value² $model->set($iter, $col, $fixed);² }²²}²²new ListStoreExample($data_model, $data);²Gtk::main();²²²?>[[include:Main/CodeTableEnd]]²²!!! library code²²[[include:Main/CodeTable]]<?php²²class PhpGtkListStore extends GtkWindow²{² protected $data;² protected $data_model;²² protected $sw; # scrolled window² protected $vbox;² protected $label;²² protected $model;² protected $tree_view;²² function __construct($data_model, $data)² {² parent::__construct();²² $this->data_model = $data_model;² $this->data = $data;²² $this->vbox = new GtkVbox(); ² $this->add($this->vbox);²² # a label on top² $this->label = new GtkLabel("Gtk ListStore Example");² $this->vbox->pack_start($this->label, false, false);²²² # a scrolled windows² $this->sw = new GtkScrolledWindow();² $this->sw->set_shadow_type(Gtk::SHADOW_ETCHED_IN);² $this->sw->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);²² $this->vbox->pack_start($this->sw);²² $this->model = $this->_create_model($this->data_model, $this->data);² $this->tree_view = new GtkTreeView($this->model);²² $this->sw->add($this->tree_view);²² $this->_add_colums($this->tree_view, $this->data_model);² $this->show_all();² }²² function _create_model($data_model, $data){²² $types = array();²² foreach($data_model as $rec){² $types[] = $rec['type'];² }²² # can't pass an arrau to GtkListStore constructor (so eval is the solution)² $code = sprintf('$list_store = new GtkListStore(%s);', join(',', $types));² eval ($code);²² foreach($data as $rec){² $list_store->append($rec);² }²² return $list_store;² }²² function _add_colums($tree_view, $data_model){² $renders = array(² 'text' => array(² 'class' => 'GtkCellRendererText',² 'field' => 'text'² ),² 'toggle' => array(² 'class' => 'GtkCellRendererToggle',² 'field' => 'active',² ),² 'progress' => array(² 'class' => 'GtkCellRendererProgress',² 'field' => 'value',² ),² 'combo' => array(² 'class' => 'GtkCellRendererCombo',² 'field' => 'text',² ),² 'pixbuf' => array(² 'class' => 'GtkCellRendererPixbuf',² 'field' => 'pixbuf',² )² );² $model = $tree_view->get_model();²² foreach($data_model as $key=>$info){²² $render = new $renders[$info['render']]['class']();² $column = new GtkTreeViewColumn(² $info['name'], $render, $renders[$info['render']]['field'], $key);²² $column->set_sort_column_id($key);² $tree_view->append_column($column);²² if(isset($info['callback'])){² $context = array($model, $key);² $render->connect($info['callback_event'], array($this, $info['callback']), $context);² }² }²² }²²}²²²?>[[include:Main/CodeTableEnd]]²²
|
|
time=1157983953
|
|
diff:1157983265:1157983265:=1,204c1²< !!! code usage :²< ²< [[include:Main/CodeTable]]<?php²< ²< include_once('PhpGtkListStore.php');²< ²< # --------------------------------------------- your data and classes --------------------------------------------------²< ²< define('COLUMN_FIXED', 0);²< define('COLUMN_NUMBER', 1);²< define('COLUMN_SEVERITY', 2);²< define('COLUMN_DESCRIPTION', 3);²< ²< ²< $data_model = array(²< array(²< 'name' => 'Fixed',²< 'render' => 'toggle', # toggle, text, progress, combo²< 'type' => Gtk::TYPE_BOOLEAN, # Gtk::TYPE_STRING, Gtk::TYPE_DOUBLE, GdkPixbuf::gtype, Gtk::TYPE_BOOLEAN, ²< ²< 'callback' => 'fixed_toggled',²< 'callback_event' => 'toggled'²< ),²< array(²< 'name' => 'Bug Number',²< 'render' => 'text',²< 'type' => Gtk::TYPE_STRING²< ),²< array(²< 'name' => 'Severity',²< 'render' => 'text',²< 'type' => Gtk::TYPE_STRING²< ),²< array(²< 'name' => 'Description',²< 'render' => 'text',²< 'type' => Gtk::TYPE_STRING²< )²< );²< ²< $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 PhpGtkListStore{²< function __construct($data_model, $data){²< parent::__construct($data_model, $data);²< ²< $this->set_title('PhpGtkListStore');²< $this->connect_simple('destroy', array('gtk', 'main_quit'));²< $this->set_position(Gtk::WIN_POS_CENTER);²< $this->set_size_request(600, 300);²< ²< # $this->tree_view->set_rules_hint(true);²< # $this->tree_view->set_search_column(COLUMN_DESCRIPTION);²< ²< }²< ²< function fixed_toggled($cell, $path, $context){²< list($model, $col) = $context;²< ²< # get toggled iter²< $iter = $model->get_iter((int)$path);²< $fixed = $model->get_value($iter, $col);²< ²< # do something with the value²< $fixed = ! $fixed;²< ²< # set new value²< $model->set($iter, COLUMN_FIXED, $fixed);²< }²< ²< }²< ²< new ListStoreExample($data_model, $data);²< Gtk::main();²< ²< ²< ?>[[include:Main/CodeTableEnd]]²< ²< !!! library code²< ²< [[include:Main/CodeTable]]<?php²< ²< class PhpGtkListStore extends GtkWindow²< {²< protected $data;²< protected $data_model;²< ²< protected $sw; # scrolled window²< protected $vbox;²< protected $label;²< ²< protected $model;²< protected $tree_view;²< ²< function __construct($data_model, $data)²< {²< parent::__construct();²< ²< $this->data_model = $data_model;²< $this->data = $data;²< ²< $this->vbox = new GtkVbox(); ²< $this->add($this->vbox);²< ²< # a label on top²< $this->label = new GtkLabel("Gtk ListStore Example");²< $this->vbox->pack_start($this->label, false, false);²< ²< ²< # a scrolled windows²< $this->sw = new GtkScrolledWindow();²< $this->sw->set_shadow_type(Gtk::SHADOW_ETCHED_IN);²< $this->sw->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);²< ²< $this->vbox->pack_start($this->sw);²< ²< $this->model = $this->_create_model($this->data_model, $this->data);²< $this->tree_view = new GtkTreeView($this->model);²< ²< $this->sw->add($this->tree_view);²< ²< $this->_add_colums($this->tree_view, $this->data_model);²< $this->show_all();²< }²< ²< function _create_model($data_model, $data){²< ²< $types = array();²< ²< foreach($data_model as $rec){²< $types[] = $rec['type'];²< }²< ²< # can't pass an arrau to GtkListStore constructor (so eval is the solution)²< $code = sprintf('$list_store = new GtkListStore(%s);', join(',', $types));²< eval ($code);²< ²< foreach($data as $rec){²< $list_store->append($rec);²< }²< ²< return $list_store;²< }²< ²< function _add_colums($tree_view, $data_model){²< $renders = array(²< 'text' => array(²< 'class' => 'GtkCellRendererText',²< 'field' => 'text'²< ),²< 'toggle' => array(²< 'class' => 'GtkCellRendererToggle',²< 'field' => 'active',²< ),²< 'progress' => array(²< 'class' => 'GtkCellRendererProgress',²< 'field' => 'value',²< ),²< 'combo' => array(²< 'class' => 'GtkCellRendererCombo',²< 'field' => 'text',²< ),²< 'pixbuf' => array(²< 'class' => 'GtkCellRendererPixbuf',²< 'field' => 'pixbuf',²< )²< );²< $model = $tree_view->get_model();²< ²< foreach($data_model as $key=>$info){²< ²< $render = new $renders[$info['render']]['class']();²< $column = new GtkTreeViewColumn(²< $info['name'], $render, $renders[$info['render']]['field'], $key);²< $tree_view->append_column($column);²< ²< if(isset($info['callback'])){²< $context = array($model, $key);²< $render->connect($info['callback_event'], array($this, $info['callback']), $context);²< }²< }²< ²< }²< ²< }²< ²< ²< ?>[[include:Main/CodeTableEnd]]²< ²---²> Describe GtkTreeViewListStore2 here.²\ No newline at end of file²
|
|
author=Marc Quinton
|
|
author:1157983265=Marc Quinton
|
|
host:1157983265=143.196.162.107
|
|
name=CodeSnippets.GtkTreeViewListStore2
|
|
host=143.196.162.107
|
|
agent=Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041217
|
|
rev=3
|
|
diff:1157983346:1157983265:=8a9,14²> define('COLUMN_FIXED', 0);²> define('COLUMN_NUMBER', 1);²> define('COLUMN_SEVERITY', 2);²> define('COLUMN_DESCRIPTION', 3);²> ²> ²77c83²< $model->set($iter, $col, $fixed);²---²> $model->set($iter, COLUMN_FIXED, $fixed);²
|
|
author:1157983346=Marc Quinton
|
|
host:1157983346=143.196.162.107
|
|
diff:1157983953:1157983346:=184,185d183²< ²< $column->set_sort_column_id($key);²
|
|
author:1157983953=Marc Quinton
|
|
host:1157983953=143.196.162.107
|