packages feed

reactive-banana-wx 0.1.0.2 → 0.2.0.1

raw patch · 5 files changed

+58/−59 lines, 5 filesdep ~reactive-banana

Dependency ranges changed: reactive-banana

Files

Makefile view
@@ -1,9 +1,9 @@ .PHONY: all clean  OBJ=dist/build-COMPILE=ghc --make -outputdir $(OBJ) -i$(OBJ) -L$(OBJ) -isrc+COMPILE=ghc --make -outputdir $(OBJ) -i$(OBJ) -L$(OBJ) -isrc -i../reactive-banana/src -Counter : src/Counter.hs src/Reactive/WX.hs+Counter : src/Counter.hs src/Reactive/Banana/WX.hs 	$(COMPILE) -o $@ $< 	macosx-app $@	 
reactive-banana-wx.cabal view
@@ -1,5 +1,5 @@ Name:                reactive-banana-wx-Version:             0.1.0.2+Version:             0.2.0.1 Synopsis:            Examples for the reactive-banana library, using wxHaskell. Description:     This library provides some examples for the @reactive-banana@ library,@@ -22,15 +22,15 @@  Library     hs-source-dirs:  src-    build-depends:   base >= 4.2 && < 4.4, reactive-banana==0.1.*,+    build-depends:   base >= 4.2 && < 4.4, reactive-banana==0.2.*,                      wx==0.12.*, wxcore==0.12.*     extensions:      ExistentialQuantification-    exposed-modules: Reactive.WX+    exposed-modules: Reactive.Banana.WX  Executable Counter     hs-source-dirs:  src     main-is:         Counter.hs-    build-depends:   base >= 4.2 && < 4.4, reactive-banana==0.1.*,+    build-depends:   base >= 4.2 && < 4.4, reactive-banana==0.2.*,                      wx==0.12.*, wxcore==0.12.*     extensions:      ExistentialQuantification 
src/Counter.hs view
@@ -5,8 +5,8 @@ ------------------------------------------------------------------------------} module Main where -import Reactive-import Reactive.WX+import Reactive.Banana+import Reactive.Banana.WX import Graphics.UI.WX hiding (Event)  {-----------------------------------------------------------------------------@@ -17,17 +17,16 @@     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+    prepareEvents $ do+        eup   <- event0 bup   command+        edown <- event0 bdown command         -        counter :: Behavior Int-        counter = accumulate ($) 0 $-            ((+1) <$ eup) `union` (subtract 1 <$ edown)+        let+            counter :: Event Int+            counter = accumE 0 $ ((+1) <$ eup) `union` (subtract 1 <$ edown)     -    sink output [text :== (show <$> counter)]+        sink output [text :== ("0", show <$> counter)]
+ src/Reactive/Banana/WX.hs view
@@ -0,0 +1,42 @@+{-# LANGUAGE ExistentialQuantification #-}+{-----------------------------------------------------------------------------+    reactive-banana-wx+    +    Utility functions for interfacing with wxHaskell+------------------------------------------------------------------------------}++module Reactive.Banana.WX where++import Reactive.Banana+import qualified Graphics.UI.WX as WX++{-----------------------------------------------------------------------------+    Wx+    +    Utilities for representing stuff from Wx as events and behaviors+------------------------------------------------------------------------------}++-- | Event with exactly one parameter.+event1 :: Typeable a => w -> WX.Event w (a -> IO ()) -> Prepare (Event a)+event1 widget e = fromAddHandler addHandler+    where+    addHandler k = WX.set widget [WX.on e WX.:~ \h x -> h x >> k x]++-- | Event without parameters.+event0 :: w -> WX.Event w (IO ()) -> Prepare (Event ())+event0 widget e = fromAddHandler addHandler+   where+   addHandler k = WX.set widget [WX.on e WX.:~ \h -> h >> k ()]++data Prop' w = forall a. (WX.Attr w a) :== (a, Event a)++-- | "Animate" a property with a stream of events+sink :: w -> [Prop' w] -> Prepare ()+sink widget props = mapM_ sink1 props+    where+    sink1 (attr :== (x,ex)) = do+        liftIO $ WX.set widget [attr  WX.:= x]+        reactimate $ (\x -> WX.set widget [attr WX.:= x]) <$> ex+++
− src/Reactive/WX.hs
@@ -1,42 +0,0 @@-{-# 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---