TREEVIEW GLADE REWRITE DATA
| From: | AngeloP | Date: | Tue, 05 Dec 2006 11:30:21 +0000 |
| Subject: | TREEVIEW GLADE REWRITE DATA | ||
| Groups: | php.gtk.general | ||
| Request: | Send a blank email to php-gtk-general+get-7487@lists.php.net to get a copy of this message | ||
Hi guys!
I've a problem I've spended all the day to solve it
I've not found any solution at this moment:
Using GtkTreeView with glade file I'm able to write data array into the grid
but
if I write a new data array I'm not able to "clear" previous data and the
new columns are appended at the end of previous ( also if I use
$model->clear() syntax )
If you see the code below and try it you can see what is the problem !!!
SCENARIO:
In glade file there are 2 buttons and a treeview
clicking on button1 you can insert an array into treeview and then
clicking button2 a new array is appended instead to overwrite
I don't know where insert a clear function ...
Below there is the php and the glade file "tree.glade"
Have you an idea how to soleve it ?
Thanks
Angelo
=====================================
<?php
//Load GTK if not happened yet
if( !class_exists("gtk")) {
dl( "php_gtk." . ( strstr( PHP_OS, "WIN") ? "dll" : "so"));
}
// self-defined function to display alternate row color
function format_col($column, $cell, $model, $iter) {
$path = $model->get_path($iter); // get the current path
$row_num = $path[0]; // note 2
$row_color = ($row_num%2==1) ? '#dddddd' : '#ffffff'; // sets the row
color
for odd and even rows
$cell->set_property('cell-background', $row_color); // sets the
background
color!
}
$GLOBALS["catalogo"] = new window1();
$GLOBALS["catalogo"]->run();
class window1 {
var $window1;
var $arWidgets;
var $strPathSeparator = "/";
var $strTitle = "Modifica il titolo";
function window1() {
$this->InitDialog();
}//function window1()
/**
* let the program enter the gtk input loop - start the user interface
*/
function run()
{
GTK::main();
}
function InitDialog()
{
strstr( PHP_OS, "WIN") ? $this->strPathSeparator = "\\" :
$this->strPathSeparator = "/";
$this->BuildDialog();
$this->window1->show();
}
function BuildDialog()
{
$this->glwindow1 = &new GladeXML( dirname( __FILE__)
.$this->strPathSeparator . "tree.glade");
$this->window1 = $this->glwindow1->get_widget( "window1");
$this->window1 ->connect( "destroy" , array( $this, "OnDestroy"));
$this->window1 ->connect( "delete-event" , array( $this,
"OnDelete"));
$this->arWidgets["button1"] = $this->glwindow1->get_widget(
"button1");
$this->arWidgets["button1"] ->connect( "clicked" , array(
&$this,"on_button1_clicked"));
$this->arWidgets["button2"] = $this->glwindow1->get_widget(
"button2");
$this->arWidgets["button2"] ->connect( "clicked" , array(
&$this,"on_button2_clicked"));
$this->arWidgets["treeview1"]=
$this->glwindow1->get_widget("treeview1");
}//function BuildDialog()
function OnDestroy()
{
Gtk::main_quit();
}//function OnDestroy()
function OnDelete()
{
$this->OnDestroy();
}//function OnDestroy()
// ==================== ON BUTTON 1 NEW TREEVIEW
function display_tree_1 ($data,$field_header) {
$modello = new GtkListStore(Gtk::TYPE_STRING,
Gtk::TYPE_STRING,Gtk::TYPE_LONG);
$field_justification = array(0, 0, 0.5);
// Creates the view to display the list store
$this->arWidgets["treeview1"]->set_model( $modello);
// Creates columns
for ($col=0; $col<count($field_header); ++$col)
{
$cell_renderer = new GtkCellRendererText();
$column = new
GtkTreeViewColumn($field_header[$col],$cell_renderer,'text', $col);
// setup self-defined function to display alternate row color
$column->set_cell_data_func($cell_renderer, "format_col");
$this->arWidgets["treeview1"]->append_column($column);
}
// pupulates the data
for ($row=0; $row<count($data); ++$row)
{
$values = array();
for ($col=0; $col<count($data[$row]); ++$col)
{
$values[] = $data[$row][$col];
}
$modello->append($values);
}
}
// ==================== ON BUTTON 2 NEW TREEVIEW
function display_tree_2 ($data,$field_header) {
$modello = new GtkListStore(Gtk::TYPE_STRING,
Gtk::TYPE_STRING,Gtk::TYPE_LONG, Gtk::TYPE_DOUBLE, Gtk::TYPE_DOUBLE);
$field_justification = array(0, 0, 0.5, 1, 1);
// Creates the view to display the list store
$this->arWidgets["treeview1"]->set_model( $modello);
// Creates columns
for ($col=0; $col<count($field_header); ++$col)
{
$cell_renderer = new GtkCellRendererText();
$column = new
GtkTreeViewColumn($field_header[$col],$cell_renderer,'text', $col);
// setup self-defined function to display alternate row color
$column->set_cell_data_func($cell_renderer, "format_col");
$this->arWidgets["treeview1"]->append_column($column);
}
// pupulates the data
for ($row=0; $row<count($data); ++$row)
{
$values = array();
for ($col=0; $col<count($data[$row]); ++$col)
{
$values[] = $data[$row][$col];
}
$modello->append($values);
}
}
function on_button1_clicked( $objPara1)
{
// Creates the list store
$data = array(
array('row0', 'Angelo',40),
array('row1', 'Remo', 20),
array('row2', 'Romolo', 15)
);
$header= array('Row #', 'Name', 'Years');
$this->display_tree_1($data,$header) ;
}
function on_button2_clicked( $objPara1)
{
// Creates the list store
$data = array(
array('row0', 'item 19', 2, 3.1,32),
array('row1', 'item 4', 20, 6.21,24),
array('row2', 'item 7', 8, 21.73,4.55),
array('row3', 'item 10', 11, 18.6,209.283),
array('row4', 'item 13', 5, 15.5,234345.00),
array('row5', 'item 16', 17, 12.4,23.45),
array('row6', 'item 3', 20, 9.36,1000.00)
);
$header= array('Row #', 'Description', 'Qty', 'Unit
Price', 'Amt');
$this->display_tree_2($data,$header) ;
}
}//class window1
?>
=========================================
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface>
<widget class="GtkWindow" id="window1">
<property name="width_request">640</property>
<property name="height_request">480</property>
<property name="visible">True</property>
<property name="title" translatable="yes">window1</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<child>
<widget class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkButton" id="button1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Push to show Array
A</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_button1_clicked"
last_modification_time="Mon, 04 Dec 2006 22:35:49 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Push to show Array
B</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_button2_clicked"
last_modification_time="Mon, 04 Dec 2006 22:35:57 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
<property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTreeView" id="treeview1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">True</property>
<property name="rules_hint">False</property>
<property name="reorderable">False</property>
<property name="enable_search">True</property>
<property name="fixed_height_mode">False</property>
<property name="hover_selection">False</property>
<property name="hover_expand">False</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>
--
Angelo Pagotto
--
View this message in context: http://www.nabble.com/TREEVIEW-GLADE-REWRITE-DATA-tf2761016.html#a7697719
Sent from the Php - GTK - General mailing list archive at Nabble.com.