Use Ruby to create Win executable?

Hi,

I would like to post a general question about the convenience of using
Ruby to program a simple application consisting of an interface where
the user inputs some options and that interacts with another program’s
API to create some files.

I’ll be doing this in Windows, by the way. I have Cygwin too.

I was suggested using VBScript to create a HTA application, because it’s
easy to program and easy to run, but I wanted to give Ruby a chance
first. Java would be okay too but it take me much longer to learn.

So here are my questions (1 and 2 are the important ones):

  1. I think it’s entirely possible to create a GUI with Ruby (either with
    Ruby itself or with Shoes). Is this right? (I’m more familiar with
    writing Perl scripts that I execute on the command-line, I have no
    experience with writing GUI).

  2. I think it’s possible to convert the final program to a executable
    file that I can distribute to Windows users for them to run the program
    without the need to install Ruby first. Is this right? How should I do
    that? How well does it work?

  3. A subjective, optional question, for whoever feels like answering and
    thinks they’re not too biased. How do you think Ruby compares to
    VBScript in terms of both difficulty to learn from scratch and
    usefulness once you learnt? I only know some perl and php.

Sorry, I forgot to say goodbye and to thank you in advance for any
hints.

Cheers, Manuel

Hi Manuel,

Manuel Souto P. wrote:

  1. I think it’s entirely possible to create a GUI with Ruby (either with
    Ruby itself or with Shoes). Is this right? (I’m more familiar with
    writing Perl scripts that I execute on the command-line, I have no
    experience with writing GUI).

Ruby itself does not provide a GUI, but there are serveral different GUI
toolkits for Ruby out there, Shoes is only one of them. If you have the
Tk sources installed on your computer (I think you can get them from the
TCL/Tk website for Windows) you should be able to use the “tk” library
of Ruby’s standard library. You could also use FxRuby or wxRuby (my
favourite) or QtRuby, only to name a few. The most are available through
RubyGems (type gem --version on the command line to see if it was
installed with Ruby [ what is the regular case with Ruby 1.9.x ] )

Manuel Souto P. wrote:

  1. I think it’s possible to convert the final program to a executable
    file that I can distribute to Windows users for them to run the program
    without the need to install Ruby first. Is this right? How should I do
    that? How well does it work?
    For this goes the same as for 1. - there are serveral solutions to that.
    For long times rubyscript2exe.rb was the Windows executable generator
    (it wasn’t a compiler), but nowadays you should use the Gem ocra
    (One-Click Ruby Application Builder) which does also care about the Gems
    needed for your scripts and is currently maintained.

Marvin

  1. I think it’s entirely possible to create a GUI with Ruby (either with
    Ruby itself or with Shoes). Is this right? (I’m more familiar with
    writing Perl scripts that I execute on the command-line, I have no
    experience with writing GUI).

There are plenty of GUI bindings for ruby towards i.e. ruby-gtk, qt,
FOX, wxwidgets and so on. Ruby is pretty much in the same boat as perl
is here.

I think you might also invoke some basic window GUI components like an
alertbox and similar via ruby only. But I think a nice toolkit would be
a better choice in the long run.

Hi Marvin,

you should use the Gem ocra
(One-Click Ruby Application Builder) which does also care about the Gems
needed for your scripts and is currently maintained.

I want to focus on this part for now. I’ve tried to install and run ocra
with a simple ruby file, but something didn’t work. Let me open a new
post for that, and once I’ve sorted that out I’ll come back here and
comment more.

Thanks to the both of you for your replies!
Manuel

Marc H. wrote:

I think you might also invoke some basic window GUI components like an
alertbox and similar via ruby only.

Yes, on Windows you can use features like the MessageBox() function from
the Windows API. There are bindings to the Windows API in Ruby’s
standard library, but they have been deprecated in Ruby 1.9, so I would
recommend you to use a gem here, too. win32-api does a very good job:

require “rubygems” #if you’re running pre-1.9
require “win32/api”

#Values just out of my head, I have no Windows to try at the moment
#see MSDN (or Google :wink: ) for the correct values
MB_OKCANCEL = 1
MB_ICONERROR = 16
ID_OK = 1
ID_CANCEL = 2

#Retrieve function “MessageBox” from “user32.dll”
msgbox = Win32::API.new(“MessageBox”, ‘LPPI’, ‘I’, “user32”)
#This should display a dialog box with a white-on-red X and two
buttons
ret = msgbox.call(0, “An error occured. Do you want to continue?”,
“Error”, MB_ICONERROR | MB_OKCANCEL) #The 0 indicates there’s no parent
window
if ret == ID_OK
#Continue your operation…
elsif ret == ID_CANCEL
#Cancel your operation…
end

