GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How can I create a dynamic List Store

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
chrikle
Familiar Face


Joined: 31 Jan 2009
Posts: 5

PostPosted: Sun Mar 07, 2010 8:39 pm    Post subject: How can I create a dynamic List Store Reply with quote

I have an array of Data rows:

In general I create model like that:
model = gtk.ListStore(gobject.TYPE_DOUBLE, gobject.TYPE_DOUBLE)
or something like that. But in this case I don't know the number of rows
I have to do something like that:
model = gtk.ListStore(ARRAY_of_TYPES)

How can I do that?
Back to top
alketi
Familiar Face


Joined: 10 Mar 2010
Posts: 22

PostPosted: Wed Mar 10, 2010 4:42 pm    Post subject: Reply with quote

I'm looking to do this as well. I have an application where I do not know (until runtime) how many columns I will need.

From my early searches it appears a way to do this might be to use: gtk_list_store_newv ()

But, I'm still looking for a simple example on how to build it up with an array.

Cheers
Back to top
tadeboro
Never Seen the Sunlight


Joined: 23 Jul 2008
Posts: 2114
Location: Slovenia

PostPosted: Wed Mar 10, 2010 5:01 pm    Post subject: Reply with quote

@alketi: Hello and welcome to the GTK+ forums.

gtk_tree_store_newv() function is indeed what you'll need to use. I'll just give an example that shows how two exactly the same stores can be created using new() and newv() functions. This will hopefully give you a kick start in development.

Code: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* Static creation */
GtkTreeStore *store1 = gtk_tree_store_new( 2, G_TYPE_STRING, G_TYPE_INT );

/* Variable creation */
/* Create dynamic array 2 elements in size */
gsize array_size = sizeog( GType ) * 2;
GType *types = g_slice_alloc( array_size );

/* Assing types */
types[0] = G_TYPE_STRING;
types[1] = G_TYPE_INT;

/* Create store */
GtkTreeStore *store2 = gtk_tree_store_newv( 2, types );

/* Free array */
g_slice_free1( array_size, types );

Tadej
Back to top
alketi
Familiar Face


Joined: 10 Mar 2010
Posts: 22

PostPosted: Wed Mar 10, 2010 6:19 pm    Post subject: Reply with quote

tadeboro, thank you for your tireless help and support on these forums. Your examples are an amazing help.

I was able to integrate your example and get it working. Though, being new to Gtk I did have to look up whether or not "sizeog" was a new data type. :) But, it was just a small typo of course.

Thanks again!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP