Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 So... VB is the easiest way to create a GUI?
Index -> Programming, Ruby -> Ruby Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Thu Aug 10, 2006 6:04 pm   Post subject: So... VB is the easiest way to create a GUI?

I say...

Bollocks! Smile

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.

Image

Then we need to create and modify the properties of a window slightly.

Image

We'll now need to connect the main_window's delete_event signal. This signal is sent when the window's close button is clicked.

Image

Then lastly we'll add a label to our window.

Image

And then we save to a file called "hello_world.glade".

We're now ready to write our Ruby file to make it all come to life.

code:
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. Smile

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:

code:
<b><span foreground="blue" size="24">Hello, world!</span></b>


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.
Sponsor
Sponsor
Sponsor
sponsor
Aziz




PostPosted: Tue Aug 07, 2007 10:55 am   Post subject: 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




PostPosted: Tue Aug 07, 2007 3:18 pm   Post subject: 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 Wink
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Aziz




PostPosted: Tue Aug 07, 2007 3:28 pm   Post subject: 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




PostPosted: Fri Jun 12, 2009 3:50 pm   Post subject: RE:So... VB is the easiest way to create a GUI?

A new Gui creator is around: 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




PostPosted: Fri Jun 12, 2009 4:00 pm   Post subject: 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.
Display posts from previous:   
   Index -> Programming, Ruby -> Ruby Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: