[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Q: How do I

Guido de Melo

5/11/2005 10:25:00 AM

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

1 Answer

Laurent Sansonetti

5/11/2005 1:31:00 PM

0

Hi,

On 5/11/05, Guido de Melo <gdm@animanga.de> wrote:
> 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"
>

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 = Gtk::TreeViewColumn.new(title, Gtk::CellRendererText.new, {:text => 0})

^^^^^^^^^^

I believe you meant

:text => 1

> @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
>
>

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

Laurent