Ruby in FlightGear gets a GUI!
October 22, 2008
Boring old black and white text scrolling down a screen isn’t very attractive, right? (Refer to my previous post). So with this on my conscience I set out to give my ruby program, which gets data from FlightGear, a nice pretty interface… well sort of pretty.
So… here it is!
Now when dealing with constant processing of input or output data and in my case it is data being received, as well as a graphical user interface you are asking ruby to do two things at once. In the general scheme of things it is not what simple old ruby does, all it knows is to run through a series of instructions and then either loop back over those instructions or terminate, that being said with exceptions. So let me now introduce threads.
Ruby threads, without going into to much detail, allow multiple processes to run parallel to each other. So I needed ruby to not only be managing the GUI but also receiving and processing I/O data and thus the use of threads.
Setting up a thread is quite simple:
And you can find more information about them in the ruby core libraries documentation, see here.
Like the rest of my programs featuring GUI’s I have a soft spot for FXRuby, and I really don’t know why but I think it is mainly because it works, strangely enough. To allow me to update each piece of information (speed, altitude, etc.) I used FXRuby’s Data Targets which I setup to be updated from within the threaded receiving process.
All in all it is a pretty straight forward program but there are still plenty of loose ends needing to be tied up before I can call it a completely finished. It doesn’t even fulfill its intended purpose yet so there is plenty more to do.
If anyone is interested in the complete ruby code post a comment (with your email address) or send me an email and I will forward it on to you.
Stay tuned for more!


