# Validator data transfer

**URL:** <https://www.ruby-forum.com/t/validator-data-transfer/194618>\
**Category:** wxRuby\
**Created:** [September 8, 2010, 2:42am UTC](https://www.ruby-forum.com/t/validator-data-transfer/194618 "2010-09-08T02:42:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![w\_barnes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f08c70/32.png) [@w\_barnes](https://www.ruby-forum.com/u/w_barnes)\
**Post date:** [September 8, 2010, 2:42am UTC](https://www.ruby-forum.com/t/validator-data-transfer/194618/1 "2010-09-08T02:42:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![w\_barnes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f08c70/32.png) [@w\_barnes](https://www.ruby-forum.com/u/w_barnes)\
**Post date:** [September 8, 2010, 5:19am UTC](https://www.ruby-forum.com/t/validator-data-transfer/194618/2 "2010-09-08T05:19:26Z")

</div>

Hello Walter,

On Tue, Sep 7, 2010 at 8:35 PM, Walter B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)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

---

<div class="post-metadata">

**Author:** ![w\_barnes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f08c70/32.png) [@w\_barnes](https://www.ruby-forum.com/u/w_barnes)\
**Post date:** [September 8, 2010, 6:51am UTC](https://www.ruby-forum.com/t/validator-data-transfer/194618/3 "2010-09-08T06:51:56Z")

</div>

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 S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: General discussion of wxRuby [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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 B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
