[Haskell-cafe] wxHaskell: getting a checkbox state

Mark Carter mcturra2000 at yahoo.co.uk
Wed Sep 14 12:58:13 EDT 2005

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 ]
and in my where clause I do:
  onCbEdit textlog me = do
       checkedp <- get me checked
       appendText textlog "onCbEdit\n"
       appendText textlog (show checkedp)
Of course, I'll ultimately want it to do something much more interesting 
than that - but I was just scratching my head wondering how on earth it 
could be done; until you came along.

Hmm. interesting. I'm finding Haskell a bit head-scratching generally. 
The syntax is unfamiliar, and Monads, blimey. My understanding of them 
so far is that they form a barrier between the big, nastey, stateful 
world, and the clean functional world that I as a programmer occupy. 
Although I seem to be using a lot of do statements, which presumably 
means that I'm back in the world of imperative programming.

I program in VBA for a living now, but I have a lot of familiarity with 
Python, and I've done a fair amount of C in my time. I know a bit about 
C++, but have never gotten involved much with the GUI side of it. A few 
days ago, I installed an old version of Visual C++, and generated an MFC 
boilerplate app. My impression is that this MFC/C++ stuff is a confused 
mess. Admittedly I know very little about MFC; but I'm fairly confident 
that if a good programmer sat down to design a GUI system from scratch, 
he would not end up with something like MFC. There seems to be too many 
"bits" to it, and you have to scatter your declarations over too many 
files, with scaffolding everywhere. My application also needs to create 
GUI elements on the fly - and the MFC approach to doing this is woefully 

I'm currently hacking BouncingBalls.hs to be more to my liking (my balls 
don't bounce, for starters). The way it adds balls is straighforward. I 
find I need to hack code that already-exists because my understanding of 
the syntax and principles is very limited. I continue my Haskell 
experiments further ...

> Arthur
> PS: there is a mailinglist for wxhaskell-related questions:
> http://lists.sourceforge.net/lists/listinfo/wxhaskell-users

Seems quite dormant, though. Only 4 postings last month.

BTW, apologies Arthur Baars - I meant to email this response to the 
newsgroup, but ended up posting to him personally.

Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com

More information about the Haskell-Cafe mailing list