From 6018d243fb09f891477caabd5ee2c9fdaed62faf Mon Sep 17 00:00:00 2001 From: "louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13" Date: Wed, 15 Sep 2010 19:05:20 +0000 Subject: fixes some crashes, and stuff --- src/gui.py | 7 ++-- src/tab.py | 64 +++++++++++++++++++++++++++++++++++ src/window.py | 105 ++++++++++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 152 insertions(+), 24 deletions(-) diff --git a/src/gui.py b/src/gui.py index 0df8be86..5f3b1323 100644 --- a/src/gui.py +++ b/src/gui.py @@ -35,8 +35,7 @@ import theme import multiuserchat as muc from handler import Handler from config import config -from tab import MucTab, InfoTab, PrivateTab -from window import Window +from tab import MucTab, InfoTab, PrivateTab, RosterInfoTab from user import User from room import Room from message import Message @@ -74,7 +73,9 @@ class Gui(object): self.stdscr = curses.initscr() self.init_curses(self.stdscr) self.xmpp = xmpp - self.tabs = [InfoTab(self.stdscr, "lol info")] + default_tab = InfoTab(self.stdscr, "Info") if self.xmpp.anon\ + else RosterInfoTab(self.stdscr, "Roster") + self.tabs = [default_tab] # a unique buffer used to store global informations # that are displayed in almost all tabs, in an # information window. diff --git a/src/tab.py b/src/tab.py index 76115a13..c26b6aee 100644 --- a/src/tab.py +++ b/src/tab.py @@ -355,3 +355,67 @@ class PrivateTab(Tab): def get_room(self): return self._room + +class RosterInfoTab(Tab): + """ + A tab, splitted in two, containg the roster and infos + """ + def __init__(self, stdscr, roster): + Tab.__init__(self, stdscr) + self.name = "Roster" + self.roster = roster + roster_width = self.width//2 + info_width = self.width-roster_width-1 + self.v_separator = window.VerticalSeparator(self.height-2, 1, 0, roster_width, stdscr, self.visible) + self.tab_win = window.GlobalInfoBar(1, self.width, self.height-2, 0, stdscr, self.visible) + self.info_win = window.TextWin(self.height-2, info_width, 0, roster_width+1, stdscr, self.visible) + self.roster_win = window.RosterWin(self.height-2, roster_width, 0, 0, stdscr, self.visible) + self.input = window.Input(1, self.width, self.height-1, 0, stdscr, self.visible) + self.set_color_state(theme.COLOR_TAB_NORMAL) + + def resize(self, stdscr): + Tab.resize(self, stdscr) + roster_width = self.width//2 + info_width = self.width-roster_width-1 + self.v_separator.resize(self.height-2, 1, 0, roster_width, stdscr, self.visible) + self.tab_win.resize(1, self.width, self.height-2, 0, stdscr, self.visible) + self.info_win.resize(self.height-2, info_width, 0, roster_width+1, stdscr, self.visible) + self.roster_win.resize(self.height-2, roster_width, 0, 0, stdscr, self.visible) + self.input.resize(1, self.width, self.height-1, 0, stdscr, self.visible) + + def refresh(self, tabs, informations): + self.v_separator.refresh() + self.roster_win.refresh(self.roster) + self.info_win.refresh(informations) + self.tab_win.refresh(tabs, tabs[0]) + self.input.refresh() + + def get_name(self): + return self.name + + def get_color_state(self): + return self._color_state + + def set_color_state(self, color): + self._color_state = color + + def on_input(self, key): + return self.input.do_command(key) + + def on_lose_focus(self): + self._color_state = theme.COLOR_TAB_NORMAL + + def on_gain_focus(self): + self._color_state = theme.COLOR_TAB_CURRENT + + def add_message(self): + return False + + def on_scroll_down(self): + debug('TODO DOWN') + + def on_scroll_up(self): + debug('TODO UP') + + def on_info_win_size_changed(self): + return diff --git a/src/window.py b/src/window.py index 342e4156..5671de44 100644 --- a/src/window.py +++ b/src/window.py @@ -39,7 +39,7 @@ class Win(object): def _resize(self, height, width, y, x, parent_win): self.height, self.width, self.x, self.y = height, width, x, y try: - self.win = parent_win.subwin(height, width, y, x) + self.win = curses.newwin(height, width, y, x) except: from common import debug debug('%s %s %s %s %s\n' % (height, width, y, x, parent_win)) @@ -312,14 +312,8 @@ class TextWin(Win): on each change. (thanks weechat :o) """ def __init__(self, height, width, y, x, parent_win, visible): - self.visible = visible - self.height = height - self.width = width - self.y = y - self.x = x - self.parent_win = parent_win Win.__init__(self, height, width, y, x, parent_win) - self.win.scrollok(1) + self.visible = visible def build_lines_from_messages(self, messages): """ @@ -445,7 +439,7 @@ class TextWin(Win): try: splitted = shlex.split(txt) except ValueError: - txt += '"' + txt = txt.replace('"', '') splitted = shlex.split(txt) for word in splitted: if word in list(special_words.keys()): @@ -882,20 +876,21 @@ class Input(Win): def clear_text(self): self.win.erase() -class Window(object): - """ - The whole "screen" that can be seen at once in the terminal. - It contains an userlist, an input zone, a topic zone and a chat zone - """ +# class RosterWin(Win): +# def __init__(self, height, width, y, x, parent_win, visible): +# Win.__init__(self, height, width, y, x, parent_win) +# self.visible = visible +# def resize(self, height, width, y, x, stdscr, visible): +# self._resize(height, width, y, x, stdscr) +# self.visible = visible - # TODO JidWindow - # elif jid: - # room = jid.split('/')[0] - # nick = '/'.join(jid.split('/')[1:]) - # topic = _('%(nick)s from room %(room)s' % {'nick': nick, 'room':room}) - # self.addnstr(0, 0, topic + " "*(self.width-len(topic)), self.width-1 - # , curses.color_pair(theme.COLOR_PRIVATE_ROOM_BAR)) +# def refresh(self, roster): +# g_lock.acquire() +# self.win.erase() +# self.addnstr('teub', 4) +# self.win.refresh() +# g_lock.release() class VerticalSeparator(Win): """ @@ -922,3 +917,71 @@ class VerticalSeparator(Win): if not self.visible: return self.rewrite_line() + +class RosterWin(Win): + """ + """ + def __init__(self, height, width, y, x, parent_win, visible): + self.visible = visible + Win.__init__(self, height, width, y, x, parent_win) + self.pos = 0 # position in the contact list + + def resize(self, height, width, y, x, stdscr, visible): + self._resize(height, width, y, x, stdscr) + + def refresh(self, roster=None): + """ + We get the roster object + """ + if not self.visible or not roster: + return + g_lock.acquire() + self.win.erase() + # TODO, two ways of scrolling + # currently: always centered + if self.pos > self.height//2 and\ + self.pos + self.height//2 < len(roster.getContacts()): + # We are centered + begin = True + end = True + pos = self.height//2 + contacts = roster.getContacts()[self.pos-pos:self.pos+pos+1] + elif self.pos <= self.height//2: + # we are at the beginning of the list + pos = self.pos + contacts = roster.getContacts()[:self.height] + begin = False + if self.height < len(roster.getContacts()): + end = True + else: + end = False + else: + # we are at the end of the list + pos = self.height - (len(roster.getContacts()) - self.pos) + contacts = roster.getContacts()[-self.height:] + begin = True + end = False + cpt = 0 # ipair ou chais plus quoi + for contact in contacts: + if cpt == pos: + self.draw_contact_line(contact, cpt, 0, 3) + else: + self.draw_contact_line(contact, cpt, 0) + cpt += 1 + if end: + self.win.addstr(self.height-1, 0, '++++') + if begin: + self.win.addstr(0, 0, '++++') + self.win.refresh() + g_lock.release() + + def draw_contact_line(self, contact, x, y, color=None): + """ + Draw on a line all informations about one contact + Use 'color' to draw the jid/display_name to show what is + is currently selected contact in the list + """ + if color: + self.win.addstr(x, y, contact.getJid().full, curses.color_pair(color)) + else: + self.win.addstr(x, y, contact.getJid().full) -- cgit v1.2.3