]>
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 | 22 | l1 = wxStaticText(self, -1, "wxTextCtrl") |
1e4a197e | 23 | t1 = wxTextCtrl(self, -1, "Test it out and see", size=(125, -1)) |
d56cebe7 | 24 | t1.SetInsertionPoint(0) |
1e4a197e RD |
25 | self.tc1 = t1 |
26 | EVT_TEXT(self, t1.GetId(), self.EvtText) | |
d56cebe7 | 27 | EVT_CHAR(t1, self.EvtChar) |
2f9be787 RD |
28 | EVT_SET_FOCUS(t1, self.OnSetFocus) |
29 | EVT_KILL_FOCUS(t1, self.OnKillFocus) | |
0122b7e3 | 30 | EVT_WINDOW_DESTROY(t1, self.OnWindowDestroy) |
c368d904 | 31 | |
8b9a4190 | 32 | l2 = wxStaticText(self, -1, "Password") |
1e4a197e RD |
33 | t2 = wxTextCtrl(self, -1, "", size=(125, -1), style=wxTE_PASSWORD) |
34 | EVT_TEXT(self, t2.GetId(), self.EvtText) | |
cf694132 | 35 | |
d56cebe7 | 36 | l3 = wxStaticText(self, -1, "Multi-line") |
1e4a197e | 37 | t3 = wxTextCtrl(self, -1, |
4deafe31 RD |
38 | "Here is a looooooooooooooong line of text set in the control.\n\n" |
39 | "The quick brown fox jumped over the lazy dog...", | |
d56cebe7 RD |
40 | size=(200, 100), style=wxTE_MULTILINE) |
41 | t3.SetInsertionPoint(0) | |
1e4a197e | 42 | EVT_TEXT(self, t3.GetId(), self.EvtText) |
c7e7022c RD |
43 | b = wxButton(self, -1, "Test Replace") |
44 | EVT_BUTTON(self, b.GetId(), self.OnTestReplace) | |
4deafe31 RD |
45 | b2 = wxButton(self, -1, "Test GetSelection") |
46 | EVT_BUTTON(self, b2.GetId(), self.OnTestGetSelection) | |
1e4a197e RD |
47 | b3 = wxButton(self, -1, "Test WriteText") |
48 | EVT_BUTTON(self, b3.GetId(), self.OnTestWriteText) | |
c7e7022c | 49 | self.tc = t3 |
1e4a197e | 50 | |
cf694132 | 51 | |
d56cebe7 | 52 | l4 = wxStaticText(self, -1, "Rich Text") |
1e4a197e | 53 | t4 = wxTextCtrl(self, -1, "If supported by the native control, this is red, and this is a different font.", |
63b6646e | 54 | size=(200, 100), style=wxTE_MULTILINE|wxTE_RICH2) |
d56cebe7 RD |
55 | t4.SetInsertionPoint(0) |
56 | t4.SetStyle(44, 47, wxTextAttr("RED", "YELLOW")) | |
d56cebe7 | 57 | points = t4.GetFont().GetPointSize() # get the current size |
1e4a197e | 58 | f = wxFont(points+3, wxROMAN, wxITALIC, wxBOLD, True) |
d56cebe7 | 59 | t4.SetStyle(63, 77, wxTextAttr("BLUE", wxNullColour, f)) |
d56cebe7 | 60 | |
1e4a197e RD |
61 | l5 = wxStaticText(self, -1, "Test Positions") |
62 | t5 = wxTextCtrl(self, -1, "0123456789\n" * 5, size=(200, 100), | |
63 | style = wxTE_MULTILINE | |
64 | #| wxTE_RICH | |
65 | | wxTE_RICH2 | |
66 | ) | |
67 | EVT_LEFT_DOWN(t5, self.OnT5LeftDown) | |
68 | self.t5 = t5 | |
69 | ||
70 | ||
4deafe31 | 71 | bsizer = wxBoxSizer(wxVERTICAL) |
1e4a197e RD |
72 | bsizer.Add(b, 0, wxGROW|wxALL, 4) |
73 | bsizer.Add(b2, 0, wxGROW|wxALL, 4) | |
74 | bsizer.Add(b3, 0, wxGROW|wxALL, 4) | |
4deafe31 | 75 | |
c7e7022c RD |
76 | sizer = wxFlexGridSizer(cols=3, hgap=6, vgap=6) |
77 | sizer.AddMany([ l1, t1, (0,0), | |
78 | l2, t2, (0,0), | |
4deafe31 | 79 | l3, t3, bsizer, |
c7e7022c | 80 | l4, t4, (0,0), |
1e4a197e | 81 | l5, t5, (0,0), |
d56cebe7 RD |
82 | ]) |
83 | border = wxBoxSizer(wxVERTICAL) | |
84 | border.Add(sizer, 0, wxALL, 25) | |
85 | self.SetSizer(border) | |
1e4a197e | 86 | self.SetAutoLayout(True) |
d56cebe7 RD |
87 | |
88 | ||
cf694132 RD |
89 | def EvtText(self, event): |
90 | self.log.WriteText('EvtText: %s\n' % event.GetString()) | |
91 | ||
92 | ||
c368d904 RD |
93 | def EvtChar(self, event): |
94 | self.log.WriteText('EvtChar: %d\n' % event.GetKeyCode()) | |
95 | event.Skip() | |
96 | ||
cf694132 | 97 | |
c7e7022c | 98 | def OnTestReplace(self, evt): |
4deafe31 RD |
99 | self.tc.Replace(5, 9, "IS A") |
100 | #self.tc.Remove(5, 9) | |
101 | ||
1e4a197e RD |
102 | def OnTestWriteText(self, evt): |
103 | self.tc.WriteText("TEXT") | |
104 | ||
4deafe31 RD |
105 | def OnTestGetSelection(self, evt): |
106 | start, end = self.tc.GetSelection() | |
107 | text = self.tc.GetValue() | |
f0db4f38 | 108 | if wxPlatform == "__WXMSW__": # This is why GetStringSelection was added |
1e4a197e | 109 | text = text.replace('\n', '\r\n') |
3628e088 | 110 | self.log.write("multi-line GetSelection(): (%d, %d)\n" |
f0db4f38 RD |
111 | "\tGetStringSelection(): %s\n" |
112 | "\tSelectedText: %s\n" % | |
113 | (start, end, | |
114 | self.tc.GetStringSelection(), | |
115 | repr(text[start:end]))) | |
c7e7022c | 116 | |
3628e088 RD |
117 | start, end = self.tc1.GetSelection() |
118 | text = self.tc1.GetValue() | |
119 | if wxPlatform == "__WXMSW__": # This is why GetStringSelection was added | |
120 | text = text.replace('\n', '\r\n') | |
121 | self.log.write("single-line GetSelection(): (%d, %d)\n" | |
122 | "\tGetStringSelection(): %s\n" | |
123 | "\tSelectedText: %s\n" % | |
124 | (start, end, | |
125 | self.tc1.GetStringSelection(), | |
126 | repr(text[start:end]))) | |
127 | ||
128 | ||
1e4a197e RD |
129 | def OnT5LeftDown(self, evt): |
130 | evt.Skip() | |
131 | wxCallAfter(self.LogT5Position, evt) | |
132 | ||
133 | def LogT5Position(self, evt): | |
134 | text = self.t5.GetValue() | |
135 | ip = self.t5.GetInsertionPoint() | |
136 | lp = self.t5.GetLastPosition() | |
137 | self.log.write("LogT5Position:\n" | |
138 | "\tGetInsertionPoint:\t%d\n" | |
139 | "\ttext[insertionpoint]:\t%s\n" | |
140 | "\tGetLastPosition:\t%d\n" | |
141 | "\tlen(text):\t\t%d\n" | |
142 | % (ip, text[ip], lp, len(text))) | |
143 | ||
144 | ||
cf694132 RD |
145 | #--------------------------------------------------------------------------- |
146 | ||
147 | def runTest(frame, nb, log): | |
148 | win = TestPanel(nb, log) | |
149 | return win | |
150 | ||
151 | #--------------------------------------------------------------------------- | |
152 | ||
153 | ||
154 | ||
155 | ||
156 | overview = """\ | |
157 | """ | |
63b6646e RD |
158 | |
159 | ||
160 | ||
161 | ||
162 | if __name__ == '__main__': | |
163 | import sys,os | |
164 | import run | |
165 | run.main(['', os.path.basename(sys.argv[0])]) | |
166 |