Foros del Web » Programando para Internet » PHP »

php gtk - crear tabla con datos de un array

Estas en el tema de php gtk - crear tabla con datos de un array en el foro de PHP en Foros del Web. hola, tengo un problema con mostrar los datos en una "GtkTreeView" inserto todos los datos y les hago print para comporbar si son leidos, pero ...
  #1 (permalink)  
Antiguo 03/02/2010, 12:33
 
Fecha de Ingreso: enero-2010
Mensajes: 62
Antigüedad: 14 años, 3 meses
Puntos: 1
php gtk - crear tabla con datos de un array

hola, tengo un problema con mostrar los datos en una "GtkTreeView"

inserto todos los datos y les hago print para comporbar si son leidos, pero en la parte de hacer la tabla me da este error

Warning: Cannot set row: number of row elements does not match the model in C:\Users\Nat\Desktop\proyectoGTK\php-gtk2\en-2.php on line 138

veo esa linea y es esto

$model->append($values);

veo el modelo y se supone que está bien porque lo saqué de un ejemplo que funcionaba y no entiendo que he hecho mal o que me falta.
  #2 (permalink)  
Antiguo 03/02/2010, 12:35
 
Fecha de Ingreso: enero-2010
Mensajes: 62
Antigüedad: 14 años, 3 meses
Puntos: 1
Respuesta: php gtk - crear tabla con datos de un array

Código PHP:
<?php

$app 
= new App();
$app->main();


class 
App {

    function 
App() {
        
$this->modules = array("main""entel""softswitch"); // names of the modules
    
}

    function 
main() {
        foreach(
$this->modules as $module) {
            
$this->apps[$module] = new $module($this);
            
$this->apps[$module]->dialog->connect('delete-event', array( &$this"on_delete_event"), $module);
            
$this->apps[$module]->dialog->connect('key-press-event', array( &$this"on_key"), $module);
        }
        
$this->apps['main']->dialog->show_all(); // show the first module
        
$this->apps['main']->dialog->run(); // let's go!
    
}

    
// process button click
    
function on_clicked($button$activated_module) {
        print 
"button_clicked: $activated_module\n";

        
$this->apps[$activated_module]->dialog->show_all(); // show the activated module
        
foreach($this->modules as $module) {
            if (
$module!=$activated_module$this->apps[$module]->dialog->hide_all(); // hide all others
        
}
        
$this->apps[$activated_module]->dialog->run();
    }

    function 
on_delete_event($widget$event$module) {
        if (
$module=='main') {
            
$this->apps['main']->dialog->destroy();
        } else {
            
$this->apps[$module]->dialog->hide();
            
$this->apps['main']->dialog->show_all(); // show the main menu
            
$this->apps['main']->dialog->run();
        }
        return 
true;
    }

    function 
on_key($widget$event$module) {
        global 
$apps;
        if (
$event->keyval==Gdk::KEY_F12) {
            if (
$module=='main') {
                
$this->apps['main']->dialog->destroy();
            } else {
                
$this->apps[$module]->dialog->hide();
                
$this->apps['main']->dialog->show_all(); // show the main menu
                
$this->apps['main']->dialog->run();
            }
        }
    }

    
// process menu item selection
    
function on_menu_select($menu_item) {
        
$item $menu_item->child->get_label();
        echo 
"menu selected: $item\n";
        if (
$item=='_Quit') {
            
$this->apps['main']->dialog->destroy();
        } else {
            
$module strtolower($item);
            print 
"module = $module\n";
            
$this->apps['main']->dialog->hide();
            
$this->apps[$module]->dialog->show_all();
            
$this->apps[$module]->dialog->run(); // let's go!
        
}
    }

}

class 
base_module {

    function 
base_module($obj) {
        
$this->main $obj// keep a copy of the module names
        
$module get_class($this);
        print 
"base_module::module = $module\n";
        
$dialog = new GtkDialog($modulenullGtk::DIALOG_MODAL);
        
$dialog->set_position(Gtk::WIN_POS_CENTER_ALWAYS);
        
$dialog->set_size_request(800600);
        
$top_area $dialog->vbox;
        
$this->dialog $dialog// keep a copy of the dialog ID

        // run the setup for each module
        
$this->setup($top_area);

        
$top_area->pack_start(new GtkLabel()); // used to "force" the button to stay at bottom
        
$this->show_buttons($top_area); // shows the buttons at bottom of windows
        
$dialog->set_has_separator(false);
    }

    function 
show_buttons($vbox) {}
}

function 
display_table($vbox$data) {

    
// Set up a scroll window
    
$scrolled_win = new GtkScrolledWindow();
    
$scrolled_win->set_policyGtk::POLICY_AUTOMATIC,
        
Gtk::POLICY_AUTOMATIC);
    
$vbox->pack_start($scrolled_win);

   
// Creates the list store
    
if (defined("GObject::TYPE_STRING")) {
        
$model = new GtkListStore(GObject::TYPE_STRINGGObject::TYPE_STRING,
                    
GObject::TYPE_STRING); // note 2
    
} else {
        
$model = new GtkListStore(Gtk::TYPE_STRINGGtk::TYPE_STRING,
                    
GObject::TYPE_STRING); // note 2
    
}
  #3 (permalink)  
Antiguo 03/02/2010, 12:36
 
Fecha de Ingreso: enero-2010
Mensajes: 62
Antigüedad: 14 años, 3 meses
Puntos: 1
Respuesta: php gtk - crear tabla con datos de un array

continuacion
Código PHP:
    $field_header = array('TgrpA''TgrpB''Duracion'); // note 3

    // Creates the view to display the list store
    
$view = new GtkTreeView($model); // note 4
    
$scrolled_win->add($view); // note 5

     // Creates columns
    
for ($col=0$col<count($field_header); $col++) {
        
$cell_renderer = new GtkCellRendererText();
        
$column = new GtkTreeViewColumn($field_header[$col],
            
$cell_renderer'text'$col);
        
$view->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];

        }
        
