From: Anatoly Z. <ana...@gm...> - 2006-02-23 11:34:02
|
On 2/20/06, Robert Dockins <rob...@fa...> wrote: > > > There don't appear to be constructors for these object types. > > > > For example, KeyEvent > > (http://wxhaskell.sourceforge.net/doc/ > > Graphics.UI.WXCore.WxcClassesAL.html#99) > > doesn't have the expected 'keyEventCreate' funciton and PaintEvent, > > which > > only has a constructor, doesn't appear in the function listings at > > all. > Hi! It's not very difficult to add them though the entire Haskell part of wxHaskell should be rebuilt then. But if you need some custom events you can use the following hack (trick, technique...): import Control.Concurrent.Chan import Graphics.UI.WX import Graphics.UI.WXCore makeEvent :: EvtHandler a -> IO (IO (), IO () -> IO ()) makeEvent target =3D do id <- idCreate evt <- commandEventCreate wxEVT_COMMAND_MENU_SELECTED id let sender =3D evtHandlerAddPendingEvent target evt binder =3D evtHandlerOnMenuCommand target id return (sender, binder) gui =3D do f <- frame [text :=3D "Some frame"] let newFrameEvent =3D makeEvent f (oneThreadReport, reactToOneThread) <- newFrameEvent (anotherOneReport, reactToAnotherThread) <- newFrameEvent reactToOneThread (putStrLn "OneThread sent event") dataChan <- newChan reactToAnotherThread $ do d <- readChan dataChan putStrLn ("Data from AnotherThread: " ++ show d) createOneThread oneThreadReport createAnotherOne anotherOneReport dataChan Performing those report actions threads can send events. My program worked properly only with threaded rts, possibly because addPendingEvent performs mutex locking. I am not sure about the exact reason, 'cause there was also some network I/O. -- Best regards, Tolik |