summaryrefslogtreecommitdiff
path: root/src/text_buffer.py
diff options
context:
space:
mode:
authorlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-09-14 02:11:07 +0000
committerlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-09-14 02:11:07 +0000
commit33f197b4ab8f65e33c30b789fb34157b70f1105d (patch)
tree161def6a9dc7f943c2677bbe68b86c631b2f10bc /src/text_buffer.py
parent29e5250904bacbabb49388fee0811aa4cdcb6708 (diff)
downloadpoezio-33f197b4ab8f65e33c30b789fb34157b70f1105d.tar.gz
poezio-33f197b4ab8f65e33c30b789fb34157b70f1105d.tar.bz2
poezio-33f197b4ab8f65e33c30b789fb34157b70f1105d.tar.xz
poezio-33f197b4ab8f65e33c30b789fb34157b70f1105d.zip
complete refactoring of the ui. Everything is now very modulable. Little info win added at the bottom. Roster is ready to be implemented.
Diffstat (limited to 'src/text_buffer.py')
-rw-r--r--src/text_buffer.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/text_buffer.py b/src/text_buffer.py
new file mode 100644
index 00000000..ad002892
--- /dev/null
+++ b/src/text_buffer.py
@@ -0,0 +1,62 @@
+# Copyright 2010 Le Coz Florent <louizatakk@fedoraproject.org>
+#
+# This file is part of Poezio.
+#
+# Poezio is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, version 3 of the License.
+#
+# Poezio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Poezio. If not, see <http://www.gnu.org/licenses/>.
+
+from message import Message
+from datetime import datetime
+import theme
+
+class TextBuffer(object):
+ """
+ This class just keep trace of messages, in a list with various
+ informations and attributes.
+ """
+ def __init__(self):
+ self.messages = [] # Message objects
+ self.pos = 0
+
+ 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))
+
+ def remove_line_separator(self):
+ """
+ Remove the line separator
+ """
+ if None in self.messages:
+ self.messages.remove(None)
+
+ def add_line_separator(self):
+ """
+ add a line separator at the end of messages list
+ """
+ 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
+