Hi all, I''m working on a dialog box for a SketchUp plug-in using wxSU with several text controls that accept numerical input only and need a little help with the validators. After going through the docs for wxRuby and wxWidgets I tried the following: class SpurGearDialog < Wx::Dialog attr_accessor :gear_teeth def create_gear_parameter_controls ... #set validators val = Wx::TextValidator.new(Wx::FILTER_INCLUDE_CHAR_LIST, @gear_teeth) val.set_includes(@arr_int) @tc_gTeeth.set_validator(val) ... end end With @tc_gTeeth being the text control, @gear_teeth the instance variable that I want the validator to save data to and @arr_int is my list of acceptable characters. When I attempt to open the dialog box, SketchUp crashes at the third line. I found I can only get the validator to work by removing @gear_teeth when creating the validator. However, if I do this I do not see how the validator can transfer data between the control and my dialog class. I''m a Ruby newbie so the problem might be my code but if not, is there a way to get data from the control using validators in wxRuby or is data transfer just not supported at this time? TIA! Walter _______________________________________________ wxruby-users mailing list wxruby-users@rubyforge.org http://rubyforge.org/mailman/listinfo/wxruby-users
Hello Walter, On Tue, Sep 7, 2010 at 8:35 PM, Walter Barnes <walter_barnes05 at yahoo.com>wrote:> Hi all, > > I''m working on a dialog box for a SketchUp plug-in using wxSU with several > text controls that accept numerical input only and need a little help with > the validators. > > After going through the docs for wxRuby and wxWidgets I tried the > following: > > class SpurGearDialog < Wx::Dialog > > attr_accessor :gear_teeth > > def create_gear_parameter_controls > > ... > > #set validators > val = Wx::TextValidator.new(Wx::FILTER_INCLUDE_CHAR_LIST, > @gear_teeth) > val.set_includes(@arr_int) > @tc_gTeeth.set_validator(val) > > ... > > end > end > > With @tc_gTeeth being the text control, @gear_teeth the instance variable > that I want the validator to save data to and @arr_int is my list of > acceptable characters. > > When I attempt to open the dialog box, SketchUp crashes at the third line. > I found I can only get the validator to work by removing @gear_teeth when > creating the validator. However, if I do this I do not see how the validator > can transfer data between the control and my dialog class. > > I''m a Ruby newbie so the problem might be my code but if not, is there a > way to get data from the control using validators in wxRuby or is data > transfer just not supported at this time? > > TIA! > > Walter >When your dialog is accepted by the user, (Eg: Wx::ID_OK is returned from show_modal), you use text_ctrl.value to retrieve the data that is stored in the field. You need to put an attr_reader on your dialog class, for your tc_gTeeth. Afterwhich, once your dialog is accepted, you use myDialog.tc_gTeeth.value to retrieve the value that the user has inputed. Hope this helps and makes sense. hth, Mario> > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >-- Mario Steele Lieutenant Commander 3 XO - Geo 99 XO - STO IFT Fleet http://www.trekfederation.com http://geo99.ruby-im.net -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20100907/f15c3d19/attachment.html>
It would appear then that validators are not fully implemented in wxRuby. From the wxWidgets docs, I think it''s possible to have a public String variable in the dialog class that the validator sends the value of the text control to. Basically then you can do MyDialog.my_variable without dealing directly with the dialog controls. If that''s not possible in wxRuby I''ll go ahead and do as you suggest and set up accessors for the text controls. Thanks Mario! ________________________________ From: Mario Steele <mario at ruby-im.net> To: General discussion of wxRuby <wxruby-users at rubyforge.org> Sent: Tue, September 7, 2010 8:18:29 PM Subject: Re: [wxruby-users] Validator data transfer Hello Walter, On Tue, Sep 7, 2010 at 8:35 PM, Walter Barnes <walter_barnes05 at yahoo.com> wrote: Hi all,> >I''m working on a dialog box for a SketchUp plug-in using wxSU with several text >controls that accept numerical input only and need a little help with the >validators. > >After going through the docs for wxRuby and wxWidgets I tried the following: > >class SpurGearDialog < Wx::Dialog > > attr_accessor :gear_teeth > > def create_gear_parameter_controls > >... > > #set validators > val = Wx::TextValidator.new(Wx::FILTER_INCLUDE_CHAR_LIST, @gear_teeth) > val.set_includes(@arr_int) > @tc_gTeeth.set_validator(val) > >... > > end >end > >With @tc_gTeeth being the text control, @gear_teeth the instance variable that >I want the validator to save data to and @arr_int is my list of acceptable >characters. > >When I attempt to open the dialog box, SketchUp crashes at the third line. I >found I can only get the validator to work by removing @gear_teeth when creating >the validator. However, if I do this I do not see how the validator can transfer >data between the control and my dialog class. > >I''m a Ruby newbie so the problem might be my code but if not, is there a way to >get data from the control using validators in wxRuby or is data transfer just >not supported at this time? > >TIA! > >WalterWhen your dialog is accepted by the user, (Eg: Wx::ID_OK is returned from show_modal), you use text_ctrl.value to retrieve the data that is stored in the field. You need to put an attr_reader on your dialog class, for your tc_gTeeth. Afterwhich, once your dialog is accepted, you use myDialog.tc_gTeeth.value to retrieve the value that the user has inputed. Hope this helps and makes sense. hth, Mario>_______________________________________________ >wxruby-users mailing list >wxruby-users at rubyforge.org >http://rubyforge.org/mailman/listinfo/wxruby-users >-- Mario Steele Lieutenant Commander 3 XO - Geo 99 XO - STO IFT Fleet http://www.trekfederation.com http://geo99.ruby-im.net -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20100907/ccc44792/attachment.html>