]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/tests/val.py
   1 from wxPython
.wx 
import * 
   5 class floatValidator(wxPyValidator
): 
   7     def __init__(self
, obj
=None, attrName
=""): 
   8         wxPyValidator
.__init
__(self
) 
   9         self
.numList 
= ['1','2','3','4','5','6','7','8','9','0','.'] 
  10         EVT_CHAR(self
, self
.OnChar
) 
  12         self
.attrName 
= attrName
 
  15         return floatValidator(self
.obj
, self
.attrName
) 
  17     def TransferToWindow(self
): 
  18         if self
.obj 
and hasattr(self
.obj
, self
.attrName
): 
  19             tc 
= wxPyTypeCast(self
.GetWindow(), "wxTextCtrl") 
  20             tc
.SetValue(str(getattr(self
.obj
, self
.attrName
))) 
  23     def TransferFromWindow(self
): 
  24         if self
.obj 
and self
.attrName
: 
  25             tc 
= wxPyTypeCast(self
.GetWindow(), "wxTextCtrl") 
  27             setattr(self
.obj
, self
.attrName
, string
.atof(text
)) 
  31     def Validate(self
, win
): 
  32         tc 
= wxPyTypeCast(self
.GetWindow(), "wxTextCtrl") 
  36             if x 
not in self
.numList
: 
  41     def OnChar(self
, event
): 
  43         if key 
< WXK_SPACE 
or key 
== WXK_DELETE 
or key 
> 255: 
  47         if chr(key
) in self
.numList
: 
  51         if not wxValidator_IsSilent(): 
  54         # Returning without calling even.Skip eats the event before it 
  55         # gets to the text control 
  60 class MyDialog(wxDialog
): 
  61     def __init__(self
, parent
): 
  62         wxDialog
.__init
__(self
, parent
, -1, "hello") 
  64         self
.theValue 
=  555.12 
  65         fltValidator 
= floatValidator(self
, "theValue") 
  67         Vbox 
= wxBoxSizer(wxVERTICAL
) 
  68         Tbox 
= wxBoxSizer(wxHORIZONTAL
) 
  69         Tbox
.Add(wxStaticText(self
, -1, "Initial Balance"), 0, wxALL
,5) 
  70         Tbox
.Add(wxTextCtrl(self
, 13, "123.45", validator 
= fltValidator
, 
  71                             size
=(100, -1)), 0, wxALL
,5) 
  75         Tbox 
= wxBoxSizer(wxHORIZONTAL
) 
  76         Tbox
.Add(wxButton(self
, wxID_OK
, "Ok"), 0, wxALL
,5) 
  77         Tbox
.Add(wxButton(self
, wxID_CANCEL
, "Cancel"), 0, wxALL
,5) 
  81         self
.SetAutoLayout(true
) 
  86 class TestFrame(wxFrame
): 
  87     def __init__(self
, parent
): 
  88         wxFrame
.__init
__(self
, parent
, -1, "Testing...", size
=(150,75)) 
  89         wxButton(self
, 25, "Click Me") 
  90         EVT_BUTTON(self
, 25, self
.OnClick
) 
  93     def OnClick(self
, event
): 
 101 app 
= wxPySimpleApp() 
 102 frame 
= TestFrame(None)