Re: Displaying domain objects with GtkTreeView



2011/11/28 RafaÅ KrupiÅski <r krupinski gmail com>:
On 28.11.2011 14:17, Tristan Van Berkom wrote:

2011/11/28 RafaÅ KrupiÅski<r krupinski gmail com>:

Hi all!

How do I display list of custom objects in GtkTreeView?
GtkTreeView takes GtkListStore as a model, but it doesn't allow custom
objects, only list of gobjects.

What could that possibly mean ?

If you have custom derived GObjects, you can certainly populate a
list-store with them.

If you have "something-else-objects" that are not GObjects, you can always
use
G_TYPE_POINTER to hold them (it would be up to you to ensure that their
life
cycle is somehow bound to the liststore... i.e. that those objects are
not destroyed
while cell renderers are trying to access them).

How exactly do I do that? I only know that cell renderers can access model
fields by index, which implies that the model must be a list (or tuple,
since I'm using python).

The model must be a GtkTreeModel, the GtkTreeModel implementation can
be a flat list, implementations are allowed to let rows have children (i.e. it
can be a tree of data).

I don't know what API python is giving to you, if it's so very
different than the
C API than that is a good way to obfuscate code and confuse new users.


On the other hand, when I want to read list's selection all I get is
the GtkListStore model - list of gobjets and I have to figure out the
actual domain object the data comes from.

You don't get a list of gobjects as far as I know, I'm not sure where you
are
getting that from.

[...]

Ok, I'm noob with Gtk/GLib, so I might've used wrong words. Plus I'm using
python, so I didn't have to care about GTypes/GObjects.

Anyway, I can display ListView using list of strings as a model. That data
is copied from my domain object. The problem is, when I read the data from
the ListView I get those strings and I have to figure out the actual domain
object for myself.

I suppose this "domain object" is another Python concept ? or a concept which
is local to your program's business logic ?


I wanted to know how to use my domain object as a ListStore model for
reading and writing - that chapter is missing from the Tree View Tutorial
I've found.

Best Regards
RafaÅ KrupiÅski




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