Hi Rouan, On 23.08.2012, at 18:37, Rouan van Dalen wrote:
> Hi everyone, > > I am having some trouble with the TreeView in gtk2hs. > > (I am using gtk2hs 0.12.3 with ghc 7.4.2 on windows 7 x64.) > > I would like to achieve the following: in 1 set up the TreeView and > its columns and > renderers, and in a different function set the model for the > TreeView control so > the data can be displayed. I have the following code: > > > populateTreeView :: TreeView -> IO () > populateTreeView tv = do > list <- listStoreNew [["Vince", "1"], ["Jhen", "2"], ["Chris", > "3"], ["Sharon", "4"]] > treeViewSetModel tv list -- this call throws warnings saying > that the model is different from the > -- one that was used in the function > below. > > > setupTreeView :: TreeView -> IO () > setupTreeView treeview = do > model <- treeStoreNew ([] :: [Tree String]) > widgetSetSizeRequest treeview 300 (-1) > > renderer <- Model.cellRendererTextNew > > col <- Model.treeViewColumnNew > Model.treeViewColumnSetTitle col "Upcoming Birtdays" > Model.cellLayoutPackStart col renderer False > Model.cellLayoutSetAttributes col renderer model -- My > problem is here I need to supply a model. > $ \l -> [Model.cellText := l] -- Is there > a function I can use to define how > -- a cell is > rendered without supplying the model? > > Model.treeViewAppendColumn treeview col > > After looking at the source code, it seems that the > 'gtk_tree_view_column_set_attributes' > function is not exposed in gtk2hs because of variable argument list > FFI restriction. > The CellLayout is an interface that a TreeViewColumn implements since TreeViewColumn is an instance of CellLayoutClass. As such, the C function you mention is just the implementation of this interface. Using the functions in CellLayout has exactly the same effect. > Is there a way to work around this problem? > Not really. Replacing the model after setting up the attributes of the renderers is in principle possible in C since it's then up to you to supply a model with exactly the same column names and types. Since we tried to get some type safety into the Haskell binding, you have to create the model first and then setup attributes of cell renderers using this model. Replacing the model after setting attributes will never work since the Haskell implementation compares the pointer of the model with which attributes were set against the model pointer in the TreeView before running the Haskell function on it (since it has to coerce a pointer to a C model to a Haskell model with the correct row type). Why do you need to replace the whole model? Is it to quickly replace the data of a tree view? It would be possible to add a function that simply replaced the contents of a ListStore with a new list (of the same type). Cheers, Axel > Regards > > Rouan. > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. > Discussions > will include endpoint security, mobile security and the latest in > malware > threats. > http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________ > Gtk2hs-devel mailing list > Gtk2hs-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Gtk2hs-devel mailing list Gtk2hs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel