WxHaskell

What is it?
wxHaskell is a portable and native GUI library for Haskell. The goal of the project is to provide an industrial strength GUI library for Haskell, but without the burden of developing (and maintaining) one ourselves.
wxHaskell is therefore built on top of wxWidgets – a comprehensive C++ library that is portable across all major GUI platforms; including GTK, Windows, X11, and MacOS X. Furthermore, it is a mature library (in development since 1992) that supports a wide range of widgets with the native look-and-feel, and it has a very active community (ranked among the top 25 most active projects on sourceforge).
Status
Since the core interface is generated automatically from the wxEiffel binding, about 90% of the wxWidgets functionality is already supported, excluding more "exotic" widgets like dockable windows. Most work is currently directed into writing a Haskellized version of the wxWidgets API. The library currently supports Windows, GTK (Linux) and MacOS X.
News
- 23 March 2008
- wxHaskell 0.10.3 is released.
- 20 January 2007
- wxHaskell has a new set of maintainers, led by Jeremy O'Donoghue. We are working on a release for version 0.10, with Uni code support, a Cabalized build process and more. All recent development is taking place under a new darcs repository (darcs get http://darcs.haskell.org/wxhaskell).
Documentation
Installation
The wxHaskell install page contains details of different people's experience in compiling and installing wxHaskell against various versions of wxWidgets on various platforms.
Tips and tricks
- Getting Started:
- read carefully http://wxhaskell.sourceforge.net/quickstart.html - it contains more information than you think
- we include below some orientation for the most essential wxhaskell concepts
- see samples/wx/Minimal.hs
- Text:
- retrieving the text of a TextCtrl: mytext <- get mytextEntry text
- staticText misbehaves on resize: make sure that you are giving the widget enough space... for example, if you want a one-line staticText, you should
- use hfill on the staticText
- not use hfill (or hfloat...) or any other widgets in the same row
- Layout:
- Don't bother looking at the the examples yet, the API is better for this
- See the Haddock-generated documentation for Graphics.UI.WX.Layout
- Got layout troubles? Packing things inside yet another panel seems to help sometimes
- Scroll Bars:
- scrollbars are just windows. You create a scrollFrame, and any widgets you want inside the scrollbars, you make this scrollFrame their parent
- see samples/wx/ImageViewer.hs
- the following widgets (controls) already include scrollbars : listBox
- Mac OS X (Darwin)
- for ghci usage download EnableGui.hs from wxhaskell.sourceforge.net/download/EnableGUI.hs and
ghc -fffi -package wx EnableGUI.hs
ghci -package wx HelloTest.hs EnableGui.hs
-- followed by :m +EnableGUI and
enableGUI >> main
- for ghci usage download EnableGui.hs from wxhaskell.sourceforge.net/download/EnableGUI.hs and
Other tips
Idle event
Use the idle event for automation.
Long computations
Scenario: you've got a looooooong computation and you want to update a progress bar or you want to have a 'STOP' button which aborts the computation
Solution:
- wxcApp(Safe)Yield
FIXME: elaborate on this!
Managing multiple windows
Scenario: you have a main window MAIN with some information. You want to create a secondary window PARAMS in which the user edits some configuration stuff. When the user closes PARAMS, the window MAIN should be updated to reflect the new settings.
You have some code which looks like
set paramsButton [ on command := do createParamsWindow updateMainWindow ]
Problem: MAIN is not updated... at least, not until you call PARAMS a second time.
Observations:
- This is NOT a problem with Haskell laziness
Explanation: updateMainWindow tries to read the new configuration value, but it does not succeed, because no configuration values have changed. Why not? Simpler than it looks: all the createParamsWindow function does is creates a window with some widgets, assign some commands to said widgets, and return. There's nothing in the createParamsWindow code that says the function should only return when PARAMS has been closed.
Solution: Pass createParamsWindow a function which updates the MAIN window:
set paramsButton [ on command := do createParamsWindow updateMainWindow ]
When the user closes PARAMS, one of the final things it should do is call this update function
External links
- Daan Leijen: wxHaskell / A Portable and Concise GUI Library for Haskell (pdf)
- Wei Tan: GUI programming with wxHaskell (pdf)
- Koen Lindström Claessen: Graphical User Interfaces in Haskell], slides (pdf, ppt)
- WxHaskell part of the course Advanced Functional Programming, by Koen Lindström Claessen and Björn Bringert, a portal like page (html)
See also
- The Haskell wikibook GUI chapter
- Autoforms
- WxFruit
- Can GUI Programming Be Liberated From The IO Monad
- Phooey: a purely functional layer on top of WxHaskell
- GuiTV: GUI-based tangible values & composable interfaces, on TV, Phooey and WxHaskell.