2011-09-06 00:45:53 +00:00
|
|
|
# Copyright 2010-2011 Florent Le Coz <louiz@louiz.org>
|
2010-08-20 20:55:42 +00:00
|
|
|
#
|
|
|
|
# This file is part of Poezio.
|
|
|
|
#
|
|
|
|
# Poezio is free software: you can redistribute it and/or modify
|
2011-09-06 00:45:53 +00:00
|
|
|
# it under the terms of the MIT license. See the COPYING file.
|
2010-08-20 20:55:42 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
Define the variables (colors and some other stuff) that are
|
|
|
|
used when drawing the interface (mainly colors)
|
|
|
|
"""
|
|
|
|
|
|
|
|
import curses
|
2010-08-22 14:57:47 +00:00
|
|
|
import glob
|
2010-08-20 20:55:42 +00:00
|
|
|
import imp
|
2010-08-22 14:57:47 +00:00
|
|
|
import os
|
2010-08-20 20:55:42 +00:00
|
|
|
from config import config
|
|
|
|
|
2011-01-12 19:09:48 +00:00
|
|
|
import logging
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2010-08-20 20:55:42 +00:00
|
|
|
## Define the default colors
|
|
|
|
## Do not change these colors, create a theme file instead.
|
|
|
|
|
|
|
|
# Message text color
|
|
|
|
COLOR_NORMAL_TEXT = 0
|
2010-09-11 02:12:52 +00:00
|
|
|
COLOR_INFORMATION_TEXT = 5
|
2011-03-29 14:48:25 +00:00
|
|
|
COLOR_HIGHLIGHT_NICK = -46
|
2010-08-20 20:55:42 +00:00
|
|
|
|
|
|
|
# User list color
|
2010-09-11 02:12:52 +00:00
|
|
|
COLOR_USER_VISITOR = 7
|
|
|
|
COLOR_USER_PARTICIPANT = 4
|
|
|
|
COLOR_USER_NONE = 0
|
|
|
|
COLOR_USER_MODERATOR = 1
|
2010-08-20 20:55:42 +00:00
|
|
|
|
2010-12-31 10:52:15 +00:00
|
|
|
# nickname colors
|
2010-12-31 11:23:56 +00:00
|
|
|
COLOR_REMOTE_USER = 5
|
2010-12-31 10:52:15 +00:00
|
|
|
|
2010-08-22 16:33:57 +00:00
|
|
|
# The character printed in color (COLOR_STATUS_*) before the nickname
|
|
|
|
# in the user list
|
|
|
|
CHAR_STATUS = ' '
|
|
|
|
|
2010-08-20 20:55:42 +00:00
|
|
|
# Separators
|
2010-09-11 02:12:52 +00:00
|
|
|
COLOR_VERTICAL_SEPARATOR = 4
|
|
|
|
COLOR_NEW_TEXT_SEPARATOR = 2
|
2011-01-12 19:09:48 +00:00
|
|
|
COLOR_MORE_INDICATOR = 6
|
2010-08-20 20:55:42 +00:00
|
|
|
|
|
|
|
# Time
|
2010-09-11 02:12:52 +00:00
|
|
|
COLOR_TIME_SEPARATOR = 6
|
2010-09-11 01:50:18 +00:00
|
|
|
COLOR_TIME_LIMITER = 0
|
|
|
|
CHAR_TIME_LEFT = ''
|
|
|
|
CHAR_TIME_RIGHT = ''
|
2010-08-20 20:55:42 +00:00
|
|
|
COLOR_TIME_NUMBERS = 0
|
|
|
|
|
|
|
|
# Tabs
|
2010-09-11 02:12:52 +00:00
|
|
|
COLOR_TAB_NORMAL = 42
|
|
|
|
COLOR_TAB_CURRENT = 56
|
|
|
|
COLOR_TAB_NEW_MESSAGE = 49
|
|
|
|
COLOR_TAB_HIGHLIGHT = 21
|
|
|
|
COLOR_TAB_PRIVATE = 28
|
2010-08-20 20:55:42 +00:00
|
|
|
|
|
|
|
# Nickname colors
|
|
|
|
LIST_COLOR_NICKNAMES = [
|
2011-02-13 21:26:05 +00:00
|
|
|
1, 2, 3, 4, 5, 6, -2, -4, -5, -6
|
2010-08-20 20:55:42 +00:00
|
|
|
]
|
2010-09-11 02:12:52 +00:00
|
|
|
COLOR_OWN_NICK = 7
|
2010-08-20 20:55:42 +00:00
|
|
|
|
|
|
|
# Status color
|
2010-09-11 02:12:52 +00:00
|
|
|
COLOR_STATUS_XA = 49
|
2010-09-11 01:50:18 +00:00
|
|
|
COLOR_STATUS_NONE = 0
|
2010-09-11 02:12:52 +00:00
|
|
|
COLOR_STATUS_DND = 21
|
|
|
|
COLOR_STATUS_AWAY = 35
|
|
|
|
COLOR_STATUS_CHAT = 28
|
2010-09-26 18:01:38 +00:00
|
|
|
COLOR_STATUS_UNAVAILABLE = 57
|
|
|
|
COLOR_STATUS_ONLINE = 41
|
2011-01-12 19:09:48 +00:00
|
|
|
|
2010-08-20 20:55:42 +00:00
|
|
|
# Bars
|
2010-09-11 02:12:52 +00:00
|
|
|
COLOR_INFORMATION_BAR = 42
|
|
|
|
COLOR_TOPIC_BAR = 42
|
|
|
|
COLOR_PRIVATE_ROOM_BAR = 28
|
2011-02-13 21:26:05 +00:00
|
|
|
COLOR_SCROLLABLE_NUMBER = -39
|
2011-01-12 19:09:48 +00:00
|
|
|
COLOR_SELECTED_ROW = 42
|
|
|
|
COLOR_PRIVATE_NAME = 42
|
|
|
|
COLOR_CONVERSATION_NAME = 42
|
|
|
|
COLOR_GROUPCHAT_NAME = 42
|
|
|
|
COLOR_COLUMN_HEADER = 36
|
2010-08-20 20:55:42 +00:00
|
|
|
|
2010-08-22 16:33:57 +00:00
|
|
|
# Strings for special messages (like join, quit, nick change, etc)
|
|
|
|
# Special messages
|
|
|
|
CHAR_JOIN = '---->'
|
|
|
|
CHAR_QUIT = '<----'
|
|
|
|
CHAR_KICK = '-!-'
|
|
|
|
|
2010-09-11 02:12:52 +00:00
|
|
|
COLOR_JOIN_CHAR = 4
|
|
|
|
COLOR_QUIT_CHAR = 1
|
|
|
|
COLOR_KICK_CHAR = 1
|
2010-08-22 16:33:57 +00:00
|
|
|
|
|
|
|
# words between ()
|
2010-09-11 02:12:52 +00:00
|
|
|
COLOR_CURLYBRACKETED_WORD = 4
|
2010-08-22 16:33:57 +00:00
|
|
|
# words between {}
|
2010-09-11 02:12:52 +00:00
|
|
|
COLOR_ACCOLADE_WORD = 6
|
2010-08-22 16:33:57 +00:00
|
|
|
# words between []
|
2010-09-11 02:12:52 +00:00
|
|
|
COLOR_BRACKETED_WORD = 3
|
2010-08-22 14:57:47 +00:00
|
|
|
|
2010-08-20 20:55:42 +00:00
|
|
|
def init_colors():
|
|
|
|
"""
|
|
|
|
Initilization of all the available ncurses colors
|
2010-09-11 01:50:18 +00:00
|
|
|
limit the number of colors to 64 (because some terminals
|
|
|
|
don't handle more than that), by removing some useless colors
|
|
|
|
like 'black on black', etc.
|
2010-08-20 20:55:42 +00:00
|
|
|
"""
|
|
|
|
curses.start_color()
|
|
|
|
curses.use_default_colors()
|
2010-09-11 02:12:52 +00:00
|
|
|
cpt = 0
|
2010-09-11 01:50:18 +00:00
|
|
|
for i in range(-1, 7):
|
|
|
|
for y in range(0, 8):
|
|
|
|
if y == i:
|
|
|
|
continue
|
2010-08-20 20:55:42 +00:00
|
|
|
curses.init_pair(cpt, y, i)
|
|
|
|
cpt += 1
|
2010-09-11 01:50:18 +00:00
|
|
|
for y in range(0, 7):
|
|
|
|
# init the default fg on others bg at last
|
|
|
|
curses.init_pair(cpt, -1, y)
|
|
|
|
cpt += 1
|
|
|
|
# Have the default color be default fg on default bg
|
2010-08-20 20:55:42 +00:00
|
|
|
reload_theme()
|
|
|
|
|
|
|
|
def reload_theme():
|
2010-09-07 23:59:35 +00:00
|
|
|
themes_dir = config.get('themes_dir', '')
|
|
|
|
themes_dir = themes_dir or\
|
|
|
|
os.path.join(os.environ.get('XDG_DATA_HOME') or\
|
|
|
|
os.path.join(os.environ.get('HOME'), '.local', 'share'),
|
|
|
|
'poezio', 'themes')
|
2010-08-22 14:57:47 +00:00
|
|
|
try:
|
|
|
|
os.makedirs(themes_dir)
|
|
|
|
except OSError:
|
|
|
|
pass
|
2011-01-12 19:09:48 +00:00
|
|
|
theme_name = config.get('theme', '')
|
2010-08-22 14:57:47 +00:00
|
|
|
if not theme_name:
|
|
|
|
return
|
2010-08-20 20:55:42 +00:00
|
|
|
try:
|
2010-08-22 14:57:47 +00:00
|
|
|
theme = imp.load_source('theme', os.path.join(themes_dir, theme_name))
|
|
|
|
except: # TODO warning: theme not found
|
2010-08-20 20:55:42 +00:00
|
|
|
return
|
|
|
|
for var in dir(theme):
|
2010-09-11 01:50:18 +00:00
|
|
|
if var.startswith('COLOR_') or var.startswith('CHAR_') or var.startswith('LIST_'):
|
2010-08-20 20:55:42 +00:00
|
|
|
globals()[var] = getattr(theme, var)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
"""
|
|
|
|
Launch 'python theme.py' to see the list of all the available colors
|
|
|
|
in your terminal
|
|
|
|
"""
|
|
|
|
s = curses.initscr()
|
|
|
|
curses.start_color()
|
|
|
|
curses.use_default_colors()
|
2010-10-04 00:27:40 +00:00
|
|
|
init_colors()
|
|
|
|
for i in range(64):
|
|
|
|
s.attron(curses.color_pair(i) | curses.A_BOLD)
|
|
|
|
s.addstr(str(curses.color_pair(i) | curses.A_BOLD))
|
|
|
|
s.attroff(curses.color_pair(i) | curses.A_BOLD)
|
|
|
|
s.addstr(' ')
|
|
|
|
s.addstr('\n')
|
|
|
|
for i in range(64):
|
2010-08-20 20:55:42 +00:00
|
|
|
s.attron(curses.color_pair(i))
|
|
|
|
s.addstr(str(i))
|
|
|
|
s.attroff(curses.color_pair(i))
|
|
|
|
s.addstr(' ')
|
2010-10-04 00:27:40 +00:00
|
|
|
|
2010-08-20 20:55:42 +00:00
|
|
|
s.refresh()
|
|
|
|
s.getch()
|
|
|
|
s.endwin()
|