Re: Creating Widgets While Inside the EventM Monad
Andy Stewart <lazycat.manatee <at> gmail.com>
2010-10-04 02:23:27 GMT
Hi Tom,
When you use EventM, you must end with 'IO ()', otherwise mismatch.
Whatever use Events or EventM, the return value of 'signal handler' is
for signal, and not use for return value *outside* signal handler.
I suggest you use IORef or TVar build [DialogWidget] or something,
example like :
dialogList <- newIORef []
window `on` keyPressEvent $ tryEvent $ do
[Control] <- eventModifier
"t" <- eventKeyName
-- When match "Ctrl + t", you can do any action for new dialog here.
liftIO $ do
dialog <- dialogNew
modifyIORef dialogList (\x -> dialog : x)
...
-- Action for new dialog ...
...
Cheers,
-- Andy
Tom Ostojich <tostojich <at> gmail.com> writes:
> Hello all,
>
> A recurring problem in my code is that I want to bind a key event to
> the creation of, say, a dialog window. Usually, binding the key event
> isn't that hard, since you can do the following:
>
> window `on` keyPressEvent $ tryEvent $ do
> [Control] <- eventModifier
> "r" <- eventKeyName
> liftIO $ ioFunction
>
> However, since the monad expects for the function to essentially
> return a type of (), it becomes very difficult to create a dialog
> window while you're in the EventM monad, since the following code
> would give a type error:
>
> window `on` keyPressEvent $ tryEvent $ do
> [Control] <- eventModifier
> "t" <- eventKeyName
> liftIO $ functionThatInstansiatesAWidget
>
> Reading up various pages on the Reader monad and available GTK
> documentation doesn't seem to handle these kinds of situations. Is
> there any way (preferably one that involves the least number of
> mutations) that I could use that will allow me to bind a key event to
> the creation of a dialog window (or any widget for that matter)?
>
> Thanks in advance,
>
> Tom Ostojich
>
> ------------------------------------------------------------------------------
> Virtualization is moving to the mainstream and overtaking non-virtualized
> environment for deploying applications. Does it make network security
> easier or more difficult to achieve? Read this whitepaper to separate the
> two and get a better understanding.
> http://p.sf.net/sfu/hp-phase2-d2d
------------------------------------------------------------------------------
Virtualization is moving to the mainstream and overtaking non-virtualized
environment for deploying applications. Does it make network security
easier or more difficult to achieve? Read this whitepaper to separate the
two and get a better understanding.
http://p.sf.net/sfu/hp-phase2-d2d