tags:

views:

172

answers:

1
+2  Q: 

wxHaskell on OS X

I want to use wxHaskell on OS X (Snow Leopard, MacBook Pro). I was able to install the library successfully and the script below:

module Main where
import Graphics.UI.WX

main :: IO ()
main = start hello

hello :: IO ()
hello
  = do f    <- frame    [text := "Hello!"]
       quit <- button f [text := "Quit", on command := close f]
       set f [layout := widget quit]

does result in a window being displayed with a single button, as specified. However, nothing happens when I click the button - I don't even get the visual response of the button turning blue to indicate that it's been depressed (haha, no pun intended).

I've heard that you have to run a package called "macosx-app" on wxHaskell binaries to get them to run, but I can't find this anywhere. It's not on my machine or (as far as I can tell) in the WX or wxHaskell distros.

Anyone know what I need to do to get this to work?

+2  A: 

The source release includes a file named macosx-app-template in the bin directory. This file is used by the following part of the configure script to create macosx-app:

cat > config/macosx-app-temp << EOF
#!/bin/sh
rezcomp="$wxinstallrezcomp"
rezfile="$wxinstallrezfile"

EOF
cat config/macosx-app-temp bin/macosx-app-template > config/macosx-app
rm -f config/macosx-app-temp
chmod a+x config/macosx-app

If you already have wxHaskell installed and aren't using the configure script, you could presumably just duplicate these steps—i.e., copy macosx-app-template to macosx-app, make it executable, and add the following lines at the top:

#!/bin/sh

libdir=""

wxrezcomp="`wx-config --rezflags`"
wxrezfile=""
if test "$wxrezcomp"; then
  for word in $wxrezcomp; do
    temp="`echo $word | grep '[^_]*_mac-[^r]*r'`"
    if test "$temp"; then
      wxrezfile="$temp"
    fi
  done
fi

if test "$wxrezfile"; then
  wxrezdir="`echo $wxrezfile | sed -e 's|\(.*\)/libwx_mac.*|\1|'`"
  wxinstallrezcomp="`echo \"${wxrezcomp}\" | sed -e \"s|${wxrezdir}|${libdir}|g\"`"
  wxinstallrezfile="`echo \"${wxrezfile}\" | sed -e \"s|${wxrezdir}|${libdir}|g\"`"
fi

rezcomp="$wxinstallrezcomp"
rezfile="$wxinstallrezfile"

Note that you need to change libdir="" to specify the directory where the wxHaskell library files are installed, and if wx-config isn't in your path you'll need to change that line as well.

Travis Brown
Beautiful! That worked perfectly.Thanks so much!
Bill