saush

Singapore.rb meeting presentation slides and source code

Posted in Ruby by sausheong on April 20, 2007

I’m pretty glad to say that the Singapore.rb event went rather well today. The crowd was quite respectable, I think, maybe around 20+ people in all were there, old and new. Meeting up with people from just curious to looking around for programmers were quite heartening, from the days when it was just Choon Keat and I pinging each other on my blog and then over email.

Anyway for the participants of the even today, here are my slides in PDF.

FxRuby and Screensvr slides

And here are the source code:

This is a the sample code in Ruby/Tk.

require 'tk'

root = TkRoot.new
button = TkButton.new(root) {
    text "Click me"
    command proc { puts "Hello world!" }
}
button.pack
Tk.mainloop

This is the sample code in wxRuby.

require 'wx'
include Wx

class FxApp < App
 def on_init
  frame = Frame.new nil, -1, "Wx2 Hello"
  panel = Panel.new frame, 1
  button = Button.new panel,  2, "Click me"
  button.evt_left_down() { | event | puts "Hello world!"  }
  frame.show
 end
end
FxApp.new.main_loop

This is the sample code in Ruby-GTK2.

require 'gtk2'
include Gtk

window = Window.new
window.signal_connect("destroy") { Gtk.main_quit }
button = Button.new "Click me"
button.signal_connect("clicked") {  puts "Hello world!" }

window.add button
window.show_all

Gtk.main

This is the sample code in FxRuby.

require 'fox16'
include Fox

app = FXApp.new

main = FXMainWindow.new app, "Fx Hello"
button = FXButton.new main, "Click me!"
button.connect(SEL_COMMAND) {  puts "Hello world!" }
app.create

main.show PLACEMENT_SCREEN

app.run

This is the slightly more complex code in FxRuby.

require 'fox16'
require 'fox16/colors'
require 'fox16/kwargs'
include Fox

app = FXApp.new

main = FXMainWindow.new(app, "Fx Hello",
                             :opts  => FXTopWindow::DECOR_ALL,
                             :width => 200,
                             :height => 100)

pane = FXText.new(main, :opts => LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT|LAYOUT_TOP|FRAME_NORMAL,
                         :width => 200,
                         :height => 55) {|pane| pane.backColor = FXColor::White }

slider = FXSlider.new(main, :opts => LAYOUT_FIX_WIDTH|LAYOUT_BOTTOM,
                            :width => 200,
                            :height => 15) {|slider| slider.value = 0}

slider.connect(SEL_COMMAND) {  pane.text = "Argh! You let go!" }
slider.connect(SEL_CHANGED) {  pane.text = "Current slider value: #{slider.value}" }
app.create

main.show PLACEMENT_SCREEN

app.run

Finally the complex looking graphics manipulation sample application you saw is actually glviewer.rb in the samples code in the FxRuby install.

You can download FxRuby from http://www.fxruby.org.

Hope everyone had fun!

About these ads

2 Responses

Subscribe to comments with RSS.

  1. Mohan said, on April 20, 2007 at 9:52 am

    It was wonderful presentation. Looking forward more like this. I am also planning to use FxRuby, help me if you find time.

    Regards,
    Mohan

  2. Herry said, on April 23, 2007 at 9:35 am

    Thanks for e presentation shaus, really learn quite a fair bit from you that evening.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 450 other followers

%d bloggers like this: