www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - GtkD: Best way to get TreeStore out of TreeView.Model

reply "Alex Horvat" <alexh gmail.com> writes:
I'm trying to get a TreeStore object back out of a TreeView in 
GtkD.

The reason for this is so that I can change the value of a cell 
in the TreeView - in this case changing one image for another.

I can't use a TreeModel for this as it does not have a setValue 
function.

I've got this working with the following code:

private bool tvTreeView_ButtonRelease(Event e, Widget sender) {
   TreeIter selectedItem = tvTreeView.getSelectedIter();
   TreeStore store = new 
TreeStore(cast(GtkTreeStore*)selectedItem.gtkTreeModel);

   store.setValue(selectedItem, 2, newPixbuf);
}

But this seems like a really ugly way to do this, I'm sure I'm 
missing something.

I've also tried:

TreeStore store = 
ObjectG.getDObject!(TreeStore)(cast(GtkTreeStore*)selectedItem.gtkTreeModel);
This creates a TreeModel not a TreeStore

TreeStore store = cast(TreeStore)tvTreeView.getModel();
In this case store == null

Does anyone know a better way of doing this?
Or is this something missing from GtkD?

Thanks
Jun 11 2013
parent reply Mike Wey <mike-wey example.com> writes:
On 06/11/2013 05:56 PM, Alex Horvat wrote:
 TreeStore store = cast(TreeStore)tvTreeView.getModel();
 In this case store == null
I think that one should work, how are you setting/creating the TreeStore? -- Mike Wey
Jun 11 2013
parent reply "Alex Horvat" <alexh gmail.com> writes:
On Tuesday, 11 June 2013 at 17:41:59 UTC, Mike Wey wrote:
 On 06/11/2013 05:56 PM, Alex Horvat wrote:
 TreeStore store = cast(TreeStore)tvTreeView.getModel();
 In this case store == null
I think that one should work, how are you setting/creating the TreeStore?
tvTreeView.setModel(CreateModel()); private TreeStore CreateModel() { TreeStore treeStore = new TreeStore([GType.STRING, GType.STRING, Pixbuf.getType()]); Values a filled recursively using treeStore.setValue(iter, column, value); }
Jun 11 2013
parent reply Mike Wey <mike-wey example.com> writes:
On 06/11/2013 07:55 PM, Alex Horvat wrote:
 On Tuesday, 11 June 2013 at 17:41:59 UTC, Mike Wey wrote:
 On 06/11/2013 05:56 PM, Alex Horvat wrote:
 TreeStore store = cast(TreeStore)tvTreeView.getModel();
 In this case store == null
I think that one should work, how are you setting/creating the TreeStore?
getModel returns an interface, so try the following: TreeStore store = cast(TreeStore)cast(void*)tv.getModel(); -- Mike Wey
Jun 12 2013
parent reply "Alex Horvat" <fake gmail.com> writes:
On Wednesday, 12 June 2013 at 21:44:55 UTC, Mike Wey wrote:
 On 06/11/2013 07:55 PM, Alex Horvat wrote:
 On Tuesday, 11 June 2013 at 17:41:59 UTC, Mike Wey wrote:
 On 06/11/2013 05:56 PM, Alex Horvat wrote:
 TreeStore store = cast(TreeStore)tvTreeView.getModel();
 In this case store == null
I think that one should work, how are you setting/creating the TreeStore?
getModel returns an interface, so try the following: TreeStore store = cast(TreeStore)cast(void*)tv.getModel();
Thanks Ok, just tried this and after setting store if I call writeln(store) the output is what looks like a memory dump, definitly something wrong there. And the program crashes if I try to use store.
Jun 12 2013
parent reply Mike Wey <mike-wey example.com> writes:
On 06/13/2013 06:14 AM, Alex Horvat wrote:
 On Wednesday, 12 June 2013 at 21:44:55 UTC, Mike Wey wrote:
 On 06/11/2013 07:55 PM, Alex Horvat wrote:
 On Tuesday, 11 June 2013 at 17:41:59 UTC, Mike Wey wrote:
 On 06/11/2013 05:56 PM, Alex Horvat wrote:
 TreeStore store = cast(TreeStore)tvTreeView.getModel();
 In this case store == null
I think that one should work, how are you setting/creating the TreeStore?
getModel returns an interface, so try the following: TreeStore store = cast(TreeStore)cast(void*)tv.getModel();
Thanks Ok, just tried this and after setting store if I call writeln(store) the output is what looks like a memory dump, definitly something wrong there. And the program crashes if I try to use store.
Could you try again with the latest git? https://github.com/gtkd-developers/GtkD/commit/ab664087b9d354f9cae7e11c17f0b7125dcf8bdd -- Mike Wey
Jun 16 2013
parent reply "Alex Horvat" <alexh gmail.com> writes:
On Sunday, 16 June 2013 at 18:22:47 UTC, Mike Wey wrote:
 On 06/13/2013 06:14 AM, Alex Horvat wrote:
 On Wednesday, 12 June 2013 at 21:44:55 UTC, Mike Wey wrote:
 On 06/11/2013 07:55 PM, Alex Horvat wrote:
 On Tuesday, 11 June 2013 at 17:41:59 UTC, Mike Wey wrote:
 On 06/11/2013 05:56 PM, Alex Horvat wrote:
 TreeStore store = cast(TreeStore)tvTreeView.getModel();
 In this case store == null
I think that one should work, how are you setting/creating the TreeStore?
getModel returns an interface, so try the following: TreeStore store = cast(TreeStore)cast(void*)tv.getModel();
Thanks Ok, just tried this and after setting store if I call writeln(store) the output is what looks like a memory dump, definitly something wrong there. And the program crashes if I try to use store.
Could you try again with the latest git? https://github.com/gtkd-developers/GtkD/commit/ab664087b9d354f9cae7e11c17f0b7125dcf8bdd
OK, I pulled the changes and rebuilt gtkd but the error is still the same. I tried all the variations in code listed in my first post, plus the one you suggested with the double cast, but everything failed in the same ways as before. On the plus side, nothing new broke - it still works with the work-around way I've got. Is there any more info I can supply that would help you?
Jun 16 2013
parent reply Mike Wey <mike-wey example.com> writes:
On 06/17/2013 04:44 AM, Alex Horvat wrote:
 On Sunday, 16 June 2013 at 18:22:47 UTC, Mike Wey wrote:
 On 06/13/2013 06:14 AM, Alex Horvat wrote:
 On Wednesday, 12 June 2013 at 21:44:55 UTC, Mike Wey wrote:
 On 06/11/2013 07:55 PM, Alex Horvat wrote:
 On Tuesday, 11 June 2013 at 17:41:59 UTC, Mike Wey wrote:
 On 06/11/2013 05:56 PM, Alex Horvat wrote:
 TreeStore store = cast(TreeStore)tvTreeView.getModel();
 In this case store == null
I think that one should work, how are you setting/creating the TreeStore?
getModel returns an interface, so try the following: TreeStore store = cast(TreeStore)cast(void*)tv.getModel();
Thanks Ok, just tried this and after setting store if I call writeln(store) the output is what looks like a memory dump, definitly something wrong there. And the program crashes if I try to use store.
Could you try again with the latest git? https://github.com/gtkd-developers/GtkD/commit/ab664087b9d354f9cae7e11c17f0b7125dcf8bdd
OK, I pulled the changes and rebuilt gtkd but the error is still the same. I tried all the variations in code listed in my first post, plus the one you suggested with the double cast, but everything failed in the same ways as before. On the plus side, nothing new broke - it still works with the work-around way I've got. Is there any more info I can supply that would help you?
What OS are you using and which compiler? -- Mike Wey
Jun 17 2013
parent reply "Alex Horvat" <alexh gmail.com> writes:
On Monday, 17 June 2013 at 17:52:38 UTC, Mike Wey wrote:
 On 06/17/2013 04:44 AM, Alex Horvat wrote:
 On Sunday, 16 June 2013 at 18:22:47 UTC, Mike Wey wrote:
 On 06/13/2013 06:14 AM, Alex Horvat wrote:
 On Wednesday, 12 June 2013 at 21:44:55 UTC, Mike Wey wrote:
 On 06/11/2013 07:55 PM, Alex Horvat wrote:
 On Tuesday, 11 June 2013 at 17:41:59 UTC, Mike Wey wrote:
 On 06/11/2013 05:56 PM, Alex Horvat wrote:
 TreeStore store = cast(TreeStore)tvTreeView.getModel();
 In this case store == null
