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