llancet has asked for the wisdom of the Perl Monks concerning the following question:
I want to create a table of laptops. One of the column is the type of CPU, so I want to only allow user to select one from a list of given CPUs. I made something like this:
Firstly, a ListStore of CPUs, and a ListStore of the big table, defined in glade:then create the GUI in perl:...... <object class="GtkTreeView" id="ModelTable"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="model">ModelListStore</property> <child internal-child="selection"> <object class="GtkTreeSelection" id="treeview-selection1 +"/> </child> </object> ...... <object class="GtkListStore" id="CPUListStore"> <columns> <!-- column-name col_cpu --> <column type="gchararray"/> </columns> </object> <object class="GtkListStore" id="ModelListStore"> <columns> <!-- column-name name --> <column type="gchararray"/> <!-- column-name cpu_name --> <column type="gchararray"/> <!-- column-name gpu_name --> <column type="gchararray"/> <!-- column-name mem_sz --> <column type="gfloat"/> <!-- column-name mem_freq --> <column type="gint"/> <!-- column-name disk_sz --> <column type="gint"/> <!-- column-name disk_rot --> <column type="gint"/> <!-- column-name screen_sz --> <column type="gfloat"/> <!-- column-name price --> <column type="gfloat"/> </columns> </object>
# this is the table $model_table = $builder->get_object('ModelTable'); # cell renderer # 0th column of "CPUListStore" is used, as it has only that column. my $renderer_table_cpu = Gtk2::CellRendererCombo->new; $renderer_table_cpu->set(model=>$builder->get_object('CPUListStore')); $renderer_table_cpu->set(text_column=>0); $renderer_table_cpu->set(has_entry=>TRUE); # the TreeViewColumn # it corresponds to the COL_CPU_NAME column of the big table my $col_cpu = Gtk2::TreeViewColumn->new; $col_cpu->pack_start($renderer_table_cpu,TRUE); $col_cpu->add_attribute($renderer_table_cpu,'text',COL_CPU_NAME);
The problem is: when I change the value in combo, the table won't get modified. It seems the change of selection in the combobox does not correctly passed to the model of table. So how to use CellRendererCombo correctly? Thanks a lot!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hwo to correctly use Gtk2::CellRendererCombo?
by zentara (Cardinal) on Feb 07, 2012 at 10:52 UTC |