danu kusmana wrote:
I'd try using what u suggested but it still doesn't
work. I make a new module TextObjectValidator.py & all
the source is the same like in the demo(class
TextObjectValidator). In wxFrame I add:
from TextObjectValidator import TextObjectValidator
& tried:
1. self.Umur = wxTextCtrl(id=wxID_MAINMENUUMUR,
name='Umur', parent=self.panel1, pos=wxPoint(168, 88),
size=wxSize(100, 21), style=0, value='',
validator=TextObjectValidator())
or
2. self.Umur = wxTextCtrl(id=wxID_MAINMENUUMUR,
name='Umur', parent=self.panel1, pos=wxPoint(168, 88),
size=wxSize(100, 21), style=0, value='')
self.Umur.SetValidator(TextObjectValidator())
or
3. in my wxButton event I add:
self.Umur.SetValidator(TextObjectValidator())
But nothing works. When I tried to go to designer mode
in Boa I got error message "name TextObjectValidator"
not defined when I tried 1 & 2
This code bellow works. Though, it doesn't capture the copy&paste insertions
to the wxTextCtrl. In other word you can 'copy' some text that contains
alpha characters and 'paste' it to the control.
BTW: Will (Sadkin), how did you handle this (copy & paste) thing in
wxMaksedTextCtrl?
···
#----------------------------------------------------------------------
from wxPython.wx import *
import string
class MyValidator(wxPyValidator):
def __init__(self, pyVar=None):
wxPyValidator.__init__(self)
EVT_CHAR(self, self.OnChar)
def Clone(self):
return MyValidator()
def Validate(self, win):
tc = self.GetWindow()
val = tc.GetValue()
for x in val:
if x not in string.digits:
return False
return True
def OnChar(self, event):
key = event.KeyCode()
if key < WXK_SPACE or key == WXK_DELETE or key > 255:
event.Skip()
return
if chr(key) in string.digits:
event.Skip()
return
if not wxValidator_IsSilent():
wxBell()
# Returning without calling even.Skip eats the event before it
# gets to the text control
return
app = wxPySimpleApp()
frm = wxFrame(None, wxNewId(), 'MyValidator')
pnl = wxPanel(frm , wxNewId())
wxTextCtrl(pnl, wxNewId(), '', validator = MyValidator())
frm.Show(True)
app.MainLoop()
#----------------------------------------------------------------------
begin 666 p1.py
M9G)O;2!W>%!Y=&AO;BYW>"!I;7!O<G0@*@T*:6UP;W)T('-T<FEN9PT*#0HC
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+0T*(RTM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2T-"F-L87-S($UY5F%L:61A=&]R*'=X4'E686QI9&%T;W(I.@T*
M(" @(&1E9B!?7VEN:71?7RAS96QF+"!P>59A<CU.;VYE*3H-"B @(" @(" @
M=WA0>59A;&ED871O<BY?7VEN:71?7RAS96QF*0T*(" @(" @("!%5E1?0TA!
M4BAS96QF+"!S96QF+D]N0VAA<BD-"@T*(" @(&1E9B!#;&]N92AS96QF*3H-
M"B @(" @(" @<F5T=7)N($UY5F%L:61A=&]R*"D-"@T*(" @(&1E9B!686QI
M9&%T92AS96QF+"!W:6XI.@T*(" @(" @("!T8R ]('-E;&8N1V5T5VEN9&]W
M*"D-"B @(" @(" @=F%L(#T@=&,N1V5T5F%L=64H*0T*#0H@(" @(" @(&9O
M<B!X(&EN('9A;#H-"B @(" @(" @(" @(&EF('@@;F]T(&EN('-T<FEN9RYD
M:6=I=',Z#0H@(" @(" @(" @(" @(" @<F5T=7)N($9A;'-E#0H@(" @(" @
M(')E='5R;B!4<G5E#0H-"B @("!D968@3VY#:&%R*'-E;&8L(&5V96YT*3H-
M"B @(" @(" @:V5Y(#T@979E;G0N2V5Y0V]D92@I#0H@(" @(" @(&EF(&ME
2 \(%=82U]34$%#12!O<B!K97D@/3T@5UA+7T1%3$5412!O<B!K97D@/B R
M-34Z#0H@(" @(" @(" @("!E=F5N="Y3:VEP*"D-"B @(" @(" @(" @(')E
M='5R;@T*(" @(" @("!I9B!C:'(H:V5Y*2!I;B!S=')I;F<N9&EG:71S.@T*
M(" @(" @(" @(" @979E;G0N4VMI<"@I#0H@(" @(" @(" @("!R971U<FX-
M"@T*(" @(" @("!I9B!N;W0@=WA686QI9&%T;W)?27-3:6QE;G0H*3H-"B @
M(" @(" @(" @('=X0F5L;"@I#0H-"B @(" @(" @(R!2971U<FYI;F<@=VET
M:&]U="!C86QL:6YG(&5V96XN4VMI<"!E871S('1H92!E=F5N="!B969O<F4@
M:70-"B @(" @(" @(R!G971S('1O('1H92!T97AT(&-O;G1R;VP-"B @(" @
M(" @<F5T=7)N#0HC+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+0T*(RTM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2T-"@T*87!P(#T@=WA0>5-I;7!L94%P<"@I
M#0IF<FT@/2!W>$9R86UE*$YO;F4L('=X3F5W260H*2P@)TUY5F%L:61A=&]R
M)RD-"G!N;" ]('=X4&%N96PH9G)M("P@=WA.97=)9"@I*0T*=WA497AT0W1R
M;"AP;FPL('=X3F5W260H*2P@)R<L('9A;&ED871O<B ]($UY5F%L:61A=&]R
C*"DI#0IF<FTN4VAO=RA4<G5E*0T*87!P+DUA:6Y,;V]P*"D`
`
end