Paul Carvalho
2010-Mar-22 18:58 UTC
[fxruby-users] How do you enable a button for any option change in UI?
I have an app that has 2 basic purposes: (1) configure options, (2) generate report. Imagine a simple layout - for example, the standard FXRuby "button.rb" script. In addition to the elements on that app, I have another button called "Save configuration". What I want to do is this: the ''save config'' button is disabled by default when you start the app. If the user makes *any* change to any of the options, I want the ''save config'' button to automatically enable. Of course, that''s my first problem. Once I''ve figured out that part, I''ll need to figure out how to read & write the options to a separate file. Any help someone can provide me with this problem would be greatly appreciated. Again, feel free to use the button.rb script as a working example, because that''s what I''m using to try and figure this out. Thanks. Paul. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100322/601770af/attachment-0001.html>
Lyle Johnson
2010-Mar-22 20:10 UTC
[fxruby-users] How do you enable a button for any option change in UI?
On Mon, Mar 22, 2010 at 1:58 PM, Paul Carvalho <tester.paul at gmail.com> wrote:> What I want to do is this: the ''save config'' button is disabled by default > when you start the app.? If the user makes *any* change to any of the > options, I want the ''save config'' button to automatically enable.For that kind of situation, I''d attach a SEL_UPDATE handler to the "Save Config" button: @save_config_button.connect(SEL_UPDATE) do if @config_changed @save_config_button.enable else @save_config_button.disable end end 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.> Of course, that''s my first problem.? Once I''ve figured out that part, I''ll > need to figure out how to read & write the options to a separate file.? Any > help someone can provide me with this problem would be greatly appreciated. > Again, feel free to use the button.rb script as a working example, because > that''s what I''m using to try and figure this out.That sounds like a good job for the registry (FXRegistry) service.
dave L
2010-Mar-22 20:54 UTC
[fxruby-users] How do you enable a button for any option change in UI?
Hi Paul, you need to have this sort of thing. have 2 buttons 1 enabled 1 not & when you click on the enabled button you disable it and enable the other. there could be better ways but this I hope shows you how in a simple fashion. def init @button1.enabled = false @button2.connect(Fox::SEL_COMMAND){ @button1.enabled = true @button2.enabled = false } @button1.connect(Fox::SEL_COMMAND){ @button2.enabled = true @button1.enabled = false } end if you want send via private email what you have and I can try to help you or do something to get you going. in regards to writing to file try this... this always OVER WRITES the data file. a+ appends onto the end of the file - all in the Rdocs for ruby 1.X.x out = File.new(''config.dat'',"w+") out.write "this is put to the config file\n" out.write "this is another line in the config file\n" out.write "this is a 3rd line" out.write "Is this a 4th line?" out.close now what you should see if something like this (if i have it right - thinking off the cuff here :) this is put to the config file this is another line in the config file this is a 3rd lineIs this a 4th line? The ''\n'' is the newline character you need to put in to have a newline appear in the disk file. HTH --- On Tue, 23/3/10, Paul Carvalho <tester.paul at gmail.com> wrote:> From: Paul Carvalho <tester.paul at gmail.com> > Subject: [fxruby-users] How do you enable a button for any option change in UI? > To: fxruby-users at rubyforge.org > Received: Tuesday, 23 March, 2010, 7:58 AM > I have an app that has 2 basic purposes: > (1) configure options, (2) generate report.? Imagine a > simple layout - for example, the standard FXRuby > "button.rb" script.? In addition to the elements > on that app, I have another button called "Save > configuration". > > > What I want to do is this: the ''save config'' button > is disabled by default when you start the app.? If the user > makes *any* change to any of the options, I want the > ''save config'' button to automatically enable. > > > Of course, that''s my first problem.? Once I''ve > figured out that part, I''ll need to figure out how to > read & write the options to a separate file.? Any help > someone can provide me with this problem would be greatly > appreciated.? Again, feel free to use the button.rb script > as a working example, because that''s what I''m using > to try and figure this out. > > > Thanks.? Paul. > > > #yiv1224944298 #avg_ls_inline_popup > {padding:0px > 0px;margin-left:0px;margin-top:0px;width:240px;overflow:hidden;word-wrap:break-word;color:black;font-size:10px;text-align:left;line-height:13px;} > > -----Inline Attachment Follows----- > > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users
Paul Carvalho
2010-Mar-23 04:11 UTC
[fxruby-users] How do you enable a button for any option change in UI?
Thanks for the reply, Lyle. 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?> > That sounds like a good job for the registry (FXRegistry) service. >Interesting. I found some info at http://www.fox-toolkit.com/registry.htmlbut 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. Please let me know. Thanks. Paul. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100323/e87857d5/attachment.html>
Lyle Johnson
2010-Mar-23 13:46 UTC
[fxruby-users] How do you enable a button for any option change in UI?
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(...) @option1.connect(SEL_COMMAND) do # the user clicked this check button to turn the option "on" or "off"... @config_changed = true end>> >> 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).
Paul Carvalho
2010-Mar-23 14:12 UTC
[fxruby-users] How do you enable a button for any option change in UI?
> > 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(...) > @option1.connect(SEL_COMMAND) do > # the user clicked this check button to turn the option "on" or > "off"... > @config_changed = true > end >Ah, yes. I hadn''t gotten that far yet. I''m still working with the UI to see if I can get it to do everything I need before I add the guts of the functions. Thanks for the tip here.> > >> > >> That sounds like a good job for the registry (FXRegistry) service. > > 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). >That''s perfect. Thanks. I am now debating whether it''s worth the bother of having a separate [Save Config] button or if I should just automatically save the options every time on exit like that example. BTW, do you know where these registry options are saved on a Windows box? I searched for a .foxrc file and in the registry but I couldn''t find them. I''d like to have an idea of what the saved options look like to help me figure out how to save/load them. Thanks! Paul. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100323/4969a0ca/attachment.html>
Lyle Johnson
2010-Mar-23 15:08 UTC
[fxruby-users] How do you enable a button for any option change in UI?
On Tue, Mar 23, 2010 at 9:12 AM, Paul Carvalho <tester.paul at gmail.com> wrote:> I am now debating whether it''s worth the bother of having a separate [Save > Config] button or if I should just automatically save the options every time > on exit like that example.Personally, I think the latter option is preferable.> BTW, do you know where these registry options are saved on a Windows box?On Windows, they''re saved in the Windows registry itself (not to a file). I know that it uses the application''s app name and vendor name as parts of the registry key, but I think you''ll need to dig into the FXRegistry class source code to get the specifics.