Re: editable treeview column




On Jan 11, 2005, at 4:47 PM, BoÅtjan ÅpetiÄ wrote:

i can't get the treeview column to store the edited entry.

You must connect a handler to the CellRendererText's "edited" signal and set the new value into the model. For example:

  use constant COLUMN_FOO => 1;
  $model = ...;

  $cell_renderer = Gtk2::CellRendererText->new;
  # create a new column in the view using this renderer to display
  # text from COLUMN_FOO of the model.
  $view->insert_column_with_attributes (-1, "Foo", $cell_renderer,
                                        text => COLUMN_FOO);
  # make sure the cell is editable.  setting it this way makes the cell
  # editable in all rows.
  $cell_renderer->set (editable => TRUE);
  # do something useful when the user edits the cell.
  $cell_renderer->signal_connect (edited => sub {
          my ($cell, $text_path, $new_text) = @_;
# could mangle the value here or perform other updates if necessary.
          my $path = Gtk2::TreePath->new_from_string ($text_path);
          my $iter = $model->get_iter ($path);
          $model->set ($iter, COLUMN_FOO, $new_text);
  });

Cell renderers don't know about column numbers and models and all that (it's outside their level of abstraction), so you must arrange to get that data in somehow; here, i've used $model and COLUMN_FOO via closure scoping. SimpleList passes the model in as signal handler argument, and stores the column number in the cell renderer's instance hash.



is there something like simpletree maybe? :)

http://cvs.sourceforge.net/viewcvs.py/gtk2-perl-ex/Gtk2-Ex/Simple/Tree/
http://gtk2-perl-ex.sourceforge.net/


and just a note: it's clumsy to have different syntax for appending a row to list model and tree model: one requres 'undef' as the first parameter, and the other can live without it.

It's not that one requires 'undef' as the first parameter --- Gtk2::TreeStore::append() requires a Gtk2::TreeIter representing the parent of the new node as its first parameter; you can specify 'undef' to say "no parent".

Clumsy or not, it's not our syntax; we're faithfully sticking to the C api, which uses the GtkTreeModelIface to tell how to get data in and out of a model and how to navigate one, but not how to add or delete rows.


--
How come hair colors for women take an hour, but "wash out the gray" stuff for men only five minutes? This is so unfair!
    -- Elysse, complaining about commercials




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