From aab22c794397a29d3a865c073702879a1e5a4645 Mon Sep 17 00:00:00 2001 From: "louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13" Date: Sun, 22 Aug 2010 14:57:47 +0000 Subject: Themes working --- src/connection.py | 6 +++++- src/gui.py | 1 + src/logging.py | 6 ++---- src/message.py | 7 +++++++ src/theme.py | 30 +++++++++++++++++++++++------- src/window.py | 4 ++-- 6 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/connection.py b/src/connection.py index 0ac8be6a..83631da0 100644 --- a/src/connection.py +++ b/src/connection.py @@ -118,7 +118,11 @@ class Connection(threading.Thread): """ handles the error messages """ - room_name = stanza.getFrom().getStripped() + from_ = stanza.getFrom() + if not from_: + room_name = '' + else: + room_name = from_.getStripped() self.handler.emit('error-message', room=room_name, error=stanza.getTag('error'), msg=stanza.getError()) diff --git a/src/gui.py b/src/gui.py index e59a97b0..1c6332b5 100644 --- a/src/gui.py +++ b/src/gui.py @@ -655,6 +655,7 @@ class Gui(object): """ """ theme.reload_theme() + self.resize_window() def command_win(self, arg): """ diff --git a/src/logging.py b/src/logging.py index f94ac466..c7414b17 100644 --- a/src/logging.py +++ b/src/logging.py @@ -18,13 +18,11 @@ import sys from os import environ, makedirs +import os from datetime import datetime from config import config -DATA_HOME = config.get('log_dir', environ.get("XDG_DATA_HOME")) -if not DATA_HOME: - DATA_HOME = environ.get('HOME')+'/.local/share' -DATA_PATH = DATA_HOME + '/poezio/' +DATA_HOME = config.get('log_dir', os.path.join(environ.get('XDG_DATA_HOME') or os.path.join(environ.get('HOME'), '.local', 'share'), 'poezio')) class Logger(object): """ diff --git a/src/message.py b/src/message.py index c5d3d47e..180981ea 100644 --- a/src/message.py +++ b/src/message.py @@ -39,6 +39,13 @@ class Message(object): def __str__(self): return self.__repr__() +class SeparatorLine(Message): + """ + Just a separator between read and not-yet-read messages + """ + def __init__(self): + Message.__init__(self, '') + class Line(object): """ A line, corresponding to ONE row of the text area. diff --git a/src/theme.py b/src/theme.py index 1748e4a3..58a51717 100644 --- a/src/theme.py +++ b/src/theme.py @@ -22,8 +22,10 @@ used when drawing the interface (mainly colors) """ import curses -import inspect +import shutil +import glob import imp +import os from config import config ## Define the default colors @@ -64,7 +66,7 @@ COLOR_OWN_NICK = 72 # Status color COLOR_STATUS_XA = 40 -COLOR_STATUS_NONE = 0 +COLOR_STATUS_NONE = 72 COLOR_STATUS_DND = 50 COLOR_STATUS_AWAY = 70 COLOR_STATUS_CHAT = 30 @@ -75,6 +77,9 @@ COLOR_TOPIC_BAR = 15 COLOR_PRIVATE_ROOM_BAR = 33 COLOR_SCROLLABLE_NUMBER = 16 +# Chars +STATUS_CHAR = ' ' + def init_colors(): """ Initilization of all the available ncurses colors @@ -100,14 +105,25 @@ def init_colors(): reload_theme() def reload_theme(): - current_module = __import__(inspect.getmodulename(__file__)) - path = config.get('theme_file', '../default.theme') + themes_dir = config.get('themes_dir', + os.path.join(os.environ.get('XDG_DATA_HOME') or os.path.join(os.environ.get('HOME'), '.local', 'share'), 'poezio', 'themes')) + try: + os.makedirs(themes_dir) + # if the directory didn't exist, copy the default themes + themes = glob.glob('../data/themes/*') + for filename in themes: + shutil.copy2(filename, themes_dir) + except OSError: + pass + theme_name = config.get('theme_file', '') + if not theme_name: + return try: - theme = imp.load_source('theme', path) - except: + theme = imp.load_source('theme', os.path.join(themes_dir, theme_name)) + except: # TODO warning: theme not found return for var in dir(theme): - if var.startswith('COLOR_'): + if var.startswith('COLOR_') or var.startswith('STATUS_'): globals()[var] = getattr(theme, var) if __name__ == '__main__': diff --git a/src/window.py b/src/window.py index 584f2f8b..dcbb14ab 100644 --- a/src/window.py +++ b/src/window.py @@ -102,7 +102,7 @@ class UserList(Win): except KeyError: show_col = theme.COLOR_STATUS_NONE self.win.attron(curses.color_pair(show_col)) - self.win.addnstr(y, 0, " ", 1) + self.win.addnstr(y, 0, theme.STATUS_CHAR, 1) self.win.attroff(curses.color_pair(show_col)) self.win.attron(curses.color_pair(role_col)) try: @@ -773,8 +773,8 @@ class Window(object): self.topic_win.resize(1, self.width, 0, 0, stdscr, visible) self.info_win.resize(1, self.width, self.height-2, 0, stdscr, visible) self.text_win.resize(self.height-3, text_width, 1, 0, stdscr, visible) - self.input.resize(1, self.width, self.height-1, 0, stdscr, visible) self.user_win.resize(self.height-3, self.width-text_width-1, 1, text_width+1, stdscr, visible) + self.input.resize(1, self.width, self.height-1, 0, stdscr, visible) def refresh(self, rooms): """ -- cgit v1.2.3