From: Leslie Viljoen Date: 2008-06-09T00:25:27+09:00 Subject: Re: Desktop multi-plataform ruby app On Sun, Jun 8, 2008 at 4:19 PM, Victor Reyes wrote: > On Sun, Jun 8, 2008 at 8:20 AM, Michael T. Richter > wrote: > >> On Sat, 2008-06-07 at 05:57 +0900, James Britt wrote: >> >> If you have questions, jump on #monkeybars on irc; the Monkeybars squad is usually about and very happy to answer questions. >> >> >> Which network? Freenode? The #monkeybars channel there has no topic and >> one person idling in it. :) >> >> -- >> *Michael T. Richter* (*GoogleTalk:* >> ttmrichter@gmail.com) >> *Never, ever, ever let systems-level engineers do human interaction design >> unless they have displayed a proven secondary talent in that area. Their >> opinion of what represents good human-computer interaction tends to be a bit >> off-track. (Bruce Tognazzini)* >> > Team, > > *Tristin*: I already tried the suggestion of FxRuby plus other GUIs. The > documentation for FxRuby was so so. I am the type that learn by example. > *Hassan*: I'll give it a try without un-installing "regular" Ruby. > *Tom*: I am also terrified of the Java T-Rex. So many packages, so many ways > to configure it, so many ..... > I went to > http://www.netbeans.org/community/releases/61/install.html#requiredsoftwareand > found the soft requirements. I proceeded to Sun site and downloaded a > ton of software: JDK, JRE, NetBeans, Etc. My installation went fine. The > problem is when I try something as simple as jruby -v (I do ruby -v for > regular ruby, so I assume the same is valid for jruby only with the prefix > j). I got the msg: > > Set JAV_HOME to point to your JDK/JRE directory. > I am using MS Windows XP and I set the variable. So now it works as long as > I am inside the *C:\jruby-1.1.2\bin* dir. I tried setting the PATH but > nothing. > *C:\jruby-1.1.2\bin>jruby -v > ruby 1.8.6 (2008-05-28 rev 6586) [x86-jruby1.1.2] > > *I set the PATH but nothing. Perhaps I am not setting the PATH correctly. So > this is my new show-stopper. I will continue playing until I either get it > or get tired. Although I am already getting tired. This is not supposed to > be this difficult. But dealing with Java nothing is ever simple. > *Leslie*: Does Glade provides a drag/drop widget creation feature? I went to > *glade.gnome.org* but could not find anything about it. Glade is a form builder, it allows you to drop containers onto forms and Gtk widgets into those containers. This is not the same as with Netbeans or Visual Studio, but you can get the same results and in some ways the system is better - it takes better care of how forms change when text is translated or fonts changed. You may find it has a learning curve in the beginning, but only until you understand how things work, after that it's quick and easy. I'm putting together a 5-minute tutorial but I'll include the text portion below to get you started. The tutorial uses the "glader" script which I'll include at the bottom. Warning: I haven't tried glader in Windows yet! Starting out with Glade and Ruby ------------------------------------------ Open glade. 1. Add a new window, common -> border width: 10 2. Add a vbox to the window (2 items), general -> spacing: 10 3. Add a hbox to the bottom area, general -> spacing: 10 4. Right-click hbox in tree, add parent, alignment 5. Put a button in each of the two bottom blocks 6. On the alignment container, horizonal scale: 0, vertical scale: 0, horizontal alignment: 1 7. On the alignment container, expand: no, fill: no If expand is no, the area does not take on more space when the parent grows. If expand is yes, the area will grow with its parent, and 'fill' controls how it grows. If 'fill' is yes, extra space is added around the widgets, otherwise the extra space goes inside the widget and the widget itself grows. 8. Add a table in the top space 9. table, packing -> expand: no, general -> row spacing: 10, column spacing: 10 Before saving, click on window1, signals -> gtkobject -> destroy and select "on_window1_destroy" from the combo. Now save as "designation" and run "./glader designation.glade" from the command line. After generation, run "ruby designation.rb" Note that when you resize, everything still looks good except the three labels, which shouldn't grow horizontally like that. Also, since you added the on_window1_destroy signal, you can close the window and your Ruby program will exit nicely (glader wrote a handler for that). Return to Glade. 1. label1, packing -> fill: deselect expand 2. Do the same for the other two labels 3. Save Now re-run designation.rb. You don't have to regenerate since the class and main file will not change, only the form definition (glade) file. If you resize you'll see that the labels now stay small and only the text fields and combo boxes grow, which is nice. ----------------------- glader.rb #!/usr/bin/ruby -w # This class is a quick way of creating a runnable Ruby program from # a single Glade form. # class Glader def initialize(glade_filename) raise ArgumentError.new("File missing: #{glade_filename}") if !File.exist?(glade_filename) raise ArgumentError.new("Not a .glade file: #{glade_filename}") if glade_filename !~ /.*\.glade/ @glade_filename = glade_filename @base_filename = File.basename(@glade_filename, ".glade") @class_filename = @base_filename + "_glade.rb" end # Runs the ruby-glade-create-template script to create a file with a # class that corresponds to the form. This can be called repeatedly # to keep creating the class every time the .glade file changes. # def make_class `/usr/bin/ruby-glade-create-template #{@glade_filename} > #{@class_filename}` @class_filename end # Creates a main program that uses the glade class created with # _make_class_ and opens the window with the form. It will do nothing # if the main program file already exists, since the user is likely # to add code to this file. # def make_main main_filename = @base_filename + '.rb' if(File.exist?(main_filename)) raise ArgumentError.new("#{main_filename} already exists, skipping") else File.open(main_filename, "w") {|f| f.write generate_main} end main_filename end private def generate_main() class_name = File.read(@class_filename).scan(/class (.*)/).to_s window_id = File.read(@glade_filename).scan(/class="\w+" id="(\w*)">$/).flatten[0] main =<" puts exit end glader = Glader.new(ARGV[0]) print "Making class file (#{glader.make_class})...\n" begin print "Making main file (#{glader.make_main})...\n" rescue => e puts e.message end puts end