]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxTextCtrl.py
2 from wxPython
.wx
import *
4 #---------------------------------------------------------------------------
6 class TestPanel(wxPanel
):
7 def __init__(self
, parent
, log
):
8 wxPanel
.__init
__(self
, parent
, -1)
11 l1
= wxStaticText(self
, -1, "wxTextCtrl")
12 t1
= wxTextCtrl(self
, 10, "Test it out and see", size
=(125, -1))
13 t1
.SetInsertionPoint(0)
14 EVT_TEXT(self
, 10, self
.EvtText
)
15 EVT_CHAR(t1
, self
.EvtChar
)
18 l2
= wxStaticText(self
, -1, "Passsword")
19 t2
= wxTextCtrl(self
, 20, "", size
=(125, -1), style
=wxTE_PASSWORD
)
20 EVT_TEXT(self
, 20, self
.EvtText
)
22 l3
= wxStaticText(self
, -1, "Multi-line")
23 t3
= wxTextCtrl(self
, 30, "How does it work with a long line of text set in the control",
24 size
=(200, 100), style
=wxTE_MULTILINE
)
25 t3
.SetInsertionPoint(0)
26 EVT_TEXT(self
, 30, self
.EvtText
)
28 l4
= wxStaticText(self
, -1, "Rich Text")
29 t4
= wxTextCtrl(self
, 40, "If supported by the native control, this is red, and this is a different font.",
30 size
=(200, 100), style
=wxTE_MULTILINE|wxTE_RICH
)
31 t4
.SetInsertionPoint(0)
32 t4
.SetStyle(44, 47, wxTextAttr("RED", "YELLOW"))
34 points
= t4
.GetFont().GetPointSize() # get the current size
35 f
= wxFont(points
+2, wxROMAN
, wxITALIC
, wxBOLD
, true
)
36 ## print 'a1', sys.getrefcount(f)
37 ## t4.SetStyle(63, 77, wxTextAttr("BLUE", font=f))
38 t4
.SetStyle(63, 77, wxTextAttr("BLUE", wxNullColour
, f
))
39 ## print 'a2', sys.getrefcount(f)
41 sizer
= wxFlexGridSizer(cols
=2, hgap
=6, vgap
=6)
42 sizer
.AddMany([ l1
, t1
,
47 border
= wxBoxSizer(wxVERTICAL
)
48 border
.Add(sizer
, 0, wxALL
, 25)
50 self
.SetAutoLayout(true
)
53 def EvtText(self
, event
):
54 self
.log
.WriteText('EvtText: %s\n' % event
.GetString())
57 def EvtChar(self
, event
):
58 self
.log
.WriteText('EvtChar: %d\n' % event
.GetKeyCode())
62 #---------------------------------------------------------------------------
64 def runTest(frame
, nb
, log
):
65 win
= TestPanel(nb
, log
)
68 #---------------------------------------------------------------------------