|
From: Mads L. <mad...@ya...> - 2008-12-07 19:27:23
|
Hi
It was great to see XRC being added to wxHaskell. Nonetheless, it seems
to have less type safety than the "traditional" way of creating widgets.
There seems to be two static guaranties we are now missing:
1) The naming of widgets is by strings which can be misspelled.
2) One can accidentally use a wrong *res function for accessing the
widget. E.g. using radioBoxRes for a button.
Fortunately, it could easily be remedied by parsing the xrc.xml file and
generating the necessary functions.
Would people think this is a good idea? Would you use it?
I have made a _very_ rudimentary proof of concept:
module Main where
import Text.HTML.TagSoup
import Text.HTML.TagSoup.Parser
import Data.Char
main = do
makeSelectorModule "controls.xrc"
makeSelectorModule :: String -> IO ()
makeSelectorModule filename = do
xml <- readFile filename
let out = outputModule filename
writeFile (out ++ ".hs") (header out ++ makeSelectors xml)
outputModule :: String -> String
outputModule filename =
toUpper (head filename) : takeWhile (/= '.') (drop 1 filename) ++ "Selector"
makeSelectors :: String -> String
makeSelectors xs = unlines $ map makeSelector $ concat $ map process $ parseTags xs
process (TagOpen "object" [("class", t), ("name", name)]) = [Widget t name]
process _ = []
data Widget = Widget String String
deriving Show
header name = "module " ++ name ++ " where\n" ++
"import Graphics.UI.WX\n"
makeSelector :: Widget -> String
makeSelector (Widget "wxButton" name) = name ++ "Button f = buttonRes f \"" ++ name ++ "\""
makeSelector _ = ""
Which for the "controls.xrc" file in the sample directory generates a
file named "ControlsSelector.hs" containing:
module ControlsSelector where
import Graphics.UI.WX
okButton f = buttonRes f "ok"
quitButton f = buttonRes f "quit"
rb1Button f = buttonRes f "rb1"
cb1Button f = buttonRes f "cb1"
If people are interested, I would gladly volunteer to turn the proof of
concept into "real" code.
Greetings
Mads Lindstrøm
|
|
From: Gour <go...@go...> - 2010-01-27 19:05:28
Attachments:
signature.asc
|
On Sun, 07 Dec 2008 20:11:19 +0100 >>>>>> "Mads" == Mads Lindstrøm wrote: Hi Mads, Mads> It was great to see XRC being added to wxHaskell. Nonetheless, it Mads> seems to have less type safety than the "traditional" way of Mads> creating widgets. XRC seems to becoming topic in wxhaskell again... Mads> There seems to be two static guaranties we are Mads> now missing: Mads> Mads> 1) The naming of widgets is by strings which can be misspelled. Mads> Mads> 2) One can accidentally use a wrong *res function for accessing Mads> the widget. E.g. using radioBoxRes for a button. Does gtk2hs using Glade suffer from the same problem? Mads> Fortunately, it could easily be remedied by parsing the xrc.xml Mads> file and generating the necessary functions. That would be great, even more to get haskell code generation from XRC support in some GUI builder. Mads> Would people think this is a good idea? Would you use it? I'd definitely using it considering it's advantage to use GUI builder to generate XRC. Mads> If people are interested, I would gladly volunteer to turn the Mads> proof of concept into "real" code. Has anything happened in regard so far (I excuse myself for questioning being quite new with wxhaskell.)? Sincerely, Gour -- Gour | Hlapicina, Croatia | GPG key: F96FF5F6 ---------------------------------------------------------------- |
|
From: Mads L. <mad...@ya...> - 2010-01-27 20:17:22
|
Hi Gour On Wed, 2010-01-27 at 19:42 +0100, Gour wrote: > On Sun, 07 Dec 2008 20:11:19 +0100 > >>>>>> "Mads" == Mads Lindstrøm wrote: > > Hi Mads, > > Mads> It was great to see XRC being added to wxHaskell. Nonetheless, it > Mads> seems to have less type safety than the "traditional" way of > Mads> creating widgets. > > XRC seems to becoming topic in wxhaskell again... > > Mads> There seems to be two static guaranties we are > Mads> now missing: > Mads> > Mads> 1) The naming of widgets is by strings which can be misspelled. > Mads> > Mads> 2) One can accidentally use a wrong *res function for accessing > Mads> the widget. E.g. using radioBoxRes for a button. > > Does gtk2hs using Glade suffer from the same problem? I do not know much about gtk2hs, but from this http://www.haskell.org/gtk2hs/docs/tutorial/glade/ it seems like the surfer from the same two problems. > > Mads> Fortunately, it could easily be remedied by parsing the xrc.xml > Mads> file and generating the necessary functions. > > That would be great, even more to get haskell code generation from XRC > support in some GUI builder. > > Mads> Would people think this is a good idea? Would you use it? > > I'd definitely using it considering it's advantage to use GUI builder > to generate XRC. > > Mads> If people are interested, I would gladly volunteer to turn the > Mads> proof of concept into "real" code. > > Has anything happened in regard so far (I excuse myself for > questioning being quite new with wxhaskell.)? Nothing has happened so far, but I will take the prototype further. I do not expect it to be much work, so hopefully something will be ready soon. I have no plans to build a non-toy XRC based GUI myself, so an early early adapter, could be very helpful in keeping this little project focused. You might be interested in being an early adapter? > > > Sincerely, > Gour /Mads |
|
From: Gour <go...@go...> - 2010-01-28 07:35:43
Attachments:
signature.asc
|
On Wed, 27 Jan 2010 20:51:12 +0100 >>>>>> "Mads" == Mads Lindstrøm wrote: Mads> I do not know much about gtk2hs, but from this Mads> http://www.haskell.org/gtk2hs/docs/tutorial/glade/ it seems like Mads> the surfer from the same two problems. Heh, we're in the same boat then. Mads> Nothing has happened so far, but I will take the prototype Mads> further. I do not expect it to be much work, so hopefully Mads> something will be ready soon. I have no plans to build a non-toy Mads> XRC based GUI myself, so an early early adapter, could be very Mads> helpful in keeping this little project focused. Hmm, interesting. You're thinking about the complete XRC GUI designer or just something to load XRC and generate wxhaskell? Mads> You might be interested in being an early adapter? In a few days we're going to vacation (on Sunday) and won't be available till the end of February and then I'm ready to help, but bear in mind I'm only wx(haskell) noob although ready to learn desiring to write desktop app. Sincerely, Gour -- Gour | Hlapicina, Croatia | GPG key: F96FF5F6 ---------------------------------------------------------------- |
|
From: Mads L. <mad...@ya...> - 2010-01-28 16:39:17
|
Hi On Thu, 2010-01-28 at 08:36 +0100, Gour wrote: > Hmm, interesting. You're thinking about the complete XRC GUI designer > or just something to load XRC and generate wxhaskell? Just something to load XRC files in a type safe manner. Are there something wrong with the GUI designer tools already made like Glade? > > Mads> You might be interested in being an early adapter? > > In a few days we're going to vacation (on Sunday) and won't be > available till the end of February and then I'm ready to help, but > bear in mind I'm only wx(haskell) noob although ready to learn > desiring to write desktop app. > OK /Mads |
|
From: Gour <go...@go...> - 2010-01-28 17:55:26
Attachments:
signature.asc
|
On Thu, 28 Jan 2010 17:39:43 +0100 >>>>>> "Mads" == Mads Lindstrøm wrote: Mads> Just something to load XRC files in a type safe manner. Are there Mads> something wrong with the GUI designer tools already made like Mads> Glade? Nope. Nothing wrong. They do the GUI job nicely. I'm happy thinking about the prospect of having some wxhaskell code generated after having nicely designed XRC. Sincerely, Gour -- Gour | Hlapicina, Croatia | GPG key: F96FF5F6 ---------------------------------------------------------------- |