
-----------------------------------
wtd
Thu Aug 10, 2006 6:04 pm

So... VB is the easiest way to create a GUI?
-----------------------------------
I say...

Bollocks!  :)

Considering the forum in which this dwells, I don't think it'll be too surprising when I suggest that my choice would be Ruby.

And for the GUI side of things, we'll use GTK+.  It's free, works well on multiple platforms, and has bindings for a great many languages, so the skills you develop using it will be applicable outside of just Ruby.

We'll also be using a fantastic tool called Glade.  Glade allows GUIs to be created visually, and then saved in an XML file.  We can load that file into our program, and then we just have to deal with signals.

Hello, world!

First we open up Glade.

require 'gtk2'
require 'libglade2'

class MyApp
   def initialize(glade_file_name)
      GladeXML.new(glade_file_name) { |handler| method(handler) }
   end

   def on_main_window_delete_event(widget, *args)
      Gtk.main_quit
   end
end

Gtk.init
MyApp.new("hello_world.glade")
Gtk.main

That's it.  When a MyApp object is created, the glade file is read.  It takes the name of each signal handler, and connects it to the method by the same name.  Thus we need only define methods with those names that take a widget and a variable number of arguments.  

We then need only initialize the run-time, create a new MyApp object, and run the main loop.

It's as simple as that

Really, it is.  :)

Knock it up a notch!  Bam!

But that's bland.  So, without making it actually do too much more, let's go back into Glade and make some changes.

First we'll add a border to the window.  Let's make it 5 pixels.  You'll have to go to the widget tree, cloick on "main_window", then in the properties window increment the "Border Width" property.  This will prevent our label from being squished up against the edges of the window.

Next we'll make some changes to that text label as well.

Select "hello_world_label" in the widget tree, and then in properties change "Use Markup" to "Yes."  The Label field then becomes:

Hello, world!

Then all we have to do is save the Glade file and rerun the app.  The text label will now appear larger, bold, and blue.

-----------------------------------
Aziz
Tue Aug 07, 2007 10:55 am

RE:So... VB is the easiest way to create a GUI?
-----------------------------------
Incredibly easy. But if you're talking easiest, I would still say Visual Studio is easier than these few steps you've posted. Better, maybe not so.

At least for this simple GUI. I don't know very much about Ruby and Glade, so it's not fair for me to say a more complicated application would be more or less easier.

Though, easier than my experience with GUIs in C++....

-----------------------------------
Tony
Tue Aug 07, 2007 3:18 pm

RE:So... VB is the easiest way to create a GUI?
-----------------------------------
I make all my GUI with XHTML (and sometimes JavaScript) in a web browser ;)

-----------------------------------
Aziz
Tue Aug 07, 2007 3:28 pm

RE:So... VB is the easiest way to create a GUI?
-----------------------------------
Huh?

Personally, I prefer to create my GUI with code. That way, you have control over everything. And if you need to alter something, you know it's not going to mess up the editor...

Not the easiest to set up, but perhaps easier to maintain. Only done it in Java though, not with .NET or other APIS

-----------------------------------
apomb
Fri Jun 12, 2009 3:50 pm

RE:So... VB is the easiest way to create a GUI?
-----------------------------------
A new Gui creator is around: [url=www.shoooes.net] Shoes  is a wonderfully easy, entertaining way of making gui applications that look fantastic. (the entire frontend of shoes itself is written using shoes's framework. )

-----------------------------------
Aziz
Fri Jun 12, 2009 4:00 pm

RE:So... VB is the easiest way to create a GUI?
-----------------------------------
One must really wonder how for you can push such a simple looking library.
