Re: Confused about Gtk2::TreeView::get_model()



On Tue, 2003-11-04 at 21:07, Joerg Mueller wrote:

Did I miss something or got it all wrong?

You confused quite a few things there. It seems like you're working from
the header files and try to guess what those functions do by looking at
their name. That may work in many cases, but it definitely got you on
the wrong track here. There's an excellent API documentation at

  http://developer.gnome.org/doc/API/2.0/gtk/

You may especially be interested in

  http://developer.gnome.org/doc/API/2.0/gtk/TreeWidgetObjects.html

To your example:

  * $treeview->get_model returns the data model, in your case a
GtkTreeStore. That's just a container that hides its content from you.
You're supposed to use public API to access and modify the data. That's
why you can't just dump it with Data::Dumper. Additionally, since you
mentioned that you have a plain list, you may want to use GtkListStore
or even Gtk2::SimpleList which is an abstraction layer on top of all
this. See `perldoc Gtk2::SimpleList`.

  * $treeview->get_selection returns the GtkTreeSelection object which
handles selections, but is *not* the selection itself. Use

  my $iter = $treeview->get_selection->get_selected;

or store the return value of $treeview->get_selection in, say,
$selection and then use $selection->get_selected.

  * $model->get_nth_child gets the nth child of a node. Something you
don't want at all. In order to get your "Up" button working, use
something like

  # get the path that refers to our selection.
  my $path = $model -> get_path($iter);

  # if there's a previous node on the same depth, move to it.
  if ($path -> prev()) {
    # if the move was succesful, $path now refers to the node right
    # before the selection. get the corresponding iterator and move it 
    # right after the selection.
    $model -> move_after($model -> get_iter($path), $iter);
  }

That basically moves the line above the selected one right below it,
which has the same effect as moving the selection one line up.

HTH,
-Torsten




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