1

I'm making a simple image downloader to learn some basic gui things in haskell. I have a staticText box that displays the file names while it's downloading them.

The problem I'm having is with this little recursive function.

saveImgs :: [String] -> IO ()
saveImgs [] = return ()
saveImgs (x:xs) = do
    let filename = tail $ x =~ "/[^/]*$"
    logMessage x
    maybeWrite filename =<< (simpleHttp x) `X.catch` statusExceptionHandler
    saveImgs xs
        where maybeWrite f b | b == L.empty = return ()
                             | otherwise    = L.writeFile f b

It takes the list of urls of images to save, and updates a textCtrl widget. Except, it only ever updates the text once, after the entire thing is done. Is there some way to update the text of a textbox manually?

Update: I tried adding a timer and starting it, but it doesn't do anything.

timerClk <- timer f [on command := windowRefresh logBox False]
Obrazi
  • 77
  • 7

1 Answers1

1

You could try refreshing with a timer, like it is done in http://dready.org/papers/wxHaskell/Watch.hs

See the line

    timerClk <- timer f [ on command := do { t <- getTimeString; set timeStatic [text := t]; windowRefresh timeStatic False} ]

Note, that Watch.hs is bitrotten, the import statements must be updated; it should work if you replace the imports with:

    import Graphics.UI.WX
    import Graphics.UI.WXCore hiding (Timer)
    import Data.Time          hiding (parseTime)
    import Control.Monad
    import System.Time
    import System.Environment
HJvT
  • 109
  • 3