summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-06-12 14:14:52 +0000
committerlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-06-12 14:14:52 +0000
commit0ca75a346af06bdf6a2d5c6d0d9731240c04898e (patch)
tree7b2a595470652e90af38ee73c7b5bedcfeb71d68
parentad8d892aa1608dc76e3e29de70911953169b91d3 (diff)
downloadpoezio-0ca75a346af06bdf6a2d5c6d0d9731240c04898e.tar.gz
poezio-0ca75a346af06bdf6a2d5c6d0d9731240c04898e.tar.bz2
poezio-0ca75a346af06bdf6a2d5c6d0d9731240c04898e.tar.xz
poezio-0ca75a346af06bdf6a2d5c6d0d9731240c04898e.zip
add missing file
-rw-r--r--README3
-rw-r--r--src/gui.py2
-rw-r--r--src/message.py43
-rw-r--r--src/window.py102
4 files changed, 114 insertions, 36 deletions
diff --git a/README b/README
index 72326299..3a88c315 100644
--- a/README
+++ b/README
@@ -42,6 +42,9 @@ http://codingteam.net/project/poezio/doc
Please DO report any bug you encounter and ask for any
feature you want.
+If you are testing poezio, and get a crash but no error, please
+take a look in the src/errors file.
+
=======================
Authors
=======================
diff --git a/src/gui.py b/src/gui.py
index 12e31a9a..17625503 100644
--- a/src/gui.py
+++ b/src/gui.py
@@ -263,7 +263,7 @@ Avail: Sets your availability to available and (optional) sets your status
def on_connected(self, jid):
"""
- When we are connected authentification confirmation is received
+ We are connected when authentification confirmation is received
"""
self.information(_("Welcome on Poezio \o/!"))
self.information(_("Your JID is %s") % jid)
diff --git a/src/message.py b/src/message.py
new file mode 100644
index 00000000..7bbb1893
--- /dev/null
+++ b/src/message.py
@@ -0,0 +1,43 @@
+#!/usr/bin/python
+# -*- coding:utf-8 -*-
+#
+# 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 common import debug
+from datetime import datetime
+
+class Message(object):
+ """
+ A message with all the associated data (nickname, time, color, etc)
+ """
+ def __init__(self, txt, time=None, nickname=None, user=None, color=None):
+ """
+ time is a datetime object, None means 'now'.
+ If no nickname is specified, it's an information.
+ user is an User object (used for the color, etc)
+ """
+ self.txt = txt
+ self.nickname = nickname
+ self.time = time
+ self.user = user
+ self.color = color
+
+ def __repr__(self):
+ return "<Message txt=%s, nickname=%s, time=%s, user=%s>" % (self.txt, self.nickname, str(self.time), str(self.user))
+ def __str__(self):
+ return self.__repr__()
+
diff --git a/src/window.py b/src/window.py
index bc41f74d..8d94941b 100644
--- a/src/window.py
+++ b/src/window.py
@@ -31,18 +31,17 @@ class Win(object):
try:
self.win = parent_win.subwin(height, width, y, x)
except:
- # Happens when the C function subwin fails. The man
- # doesn't give a reason for this to happen, so I can't
- # really fix this.
- # just don't crash when this happens.
+ # When resizing in a too little height (less than 3 lines)
+ # We don't need to resize the window, since this size
+ # just makes no sense
+ # Just don't crash when this happens.
# (°> also, a penguin
# //\
# V_/_
- print parent_win, parent_win.height, parent_win.width, height, width, y, x
- raise
+ pass
self.win.idlok(1)
self.win.leaveok(1)
- self.win.syncok(0)
+ # self.win.syncok(0)
def refresh(self):
self.win.noutrefresh()
@@ -175,6 +174,22 @@ class TextWin(Win):
self.x = x
self.parent_win = parent_win
Win.__init__(self, height, width, y, x, parent_win)
+ self.win.scrollok(1)
+
+ def keep_n_lines(self, messages):
+ """
+ Keep just self.win.height lines, no more.
+ So, remove one top line for each "\n" found in the messages
+ """
+ messages = messages[::-1]
+ for m in messages:
+ nb = m.txt.count('\n')
+ # remove the nb top lines
+ for _ in xrange(nb):
+ messages.pop(len(messages)-1) # remove the last one
+ debug(str(nb)+' backslash')
+ debug(str(len(messages)))
+ return messages[::-1]
def refresh(self, room):
"""
@@ -182,29 +197,41 @@ class TextWin(Win):
# TODO: keep a position in the room, and display
# the messages from this position (can be used to scroll)
from common import debug
- y = 0
+ # y = 0
+ debug("je suis VISIBLE:%s" % self.visible)
+ if not self.visible:
+ return
self.win.erase()
+ self.win.move(0, 0)
if room.pos != 0:
messages = room.messages[-self.height - room.pos : -room.pos]
else:
messages = room.messages[-self.height:]
+ # lines = self.keep_n_lines(messages)
+ first = True
for message in messages:
# debug(str(message))
- self.write_time(y, message.time)
+ if first:
+ first = False
+ else:
+ self.win.addch('\n')
+ self.write_time(message.time)
if message.nickname is not None:
- x = self.write_nickname(y, message.nickname.encode('utf-8'), message.user)
+ # x =
+ self.write_nickname(message.nickname.encode('utf-8'), message.user)
else:
- x = 11
+ # x = 11
self.win.attron(curses.color_pair(8))
- y += self.write_text(y, x, message.txt, message.color)
+ # y +=
+ self.write_text(message.txt, message.color)
if message.nickname is None:
self.win.attroff(curses.color_pair(8))
# self.win.addnstr(y, x, message.txt, 40)
# self.win
- y += 1
+ # y += 1
self.win.refresh()
- def write_text(self, y, x, txt, color):
+ def write_text(self, txt, color):
"""
return the number of line written, -1
"""
@@ -212,48 +239,53 @@ class TextWin(Win):
l = 0
if color:
self.win.attron(curses.color_pair(color))
- while txt != '':
- debug(txt)
- if txt[:self.width-x].find('\n') != -1:
- limit = txt[:self.width-x].find('\n')
- debug("=================="+str(limit))
- else:
- limit = self.width-x
- self.win.addnstr(y+l, x, txt, limit)
- txt = txt[limit+1:]
- l += 1
+ self.win.addstr(txt)
+ # while txt != '':
+ # # debug(txt)
+ # if txt[:self.width-x].find('\n') != -1:
+ # limit = txt[:self.width-x].find('\n')
+ # # debug("=================="+str(limit))
+ # else:
+ # limit = self.width-x
+ # self.win.addnstr(txt, limit)
+ # txt = txt[limit+1:]
+ # l += 1
if color:
self.win.attroff(curses.color_pair(color))
- return l-1
+ # return l-1
- def write_nickname(self, y, nickname, user):
+ def write_nickname(self, nickname, user):
"""
Write the nickname, using the user's color
and return the number of written characters
"""
if user:
self.win.attron(curses.color_pair(user.color))
- self.win.addstr(y, 11, nickname)
+ self.win.addstr(nickname)
if user:
self.win.attroff(curses.color_pair(user.color))
- self.win.addnstr(y, 11+len(nickname.decode('utf-8')), "> ", 2)
- return len(nickname.decode('utf-8')) + 13
+ self.win.addnstr("> ", 2)
+ # return len(nickname.decode('utf-8')) + 13
- def write_time(self, y, time):
+ def write_time(self, time):
"""
Write the date on the yth line of the window
"""
- self.win.addnstr(y, 0, '['+time.strftime("%H"), 3)
+ # debug(str(self.win.getmaxyx()))
+ # debug(str(y))
+ # debug('___________________')
+ self.win.addnstr('['+time.strftime("%H"), 3)
self.win.attron(curses.color_pair(9))
- self.win.addnstr(y, 3, ':', 1)
+ self.win.addnstr(':', 1)
self.win.attroff(curses.color_pair(9))
- self.win.addstr(y, 4, time.strftime('%M'), 2)
+ self.win.addnstr(time.strftime('%M'), 2)
self.win.attron(curses.color_pair(9))
- self.win.addstr(y, 6, ':', 1)
+ self.win.addnstr(':', 1)
self.win.attroff(curses.color_pair(9))
- self.win.addstr(y, 7, time.strftime('%S') + "] ", 3)
+ self.win.addnstr(time.strftime('%S') + "] ", 3)
def resize(self, height, width, y, x, stdscr, visible):
+ self.visible = visible
self._resize(height, width, y, x, stdscr)
# def redraw(self, room):