3 """Scrolling text buffer panel for Hooke.
11 class OutputPanel (Panel, wx.TextCtrl):
12 """Scrolling text buffer panel.
14 def __init__(self, name=None, callbacks=None, buffer_lines=1000, **kwargs):
15 self._buffer_lines = buffer_lines
16 if (kwargs.get('style') & wx.TE_READONLY == 0):
17 raise NotImplementedError('%s assumes a readonly TextCtrl'
18 % self.__class__.__name__)
19 super(OutputPanel, self).__init__(
20 name='output', callbacks=callbacks, **kwargs)
22 def write(self, text):
24 self._limit_to_buffer()
26 def _limit_to_buffer(self):
27 """Limit number of lines retained in the buffer to `._buffer_lines`.
29 num_lines = self.GetNumberOfLines()
30 line_index = num_lines - self._buffer_lines
32 first_pos = 0 # character index for the first character to keep
33 for i in range(line_index):
34 first_pos += self.GetLineLength(i) + 1 # +1 for '\n'
35 self.Remove(0, first_pos)