2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import wx
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestPanel(wx.Panel):
|
2001-07-27 23:06:02 -04:00
|
|
|
def OnSetFocus(self, evt):
|
|
|
|
print "OnSetFocus"
|
|
|
|
evt.Skip()
|
|
|
|
def OnKillFocus(self, evt):
|
|
|
|
print "OnKillFocus"
|
|
|
|
evt.Skip()
|
2001-10-12 19:26:38 -04:00
|
|
|
def OnWindowDestroy(self, evt):
|
|
|
|
print "OnWindowDestroy"
|
|
|
|
evt.Skip()
|
|
|
|
|
2001-07-27 23:06:02 -04:00
|
|
|
|
1999-04-29 23:29:54 -04:00
|
|
|
def __init__(self, parent, log):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
1999-04-29 23:29:54 -04:00
|
|
|
self.log = log
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
l1 = wx.StaticText(self, -1, "wx.TextCtrl")
|
|
|
|
t1 = wx.TextCtrl(self, -1, "Test it out and see", size=(125, -1))
|
2001-06-15 17:43:26 -04:00
|
|
|
t1.SetInsertionPoint(0)
|
2003-03-25 01:35:27 -05:00
|
|
|
self.tc1 = t1
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
self.Bind(wx.EVT_TEXT, self.EvtText, t1)
|
|
|
|
t1.Bind(wx.EVT_CHAR, self.EvtChar)
|
|
|
|
t1.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
|
|
|
|
t1.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
|
|
|
|
t1.Bind(wx.EVT_WINDOW_DESTROY, self.OnWindowDestroy)
|
|
|
|
|
|
|
|
l2 = wx.StaticText(self, -1, "Password")
|
|
|
|
t2 = wx.TextCtrl(self, -1, "", size=(125, -1), style=wx.TE_PASSWORD)
|
|
|
|
self.Bind(wx.EVT_TEXT, self.EvtText, t2)
|
|
|
|
|
|
|
|
l3 = wx.StaticText(self, -1, "Multi-line")
|
|
|
|
t3 = wx.TextCtrl(self, -1,
|
2001-11-12 22:14:05 -05:00
|
|
|
"Here is a looooooooooooooong line of text set in the control.\n\n"
|
|
|
|
"The quick brown fox jumped over the lazy dog...",
|
2003-12-08 20:23:28 -05:00
|
|
|
size=(200, 100), style=wx.TE_MULTILINE)
|
|
|
|
|
2001-06-15 17:43:26 -04:00
|
|
|
t3.SetInsertionPoint(0)
|
2003-12-08 20:23:28 -05:00
|
|
|
self.Bind(wx.EVT_TEXT, self.EvtText, t3)
|
|
|
|
b = wx.Button(self, -1, "Test Replace")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnTestReplace, b)
|
|
|
|
b2 = wx.Button(self, -1, "Test GetSelection")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnTestGetSelection, b2)
|
|
|
|
b3 = wx.Button(self, -1, "Test WriteText")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnTestWriteText, b3)
|
2001-08-14 15:19:48 -04:00
|
|
|
self.tc = t3
|
2003-03-25 01:35:27 -05:00
|
|
|
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
l4 = wx.StaticText(self, -1, "Rich Text")
|
|
|
|
t4 = wx.TextCtrl(self, -1, "If supported by the native control, this is red, and this is a different font.",
|
|
|
|
size=(200, 100), style=wx.TE_MULTILINE|wx.TE_RICH2)
|
2001-06-15 17:43:26 -04:00
|
|
|
t4.SetInsertionPoint(0)
|
2003-12-08 20:23:28 -05:00
|
|
|
t4.SetStyle(44, 47, wx.TextAttr("RED", "YELLOW"))
|
2001-06-15 17:43:26 -04:00
|
|
|
points = t4.GetFont().GetPointSize() # get the current size
|
2003-12-08 20:23:28 -05:00
|
|
|
f = wx.Font(points+3, wx.ROMAN, wx.ITALIC, wx.BOLD, True)
|
|
|
|
t4.SetStyle(63, 77, wx.TextAttr("BLUE", wx.NullColour, f))
|
|
|
|
|
|
|
|
l5 = wx.StaticText(self, -1, "Test Positions")
|
|
|
|
t5 = wx.TextCtrl(self, -1, "0123456789\n" * 5, size=(200, 100),
|
|
|
|
style = wx.TE_MULTILINE
|
|
|
|
#| wx.TE_RICH
|
|
|
|
| wx.TE_RICH2
|
2003-03-25 01:35:27 -05:00
|
|
|
)
|
2003-12-08 20:23:28 -05:00
|
|
|
t5.Bind(wx.EVT_LEFT_DOWN, self.OnT5LeftDown)
|
2003-03-25 01:35:27 -05:00
|
|
|
self.t5 = t5
|
|
|
|
|
2004-01-14 20:24:35 -05:00
|
|
|
space = 4
|
2003-12-08 20:23:28 -05:00
|
|
|
bsizer = wx.BoxSizer(wx.VERTICAL)
|
2004-01-14 20:24:35 -05:00
|
|
|
bsizer.Add(b, 0, wx.GROW|wx.ALL, space)
|
|
|
|
bsizer.Add(b2, 0, wx.GROW|wx.ALL, space)
|
|
|
|
bsizer.Add(b3, 0, wx.GROW|wx.ALL, space)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2004-01-14 20:24:35 -05:00
|
|
|
sizer = wx.FlexGridSizer(cols=3, hgap=space, vgap=space)
|
2001-08-14 15:19:48 -04:00
|
|
|
sizer.AddMany([ l1, t1, (0,0),
|
|
|
|
l2, t2, (0,0),
|
2001-11-12 22:14:05 -05:00
|
|
|
l3, t3, bsizer,
|
2001-08-14 15:19:48 -04:00
|
|
|
l4, t4, (0,0),
|
2003-03-25 01:35:27 -05:00
|
|
|
l5, t5, (0,0),
|
2001-06-15 17:43:26 -04:00
|
|
|
])
|
2003-12-08 20:23:28 -05:00
|
|
|
border = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
border.Add(sizer, 0, wx.ALL, 25)
|
2001-06-15 17:43:26 -04:00
|
|
|
self.SetSizer(border)
|
2003-03-25 01:35:27 -05:00
|
|
|
self.SetAutoLayout(True)
|
2001-06-15 17:43:26 -04:00
|
|
|
|
|
|
|
|
1999-04-29 23:29:54 -04:00
|
|
|
def EvtText(self, event):
|
|
|
|
self.log.WriteText('EvtText: %s\n' % event.GetString())
|
|
|
|
|
|
|
|
|
2000-10-30 16:08:42 -05:00
|
|
|
def EvtChar(self, event):
|
|
|
|
self.log.WriteText('EvtChar: %d\n' % event.GetKeyCode())
|
|
|
|
event.Skip()
|
|
|
|
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2001-08-14 15:19:48 -04:00
|
|
|
def OnTestReplace(self, evt):
|
2001-11-12 22:14:05 -05:00
|
|
|
self.tc.Replace(5, 9, "IS A")
|
|
|
|
#self.tc.Remove(5, 9)
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
def OnTestWriteText(self, evt):
|
|
|
|
self.tc.WriteText("TEXT")
|
|
|
|
|
2001-11-12 22:14:05 -05:00
|
|
|
def OnTestGetSelection(self, evt):
|
|
|
|
start, end = self.tc.GetSelection()
|
|
|
|
text = self.tc.GetValue()
|
2003-12-08 20:23:28 -05:00
|
|
|
if wx.Platform == "__WXMSW__": # This is why GetStringSelection was added
|
2003-03-25 01:35:27 -05:00
|
|
|
text = text.replace('\n', '\r\n')
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2003-08-08 17:32:52 -04:00
|
|
|
self.log.write("multi-line GetSelection(): (%d, %d)\n"
|
2001-11-13 23:01:42 -05:00
|
|
|
"\tGetStringSelection(): %s\n"
|
|
|
|
"\tSelectedText: %s\n" %
|
|
|
|
(start, end,
|
|
|
|
self.tc.GetStringSelection(),
|
|
|
|
repr(text[start:end])))
|
2001-08-14 15:19:48 -04:00
|
|
|
|
2003-08-08 17:32:52 -04:00
|
|
|
start, end = self.tc1.GetSelection()
|
|
|
|
text = self.tc1.GetValue()
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
if wx.Platform == "__WXMSW__": # This is why GetStringSelection was added
|
2003-08-08 17:32:52 -04:00
|
|
|
text = text.replace('\n', '\r\n')
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2003-08-08 17:32:52 -04:00
|
|
|
self.log.write("single-line GetSelection(): (%d, %d)\n"
|
|
|
|
"\tGetStringSelection(): %s\n"
|
|
|
|
"\tSelectedText: %s\n" %
|
|
|
|
(start, end,
|
|
|
|
self.tc1.GetStringSelection(),
|
|
|
|
repr(text[start:end])))
|
|
|
|
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
def OnT5LeftDown(self, evt):
|
|
|
|
evt.Skip()
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.CallAfter(self.LogT5Position, evt)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
|
|
|
def LogT5Position(self, evt):
|
|
|
|
text = self.t5.GetValue()
|
|
|
|
ip = self.t5.GetInsertionPoint()
|
|
|
|
lp = self.t5.GetLastPosition()
|
|
|
|
self.log.write("LogT5Position:\n"
|
|
|
|
"\tGetInsertionPoint:\t%d\n"
|
|
|
|
"\ttext[insertionpoint]:\t%s\n"
|
|
|
|
"\tGetLastPosition:\t%d\n"
|
|
|
|
"\tlen(text):\t\t%d\n"
|
|
|
|
% (ip, text[ip], lp, len(text)))
|
|
|
|
|
|
|
|
|
1999-04-29 23:29:54 -04:00
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestPanel(nb, log)
|
|
|
|
return win
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
overview = """\
|
2004-01-12 22:17:17 -05:00
|
|
|
A TextCtrl allows text to be displayed and (possibly) edited. It may be single
|
2003-12-08 20:23:28 -05:00
|
|
|
line or multi-line, support styles or not, be read-only or not, and even supports
|
|
|
|
text masking for such things as passwords.
|
2002-07-11 16:41:21 -04:00
|
|
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
"""
|
2002-07-11 16:41:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
|
|
|
run.main(['', os.path.basename(sys.argv[0])])
|
|
|
|
|