From: James M. <ji...@ya...> - 2005-05-11 05:33:52
|
Hi y'all, 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++), 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? 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 |
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 |
From: shelarcy <she...@ca...> - 2005-05-11 11:53:15
|
On Wed, 11 May 2005 10:06:13 +0200, Daan Leijen <da...@cs...> wrote: > 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. "PersistentDocument" is found by mailing-list log, here. http://www.haskell.org/pipermail/haskell/2004-December/015078.html But this first version function is very primitive sample. If use this library, need to customise redo and undo function for application. > (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). Daan, When next release comes, after current two week work, or you come back this project? If after come back this project, I hope you commit on current work to CVS. Because I want to use your current work - SOEgraphics on wxHaskell - on my project. I already bind FFmpeg function to play AVI file on wxHaskell. And I want to support save AVI from SOEGraphics Animation (yes, I also want to combine Pan (PanTheon?) and Fran, if it is possible). Drug&Drop is important for UI, but SOEGraphics are more important now. so I wait this work done instead mail for question. -- shelarcy <shelarcy capella.freemail.ne.jp> http://page.freett.com/shelarcy/ |
From: Arjan v. I. <af...@cs...> - 2005-05-11 12:51:28
|
Hi James, > That worked > out ok, so I added code to correctly enable & disable > menu attributes, such a disabling "Close" when there's > no opened file. > [...] As Daan pointed out, I have written a library for exactly these kind of application. It handles graying out of menu items, undo & redo, title bar updating etcetera. Enclosed you can find the library (2 files) and a small demo that uses it. It solves the problem of the many parameters by putting everything in a big record. Hope this helps, Arjan |