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
on 2010-09-08 02:42
on 2010-09-08 05:19
Hello Walter, On Tue, Sep 7, 2010 at 8:35 PM, Walter Barnes <walter_barnes05@yahoo.com>wrote: > > @tc_gTeeth.set_validator(val) > When I attempt to open the dialog box, SketchUp crashes at the third line. > 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
on 2010-09-08 06:51
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@ruby-im.net> To: General discussion of wxRuby <wxruby-users@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@yahoo.com> wrote: Hi all, > > >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
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.