possible to validate text from a textCtl made within an HtmlWindow?

The subject basically says it. I tried using a validator class found in Mike’s answer here (http://stackoverflow.com/questions/2198903/wx-textctrl-and-wx-validator), including that class, and then constructing the textCtrl within the HTML like so:

…but the resulting textCtrl allows digits. Not sure how to do this. Hints welcomed.

Thanks,
Che

Not tried embedding wx in html but looking at the demo code it is
not using validators in the typical wx sense but is using a derived
class
so your wxp tag would need to read:
which I am not sure is allowed
or you would need to derive a class from CharValidator called say
AlphaCharValidator that in it’s default constructor initialises the
parent class with ‘no-digit’ - as I said I have no experience with
wxp tags so could be completely wrong here but hope this gets you
pointed in the right direction.

···

On 22/12/12 04:06, C M wrote:

  The subject basically says it.  I tried using a

validator class found in Mike’s answer here (http://stackoverflow.com/questions/2198903/wx-textctrl-and-wx-validator ),
including that class, and then constructing the textCtrl within
the HTML like so:

  <wxp module="wx" class="TextCtrl" width="50%"

validator=“CharValidator(‘no-digit’)”>

  ...but the resulting textCtrl allows digits.  Not sure how to do

this. Hints welcomed.

  Thanks,

  Che

  --

  To unsubscribe, send email to

or visit
CharValidator


Steve Gadget Barnes

wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en

wxp tags use nested <param> tags to collect keyword args to pass to the widget's constructor, see the docstring in wx.lib.wxptag for details. However it will not work with complex expressions for the parameter values like creating a validator instance, at least not currently. The wxp tag handler is not very complex, so it wouldn't be impossible to make it be more capable in the types of parameters that it could create for passing to the widget.

There are some easy alternatives to hacking the tag handler though. You can use <param> to give the widget an ID and/or a name, and then find the widget by ID/name after the document has been loaded and assign the validator to it with SetValidator.

Another possibility is to create your own class derived from wx.TextCtrl that assigns a validator to itself, and then specify that module and class name in the <wxp> tag. If you want to make the class able to use various types of validators (or other parameters) then you can make your class' __init__ accept additional keyword args beyond the standard ones and then specify those values with <param>.

···

On 12/22/12 12:05 AM, Steve Barnes wrote:

On 22/12/12 04:06, C M wrote:

The subject basically says it. I tried using a validator class found
in Mike's answer here
(python - wx.TextCtrl and wx.Validator - Stack Overflow),
including that class, and then constructing the textCtrl within the
HTML like so:

<wxp module="wx" class="TextCtrl" width="50%"
validator="CharValidator('no-digit')">

...but the resulting textCtrl allows digits. Not sure how to do
this. Hints welcomed.

Not tried embedding wx in html but looking at the demo code it is not
using validators in the typical wx sense but is using a derived class
>CharValidator> so your wxp tag would need to read:
<wxp module="wx" width="50%" class="CharValidator('no-digit')"> which I
am not sure is allowed or you would need to derive a class from
CharValidator called say AlphaCharValidator that in it's default
constructor initialises the parent class with 'no-digit' - as I said I
have no experience with wxp tags so could be completely wrong here but
hope this gets you pointed in the right direction.

--
Robin Dunn
Software Craftsman

Great intel, as always. The SetValidator() approach works well for me. Thanks,
Che

···

On Sat, Dec 22, 2012 at 2:38 PM, Robin Dunn robin@alldunn.com wrote:

On 12/22/12 12:05 AM, Steve Barnes wrote:

On 22/12/12 04:06, C M wrote:

The subject basically says it. I tried using a validator class found

in Mike’s answer here

(http://stackoverflow.com/questions/2198903/wx-textctrl-and-wx-validator),

including that class, and then constructing the textCtrl within the

HTML like so:

<wxp module=“wx” class=“TextCtrl” width=“50%”

validator=“CharValidator(‘no-digit’)”>

…but the resulting textCtrl allows digits. Not sure how to do

this. Hints welcomed.

Not tried embedding wx in html but looking at the demo code it is not

using validators in the typical wx sense but is using a derived class

CharValidator> so your wxp tag would need to read:

which I

am not sure is allowed or you would need to derive a class from

CharValidator called say AlphaCharValidator that in it’s default

constructor initialises the parent class with ‘no-digit’ - as I said I

have no experience with wxp tags so could be completely wrong here but

hope this gets you pointed in the right direction.

wxp tags use nested tags to collect keyword args to pass to the widget’s constructor, see the docstring in wx.lib.wxptag for details. However it will not work with complex expressions for the parameter values like creating a validator instance, at least not currently. The wxp tag handler is not very complex, so it wouldn’t be impossible to make it be more capable in the types of parameters that it could create for passing to the widget.

There are some easy alternatives to hacking the tag handler though. You can use to give the widget an ID and/or a name, and then find the widget by ID/name after the document has been loaded and assign the validator to it with SetValidator.

Another possibility is to create your own class derived from wx.TextCtrl that assigns a validator to itself, and then specify that module and class name in the tag. If you want to make the class able to use various types of validators (or other parameters) then you can make your class’ init accept additional keyword args beyond the standard ones and then specify those values with .