顯示具有 wxHaskell 標籤的文章。 顯示所有文章
顯示具有 wxHaskell 標籤的文章。 顯示所有文章

2010年11月1日 星期一

[Note] The GUI Issue

gtk+,之前在Mac OSX上面跑太多次有問題,已經有點怕了說,不過這次用brew灌就可以用了!不過compile的時候要給的參數好多,照說應該link和load的路徑都不需要再給,改下次有空再來試好了。



裝qt,其實nokia往站上有binary可以裝,可是跑起來覺得怪彆扭的。重點是這樣就打壞了原本弄好的lib系統。所以還是看看homebrew有沒有,果然有,那就灌吧!
> brew install qt
然後,等超過一個半小時了還沒好,所以下次再寫qt筆記吧 XD



這兩天在弄gtk+,莫名其妙的弄半天以後發現,brew灌起來的gtk+應該是可以用。雖說會噴一個奇怪的error出來,但是至少有東西了(那個error好像和顯示裝置的驅動還是設定有關)。gtk可以跑,我當然一如往常的想去試一下多年的夢想「gtk2hs」!他官網晃一圈以後就想起一個慘忍的事實:gtk2hs在ghc 6.12上面有bug。Orz

好吧,只好忍痛和gtk2hs說掰掰。不甘心之餘又回頭去看看現在有什麼其他的GUI package可以用用看。東看西看,還是只有gtk2hs和wxHaskell比較大宗。Orz

無奈之下,試試看wxHaskell吧:
在開始裝wxhaskell之前,要先把mac os x內建的wxWidgets換掉:
> brew install wxmac
如果沒有做這一步,之後執行macosx-app出來的.app會不能執行(mac會該說這個東西格式不對)。

wxmac要build好一會兒(10~20分鐘左右)。然後就可以用cabal來install正主兒:
> cabal install wxcore
build的時候,有滿坑滿谷的cpp deprecated warning Orz。為保安全,紀錄下g++的version:
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)
Copyright (C) 2007 Free Software Foundation, Inc.
然後 > cabal install wx
我也不知道我幹麼分兩段裝,一定是白爛病發作了XD。裝好以後確定一下東西有進去ghc-pkg。
> ghc-pkg list
/usr/local/Cellar/ghc/6.12.3/lib/ghc/package.conf.d
..[略]..
/Users/Jaiyalas/.ghc/i386-darwin-6.12.3/package.conf.d
wx-0.12.1.6
wxcore-0.12.1.6
wxdirect-0.12.1.3

接下來才是問題所在,gui的東西似乎在mac上面都特別刁鑽。wx同樣也不是可以讓你乖乖跑一下就有結果可以開開心心用的。用ghc compile以後直接執行他會噴error如下,並且會跑出一個只能看不能用的視窗。
10:46:15: Debug: wxColour::Set - couldn't set to colour string 'GREY'
[Debug] 10:46:15: Adding duplicate image handler for 'PNG file'
[Debug] 10:46:15: Adding duplicate image handler for 'JPEG file'
[Debug] 10:46:15: Adding duplicate image handler for 'TIFF file'
[Debug] 10:46:15: Adding duplicate image handler for 'GIF file'
[Debug] 10:46:15: Adding duplicate image handler for 'PNM file'
[Debug] 10:46:15: Adding duplicate image handler for 'PCX file'
[Debug] 10:46:15: Adding duplicate image handler for 'Windows icon file'
[Debug] 10:46:15: Adding duplicate image handler for 'Windows cursor file'
[Debug] 10:46:15: Adding duplicate image handler for 'Windows animated cursor file'
[Debug] 10:46:15: Adding duplicate image handler for 'TGA file'
[Debug] 10:46:15: Adding duplicate image handler for 'XPM file'

解決的辦法是把原本的executable file包成.app再去打開它。不過這之前就需要macosx-app來作這件事。細節可以參考stackoverflow上的說明。這邊作個簡單的描述:
抓下macosx-app的模板順便改名字和操作模式
> wget http://code.haskell.org/wxhaskell/bin/macosx-app-template
> mv macosx-app-template macosx-app
> chmod a+x macosx-app
然後開個順手的editor把下面這段加到macosx-app的最上面:
#!/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"

直接執行macosx-app的話會看到他噴出一些warning
> ./macosx-app
Warning: --rezflags, along with Mac OS classic resource building is deprecated. You should remove this from your Makefile and build .app bundles instead.
error: you need to specify a program. Use "--help" to show valid options.
這邊可以不用理他(其實是我也不知道怎要怎麼解決,反正可以用 Orz)

以上都準備好以後就可以直接
> ghc -package wx -o helloworld HelloWorld.hs
> macosx-app -v helloworld
> open helloworld.app
感人的小視窗就會跳出來惹 OvQ