Marvin

Manuel Souto P. wrote:

I’ve tried to install and run ocra
with a simple ruby file, but something didn’t work. Let me open a new
post for that, and once I’ve sorted that out I’ll come back here and
comment more.

In case you think you can help, this is the related post:
http://www.ruby-forum.com/topic/193185#new

Thanks!
Manuel

Manuel Souto pico wrote:

easy to program and easy to run, but I wanted to give Ruby a chance
first. Java would be okay too but it take me much longer to learn.

Use JRuby + Monkeybars for effortless GUI building, then use Rawr to
create the exe file.

So here are my questions (1 and 2 are the important ones):

  1. I think it’s entirely possible to create a GUI with Ruby (either with
    Ruby itself or with Shoes). Is this right? (I’m more familiar with
    writing Perl scripts that I execute on the command-line, I have no
    experience with writing GUI).

For anything serious, look at using Swing + JRuby.

  1. I think it’s possible to convert the final program to a executable
    file that I can distribute to Windows users for them to run the program
    without the need to install Ruby first. Is this right? How should I do
    that? How well does it work?

Rawr bundles up everything needed to run the app. The end user just
needs to have Java (almost guaranteed).

  1. A subjective, optional question, for whoever feels like answering and
    thinks they’re not too biased. How do you think Ruby compares to
    VBScript in terms of both difficulty to learn from scratch and
    usefulness once you learnt? I only know some perl and php.

VBScript is OK for short hacks and scripting Office apps. Not for
anything substantial.


James B.

www.jamesbritt.com - Playing with Better Toys
www.ruby-doc.org - Ruby Help & Documentation
www.rubystuff.com - The Ruby Store for Ruby Stuff
www.neurogami.com - Smart application development

I was suggested using VBScript to create a HTA application, because it’s
easy to program and easy to run, but I wanted to give Ruby a chance
first. Java would be okay too but it take me much longer to learn.

Ruby would be more interesting too … :stuck_out_tongue_winking_eye:

  1. I think it’s entirely possible to create a GUI with Ruby (either with
    Ruby itself or with Shoes). Is this right? (I’m more familiar with
    writing Perl scripts that I execute on the command-line, I have no
    experience with writing GUI).

If you have no UI experience, Shoes is awesome. Simple and to the point.
All of the other Ruby native UI options do have a non-trivial learning
curve.

  1. I think it’s possible to convert the final program to a executable
    file that I can distribute to Windows users for them to run the program
    without the need to install Ruby first. Is this right? How should I do
    that? How well does it work?

The options are limited - via JRuby you cab use Rawr to achieve this.
There
is
also the RubyScript2exe option, but I am not sure how maintained this
is.

Also, shoes itself provides a windows (and Mac) packaging solution that
works as you describe (downloading necessary binaries on demand).

  1. A subjective, optional question, for whoever feels like answering and
    thinks they’re not too biased. How do you think Ruby compares to
    VBScript in terms of both difficulty to learn from scratch and
    usefulness once you learnt? I only know some perl and php.

You are not going to get much subjectivity here from me … :stuck_out_tongue_winking_eye:

Ruby is simply far more versatile than the other options (PHP, VBScript,
can’t comment on perl). You learn it for shell scripting purposes,
testing,
building software etc. and then
somehow your knowledge is applicable in entirely different domains.

Its a much more interesting leaning experience. The initial learning
curve
is not steep,
but it is a huge curve, and you are productive at a very early part of
it.

regards,
Richard

Hello,

Due to limited time (it had to be done by tomorrow, when I go on
holidays) I’m developing the first part of the program as a web
application with PHP and Javascript (with which I’m more familiar), and
that’ll do the trick for now. Later on, I want to keep exploring Ruby
and if possible migrate and expand this application.

I’m very interested in Ruby and I am very happy with the response from
other users like you in this forum. I just wanted to say that and thank
you for your help so far. Hopefully I’ll get to something when I come
back from my holidays in a few days. So don’t think that I asked and
then disappeared :wink:

Cheers, and happy August.

Manuel

On Aug 12, 3:44 pm, Manuel Souto P. [email protected] wrote:

you for your help so far. Hopefully I’ll get to something when I come
back from my holidays in a few days. So don’t think that I asked and
then disappeared :wink:

Cheers, and happy August.

Manuel


Posted viahttp://www.ruby-forum.com/.

Even if I were in a big hurry, I’d give Titanium a look, too.
http://www.appcelerator.com/products/titanium-desktop/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs