The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Gtk and Rails: a strange meeting

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Rudi Cilibrasi

Posts: 25
Nickname: cilibrar
Registered: Aug, 2004

Rudi Cilibrasi is a longtime programmer and machine-learning researcher who loves Ruby
Gtk and Rails: a strange meeting Posted: Oct 10, 2005 4:49 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Rudi Cilibrasi.
Original Post: Gtk and Rails: a strange meeting
Feed Title: Esoteric Ruby Blog
Feed URL: http://cilibrar.com/~cilibrar/erblog.cgi/index.rss
Feed Description: A weblog made to explore some Ruby ideas in great detail and try to work out ideal solutions to real problems.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Rudi Cilibrasi
Latest Posts From Esoteric Ruby Blog

Advertisement
Well, I woke up this morning with a strange idea in my head. I was thinking about how cool Rails is, and how sad it is that so few people get to know it right now. I then remembered another nice library called Gtk, the Gnu version of a portable GUI toolkit, and I remembered the Ruby binding for it. Then I thought, what if you wrote something in rails that provided a Gtk-like interface. So that you could run ruby Gtk programs under a rails web application. It would have to dynamically generate the html that would best approximate the Gtk calls that have been issued. An hour and a half later, rtk was born: Download rtk.tar.gz source Here is the Two Buttons Ruby-Gnome example that this is based on. And here is the controller file where the GtkRails code is embedded:
class MulController < ApplicationController
  private
  def zputs(*args)
    args.each { |i|
      Gtk::Window.getMessageConsole.addmsg(i)
    }
  end
  def greeting(num)
      zputs "This is button #{num}"
  end
  public
  def ui
#    @w = @session['w']
    evt = @params['event']
    id = @params['id']
    Gtk::Signallable.send_signal(id, evt) if evt && id
    rt()
    render :action=>'rt'
  end
  def rt
    unless @w = Gtk::Window.getTopWindow
    # Build the GUI
    window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)
    hbox   = Gtk::HBox.new(false,0)

    button1 = Gtk::Button.new("button 1")
    button2 = Gtk::Button.new("button 2")
    but3 = Gtk::Button.new("but3")

    hbox.pack_start button1, true, true, 0
    hbox.pack_start button2, true, true, 0

    window.add hbox
    window.add but3

    # Callbacks and configuration.

    window.set_title    "Two buttons"
    window.border_width 10
    window.signal_connect('delete_event') { false }
    window.signal_connect('destroy') { Gtk.main_quit }

    button1.signal_connect('clicked') { greeting(1) }
    button2.signal_connect('clicked') { greeting(2) }
    but3.signal_connect('clicked') { zputs "You pressed button 3!" }

    # All done.
    window.show_all
    Gtk.main

    @w = Gtk::Window.getTopWindow
    end
  end
end

Read: Gtk and Rails: a strange meeting

Topic: It Came ... From The Past! Previous Topic   Next Topic Topic: October meeting was awesome.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use