TRANSCODE Explorations into the Code Transcendental.

GUtopIa Revisited

GUtopIa Revisited

Recently I had to buckle down and create and honest to goodness desktop GUI application in Ruby. So once again, after some six years, I set down to weigh my options. It saddens me to say, after all these years, the state of desktop GUI programming with Ruby is still a rather sorry affair. Yes, there have been many improvements –thanks to the hard work of many a good programmer, but the task of creating a Ruby-based GUI application still remains a very non-Ruby-esque ordeal.

My first attempt at it this time was with Shoes. Shoes is a new and very nice GUI engine written largely from scratch by the well known WhyTheLuckyStiff. It’s a noble effort and some really neat programs can come from using Shoes. Unfortunately for my needs Shoes proved to be too buggy and immature –at times I saw visual artifacts and there are a very limited number of controls. And worst of all, the fact that it includes it’s own Ruby interpretor and manges it’s own gems caused it not to work well with some other libraries. For instance, I could not get it to use the latest version of Mechanize.

After examining other choices, such as creating one GUI script per major platform (too much work), or using the old standby FxRuby (never been happy with the lack of native look-and-feel), I decided to try a different course. I was well versed in web application design, so I tried my hand at rigging a web app to act like a desktop app via a locally running server using Ajax calls. The end result certainly looked good and basically worked. But there was a troubling lack of robustness in the interaction between the front-end and back-end. I had to poll the back-end to see what was going on, and the back-end had to spawn threads in order to provide a response to the browser while continuing to work on long-running processes. So it worked, but barely. I’m sure it could be improved, but for a devote POLSer like myself, that meant getting into mucky waters I really didn’t feel like I should need to be diving into anyway. Too bad. Web GUI design is quite advanced compared to Desktop GUI. Why no one has tried to map it directly to the desktop before is beyond me (but you can believe me when I tell you, I can’t wait to delve into Plam’s pre and it’s webOS development platform, which apparently does exactly this).

So where did this leave me? Well, I figured I had one last good shot with wxRuby. Ironically I had something to do with the birth of that project. It was those six years ago that I first looked into GUI frameworks for Ruby. Rich Kilmer was talking about his Utopia/Alpha ideas and I was just starting to feel comfortable with writing scripts in Ruby. I decided there needed to be something better, and working off of Rich’s idea’s for an API I came up the idea of GUtopIa, which would supply a font-end API that anyone could interface to a back-end GUI framework. Sort of a best of all worlds kind of design. A number of people were psyched about the idea, and joined with me to discuss and pursue the project. Unfortunately, I was still wet behind the ears, and the fellow programmers who first entertained working with me didn’t care much for my new-boy-brash style. They told me so, and decided on their own course, to create bindings for wxWidgets instead. I wasn’t happy about it personally. Having studied wxWidgets some, I knew it would be a long time before anything really useful was to come of that project –if at all. In hindsight, while I still believe GUtopIa is a good idea, I am glad it’s didn’t proceed back then –I still had a lot to learn about Ruby before I could do something like that as well as I would really like.

So it was time to check out what the wxRuby team had accomplished. My first handful, or so, attempts were miserable failures. WxRuby has some issues. It is tempermental, and so much like the C API I felt like I was actually programming in C. This is not how Ruby programming is supposed to be! I was having real trouble getting anything more then a basic frame and menu to work. Frustrated with the straight coding approach, I decided to see what WYSIWYG form builders were to be had. I knew wxWidgets touted these, so I looked around and found the precisely named wxFormBuilder. This made it fairly easy to design my complex form and best of all it made it clearer to me how wxWidget GUIs are built. Unfortunately the generated markup, called an XRC file, had issues of it’s own and wouldn’t load properly into Ruby. Once again, I was at a dead end.

Something really needed to be done about this state of affairs. And so I have decided to resurrect the GUtopIa project. I found my old code, looked at it, scrapped it, and started fresh. I’m going to proceed by specifying the front-end API as much as possible, before even considering back-end implementations. With any luck others will see what I’m doing and offer to build a an interface to their favorite framework. So far what I have looks very sweet. Just to wet your whistle, here’s a potential example.

    layout = GUtopIa::Layout.new do
      [ [ 'Name'  ], [ entry ] ]
      [ [ 'Phone' ], [ entry ] ]
      [ [ 'EMail' ], [ entry ] ]
    end
    layout.show

Yes, believe it or not, that’s a fairly complete GUI layout. In an upcoming post I’ll explain how it all works in more detail. But before I get into that, I still need a working desktop GUI application ASAP! I don’t have time to develop GUtopIa for this. So now I’ve tried again at coding wxRuby from hand, but this time using a very Ruby-esque lazy evaluation approach I had experimented with a long time ago in a Ruby Quiz on crossword puzzle drawing. Finally I got the results I wanted with out going cross-eyed looking at the code. Amazing how a well organized approach can make all the difference. I’ll demonstrate my design in my next blog post.


title : GUtopIa Revisited author : trans categories : [ruby, gui] date : 2010-03-20 layout : post