]>
Commit | Line | Data |
---|---|---|
1 | import sys | |
2 | from wxPython.wx import * | |
3 | ||
4 | #--------------------------------------------------------------------------- | |
5 | ||
6 | class TestPanel(wxPanel): | |
7 | def OnSetFocus(self, evt): | |
8 | print "OnSetFocus" | |
9 | evt.Skip() | |
10 | def OnKillFocus(self, evt): | |
11 | print "OnKillFocus" | |
12 | evt.Skip() | |
13 | ||
14 | def __init__(self, parent, log): | |
15 | wxPanel.__init__(self, parent, -1) | |
16 | self.log = log | |
17 | ||
18 | l1 = wxStaticText(self, -1, "wxTextCtrl") | |
19 | t1 = wxTextCtrl(self, 10, "Test it out and see", size=(125, -1)) | |
20 | t1.SetInsertionPoint(0) | |
21 | EVT_TEXT(self, 10, self.EvtText) | |
22 | EVT_CHAR(t1, self.EvtChar) | |
23 | EVT_SET_FOCUS(t1, self.OnSetFocus) | |
24 | EVT_KILL_FOCUS(t1, self.OnKillFocus) | |
25 | ||
26 | ||
27 | l2 = wxStaticText(self, -1, "Passsword") | |
28 | t2 = wxTextCtrl(self, 20, "", size=(125, -1), style=wxTE_PASSWORD) | |
29 | EVT_TEXT(self, 20, self.EvtText) | |
30 | ||
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) | |
35 | EVT_TEXT(self, 30, self.EvtText) | |
36 | ||
37 | l4 = wxStaticText(self, -1, "Rich Text") | |
38 | t4 = wxTextCtrl(self, 40, "If supported by the native control, this is red, and this is a different font.", | |
39 | size=(200, 100), style=wxTE_MULTILINE|wxTE_RICH) | |
40 | t4.SetInsertionPoint(0) | |
41 | t4.SetStyle(44, 47, wxTextAttr("RED", "YELLOW")) | |
42 | ||
43 | points = t4.GetFont().GetPointSize() # get the current size | |
44 | f = wxFont(points+2, wxROMAN, wxITALIC, wxBOLD, true) | |
45 | ## print 'a1', sys.getrefcount(f) | |
46 | ## t4.SetStyle(63, 77, wxTextAttr("BLUE", font=f)) | |
47 | t4.SetStyle(63, 77, wxTextAttr("BLUE", wxNullColour, f)) | |
48 | ## print 'a2', sys.getrefcount(f) | |
49 | ||
50 | sizer = wxFlexGridSizer(cols=2, hgap=6, vgap=6) | |
51 | sizer.AddMany([ l1, t1, | |
52 | l2, t2, | |
53 | l3, t3, | |
54 | l4, t4, | |
55 | ]) | |
56 | border = wxBoxSizer(wxVERTICAL) | |
57 | border.Add(sizer, 0, wxALL, 25) | |
58 | self.SetSizer(border) | |
59 | self.SetAutoLayout(true) | |
60 | ||
61 | ||
62 | def EvtText(self, event): | |
63 | self.log.WriteText('EvtText: %s\n' % event.GetString()) | |
64 | ||
65 | ||
66 | def EvtChar(self, event): | |
67 | self.log.WriteText('EvtChar: %d\n' % event.GetKeyCode()) | |
68 | event.Skip() | |
69 | ||
70 | ||
71 | #--------------------------------------------------------------------------- | |
72 | ||
73 | def runTest(frame, nb, log): | |
74 | win = TestPanel(nb, log) | |
75 | return win | |
76 | ||
77 | #--------------------------------------------------------------------------- | |
78 | ||
79 | ||
80 | ||
81 | ||
82 | overview = """\ | |
83 | """ |