Advertisement
DevPlayer

test wxPython wx.TextCtrl text length limit

Sep 23rd, 2011
842
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. import wx
  2.  
  3. # Test wx.TextCtrl for preexisting textctrl.value limit.
  4. # 2011-Sep-09
  5. # used tab char not 4 spaces
  6.  
  7.  
  8. class Frame(wx.Frame):
  9.     def __init__(self, parent=None, inc=100, *args, **kwargs):
  10.         super(Frame,self).__init__(parent, *args, **kwargs)
  11.        
  12.         self.tc = wx.TextCtrl(self, style=wx.TE_MULTILINE)
  13.         #tc.Bind(wx.EVT_COMMAND_TEXT_MAXLEN, self.OnHitMax)
  14.         self.tc.Bind(wx.EVT_TEXT_MAXLEN, self.OnHitMax)
  15.         self.Bind(wx.EVT_CLOSE, self.OnClose)
  16.         self.Bind(wx.EVT_IDLE, self.OnIdle)
  17.  
  18.         self.text = '123456789 ' * inc
  19.         #self.text = '123456789 ' * 10000
  20.         self.appendMore = True
  21.  
  22.         self.Show()
  23.  
  24.     def OnHitMax(self, event):
  25.         print( 'Length: %d' % len(self.tc.GetValue()))
  26.         self.appendMore = False
  27.         event.Skip()
  28.  
  29.     def OnIdle(self, event):
  30.         print( 'Length: %d' % len(self.tc.GetValue()))
  31.         if self.appendMore:
  32.             self.tc.AppendText(self.text)
  33.  
  34.         event.Skip()
  35.  
  36.     def OnClose(self, event):
  37.         self.Destroy()
  38.  
  39.  
  40. print('\n')
  41. print('Look what happens at 30000 and 62000')
  42. print('To speed it up wiggle mouse over window.')
  43. print('Note that on Windows Xp Pro SP3 32bit idle event happens once a sec.')
  44. print("Tested on wxPython '2.8.11.0 (msw-unicode)'")
  45. print('Python 2.7 (r27:82525, Jul  4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32')
  46. print('\n')
  47.  
  48. app = wx.App(0)
  49. frame = Frame(None, 100, title='Test wx.TextCtrl maxium limit')
  50. app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement