[fxruby-users] How do you enable a button for any option change in UI?
lyle at lylejohnson.name
Tue Mar 23 09:46:10 EDT 2010
On Mon, Mar 22, 2010 at 11:11 PM, Paul Carvalho <tester.paul at gmail.com> wrote:
> On 22 March 2010 16:10, Lyle Johnson wrote:
>> Elsewhere in my code, I'd set @config_changed to false whenever the
>> user clicked "Save Config", or to false whenever they made a change to
>> one of the config values.
> This is the part that I wanted help with. How does the app know if/when
> _any_ option has changed? Do I need to iterate through every option and
> check for status change? Is there a method that tells me when an object has
> changed from when it was first drawn/created?
Almost every widget that can be "clicked" sends a SEL_COMMAND message
to its target whenever it gets clicked. This is true for basic
buttons, but also for radio buttons, check buttons, etc. I would have
assumed that you were already reacting to these messages anyways. But
anyways, so, it's not exactly that you're iterating through all of the
options constantly, but you'd just watch for when they change, e.g.
@option1 = FXCheckButton.new(...)
# the user clicked this check button to turn the option "on" or "off"...
@config_changed = true
>> That sounds like a good job for the registry (FXRegistry) service.
> Interesting. I found some info at http://www.fox-toolkit.com/registry.html
> but no examples that I can learn from. Do you know of any examples? I like
> using the button.rb script for testing with. If I can figure out how to
> load/save the settings for that program, I should be able to transfer it to
> my app.
Sure, take a look at the imageviewer.rb example program that comes
with FXRuby. In the ImageWindow#onCmdQuit method you see examples of
how to write application settings out to the registry; in
ImageWindow#create, you see the opposite (reading those saved settings
back into the application).
More information about the fxruby-users