Q: How do I

Discussion in 'Ruby' started by Guido de Melo, May 11, 2005.

  1. Hallo ruby users,

    I' writing a tool to display bibliographical data in columns and I want to
    employ glade for the first time. My display gets built with the source
    below, but I don't get any columns. Can someone please comment?

    Thanks
    Guido


    #!/usr/bin/ruby

    require 'libglade2'

    class Rbib
    def initialize(path)
    @glade = GladeXML.new(path) {|handler| method(handler)}
    @view = @glade.get_widget("treeview1")
    # key, title, name, year, rank, category
    @liststore = Gtk::ListStore.new(String, String, String, String, String, String, String)
    iter = @liststore.append
    iter[0] = "key"
    iter[1] = "title"
    iter[2] = "name"
    iter[3] = "year"
    iter[4] = "rank"
    iter[5] = "category"

    %w{key title name year rank category}.each_with_index do |title, i|
    col = Gtk::TreeViewColumn.new(title, Gtk::CellRendererText.new, {:text => 0})
    @view.append_column(col)
    end
    end

    # just do simple stuff for now
    def on_quit
    Gtk.main_quit
    end
    end

    Gnome::program.new("test", "0.1")
    Rbib.new(File.dirname($0) + "/test.glade")
    Gtk.main
     
    Guido de Melo, May 11, 2005
    #1
    1. Advertising

  2. Hi,

    On 5/11/05, Guido de Melo <> wrote:
    > Hallo ruby users,
    >=20
    > I' writing a tool to display bibliographical data in columns and I want t=

    o
    > employ glade for the first time. My display gets built with the source
    > below, but I don't get any columns. Can someone please comment?
    >=20
    > Thanks
    > Guido
    >=20
    > #!/usr/bin/ruby
    >=20
    > require 'libglade2'
    >=20
    > class Rbib
    > def initialize(path)
    > @glade =3D GladeXML.new(path) {|handler| method(handler)}
    > @view =3D @glade.get_widget("treeview1")
    > # key, title, name, year, rank, category
    > @liststore =3D Gtk::ListStore.new(String, String, String, String, Str=

    ing, String, String)
    > iter =3D @liststore.append
    > iter[0] =3D "key"
    > iter[1] =3D "title"
    > iter[2] =3D "name"
    > iter[3] =3D "year"
    > iter[4] =3D "rank"
    > iter[5] =3D "category"
    >=20


    You seem to forgot to plug your model (liststore) in the view there.

    > %w{key title name year rank category}.each_with_index do |title, i|
    > col =3D Gtk::TreeViewColumn.new(title, Gtk::CellRendererText.new, {=

    :text =3D> 0})
    =20
    ^^^^^^^^^^

    I believe you meant

    :text =3D> 1

    > @view.append_column(col)
    > end
    > end
    >=20
    > # just do simple stuff for now
    > def on_quit
    > Gtk.main_quit
    > end
    > end
    >=20
    > Gnome::program.new("test", "0.1")
    > Rbib.new(File.dirname($0) + "/test.glade")
    > Gtk.main
    >=20
    >=20


    This is the best I can do without seeing the .glade file. If these
    changes do not work please post your .glade file :)

    Laurent
     
    Laurent Sansonetti, May 11, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page