From: Robert D. <rob...@fa...> - 2006-02-23 15:16:43
|
On Feb 23, 2006, at 6:33 AM, Anatoly Zaretsky wrote: > 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. How would one go about adding them? I'm not familiar with the how WxEiffel and the WxHaskell build system works. Is there a particular reason they aren't exposed already? > But if you need some custom events > you can use the following hack (trick, technique...): I'm not sure I fully understand, so let me paraphrase and see if I've got this right: 'makeEvent' takes an object which can handle events and returns a pair where -- the first element triggers an event by via the menu event handler on the passed in object -- the second element lets you set the event handler If you want to pass additional data beyond the simple occurance of the event, you need external concurrency primitives. > import Control.Concurrent.Chan > import Graphics.UI.WX > import Graphics.UI.WXCore > > makeEvent :: EvtHandler a -> IO (IO (), IO () -> IO ()) > makeEvent target = > do > id <- idCreate > evt <- commandEventCreate wxEVT_COMMAND_MENU_SELECTED id > let sender = evtHandlerAddPendingEvent target evt > binder = evtHandlerOnMenuCommand target id > return (sender, binder) > > gui = do > f <- frame [text := "Some frame"] > > let newFrameEvent = 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. Ahh. That's unfortunate. I'll have to think on this. Thank you for your reply! Rob Dockins Speak softly and drive a Sherman tank. Laugh hard; it's a long way to the bank. -- TMBG |