$model->append($values); // note 6
        //print_r (array_values($values));
    
}


}


class 
entel extends base_module {
    function 
setup($vbox) {
        
$this->dialog->set_size_request(800600);
        
$title = new GtkLabel("Entel 2");
        
$vbox->pack_start($title00);
        
$vbox->pack_start(new GtkLabel(), 00);
        
$flat_file_db 'C:\Users\Nat\Desktop\proyectoGTK\php-gtk2\en-2-2.txt'// note 1
        
$handle = @fopen($flat_file_db"r");

        
//array entel 2
        
$array_TgrpA = array();
        
$array_TgrpB = array();
        
$array_Nadi142 = array();
        
$array_Fecha = array();
        
$array_Hora = array();
        
$array_Durac = array();
        
$array_NadiB = array();
        
$array_number = array();
        if (
$handle) {
        while (!
feof($handle)) {
        
$buffer fgets($handle);
                   
$TgrpA substr("$buffer",16);
                   
$TgrpB substr("$buffer",77);
                   
$Nadi142 substr("$buffer",309);
                   
$Fecha substr("$buffer",808);
                   
$Hora substr("$buffer",898);
                   
$Durac substr("$buffer",985);
                   
$NadiB substr("$buffer",10715);
                   
$number substr("$buffer"1073);

    
array_push($array_TgrpA$TgrpA);
    
array_push($array_TgrpB$TgrpB);
    
array_push($array_Nadi142$Nadi142);
    
array_push($array_Fecha$Fecha);
    
array_push($array_Hora$Hora);
    
array_push($array_Durac$Durac);
    
array_push($array_NadiB$NadiB);
    
array_push($array_number$number);

                 }
    
$data = array($array_TgrpA,
        
$array_TgrpB,
        
$array_Durac);

    
//numbers
    
$array_count_number array_count_values($array_number); // muestra cuantas veces se repite el mismo valor
    
$array_keys_number array_keys($array_count_number);   // muestra las llaves de los numeros buscados con $array_count_number
   /*
    //TgrpA
    $array_count_TgrpA = array_count_values($array_TgrpA);
    $array_keys_TgrpA = array_keys($array_count_TgrpA);
    //TgrpB
    $array_count_TgrpB = array_count_values($array_TgrpB);
    $array_keys_TgrPB = array_keys($array_count_TgrpB);*/



function obtenerUbicacionIguales($NumeroIndice$array_number)
{
    
$resultado = array();
    for(
$i 0$i count($array_number); $i++)
        if(
$array_number[$i] == $NumeroIndice// Si el numero indice buscado es igual al indice en la posicion actual
            
$resultado[] = $i// Agregar la posicion / ubicacion en el resultado.
    
return $resultado;
}


//OBTENER VALORES 1
function obtenerValoresTgrpA($NumeroIndice$array_number$array_TgrpA)
{
    
$resultado = array();
    for(
$i 0$i count($array_number); $i++)
        if(
$array_number[$i] == $NumeroIndice// Si coincide el indice con el numero indice requerido
            
$resultado[] = $array_TgrpA[$i]; // Agregar la palabra correspondiente en el resultado.
    
return $resultado;
}

function 
obtenerValoresTgrpB($NumeroIndice$array_number$array_TgrpB)
{
    
$resultado = array();
    for(
$i 0$i count($array_number); $i++)
        if(
$array_number[$i] == $NumeroIndice// Si coincide el indice con el numero indice requerido
            
$resultado[] = $array_TgrpB[$i]; // Agregar la palabra correspondiente en el resultado.
    
return $resultado;
}

function 
obtenerValoresNadi142($NumeroIndice$array_number$array_Nadi142)
{
    
$resultado = array();
    for(
$i 0$i count($array_number); $i++)
        if(
$array_number[$i] == $NumeroIndice// Si coincide el indice con el numero indice requerido
            
$resultado[] = $array_Nadi142[$i]; // Agregar la palabra correspondiente en el resultado.
    
return $resultado;
}

function 
obtenerValoresNadiB($NumeroIndice$array_number$array_NadiB)
{
    
$resultado = array();
    for(
$i 0$i count($array_number); $i++)
        if(
$array_number[$i] == $NumeroIndice// Si coincide el indice con el numero indice requerido
            
$resultado[] = $array_NadiB[$i]; // Agregar la palabra correspondiente en el resultado.
    
return $resultado;
}

function 
obtenerValoresDurac($NumeroIndice$array_number$array_Durac)
{
    
$resultado = array();
    for(
$i 0$i count($array_number); $i++)
        if(
$array_number[$i] == $NumeroIndice// Si coincide el indice con el numero indice requerido
            
$resultado[] = $array_Durac[$i]; // Agregar la palabra correspondiente en el resultado.
    
return $resultado;
}

// FIN OBTENER VALORES1

       
display_table($vbox$data);
                 }
    }
}

class 
softswitch extends base_module {
    function 
setup($vbox) {
        
$this->dialog->set_size_request(800600);
        
$vbox->pack_start(new GtkLabel(get_class($this)));
    }
}



class 
main extends base_module {
    function 
setup($vbox) {
        
//define menu definition
        
$menu_definition = array(
        
'_Archivo' => array('_Cerrar'),
        
'_Aplicaciones' => array( 'Entel''SoftSwitch')
        );
        
$this->setup_menu($vbox$menu_definition);
        
$vbox->pack_start(new GtkLabel('Menu Principal'));


    }

    
// shows the buttons at bottom of windows only for main_menu
    
function show_buttons($vbox) {
        global 
$modules;
        
$hbox = new GtkHBox();
        
$vbox->pack_start($hbox00);
        
$hbox->pack_start(new GtkLabel());
        foreach(
$this->main->modules as $module) {
            if (
$module=='main') continue; // skip the main_menu button
            
$button = new GtkButton(strtoupper(substr($module,0,1)).substr($module,1)); // cap 1st letter
            
$button->set_size_request(8032); // makes all button the same size
            
if ($module == get_class($this)) { // sets the color of the respective button
                
$button->modify_bg(Gtk::STATE_NORMALGdkColor::parse("#95DDFF"));
                
$button->modify_bg(Gtk::STATE_ACTIVEGdkColor::parse("#95DDFF"));
                
$button->modify_bg(Gtk::STATE_PRELIGHTGdkColor::parse("#95DDFF"));
            }
            
$hbox->pack_start($button00);
            
$hbox->pack_start(new GtkLabel());
            
$button->connect('clicked', array(&$this->main,'on_clicked'), $module); // event handler to handle button click
        
}
    }

    
// setup menu
    
function setup_menu($vbox$menus) {
        
$menubar = new GtkMenuBar();
        
$vbox->pack_start($menubar00);
        foreach(
$menus as $toplevel => $sublevels) {
            
$menubar->append($top_menu = new GtkMenuItem($toplevel));
            
$menu = new GtkMenu();
            
$top_menu->set_submenu($menu);
            foreach(
$sublevels as $submenu) {
                if (
$submenu=='<hr>') {
                    
$menu->append(new GtkSeparatorMenuItem());
                } else {
                    
$menu->append($menu_item = new GtkMenuItem($submenu));
                    
$menu_item->connect('activate', array(&$this->main'on_menu_select'));
                }
            }
        }
    }
}

?> 
  #4 (permalink)  
Antiguo 03/02/2010, 12:48
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Tema movido desde PHP a PHP-GTK

Etiquetas: gtk, tablas
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:45.