Difference between revisions of "Grapefruit"

From HaskellWiki
Jump to navigation Jump to search
(building update (multiple packages))
(building update)
Line 33: Line 33:
 
== Building ==
 
== Building ==
   
You need GHC 6.8.1 and Gtk2Hs 0.9.12.1 to build and use Grapefruit.
+
You need at least GHC 6.8.1 and Gtk2Hs 0.9.12.1 to build and use Grapefruit. Currently, Grapefruit is tested with GHC 6.8.2 and Gtk2Hs 0.9.12.1.
   
 
To actually build Grapefruit, use [http://haskell.org/cabal/ Cabal]. Grapefruit consists of the following packages:
 
To actually build Grapefruit, use [http://haskell.org/cabal/ Cabal]. Grapefruit consists of the following packages:
Line 42: Line 42:
 
* grapefruit-examples
 
* grapefruit-examples
 
You should build these packages in this order by descending into the respective directories and issuing the appropriate Cabal commands there. If you don’t have any special requirements (like a non-default install path), you can use the following sequence of commands for each package:<blockquote><p><code>runghc Setup.lhs configure<br />runghc Setup.lhs build<br />runghc Setup.lhs install</code></p></blockquote>
 
You should build these packages in this order by descending into the respective directories and issuing the appropriate Cabal commands there. If you don’t have any special requirements (like a non-default install path), you can use the following sequence of commands for each package:<blockquote><p><code>runghc Setup.lhs configure<br />runghc Setup.lhs build<br />runghc Setup.lhs install</code></p></blockquote>
  +
  +
It might be that during building of grapefruit-example you will experience error messages like “Can't find interface-file declaration for type constructor or class Graphics.UI.Grapefruit.Adapters.Gtk2Hs.Widget.:CoF:R2Value” with some message lines before and after them. Please ignore them and try to run the executables nevertheless. I experienced no problems with this approach.
   
 
== Documentation ==
 
== Documentation ==

Revision as of 13:59, 17 January 2008


About

Grapefruit is a library for creating graphical user interfaces and animated graphics in a declarative way. It is currently based on Gtk2Hs but implementations on top of other GUI libraries are planned for the future.

Grapefruit makes it possible to implement graphical user interfaces by describing them as systems of interconnected components. Components can be visible components like widgets and windows but also invisible components which provide certain control functionality. Component systems can be built from components by using methods from the Arrow and ArrowLoop classes.

Components communicate via signals. A signal is either continuous or discrete. A continuous signal denotes a time-varying value. A discrete signal denotes a sequence of values assigned to discrete points in time and can therefore be used to model streams of events. Several functions allow the construction of signals in a purely functional manner.

Grapefruit has also support for list signals, special signals denoting time-varying lists where each element has a unique identity. An algebra for list signals provides operations like concatenation, filtering and sorting. The key point is that when the value of a list signal changes, the values of the list signals depending on it do not have to be recalculated completely but can be just updated incrementally.

User interfaces with a changing collection of widgets are also possible with Grapefruit. There is a special widget which takes a list signal of widgets as its input and always contains the elements of it as its child widgets.

Furthermore, it is possible to implement animations using graphic signals. These are implemented on top of OpenGL. So-called caching graphic signals are available to make use of OpenGL’s display lists.

With Grapefruit, user interface descriptions always cover the complete lifetime of the respective interface. No explicit event handler registrations and no explicit recalculations of values are necessary. This is in line with the declarative nature of Haskell because it stresses how the user interface operates instead of how this operation is achieved. Internally though, signals are implemented efficiently using the event dispatching and handling mechanism of the underlying GUI toolkit.

The roots of Grapefruit lie in systems like FranTk and wxFruit. Grapefruit tries to combine concepts of these systems with new ideas to become a system which maintains a reasonable balance between ease of use and efficiency, and is applicable to real world problems.

Status

As of Oktober 2007, Grapefruit is still in an early stage. Lots of basic concepts are implemented but Grapefruit still lacks a wide variety of widgets, for example. However, adding new widgets shouldn’t be too difficult since Grapefruit provides good generic support for doing this.

Furthermore, work on formal specification and verification of GUI properties based on Grapefruit’s GUI programming interface and dependent types has just started. The proof assistant Coq will be used in this context.

Source code

The source code of Grapefruit resides inside a darcs repository under http://softbase.org/grapefruit/darcs/main/. To get a copy, you can use the command darcs get http://softbase.org/grapefruit/darcs/main.

Building

You need at least GHC 6.8.1 and Gtk2Hs 0.9.12.1 to build and use Grapefruit. Currently, Grapefruit is tested with GHC 6.8.2 and Gtk2Hs 0.9.12.1.

To actually build Grapefruit, use Cabal. Grapefruit consists of the following packages:

  • grapefruit-frp
  • grapefruit-records
  • grapefruit-gui
  • grapefruit-graphics
  • grapefruit-examples

You should build these packages in this order by descending into the respective directories and issuing the appropriate Cabal commands there. If you don’t have any special requirements (like a non-default install path), you can use the following sequence of commands for each package:

runghc Setup.lhs configure
runghc Setup.lhs build
runghc Setup.lhs install

It might be that during building of grapefruit-example you will experience error messages like “Can't find interface-file declaration for type constructor or class Graphics.UI.Grapefruit.Adapters.Gtk2Hs.Widget.:CoF:R2Value” with some message lines before and after them. Please ignore them and try to run the executables nevertheless. I experienced no problems with this approach.

Documentation

There is also documentation generated by Haddock. This documentation comes in two flavors. The API documentation covers only the public interface while the complete documentation covers also the internals. Note that the documentation might be out of date since it is not automatically regenerated on every commit yet.

Grapefruit-related talks

Screenshots

Following are some screenshots from example programs using Grapefruit:

Simple
Clicking on the button adds a star to the caption of the button. This doesn’t look very meaningful. However, Simple is actually a very important example since it demonstrates that feedbacks work—the output of the button is transformed and then used as the button’s input.
Grapefruit-screenshot-Simple.png
Codebreaker
This is a Mastermind™-like game. The Add button is enabled if and only if the input field contains a valid code and the display box is enabled if and only if the list of guesses does not contain the code chosen by the computer. These properties are described in a declarative way in the source code.
Grapefruit-screenshot-Codebreaker.png
CircuitingObjects
This example demonstrates Grapefruit’s support for animations.
Grapefruit-screenshot-CircuitingObjects.png