Fun with FX ruby

I’m want to dynamicly add.delete rows to a table using
FX ruby, but I’m running into some difficulty.

In My dialog I have a connect for when I click an item
in my table

@table.connect(SEL_COMMAND, method(:push))

which runs this method (It looks in Col 4 for the
"add" button, adds a row, and changes the button to
delete. If it’s delete, the delete the row)

def push(sender, sel, ptr)
x = ptr.col
y = ptr.row
return if y == 0

if x == 4
  if @table.getItem(y,x).to_s == "Add"
    @table.setItemText(y,4, "Delete")
    FXTable::ID_INSERT_ROW
    @table.setItemText(y,0, y.to_s)
    @table.getItem(y, 0).setButton(true)
    @table.getItem(y, 0).justify = 0
    @table.setItemText(y,4, "Add")
    @table.getItem(y, 4).setButton(true)
    @table.getItem(y, 4).justify = 0

  elsif @table.getItem(y,x).to_s == "Delete"
    puts "DELETE"
    FXTable::ID_DELETE_ROW
  end
end

end

I’m sure I’m using FXTable::ID_INSERT_ROW and
FXTable::ID_DELETE_ROW incorrectly, how do you use it
correctly? How do you delete the row you are currently
clicking on?

-Mark.

···

Do you Yahoo!?
HotJobs - Search new jobs daily now
http://hotjobs.yahoo.com/

Mark Krell wrote:

I’m want to dynamicly add.delete rows to a table using
FX ruby, but I’m running into some difficulty.

In My dialog I have a connect for when I click an item
in my table

@table.connect(SEL_COMMAND, method(:push))

which runs this method (It looks in Col 4 for the
“add” button, adds a row, and changes the button to
delete. If it’s delete, the delete the row)

I’m sure I’m using FXTable::ID_INSERT_ROW and
FXTable::ID_DELETE_ROW incorrectly, how do you use it
correctly? How do you delete the row you are currently
clicking on?

FXTable::ID_INSERT_ROW and FXTable::ID_DELETE_ROW are just constants
used as message identifiers – they aren’t themselves methods that you
can call directly. The most straightforward way for you to do this from
Ruby code is to just call the insertRows() or removeRows() methods
directly on the FXTable:

~ def push(theTable, sel, currentPos)
~ row = ptr.row
~ col = ptr.col
~ return if row == 0

~ if col == 4
~ if @table.getItem(row, col).to_s == “Add”
~ @table.setItemText(row, 4, “Delete”)
~ @table.insertRows(row, 1)
~ @table.setItemText(row, 0, row.to_s)
~ @table.getItem(row, 0).setButton(true)
~ @table.getItem(row, 0).justify = 0
~ @table.setItemText(row, 4, “Add”)
~ @table.getItem(row, 4).setButton(true)
~ @table.getItem(row, 4).justify = 0
~ elsif @table.getItem(row, col).to_s == “Delete”
~ @table.removeRows(row, 1)
~ end
~ end
~ end

Hope this helps,

Lyle