Re: Column model has only 1 column




On Sep 16, 2005, at 1:45 AM, James McArthur wrote:

I have a piece of code that looks like this:

   my %column_definition = ( "Date" => "text" );
   my $table = $gladexml->get_widget('treeEventOutput');
   my $simpleList = Gtk2::SimpleList->new_from_treeview ( $table,
%column_definition);

This creates a Gtk2::ListStore with one column of type Glib::String, and sets that model into $table; then packs a single TreeViewColumn (with a CellRendererText) into the TreeView, after reblessing it to SimpleList.


   foreach my $state (@states)
   {
      $table->append_column
(Gtk2::TreeViewColumn->new_with_attributes ($state,
Gtk2::CellRendererText->new, 'text', 0));
   }

This adds more TreeViewColumns to the view, all getting their data from the one and only column of the model.


When I go to add data into the columns using:

   if ($$record[0] =~ /FirstState/) { push @{$simpleList->{data}},
[$key, $$record[1], undef]; }

Here, you attempt to set three columns' worth of data into the list store through the TiedList wrapper. Since the list store has only one column, as seen above, you get an error:

   "can't set value for column 1, model only has 1 columns"

It looks like the SimpleList isn't seeing the new columns being added.

Ah, here you are tripped up by semantics. It certainly does see the view columns you added --- but you only added view columns. That has nothing to do with model columns.

Remember; SimpleList aims to provide a Simple 1:1 mapping of model and view columns, but TreeView is not required to work that way.

How do I convince the SimpleList to do what I want?

In general, you must specify the full complement of model columns at creation time. Models don't handle changing their columns after creation.

On 2005/06/16 i applied a patch to Gtk2::SimpleList that allows the model to be replaced after the SimpleList has been initialized, by doing $slist->set_model($new_model); this should be available in Gtk2 1.100. The patch doesn't appear to have made it to Gtk2::Ex::SimpleList yet. Not for the faint of heart.


--
"There's a documentary that i wanted to watch on PBS. I heard about it in NPR. ... Oh my god, did i just say that?"
  -- elysse




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]