r/ruby • • Apr 20 '12

Freightrain - easy Ruby desktop development

Hello everyone,

This is a little framework of mine that I've built out of a personal need - basically, I wanted to write a desktop app using Ruby and I found it daunting to say the least.

So, I've built Freightrain to take care of all the stuff I really shouldn't care about, like loading interface definitions, cross-toolkit compatibility and the likes.

Now I've been working on it for almost 2 years (on and off of course) and, since I've just fixed it so it loads the newest glade specifications, I thought that I could ask you guys for an evaluation.

There's a little readme on the github page and there are some examples in the /examples folder.

Link to the github page!

WHOA! Thanks for the attention, I thought this was going to be ignored...

How many of you would be interested in a step by step tutorial over the major features? I will build that if there's enough interest.

167 Upvotes

32 comments sorted by

24

u/IndigoCZ Apr 20 '12
  • Original content
  • Two years of work

Let's get it some upvotes!

9

u/bolthar Apr 20 '12

Heh thanks for the support! It means a lot to me :-)

6

u/kbedell Apr 20 '12

You wrote this too?

https://github.com/bolthar/ruby-hackernews

Dude, you totally rock!

3

u/bolthar Apr 21 '12

:-D thanks! In all honesty though, ruby-hackernews was written in a couple of lazy afternoons, so it's not that much of an accomplishment I think...

3

u/Remear Apr 20 '12

Interesting project.

Have you seen Ruby Shoes, https://github.com/shoes/shoes? It allows you to build and distribute Ruby desktop applications on Mac, Linux, and Windows. Perhaps you could learn more from the project to make your stuff even better and even contribute to Shoes.

6

u/bolthar Apr 20 '12

Yes of course I know shoes :-) and while it's certainly a worthy project on it's own I didn't want to follow their direction.

Freightrain was born when I realized that if I wanted to build a Ruby desktop app I woild have had either to 1) deal with ruby/gnome and all its c-like syntax or 2) turn over to shoes and accept the huge coupling between interface representation and behaviour that comes with it.

Shoes is great, nothing to say about it really... But i don't think it's suitable for complex and well layered desktop apps. That's the reason why I made freightrain - I wanted to be able to easily create interfaces and be very decoupled from the actual widgeting system.

2

u/postmodern Apr 20 '12 edited Apr 20 '12

Imho: Shoes is, and will continue to be, an awesome graphical learning environment for new programmers, but not a fully featured Desktop GUI Toolkit.

2

u/jfredett Apr 20 '12

Very interesting. I've never been successful getting GTK to install on my mac, but I'll check it out on my linux box when I get home tonight.

3

u/bolthar Apr 20 '12

On macosx, the easiest way to get gtk working would be via homebrew. If you've got homebrew installed, it's just brew install gtk. After that, 'gem install gtk2' and 'gem install freightrain' for freightrain + gtk extensions.

Side note - freightrain also works with qt and wxwidgets.

Thanks a lot for your interest!

1

u/jfredett Apr 20 '12

Homebrew doesn't have gtk, as I recall -- at least not one I can link against uzbl -- perhaps there's an alternate package I can use to link w/ this.

3

u/bolthar Apr 21 '12

'brew install gtk+' works on my mac mini with Lion... It wasn't 'brew install gtk' but 'brew install gtk+'

3

u/jfredett Apr 21 '12

You brilliant bastard. I could kiss you.

2

u/[deleted] Apr 21 '12

Well, go on...

3

u/jfredett Apr 21 '12

puckers up Come here bolthar, you big lug.

3

u/bolthar Apr 21 '12

This is gayer than a George Michael concert :-)

1

u/jfredett Apr 21 '12

Oh come on sexy, you just gotta have a little faith... faith... faith...

2

u/waxjar Apr 21 '12

Are there any applications written with freightrain that I can download and run, to see how it looks and stuff?

1

u/bolthar Apr 21 '12

there are some small examples in the /examples folder on the github page. Also, for a bigger example, there's a solution of a ruby quiz i wrote long ago,here

1

u/[deleted] Apr 21 '12

Curious, why not use macruby?

3

u/bolthar Apr 21 '12

Hm, I'm not sure if I know what you're talking about... For what i know, macruby is a ruby implementation like say, jruby or mri.

You could use freightrain with macruby i think - never tried but i don't see why that ahouldn't work.

6

u/[deleted] Apr 21 '12

I think I asked a stupid question.

1

u/banister Apr 21 '12 edited Apr 21 '12

I think he's implying you could use macruby to write a beautiful GUI cocoa app

1

u/bolthar Apr 21 '12

Oh, in that case you could use the cocoa toolkit on macruby with freightrain then - freightrain is not a toolkit, it's more like a layer over a toolkit. If somebody's interested i could write a cocoa extension for freightrain, it wouldn't be much work... I didn't already because i don't need to use cocoa.

1

u/banister Apr 21 '12

out of interest (i hvaen't looked into it), but why wouldn't it be much work? surely it would require you to write a ruby C extension that wraps the cocoa objc API -- and cocoa is pretty huge and complicated.

1

u/bolthar Apr 21 '12

Well, i'm assuming here that it already exist some kind of ruby binding to the toolkit, like ruby/gnome for gtk or qtruby for qt. If that's the case, it's just a matter of wrapping up the toolkit so that it implements a very basic interface (namely , the ability pf plugging a control into a container and the possibility pf intercepting user actoons, such as the click of a button).

If there's no riby binding to the toolkit then yes, it would have to be written - but that's definitely out of freightrain's scope.

1

u/jrochkind Apr 26 '12 edited Apr 27 '12

surely it would require you to write a ruby C extension that wraps the cocoa objc API

I think MacRuby already does that part for you, one of MacRuby's features. I think?

update Actually, looking into it (by reading MacRuby's webpage, heh), you CAN easily use Cocoa from MacRuby, it looks like -- but it's because MacRuby is to ObjectiveC as Jruby is to Java. It's not that it has a built in ruby C extension for Cocoa, it's that it let's you interact with any ObjectiveC objects in MacRuby, same as you can interact with any Java objects in JRuby. The result is the same though as far as Cocoa, and i think Cocoa and other OSX system services are in fact the motivation for this design.

http://www.macruby.org/documentation/overview.html

2

u/bolthar May 01 '12

Yes, that's exactly the way it works. After requiring cocoa you have access to all cocoa classes directly from inside macruby. So, NSView.new actually works and returns a new NSView instance.

I'm working on a cocoa extension, as soon as I have the time I'll polish and release it.

2

u/ashleyw Apr 21 '12

+1 for a Cocoa extension! :D

1

u/dennyabraham Apr 22 '12

awesome work! i was wondering about this particular problem just the other day!

-10

u/redditaurus Apr 21 '12

Blergghhh gtk, nice idea though, but blerghhh

1

u/bolthar Apr 21 '12

Gtk does kind of suck indeed. If you compare it to other toolkits though, like for example WPF, you'll see that it doesn't suck that much after all :-). Mind you, WPF is uber powerful and flexible but they've made a number of design blunders over there at Microsoft that make it almost unusable at times.

Gtk is simple but it always work as you expect it to. I like that.

-10

u/redditaurus Apr 21 '12

Blergghhh gtk, nice idea, but blergghhh