]>
Commit | Line | Data |
---|---|---|
d56cebe7 | 1 | import sys |
cf694132 RD |
2 | from wxPython.wx import * |
3 | ||
4 | #--------------------------------------------------------------------------- | |
5 | ||
6 | class TestPanel(wxPanel): | |
2f9be787 RD |
7 | def OnSetFocus(self, evt): |
8 | print "OnSetFocus" | |
9 | evt.Skip() | |
10 | def OnKillFocus(self, evt): | |
11 | print "OnKillFocus" | |
12 | evt.Skip() | |
0122b7e3 RD |
13 | def OnWindowDestroy(self, evt): |
14 | print "OnWindowDestroy" | |
15 | evt.Skip() | |
16 | ||
2f9be787 | 17 | |
cf694132 RD |
18 | def __init__(self, parent, log): |
19 | wxPanel.__init__(self, parent, -1) | |
20 | self.log = log | |
21 | ||
d56cebe7 RD |
22 | l1 = wxStaticText(self, -1, "wxTextCtrl") |
23 | t1 = wxTextCtrl(self, 10, "Test it out and see", size=(125, -1)) | |
24 | t1.SetInsertionPoint(0) | |
cf694132 | 25 | EVT_TEXT(self, 10, self.EvtText) |
d56cebe7 | 26 | EVT_CHAR(t1, self.EvtChar) |
2f9be787 RD |
27 | EVT_SET_FOCUS(t1, self.OnSetFocus) |
28 | EVT_KILL_FOCUS(t1, self.OnKillFocus) | |
0122b7e3 | 29 | EVT_WINDOW_DESTROY(t1, self.OnWindowDestroy) |
c368d904 | 30 | |
d56cebe7 RD |
31 | l2 = wxStaticText(self, -1, "Passsword") |
32 | t2 = wxTextCtrl(self, 20, "", size=(125, -1), style=wxTE_PASSWORD) | |
cf694132 RD |
33 | EVT_TEXT(self, 20, self.EvtText) |
34 | ||
d56cebe7 | 35 | l3 = wxStaticText(self, -1, "Multi-line") |
4deafe31 RD |
36 | t3 = wxTextCtrl(self, 30, |
37 | "Here is a looooooooooooooong line of text set in the control.\n\n" | |
38 | "The quick brown fox jumped over the lazy dog...", | |
d56cebe7 RD |
39 | size=(200, 100), style=wxTE_MULTILINE) |
40 | t3.SetInsertionPoint(0) | |
cf694132 | 41 | EVT_TEXT(self, 30, self.EvtText) |
c7e7022c RD |
42 | b = wxButton(self, -1, "Test Replace") |
43 | EVT_BUTTON(self, b.GetId(), self.OnTestReplace) | |
4deafe31 RD |
44 | b2 = wxButton(self, -1, "Test GetSelection") |
45 | EVT_BUTTON(self, b2.GetId(), self.OnTestGetSelection) | |
c7e7022c | 46 | self.tc = t3 |
cf694132 | 47 | |
d56cebe7 RD |
48 | l4 = wxStaticText(self, -1, "Rich Text") |
49 | t4 = wxTextCtrl(self, 40, "If supported by the native control, this is red, and this is a different font.", | |
63b6646e | 50 | size=(200, 100), style=wxTE_MULTILINE|wxTE_RICH2) |
d56cebe7 RD |
51 | t4.SetInsertionPoint(0) |
52 | t4.SetStyle(44, 47, wxTextAttr("RED", "YELLOW")) | |
53 | ||
54 | points = t4.GetFont().GetPointSize() # get the current size | |
00b6c4e3 | 55 | f = wxFont(points+3, wxROMAN, wxITALIC, wxBOLD, true) |
d56cebe7 | 56 | t4.SetStyle(63, 77, wxTextAttr("BLUE", wxNullColour, f)) |
d56cebe7 | 57 | |
4deafe31 RD |
58 | bsizer = wxBoxSizer(wxVERTICAL) |
59 | bsizer.Add(b, 0, wxGROW) | |
60 | bsizer.Add(b2, 0, wxGROW) | |
61 | ||
c7e7022c RD |
62 | sizer = wxFlexGridSizer(cols=3, hgap=6, vgap=6) |
63 | sizer.AddMany([ l1, t1, (0,0), | |
64 | l2, t2, (0,0), | |
4deafe31 | 65 | l3, t3, bsizer, |
c7e7022c | 66 | l4, t4, (0,0), |
d56cebe7 RD |
67 | ]) |
68 | border = wxBoxSizer(wxVERTICAL) | |
69 | border.Add(sizer, 0, wxALL, 25) | |
70 | self.SetSizer(border) | |
71 | self.SetAutoLayout(true) | |
72 | ||
73 | ||
cf694132 RD |
74 | def EvtText(self, event): |
75 | self.log.WriteText('EvtText: %s\n' % event.GetString()) | |
76 | ||
77 | ||
c368d904 RD |
78 | def EvtChar(self, event): |
79 | self.log.WriteText('EvtChar: %d\n' % event.GetKeyCode()) | |
80 | event.Skip() | |
81 | ||
cf694132 | 82 | |
c7e7022c | 83 | def OnTestReplace(self, evt): |
4deafe31 RD |
84 | self.tc.Replace(5, 9, "IS A") |
85 | #self.tc.Remove(5, 9) | |
86 | ||
87 | def OnTestGetSelection(self, evt): | |
88 | start, end = self.tc.GetSelection() | |
89 | text = self.tc.GetValue() | |
f0db4f38 | 90 | if wxPlatform == "__WXMSW__": # This is why GetStringSelection was added |
4deafe31 | 91 | text = string.replace(text, '\n', '\r\n') |
f0db4f38 RD |
92 | self.log.write("GetSelection(): (%d, %d)\n" |
93 | "\tGetStringSelection(): %s\n" | |
94 | "\tSelectedText: %s\n" % | |
95 | (start, end, | |
96 | self.tc.GetStringSelection(), | |
97 | repr(text[start:end]))) | |
c7e7022c RD |
98 | |
99 | ||
cf694132 RD |
100 | #--------------------------------------------------------------------------- |
101 | ||
102 | def runTest(frame, nb, log): | |
103 | win = TestPanel(nb, log) | |
104 | return win | |
105 | ||
106 | #--------------------------------------------------------------------------- | |
107 | ||
108 | ||
109 | ||
110 | ||
111 | overview = """\ | |
112 | """ | |
63b6646e RD |
113 | |
114 | ||
115 | ||
116 | ||
117 | if __name__ == '__main__': | |
118 | import sys,os | |
119 | import run | |
120 | run.main(['', os.path.basename(sys.argv[0])]) | |
121 |