Skip to content

Instantly share code, notes, and snippets.

@HeinrichApfelmus
Created October 11, 2011 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HeinrichApfelmus/1278515 to your computer and use it in GitHub Desktop.
Save HeinrichApfelmus/1278515 to your computer and use it in GitHub Desktop.
wxHaskell - Minimal example demonstrating "concurrent" event occurrences
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 ]
@HeinrichApfelmus
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment