]>
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() | |
13 | ||
cf694132 RD |
14 | def __init__(self, parent, log): |
15 | wxPanel.__init__(self, parent, -1) | |
16 | self.log = log | |
17 | ||
d56cebe7 RD |
18 | l1 = wxStaticText(self, -1, "wxTextCtrl") |
19 | t1 = wxTextCtrl(self, 10, "Test it out and see", size=(125, -1)) | |
20 | t1.SetInsertionPoint(0) | |
cf694132 | 21 | EVT_TEXT(self, 10, self.EvtText) |
d56cebe7 | 22 | EVT_CHAR(t1, self.EvtChar) |
2f9be787 RD |
23 | EVT_SET_FOCUS(t1, self.OnSetFocus) |
24 | EVT_KILL_FOCUS(t1, self.OnKillFocus) | |
c368d904 | 25 | |
cf694132 | 26 | |
d56cebe7 RD |
27 | l2 = wxStaticText(self, -1, "Passsword") |
28 | t2 = wxTextCtrl(self, 20, "", size=(125, -1), style=wxTE_PASSWORD) | |
cf694132 RD |
29 | EVT_TEXT(self, 20, self.EvtText) |
30 | ||
d56cebe7 RD |
31 | l3 = wxStaticText(self, -1, "Multi-line") |
32 | t3 = wxTextCtrl(self, 30, "How does it work with a long line of text set in the control", | |
33 | size=(200, 100), style=wxTE_MULTILINE) | |
34 | t3.SetInsertionPoint(0) | |
cf694132 | 35 | EVT_TEXT(self, 30, self.EvtText) |
c7e7022c RD |
36 | b = wxButton(self, -1, "Test Replace") |
37 | EVT_BUTTON(self, b.GetId(), self.OnTestReplace) | |
38 | self.tc = t3 | |
cf694132 | 39 | |
d56cebe7 RD |
40 | l4 = wxStaticText(self, -1, "Rich Text") |
41 | t4 = wxTextCtrl(self, 40, "If supported by the native control, this is red, and this is a different font.", | |
42 | size=(200, 100), style=wxTE_MULTILINE|wxTE_RICH) | |
43 | t4.SetInsertionPoint(0) | |
44 | t4.SetStyle(44, 47, wxTextAttr("RED", "YELLOW")) | |
45 | ||
46 | points = t4.GetFont().GetPointSize() # get the current size | |
47 | f = wxFont(points+2, wxROMAN, wxITALIC, wxBOLD, true) | |
48 | ## print 'a1', sys.getrefcount(f) | |
49 | ## t4.SetStyle(63, 77, wxTextAttr("BLUE", font=f)) | |
50 | t4.SetStyle(63, 77, wxTextAttr("BLUE", wxNullColour, f)) | |
51 | ## print 'a2', sys.getrefcount(f) | |
52 | ||
c7e7022c RD |
53 | sizer = wxFlexGridSizer(cols=3, hgap=6, vgap=6) |
54 | sizer.AddMany([ l1, t1, (0,0), | |
55 | l2, t2, (0,0), | |
56 | l3, t3, b, | |
57 | l4, t4, (0,0), | |
d56cebe7 RD |
58 | ]) |
59 | border = wxBoxSizer(wxVERTICAL) | |
60 | border.Add(sizer, 0, wxALL, 25) | |
61 | self.SetSizer(border) | |
62 | self.SetAutoLayout(true) | |
63 | ||
64 | ||
cf694132 RD |
65 | def EvtText(self, event): |
66 | self.log.WriteText('EvtText: %s\n' % event.GetString()) | |
67 | ||
68 | ||
c368d904 RD |
69 | def EvtChar(self, event): |
70 | self.log.WriteText('EvtChar: %d\n' % event.GetKeyCode()) | |
71 | event.Skip() | |
72 | ||
cf694132 | 73 | |
c7e7022c RD |
74 | def OnTestReplace(self, evt): |
75 | self.tc.Replace(4, 8, "DOES") | |
76 | #self.tc.Remove(4, 8) | |
77 | ||
78 | ||
cf694132 RD |
79 | #--------------------------------------------------------------------------- |
80 | ||
81 | def runTest(frame, nb, log): | |
82 | win = TestPanel(nb, log) | |
83 | return win | |
84 | ||
85 | #--------------------------------------------------------------------------- | |
86 | ||
87 | ||
88 | ||
89 | ||
90 | overview = """\ | |
91 | """ |