RubyLit - Ruby.del.litoral!
Text View

El widget Text View de ruby GTK reemplaza al text de la versión anterior de gtk.

screenshot del ejemplo

El siguiente ejemplo muestra como usarlo.


require 'gtk2'

class Editor

  def initialize
      # creo la ventana principal
    appwindow = Gtk::Window.new(Gtk::Window::TOPLEVEL) 
    appwindow.set_title('TextView')
    appwindow.set_default_size(200,200)

    # capturo el clic en la X
    appwindow.signal_connect('destroy') {Gtk.main_quit}

    # un contenedor que provee scroll vertical y horizontal
    scrollwindow = Gtk::ScrolledWindow.new( nil, nil )

    # el widget que nos interesa.
    textview = Gtk::TextView.new

    # buffer es el complemento que usa el TextView
    buffer   = textview.buffer

    # una caja vertical para ordenar los widget
    vbox     = Gtk::VBox.new(false)

    # boton para ver el texto
    boton1    = Gtk::Button.new("Ver el texto")
    boton1.signal_connect( "button_press_event", Gdk::Event::BUTTON_PRESS  ) { 
        print buffer.text
        print "\n========\n" 
    }

    # boton para setear un texto
    boton2    = Gtk::Button.new("Poner un texto")
    boton2.signal_connect( "button_press_event", Gdk::Event::BUTTON_PRESS  ) { 
        buffer.text = "chau <ponga el otro script languaje acá>\n\nHola Ruby/GTK!" 
    }

    # "empaqueto" los widgets
    scrollwindow.add(textview)
    vbox.pack_start(scrollwindow, true)
    vbox.pack_start(boton1, false)
    vbox.pack_start(boton2, false)
      appwindow.add(vbox)

      # muestro todo
    appwindow.show_all
  end

end

Gtk.init
Editor.new
Gtk.main