FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TreeView / ListStore question

 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
bkropf



Joined: 28 Oct 2008
Posts: 6

PostPosted: Sat May 02, 2009 9:38 am    Post subject: TreeView / ListStore question Reply with quote

I'm currently having some trouble with using ListStore with a TreeView (I haven't tried TreeStore yet, but I suspect it will be similar). I'm using current svn of gtkd, tango svn, and gdc 4.1.2 20070214 ( gdc 0.24, using dmd 1.030) on x86_64. When I build the test below I get an empty window with no items displayed. Has anyone gotten TreeVIew & ListStores working properly?

Also of interest:

If I uncomment the lines related to columns, then I get the column headers with two clickable lines in the TreeVIew, but no visible text.

If I uncomment the lines related to adding a second column, then I get a segfault.

Code:

module treeviewexample;

import gtk.Main;
import gtk.Window;
import gtk.Widget;
import gtk.TreeIter;
import gtk.TreeView;
import gtk.TreeViewColumn;
import gtk.ListStore;

int main(char[][] args) {
   Main.init(args);
   
   Window window = new Window("TreeView Example");
   
   TreeView tree = new TreeView();
   window.add(tree);
   
   //TreeViewColumn artistColumn = new TreeViewColumn();
   //artistColumn.setTitle = "Artist";
   
   //TreeViewColumn songColumn = new TreeViewColumn();
   //songColumn.setTitle = "Song Title";
   
   //tree.appendColumn(artistColumn);
   //tree.appendColumn(songColumn);
   
   GType[1] types;
   types[0] = GType.STRING;
   //types[1] = GType.STRING;
   
   ListStore musicListStore = new ListStore(types);
   TreeIter iter = musicListStore.createIter();
   
   musicListStore.setValue(iter, 0, "Radiohead");
   //musicListStore.setValue(iter, 1, "15 Step");
   
   musicListStore.append(iter);
   musicListStore.setValue(iter, 0, "Doors");
   //musicListStore.setValue(iter, 1, "Hello I Love You");
   
   tree.setModel(musicListStore);
   
   window.addOnHide(delegate void(Widget w) { Main.exit(0); });
   window.showAll;
   
   Main.run();
   return 0;
}
Back to top
View user's profile Send private message
okibi



Joined: 04 Jan 2007
Posts: 170

PostPosted: Sat May 02, 2009 7:00 pm    Post subject: Reply with quote

Try this:

Code:

module treeviewexample;

import gtk.Main;
import gtk.Window;
import gtk.Widget;
import gtk.TreeIter;
import gtk.TreeView;
import gtk.TreeViewColumn;
import gtk.ListStore;
import gtk.CellRendererText;

int main(char[][] args) {
   Main.init(args);
   
   Window window = new Window("TreeView Example");
   
   TreeView tree = new TreeView();
   window.add(tree);
   
   TreeViewColumn artistColumn = new TreeViewColumn();
   artistColumn.setTitle = "Artist";
   tree.appendColumn(artistColumn);
   CellRendererText cell_text = new CellRendererText();
   artistColumn.packStart(cell_text, 0);
   artistColumn.addAttribute(cell_text, "text", 0);
   
   TreeViewColumn songColumn = new TreeViewColumn();
   songColumn.setTitle = "Song Title";
   tree.appendColumn(songColumn);
   cell_text = new CellRendererText();
   songColumn.packStart(cell_text, 0);
   songColumn.addAttribute(cell_text, "text", 1);   
   
   GType[] types;
   types ~= GType.STRING;
   types ~= GType.STRING;
   
   ListStore musicListStore = new ListStore(types);
   TreeIter iter = musicListStore.createIter();
   
   musicListStore.setValue(iter, 0, "Radiohead");
   musicListStore.setValue(iter, 1, "15 Step");
   
   musicListStore.append(iter);
   musicListStore.setValue(iter, 0, "Doors");
   musicListStore.setValue(iter, 1, "Hello I Love You");
   
   tree.setModel(musicListStore);
   
   window.addOnHide(delegate void(Widget w) { Main.exit(0); });
   window.showAll;
   
   Main.run();
   return 0;
}
Back to top
View user's profile Send private message
bkropf



Joined: 28 Oct 2008
Posts: 6

PostPosted: Sat May 02, 2009 9:19 pm    Post subject: Reply with quote

I actually think the issue is related to 64 bit glib / gtk. When I print the size of a GType from gtkD, I get 4 bytes, but when I print the size of a GType from c++ I get 8 bytes.

Output from my D program:
Code:

sizeof GType 4
sizeof GType.STRING 4
sizeof pointer 8


But from a simple C++ program:
Code:

sizeof G_TYPE_STRING 8



I have also verified that if I add a long as basetype to the GType enum, then things work as expected. I'll try to figure out a way to properly version this for 64 bit and submit a ticket.
Back to top
View user's profile Send private message
okibi



Joined: 04 Jan 2007
Posts: 170

PostPosted: Sat May 02, 2009 10:20 pm    Post subject: Reply with quote

Oh, you're right. I thought that issue was fixed awhile back?

I'll look into it tonight/tomorrow morning. Shouldn't be too hard to implement a fix.
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sun May 03, 2009 8:08 am    Post subject: Reply with quote

I changed the basetype of the GType Enum to size_t which should be the correct size on all platforms.

@okibi: I saw the ticket before your post, i hope you didn't start working on a fix already Wink
Back to top
View user's profile Send private message
okibi



Joined: 04 Jan 2007
Posts: 170

PostPosted: Sun May 03, 2009 10:08 am    Post subject: Reply with quote

I looked, but wasn't going to do anything until this morning.

Glad to see you already implemented a fix. Smile
Back to top
View user's profile Send private message
bkropf



Joined: 28 Oct 2008
Posts: 6

PostPosted: Wed May 06, 2009 9:33 pm    Post subject: Reply with quote

Thanks, it worked great!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group