Re: [PHP-GTK] Combobox issue (repopulate)

[email protected] (Jake Cobb)
Newsgroups php.gtk.general
Message-ID <[email protected]>
Hello,

I think you're passing $modelo4 to connect_simple() when its not yet an 
object, perhaps expecting the value (object reference) you later assign 
to $modelo4 to be passed when in fact it will be passing the value 
(probably empty) of $modelo4 as it is when connect_simple() is called.  
For example, with this callback:

function isGtkListStore($model)
{
    if($model instanceof GtkListStore)
        print("Model is a GtkListStore.\n");
    else
        print("Model is not a GtkListStore.\n");
}

If you do this:

$combo_box->connect_simple('changed', 'isGtkListStore', $model);
$model = new GtkListStore(Gtk::TYPE_STRING);

Then you will see "Model is not a GtkListStore" printed with each 
changed signal.  If instead you do:

$model = new GtkListStore(Gtk::TYPE_STRING);
$combo_box->connect_simple('changed', 'isGtkListStore', $model);

Then you will see "Model is a GtkListStore" printed with each changed 
signal.

-Jake Cobb


Robertico wrote:
> Hi friends.
>
>    I have problems repopulating a combobox depends on a previous combobox
> selection. I build my form by a loop and in some part it does the next:
>
>
> ## Combobox para Tercero (First Combobox)
>             }else if($fila == 2)
>             {
>                 $aTipo =
> array("04"=>"Nacional","05"=>"Extranjero","06"=>"Global");
>
>
>                 $cajasCampos[$fila] = new GtkComboBox();
>                 $modelo3 = new
> GtkListStore(Gtk::TYPE_STRING,Gtk::TYPE_STRING);
>                 $cajasCampos[$fila]->set_model($modelo3);
>                 $cellRenderer = new GtkCellRendererText();
>                 $cajasCampos[$fila]->pack_start($cellRenderer);
>                 $cajasCampos[$fila]->set_attributes($cellRenderer, 'text',
> 0);
>                 $cajasCampos[$fila]->set_attributes($cellRenderer, 'text',
> 1);
>
>                 fillCombobox($modelo3,$aTipo); // easy function that
> populate the combo, receives the model and the array elements
>                 $cajasCampos[$fila]->set_active(0);
>
> $cajasCampos[$fila]->connect_simple('changed','cambiaTercero',$cajasCampos[$fila],$modelo4);
> // calling the function to repopulate
>
>                 $tabla->attach($cajasCampos[$fila],1,2,$fila,$fila+1);
>
>
>             ## Combobox para Operacion (Second combobox, the one I want to
> to change it)
>             }else if($fila == 3)
>             {
>                 $aOperacion = array("03"=>"Prestación de Servicios
> Profesionales",
>                                              "06"=>"Arrendamiento de
> Inmuebles",
>                                              "85"=>"Otros");
>
>
>                 $cajasCampos[$fila] = new GtkComboBox();
>                 $modelo4 = new
> GtkListStore(Gtk::TYPE_STRING,Gtk::TYPE_STRING);
>                 $cajasCampos[$fila]->set_model($modelo4);
>                 $cellRenderer = new GtkCellRendererText();
>                 $cajasCampos[$fila]->pack_start($cellRenderer);
>                 $cajasCampos[$fila]->set_attributes($cellRenderer, 'text',
> 0);
>                 $cajasCampos[$fila]->set_attributes($cellRenderer, 'text',
> 1);
>
>                 fillCombobox($modelo4,$aOperacion);
>                 $cajasCampos[$fila]->set_active(0);
>
>                 $tabla->attach($cajasCampos[$fila],1,2,$fila,$fila+1);
>
>             }
>
> Then I have these functions
>
> function fillCombobox($modelo,$arreglo)
> {
> ## Rellenamos el combo con sus datos (Populate the array)
>     while(list($valor,$texto) = each($arreglo))
>     {
>       $modelo->append(array($valor,$texto));
>     }
> }
>
> function cambiaTercero($combo,$modelo) // this function should repopulate
> the second combobox
> {
>     $seleccion = $combo->get_model();
>     $valor = $seleccion->get_value($combo->get_active_iter(),0);
>
>         switch ($valor)
>         {
>             case '04':
>                             $aNOperacion = array("03"=>"Prestación de
> Servicios Profesionales",
>
> "06"=>"Arrendamiento de Inmuebles",
>
> "85"=>"Otros");
>                             break;
>             case '05':
>                             $aNOperacion = array("03"=>"Prestación de
> Servicios Profesionales",
>
> "85"=>"Otros");
>                             break;
>             case '15':
>                             $aNOperacion = array("03"=>"Prestación de
> Servicios Profesionales",
>
> "06"=>"Arrendamiento de Inmuebles",
>
> "85"=>"Otros");
>                             break;
>         }
>         $modelo->clear();
>         fillCombobox($modelo,$aNoperacion);
> }
>
>
> Well, php tell me I'm calling a function clear() on a non-object.
>
> Thanks to all!
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.