From: Daan L. <da...@cs...> - 2005-05-11 08:06:25
|
Hi James, James Mitchell wrote: > In order to better learn Haskell, I've set myself a > project that happens to include GUI work (I figure if > I can't have a GUI w/ Haskell, then it's back to C++), Great! > so I downloaded wxHaskell, read the example, and coded > up a little window with a "File" menu. That worked > out ok, so I added code to correctly enable & disable > menu attributes, such a disabling "Close" when there's > no opened file. This also worked ok, but has left me > with an organizational challenge. I have a bundle of > lines like this: > > mNew <- menuItem mFile [text := "&New"] > > ... which isn't a big deal, but then when I want to > code the actual event handlers, I end up with these > huge parameter lists, with each of the items in > question an individual variable. If this were C or > C++, I'd have each of these guys as a property of a > structure or class, and then just pass around the > structure as a whole. What's the "right" way to do > this with wxHaskell? This is one of the main troubles with wxHaskell: the library doesn't offer a standard abstraction mechanism and all state is passed explicitly. However, there are some ways to make this less painful. I think that the Dazzle application uses a big state record. Something like: data State = State { mNew :: MenuItem () , ... , mainWindow :: Window () , ... } Each event handler gets the state passed. By using a record, we can easily change the State while keeping all the code that doesn't rely on the change the same. Now, you can write a function "updateMenus :: State -> IO ()" that just updates all the menus by looking at the "State" -- this also guarantees that everything is done in one place. (Actually, I just read wxWidgets has an "wxUpdateUIEvent" especially to allow this kind of programming in C++ too where all the menu disabling/enabling is in one spot -- I'll add this event to the next release of wxHaskell). I believe that Arjan van IJzendoorn has released a utility library "PersistentDocument" that manages file open/close stuff for document oriented applications. I couldn't find it on the web but maybe you can send him an email and I am sure he tells you his tricks. I hope this helps, -- Daan. > > thanks in advance, > > James > > > > |-----------------------------------------------| > | James Mitchell | http://www.jimdesu.us | > |-----------------------------------------------| > |When the shoe fits, the foot is forgotten; when| > |the belt fits, the belly is forgotten; when the| > |heart is right, "for" and "against" are | > |forgotten. -- Chuang Tzu | > |-----------------------------------------------| > > > > __________________________________ > Yahoo! Mail Mobile > Take Yahoo! Mail with you! Check email on your mobile phone. > http://mobile.yahoo.com/learn/mail > > > ------------------------------------------------------- > This SF.Net email is sponsored by Oracle Space Sweepstakes > Want to be the first software developer in space? > Enter now for the Oracle Space Sweepstakes! > http://ads.osdn.com/?ad_id=7393&alloc_id=16281&op=click > _______________________________________________ > wxhaskell-users mailing list > wxh...@li... > https://lists.sourceforge.net/lists/listinfo/wxhaskell-users |