[Haskell-beginners] recursively retrieving widgets handlers in
wxhaskell
legajid
legajid at free.fr
Mon Apr 5 12:07:27 EDT 2010
Hi Stephen,
Thanks for your answer. I'll look at it carefully to insert it into my
project.
My question came from my project : manage a book library.
A main frame lists all the books in a listCtrl.
On this frame, an menu option allows selections on different criterias
(author, title, ...).
After validating selection, the listCtrl is loaded again, with the books
answering the selections.
The structure of my program is this one :
frame -> intial loading of data (no selections)
frame -> menu option -> selection frame then when validated
loading data (selections here
are updated in the sql query)
The loading function is called from two different functions.
I want the loading function to display the number of books selected in
the status bar.
To do this, the function "loading" must get the status field handler. So
the selection menu option too, to be able to give it to the "loading".
It's a bit boring since "selection" doesnt't need it at all, except to
pass it to another function.
Adding new functions will certainly add new parameters for their
specific needs.
My strange idea was : as i have to pass the main frame handler to my
functions, the loading function could explore the hierarchy to find the
status field, since i give it a specific value for "identity" attribute.
So, the only parameter, common to all functions, will be the main frame
handler.
Why do i pass the main frame handler ? Because my selection function
displays a modal dialog, that must refer to the "calling" frame.
I see a problem with this approach : no more reference to a field at
compilation time (just a handler with a value like 0x.......), so
possible error at run time.
A second issue is : status field in a statusbar has no identity
attribute, like other widgets have (text, buttons, ...). In this
specific case, my idea has no solution; i have to change the statusbar
into a simple label.
But, i want to keep the idea when i write an export function, so the
main frame displays a rolling counter as long as the books are written
in a csv file.
Has anyone already experimented this kind of project? Am i right to do
this? Is there another way ?
Thanks,
Didier
2. n
Stephen Tetley a écrit :
> Hi Didier
>
> I think I've simplified what you are saying to remove the dependency
> on wxHaskell. Recursing a widget hierarchy to all get a list of all
> widgets seems a bit strange, though demo1 does this.
>
> Generally I'd expect you would want to recursively process the widget
> hierarchy collecting some attribute of each widget - demo2 does this.
>
> I've put the recursive functions into the IO monad to model wxHaskell
> where widgets are in some monad.
>
> code follows...
>
>
> -- Model widgets as a simple binary tree - labels and interior
> -- nodes both have names.
>
More information about the Beginners
mailing list