From a1af8a49f15ff9d11a7c1e0ce6809e632ac25d28 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 22 Jan 2019 20:27:34 +0100 Subject: Store get_theme() in a variable in each function, to avoid redundant calls. --- poezio/windows/bookmark_forms.py | 25 +++++++------ poezio/windows/data_forms.py | 25 ++++++------- poezio/windows/info_bar.py | 21 +++++------ poezio/windows/info_wins.py | 77 +++++++++++++++++++++++----------------- poezio/windows/list.py | 14 ++++---- poezio/windows/muc.py | 16 +++++---- poezio/windows/roster_win.py | 77 +++++++++++++++++++++------------------- poezio/windows/text_win.py | 40 ++++++++++++--------- 8 files changed, 163 insertions(+), 132 deletions(-) (limited to 'poezio/windows') diff --git a/poezio/windows/bookmark_forms.py b/poezio/windows/bookmark_forms.py index 2940ef04..8b9150d6 100644 --- a/poezio/windows/bookmark_forms.py +++ b/poezio/windows/bookmark_forms.py @@ -245,9 +245,10 @@ class BookmarksWin(Win): return if self.current_input == 0: return + theme = get_theme() self.lines[self.current_input][ self.current_horizontal_input].set_color( - get_theme().COLOR_NORMAL_TEXT) + theme.COLOR_NORMAL_TEXT) self.current_input -= 1 # Adjust the scroll position if the current_input would be outside # of the visible area @@ -256,20 +257,21 @@ class BookmarksWin(Win): self.refresh() self.lines[self.current_input][ self.current_horizontal_input].set_color( - get_theme().COLOR_SELECTED_ROW) + theme.COLOR_SELECTED_ROW) def go_to_next_horizontal_input(self) -> None: if not self.lines: return + theme = get_theme() self.lines[self.current_input][ self.current_horizontal_input].set_color( - get_theme().COLOR_NORMAL_TEXT) + theme.COLOR_NORMAL_TEXT) self.current_horizontal_input += 1 if self.current_horizontal_input > 3: self.current_horizontal_input = 0 self.lines[self.current_input][ self.current_horizontal_input].set_color( - get_theme().COLOR_SELECTED_ROW) + theme.COLOR_SELECTED_ROW) def go_to_next_page(self) -> bool: if not self.lines: @@ -278,9 +280,10 @@ class BookmarksWin(Win): if self.current_input == len(self.lines) - 1: return False + theme = get_theme() self.lines[self.current_input][ self.current_horizontal_input].set_color( - get_theme().COLOR_NORMAL_TEXT) + theme.COLOR_NORMAL_TEXT) inc = min(self.height, len(self.lines) - self.current_input - 1) if self.current_input + inc - self.scroll_pos > self.height - 1: @@ -291,7 +294,7 @@ class BookmarksWin(Win): self.current_input += inc self.lines[self.current_input][ self.current_horizontal_input].set_color( - get_theme().COLOR_SELECTED_ROW) + theme.COLOR_SELECTED_ROW) return True def go_to_previous_page(self) -> bool: @@ -301,9 +304,10 @@ class BookmarksWin(Win): if self.current_input == 0: return False + theme = get_theme() self.lines[self.current_input][ self.current_horizontal_input].set_color( - get_theme().COLOR_NORMAL_TEXT) + theme.COLOR_NORMAL_TEXT) dec = min(self.height, self.current_input) self.current_input -= dec @@ -314,7 +318,7 @@ class BookmarksWin(Win): self.refresh() self.lines[self.current_input][ self.current_horizontal_input].set_color( - get_theme().COLOR_SELECTED_ROW) + theme.COLOR_SELECTED_ROW) return True def go_to_previous_horizontal_input(self) -> None: @@ -322,13 +326,14 @@ class BookmarksWin(Win): return if self.current_horizontal_input == 0: return + theme = get_theme() self.lines[self.current_input][ self.current_horizontal_input].set_color( - get_theme().COLOR_NORMAL_TEXT) + theme.COLOR_NORMAL_TEXT) self.current_horizontal_input -= 1 self.lines[self.current_input][ self.current_horizontal_input].set_color( - get_theme().COLOR_SELECTED_ROW) + theme.COLOR_SELECTED_ROW) def on_input(self, key: str) -> None: if not self.lines: diff --git a/poezio/windows/data_forms.py b/poezio/windows/data_forms.py index b8dd8531..3ec44b97 100644 --- a/poezio/windows/data_forms.py +++ b/poezio/windows/data_forms.py @@ -438,10 +438,11 @@ class FormWin: return if self.current_input == len(self.inputs) - 1: return + theme = get_theme() self.inputs[self.current_input]['input'].set_color( - get_theme().COLOR_NORMAL_TEXT) + theme.COLOR_NORMAL_TEXT) self.inputs[self.current_input]['label'].set_color( - get_theme().COLOR_NORMAL_TEXT) + theme.COLOR_NORMAL_TEXT) self.current_input += 1 jump = 0 while self.current_input + jump != len( @@ -460,19 +461,20 @@ class FormWin: self.scroll_pos += 1 self.refresh() self.inputs[self.current_input]['input'].set_color( - get_theme().COLOR_SELECTED_ROW) + theme.COLOR_SELECTED_ROW) self.inputs[self.current_input]['label'].set_color( - get_theme().COLOR_SELECTED_ROW) + theme.COLOR_SELECTED_ROW) def go_to_previous_input(self): if not self.inputs: return if self.current_input == 0: return + theme = get_theme() self.inputs[self.current_input]['input'].set_color( - get_theme().COLOR_NORMAL_TEXT) + theme.COLOR_NORMAL_TEXT) self.inputs[self.current_input]['label'].set_color( - get_theme().COLOR_NORMAL_TEXT) + theme.COLOR_NORMAL_TEXT) self.current_input -= 1 jump = 0 while self.current_input - jump > 0 and self.inputs[self.current_input @@ -489,9 +491,9 @@ class FormWin: self.refresh() self.current_input -= jump self.inputs[self.current_input]['input'].set_color( - get_theme().COLOR_SELECTED_ROW) + theme.COLOR_SELECTED_ROW) self.inputs[self.current_input]['label'].set_color( - get_theme().COLOR_SELECTED_ROW) + theme.COLOR_SELECTED_ROW) def on_input(self, key, raw=False): if not self.inputs: @@ -521,11 +523,10 @@ class FormWin: inp['input'].refresh() inp['label'].refresh() if self.inputs and self.current_input < self.height - 1: - self.inputs[self.current_input]['input'].set_color( - get_theme().COLOR_SELECTED_ROW) + color = get_theme().COLOR_SELECTED_ROW + self.inputs[self.current_input]['input'].set_color(color) self.inputs[self.current_input]['input'].refresh() - self.inputs[self.current_input]['label'].set_color( - get_theme().COLOR_SELECTED_ROW) + self.inputs[self.current_input]['label'].set_color(color) self.inputs[self.current_input]['label'].refresh() def refresh_current_input(self): diff --git a/poezio/windows/info_bar.py b/poezio/windows/info_bar.py index 15821c10..ac900103 100644 --- a/poezio/windows/info_bar.py +++ b/poezio/windows/info_bar.py @@ -25,8 +25,9 @@ class GlobalInfoBar(Win): def refresh(self) -> None: log.debug('Refresh: %s', self.__class__.__name__) self._win.erase() + theme = get_theme() self.addstr(0, 0, "[", - to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + to_curses_attr(theme.COLOR_INFORMATION_BAR)) show_names = config.get('show_tab_names') show_nums = config.get('show_tab_numbers') @@ -37,7 +38,7 @@ class GlobalInfoBar(Win): if not tab: continue color = tab.color - if not show_inactive and color is get_theme().COLOR_TAB_NORMAL: + if not show_inactive and color is theme.COLOR_TAB_NORMAL: continue try: if show_nums or not show_names: @@ -51,16 +52,16 @@ class GlobalInfoBar(Win): else: self.addstr("%s" % tab.name, to_curses_attr(color)) self.addstr("|", - to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + to_curses_attr(theme.COLOR_INFORMATION_BAR)) except: # end of line break (y, x) = self._win.getyx() self.addstr(y, x - 1, '] ', - to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + to_curses_attr(theme.COLOR_INFORMATION_BAR)) (y, x) = self._win.getyx() remaining_size = self.width - x self.addnstr(' ' * remaining_size, remaining_size, - to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + to_curses_attr(theme.COLOR_INFORMATION_BAR)) self._refresh() @@ -76,17 +77,17 @@ class VerticalGlobalInfoBar(Win): height, width = self._win.getmaxyx() self._win.erase() sorted_tabs = [tab for tab in self.core.tabs if tab] + theme = get_theme() if not config.get('show_inactive_tabs'): sorted_tabs = [ tab for tab in sorted_tabs - if tab.vertical_color != get_theme().COLOR_VERTICAL_TAB_NORMAL + if tab.vertical_color != theme.COLOR_VERTICAL_TAB_NORMAL ] nb_tabs = len(sorted_tabs) use_nicks = config.get('use_tab_nicks') if nb_tabs >= height: for y, tab in enumerate(sorted_tabs): - if tab.vertical_color == get_theme( - ).COLOR_VERTICAL_TAB_CURRENT: + if tab.vertical_color == theme.COLOR_VERTICAL_TAB_CURRENT: pos = y break # center the current tab as much as possible @@ -102,14 +103,14 @@ class VerticalGlobalInfoBar(Win): if asc_sort: y = height - y - 1 self.addstr(y, 0, "%2d" % tab.nb, - to_curses_attr(get_theme().COLOR_VERTICAL_TAB_NUMBER)) + to_curses_attr(theme.COLOR_VERTICAL_TAB_NUMBER)) self.addstr('.') if use_nicks: self.addnstr("%s" % tab.get_nick(), width - 4, to_curses_attr(color)) else: self.addnstr("%s" % tab.name, width - 4, to_curses_attr(color)) - separator = to_curses_attr(get_theme().COLOR_VERTICAL_SEPARATOR) + separator = to_curses_attr(theme.COLOR_VERTICAL_SEPARATOR) self._win.attron(separator) self._win.vline(0, width - 1, curses.ACS_VLINE, height) self._win.attroff(separator) diff --git a/poezio/windows/info_wins.py b/poezio/windows/info_wins.py index abc0a401..d07cbe20 100644 --- a/poezio/windows/info_wins.py +++ b/poezio/windows/info_wins.py @@ -94,9 +94,10 @@ class PrivateInfoWin(InfoWin): def write_room_name(self, name): jid = safeJID(name) room_name, nick = jid.bare, jid.resource - self.addstr(nick, to_curses_attr(get_theme().COLOR_PRIVATE_NAME)) + theme = get_theme() + self.addstr(nick, to_curses_attr(theme.COLOR_PRIVATE_NAME)) txt = ' from room %s' % room_name - self.addstr(txt, to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + self.addstr(txt, to_curses_attr(theme.COLOR_INFORMATION_BAR)) def write_chatstate(self, state): if state: @@ -119,15 +120,16 @@ class MucListInfoWin(InfoWin): def refresh(self, name=None, window=None): log.debug('Refresh: %s', self.__class__.__name__) self._win.erase() + theme = get_theme() if name: self.addstr(name, - to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + to_curses_attr(theme.COLOR_INFORMATION_BAR)) else: self.addstr(self.message, - to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + to_curses_attr(theme.COLOR_INFORMATION_BAR)) if window: self.print_scroll_position(window) - self.finish_line(get_theme().COLOR_INFORMATION_BAR) + self.finish_line(theme.COLOR_INFORMATION_BAR) self._refresh() @@ -176,9 +178,9 @@ class ConversationInfoWin(InfoWin): Write all information added by plugins by getting the value returned by the callbacks. """ + color = to_curses_attr(get_theme().COLOR_INFORMATION_BAR) for plugin in information.values(): - self.addstr(plugin(jid), - to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + self.addstr(plugin(jid), color) def write_resource_information(self, resource): """ @@ -188,38 +190,40 @@ class ConversationInfoWin(InfoWin): presence = "unavailable" else: presence = resource.presence - color = get_theme().color_show(presence) + theme = get_theme() + color = theme.color_show(presence) if not presence: - presence = get_theme().CHAR_STATUS - self.addstr('[', to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + presence = theme.CHAR_STATUS + self.addstr('[', to_curses_attr(theme.COLOR_INFORMATION_BAR)) self.addstr(presence, to_curses_attr(color)) if resource and resource.status: shortened = resource.status[:20] + (resource.status[:20] and '…') self.addstr(' %s' % shortened, - to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) - self.addstr(']', to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + to_curses_attr(theme.COLOR_INFORMATION_BAR)) + self.addstr(']', to_curses_attr(theme.COLOR_INFORMATION_BAR)) def write_contact_information(self, contact): """ Write the information about the contact """ + color = to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) if not contact: - self.addstr("(contact not in roster)", - to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + self.addstr("(contact not in roster)", color) return display_name = contact.name if display_name: - self.addstr('%s ' % (display_name), - to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + self.addstr('%s ' % (display_name), color) def write_contact_jid(self, jid): """ Just write the jid that we are talking to """ - self.addstr('[', to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + theme = get_theme() + color = to_curses_attr(theme.COLOR_INFORMATION_BAR)) + self.addstr('[', color) self.addstr(jid.full, - to_curses_attr(get_theme().COLOR_CONVERSATION_NAME)) - self.addstr('] ', to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + to_curses_attr(theme.COLOR_CONVERSATION_NAME)) + self.addstr('] ', color) def write_chatstate(self, state): if state: @@ -236,14 +240,16 @@ class DynamicConversationInfoWin(ConversationInfoWin): """ log.debug("write_contact_jid DynamicConversationInfoWin, jid: %s", jid.resource) - self.addstr('[', to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + theme = get_theme() + color = to_curses_attr(theme.COLOR_INFORMATION_BAR)) + self.addstr('[', color) self.addstr(jid.bare, - to_curses_attr(get_theme().COLOR_CONVERSATION_NAME)) + to_curses_attr(theme.COLOR_CONVERSATION_NAME)) if jid.resource: self.addstr( "/%s" % (jid.resource, ), - to_curses_attr(get_theme().COLOR_CONVERSATION_RESOURCE)) - self.addstr('] ', to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + to_curses_attr(theme.COLOR_CONVERSATION_RESOURCE)) + self.addstr('] ', color) class MucInfoWin(InfoWin): @@ -277,22 +283,26 @@ class MucInfoWin(InfoWin): Write all information added by plugins by getting the value returned by the callbacks. """ + color = to_curses_attr(get_theme().COLOR_INFORMATION_BAR) for plugin in information.values(): - self.addstr(plugin(jid), - to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + self.addstr(plugin(jid), color) def write_room_name(self, room): - self.addstr('[', to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + theme = get_theme() + color = to_curses_attr(theme.COLOR_INFORMATION_BAR) + self.addstr('[', color) self.addstr(room.name, - to_curses_attr(get_theme().COLOR_GROUPCHAT_NAME)) - self.addstr(']', to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + to_curses_attr(theme.COLOR_GROUPCHAT_NAME)) + self.addstr(']', color) def write_participants_number(self, room): - self.addstr('{', to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + theme = get_theme() + color = to_curses_attr(theme.COLOR_INFORMATION_BAR) + self.addstr('{', color) self.addstr( str(len(room.users)), - to_curses_attr(get_theme().COLOR_GROUPCHAT_NAME)) - self.addstr('} ', to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + to_curses_attr(theme.COLOR_GROUPCHAT_NAME)) + self.addstr('} ', color) def write_disconnected(self, room): """ @@ -386,10 +396,11 @@ class ConfirmStatusWin(Win): def refresh(self): log.debug('Refresh: %s', self.__class__.__name__) self._win.erase() + theme = get_theme() if self.critical: - color = get_theme().COLOR_WARNING_PROMPT + color = theme.COLOR_WARNING_PROMPT else: - color = get_theme().COLOR_INFORMATION_BAR + color = theme.COLOR_INFORMATION_BAR c_color = to_curses_attr(color) self.addstr(self.text, c_color) self.finish_line(color) diff --git a/poezio/windows/list.py b/poezio/windows/list.py index f03dcf6a..350255c6 100644 --- a/poezio/windows/list.py +++ b/poezio/windows/list.py @@ -94,6 +94,7 @@ class ListWin(Win): log.debug('Refresh: %s', self.__class__.__name__) self._win.erase() lines = self.lines[self._starting_pos:self._starting_pos + self.height] + color = to_curses_attr(get_theme().COLOR_INFORMATION_BAR) for y, line in enumerate(lines): x = 0 for col in self._columns.items(): @@ -106,9 +107,7 @@ class ListWin(Win): if not txt: continue if line is self.lines[self._selected_row]: - self.addstr( - y, x, txt[:size], - to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + self.addstr(y, x, txt[:size], color) else: self.addstr(y, x, txt[:size]) x += size @@ -189,23 +188,24 @@ class ColumnHeaderWin(Win): log.debug('Refresh: %s', self.__class__.__name__) self._win.erase() x = 0 + theme = get_theme() for col in self._columns: txt = col if col in self._column_order: if self._column_order_asc: - txt += get_theme().CHAR_COLUMN_ASC + txt += theme.CHAR_COLUMN_ASC else: - txt += get_theme().CHAR_COLUMN_DESC + txt += theme.CHAR_COLUMN_DESC #⇓⇑↑↓⇧⇩▲▼ size = self._columns_sizes[col] txt += ' ' * (size - len(txt)) if col in self._column_sel: self.addstr( 0, x, txt, - to_curses_attr(get_theme().COLOR_COLUMN_HEADER_SEL)) + to_curses_attr(theme.COLOR_COLUMN_HEADER_SEL)) else: self.addstr(0, x, txt, - to_curses_attr(get_theme().COLOR_COLUMN_HEADER)) + to_curses_attr(theme.COLOR_COLUMN_HEADER)) x += size self._refresh() diff --git a/poezio/windows/muc.py b/poezio/windows/muc.py index 72dc602c..951940e1 100644 --- a/poezio/windows/muc.py +++ b/poezio/windows/muc.py @@ -110,15 +110,16 @@ class UserList(Win): self.addstr(y, 1, symbol, to_curses_attr(color)) def draw_status_chatstate(self, y: int, user: User) -> None: - show_col = get_theme().color_show(user.show) + theme = get_theme() + show_col = theme.color_show(user.show) if user.chatstate == 'composing': - char = get_theme().CHAR_CHATSTATE_COMPOSING + char = theme.CHAR_CHATSTATE_COMPOSING elif user.chatstate == 'active': - char = get_theme().CHAR_CHATSTATE_ACTIVE + char = theme.CHAR_CHATSTATE_ACTIVE elif user.chatstate == 'paused': - char = get_theme().CHAR_CHATSTATE_PAUSED + char = theme.CHAR_CHATSTATE_PAUSED else: - char = get_theme().CHAR_STATUS + char = theme.CHAR_STATUS self.addstr(y, 0, char, to_curses_attr(show_col)) def resize(self, height: int, width: int, y: int, x: int) -> None: @@ -138,17 +139,18 @@ class Topic(Win): def refresh(self, topic: Optional[str] = None) -> None: log.debug('Refresh: %s', self.__class__.__name__) + theme = get_theme() self._win.erase() if topic is not None: msg = topic[:self.width - 1] else: msg = self._message[:self.width - 1] - self.addstr(0, 0, msg, to_curses_attr(get_theme().COLOR_TOPIC_BAR)) + self.addstr(0, 0, msg, to_curses_attr(theme.COLOR_TOPIC_BAR)) _, x = self._win.getyx() remaining_size = self.width - x if remaining_size: self.addnstr(' ' * remaining_size, remaining_size, - to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + to_curses_attr(theme.COLOR_INFORMATION_BAR)) self._refresh() def set_message(self, message) -> None: diff --git a/poezio/windows/roster_win.py b/poezio/windows/roster_win.py index 3c62ea0a..2efdd324 100644 --- a/poezio/windows/roster_win.py +++ b/poezio/windows/roster_win.py @@ -195,18 +195,20 @@ class RosterWin(Win): """ The header at the top """ + color = get_theme().COLOR_INFORMATION_BAR self.addstr( 'Roster: %s/%s contacts' % (roster.get_nb_connected_contacts(), len(roster)), - to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) - self.finish_line(get_theme().COLOR_INFORMATION_BAR) + to_curses_attr(color)) + self.finish_line(color) def draw_group(self, y: int, group: RosterGroup, colored: bool) -> None: """ Draw a groupname on a line """ + color = to_curses_attr(get_theme().COLOR_SELECTED_ROW) if colored: - self._win.attron(to_curses_attr(get_theme().COLOR_SELECTED_ROW)) + self._win.attron(color) if group.folded: self.addstr(y, 0, '[+] ') else: @@ -217,7 +219,7 @@ class RosterWin(Win): self.truncate_name(group.name, len(contacts) + 4) + contacts) if colored: - self._win.attroff(to_curses_attr(get_theme().COLOR_SELECTED_ROW)) + self._win.attroff(color) self.finish_line() def truncate_name(self, name, added): @@ -263,17 +265,17 @@ class RosterWin(Win): added += 4 if contact.ask: - added += len(get_theme().CHAR_ROSTER_ASKED) + added += len(theme.CHAR_ROSTER_ASKED) if show_s2s_errors and contact.error: - added += len(get_theme().CHAR_ROSTER_ERROR) + added += len(theme.CHAR_ROSTER_ERROR) if contact.tune: - added += len(get_theme().CHAR_ROSTER_TUNE) + added += len(theme.CHAR_ROSTER_TUNE) if contact.mood: - added += len(get_theme().CHAR_ROSTER_MOOD) + added += len(theme.CHAR_ROSTER_MOOD) if contact.activity: - added += len(get_theme().CHAR_ROSTER_ACTIVITY) + added += len(theme.CHAR_ROSTER_ACTIVITY) if contact.gaming: - added += len(get_theme().CHAR_ROSTER_GAMING) + added += len(theme.CHAR_ROSTER_GAMING) if show_roster_sub in ('all', 'incomplete', 'to', 'from', 'both', 'none'): added += len( @@ -291,7 +293,7 @@ class RosterWin(Win): if colored: self.addstr(display_name, - to_curses_attr(get_theme().COLOR_SELECTED_ROW)) + to_curses_attr(theme.COLOR_SELECTED_ROW)) else: self.addstr(display_name) @@ -302,34 +304,35 @@ class RosterWin(Win): contact.subscription, keep=show_roster_sub), to_curses_attr(theme.COLOR_ROSTER_SUBSCRIPTION)) if contact.ask: - self.addstr(get_theme().CHAR_ROSTER_ASKED, - to_curses_attr(get_theme().COLOR_IMPORTANT_TEXT)) + self.addstr(theme.CHAR_ROSTER_ASKED, + to_curses_attr(theme.COLOR_IMPORTANT_TEXT)) if show_s2s_errors and contact.error: - self.addstr(get_theme().CHAR_ROSTER_ERROR, - to_curses_attr(get_theme().COLOR_ROSTER_ERROR)) + self.addstr(theme.CHAR_ROSTER_ERROR, + to_curses_attr(theme.COLOR_ROSTER_ERROR)) if contact.tune: - self.addstr(get_theme().CHAR_ROSTER_TUNE, - to_curses_attr(get_theme().COLOR_ROSTER_TUNE)) + self.addstr(theme.CHAR_ROSTER_TUNE, + to_curses_attr(theme.COLOR_ROSTER_TUNE)) if contact.activity: - self.addstr(get_theme().CHAR_ROSTER_ACTIVITY, - to_curses_attr(get_theme().COLOR_ROSTER_ACTIVITY)) + self.addstr(theme.CHAR_ROSTER_ACTIVITY, + to_curses_attr(theme.COLOR_ROSTER_ACTIVITY)) if contact.mood: - self.addstr(get_theme().CHAR_ROSTER_MOOD, - to_curses_attr(get_theme().COLOR_ROSTER_MOOD)) + self.addstr(theme.CHAR_ROSTER_MOOD, + to_curses_attr(theme.COLOR_ROSTER_MOOD)) if contact.gaming: - self.addstr(get_theme().CHAR_ROSTER_GAMING, - to_curses_attr(get_theme().COLOR_ROSTER_GAMING)) + self.addstr(theme.CHAR_ROSTER_GAMING, + to_curses_attr(theme.COLOR_ROSTER_GAMING)) self.finish_line() def draw_resource_line(self, y: int, resource: Resource, colored: bool) -> None: """ Draw a specific resource line """ - color = get_theme().color_show(resource.presence) - self.addstr(y, 4, get_theme().CHAR_STATUS, to_curses_attr(color)) + theme = get_theme() + color = theme.color_show(resource.presence) + self.addstr(y, 4, theme.CHAR_STATUS, to_curses_attr(color)) if colored: self.addstr(y, 8, self.truncate_name(str(resource.jid), 6), - to_curses_attr(get_theme().COLOR_SELECTED_ROW)) + to_curses_attr(theme.COLOR_SELECTED_ROW)) else: self.addstr(y, 8, self.truncate_name(str(resource.jid), 6)) self.finish_line() @@ -350,6 +353,7 @@ class ContactInfoWin(Win): """ draw the contact information """ + theme = get_theme() resource = contact.get_highest_priority_resource() if contact: jid = str(contact.bare_jid) @@ -365,8 +369,8 @@ class ContactInfoWin(Win): self.addstr(0, 0, '%s (%s)' % ( jid, presence, - ), to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) - self.finish_line(get_theme().COLOR_INFORMATION_BAR) + ), to_curses_attr(theme.COLOR_INFORMATION_BAR)) + self.finish_line(theme.COLOR_INFORMATION_BAR) i += 1 self.addstr(i, 0, 'Subscription: %s' % (contact.subscription, )) self.finish_line() @@ -374,7 +378,7 @@ class ContactInfoWin(Win): if contact.ask: if contact.ask == 'asked': self.addstr(i, 0, 'Ask: %s' % (contact.ask, ), - to_curses_attr(get_theme().COLOR_IMPORTANT_TEXT)) + to_curses_attr(theme.COLOR_IMPORTANT_TEXT)) else: self.addstr(i, 0, 'Ask: %s' % (contact.ask, )) self.finish_line() @@ -386,33 +390,33 @@ class ContactInfoWin(Win): if contact.error: self.addstr(i, 0, 'Error: %s' % contact.error, - to_curses_attr(get_theme().COLOR_ROSTER_ERROR)) + to_curses_attr(theme.COLOR_ROSTER_ERROR)) self.finish_line() i += 1 if contact.tune: self.addstr(i, 0, 'Tune: %s' % common.format_tune_string(contact.tune), - to_curses_attr(get_theme().COLOR_NORMAL_TEXT)) + to_curses_attr(theme.COLOR_NORMAL_TEXT)) self.finish_line() i += 1 if contact.mood: self.addstr(i, 0, 'Mood: %s' % contact.mood, - to_curses_attr(get_theme().COLOR_NORMAL_TEXT)) + to_curses_attr(theme.COLOR_NORMAL_TEXT)) self.finish_line() i += 1 if contact.activity: self.addstr(i, 0, 'Activity: %s' % contact.activity, - to_curses_attr(get_theme().COLOR_NORMAL_TEXT)) + to_curses_attr(theme.COLOR_NORMAL_TEXT)) self.finish_line() i += 1 if contact.gaming: self.addstr( i, 0, 'Game: %s' % common.format_gaming_string(contact.gaming), - to_curses_attr(get_theme().COLOR_NORMAL_TEXT)) + to_curses_attr(theme.COLOR_NORMAL_TEXT)) self.finish_line() i += 1 @@ -420,9 +424,10 @@ class ContactInfoWin(Win): """ draw the group information """ + theme = get_theme() self.addstr(0, 0, group.name, - to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) - self.finish_line(get_theme().COLOR_INFORMATION_BAR) + to_curses_attr(theme.COLOR_INFORMATION_BAR)) + self.finish_line(theme.COLOR_INFORMATION_BAR) def refresh(self, selected_row: Row) -> None: log.debug('Refresh: %s', self.__class__.__name__) diff --git a/poezio/windows/text_win.py b/poezio/windows/text_win.py index d0669b26..1de905ea 100644 --- a/poezio/windows/text_win.py +++ b/poezio/windows/text_win.py @@ -350,9 +350,10 @@ class TextWin(BaseTextWin): txt = message.txt if not txt: return [] + theme = get_theme() if len(message.str_time) > 8: default_color = ( - FORMAT_CHAR + dump_tuple(get_theme().COLOR_LOG_MSG) + '}') # type: Optional[str] + FORMAT_CHAR + dump_tuple(theme.COLOR_LOG_MSG) + '}') # type: Optional[str] else: default_color = None ret = [] # type: List[Union[None, Line]] @@ -360,9 +361,9 @@ class TextWin(BaseTextWin): offset = 0 if message.ack: if message.ack > 0: - offset += poopt.wcswidth(get_theme().CHAR_ACK_RECEIVED) + 1 + offset += poopt.wcswidth(theme.CHAR_ACK_RECEIVED) + 1 else: - offset += poopt.wcswidth(get_theme().CHAR_NACK) + 1 + offset += poopt.wcswidth(theme.CHAR_NACK) + 1 if nick: offset += poopt.wcswidth(nick) + 2 # + nick + '> ' length if message.revisions > 0: @@ -372,9 +373,9 @@ class TextWin(BaseTextWin): if timestamp: if message.str_time: offset += 1 + len(message.str_time) - if get_theme().CHAR_TIME_LEFT and message.str_time: + if theme.CHAR_TIME_LEFT and message.str_time: offset += 1 - if get_theme().CHAR_TIME_RIGHT and message.str_time: + if theme.CHAR_TIME_RIGHT and message.str_time: offset += 1 lines = poopt.cut_text(txt, self.width - offset - 1) prepend = default_color if default_color else '' @@ -439,10 +440,11 @@ class TextWin(BaseTextWin): nick = truncate_nick(msg.nickname, nick_size) offset += poopt.wcswidth(nick) if msg.ack: + theme = get_theme() if msg.ack > 0: - offset += poopt.wcswidth(get_theme().CHAR_ACK_RECEIVED) + 1 + offset += poopt.wcswidth(theme.CHAR_ACK_RECEIVED) + 1 else: - offset += poopt.wcswidth(get_theme().CHAR_NACK) + 1 + offset += poopt.wcswidth(theme.CHAR_NACK) + 1 if msg.me: offset += 3 else: @@ -497,25 +499,28 @@ class TextWin(BaseTextWin): return 0 def write_line_separator(self, y) -> None: - char = get_theme().CHAR_NEW_TEXT_SEPARATOR + theme = get_theme() + char = theme.CHAR_NEW_TEXT_SEPARATOR self.addnstr(y, 0, char * (self.width // len(char) - 1), self.width, - to_curses_attr(get_theme().COLOR_NEW_TEXT_SEPARATOR)) + to_curses_attr(theme.COLOR_NEW_TEXT_SEPARATOR)) def write_ack(self) -> int: - color = get_theme().COLOR_CHAR_ACK + theme = get_theme() + color = theme.COLOR_CHAR_ACK self._win.attron(to_curses_attr(color)) - self.addstr(get_theme().CHAR_ACK_RECEIVED) + self.addstr(theme.CHAR_ACK_RECEIVED) self._win.attroff(to_curses_attr(color)) self.addstr(' ') - return poopt.wcswidth(get_theme().CHAR_ACK_RECEIVED) + 1 + return poopt.wcswidth(theme.CHAR_ACK_RECEIVED) + 1 def write_nack(self) -> int: - color = get_theme().COLOR_CHAR_NACK + theme = get_theme() + color = theme.COLOR_CHAR_NACK self._win.attron(to_curses_attr(color)) - self.addstr(get_theme().CHAR_NACK) + self.addstr(theme.CHAR_NACK) self._win.attroff(to_curses_attr(color)) self.addstr(' ') - return poopt.wcswidth(get_theme().CHAR_NACK) + 1 + return poopt.wcswidth(theme.CHAR_NACK) + 1 def write_nickname(self, nickname, color, highlight=False) -> None: """ @@ -626,9 +631,10 @@ class XMLTextWin(BaseTextWin): offset += poopt.wcswidth(nick) + 1 # + nick + ' ' length if message.str_time: offset += 1 + len(message.str_time) - if get_theme().CHAR_TIME_LEFT and message.str_time: + theme = get_theme() + if theme.CHAR_TIME_LEFT and message.str_time: offset += 1 - if get_theme().CHAR_TIME_RIGHT and message.str_time: + if theme.CHAR_TIME_RIGHT and message.str_time: offset += 1 lines = poopt.cut_text(txt, self.width - offset - 1) prepend = default_color if default_color else '' -- cgit v1.2.3