Moving rows included on a gtk treeview using a single button

Hello everybody i’m new here :), I’m trying to get handle of gtk
treeviews,
right now, i know how to create rows, columns and some else, but i have
a
problem, i want to move the rows using a button, come on the classic up
and
down, well i don’t an idea to do that =/ i’m learning about ruby + gtk,
i
think this combination is simply wow, here is the code i’m using glade,
libglade can someone let me a little of light?, some example to do that
or
just talk me something about, using glade or simple gtk.

how you can see, i’m following some of your examples.
watch the picture too, to get a better idea.

I extend my regards to everyone greetings.

Julio César Sosa Yeladaqui.

±----------------------
+treeview.rb
±----------------------

#!/usr/bin/env ruby

=begin
treeview.rb - Ruby/Libglade2 sample script.

Copyright © 2002-2006 Ruby-GNOME2 Project Team
This program is licenced under the same licence as Ruby-GNOME2.

$Id: treeview.rb,v 1.5 2006/06/17 14:14:55 mutoh Exp $
=end

Manejo y control de Listas o treeview de gtk mediante glade en Ruby

Crear ---------- Si

Ordenar -------- Si

Eliminar ------- Pendiente

Mover Arriba/Abajo -------Pendiente

require ‘libglade2’

class Treeview
def initialize(path)
@glade = GladeXML.new(path) {|handler| method(handler)}
@treeview = @glade[“treeview1”]
@model = Gtk::TreeStore.new(String, String)

crt = Gtk::CellRendererText.new

column = Gtk::TreeViewColumn.new(“Test”, Gtk::CellRendererText.new,

{:text => 0})

column2 = Gtk::TreeViewColumn.new(“hola”,

Gtk::CellRendererText.new,
{:text => 1})

column = Gtk::TreeViewColumn.new("Test", crt, {:text => 0})
column2 = Gtk::TreeViewColumn.new("hola", crt, {:text => 1})

#-----------------------------------------

root_iter = @model.append(nil)

rootx_iter = @model.append(nil)

#-------------------------------------
@treeview.append_column(column)

root_iter.set_value(0, "hello guys")

rootx_iter.set_value(0, "moco")

child1 = @model.append(root_iter)

child1.set_value(0, “Child1”)

@treeview.set_model(@model)

#-------------------------------------
@treeview.append_column(column2)

root_iter = @model.append(nil)

root_iter.set_value(1, "jojojo")

rootx_iter.set_value(1, "loco")

hijo_col2 = @model.append(root_iter)

hijo_col2.set_value(1, “yo no jui”)

#--------------------------------------
@treeview.set_model(@model)

@treeview.set_size_request(200, 200)

end
end

Treeview.new(“treeview.glade”)
Gtk.main

Julio César Sosa Yeladaqui wrote:

Hello everybody i’m new here :), I’m trying to get handle of gtk treeviews,
right now, i know how to create rows, columns and some else, but i have a
problem, i want to move the rows using a button, come on the classic up and
down, well i don’t an idea to do that =/ i’m learning about ruby + gtk, i
think this combination is simply wow, here is the code i’m using glade,
libglade can someone let me a little of light?, some example to do that or
just talk me something about, using glade or simple gtk.

Try putting something like this in Treeview.initialize:

down_button = @glade["button4"]
down_button.signal_connect("clicked"){
  selected_item = @treeview.selection.selected
  @model.move_before( selected_item, nil )  # move to end of list
}

This will cause the block of code, between { and }, to be executed
when the down button is clicked. This code will move the
selected row to the bottom of the list. This isn’t exactly what
you want. You’ll have to read the documentation for Gtk::TreeStore
to find out how to do it. Also this code does not do any error
checking, it crashes if no line is selected when you press the down
button. Something else that can be easily fixed.

I hope this helps. And welcome to ruby/gtk!

Martin


This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

thanks a lot Martin i will try it n___n i love this community

2007/6/8, Martin P. [email protected]:

Try putting something like this in Treeview.initialize:
you want. You’ll have to read the documentation for Gtk::TreeStore
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/


ruby-gnome2-devel-en mailing list
[email protected]
ruby-gnome2-devel-en List Signup and Options


This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/