reactive-banana-wx (empty) → 0.1.0.0
raw patch · 6 files changed
+157/−0 lines, 6 filesdep +basedep +reactive-bananadep +wxsetup-changed
Dependencies added: base, reactive-banana, wx, wxcore
Files
- LICENSE +30/−0
- Makefile +14/−0
- Setup.hs +2/−0
- reactive-banana-wx.cabal +36/−0
- src/Counter.hs +33/−0
- src/Reactive/WX.hs +42/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2011, Heinrich Apfelmus++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Heinrich Apfelmus nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Makefile view
@@ -0,0 +1,14 @@+.PHONY: all clean++OBJ=dist/build+COMPILE=ghc --make -outputdir $(OBJ) -i$(OBJ) -L$(OBJ) -isrc++Counter : src/Counter.hs src/Reactive/WX.hs+ $(COMPILE) -o $@ $<+ macosx-app $@ +++all: Counter++clean:+ rm -rf $(APPS) obj/*.o obj/*.hi *.app *.exe *.manifest
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ reactive-banana-wx.cabal view
@@ -0,0 +1,36 @@+Name: reactive-banana-wx+Version: 0.1.0.0+Synopsis: Examples for the reactive-banana library, using wxHaskell.+Description:+ This library provides some examples for the @reactive-banana@ library,+ using wxHaskell.++Homepage: https://github.com/HeinrichApfelmus/Haskell-BlackBoard+License: BSD3+License-file: LICENSE+Author: Heinrich Apfelmus+Maintainer: Heinrich Apfelmus <apfelmus quantentunnel de>+Category: FRP, GUI++Build-type: Simple++Extra-source-files: Makefile++-- Constraint on the version of Cabal needed to build this package.+Cabal-version: >=1.6+++Library+ hs-source-dirs: src+ build-depends: base==4.2.*, reactive-banana==0.1.*,+ wx==0.12.*, wxcore==0.12.*+ extensions: ExistentialQuantification+ exposed-modules: Reactive.WX++Executable Counter+ hs-source-dirs: src+ main-is: Counter.hs+ build-depends: base==4.2.*, reactive-banana==0.1.*,+ wx==0.12.*, wxcore==0.12.*+ extensions: ExistentialQuantification+
+ src/Counter.hs view
@@ -0,0 +1,33 @@+{-----------------------------------------------------------------------------+ reactive-banan-wx+ + Example: Counter+------------------------------------------------------------------------------}+module Counter where++import Reactive+import Reactive.WX+import Graphics.UI.WX hiding (Event)++{-----------------------------------------------------------------------------+ Main+------------------------------------------------------------------------------}+main = start $ do+ f <- frame [text := "Counter"]+ bup <- button f [text := "Up"]+ bdown <- button f [text := "Down"]+ output <- staticText f []+ + set f [layout := margin 10 $+ column 5 [widget bup, widget bdown, widget output]]+ + let+ eup, edown :: Event ()+ eup = event0 bup command+ edown = event0 bdown command+ + counter :: Behavior Int+ counter = accumulate ($) 0 $+ ((+1) <$ eup) `union` (subtract 1 <$ edown)+ + sink output [text :== (show <$> counter)]
+ src/Reactive/WX.hs view
@@ -0,0 +1,42 @@+{-# LANGUAGE ExistentialQuantification #-}+{-----------------------------------------------------------------------------+ reactive-banan-wx+ + Utility functions for interfacing with wxHaskell+------------------------------------------------------------------------------}++module Reactive.WX where++import Reactive.Core+import qualified Graphics.UI.WX as WX++{-----------------------------------------------------------------------------+ Wx+ + Utilities for representing stuff from Wx as events and behaviors+------------------------------------------------------------------------------}++-- | Event with exactly one parameter.+event1 :: w -> WX.Event w (a -> IO ()) -> Event a+event1 widget e = fromEventSource $ EventSource+ { getEventHandler = WX.get widget (WX.on e)+ , setEventHandler = \h -> WX.set widget [WX.on e WX.:= h] }++-- | Event without parameters.+event0 :: w -> WX.Event w (IO ()) -> Event ()+event0 widget e = fromEventSource $ EventSource+ { getEventHandler = (\m -> \() -> m) `fmap` WX.get widget (WX.on e)+ , setEventHandler = \h -> WX.set widget [WX.on e WX.:= h ()] }++data Prop' w = forall a. (WX.Attr w a) :== Behavior a++-- | "Animate" a property with a behavior+sink :: w -> [Prop' w] -> Prepare ()+sink widget props = mapM_ sink1 props+ where+ sink1 (attr :== b) = do+ WX.set widget [attr WX.:= initial b]+ reactimate $ (\a -> WX.set widget [attr WX.:= a]) `fmap` changes b+++