Return to Snippet

Revision: 16158
at July 27, 2009 18:50 by keigoi


Initial Code
import EnableGUI -- from http://wxhaskell.sourceforge.net/download/EnableGUI.hs

import Graphics.UI.WXCore hiding (Var)
import Graphics.UI.WX hiding (Var, enter)
import Data.Bits ((.&.), complement)

myEventId = wxID_HIGHEST+1 -- the custom event ID
-- the custom event is registered as a menu event
createMyEvent = commandEventCreate wxEVT_COMMAND_MENU_SELECTED myEventId
registerMyEvent win io = evtHandlerOnMenuCommand win myEventId io

gui
  = do f <- frame [text := "custom event sample"]
       bt <- button f [text := "click to invoke a custom event"]
       set f [layout := column 1 [hfill (widget bt)]]
       set bt [on command := onClick f]
       registerMyEvent f (putStrLn "The custom event is fired!!")
       return ()
  where
      onClick f
        = do
          ev <- createMyEvent
          evtHandlerProcessEvent f ev
          return ()


main = enableGUI >> start gui

Initial URL

                                

Initial Description
This examples shows how to handle user-defined events in wxHaskell via menu events.

If the thread issues an event is not the main thread, use evtHandlerAddPendingEvent instead of evtHandlerProcessEvent.

Initial Title
wxHaskell multi-thread & custom event example

Initial Tags

                                

Initial Language
Haskell