Skip to content

Commit

Permalink
Merge remote branch 'origin/develop'
Browse files Browse the repository at this point in the history
Conflicts:
	reactive-banana-wx/Setup.hs
	reactive-banana-wx/reactive-banana-wx.cabal
	reactive-banana-wx/src/Animation.hs
	reactive-banana-wx/src/Reactive/Banana/WX.hs
	reactive-banana/src/Reactive/Banana/Combinators.hs
	reactive-banana/src/Reactive/Banana/Frameworks.hs
  • Loading branch information
HeinrichApfelmus committed Aug 26, 2012
2 parents 07f3e9b + 08a6578 commit 094300a
Show file tree
Hide file tree
Showing 42 changed files with 2,031 additions and 1,361 deletions.
3 changes: 3 additions & 0 deletions reactive-banana-wx/Makefile
Expand Up @@ -24,6 +24,9 @@ Asteroids : src/Asteroids.hs src/Reactive/Banana/WX.hs
$(COMPILE) -o $@ $< -outputdir $(OBJ)/$@.tmp/ && macosx-app $@ \
&& cp data/* $@.app/Contents/Resources

BarTab : src/BarTab.hs src/Reactive/Banana/WX.hs
$(COMPILE) -o $@ $< -outputdir $(OBJ)/$@.tmp/ && macosx-app $@

Counter : src/Counter.hs src/Reactive/Banana/WX.hs
$(COMPILE) -o $@ $< -outputdir $(OBJ)/$@.tmp/ && macosx-app $@

Expand Down
2 changes: 1 addition & 1 deletion reactive-banana-wx/Setup.hs
Expand Up @@ -15,7 +15,7 @@ guiApps =
[mkApp filesAsteroids "Asteroids", mkApp filesAnimation "Animation"] ++ apps

apps = map (mkApp []) $
words "Arithmetic Counter CurrencyConverter CRUD"
words "Arithmetic BarTab Counter CurrencyConverter CRUD"
++ words "NetMonitor TicTacToe TwoCounters Wave"
filesAsteroids = map ("data/" ++) $
words "burning.ico rock.ico ship.ico explode.wav"
Expand Down
96 changes: 27 additions & 69 deletions reactive-banana-wx/reactive-banana-wx.cabal
@@ -1,5 +1,5 @@
Name: reactive-banana-wx
Version: 0.6.0.1
Version: 0.7.0.0
Synopsis: Examples for the reactive-banana library, using wxHaskell.
Description:
This library provides some GUI examples for the @reactive-banana@ library,
Expand All @@ -13,10 +13,6 @@ Description:
.
@cabal install reactive-banana-wx -fbuildExamples@
.
IMPORTANT NOTE:
There are a few issues with WxWidgets 2.9.3 and some examples may crash.
These problems are only solved in wx-0.90.0.1 and higher.
.
Stability forecast: The wrapper functions are rather provisional.

Homepage: http://haskell.org/haskellwiki/Reactive-banana
Expand All @@ -32,7 +28,7 @@ Build-type: Custom
Extra-source-files: Makefile

data-dir: data
data-files: *.ico, *.wav, *.png
data-files: *.ico, *.wav

flag buildExamples
description: Build example executables
Expand All @@ -42,9 +38,8 @@ Library
hs-source-dirs: src
build-depends: base >= 4.2 && < 5,
cabal-macosx >= 0.1 && < 0.3,
reactive-banana >= 0.6.0.0 && < 0.7,
wxcore (>= 0.13.2.1 && < 0.90) || (>= 0.90.0.1 && < 0.91),
wx (>= 0.13.2.1 && < 0.90) || (>= 0.90.0.1 && < 0.91)
reactive-banana >= 0.7.0.0 && < 0.8,
wx >= 0.90 && < 0.91, wxcore >= 0.90 && < 0.91
extensions: ExistentialQuantification
exposed-modules: Reactive.Banana.WX

Expand All @@ -55,17 +50,8 @@ Source-repository head

Executable Animation
if flag(buildExamples)
build-depends:
process >= 1.0 && < 1.2,
random == 1.0.*,
executable-path == 0.0.*,
filepath >= 1.1 && <= 1.4,
reactive-banana,
wx,
wxcore,
base
cpp-options: -DbuildExamples

cpp-options: -DbuildExamples
build-depends: reactive-banana, wx, wxcore, base
else
buildable: False
hs-source-dirs: src
Expand All @@ -74,12 +60,7 @@ Executable Animation

Executable Arithmetic
if flag(buildExamples)
build-depends:
process >= 1.0 && < 1.2,
reactive-banana,
wx,
wxcore,
base
build-depends: reactive-banana, wx, wxcore, base
else
buildable: False
hs-source-dirs: src
Expand All @@ -91,50 +72,43 @@ Executable Asteroids
random == 1.0.*,
executable-path == 0.0.*,
filepath >= 1.1 && <= 1.4,
reactive-banana,
wx,
wxcore,
base
reactive-banana, wx, wxcore, base
cpp-options: -DbuildExamples
else
buildable: False
hs-source-dirs: src
other-modules: Paths_reactive_banana_wx, Paths
main-is: Asteroids.hs

Executable BarTab
if flag(buildExamples)
build-depends: reactive-banana, wx, wxcore, base
else
buildable: False
hs-source-dirs: src
main-is: BarTab.hs

Executable Counter
if flag(buildExamples)
build-depends:
reactive-banana,
wx,
wxcore,
base
build-depends: reactive-banana, wx, wxcore, base
else
buildable: False
hs-source-dirs: src
main-is: Counter.hs

Executable CurrencyConverter
if flag(buildExamples)
build-depends:
process >= 1.0.1 && < 1.2,
reactive-banana,
wx,
wxcore,
base
build-depends: process >= 1.0.1 && < 1.2,
reactive-banana, wx, wxcore, base
else
buildable: False
hs-source-dirs: src
main-is: CurrencyConverter.hs

Executable CRUD
if flag(buildExamples)
build-depends:
containers >= 0.3 && < 0.6,
reactive-banana,
wx,
wxcore,
base
build-depends: containers >= 0.3 && < 0.5,
reactive-banana, wx, wxcore, base
else
buildable: False
hs-source-dirs: src
Expand All @@ -143,49 +117,33 @@ Executable CRUD

Executable NetMonitor
if flag(buildExamples)
build-depends:
process >= 1.0 && < 1.2,
reactive-banana,
wx,
wxcore,
base
build-depends: process >= 1.0 && < 1.2,
reactive-banana, wx, wxcore, base
else
buildable: False
hs-source-dirs: src
main-is: NetMonitor.hs

Executable TicTacToe
if flag(buildExamples)
build-depends:
array >= 0.3 && < 0.5,
reactive-banana,
wx,
wxcore,
base
build-depends: array >= 0.3 && < 0.5,
reactive-banana, wx, wxcore, base
else
buildable: False
hs-source-dirs: src
main-is: TicTacToe.hs

Executable TwoCounters
if flag(buildExamples)
build-depends:
reactive-banana,
wx,
wxcore,
base
build-depends: reactive-banana, wx, wxcore, base
else
buildable: False
hs-source-dirs: src
main-is: TwoCounters.hs

Executable Wave
if flag(buildExamples)
build-depends:
reactive-banana,
wx,
wxcore,
base
build-depends: reactive-banana, wx, wxcore, base
else
buildable: False
hs-source-dirs: src
Expand Down
4 changes: 2 additions & 2 deletions reactive-banana-wx/src/Animation.hs
Expand Up @@ -3,7 +3,7 @@
Example: A simple animation.
------------------------------------------------------------------------------}
{-# LANGUAGE ScopedTypeVariables #-} -- allows "forall t. NetworkDescription t"
{-# LANGUAGE ScopedTypeVariables #-} -- allows "forall t. Moment t"

import Graphics.UI.WX hiding (Event, Vector)
import Reactive.Banana
Expand Down Expand Up @@ -43,7 +43,7 @@ main = start $ do
set ff [ layout := minsize (sz width height) $ widget pp ]

-- event network
let networkDescription :: forall t. NetworkDescription t ()
let networkDescription :: forall t. Frameworks t => Moment t ()
networkDescription = do
etick <- event0 t command -- frame timer
emouse <- event1 pp mouse -- mouse events
Expand Down
4 changes: 2 additions & 2 deletions reactive-banana-wx/src/Arithmetic.hs
Expand Up @@ -3,7 +3,7 @@
Example: Very simple arithmetic
------------------------------------------------------------------------------}
{-# LANGUAGE ScopedTypeVariables #-} -- allows "forall t. NetworkDescription t"
{-# LANGUAGE ScopedTypeVariables #-} -- allows "forall t. Moment t"

import Data.Maybe

Expand All @@ -24,7 +24,7 @@ main = start $ do
[widget input1, label "+", widget input2
, label "=", minsize (sz 40 20) $ widget output]]

let networkDescription :: forall t. NetworkDescription t ()
let networkDescription :: forall t. Frameworks t => Moment t ()
networkDescription = do

binput1 <- behaviorText input1 ""
Expand Down
4 changes: 2 additions & 2 deletions reactive-banana-wx/src/Asteroids.hs
Expand Up @@ -11,7 +11,7 @@
https://github.com/killerswan/wxAsteroids/issues/1
http://comments.gmane.org/gmane.comp.lang.haskell.wxhaskell.general/1086
------------------------------------------------------------------------------}
{-# LANGUAGE ScopedTypeVariables #-} -- allows "forall t. NetworkDescription t"
{-# LANGUAGE ScopedTypeVariables #-} -- allows "forall t. Moment t"

import Graphics.UI.WX hiding (Event)
import Graphics.UI.WXCore as WXCore
Expand Down Expand Up @@ -81,7 +81,7 @@ asteroids = do
]

-- event network
let networkDescription :: forall t. NetworkDescription t ()
let networkDescription :: forall t. Frameworks t => Moment t ()
networkDescription = do
-- timer
etick <- event0 t command
Expand Down
89 changes: 89 additions & 0 deletions reactive-banana-wx/src/BarTab.hs
@@ -0,0 +1,89 @@
{-----------------------------------------------------------------------------
reactive-banana-wx
Example: Bar tab with a variable number of widgets
------------------------------------------------------------------------------}
{-# LANGUAGE ScopedTypeVariables #-} -- allows "forall t. Moment t"
{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}

import Data.Maybe (listToMaybe)

import Graphics.UI.WX hiding (Event)
import Reactive.Banana
import Reactive.Banana.WX

import Data.Traversable (sequenceA)

{-----------------------------------------------------------------------------
Main
------------------------------------------------------------------------------}
main = start $ do
f <- frame [text := "Bar Tab"]
msg <- staticText f [ text := "Sum:" ]
total <- staticText f []
add <- button f [text := "Add"]
remove <- button f [text := "Remove"]

let networkDescription :: forall t. Frameworks t => Moment t ()
networkDescription = do
eAdd <- event0 add command
eRemove <- event0 remove command

let
newEntry :: Frameworks s
=> Moment s (TextCtrl (), AnyMoment Behavior String)
newEntry = do
wentry <- liftIONow $ entry f []
bentry <- trimB =<< behaviorText wentry ""
return (wentry, bentry)

eNewEntry <- execute $ (FrameworksMoment newEntry <$ eAdd)

let
eDoRemove = whenE (not . null <$> bEntries) eRemove

eEntries :: Event t [(TextCtrl (), AnyMoment Behavior String)]
eEntries = accumE [] $
((\x -> (++ [x])) <$> eNewEntry) `union` (init <$ eDoRemove)

bEntries = stepper [] eEntries

reactimate $ ((\w -> set w [ visible := False]) . fst . last)
<$> bEntries <@ eDoRemove

let
ePrices :: Event t [AnyMoment Behavior Number]
ePrices = map (fmap readNumber . snd) <$> eEntries

bLayout :: Behavior t Layout
bLayout = mkLayout . map fst <$> bEntries

mkLayout entries = margin 10 $ column 10 $
[row 10 [widget add, widget remove]] ++ map widget entries
++ [row 10 $ [widget msg, minsize (sz 40 20) $ widget total]]

bTotal :: Behavior t Number
bTotal = switchB (pure Nothing) $
(fmap sum . sequenceA) <$> ePrices

sink total [text :== showNumber <$> bTotal]
sink f [layout :== bLayout]

network <- compile networkDescription
actuate network

{-----------------------------------------------------------------------------
Utilities
------------------------------------------------------------------------------}
type Number = Maybe Double

instance Num Number where
(+) = liftA2 (+)
(-) = liftA2 (-)
(*) = liftA2 (*)
abs = fmap abs
signum = fmap signum
fromInteger = pure . fromInteger

readNumber s = listToMaybe [x | (x,"") <- reads s]
showNumber = maybe "--" show

0 comments on commit 094300a

Please sign in to comment.