diff options
author | louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13> | 2010-12-15 15:40:43 +0000 |
---|---|---|
committer | louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13> | 2010-12-15 15:40:43 +0000 |
commit | 0db8bf7d461e1d618ae7efb2f00dc2d99ddf7ca3 (patch) | |
tree | 38cf0930bb62a1b26dde8e24644694e94a73f234 /src/text_buffer.py | |
parent | 24d6894b64455ca1135a8b43ddf4ddbf94365a96 (diff) | |
download | poezio-0db8bf7d461e1d618ae7efb2f00dc2d99ddf7ca3.tar.gz poezio-0db8bf7d461e1d618ae7efb2f00dc2d99ddf7ca3.tar.bz2 poezio-0db8bf7d461e1d618ae7efb2f00dc2d99ddf7ca3.tar.xz poezio-0db8bf7d461e1d618ae7efb2f00dc2d99ddf7ca3.zip |
HUGE performance improvement on refresh. fixed #1855
Diffstat (limited to 'src/text_buffer.py')
-rw-r--r-- | src/text_buffer.py | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/text_buffer.py b/src/text_buffer.py index 43bf008f..32c6f725 100644 --- a/src/text_buffer.py +++ b/src/text_buffer.py @@ -18,10 +18,15 @@ Define the TextBuffer class """ +import logging +log = logging.getLogger(__name__) + from message import Message from datetime import datetime import theme +MESSAGE_NB_LIMIT = 16384 + class TextBuffer(object): """ This class just keep trace of messages, in a list with various @@ -29,15 +34,28 @@ class TextBuffer(object): """ def __init__(self): self.messages = [] # Message objects - self.pos = 0 + self.windows = [] # we keep track of one or more windows + # so we can pass the new messages to them, as they are added, so + # they (the windows) can built the lines from the new message + + def add_window(self, win): + self.windows.append(win) def add_message(self, txt, time=None, nickname=None, colorized=False): color = theme.COLOR_NORMAL_TEXT user = None time = time or datetime.now() - if self.pos: # avoid scrolling of one line when one line is received - self.pos += 1 - self.messages.append(Message(txt, time, nickname, user, color, colorized)) + # if self.pos: # avoid scrolling of one line when one line is received + # self.pos += 1 + msg = Message(txt, time, nickname, user, color, colorized) + self.messages.append(msg) + while len(self.messages) > MESSAGE_NB_LIMIT: + self.messages.pop(0) + for window in self.windows: # make the associated windows + # build the lines from the new message + nb = window.build_new_message(msg) + if window.pos != 0: + window.scroll_up(nb) def remove_line_separator(self): """ @@ -52,15 +70,3 @@ class TextBuffer(object): """ if None not in self.messages: self.messages.append(None) - - def scroll_up(self, dist=14): - # The pos can grow a lot over the top of the number of - # available lines, it will be fixed on the next refresh of the - # screen anyway - self.pos += dist - - def scroll_down(self, dist=14): - self.pos -= dist - if self.pos <= 0: - self.pos = 0 - |