Personal tools

AutoForms

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
m
(Added category wxHaskell)
 
(21 intermediate revisions by one user not shown)
Line 1: Line 1:
  +
IMPORTANT! Development of AutoForms has stopped. In stead use [[WxGeneric]] which is based upon AutoForms. This page may still a good resource for ideas and rationale.
  +
 
= Abstract =
 
= Abstract =
 
AutoForms is a library to ease the creation of Graphical User Interfaces (GUI). It does this by using generic programming to construct GUI components.
 
AutoForms is a library to ease the creation of Graphical User Interfaces (GUI). It does this by using generic programming to construct GUI components.
Line 4: Line 6:
 
The AutoForms user creates an ordinary algebraic data type (ADT), which should reflect the data model of an application. From this ADT AutoForms automatically constructs a GUI component, by using the structure and identifiers of the ADT. To facilitate this construction, AutoForms uses [http://homepages.cwi.nl/~ralf/syb3/ the "Scrap your boilerplate" approach] to generic programming.
 
The AutoForms user creates an ordinary algebraic data type (ADT), which should reflect the data model of an application. From this ADT AutoForms automatically constructs a GUI component, by using the structure and identifiers of the ADT. To facilitate this construction, AutoForms uses [http://homepages.cwi.nl/~ralf/syb3/ the "Scrap your boilerplate" approach] to generic programming.
   
This component can be displayed using [http://wxhaskell.sourceforge.net/ WxHaskell] or by using AutoForms functions. The first facilitates that people who already knows WxHaskell quickly will be able to make GUIs. The second is our attempt at a more functional GUI toolkit.
+
This component can be displayed using [http://wxhaskell.sourceforge.net/ WxHaskell] or by an AutoForms custom monad called WxM.. The first facilitates that people who already knows WxHaskell quickly will be able to make GUIs. The second is our attempt at a more type-safe and easier to use GUI toolkit.
   
 
= Installation =
 
= Installation =
   
Download [https://sourceforge.net/project/showfiles.php?group_id=148130&package_id=163454 AutoForms release 0.3 (AForms.tgz)] and follow the instructions in README.txt.
+
You need the following prerequisites:
  +
  +
* Install [http://wxhaskell.sourceforge.net/ WxHaskell]. You properly need to use the [http://cvs.haskell.org/darcs/wxhaskell/ version in darcs].
  +
* Install [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/syb-with-class-0.3 Scrap Your Boilerplate].
  +
  +
Download [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/AutoForms-0.4.2 AutoForms release 0.4.2] and follow the instructions in README.txt.
   
 
You can also try the bleeding edge version by doing:
 
You can also try the bleeding edge version by doing:
Line 18: Line 20:
 
The three best sources of documentation is the
 
The three best sources of documentation is the
   
* [http://autoforms.sourceforge.net Haddock generated documentation] - however, currently it is a little spare, as we have not yet been successful, at getting the Summer of Code version of Haddock to work properly.
+
* [http://autoforms.sourceforge.net/autodoc/index.html Haddock generated documentation]
* The examples in the [http://autoforms.svn.sourceforge.net/viewvc/autoforms/trunk/AForms/src/Examples/ | src/Examples folder] in the AutoForms distribution.
+
* The examples in the [http://autoforms.svn.sourceforge.net/viewvc/autoforms/trunk/AForms/src/Examples/ src/Examples folder] in the AutoForms distribution.
 
* The two examples below
 
* The two examples below
* The [AutoForms/Tutorial AutoForms tutorial]
+
* The [[AutoForms/Tutorial|AutoForms tutorial]]
   
= Using WxHaskell with AutoForms =
+
= Using AutoForms in cooperation with WxHaskell =
   
 
The best way to illustrate AutoForms is with some examples.
 
The best way to illustrate AutoForms is with some examples.
Line 37: Line 39:
 
main :: IO ()
 
main :: IO ()
 
main = start $
 
main = start $
do w <- frame [text := "Small example"]
+
do w <- frame [text := "AFWx example"]
 
p <- panel w []
 
p <- panel w []
 
 
wid <- makeWidget (0.96::Double, 123::Int, "asdf") p [ ]
+
wid <- makeWidget (0.96::Double, 123::Int, "asdf") p []
 
setWidButton <- button p [ text := "Set widget"
 
setWidButton <- button p [ text := "Set widget"
 
, on command := set wid [ value := (0.32, 456, "New Value") ]
 
, on command := set wid [ value := (0.32, 456, "New Value") ]
Line 55: Line 57:
   
 
<haskell>
 
<haskell>
{-# OPTIONS -fglasgow-exts #-}
+
{-# LANGUAGE FlexibleContexts, FlexibleInstances
{-# OPTIONS -fth #-}
+
, MultiParamTypeClasses, TemplateHaskell, UndecidableInstances #-}
{-# OPTIONS -fallow-undecidable-instances #-}
 
{-# OPTIONS -fallow-overlapping-instances #-}
 
   
 
module SettingsForm where
 
module SettingsForm where
Line 67: Line 69:
 
, spacesInSteadOfTabulators :: Bool } deriving (Show, Eq)
 
, spacesInSteadOfTabulators :: Bool } deriving (Show, Eq)
 
$(derive [''Settings])
 
$(derive [''Settings])
 
-- Should not be neccesary, but GHC 6.6 requires it. Remove when we stop support for GHC 6.6.
 
instance ECCreator Settings
 
   
 
defaultValues :: Settings
 
defaultValues :: Settings
Line 83: Line 82:
 
</haskell>
 
</haskell>
   
Compared to the previous example there is a few new things. First of all we need to set some compiler options, as shown at the top. Secondly, we need to use the template-Haskell function to derive an instance for the Settings-type. Thirdly, we also need to declare that the Settings-type is an instance of ECCreator. The last step is only neccesary for GHC 6.6 - not in GHC 6.8.
+
Compared to the previous example there is a few new things. First of all we need to set some compiler options, as shown at the top. Secondly, we need to use the template-Haskell function to derive an instance for the Settings-type. Thirdly, we also need to declare that the Settings-type is an instance of ECCreator.
   
= Using AutoForms only =
+
= Using the AutoForms monad (WxM) =
The best way to get familiar with the AutoForms-only interface to AutoForms is via [[AutoForms/Tutorial | this tutorial]].
+
The best way to get familiar with the AutoForms monad (WxM) interface to AutoForms is via [[AutoForms/Tutorial|this tutorial]].
But be warned. This interface is experimental. And while it works for some smaller examples, it do have it shortcomings. It is therefore also likely be replaced with something quite different.
 
   
 
= Current state and plans =
 
= Current state and plans =
   
To understand the current state it will be advantageous to know the history of AutoForms. In the beginning this library was inspired by [http://www.sandr.dds.nl/FunctionalForms/index.html functional forms]. E.g. it was an solely an attempt to ease the construction of simple forms (like a preference dialog). Shortly after starting the project, the author discovered that a very similar approach to GUI construction had existed for some time. Namely the [http://www.cs.ru.nl/research/reports/full/NIII-R0408.pdf clean GEC library]. The Clean GEC library do not only try to create forms, but tries to be useable for any kind of GUI. This inspired the author to widen AutoForms scope, by creating functionality for buttons, menus, timers, and more. This unfortunately delayed the core functionality of AutoForms, namely the automatic transformation of an ADT to a GUI.
+
To understand the current state it will be advantageous to know the history of AutoForms. In the beginning this library was inspired by [http://www.sandr.dds.nl/FunctionalForms/index.html functional forms]. E.g. it was an solely an attempt to ease the construction of simple forms (like a preference dialog). Shortly after starting the project, the author discovered that a very similar approach to GUI construction had existed for some time. Namely the [http://www.cs.ru.nl/research/reports/full/NIII-R0408.pdf clean GEC library]. The Clean GEC library do not only try to create forms, but tries to be useable for any kind of GUI. This inspired the author to widen AutoForms scope, by creating functionality for buttons, menus, timers, and more. We encapsulated this functionality in our own monad (WxM). The extra functionality unfortunately delayed the core of AutoForms, namely the automatic transformation of an ADT to a GUI. While this transformation is implemented, it is not as 'inteligent' as it could be.
   
The larger set of functionality has proven less than perfect, as it is not as flexible as was initially hoped for. Thus, we need to make a change of direction. We will do this by either changing the more dynamic aspects of AutoForms (menus, buttons, ...) and/or by dropping the dynamic aspects of AutoForms and gambling on closer integration with existing libraries - like WxHaskell. The last option will also have the advantage of limiting AutoForms scope, and thus speed up development.
+
The larger set of functionality initially proven less than perfect, as it is not as flexible as was initially hoped for. Thus, we have made fundamental changes in this version (0.4). These fundamental changes are not completely finished yet and will be the focus of the next version (0.6).
 
Many people are and has been working on making more functional (as opposed to imperative) Haskell GUI toolkits. This could make Haskell a more productive language for constructing GUI-s. Thus we also consider to integrate AutoForms with one of these toolkits.
 
   
 
= Users of AutoForms =
 
= Users of AutoForms =
Line 101: Line 100:
   
 
* [http://sourceforge.net/projects/autoforms SourceForge site for AutoForms]
 
* [http://sourceforge.net/projects/autoforms SourceForge site for AutoForms]
* [http://www.sandr.dds.nl/FunctionalForms/index.html FunctionalForms] - An approach to making form creation easy. This library is also using WxHaskell. It was the initial inspiration for starting AutoForms.
+
* [http://www.cs.vu.nl/boilerplate/ The generic library which is used in this library]. People from the [http://happs.org/ HappS project] maintains [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/syb-with-class the version of SYB that AutoForms uses].
* [http://www.cs.vu.nl/boilerplate/ The generic library which is used in this library]
+
  +
== Related work ==
 
* [http://www.cs.ru.nl/research/reports/full/NIII-R0408.pdf Compositional Model-Views with Generic Graphical User Interfaces] - Library which, like AutoForms, deduce GUI elements from data types.
 
* [http://www.cs.ru.nl/research/reports/full/NIII-R0408.pdf Compositional Model-Views with Generic Graphical User Interfaces] - Library which, like AutoForms, deduce GUI elements from data types.
  +
* [http://www.sandr.dds.nl/FunctionalForms/index.html FunctionalForms] - An approach to making form creation easy. This library is also using WxHaskell. It was the initial inspiration for starting AutoForms.
  +
* [http://www.cs.nott.ac.uk/~nhn/TFP2006/Papers/01-PolakJarosz-AutomaticGUIFormGenerationUsingTH.pdf Automatic Graphical User Interface Form Generation Using Template Haskell] - a paper about using [[Template_Haskell | Template Haskell]] for the automatic construction of GUI forms.
   
 
= Author of AutoForms =
 
= Author of AutoForms =
Line 110: Line 111:
 
[[Category:Applications]]
 
[[Category:Applications]]
 
[[Category:User interfaces]]
 
[[Category:User interfaces]]
  +
[[Category:wxHaskell]]

Latest revision as of 21:00, 15 January 2012

IMPORTANT! Development of AutoForms has stopped. In stead use WxGeneric which is based upon AutoForms. This page may still a good resource for ideas and rationale.

Contents

[edit] 1 Abstract

AutoForms is a library to ease the creation of Graphical User Interfaces (GUI). It does this by using generic programming to construct GUI components.

The AutoForms user creates an ordinary algebraic data type (ADT), which should reflect the data model of an application. From this ADT AutoForms automatically constructs a GUI component, by using the structure and identifiers of the ADT. To facilitate this construction, AutoForms uses the "Scrap your boilerplate" approach to generic programming.

This component can be displayed using WxHaskell or by an AutoForms custom monad called WxM.. The first facilitates that people who already knows WxHaskell quickly will be able to make GUIs. The second is our attempt at a more type-safe and easier to use GUI toolkit.

[edit] 2 Installation

You need the following prerequisites:

Download AutoForms release 0.4.2 and follow the instructions in README.txt.

You can also try the bleeding edge version by doing:

svn export https://autoforms.svn.sourceforge.net/svnroot/autoforms/trunk/AForms

[edit] 3 Documentation

The three best sources of documentation is the

[edit] 4 Using AutoForms in cooperation with WxHaskell

The best way to illustrate AutoForms is with some examples.

First, we create a widget consisting of a Double, an Int, and a String. This widget is displayed in a window and the values can be manipulated.

module AFWxExample where
 
import Graphics.UI.WX
import Graphics.UI.AF.AFWx
 
main :: IO ()
main = start $
     do w <- frame [text := "AFWx example"]
        p <- panel w []
 
        wid <- makeWidget (0.96::Double, 123::Int, "asdf") p []
        setWidButton <- button p [ text := "Set widget"
                                 , on command := set wid [ value := (0.32, 456, "New Value") ]
                                 ]
 
        set w [ layout := container p $ fill $ column 10
                           [ widget wid, widget setWidButton ]
              ]

The function makeWidget creates a WxHaskell widget and should be the only thing unrecognisable to an ordinary WxHaskell programmer.

We can also create widgets for custom ADT-s. We will show this be creating a settings dialog for a text editor:

{-# LANGUAGE FlexibleContexts, FlexibleInstances
  , MultiParamTypeClasses, TemplateHaskell, UndecidableInstances #-}
 
module SettingsForm where
 
import Graphics.UI.AF.AFWx
import Graphics.UI.WX
 
data Settings = Settings { lineWrap        :: Bool, splitWords      :: Bool
                         , autoSave        :: Bool, tabulatorStops  :: [Int]
                         , spacesInSteadOfTabulators :: Bool }     deriving (Show, Eq)
$(derive [''Settings])
 
defaultValues :: Settings
defaultValues = Settings True False False ([4,8,12] ++ [16,20..120]) False
 
main = start $
      do w <- frame [ text := "Text Editor Settings Forms" ]
         p <- panel w []
 
         wid <- makeWidget defaultValues p []
 
         set p [ layout := widget wid ]

Compared to the previous example there is a few new things. First of all we need to set some compiler options, as shown at the top. Secondly, we need to use the template-Haskell function to derive an instance for the Settings-type. Thirdly, we also need to declare that the Settings-type is an instance of ECCreator.

[edit] 5 Using the AutoForms monad (WxM)

The best way to get familiar with the AutoForms monad (WxM) interface to AutoForms is via this tutorial.

[edit] 6 Current state and plans

To understand the current state it will be advantageous to know the history of AutoForms. In the beginning this library was inspired by functional forms. E.g. it was an solely an attempt to ease the construction of simple forms (like a preference dialog). Shortly after starting the project, the author discovered that a very similar approach to GUI construction had existed for some time. Namely the clean GEC library. The Clean GEC library do not only try to create forms, but tries to be useable for any kind of GUI. This inspired the author to widen AutoForms scope, by creating functionality for buttons, menus, timers, and more. We encapsulated this functionality in our own monad (WxM). The extra functionality unfortunately delayed the core of AutoForms, namely the automatic transformation of an ADT to a GUI. While this transformation is implemented, it is not as 'inteligent' as it could be.

The larger set of functionality initially proven less than perfect, as it is not as flexible as was initially hoped for. Thus, we have made fundamental changes in this version (0.4). These fundamental changes are not completely finished yet and will be the focus of the next version (0.6).

[edit] 7 Users of AutoForms

  • Kamiariduki - A system to judge your derivative work's purpose and license is valid with Ceative Commons License Works.

[edit] 8 Links

[edit] 8.1 Related work

[edit] 9 Author of AutoForms

The author of this library is Mads Lindstrøm. Feel free to contact me with questions, ideas, or comments.