Personal tools

WxHaskell

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(What is it?: Removed info about the 0.13 branch, as it is no longer maintained)
(114 intermediate revisions by 17 users not shown)
Line 1: Line 1:
[[Category:User interfaces]]
+
<!-- __NOTOC__ -->
  
[[Image:Wxhaskell-black-small.png|center]]
 
  
 +
[[File:Wxhaskell-black-medium.png|right|500px]]
 +
<br>
 
== What is it? ==
 
== What is it? ==
  
Line 8: Line 9:
 
maintaining) one ourselves.
 
maintaining) one ourselves.
  
wxHaskell is therefore built on top of [http://www.wxwidgets.org 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).
+
wxHaskell is therefore built on top of [http://www.wxwidgets.org 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.
 +
 
 +
The current version of wxHaskell supports wxWidgets 2.9 and 3.0. For wxWidgets 3.0, Windows users can easily install wxWidgets together with wxHaskell, using a [https://sourceforge.net/projects/wxhaskell/files/wxInstall/ wxInstall package].
  
 
== Status ==
 
== Status ==
  
Since the core interface is generated automatically from the [http://elj.sourceforge.net/projects/gui/ewxw/ wxEiffel] binding, about 90% of the wxWidgets functionality is already supported, excluding more &quot;exotic&quot; 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.
+
The core interface of wxHaskell was originally derived from the [http://elj.sourceforge.net/projects/gui/ewxw/ wxEiffel] binding. Work on this has been dormant for several years, but the wxHaskell maintainers now support updates to the wxWidgets API themselves.
  
 +
There are four key components of wxHaskell from version 0.90 onwards (three in earlier branches).
 +
* wxdirect parses specially written C headers and generates low level Haskell FFI bindings for the exported functions.
 +
* wxc is a C language binding for wxWidgets. It is needed because the Haskell FFI can only bind to C as it does not understand C++ name mangling. Because it is a C language wrapper over wxWidgets, and is generated as a standard dynamic library on all supported platforms, wxc could be used as the basis for a wxWidgets wrapper for any language which supports linking to C (so that would be all of them then). In older versions of wxHaskell, the wxc components were built as a monolithic static library with wxcore.
 +
* wxcore is a set of low-level Haskell bindings to wxc. A large part is generated automatically by wxdirect, with some key abstractions being hand-coded in Haskell. You can program directly to the wxcore interface if you wish (it is sometimes the only way, in fact).
 +
* wx is a set of higher-level wrappers over wxcore. It is intended to make it easier to write reasonably idiomatic Haskell. Most wxHaskell software is about 80% wx and 20% wxcore.
  
== News ==
+
The C wrapper is, unfortunately, generated by hand, so there is some (mainly tedious boilerplate) work involved in porting a new set of widgets to wxHaskell. Some work has been done into automating this aspect, but we are far from being able to replicate the approach reliably over then entire API as yet.
  
<dl><dt>23 March 2008</dt>
+
From the perspective of the user (rather than the developer) about 90% of the core wxWidgets functionality is already supported, excluding more &quot;exotic&quot; widgets like dockable windows. The library supports Windows, GTK (Linux) and macOS X.
<dd>wxHaskell 0.10.3 is [http://sourceforge.net/project/showfiles.php?group_id=73133 released].</dd>
+
<dt>20 January 2007</dt><dd>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).</dd></dl>
+
  
== Documentation ==
+
== News ==
  
* [http://wxhaskell.sourceforge.net/index.html homepage]
+
; 28 April 2017: wxHaskell 0.92.3 is released.
* [http://wxhaskell.sourceforge.net/screenshots.html screenshots]
+
; 30 December 2015: wxInstall Achelanne 0.1 and wxHaskell 0.92.2 are released.
** [http://wxhaskell.sourceforge.net/samples.html samples]
+
; 9 October 2015: wxInstall Abriline packages and wxHaskell 0.92.1 are released.
** [http://wxhaskell.sourceforge.net/applications.html applications]
+
; 27 August 2015: wxHaskell 0.92.0 is released.
* [[WxHaskell/Documentation|documentation]]
+
; 12 August 2014: wxHaskell 0.91.0 is released. This version accepts wxWidgets 2.9 and 3.0.
** [[WxHaskell/License|license]]
+
; 21 March 2014: wxHaskell 0.90.1 is released.
** [[WxHaskell/Quickstart|quick start]]
+
** [[WxHaskell/FAQ|faq]]
+
* [[WxHaskell/Download|download]]
+
*[[WxHaskell/Building|building]]
+
** [[WxHaskell/Building_on_Cygwin|cygwin]]
+
** [[WxHaskell/Building_on_Windows|msc]]
+
** [[WxHaskell/Building_on_MacOS_X|macosx]]
+
*[[WxHaskell/Development|development]]
+
*[[WxHaskell/Contribute|contribute]]
+
  
== Installation ==
+
See also [[wxHaskell/Old wxHaskell news | Old wxHaskell news]]
  
The [[WxHaskell/Install | wxHaskell install]] page contains details of different people's experience in compiling and installing wxHaskell against various versions of wxWidgets on various platforms.
+
== Documentation ==
  
== Tips ==
+
* [http://wxhaskell.sourceforge.net/screenshots.html Screenshots]
 +
** [http://wxhaskell.sourceforge.net/samples.html Samples] ( the links to the source code on that page are broken, but you can see the sources  [https://github.com/wxHaskell/wxHaskell/tree/master/samples here] )
 +
** [http://wxhaskell.sourceforge.net/applications.html Applications]
 +
* [[/Documentation/|Using wxHaskell]]
 +
** [[/License/]]
 +
** [[/Quick start/]]
 +
** [[/FAQ/]]
 +
** [[/Short guide/]]
 +
** [[/Tips and tricks/]]
 +
** [https://hackage.haskell.org/package/wx/docs/doc-index.html Index] of the wx API documentation
 +
** [https://hackage.haskell.org/package/wxcore-0.92.0.0/docs/doc-index.html Index] of the wxcore API documentation
 +
** [[WxHaskell/Hierarchy | The hierarchy of the C++ classes of wxWidgets, as mapped in wxHaskell]]
 +
* [[/Download/]]
 +
* Building and installing. Please refer to your platform.
 +
** [[/Linux/]]
 +
** [[/Mac/]]
 +
** [[/Windows/]]
 +
** Additional information here. Please help migrating these parts to their appropriate platform.
 +
*** [[/2.8/|wxWidgets 2.8.x]]
 +
*** [[/0.13/|wxHaskell 0.13 for wxWidgets 2.8.x]]
 +
*** [[WxHaskell/Building]]
 +
*[[/Development/]]
 +
** [[/Development/Environment | Working on wxHaskell]]
 +
** [[/Development/Debugging  | Debugging]]
 +
*[[/Contribute/]]
  
# Getting Started:
+
== Resources ==
#* read carefully http://wxhaskell.sourceforge.net/quickstart.html - it contains more information than you think
+
* [http://sourceforge.net/p/wxhaskell/_list/tickets Tickets for bugs and feature requests]
#* we include below some orientation for the most essential wxhaskell concepts
+
* [https://lists.sourceforge.net/lists/listinfo/wxhaskell-devel The developer mailing list (wxhaskell-devel)] [http://sourceforge.net/p/wxhaskell/mailman/wxhaskell-devel/ (archive)]
#* see samples/wx/Minimal.hs
+
* [http://sourceforge.net/p/wxhaskell/mailman/wxhaskell-users/ The wxHaskell users mailing list (wxhaskell-users)] [http://sourceforge.net/p/wxhaskell/mailman/wxhaskell-users/ (archive)]
# Text:
+
* [https://github.com/wxHaskell/wxHaskell wxHaskell repository], as of 2 Aug 2013 replacing the [https://github.com/jodonoghue/wxHaskell old repo] and [https://github.com/atzedijkstra/wxHaskell temporary maintenance repo] on GitHub
#* 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
+
# [[WxHaskell/Layout | 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 <br /><code> ghc -fffi -package wx EnableGUI.hs<br /> ghci -package wx HelloTest.hs EnableGui.hs<br />-- followed by :m +EnableGUI and <br />enableGUI >> main</code>
+
 
+
== A Short Guide ==
+
 
+
It is helpful to a get a grip on three basic concepts: Widgets, Layout and Events.
+
 
+
=== Widgets ===
+
Widgets are the basic components of any GUIs.  They include buttons, radio boxes, frames and what not.  There are essentially two kinds of widgets: windows and controls.  Windows are widgets that contain other widgets.  Note: what you might normally think of as a window, i.e. that big thing with the close, minimise, maximise buttons on your OS in wxHaskell is a special kind of window called a "frame".
+
 
+
We define windows by calling some function (for example, ''frame'') with a list of attributes.  Here is a example which creates a frame with the title bar "Hello!":
+
 
+
hello
+
  = do f    <- frame    [text := "Hello!"]
+
 
+
The more interesting widgets are controls such a buttons and check boxes.  We define controls almost the same way as windows, by calling some function (for example, ''button'') with a window and a list of attributes:
+
 
+
hello
+
  = do f    <- frame    [text := "Hello!"]
+
        quit <- button f [text := "Quit"]
+
 
+
The relevant documentation:
+
  * http://wxhaskell.sourceforge.net/doc/Graphics.UI.WX.Controls.html
+
  * http://wxhaskell.sourceforge.net/doc/Graphics.UI.WX.Window.html
+
 
+
=== Layout ===
+
[[WxHaskell/Layout | Layout]] means telling wxHaskell how to arrange your widgets with respect to each other.  It is something you would normally do after you have defined all your widgets.
+
 
+
We won't go into much detail here because the Haddock-generated documentation is very helpful here, but here is a trivial example of layout where all we do is stick the quit button in the frame.  Notice how layout is just an attribute of the frame widget.
+
 
+
hello
+
  = do f    <- frame    [text := "Hello!"]
+
        quit <- button f [text := "Quit"]
+
        set f [layout := widget quit]
+
 
+
  * http://wxhaskell.sourceforge.net/doc/Graphics.UI.WX.Layout.html
+
 
+
==== Scrolled windows ====
+
 
+
Widgets (for example, listboxes) will automatically create scrolled windows for you.  You only need to deal with them if you are working with bitmaps.
+
 
+
 
+
==== XRC ====
+
How do you use XRC-Files with wxHaskell? Is it possible?
+
 
+
''- I also very much would like to know this. Anyone?''
+
 
+
:''There isn't a way, but it sounds like it might be a fun library to build''
+
 
+
=== Events ===
+
Events are what joins your widgets to the rest of your code.  Whenever a user manipulates a widget (e.g. presses a button), an event is triggered.
+
If you set the appropriate attributes, you can cause these events to call some piece of Haskell code.  In the following example, we set the "on command" attribute to close the frame f.
+
 
+
hello
+
  = do f    <- frame    [text := "Hello!"]
+
        quit <- button f [text := "Quit", on command := close f]
+
        set f [layout := widget quit]
+
 
+
* http://wxhaskell.sourceforge.net/doc/Graphics.UI.WX.Events.html
+
 
+
==== Idle Event ====
+
Use [[WxHaskell/Idle event | idle event]] for automation.
+
 
+
== Tricky problems and their solutions ==
+
 
+
=== 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 ==
 
== External links ==
  
* Daan Leijen: [http://www.cs.uu.nl/~daan/download/papers/wxhaskell.pdf wxHaskell / A Portable and Concise GUI Library for Haskell] (pdf)
+
* Daan Leijen: [[media:wxhaskell.pdf | wxHaskell - A Portable and Concise GUI Library for Haskell]]
 
* Wei Tan: [http://www.cse.unsw.edu.au/~cs4132/lecture/wlta543.pdf GUI programming with wxHaskell] (pdf)
 
* Wei Tan: [http://www.cse.unsw.edu.au/~cs4132/lecture/wlta543.pdf GUI programming with wxHaskell] (pdf)
* Koen Lindström Claessen: Graphical User Interfaces in Haskell], slides ([http://www.cs.chalmers.se/Cs/Grundutb/Kurser/afp/slides-GUI.pdf pdf], [http://www.cs.chalmers.se/Cs/Grundutb/Kurser/funht/lec-6a-GUI.ppt ppt])
+
* [https://web.archive.org/web/20091220115259/http://www.cse.chalmers.se/edu/course/afp/lab1.html Assignment 1] part of the course (Web Archive)
* [http://www.cs.chalmers.se/Cs/Grundutb/Kurser/afp/wxhaskell.html WxHaskell] part of the course [http://www.cs.chalmers.se/Cs/Grundutb/Kurser/afp/ Advanced Functional Programming], by [http://www.cs.chalmers.se/~koen/ Koen Lindström Claessen] and [http://www.cs.chalmers.se/~bringert/ Björn Bringert], a portal like page (html)
+
[http://www.cse.chalmers.se/edu/course/afp/index.html Advanced Functional Programming], by [http://www.cse.chalmers.se/~koen/ Koen Lindström Claessen] and [http://www.cse.chalmers.se/alumni/bringert/ Björn Bringert], a portal like page (html)
 +
* [https://en.wordpress.com/tag/wxhaskell/ Blog articles about wxHaskell]
 +
* [https://stackoverflow.com/questions/tagged/wxhaskell Questions about wxHaskell] on Stack Overflow
 +
* Sander Evers, Peter Achten, and Jan Kuper: [https://web.archive.org/web/20110724164915/http://www.st.cs.ru.nl/papers/2005/eves2005-FFormsIFL04.pdf A Functional Programming Technique for Forms in GUI] (PDF, from the Web Archive)
 +
* [http://www.sandr.dds.nl/FunctionalForms/ FunctionalForms], a combinator library/domain specific language for wxHaskell which enables a very concise programming style for forms (not maintained since 2005)
 +
* [https://wewantarock.wordpress.com/2010/01/31/building-a-text-editor-part-1/  Learning by Example Beginners]: a Text Editor
 +
* [https://wewantarock.wordpress.com/2010/01/07/custom-controls-in-wxhaskell-part-1/  Learning by Example Intermediate]:  Custom controls
  
 
== See also ==
 
== See also ==
  
* [http://en.wikibooks.org/wiki/Haskell/GUI The Haskell wikibook GUI chapter]
+
* The [http://packdeps.haskellers.com/reverse/wx reverse dependencies list for wx]
* [http://autoforms.sourceforge.net Autoforms]
+
* [http://hackage.haskell.org/package/wxhnotepad An example of how to implement a basic notepad with wxHaskell]
* [http://zoo.cs.yale.edu/classes/cs490/03-04b/bartholomew.robinson/ WxFruit]
+
* [http://www.mail-archive.com/wxhaskell-users@lists.sourceforge.net/msg01178.html Reducing linking and startup times]
* [http://www.haskell.org/jcp/hw05.pdf Can GUI Programming Be Liberated From The IO Monad]
+
* [http://sourceforge.net/p/wxhaskell/feature-requests/6/ Modified Paint.hs example] to show wxGCDC and graphics path drawing in action.
* [[Phooey]]: a purely functional layer on top of WxHaskell
+
* [https://en.wikibooks.org/wiki/Haskell/GUI The Haskell wikibook GUI chapter]
* [[GuiTV]]: GUI-based tangible values & composable interfaces, on [[TV]], [[Phooey]] and WxHaskell.
+
* [https://lindstroem.wordpress.com/2008/05/21/using-wxgeneric/ WxGeneric]
 +
* [[wxFruit]]
 +
* [http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.167.3926&rep=rep1&type=pdf 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.
 +
* [[wxAsteroids]]: a game demonstrating wxHaskell.
 +
* [[GeBoP]]: the General Boardgames Player, offers a set of board games: Ataxx, Bamp, Halma, Hex, Kram, Nim, Reversi, TicTacToe, and Zenix.
 +
* [https://github.com/JohnLato/Haskell-BlackBoard/blob/master/README.md Haskell-BlackBoard:] a drawing application for making slideshows and videos, based on wxHaskell and [[Functional Reactive Programming]]
 +
* [[Reactive-banana|reactive-banana]] - FRP library with bindings to wxHaskell.
 +
* [http://uu-computerscience.github.io/js-asteroids/ wxHaskell for the web]: a port of a subset of wxHaskell to the web browser.
 +
* [https://stackoverflow.com/questions/15867654/wx-haskell-drag-and-drop-example wxHaskell Drag and Drop example] (Stack Overflow)
 +
* The package [http://hackage.haskell.org/package/binding-wx binding-wx]; binds mutable data and lists to wxHaskell widgets.
 +
* [http://wxhaskell.sourceforge.net/applications.html Application screenshots]
 +
* [http://foswiki.cs.uu.nl/foswiki/Dazzle/WebHome Dazzle] (see also [http://www.cs.uu.nl/dazzle/f08-schrage.pdf Haskell Ready to Dazzle the Real World] (PDF))
 +
* [ https://www.scss.tcd.ie/Andrew.Butterfield/Saoithin/ Unifying Theories of Programming Theorem Prover U·(TP)2]
 +
* [https://github.com/bendmorris/pssat Protein Secondary Structure Alignment Tool] - performs a probabilistic alignment of predicted secondary structures, and generates HTML output
  
[[Category:Applications]]
+
 
 +
[[Category:User interfaces]]
 +
[[Category:Libraries]]
 
[[Category:wxHaskell]]
 
[[Category:wxHaskell]]
 +
[[Category:Packages]]

Revision as of 13:33, 28 June 2017


Wxhaskell-black-medium.png


Contents

1 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.

The current version of wxHaskell supports wxWidgets 2.9 and 3.0. For wxWidgets 3.0, Windows users can easily install wxWidgets together with wxHaskell, using a wxInstall package.

2 Status

The core interface of wxHaskell was originally derived from the wxEiffel binding. Work on this has been dormant for several years, but the wxHaskell maintainers now support updates to the wxWidgets API themselves.

There are four key components of wxHaskell from version 0.90 onwards (three in earlier branches).

  • wxdirect parses specially written C headers and generates low level Haskell FFI bindings for the exported functions.
  • wxc is a C language binding for wxWidgets. It is needed because the Haskell FFI can only bind to C as it does not understand C++ name mangling. Because it is a C language wrapper over wxWidgets, and is generated as a standard dynamic library on all supported platforms, wxc could be used as the basis for a wxWidgets wrapper for any language which supports linking to C (so that would be all of them then). In older versions of wxHaskell, the wxc components were built as a monolithic static library with wxcore.
  • wxcore is a set of low-level Haskell bindings to wxc. A large part is generated automatically by wxdirect, with some key abstractions being hand-coded in Haskell. You can program directly to the wxcore interface if you wish (it is sometimes the only way, in fact).
  • wx is a set of higher-level wrappers over wxcore. It is intended to make it easier to write reasonably idiomatic Haskell. Most wxHaskell software is about 80% wx and 20% wxcore.

The C wrapper is, unfortunately, generated by hand, so there is some (mainly tedious boilerplate) work involved in porting a new set of widgets to wxHaskell. Some work has been done into automating this aspect, but we are far from being able to replicate the approach reliably over then entire API as yet.

From the perspective of the user (rather than the developer) about 90% of the core wxWidgets functionality is already supported, excluding more "exotic" widgets like dockable windows. The library supports Windows, GTK (Linux) and macOS X.

3 News

28 April 2017
wxHaskell 0.92.3 is released.
30 December 2015
wxInstall Achelanne 0.1 and wxHaskell 0.92.2 are released.
9 October 2015
wxInstall Abriline packages and wxHaskell 0.92.1 are released.
27 August 2015
wxHaskell 0.92.0 is released.
12 August 2014
wxHaskell 0.91.0 is released. This version accepts wxWidgets 2.9 and 3.0.
21 March 2014
wxHaskell 0.90.1 is released.

See also Old wxHaskell news

4 Documentation

5 Resources

6 External links

Advanced Functional Programming, by Koen Lindström Claessen and Björn Bringert, a portal like page (html)

7 See also