From d55cc5872503567775f0d7a7731d6f489bf2299b Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 12 Nov 2017 15:03:09 +0100 Subject: yapf -ir --- poezio/windows/roster_win.py | 152 +++++++++++++++++++++++++++---------------- 1 file changed, 96 insertions(+), 56 deletions(-) (limited to 'poezio/windows/roster_win.py') diff --git a/poezio/windows/roster_win.py b/poezio/windows/roster_win.py index 73191e84..7b1e5ba7 100644 --- a/poezio/windows/roster_win.py +++ b/poezio/windows/roster_win.py @@ -17,11 +17,10 @@ from poezio.theming import get_theme, to_curses_attr class RosterWin(Win): - def __init__(self): Win.__init__(self) - self.pos = 0 # cursor position in the contact list - self.start_pos = 1 # position of the start of the display + self.pos = 0 # cursor position in the contact list + self.start_pos = 1 # position of the start of the display self.selected_row = None self.roster_cache = [] @@ -34,15 +33,15 @@ class RosterWin(Win): Return True if we scrolled, False otherwise """ pos = self.pos - if self.pos < self.roster_len-number: + if self.pos < self.roster_len - number: self.pos += number else: self.pos = self.roster_len - 1 - if self.pos >= self.start_pos-1 + self.height-1: + if self.pos >= self.start_pos - 1 + self.height - 1: if number == 1: self.scroll_down(8) else: - self.scroll_down(self.pos-self.start_pos - self.height // 2) + self.scroll_down(self.pos - self.start_pos - self.height // 2) self.update_pos() return pos != self.pos @@ -51,7 +50,7 @@ class RosterWin(Win): Return True if we scrolled, False otherwise """ pos = self.pos - if self.pos-number >= 0: + if self.pos - number >= 0: self.pos -= number else: self.pos = 0 @@ -59,7 +58,7 @@ class RosterWin(Win): if number == 1: self.scroll_up(8) else: - self.scroll_up(self.start_pos-self.pos + self.height // 2) + self.scroll_up(self.start_pos - self.pos + self.height // 2) self.update_pos() return pos != self.pos @@ -71,10 +70,10 @@ class RosterWin(Win): def scroll_down(self, number=8): pos = self.start_pos - if self.start_pos + number <= self.roster_len-1: + if self.start_pos + number <= self.roster_len - 1: self.start_pos += number else: - self.start_pos = self.roster_len-1 + self.start_pos = self.roster_len - 1 return self.start_pos != pos def scroll_up(self, number=8): @@ -106,21 +105,23 @@ class RosterWin(Win): # build the cache for group in roster.get_groups(group_sort): contacts_filtered = group.get_contacts() - if (not show_offline and group.get_nb_connected_contacts() == 0) or not contacts_filtered: - continue # Ignore empty groups + if (not show_offline and group.get_nb_connected_contacts() == 0 + ) or not contacts_filtered: + continue # Ignore empty groups self.roster_cache.append(group) if group.folded: - continue # ignore folded groups + continue # ignore folded groups for contact in group.get_contacts(sort=sort): if not show_offline and len(contact) == 0: - continue # ignore offline contacts + continue # ignore offline contacts self.roster_cache.append(contact) if not contact.folded(group.name): for resource in contact.get_resources(): self.roster_cache.append(resource) roster.last_built = datetime.now() if self.selected_row in self.roster_cache: - if self.pos < self.roster_len and self.roster_cache[self.pos] != self.selected_row: + if self.pos < self.roster_len and self.roster_cache[self. + pos] != self.selected_row: self.pos = self.roster_cache.index(self.selected_row) def refresh(self, roster): @@ -131,7 +132,8 @@ class RosterWin(Win): log.debug('Refresh: %s', self.__class__.__name__) self.build_roster_cache(roster) # make sure we are within bounds - self.move_cursor_up((self.roster_len + self.pos) if self.pos >= self.roster_len else 0) + self.move_cursor_up((self.roster_len + self.pos) + if self.pos >= self.roster_len else 0) if not self.roster_cache: self.selected_row = None self._win.erase() @@ -140,10 +142,12 @@ class RosterWin(Win): y = 1 group = "none" # scroll down if needed - if self.start_pos+self.height <= self.pos+2: - self.scroll_down(self.pos - self.start_pos - self.height + (self.height//2)) + if self.start_pos + self.height <= self.pos + 2: + self.scroll_down(self.pos - self.start_pos - self.height + + (self.height // 2)) # draw the roster from the cache - roster_view = self.roster_cache[self.start_pos-1:self.start_pos+self.height] + roster_view = self.roster_cache[self.start_pos - 1: + self.start_pos + self.height] options = { 'show_roster_sub': config.get('show_roster_subscriptions'), @@ -153,7 +157,7 @@ class RosterWin(Win): for item in roster_view: draw_selected = False - if y -2 + self.start_pos == self.pos: + if y - 2 + self.start_pos == self.pos: draw_selected = True self.selected_row = item @@ -161,7 +165,8 @@ class RosterWin(Win): self.draw_group(y, item, draw_selected) group = item.name elif isinstance(item, Contact): - self.draw_contact_line(y, item, draw_selected, group, **options) + self.draw_contact_line(y, item, draw_selected, group, + **options) elif isinstance(item, Resource): self.draw_resource_line(y, item, draw_selected) @@ -169,26 +174,25 @@ class RosterWin(Win): if self.start_pos > 1: self.draw_plus(1) - if self.start_pos + self.height-2 < self.roster_len: - self.draw_plus(self.height-1) + if self.start_pos + self.height - 2 < self.roster_len: + self.draw_plus(self.height - 1) self._refresh() - def draw_plus(self, y): """ Draw the indicator that shows that the list is longer than what is displayed """ - self.addstr(y, self.width-5, '++++', to_curses_attr(get_theme().COLOR_MORE_INDICATOR)) + self.addstr(y, self.width - 5, '++++', + to_curses_attr(get_theme().COLOR_MORE_INDICATOR)) def draw_roster_information(self, roster): """ The header at the top """ - self.addstr('Roster: %s/%s contacts' % ( - roster.get_nb_connected_contacts(), - len(roster)), - to_curses_attr(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) def draw_group(self, y, group, colored): @@ -202,7 +206,8 @@ class RosterWin(Win): else: self.addstr(y, 0, '[-] ') contacts = " (%s/%s)" % (group.get_nb_connected_contacts(), len(group)) - self.addstr(y, 4, self.truncate_name(group.name, len(contacts)+4) + contacts) + self.addstr( + y, 4, self.truncate_name(group.name, len(contacts) + 4) + contacts) if colored: self._win.attroff(to_curses_attr(get_theme().COLOR_SELECTED_ROW)) self.finish_line() @@ -212,8 +217,14 @@ class RosterWin(Win): return name return name[:self.width - added - 1] + '…' - def draw_contact_line(self, y, contact, colored, group, show_roster_sub=False, - show_s2s_errors=True, show_roster_jids=False): + def draw_contact_line(self, + y, + contact, + colored, + group, + show_roster_sub=False, + show_s2s_errors=True, + show_roster_jids=False): """ Draw on a line all information about one contact. This is basically the highest priority resource's information @@ -255,37 +266,51 @@ class RosterWin(Win): added += len(get_theme().CHAR_ROSTER_ACTIVITY) if contact.gaming: added += len(get_theme().CHAR_ROSTER_GAMING) - if show_roster_sub in ('all', 'incomplete', 'to', 'from', 'both', 'none'): - added += len(theme.char_subscription(contact.subscription, keep=show_roster_sub)) + if show_roster_sub in ('all', 'incomplete', 'to', 'from', 'both', + 'none'): + added += len( + theme.char_subscription( + contact.subscription, keep=show_roster_sub)) if not show_roster_jids and contact.name: display_name = '%s' % contact.name elif contact.name and contact.name != contact.bare_jid: display_name = '%s (%s)' % (contact.name, contact.bare_jid) else: - display_name = '%s' % (contact.bare_jid,) + display_name = '%s' % (contact.bare_jid, ) display_name = self.truncate_name(display_name, added) + nb if colored: - self.addstr(display_name, to_curses_attr(get_theme().COLOR_SELECTED_ROW)) + self.addstr(display_name, + to_curses_attr(get_theme().COLOR_SELECTED_ROW)) else: self.addstr(display_name) - if show_roster_sub in ('all', 'incomplete', 'to', 'from', 'both', 'none'): - self.addstr(theme.char_subscription(contact.subscription, keep=show_roster_sub), to_curses_attr(theme.COLOR_ROSTER_SUBSCRIPTION)) + if show_roster_sub in ('all', 'incomplete', 'to', 'from', 'both', + 'none'): + self.addstr( + theme.char_subscription( + 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(get_theme().CHAR_ROSTER_ASKED, + to_curses_attr(get_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(get_theme().CHAR_ROSTER_ERROR, + to_curses_attr(get_theme().COLOR_ROSTER_ERROR)) if contact.tune: - self.addstr(get_theme().CHAR_ROSTER_TUNE, to_curses_attr(get_theme().COLOR_ROSTER_TUNE)) + self.addstr(get_theme().CHAR_ROSTER_TUNE, + to_curses_attr(get_theme().COLOR_ROSTER_TUNE)) if contact.activity: - self.addstr(get_theme().CHAR_ROSTER_ACTIVITY, to_curses_attr(get_theme().COLOR_ROSTER_ACTIVITY)) + self.addstr(get_theme().CHAR_ROSTER_ACTIVITY, + to_curses_attr(get_theme().COLOR_ROSTER_ACTIVITY)) if contact.mood: - self.addstr(get_theme().CHAR_ROSTER_MOOD, to_curses_attr(get_theme().COLOR_ROSTER_MOOD)) + self.addstr(get_theme().CHAR_ROSTER_MOOD, + to_curses_attr(get_theme().COLOR_ROSTER_MOOD)) if contact.gaming: - self.addstr(get_theme().CHAR_ROSTER_GAMING, to_curses_attr(get_theme().COLOR_ROSTER_GAMING)) + self.addstr(get_theme().CHAR_ROSTER_GAMING, + to_curses_attr(get_theme().COLOR_ROSTER_GAMING)) self.finish_line() def draw_resource_line(self, y, resource, colored): @@ -295,7 +320,9 @@ class RosterWin(Win): color = get_theme().color_show(resource.presence) self.addstr(y, 4, get_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)) + self.addstr(y, 8, + self.truncate_name(str(resource.jid), 6), + to_curses_attr(get_theme().COLOR_SELECTED_ROW)) else: self.addstr(y, 8, self.truncate_name(str(resource.jid), 6)) self.finish_line() @@ -308,6 +335,7 @@ class RosterWin(Win): return self.roster_cache[self.pos] return None + class ContactInfoWin(Win): def draw_contact_info(self, contact): """ @@ -319,23 +347,27 @@ class ContactInfoWin(Win): elif resource: jid = resource.jid else: - jid = 'example@example.com' # should never happen + jid = 'example@example.com' # should never happen if resource: presence = resource.presence else: presence = 'unavailable' i = 0 - self.addstr(0, 0, '%s (%s)'%(jid, presence,), to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + self.addstr(0, 0, '%s (%s)' % ( + jid, + presence, + ), to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) self.finish_line(get_theme().COLOR_INFORMATION_BAR) i += 1 - self.addstr(i, 0, 'Subscription: %s' % (contact.subscription,)) + self.addstr(i, 0, 'Subscription: %s' % (contact.subscription, )) self.finish_line() i += 1 if contact.ask: if contact.ask == 'asked': - self.addstr(i, 0, 'Ask: %s' % (contact.ask,), to_curses_attr(get_theme().COLOR_IMPORTANT_TEXT)) + self.addstr(i, 0, 'Ask: %s' % (contact.ask, ), + to_curses_attr(get_theme().COLOR_IMPORTANT_TEXT)) else: - self.addstr(i, 0, 'Ask: %s' % (contact.ask,)) + self.addstr(i, 0, 'Ask: %s' % (contact.ask, )) self.finish_line() i += 1 if resource: @@ -344,27 +376,34 @@ class ContactInfoWin(Win): i += 1 if contact.error: - self.addstr(i, 0, 'Error: %s' % contact.error, to_curses_attr(get_theme().COLOR_ROSTER_ERROR)) + self.addstr(i, 0, 'Error: %s' % contact.error, + to_curses_attr(get_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)) + self.addstr(i, 0, + 'Tune: %s' % common.format_tune_string(contact.tune), + to_curses_attr(get_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)) + self.addstr(i, 0, 'Mood: %s' % contact.mood, + to_curses_attr(get_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)) + self.addstr(i, 0, 'Activity: %s' % contact.activity, + to_curses_attr(get_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)) + self.addstr( + i, 0, 'Game: %s' % common.format_gaming_string(contact.gaming), + to_curses_attr(get_theme().COLOR_NORMAL_TEXT)) self.finish_line() i += 1 @@ -372,7 +411,8 @@ class ContactInfoWin(Win): """ draw the group information """ - self.addstr(0, 0, group.name, to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + self.addstr(0, 0, group.name, + to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) self.finish_line(get_theme().COLOR_INFORMATION_BAR) def refresh(self, selected_row): -- cgit v1.2.3