Re: TreeView? (and: conceptual docs on Gtk2?)




On Mar 22, 2008, at 5:20 AM, Oliver Bandel wrote:
Hello,

how to use the TreeView-Stuff?


My first thing I need, is a listing of columns/rows
that I get from a database.

You may be interested in Daniel Kasak's work:

http://search.cpan.org/~dkasak/Gtk2-Ex-Datasheet-DBI-2.1/lib/Gtk2/Ex/Datasheet/DBI.pm


What I found out so far from examples, is,
that there must be a data-model and a view
be created and then the data inserted into the
data-model, and the view must be udated.
(Is this update done automatically by gtk? Can it be
done with/without automatic update? Is this possible to change?)

The updates are automatic. If you want to make mass changes without UI updates slowing you down, first disconnect the model from the view, update the model, then reconnect the model to the view, like this:

    $model = $treeview->get_model ();
    $treeview->set_model (undef);
    do_lots_of_stuff_to_model ($model);
    $treeview->set_model ($model);



I have no complete working example, only tried some things and got this
minimal stuff here:

===============================

my $renderer = Gtk2::CellRendererText->new;

my $column = Gtk2::TreeViewColumn -> new_with_attributes ("Nachname",
$renderer);
$view->append_column($column);

You have supplied no attributes, so the column doesn't know how to set up the renderer, and therefore will draw nothing even if you have data in your model.

The TreeViewColumn uses its renderer to draw each cell in the column. It does this by using the attributes to decide how to set properties of the renderer before drawing each cell. The attributes typically map to values from the model. For example:

$column = Gtk2::TreeViewColumn->new_with_attributes ($title, $renderer, text => 2);

means "draw in this cell the text from column 2 in the model". (Note that the column number in the view has nothing to do with the column number in the model. View columns may be reordered via drag and drop.)

Please see the TreeView tutorial linked below.


$globvbox->pack_start($view, FALSE, FALSE, 0);

You typically want to put a TreeView inside a ScrolledWindow.


===============================

At least I got some coulmn-headers on the screen,
but that's all.

That's a start!  :-)


My question is now: how to insert data into the model,
how to access that stuff?

That's all part of the TreeModel API, using TreeIters and such.

http://gtk2-perl.sourceforge.net/doc/pod/Gtk2/TreeModel.html

See the tutorials and documents listed below for details.


What kinds of "CellRenderer"s are available?
Is there an overview on the many possibilities?

The built-in CellRenderers are listed in the API reference:

http://library.gnome.org/devel/gtk/stable/TreeWidgetObjects.html

However, CellRenderer is an abstract class from which you can derive just about whatever you need, depending on how far you want to go. The Gtk2::CellRenderer manpage explains how to do this, the Gtk2 sources include several examples.


The same questions for the Models: what different Models are
available?

ListStore holds flat lists or tables, TreeStore holds hierarchical data, and you can implement the TreeModel interface in your own object to provide direct access to other data. Several other "proxy" models exist, such as TreeModelFilter and TreeModelSort.

TreeModel and TreeView hold rows of columns, and are NOT meant to be used as a general spreadsheet widget.

In perl, the Gtk2::Ex::SimpleList class wraps up a TreeView and a tied ListStore to take away the tedium of the MVC API for simple things. As Gtk2::Ex::Simple::TiedList is quite handy, SimpleList tends to be abused for things that aren't actually Simple. ;-) But, you can use TiedList on its own for easier data access.

http://search.cpan.org/~rmcfarla/Gtk2-Ex-Simple-List-0.50/lib/Gtk2/Ex/Simple/List.pm


Is there a tutorial, that makes it easy to start with that stuff?
I'm relatively new to Gtk2-Perl (and Gtk2), so this is not just
another widget for me. I'm also loking for documentations on the
concepts of Gtk2, because I have not found a conceptual paper on it.

Tim-Philipp Müller wrote the canonical tutorial for the TreeView, which contains a description of the concepts. It's targeted at users of gtk+'s C API, but the translation to perl is relatively painless. Here's a deep link, and you can reach the table of contents from there:

http://scentric.net/tutorial/sec-treeview-components.html


Here's a description for how to translate the C API to Perl and back:

http://gtk2-perl.sourceforge.net/doc/pod/Gtk2/api.html



There are tutorials, but they are not explaining the whole concept in a
way, that one can understand, why one usese some methods and others
not... So, independent of a help for the TreeView-Widget-Stuff,
I'm also looking for some more overvieww documentation.

There's the main gtk+ C tutorial:

http://library.gnome.org/devel/gtk-tutorial/stable/


as well as real-paper books:

The Official GNOME 2 Developer's Guide
http://nostarch.com/gnome.htm

Foundations of GTK+ Development
http://www.gtkbook.com/


--
Me:  What's that in your mouth?
Zella:  *swallows laboriously*  Nothing.
Me:  What did you just swallow?
Zella:  A booger.
Me:  Baby girl, don't eat boogers.  That's gross.
Zella:  But it was in my nose.




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