Created
October 11, 2011 16:04
-
-
Save HeinrichApfelmus/1278515 to your computer and use it in GitHub Desktop.
wxHaskell - Minimal example demonstrating "concurrent" event occurrences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Graphics.UI.WX | |
main = start $ do | |
-- create widgets | |
f <- frame [ text := "Example" ] | |
b <- button f [ text := "Test" ] | |
e <- entry f [ text := "1" ] | |
status <- staticText f [ size := sz 40 20 ] | |
-- populate initial values | |
set f [ layout := margin 10 $ | |
column 10 [ widget e, widget status, widget b]] | |
set status [ text := "Ready." ] | |
focusOn e | |
invariant <- variable [ value := True ] | |
let | |
onButtonClick = do | |
-- disable the text field when the button is clicked | |
set invariant [ value := False ] | |
set e [ text := "Button clicked", enabled := False ] | |
set invariant [ value := True ] | |
onLoseFocus = do | |
-- print the invariant when the text fields loses focus | |
b <- get invariant value | |
set status [ text := "Invariant " ++ if b then "good." else "broken!" ] | |
set e [ on focus := \b -> if b then return () else onLoseFocus ] | |
set b [ on command := onButtonClick ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Discussion: http://apfelmus.nfshost.com/blog/2011/10/11-frp-concurrent-events.html