diff options
-rw-r--r-- | data/themes/dark | 81 | ||||
-rw-r--r-- | data/themes/dark.py | 35 | ||||
-rw-r--r-- | data/themes/poezio | 83 | ||||
-rw-r--r-- | src/core.py | 7 | ||||
-rw-r--r-- | src/tabs.py | 53 | ||||
-rw-r--r-- | src/theming.py | 71 |
6 files changed, 116 insertions, 214 deletions
diff --git a/data/themes/dark b/data/themes/dark deleted file mode 100644 index 77093577..00000000 --- a/data/themes/dark +++ /dev/null @@ -1,81 +0,0 @@ -# A dark theme file. -# For more informations, see http://dev.louiz.org/project/poezio/doc/TheThemes - -# Message text color -COLOR_NORMAL_TEXT = 0 -COLOR_INFORMATION_TEXT = 5 -COLOR_HIGHLIGHT_NICK = 10 - -# User list color -COLOR_USER_VISITOR = 7 -COLOR_USER_PARTICIPANT = 4 -COLOR_USER_NONE = 0 -COLOR_USER_MODERATOR = 1 - -# The character printed in color (COLOR_STATUS_*) before the nickname -# in the user list -CHAR_STATUS = '|' - -# Separators -COLOR_VERTICAL_SEPARATOR = 0 -COLOR_NEW_TEXT_SEPARATOR = 2 -COLOR_MORE_INDICATOR = 3 - -# Time -COLOR_TIME_SEPARATOR = 6 -COLOR_TIME_LIMITER = 0 -CHAR_TIME_LEFT = '' -CHAR_TIME_RIGHT = '' -COLOR_TIME_NUMBERS = 0 - -# Tabs -COLOR_TAB_NORMAL = 57 -COLOR_TAB_CURRENT = 7 -COLOR_TAB_NEW_MESSAGE = 10 -COLOR_TAB_HIGHLIGHT = 8 -COLOR_TAB_PRIVATE = 9 -COLOR_TAB_DISCONNECTED = 30 - -# Nickname colors -LIST_COLOR_NICKNAMES = [ - 1, 2, 3, 4, 5, 6, -2, -4, -5, -6 - ] -COLOR_OWN_NICK = 7 - -# Status color -COLOR_STATUS_XA = 5 -COLOR_STATUS_NONE = 4 -COLOR_STATUS_DND = 1 -COLOR_STATUS_AWAY = 3 -COLOR_STATUS_CHAT = 2 -COLOR_STATUS_UNAVAILABLE = 57 -COLOR_STATUS_ONLINE = 41 - -# Bars -COLOR_INFORMATION_BAR = 57 -COLOR_TOPIC_BAR = 14 -COLOR_PRIVATE_ROOM_BAR = 9 -COLOR_SCROLLABLE_NUMBER = 10 -COLOR_SELECTED_ROW = 14 -COLOR_PRIVATE_NAME = 13 -COLOR_CONVERSATION_NAME = 10 -COLOR_GROUPCHAT_NAME = 13 -COLOR_COLUMN_HEADER = 13 - -# Strings for special messages (like join, quit, nick change, etc) - -# Special messages -CHAR_JOIN = '---->' -CHAR_QUIT = '<----' -CHAR_KICK = '-!-' - -COLOR_JOIN_CHAR = 4 -COLOR_QUIT_CHAR = 1 -COLOR_KICK_CHAR = 1 - -# words between () -COLOR_CURLYBRACKETED_WORD = 4 -# words between {} -COLOR_ACCOLADE_WORD = 6 -# words between [] -COLOR_BRACKETED_WORD = 3 diff --git a/data/themes/dark.py b/data/themes/dark.py new file mode 100644 index 00000000..bbe226f8 --- /dev/null +++ b/data/themes/dark.py @@ -0,0 +1,35 @@ +import theming + +class DarkTheme(theming.Theme): + COLOR_INFORMATION_BAR = (-1, 236) + COLOR_STATUS_XA = (53, -1) + COLOR_STATUS_AWAY = (214, -1) + COLOR_STATUS_DND = (160, -1) + COLOR_STATUS_CHAT = (34 , -1) + COLOR_STATUS_UNAVAILABLE = (242 , -1) + COLOR_STATUS_ONLINE = (27 , -1) + + COLOR_VERTICAL_SEPARATOR = (236, -1) + COLOR_NEW_TEXT_SEPARATOR = (213, -1) + COLOR_MORE_INDICATOR = (6, 4) + + COLOR_HIGHLIGHT_NICK = (236, 202, 'b') + + COLOR_TAB_NORMAL = (-1, 236) + COLOR_TAB_CURRENT = (-1, 16) + COLOR_TAB_NEW_MESSAGE = (3, 236) + COLOR_TAB_HIGHLIGHT = (1, 236) + COLOR_TAB_PRIVATE = (2, 236) + COLOR_TAB_DISCONNECTED = (13, 236) + + COLOR_TOPIC_BAR = (-1, 236) + COLOR_SCROLLABLE_NUMBER = (220, 236, 'b') + COLOR_SELECTED_ROW = (-1, 238) + COLOR_PRIVATE_NAME = (173, 236) + COLOR_CONVERSATION_NAME = (2, 236) + COLOR_GROUPCHAT_NAME = (106, 236) + COLOR_COLUMN_HEADER = (36, 236) + +theme = DarkTheme() + + diff --git a/data/themes/poezio b/data/themes/poezio deleted file mode 100644 index b5bb6a66..00000000 --- a/data/themes/poezio +++ /dev/null @@ -1,83 +0,0 @@ -# A theme file. (the Default one) -# For more informations, see http://dev.louiz.org/project/poezio/doc/TheThemes - -# Message text color -COLOR_NORMAL_TEXT = 0 -COLOR_INFORMATION_TEXT = 5 -COLOR_HIGHLIGHT_NICK = -46 - -# User list color -COLOR_USER_VISITOR = 7 -COLOR_USER_PARTICIPANT = 4 -COLOR_USER_NONE = 0 -COLOR_USER_MODERATOR = 1 - -# nickname colors -COLOR_REMOTE_USER = 5 - -# The character printed in color (COLOR_STATUS_*) before the nickname -# in the user list -CHAR_STATUS = ' ' - -# Separators -COLOR_VERTICAL_SEPARATOR = 4 -COLOR_NEW_TEXT_SEPARATOR = 2 -COLOR_MORE_INDICATOR = 6 - -# Time -COLOR_TIME_SEPARATOR = 6 -COLOR_TIME_LIMITER = 0 -CHAR_TIME_LEFT = '' -CHAR_TIME_RIGHT = '' -COLOR_TIME_NUMBERS = 0 - -# Tabs -COLOR_TAB_NORMAL = 42 -COLOR_TAB_CURRENT = 56 -COLOR_TAB_NEW_MESSAGE = 49 -COLOR_TAB_HIGHLIGHT = 21 -COLOR_TAB_PRIVATE = 28 -COLOR_TAB_DISCONNECTED = 30 - -# Nickname colors -LIST_COLOR_NICKNAMES = [ - 1, 2, 3, 4, 5, 6, -2, -4, -5, -6 - ] -COLOR_OWN_NICK = 7 - -# Status color -COLOR_STATUS_XA = 49 -COLOR_STATUS_NONE = 0 -COLOR_STATUS_DND = 21 -COLOR_STATUS_AWAY = 35 -COLOR_STATUS_CHAT = 28 -COLOR_STATUS_UNAVAILABLE = 57 -COLOR_STATUS_ONLINE = 41 - -# Bars -COLOR_INFORMATION_BAR = 42 -COLOR_TOPIC_BAR = 42 -COLOR_PRIVATE_ROOM_BAR = 28 -COLOR_SCROLLABLE_NUMBER = 39 -COLOR_SELECTED_ROW = 42 -COLOR_PRIVATE_NAME = 42 -COLOR_CONVERSATION_NAME = 42 -COLOR_GROUPCHAT_NAME = 42 -COLOR_COLUMN_HEADER = 36 - -# Strings for special messages (like join, quit, nick change, etc) -# Special messages -CHAR_JOIN = '---->' -CHAR_QUIT = '<----' -CHAR_KICK = '-!-' - -COLOR_JOIN_CHAR = 4 -COLOR_QUIT_CHAR = 1 -COLOR_KICK_CHAR = 1 - -# words between () -COLOR_CURLYBRACKETED_WORD = 4 -# words between {} -COLOR_ACCOLADE_WORD = 6 -# words between [] -COLOR_BRACKETED_WORD = 3 diff --git a/src/core.py b/src/core.py index 230253de..3c4af5d9 100644 --- a/src/core.py +++ b/src/core.py @@ -809,6 +809,7 @@ class Core(object): stdscr.keypad(True) curses.start_color() curses.use_default_colors() + theming.reload_theme() curses.ungetch(" ") # H4X: without this, the screen is stdscr.getkey() # erased on the first "getkey()" @@ -886,7 +887,7 @@ class Core(object): self.command_win('%s' % tab.nb) return for tab in self.tabs: - if tab.get_color_state() == theme.COLOR_TAB_DISCONNECTED: + if tab.get_color_state() == get_theme().COLOR_TAB_DISCONNECTED: self.command_win('%s' % tab.nb) return for tab in self.tabs: @@ -1179,9 +1180,7 @@ class Core(object): self.xmpp.plugin['xep_0030'].get_items(jid=server, block=False, callback=list_tab.on_muc_list_item_received) def command_theme(self, arg): - """ - """ - # get_theme().reload_theme() + theming.reload_theme() self.refresh_window() def command_win(self, arg): diff --git a/src/tabs.py b/src/tabs.py index 88d8ad7f..1b0406f2 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -799,7 +799,8 @@ class MucTab(ChatTab): room.users.append(new_user) if from_nick == room.own_nick: room.joined = True - self.send_chat_state('active') + if self.core.current_tab() == self and self.core.status.show not in ('xa', 'away'): + self.send_chat_state('active') new_user.color = get_theme().COLOR_OWN_NICK room.add_message(_("\x195}Your nickname is \x193}%s") % (from_nick)) if '170' in status_codes: @@ -999,10 +1000,12 @@ class PrivateTab(ChatTab): # keys self.key_func['^I'] = self.completion # commands - #self.commands['info'] = (self.command_info, _('Usage: /info\nInfo: Display some information about the user in the MUC: '), None) + self.commands['info'] = (self.command_info, _('Usage: /info\nInfo: Display some information about the user in the MUC: '), None) self.commands['unquery'] = (self.command_unquery, _("Usage: /unquery\nUnquery: close the tab"), None) self.commands['part'] = (self.command_unquery, _("Usage: /part\nPart: close the tab"), None) + self.commands['version'] = (self.command_version, _('Usage: /version\nVersion: get the software version of the current interlocutor (usually its XMPP client and Operating System)'), None) self.resize() + self.parent_muc = self.core.get_tab_by_name(JID(room.name).bare, MucTab) self.on = True def completion(self): @@ -1019,7 +1022,8 @@ class PrivateTab(ChatTab): msg['body'] = xhtml.clean_text(line) msg['xhtml_im'] = xhtml.poezio_colors_to_html(line) if config.get('send_chat_states', 'true') == 'true' and self.remote_wants_chatstates is not False: - msg['chat_state'] = 'active' + needed = 'inactive' if self.core.status.show in ('xa', 'away') else 'active' + msg['chat_state'] = needed msg.send() self.core.add_message_to_text_buffer(self.get_room(), line, None, self.core.own_nick or self.get_room().own_nick) logger.log_message(JID(self.get_name()).bare, self.core.own_nick, line) @@ -1033,6 +1037,31 @@ class PrivateTab(ChatTab): """ self.core.close_tab() + def command_version(self, arg): + """ + /version + """ + def callback(res): + if not res: + return self.core.information('Could not get the software version from %s' % (jid,), 'Warning') + version = '%s is running %s version %s on %s' % (jid, + res.get('name') or _('an unknown software'), + res.get('version') or _('unknown'), + res.get('os') or _('on an unknown platform')) + self.core.information(version, 'Info') + jid = self.get_room().name + self.core.xmpp.plugin['xep_0092'].get_version(jid, callback=callback) + + def command_info(self, arg): + """ + /info + """ + if arg: + self.parent_muc.command_info(arg) + else: + user = JID(self.get_room().name).resource + self.parent_muc.command_info(user) + def resize(self): if self.core.information_win_size >= self.height-3 or not self.visible: return @@ -1124,22 +1153,25 @@ class PrivateTab(ChatTab): """ The user left the associated MUC """ + self.deactivate() if not status_message: self.get_room().add_message(_('\x191}%(spec)s \x193}%(nick)s\x195} has left the room') % {'nick':from_nick.replace('"', '\\"'), 'spec':get_theme().CHAR_QUIT.replace('"', '\\"')}) else: self.get_room().add_message(_('\x191}%(spec)s \x193}%(nick)s\x195} has left the room (%(status)s)"') % {'nick':from_nick.replace('"', '\\"'), 'spec':get_theme().CHAR_QUIT, 'status': status_message.replace('"', '\\"')}) - self.deactivate() - self.refresh() - self.core.doupdate() + if self.core.current_tab() is self: + self.refresh() + self.core.doupdate() def user_rejoined(self, nick): """ The user (or at least someone with the same nick) came back in the MUC """ - self.get_room().add_message('\x194}%(spec)s \x193}%(nick)s\x195} joined the room' % {'nick':nick, 'spec':get_theme().CHAR_JOIN}) self.activate() - self.refresh() - self.core.doupdate() + self.get_room().add_message('\x194}%(spec)s \x193}%(nick)s\x195} joined the room' % {'nick':nick, 'spec':get_theme().CHAR_JOIN}) + if self.core.current_tab() is self: + self.refresh() + self.core.doupdate() + def activate(self): self.on = True @@ -1527,7 +1559,8 @@ class ConversationTab(ChatTab): msg['body'] = xhtml.clean_text(line) msg['xhtml_im'] = xhtml.poezio_colors_to_html(line) if config.get('send_chat_states', 'true') == 'true' and self.remote_wants_chatstates is not False: - msg['chat_state'] = 'active' + needed = 'inactive' if self.core.status.show in ('xa', 'away') else 'active' + msg['chat_state'] = needed msg.send() self.core.add_message_to_text_buffer(self.get_room(), line, None, self.core.own_nick) logger.log_message(JID(self.get_name()).bare, self.core.own_nick, line) diff --git a/src/theming.py b/src/theming.py index eecd749c..382a3146 100644 --- a/src/theming.py +++ b/src/theming.py @@ -34,24 +34,18 @@ is a string and can contain one or more of these characteres: For example, (200, 208, 'bu') is bold, underlined and pink foreground on orange background. -A theme file is a python file containing two objects named 'theme' and 'theme8', which both are -instances of two classes (derived from the Theme class) defined in that same file. -For example, in darktheme.py: +A theme file is a python file containing one object named 'theme', which is an +instance of a class (derived from the Theme class) defined in that same file. +For example, in pinkytheme.py: import theming -class DarkTheme(theming.Theme): +class PinkyTheme(theming.Theme): COLOR_NORMAL_TEXT = (200, -1) - [...] -class DarkTheme8(theming.Theme): - COLOR_NORMAL_TEXT = (1, -1) - [...] +theme = PinkyTheme() -theme = DarkTheme() -theme8 = DarkTheme8() - -if the command '/theme darktheme' is issued, we import the darktheme.py file -and set the global variable 'theme' to darktheme.theme. +if the command '/theme pinkytheme' is issued, we import the pinkytheme.py file +and set the global variable 'theme' to pinkytheme.theme. And in poezio's code we just use theme.COLOR_NORMAL_TEXT etc @@ -84,14 +78,14 @@ class Theme(object): """ # Message text color COLOR_NORMAL_TEXT = (-1, -1) - COLOR_INFORMATION_TEXT = (137, -1) - COLOR_HIGHLIGHT_NICK = (208, 22) + COLOR_INFORMATION_TEXT = (137, -1) # TODO + COLOR_HIGHLIGHT_NICK = (3, 5, 'b') # User list color - COLOR_USER_VISITOR = (13, -1) - COLOR_USER_PARTICIPANT = (7, -1) - COLOR_USER_NONE = (243, -1) - COLOR_USER_MODERATOR = (160, -1) + COLOR_USER_VISITOR = (0, -1) + COLOR_USER_PARTICIPANT = (4, -1) + COLOR_USER_NONE = (0, -1) + COLOR_USER_MODERATOR = (1, -1) # nickname colors COLOR_REMOTE_USER = (5, -1) @@ -106,7 +100,7 @@ class Theme(object): COLOR_MORE_INDICATOR = (6, 4) # Time - COLOR_TIME_SEPARATOR = (6, -1) + COLOR_TIME_SEPARATOR = (106, -1) COLOR_TIME_LIMITER = (0, -1) CHAR_TIME_LEFT = '' CHAR_TIME_RIGHT = '' @@ -115,32 +109,35 @@ class Theme(object): # Tabs COLOR_TAB_NORMAL = (7, 4) COLOR_TAB_CURRENT = (7, 6) - COLOR_TAB_NEW_MESSAGE = (7, 3) - COLOR_TAB_HIGHLIGHT = (7, 9) + COLOR_TAB_NEW_MESSAGE = (7, 5) + COLOR_TAB_HIGHLIGHT = (7, 1) COLOR_TAB_PRIVATE = (7, 2) COLOR_TAB_DISCONNECTED = (7, 8) # Nickname colors - LIST_COLOR_NICKNAMES = [(1, -1), (2, -1), (3, -1), (4, -1), (5, -1), (6, -1), (7, -1), (8, -1), (21, -1), (154, -1), (202, -1), (123, -1), (216, -1)] + # A list of colors randomly attributed to nicks in MUCs + # Setting more colors makes it harder to have two nicks with the same color, + # avoiding confusions. + LIST_COLOR_NICKNAMES = [(1, -1), (2, -1), (3, -1), (4, -1), (5, -1), (6, -1), (7, -1), (8, -1), (9, -1), (10, -1), (11, -1), (12, -1), (13, -1), (14, -1), (23, -1), (23, -1), (88, -1), (99, -1), (100, -1), (154, -1), (213, -1), (216, -1), (227, -1)] + # This is your own nickname COLOR_OWN_NICK = (254, -1) # Status color - COLOR_STATUS_XA = (234, 90) - COLOR_STATUS_NONE = (234, 4) - COLOR_STATUS_DND = (234, 1) - COLOR_STATUS_AWAY = (234, 3) - COLOR_STATUS_CHAT = (234, 2) + COLOR_STATUS_XA = (16, 90) + COLOR_STATUS_NONE = (16, 4) + COLOR_STATUS_DND = (16, 1) + COLOR_STATUS_AWAY = (16, 3) + COLOR_STATUS_CHAT = (16, 2) COLOR_STATUS_UNAVAILABLE = (-1, 247) - COLOR_STATUS_ONLINE = (234, 4) + COLOR_STATUS_ONLINE = (16, 4) # Bars COLOR_INFORMATION_BAR = (7, 4) COLOR_TOPIC_BAR = (7, 4) - COLOR_PRIVATE_ROOM_BAR = (-1, 4) - COLOR_SCROLLABLE_NUMBER = (214, 4, 'b') + COLOR_SCROLLABLE_NUMBER = (220, 4, 'b') COLOR_SELECTED_ROW = (-1, 33) COLOR_PRIVATE_NAME = (-1, 4) - COLOR_CONVERSATION_NAME = (4, 4) + COLOR_CONVERSATION_NAME = (2, 4) COLOR_GROUPCHAT_NAME = (7, 4) COLOR_COLUMN_HEADER = (36, 4) @@ -223,7 +220,7 @@ def to_curses_attr(color_tuple): curses_pair = curses_pair | curses.A_BOLD if 'u' in additional_val: curses_pair = curses_pair | curses.A_UNDERLINE - if 'x' in additional_val: + if 'a' in additional_val: curses_pair = curses_pair | curses.A_BLINK return curses_pair @@ -247,11 +244,13 @@ def reload_theme(): if not theme_name: return try: - new_theme = imp.load_source('theme', os.path.join(themes_dir, theme_name)) + file_path = os.path.join(themes_dir, theme_name)+'.py' + log.debug('Theme file to load: %s' %(file_path,)) + new_theme = imp.load_source('theme', os.path.join(themes_dir, theme_name)+'.py') except: # TODO warning: theme not found return global theme - theme = new_theme + theme = new_theme.theme if __name__ == '__main__': """ @@ -260,7 +259,7 @@ if __name__ == '__main__': s = curses.initscr() curses.start_color() curses.use_default_colors() - s.addstr('%s' % curses.COLORS, to_curses_attr((3, -1, 'x'))) + s.addstr('%s' % curses.COLORS, to_curses_attr((3, -1, 'a'))) s.refresh() s.getkey() curses.endwin() |