complete refactoring of the ui. Everything is now very modulable. Little info...

complete refactoring of the ui. Everything is now very modulable. Little info win added at the bottom. Roster is ready to be implemented.
parent 29e52509
This diff is collapsed.
......@@ -47,7 +47,7 @@ class MyStdErr(object):
sys.stderr.close()
sys.stderr = self.old_stderr
my_stderr = MyStdErr(open('/dev/null', 'a'))
# my_stderr = MyStdErr(open('/dev/null', 'a'))
def exception_handler(type_, value, trace):
"""
......@@ -64,7 +64,7 @@ def exception_handler(type_, value, trace):
import os # used to quit the program even from a thread
os.abort()
sys.excepthook = exception_handler
# sys.excepthook = exception_handler
import signal
......
......@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with Poezio. If not, see <http://www.gnu.org/licenses/>.
from text_buffer import TextBuffer
from datetime import datetime
from random import randrange
from config import config
......@@ -23,36 +24,23 @@ from message import Message
import common
import theme
class Room(object):
class Room(TextBuffer):
"""
"""
number = 0
def __init__(self, name, nick, window, jid=None):
self.jid = jid # used for a private chat. None if it's a MUC
def __init__(self, name, nick):
TextBuffer.__init__(self)
self.name = name
self.own_nick = nick
self.color_state = theme.COLOR_TAB_NORMAL # color used in RoomInfo
self.nb = Room.number # number used in RoomInfo
Room.number += 1
self.joined = False # false until self presence is received
self.users = [] # User objects
self.messages = [] # Message objects
self.topic = ''
self.window = window
self.pos = 0 # offset
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
def disconnect(self):
"""
Set the state of the room as not joined, so
we can know if we can join it, send messages to it, etc
"""
self.joined = False
def log_message(self, txt, time, nickname):
......@@ -89,6 +77,19 @@ class Room(object):
break
return color
def get_user_by_name(self, nick):
for user in self.users:
if user.nick == nick:
return user
return None
def set_color_state(self, color):
"""
Set the color that will be used to display the room's
number in the RoomInfo window
"""
self.color_state = color
def add_message(self, txt, time=None, nickname=None, colorized=False):
"""
Note that user can be None even if nickname is not None. It happens
......@@ -103,10 +104,10 @@ class Room(object):
if not time and nickname and\
nickname != self.own_nick and\
self.color_state != theme.COLOR_TAB_CURRENT:
if not self.jid and self.color_state != theme.COLOR_TAB_HIGHLIGHT:
if self.color_state != theme.COLOR_TAB_HIGHLIGHT:
self.set_color_state(theme.COLOR_TAB_NEW_MESSAGE)
elif self.jid:
self.set_color_state(theme.COLOR_TAB_PRIVATE)
# elif self.jid:
# self.set_color_state(theme.COLOR_TAB_PRIVATE)
if not nickname:
color = theme.COLOR_INFORMATION_TEXT
else:
......@@ -117,30 +118,3 @@ class Room(object):
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 get_user_by_name(self, nick):
for user in self.users:
if user.nick == nick:
return user
return None
def set_color_state(self, color):
"""
Set the color that will be used to display the room's
number in the RoomInfo window
"""
self.color_state = color
This diff is collapsed.
# 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
......@@ -108,6 +108,7 @@ def init_colors():
"""
curses.start_color()
curses.use_default_colors()
curses.curs_set(0)
cpt = 0
for i in range(-1, 7):
for y in range(0, 8):
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment