FXTable - changing cell content on click

View: New views
1 Messages — Rating Filter:   Alert me  

FXTable - changing cell content on click

by patriceB :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I've got a problem relating to the FXTable widget.

What I want to do is, that whenever a cell is clicked a value out of a range of four possibile values is assigned to that cell.

For example, those values might be "++", "+", "o" and "-".

Initially the table is empty, so in the first click on a specific cell "++" should get written into it, on the second click "+" and so on.

Here is the catch though: I' still relatively new to Ruby and programming in general, so with my knowledge being superficial in the best case it's enterily possible (and likely) that I just lack the proper basic understanding of...well...everything.

Anyway, my my battle plan was to create a simple array, which would store the values. In the FXRuby API I read that, if SEL_COMMAND is used on a table it sends an FXTablePos instance, which indicates the current cell.

So my idea was to store that instance  as key in a hash and assign a initial value of 0 to it. The value then would act as an index to be used in the content array and gets incremented on every click.

The relevant bits of my code read something like this:

def datafill
    contents = ["++", "+", "o", "-"]
   @tabelle.connect(SEL_COMMAND) do  |fu, man, chu|
        @tabelle.setItemText(chu.row, chu.col, contents[hashupdate(chu)])
        end
end

def hashupdate(foo)
     if @loc[foo] == nil
        @loc[foo] = 0
    else
    current = @loc.fetch(foo)
    current += 1
   @loc[foo] = current
   end
       
   return @loc[foo]
       
end

Now obviously I've been going at it for quite some time now, and I've reached the point where I'm running in circles.

What happens when I run the programm is, that regardless of how often I click on a cell just "++" gets assigned to it, which probably means, that the hash is empty in any case, and that I missed something very, very fundamental.

Any comments, suggestions or help would be very much appreciated.

Thanks in advance
Patrice