[Haskell-cafe] wxHaskell: getting a checkbox state

Sebastian Sylvan sebastian.sylvan at gmail.com
Thu Sep 15 18:12:50 EDT 2005


On 9/14/05, Mark Carter <mcturra2000 at yahoo.co.uk> wrote:
> Arthur Baars wrote:
> 
> > Hi,
> >
> > A "Checkbox" is instance of the class Checkable:
> > http://wxhaskell.sourceforge.net/doc/
> > Graphics.UI.WX.Classes.html#t%3ACheckable
> >
> > This means you can "get" and "set" the "checked" property for
> > checkboxes.
> > for example:
> >  c <- get cbEdit checked
> >  set cbEdit [checked := not c ]
> >
> > The following code makes the checkbox print its state every time it
> > is  checked or unchecked:
> >        cbEdit <- checkBox f [text := "Edit Mode" ]
> >        set cbEdit [ on command :=  do v <- get cbEdit checked
> >                                       print v
> >                   ]
> 
> 
> AHA! Yes, very useful.
> 
> The problem I was having before was that I was trying to create a
> separate function onCbEdit, thus:
>    cbEdit <- checkBox p1 [text := "Edit Mode", on command :=  onCbEdit
> textlog   ]
> This had the problem that onCbEdit basically needed to have its control
> passed in (i.e. cbEdit) as a parameter in order to inspect its state. So
> I wanted to do something like:
>    cbEdit <- checkBox p1 [text := "Edit Mode", on command :=  onCbEdit
> textlog   cbEdit ]
> Except you can't do that, because  cbEdit isn't yet defined. But your
> suggestion gets 'round that. In the main loop, I now do:
>   cbEdit <- checkBox p1 [text := "Edit Mode" ]
>   set cbEdit [ on command :=  onCbEdit textlog  cbEdit ]

Some extension (I think) to GHC allows mdo-notation (recursive do). So
you can do this:
mdo -- yadayada....
       cbEdit <- checBox p1 [text := "Edit Mode", on comand :=
onCbEdit textlog cbEdit]
       -- yadayada...

/S

-- 
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862


More information about the Haskell-Cafe mailing list