From 9e46ac75dee6d5f2b70e863259ab2888eb169d3a Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 31 Jan 2000 21:01:00 +0000 Subject: [PATCH] new tests git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5767 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- utils/wxPython/tests/grid.py | 24 ++++++++ utils/wxPython/tests/ste.py | 24 ++++++++ utils/wxPython/tests/val.py | 108 +++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 utils/wxPython/tests/grid.py create mode 100644 utils/wxPython/tests/ste.py create mode 100644 utils/wxPython/tests/val.py diff --git a/utils/wxPython/tests/grid.py b/utils/wxPython/tests/grid.py new file mode 100644 index 0000000000..85c629398d --- /dev/null +++ b/utils/wxPython/tests/grid.py @@ -0,0 +1,24 @@ +from wxPython.wx import * +from wxPython.lib.grids import wxFlexGridSizer + +class aFrame(wxFrame): + def __init__(self, parent=NULL, id=-1, title="test"): + wxFrame.__init__(self, parent, id, title) + s =wxBoxSizer(wxVERTICAL) + gs =wxFlexGridSizer(2, 2, 2, 2) + for label in ('one', 'two', 'tree', 'four'): + gs.Add(wxButton(self, -1, label, size=(100,100)), 1, wxEXPAND) + s.Add(gs, 1, wxEXPAND|wxALL, 50) + self.SetSizer(s) + self.SetAutoLayout(TRUE) + s.Fit(self) + +class MyApp(wxApp): + def OnInit(self): + frame =aFrame() + self.SetTopWindow(frame) + frame.Show(TRUE) + return TRUE + +app=MyApp(0) +app.MainLoop() diff --git a/utils/wxPython/tests/ste.py b/utils/wxPython/tests/ste.py new file mode 100644 index 0000000000..30e1cc47af --- /dev/null +++ b/utils/wxPython/tests/ste.py @@ -0,0 +1,24 @@ + + +from wxPython.wx import * +from wxPython.ste import wxStyledTextEditorCtrl + + +app = wxPySimpleApp() +frame = wxFrame(None, -1, "Testing...", (0,0), (320,480)) +ed = wxStyledTextEditorCtrl(frame, -1) +ed.AddText(open('test7.py').read()) + +#ed.AddText("This is a test\nThis is only a test.\n\nHere we go cowboys, here we go!!!\nThe End") +#ed.SetBufferedDraw(false) + +#ed.StyleSetFontAttr(1, 14, "Times New Roman", true, false) +#ed.StyleSetForeground(1, wxBLUE) +#ed.StyleSetFont(2, wxFont(12, wxMODERN, wxNORMAL, wxNORMAL, false)) + +#ed.StartStyling(48, 0xff) +#ed.SetStyleFor(7, 1) + + +frame.Show(true) +app.MainLoop() diff --git a/utils/wxPython/tests/val.py b/utils/wxPython/tests/val.py new file mode 100644 index 0000000000..9a05123019 --- /dev/null +++ b/utils/wxPython/tests/val.py @@ -0,0 +1,108 @@ +from wxPython.wx import * +import string + + +class floatValidator(wxPyValidator): + + def __init__(self, obj=None, attrName=""): + wxPyValidator.__init__(self) + self.numList = ['1','2','3','4','5','6','7','8','9','0','.'] + EVT_CHAR(self, self.OnChar) + self.obj = obj + self.attrName = attrName + + def Clone(self): + return floatValidator(self.obj, self.attrName) + + def TransferToWindow(self): + if self.obj and hasattr(self.obj, self.attrName): + tc = wxPyTypeCast(self.GetWindow(), "wxTextCtrl") + tc.SetValue(str(getattr(self.obj, self.attrName))) + return true + + def TransferFromWindow(self): + if self.obj and self.attrName: + tc = wxPyTypeCast(self.GetWindow(), "wxTextCtrl") + text = tc.GetValue() + setattr(self.obj, self.attrName, string.atof(text)) + return true + + + def Validate(self, win): + tc = wxPyTypeCast(self.GetWindow(), "wxTextCtrl") + val = tc.GetValue() + + for x in val: + if x not in self.numList: + 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 self.numList: + event.Skip() + return + + if not wxValidator_IsSilent(): + wxBell() + + # Returning without calling even.Skip eats the event before it + # gets to the text control + return + + + +class MyDialog(wxDialog): + def __init__(self, parent): + wxDialog.__init__(self, parent, -1, "hello") + + self.theValue = 555.12 + fltValidator = floatValidator(self, "theValue") + + Vbox = wxBoxSizer(wxVERTICAL) + Tbox = wxBoxSizer(wxHORIZONTAL) + Tbox.Add(wxStaticText(self, -1, "Initial Balance"), 0, wxALL,5) + Tbox.Add(wxTextCtrl(self, 13, "123.45", validator = fltValidator, + size=(100, -1)), 0, wxALL,5) + + Vbox.Add(Tbox, 0, 0) + + Tbox = wxBoxSizer(wxHORIZONTAL) + Tbox.Add(wxButton(self, wxID_OK, "Ok"), 0, wxALL,5) + Tbox.Add(wxButton(self, wxID_CANCEL, "Cancel"), 0, wxALL,5) + + Vbox.Add(Tbox, 0, 0) + + self.SetAutoLayout(true) + self.SetSizer(Vbox) + Vbox.Fit(self) + + +class TestFrame(wxFrame): + def __init__(self, parent): + wxFrame.__init__(self, parent, -1, "Testing...", size=(150,75)) + wxButton(self, 25, "Click Me") + EVT_BUTTON(self, 25, self.OnClick) + + + def OnClick(self, event): + dlg = MyDialog(self) + dlg.ShowModal() + print dlg.theValue + dlg.Destroy() + + + +app = wxPySimpleApp() +frame = TestFrame(None) +frame.Show(true) +app.MainLoop() + + + + -- 2.45.2