Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Adicionando colunas editáveis no GtkTreeview
- * PHP-GTK
- * http://andor.com.br
- */
- /**
- * Seta a codificação do programa
- */
- ini_set("php-gtk.codepage", "UTF-8");
- /**
- * Classe de exemplo
- */
- class Demo {
- /**
- * Armazena os widgets necessarios
- *
- * @access private
- * @property array $widgets
- */
- public $widgets = array();
- /**
- * @name __construct()
- * @return Demo
- */
- public function __construct() {
- // Cria a janela
- $this->widgets['frmDemo'] = new GtkWindow();
- $this->widgets['frmDemo']->set_size_request(250, 250);
- $this->widgets['frmDemo']->set_position(Gtk::WIN_POS_CENTER_ALWAYS);
- $this->widgets['frmDemo']->set_title("Demo");
- $this->widgets['frmDemo']->connect("destroy", array($this, "frmDemo_unload"));
- $vbox = new GtkVBox();
- // Cria o modelo
- $model = new GtkListStore(GObject::TYPE_STRING, GObject::TYPE_STRING);
- // Creia o treeview
- $this->widgets['trvTeste'] = new GtkTreeView($model);
- // Cria a colunas
- $render = new GtkCellRendererText();
- $render->set_property("editable", TRUE);
- $render->connect("edited", array($this, "trvTeste_onChange"), 0);
- $column = new GtkTreeViewColumn("Couna 1", $render, "text", 0);
- $this->widgets['trvTeste']->append_column($column);
- $render = new GtkCellRendererText();
- $render->set_property("editable", TRUE);
- $render->connect("edited", array($this, "trvTeste_onChange"), 1);
- $column = new GtkTreeViewColumn("Coluna 2", $render, "text", 1);
- $this->widgets['trvTeste']->append_column($column);
- // Popula o model
- $model->append(array("Valor 1", "1,19"));
- $model->append(array("Valor 2", "2,32"));
- $model->append(array("Valor 3", "3,29"));
- $model->append(array("Valor 4", "4,02"));
- $model->append(array("Valor 5", "5,30"));
- // Inicia a aplicação
- $vbox->pack_start($this->widgets['trvTeste']);
- $this->widgets['frmDemo']->add($vbox);
- $this->frmDemo_onload();
- }
- /**
- * Método do carregamento do formulario
- *
- * @name frmDemo_onload()
- */
- public function frmDemo_onload() {
- // Inicia a aplicação
- $this->widgets['frmDemo']->show_all();
- Gtk::main();
- }
- /**
- * Método do descarregamento do formulario
- *
- * @name frmDemo_unload()
- */
- public function frmDemo_unload() {
- // Encerra a aplicação
- Gtk::main_quit();
- }
- /**
- * Método que edita as colunas do trvTeste
- *
- * @name trvTeste_onChange
- * @param GtkCellRender $cellRenderer Renderizador da coluna
- * @param integer $path Linha que foi editada
- * @param mixed $value Valor que está sendo adicionado
- * @param integer $column Numero da coluna editada
- */
- public function trvTeste_onChange($cellRenderer, $path, $value, $column) {
- // Verifica se foi digitado alguma coisa
- if(trim($value) == "") {
- return FALSE;
- }
- // Recupera o model do treeview
- $model = $this->widgets['trvTeste']->get_model();
- $iter = $model->get_iter($path);
- // Seta o valor no treeview
- $model->set($iter, $column, $value);
- }
- }
- /**
- * Inicia o demo
- */
- new Demo();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement