From: Axel S. <A....@ke...> - 2006-12-06 10:56:17
|
On Wed, 2006-12-06 at 16:17 +0900, Robert Marlow wrote: > G'day. I'm reporting this bug here since I don't seem to have > appropriate permissions for > http://hackage.haskell.org/trac/gtk2hs/newticket > > > I've been testing out ListStoreNew with comboBoxEntry and have hit upon > a problem. The following code should serve as an example: > > import Graphics.UI.Gtk > import qualified Graphics.UI.Gtk.TreeList.ListStoreNew as LS > > main :: IO () > main = do > initGUI > window <- windowNew > onDestroy window mainQuit > combo <- comboBoxEntryNew > store <- LS.listStoreNew ["foo", "bar", "baz"] > comboBoxEntrySetTextModel combo store > set window [ containerChild := combo ] > widgetShowAll window > mainGUI > > > Compiling and running the program should bring up a window with a single > combo box with the options "foo", "bar" and "baz". Attempting to select > any of these will result in the error: > > Gtk-CRITICAL **: gtk_entry_set_text: assertion `text != NULL' failed > > I've spent some time trying to figure out what's causing this to happen > but haven't yet been able to fix it. The comboBoxEntrySetTextModel function is used to set up a special case in which the box only contains strings. It creates its own model which is incompatible with our new Haskell model which you create and then use to overwrite the special-case one. So, you should use comboBoxAppendText and friends in ComboBox which are the functions to be used when the widget is set up with comboBoxEntrySetTextModel. I think these function work. I tried to get it to work with the Haskell model: main = do initGUI window <- windowNew onDestroy window mainQuit store <- LS.listStoreNew ["foo", "bar", "baz"] combo <- comboBoxEntryNewWithModel store text <- cellRendererTextNew cellLayoutSetAttributes combo text store (\string -> [cellText := string]) set window [ containerChild := combo ] widgetShowAll window mainGUI Alas, this bombs out since somewhere the ComboBox creates its own CellRenderer and refuses to use the one that I set. I get: Gtk-CRITICAL **: gtk_combo_box_cell_layout_set_cell_data_func: assertion `info != NULL' failed I'm investigating. But these are the dark corners of Gtk+ that few people use, it's just us trying to implement stores in Haskell. > On an unrelated note (at least it seems unrelated since my try at > changing it didn't help), I was wondering if listStoreGetValue might > work better as ListStore a -> Int -> IO (Maybe a) and if I suppose that might be the better type. This would be consistent with TreeStoreNew where treeStoreGetNode :: TreeStore a -> TreePath -> IO (Maybe a) > ListStoreNew.customModelGetIter should check if 'n' is in bounds before > returning an iter. If so, I can provide a patch. This, on the other hand, is probably superfluous. Turning an index into an iter is only performed by a view once it has established that the nth element exists. Even if it creates and uses an invalid iterator, the fault is caught in customTreeModelGetRow when accessing the entry. But please send us the first patch! Thanks for trying the spectacularly wonky new tree/list store, Axel. |