I have an old-school programming background, but am new to Ruby: For a Hangman game I have A..Z buttons connected via FXDataTarget (set to -1 so that first button is not auto-selected). During play, as each button is pressed it is disabled. To initialize a new game I re-enable each button. All is well except that the last button from the previous game is highlighted, and thus unavailable (until a different button is pressed). I obviously would like ALL buttons set as at load time.
I have tried changing attributes(buttonStyle and State); I have tried killFocus; I have even tried re-creating the FXDataTarget. None of these have any effect.
@letterSel =FXDataTarget.new(-1)
letterBtns = {}
("A".."Z").each_with_index do |ltr, x|
letterBtns[x] = FXButton.new(matrix, ltr, opts:FRAME_RAISED, target:@letterSel, selector:FXDataTarget::ID_OPTION+(x))
end
@letterSel.connect(SEL_COMMAND) do |sender, sel, data|
ltr = letterBtns[data].text
letterBtns[data].disable
end
newGameBtn.connect(SEL_COMMAND) do |sender, sel, data|
matrix.each_child do |btn|
btn.enable
# And here is where I try manipulating the button's appearance/functionality
end
end
OK, I'm a bit stupid - the answer was obvious! All I needed to do was set the FXDataTarget value back to -1: @letterSel.value = -1
(I don't know how to flag this as resolved)