Tuesday, March 30, 2010

FXRuby 'FRAME' type examples

I created a good working UI using foxGUIb 1.0.0 for an app that I've wanted to create for a while now.  The problem I have with the source code generated is that it's hard to customise.  When something doesn't look quite right, I'm competing with several layers for clarity and what I see in the generated source code doesn't match what I see built with the tool.

I gave up trying to make it work for me and decided to just start from scratch with plain FXRuby.  I'm using the foxGUIb layout as my 'spec' or template to build the app using simpler code.  The problem now, of course, is that I don't know FXRuby and am learning it as I go.  Google is my friend, coupled with the many examples available from the FXRuby docs.

While working with FXGroupBox, I was trying to figure out what the different frameStyle types did. e.g. FRAME_GROOVE, FRAME_LINE,  FRAME_RAISED, FRAME_RIDGE,  FRAME_SUNKEN, FRAME_THICK, and FRAME_NORMAL

Google turned up this example from the "FXRuby: Create Lean and Mean GUIs with Ruby" book.  I love online examples! =)

Can you find the error in the code?

Tuesday, March 2, 2010

Enabling checkboxes in FXRuby

While playing around with FXRuby, I tried to create a form window where you could have an "Include All?" check box at the top that automatically enables/disables all the other options (check boxes) below.

This turned out to be non-obvious to code for a non-programmer like me. None of the FXRuby examples include code that does something like this. Google didn't help and neither did the FXRuby book. (Although in all fairness, I only skimmed through the book and didn't read the whole thing.)

I posted a request for some help to the FXRuby forum and a kind soul wrote up an example to do just that. Rather than include the sample code in an email, he posted it online at: http://pastebin.com/rPKJLC9r

I'd never heard of Pastebin.com until now. Seems like a cool place to drop random chunks of code that you can have others look over and help you get working. I posted the link here so I can remember where to find it next time.

Oh, and the FXRuby code example was perfect. Just what I needed. The sample code was an over-simplified version of what I needed to do but it was enough to help me understand the relationship between the objects and commands.

Wednesday, February 24, 2010

Creating UI's with Ruby

I began with Ruby years ago by writing scripts to help me test a web app. I used WATIR for that. I will likely write more about Watir another time.

It took me a while to figure out how to write and structure the scripts using whatever examples I found online. It wasn't until I read Brian Marick's "Everyday Scripting with Ruby" that I really understood how to structure a ruby program. Excellent book by the way - I highly recommend it!

Over the years I accumulated quite the army of command-line programs/scripts and one thing I've wanted to do was figure out how to put a pretty UI/front-end on some of these scripts.

Apparently with Ruby, you have a few different options - TK, FXRuby, Shoes, etc.

I decided to settle on FXRuby since it's the only one that happens to be supported out-of-the-box with a clean Ruby install. (Watch, I bet they'll remove it from a future distribution/release now that I've said that.)

FXRuby is kind of neat. The main home page has some good documentation and examples to help get you started.

I was able to easily create some simple apps, but then it gets kind of tough. Working with FXRuby reminds me of the time I took a course in Japanese, some 20 years ago. Nice language. I picked up the alphabets, sentence structure and syntaxes and some of the vocabulary. I got the basics but just couldn't piece together big sentences/conversations. It just got too complicated for me. I suppose if I'd gone to Japan or had more opportunity to practice that it would have gotten easier, but I didn't and it didn't.

FXRuby's like that. Looks simple on the surface, but make no mistake, you need to know how to program to piece together a working app! The examples are helpful, but what I want to do is somehow always a bit more complicated than the available examples. Sigh. If only it were easier to pull together a UI for such a friendly programming language.

I discovered foxGUIb a few days ago. That tool really helped me figure out the relationships between the various layout styles and elements to bring together a UI. Unfortunately, I don't think I can use the code it generated, so I now have a pretty prototype with no working code underneath.

Oh well. Here's hoping that with practice it will get easier to do this sort of thing. I've browsed all of the available GUI toolkits and they're all the same to me. They start off with easy, Ruby'ishly-simple examples that try to hook you - then "WHAM!", insert programming jargon, hooks, classes and structures and "voila! there you go." Easy as 1, 2, googolplex.

Ruby I like. All of the available toolkits to help you build UI's still seem very programmerish to me. Not cool.

5 Chapters of O’Reilly’s Ruby Best Practices – Free!

Came across a tweet today:
zeljkofilipin 5 Chapters of O’Reilly’s #Ruby Best Practices – Free! http://bit.ly/aFhTcE

Of course, I followed the link and discovered the RubyInside web site... and that yes, O'Reilly has made the first 5 chapters of 'Ruby Best Practices' available in PDF form online for free.

I browsed them. Boring. Way to suck the life and passion out of a fun and cool programming language.

I've collected a bunch of Ruby ebooks in PDF and CHM (Windows help file) format in my travels over the last few years. I haven't read a single one of them. Or rather, the benefit (for me) is in helping me do a quick electronic search through the text to see if there's something that will help me with whatever current programming problem I'm working on.

I have a few books (sorry environmentalists, but I still prefer paper) that I use for reference and have a few that I still plan to read, but in general I've learnt programming by doing it. Which is to say that I don't really know how to program so much as do creative and well-documented hacking. ;)

I've got more to learn, but only as much as I need to learn to complete whatever projects I'm working on. I'm not a programmer by trade so I will defer to the experts when I need to get some real work done. God bless online forums! =)

Cheers!

Wednesday, August 19, 2009

Rubular

ooooo... came across this just now by accident. Really cool!

Rubular - a Ruby regular expression editor.

This is the first Ruby-centric regex checker that I've found. Handy reference.

Thursday, August 13, 2009

Ugh!

Google is a blessing and a disappointment at the same time sometimes. I got distracted looking for a routine today to solve a particular question I had. I was looking for a simple (?) mathematical algorithm. I found many pages on the Math - they were okay, but only helpful to a point. And then I found some pages with sample Ruby code on them - great!

Until I actually tried the code. And read the code. And then gagged myself with a spoon and completely rewrote the code. I ended up with less than half of the total lines of code that I originally found on the 'net. (BTW, I still don't know what the other half of the code was trying to do. Really.)

Why is it that almost all of the Ruby code samples out there (that I have come across) are written by non-Ruby programmers? Their code is junk. I'm sorry but anyone who takes Java, Perl or C code (or whatever) and thinks they can do some simple translation to Ruby is sadly mistaken.

It took me about 15 minutes of staring at a For-Next loop to discover that I could rewrite it with a .each do loop. I was confused by the For-Next -- I hadn't seen one of those since the early 90's. It was just really surreal code, you know? Here I was looking at non-Ruby code that worked in Ruby. Weird.

Did it solve my problem? Kinda sorta. Rewriting the code into something intelligible gave me enough insight to write the remaining code I needed to answer my question.

I debated whether or not to include some examples here (of the shoddy Ruby code) but I don't think I want to give any attention to some of the many poor programmers out there. They clearly don't deserve any more mention than Google has already provided. I'll think about posting some of my examples here when I get some free time though ... for balance.

Note to the Ruby posers out there: Just stop. Please. You're embarrassing yourselves. It ain't a bandwagon. If you don't get it, please stay away from the programming language translators. Ruby ain't like the other languages - it puts humans first, not the machine. Talk in human terms, not computer jargon. Ugh.

I would have preferred to have gotten no (Google) hits and just posted the question to one of the helpful Ruby forums instead.

Sunday, July 19, 2009

Handy Ruby Quick Reference

Found this on the web last night:

http://www.zenspider.com/Languages/Ruby/QuickRef.html

Very handy in a pinch.