Themes working

parent 3ed25bdf
...@@ -118,7 +118,11 @@ class Connection(threading.Thread): ...@@ -118,7 +118,11 @@ class Connection(threading.Thread):
""" """
handles the error messages 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, self.handler.emit('error-message', room=room_name,
error=stanza.getTag('error'), error=stanza.getTag('error'),
msg=stanza.getError()) msg=stanza.getError())
......
...@@ -655,6 +655,7 @@ class Gui(object): ...@@ -655,6 +655,7 @@ class Gui(object):
""" """
""" """
theme.reload_theme() theme.reload_theme()
self.resize_window()
def command_win(self, arg): def command_win(self, arg):
""" """
......
...@@ -18,13 +18,11 @@ ...@@ -18,13 +18,11 @@
import sys import sys
from os import environ, makedirs from os import environ, makedirs
import os
from datetime import datetime from datetime import datetime
from config import config from config import config
DATA_HOME = config.get('log_dir', environ.get("XDG_DATA_HOME")) DATA_HOME = config.get('log_dir', os.path.join(environ.get('XDG_DATA_HOME') or os.path.join(environ.get('HOME'), '.local', 'share'), 'poezio'))
if not DATA_HOME:
DATA_HOME = environ.get('HOME')+'/.local/share'
DATA_PATH = DATA_HOME + '/poezio/'
class Logger(object): class Logger(object):
""" """
......
...@@ -39,6 +39,13 @@ class Message(object): ...@@ -39,6 +39,13 @@ class Message(object):
def __str__(self): def __str__(self):
return self.__repr__() 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): class Line(object):
""" """
A line, corresponding to ONE row of the text area. A line, corresponding to ONE row of the text area.
......
...@@ -22,8 +22,10 @@ used when drawing the interface (mainly colors) ...@@ -22,8 +22,10 @@ used when drawing the interface (mainly colors)
""" """
import curses import curses
import inspect import shutil
import glob
import imp import imp
import os
from config import config from config import config
## Define the default colors ## Define the default colors
...@@ -64,7 +66,7 @@ COLOR_OWN_NICK = 72 ...@@ -64,7 +66,7 @@ COLOR_OWN_NICK = 72
# Status color # Status color
COLOR_STATUS_XA = 40 COLOR_STATUS_XA = 40
COLOR_STATUS_NONE = 0 COLOR_STATUS_NONE = 72
COLOR_STATUS_DND = 50 COLOR_STATUS_DND = 50
COLOR_STATUS_AWAY = 70 COLOR_STATUS_AWAY = 70
COLOR_STATUS_CHAT = 30 COLOR_STATUS_CHAT = 30
...@@ -75,6 +77,9 @@ COLOR_TOPIC_BAR = 15 ...@@ -75,6 +77,9 @@ COLOR_TOPIC_BAR = 15
COLOR_PRIVATE_ROOM_BAR = 33 COLOR_PRIVATE_ROOM_BAR = 33
COLOR_SCROLLABLE_NUMBER = 16 COLOR_SCROLLABLE_NUMBER = 16
# Chars
STATUS_CHAR = ' '
def init_colors(): def init_colors():
""" """
Initilization of all the available ncurses colors Initilization of all the available ncurses colors
...@@ -100,14 +105,25 @@ def init_colors(): ...@@ -100,14 +105,25 @@ def init_colors():
reload_theme() reload_theme()
def reload_theme(): def reload_theme():
current_module = __import__(inspect.getmodulename(__file__)) themes_dir = config.get('themes_dir',
path = config.get('theme_file', '../default.theme') 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: try:
theme = imp.load_source('theme', path) theme = imp.load_source('theme', os.path.join(themes_dir, theme_name))
except: except: # TODO warning: theme not found
return return
for var in dir(theme): for var in dir(theme):
if var.startswith('COLOR_'): if var.startswith('COLOR_') or var.startswith('STATUS_'):
globals()[var] = getattr(theme, var) globals()[var] = getattr(theme, var)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -102,7 +102,7 @@ class UserList(Win): ...@@ -102,7 +102,7 @@ class UserList(Win):
except KeyError: except KeyError:
show_col = theme.COLOR_STATUS_NONE show_col = theme.COLOR_STATUS_NONE
self.win.attron(curses.color_pair(show_col)) 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.attroff(curses.color_pair(show_col))
self.win.attron(curses.color_pair(role_col)) self.win.attron(curses.color_pair(role_col))
try: try:
...@@ -773,8 +773,8 @@ class Window(object): ...@@ -773,8 +773,8 @@ class Window(object):
self.topic_win.resize(1, self.width, 0, 0, stdscr, visible) 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.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.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.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): def refresh(self, rooms):
""" """
......
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