]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxTextCtrl.py
2 from wxPython
.wx
import *
4 #---------------------------------------------------------------------------
6 class TestPanel(wxPanel
):
7 def OnSetFocus(self
, evt
):
10 def OnKillFocus(self
, evt
):
14 def __init__(self
, parent
, log
):
15 wxPanel
.__init
__(self
, parent
, -1)
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
)
26 l2
= wxStaticText(self
, -1, "Passsword")
27 t2
= wxTextCtrl(self
, 20, "", size
=(125, -1), style
=wxTE_PASSWORD
)
28 EVT_TEXT(self
, 20, self
.EvtText
)
30 l3
= wxStaticText(self
, -1, "Multi-line")
31 t3
= wxTextCtrl(self
, 30, "How does it work with a long line of text set in the control",
32 size
=(200, 100), style
=wxTE_MULTILINE
)
33 t3
.SetInsertionPoint(0)
34 EVT_TEXT(self
, 30, self
.EvtText
)
35 b
= wxButton(self
, -1, "Test Replace")
36 EVT_BUTTON(self
, b
.GetId(), self
.OnTestReplace
)
39 l4
= wxStaticText(self
, -1, "Rich Text")
40 t4
= wxTextCtrl(self
, 40, "If supported by the native control, this is red, and this is a different font.",
41 size
=(200, 100), style
=wxTE_MULTILINE|wxTE_RICH
)
42 t4
.SetInsertionPoint(0)
43 t4
.SetStyle(44, 47, wxTextAttr("RED", "YELLOW"))
45 points
= t4
.GetFont().GetPointSize() # get the current size
46 f
= wxFont(points
+3, wxROMAN
, wxITALIC
, wxBOLD
, true
)
47 ## print 'a1', sys.getrefcount(f)
48 ## t4.SetStyle(63, 77, wxTextAttr("BLUE", font=f))
49 t4
.SetStyle(63, 77, wxTextAttr("BLUE", wxNullColour
, f
))
50 ## print 'a2', sys.getrefcount(f)
52 sizer
= wxFlexGridSizer(cols
=3, hgap
=6, vgap
=6)
53 sizer
.AddMany([ l1
, t1
, (0,0),
58 border
= wxBoxSizer(wxVERTICAL
)
59 border
.Add(sizer
, 0, wxALL
, 25)
61 self
.SetAutoLayout(true
)
64 def EvtText(self
, event
):
65 self
.log
.WriteText('EvtText: %s\n' % event
.GetString())
68 def EvtChar(self
, event
):
69 self
.log
.WriteText('EvtChar: %d\n' % event
.GetKeyCode())
73 def OnTestReplace(self
, evt
):
74 self
.tc
.Replace(4, 8, "DOES")
78 #---------------------------------------------------------------------------
80 def runTest(frame
, nb
, log
):
81 win
= TestPanel(nb
, log
)
84 #---------------------------------------------------------------------------