Sorry,
None of your suggestions work :(  Thank you much for your help.  Take a look
at my attachment and at updateList5.  It works, though I bet it leaks 
memory.

As I have said before listStoreRemove and listStoreClear do not work at all!
  They both error out with a empy list error.

Timothy


---------- Původní zpráva ----------
Od: Axel Simon <axel.si...@in.tum.de>
Datum: 8. 11. 2012
Předmět: Re: [Gtk2hs-devel] listStoreClear , listStoreRemove, and 
treeViewSetModel all broken?
"On 08.11.2012, at 19:48, <timothyho...@seznam.cz> wrote:

> You didn't read the comments of my source. I cannot prepend, because I 
want to be able to remove items as well as add them. I think I'll end up 
just replacing the entire tree view, and to Dickens with performance.
> 

Have a look at 

http://hackage.haskell.org/packages/archive/gtk/0.12.3/doc/html/src/Graphics
-UI-Gtk-ModelView-ListStore.html
(http://hackage.haskell.org/packages/archive/gtk/0.12.3/doc/html/src/Graphics-UI-Gtk-ModelView-ListStore.html)

which shows you which functions are implemented. If you want to replace a 
list with the minimum distraction, you could iterate through the old and the
new list at the same time and emit the corresponding listStoreInsert and 
listStoreRemove calls. If you're ok with replacing the whole list, call 
listStoreClear (but note that this is also linear) and then 
listStorePrependList.

You cannot replace the whole ListStore or even the ListView widget as this 
causes all sorts of havoc in the user interface.

Cheers,
Axel

> 
> 
> Timothy
> 
> 
> 
> ---------- Původní zpráva ----------
> Od: Axel Simon <axel.si...@in.tum.de>
> Datum: 8. 11. 2012
> Předmět: Re: [Gtk2hs-devel] listStoreClear , listStoreRemove, and 
treeViewSetModel all broken?
> 
> Hi Tim,
> 
> You cannot replace the model of the view with a new one. You need to 
> modify the existing ListStore.
> 
> Could you try listStorePrependList? That looks like the most sane 
> function that is actually implemented. I admit that ListStore could 
> use some love.
> 
> Cheers,
> Axel
> 
> On 08.11.2012, at 14:56, <timothyho...@seznam.cz> wrote:
> 
> > Hey I've been playing around with http://www.haskell.org/haskellwiki/Gtk
2Hs/Tutorials/TreeView
(http://www.haskell.org/haskellwiki/Gtk2Hs/Tutorials/TreeView) 
> > and packing it up into a simple library. I'm trying to make the 
> > list updatable however, and so far all of my attempts have failed :(
> >
> > See line 45 of my attachment please.
> > <SimpleListView.hs>
> > ------------------------------------------------------------------------
------
> > Everyone hates slow websites. So do we.
> > Make your web apps faster with AppDynamics
> > Download AppDynamics Lite for free today:
> > http://p.sf.net/sfu/appdyn_d2d_nov______________________________________
_________
(http://p.sf.net/sfu/appdyn_d2d_nov_______________________________________________)
> > Gtk2hs-devel mailing list
> > Gtk2hs-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel
(https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel)"
-- From http://www.haskell.org/haskellwiki/Gtk2Hs/Tutorials/TreeView

module Main where
--module SimpleListView where

import Graphics.UI.Gtk as GTK
import Control.Concurrent.MVar as MV

--{-
main :: IO ()
main = do
   initGUI       -- is start
   window <- windowNew
   (treeview,UpdateTreeView updateList) <- simpleListView "Subjects" ["Fred","Bob","Mary"] putStrLn
   containerAdd window treeview
   onDestroy window mainQuit
   widgetShowAll window
   updateList' <- updateList $ map show [1..10]
   mainGUI
   return ()---}

newtype UpdateTreeView = UpdateTreeView ([String] -> IO UpdateTreeView)

simpleListView :: String -> [String] -> (String -> IO()) -> IO (GTK.VBox,UpdateTreeView)
simpleListView title intitialListItems onSelect = do
 vb <- GTK.vBoxNew False 0
 let
  createListView listItems =
   do
    list <- listStoreNew listItems
    listMVar <- MV.newMVar list
    treeview <- GTK.treeViewNewWithModel list
    GTK.boxPackEnd vb treeview GTK.PackGrow 0
    GTK.treeViewSetHeadersVisible treeview True
    -- there should be a simpler way to render a list as the following!
    col <- GTK.treeViewColumnNew
    GTK.treeViewColumnSetTitle col title
    renderer <- GTK.cellRendererTextNew
    GTK.cellLayoutPackStart col renderer False
    GTK.cellLayoutSetAttributes col renderer list
            $ \ind -> [GTK.cellText := ind]
    GTK.treeViewAppendColumn treeview col

    tree <- GTK.treeViewGetSelection treeview
    GTK.treeSelectionSetMode tree  SelectionSingle
    GTK.onSelectionChanged tree (oneSelection listMVar tree onSelect)
    let
     updateList1 newListItems =
      do
       putStrLn "1"
       newList <- listStoreNew newListItems
       putStrLn "2"
       GTK.cellLayoutSetAttributes col renderer newList
         $ \ind -> [GTK.cellText := ind]
       putStrLn "3"
       GTK.treeViewSetModel treeview newList
       --SimpleListView: Prelude.head: empty list
       putStrLn "4"
       return $ UpdateTreeView updateList1
     updateList2 newListItems =
      do
       size <- GTK.listStoreGetSize list
       mapM_ (GTK.listStoreRemove list) [0..size-1]
       -- SimpleListView: Prelude.head: empty list
       mapM_ (GTK.listStoreAppend list) newListItems
       return $ UpdateTreeView updateList2
     updateList3 newListItems =
      do
       GTK.listStoreClear list
       mapM_ (GTK.listStoreAppend list) newListItems
       -- SimpleListView: Prelude.head: empty list
       return $ UpdateTreeView updateList3
     updateList4 newListItems =
      do
       GTK.listStoreRemove list 0
       -- SimpleListView: Prelude.head: empty list
       return $ UpdateTreeView updateList4
     updateList5 newListItems = --Works!
      do
       GTK.widgetDestroy treeview
       (_,update) <- createListView newListItems
       widgetShowAll vb
       return update
    return $ (treeview,UpdateTreeView updateList5)
 (_,update) <- createListView intitialListItems
 return (vb,update)


oneSelection :: MV.MVar (GTK.ListStore String) -> GTK.TreeSelection -> (String -> IO ()) ->  IO ()
oneSelection listMVar tree onSelect = do
   list <- MV.takeMVar listMVar
   sel <- GTK.treeSelectionGetSelectedRows tree
   let s = head  (head sel)
   v <- GTK.listStoreGetValue list s
   onSelect v
   MV.putMVar listMVar list
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_nov
_______________________________________________
Gtk2hs-devel mailing list
Gtk2hs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel

Reply via email to