I think that one should work, how are you setting/creating the TreeStore?
getModel returns an interface, so try the following: TreeStore store = cast(TreeStore)cast(void*)tv.getModel();
Thanks Ok, just tried this and after setting store if I call writeln(store) the output is what looks like a memory dump, definitly something wrong there. And the program crashes if I try to use store.
Could you try again with the latest git? https://github.com/gtkd-developers/GtkD/commit/ab664087b9d354f9cae7e11c17f0b7125dcf8bdd
OK, I pulled the changes and rebuilt gtkd but the error is still the same. I tried all the variations in code listed in my first post, plus the one you suggested with the double cast, but everything failed in the same ways as before. On the plus side, nothing new broke - it still works with the work-around way I've got. Is there any more info I can supply that would help you?
What OS are you using and which compiler?
Linux (Fedora) 64bit, DMD 2.063.1
Jun 17 2013
next sibling parent "Alex Horvat" <alexh gmail.com> writes:
Just upgraded to dmd 2.063.2 - no difference
Jun 17 2013
prev sibling parent reply Mike Wey <mike-wey example.com> writes:
On 06/17/2013 09:32 PM, Alex Horvat wrote:
 On Monday, 17 June 2013 at 17:52:38 UTC, Mike Wey wrote:
 On 06/17/2013 04:44 AM, Alex Horvat wrote:
 On Sunday, 16 June 2013 at 18:22:47 UTC, Mi
 Could you try again with the latest git?

 https://github.com/gtkd-developers/GtkD/commit/ab664087b9d354f9cae7e11c17f0b7125dcf8bdd
OK, I pulled the changes and rebuilt gtkd but the error is still the same. I tried all the variations in code listed in my first post, plus the one you suggested with the double cast, but everything failed in the same ways as before. On the plus side, nothing new broke - it still works with the work-around way I've got. Is there any more info I can supply that would help you?
What OS are you using and which compiler?
Linux (Fedora) 64bit, DMD 2.063.1
I seem to have missed a few cases in the last commit, would you mind trying again? https://github.com/gtkd-developers/GtkD/commit/7e95380bbb4f569c95fc9435711e1f2ec73122fe -- Mike Wey
Jun 19 2013
parent reply "Alex Horvat" <alexh gmail.com> writes:
 I seem to have missed a few cases in the last commit, would you 
 mind trying again?

 https://github.com/gtkd-developers/GtkD/commit/7e95380bbb4f569c95fc9435711e1f2ec73122fe
Sorry, no changes - still getting the same errors as before.
Jun 19 2013
parent reply Mike Wey <mike-wey example.com> writes:
On 06/20/2013 07:53 AM, Alex Horvat wrote:
 I seem to have missed a few cases in the last commit, would you mind
 trying again?

 https://github.com/gtkd-developers/GtkD/commit/7e95380bbb4f569c95fc9435711e1f2ec73122fe
Sorry, no changes - still getting the same errors as before.
Does this code run successfully for you? ---- import gtk.Main; import gtk.TreeStore; import gtk.TreeView; void main(string[] args) { Main.init(args); TreeStore ts = new TreeStore([GType.STRING, GType.STRING]); TreeView tv = new TreeView(); tv.setModel(ts); TreeStore store = cast(TreeStore)tv.getModel(); assert(store !is null); store.getNColumns(); } ---- -- Mike Wey
Jun 20 2013
parent "Alex Horvat" <alexh gmail.com> writes:
On Thursday, 20 June 2013 at 17:44:18 UTC, Mike Wey wrote:
 On 06/20/2013 07:53 AM, Alex Horvat wrote:
 I seem to have missed a few cases in the last commit, would 
 you mind
 trying again?

 https://github.com/gtkd-developers/GtkD/commit/7e95380bbb4f569c95fc9435711e1f2ec73122fe
Sorry, no changes - still getting the same errors as before.
Does this code run successfully for you? ---- import gtk.Main; import gtk.TreeStore; import gtk.TreeView; void main(string[] args) { Main.init(args); TreeStore ts = new TreeStore([GType.STRING, GType.STRING]); TreeView tv = new TreeView(); tv.setModel(ts); TreeStore store = cast(TreeStore)tv.getModel(); assert(store !is null); store.getNColumns(); } ----
Yes, and I did writeln(store) and the result was a treestore so this code works fine. Yet still my code doesn't work even though it's effectively doing the same thing, kind of weird.
Jun 20 2013