Paolo Micossi
2007-Aug-15 13:32 UTC
[fxruby-users] Beginner question: handling FXColorDialog cancellation
Hello. As part of my first FXRuby project I''m trying to set up things so that the color of some graphic elements gets changed by pressing a button. The button pops up an FXColorDialog and code is supplied to handle the change. I test the value returned by FXColorDialog::execute to detect cancellation and restore the original color, but it does not seem to work. Here is the relevant code fragment: FXButton.new(frame,''Sinusoide'',nil,nil,0,LAYOUT_FILL_X| BUTTON_NORMAL).connect(SEL_COMMAND) do d = FXColorDialog.new(self,''Colore Sinusoide'') d.rgba = @graph.getPlot(''Test Curve'').color c = d.rgba d.connect(SEL_COMMAND) do |sender,sel,ev| @graph.getPlot(''Test Curve'').color = ev end unless d.execute @graph.getPlot(''Test Curve'').color = c end end Before the FXColorDialog is executed I initialize it with the current color of the object, and also save it in variable "c" for later restore. The dialog shows up with the right initialized color. The color= setter method of the graphic elements sends update messages to the relevant targets, so i can see the color being updated on screen all right while I''m choosing inside the dialog. On dialog exit the color will stay put at the last color chosen in the dialog, regardless of pressing ''Accept'' or ''Cancel'' Why is it so? Regards, Paolo Micossi -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/fxruby-users/attachments/20070815/23807887/attachment.html
Lyle Johnson
2007-Aug-18 03:07 UTC
[fxruby-users] Beginner question: handling FXColorDialog cancellation
On Aug 15, 2007, at 8:32 AM, Paolo Micossi wrote:> The button pops up an FXColorDialog and code is supplied to handle > the change. I test the value returned by FXColorDialog::execute to > detect cancellation and restore the original color, but it does not > seem to work.The execute() method returns either 0 or 1, so I think the problem has to do with the test that you''re using: unless d.execute # ... end The code inside this block will *never* run, because both 0 and 1 evaluate to "true" in Ruby. You should see the expected result for Cancel if you change it to this: if d.execute == 0 @graph.getPlot(''Test Curve'').color = c end Hope this helps, Lyle