From 28ce49dcaaa1f7e958e09aff2af7d1e956796ad9 Mon Sep 17 00:00:00 2001 From: mathieui Date: Fri, 29 Jun 2018 21:18:09 +0200 Subject: Update poezio for the new tabs module --- poezio/tabs/adhoc_commands_list.py | 2 +- poezio/tabs/basetabs.py | 17 +++------ poezio/tabs/bookmarkstab.py | 8 ++-- poezio/tabs/confirmtab.py | 5 ++- poezio/tabs/conversationtab.py | 5 ++- poezio/tabs/listtab.py | 5 ++- poezio/tabs/muclisttab.py | 2 +- poezio/tabs/muctab.py | 75 +++++++++++++++++++------------------- poezio/tabs/privatetab.py | 20 +++++----- poezio/tabs/rostertab.py | 20 +++++----- poezio/tabs/xmltab.py | 12 +++--- 11 files changed, 89 insertions(+), 82 deletions(-) (limited to 'poezio/tabs') diff --git a/poezio/tabs/adhoc_commands_list.py b/poezio/tabs/adhoc_commands_list.py index a1b186be..fecfc9e2 100644 --- a/poezio/tabs/adhoc_commands_list.py +++ b/poezio/tabs/adhoc_commands_list.py @@ -58,7 +58,7 @@ class AdhocCommandsListTab(ListTab): for item in get_items()] self.listview.set_lines(items) self.info_header.message = 'Ad-hoc commands of JID %s' % self.name - if self.core.current_tab() is self: + if self.core.tabs.current_tab is self: self.refresh() else: self.state = 'highlight' diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index 13c54c27..8cca8606 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -92,6 +92,7 @@ class Tab(object): def __init__(self, core): self.core = core + self.nb = 0 if not hasattr(self, 'name'): self.name = self.__class__.__name__ self.input = None @@ -108,13 +109,6 @@ class Tab(object): def size(self): return self.core.size - @property - def nb(self): - for index, tab in enumerate(self.core.tabs): - if tab == self: - return index - return len(self.core.tabs) - @staticmethod def tab_win_height(): """ @@ -293,8 +287,8 @@ class Tab(object): if self.missing_command_callback is not None: error_handled = self.missing_command_callback(low) if not error_handled: - self.core.information("Unknown command (%s)" % - (command), 'Error') + self.core.information( + "Unknown command (%s)" % (command), 'Error') if command in ('correct', 'say'): # hack arg = xhtml.convert_simple_to_full_colors(arg) else: @@ -685,8 +679,9 @@ class ChatTab(Tab): 'paused') self.core.add_timed_event(new_event) self.timed_event_paused = new_event - new_event = timed_events.DelayedEvent(30, self.send_chat_state, - 'inactive' if self.inactive else 'active') + new_event = timed_events.DelayedEvent( + 30, self.send_chat_state, 'inactive' + if self.inactive else 'active') self.core.add_timed_event(new_event) self.timed_event_not_paused = new_event diff --git a/poezio/tabs/bookmarkstab.py b/poezio/tabs/bookmarkstab.py index ceccc99d..1ee623c5 100644 --- a/poezio/tabs/bookmarkstab.py +++ b/poezio/tabs/bookmarkstab.py @@ -25,7 +25,8 @@ class BookmarksTab(Tab): self.new_bookmarks = [] self.removed_bookmarks = [] self.header_win = windows.ColumnHeaderWin( - ('name', 'room@server/nickname', 'password', 'autojoin', 'storage')) + ('name', 'room@server/nickname', 'password', 'autojoin', + 'storage')) self.bookmarks_win = windows.BookmarksWin( self.bookmarks, self.height - 4, self.width, 1, 0) self.help_win = windows.HelpText('Ctrl+Y: save, Ctrl+G: cancel, ' @@ -77,8 +78,9 @@ class BookmarksTab(Tab): if not self.bookmarks[bm.jid]: self.bookmarks.append(bm) else: - self.core.information('Invalid JID for bookmark: %s/%s' % - (bm.jid, bm.nick), 'Error') + self.core.information( + 'Invalid JID for bookmark: %s/%s' % (bm.jid, bm.nick), + 'Error') return for bm in self.removed_bookmarks: diff --git a/poezio/tabs/confirmtab.py b/poezio/tabs/confirmtab.py index 28c26122..545bb761 100644 --- a/poezio/tabs/confirmtab.py +++ b/poezio/tabs/confirmtab.py @@ -106,8 +106,9 @@ class ConfirmTab(Tab): def on_info_win_size_changed(self): if self.core.information_win_size >= self.height - 3: return - self.dialog.resize(self.height - 3 - self.core.information_win_size - - Tab.tab_win_height(), self.width, 1, 0) + self.dialog.resize( + self.height - 3 - self.core.information_win_size - + Tab.tab_win_height(), self.width, 1, 0) self.infowin_bottom.resize( 1, self.width, self.height - 2 - self.core.information_win_size - Tab.tab_win_height(), 0) diff --git a/poezio/tabs/conversationtab.py b/poezio/tabs/conversationtab.py index a8a22b4a..e93fe1e3 100644 --- a/poezio/tabs/conversationtab.py +++ b/poezio/tabs/conversationtab.py @@ -376,8 +376,9 @@ class ConversationTab(OneToOneTab): def on_info_win_size_changed(self): if self.core.information_win_size >= self.height - 3: return - self.text_win.resize(self.height - 3 - self.core.information_win_size - - Tab.tab_win_height(), self.width, 1, 0) + self.text_win.resize( + self.height - 3 - self.core.information_win_size - + Tab.tab_win_height(), self.width, 1, 0) self.get_info_header().resize( 1, self.width, self.height - 2 - self.core.information_win_size - Tab.tab_win_height(), 0) diff --git a/poezio/tabs/listtab.py b/poezio/tabs/listtab.py index 84dcc38b..1c96f778 100644 --- a/poezio/tabs/listtab.py +++ b/poezio/tabs/listtab.py @@ -173,8 +173,9 @@ class ListTab(Tab): self.info_header.resize( 1, self.width, self.height - 2 - self.core.information_win_size - Tab.tab_win_height(), 0) - self.listview.resize(self.height - 3 - self.core.information_win_size - - Tab.tab_win_height(), self.width, 1, 0) + self.listview.resize( + self.height - 3 - self.core.information_win_size - + Tab.tab_win_height(), self.width, 1, 0) def on_lose_focus(self): self.state = 'normal' diff --git a/poezio/tabs/muclisttab.py b/poezio/tabs/muclisttab.py index e12d24ee..6ba7816d 100644 --- a/poezio/tabs/muclisttab.py +++ b/poezio/tabs/muclisttab.py @@ -59,7 +59,7 @@ class MucListTab(ListTab): for item in get_items()] self.listview.set_lines(items) self.info_header.message = 'Chatroom list on server %s' % self.name - if self.core.current_tab() is self: + if self.core.tabs.current_tab is self: self.refresh() else: self.state = 'highlight' diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index 70d66ffb..246606e3 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -193,9 +193,9 @@ class MucTab(ChatTab): valid_affiliations = ('outcast', 'none', 'member', 'admin', 'owner') if affiliation not in valid_affiliations: - return self.core.information('The affiliation must be one of ' + - ', '.join(valid_affiliations), - 'Error') + return self.core.information( + 'The affiliation must be one of ' + + ', '.join(valid_affiliations), 'Error') if nick_or_jid in [user.nick for user in self.users]: muc.set_user_affiliation( self.core.xmpp, @@ -220,8 +220,9 @@ class MucTab(ChatTab): def callback(iq): if iq['type'] == 'error': - self.core.information("Could not set role '%s' for '%s'." % - (role, nick), "Warning") + self.core.information( + "Could not set role '%s' for '%s'." % (role, nick), + "Warning") valid_roles = ('none', 'visitor', 'participant', 'moderator') @@ -281,10 +282,8 @@ class MucTab(ChatTab): user = self.get_user_by_name(self.topic_from) if user: user_text = dump_tuple(user.color) - user_string = '\x19%s}(set by \x19%s}%s\x19%s})' % (info_text, - user_text, - user.nick, - info_text) + user_string = '\x19%s}(set by \x19%s}%s\x19%s})' % ( + info_text, user_text, user.nick, info_text) else: user_string = self.topic_from else: @@ -430,7 +429,7 @@ class MucTab(ChatTab): self.handle_presence_joined(presence, status_codes) except PresenceError: self.core.room_error(presence, presence['from'].bare) - if self.core.current_tab() is self: + if self.core.tabs.current_tab is self: self.text_win.refresh() self.user_win.refresh_if_changed(self.users) self.info_header.refresh(self, self.text_win, user=self.own_user) @@ -454,9 +453,9 @@ class MucTab(ChatTab): # Enable the self ping event, to regularly check if we # are still in the room. self.enable_self_ping_event() - if self.core.current_tab() is not self: + if self.core.tabs.current_tab is not self: self.refresh_tab_win() - self.core.current_tab().refresh_input() + self.core.tabs.current_tab.refresh_input() self.core.doupdate() def handle_presence_unjoined(self, presence, deterministic, own=False): @@ -488,9 +487,9 @@ class MucTab(ChatTab): if self.name in self.core.initial_joins: self.core.initial_joins.remove(self.name) self._state = 'normal' - elif self != self.core.current_tab(): + elif self != self.core.tabs.current_tab: self._state = 'joined' - if (self.core.current_tab() is self + if (self.core.tabs.current_tab is self and self.core.status.show not in ('xa', 'away')): self.send_chat_state('active') new_user.color = get_theme().COLOR_OWN_NICK @@ -650,8 +649,8 @@ class MucTab(ChatTab): self.core.on_user_rejoined_private_conversation(self.name, from_nick) def on_user_nick_change(self, presence, user, from_nick, from_room): - new_nick = presence.xml.find('{%s}x/{%s}item' % - (NS_MUC_USER, NS_MUC_USER)).attrib['nick'] + new_nick = presence.xml.find( + '{%s}x/{%s}item' % (NS_MUC_USER, NS_MUC_USER)).attrib['nick'] old_color = user.color if user.nick == self.own_nick: self.own_nick = new_nick @@ -722,7 +721,7 @@ class MucTab(ChatTab): self.core.disable_private_tabs(self.name, reason=kick_msg) self.disconnect() self.refresh_tab_win() - self.core.current_tab().refresh_input() + self.core.tabs.current_tab.refresh_input() if config.get_by_tabname('autorejoin', self.general_jid): delay = config.get_by_tabname('autorejoin_delay', self.general_jid) @@ -800,7 +799,7 @@ class MucTab(ChatTab): self.core.disable_private_tabs(self.name, reason=kick_msg) self.disconnect() self.refresh_tab_win() - self.core.current_tab().refresh_input() + self.core.tabs.current_tab.refresh_input() # try to auto-rejoin if config.get_by_tabname('autorejoin', self.general_jid): delay = config.get_by_tabname('autorejoin_delay', @@ -959,9 +958,8 @@ class MucTab(ChatTab): role != user.role): # display the message in the room self._text_buffer.add_message(msg) - self.core.on_user_changed_status_in_private('%s/%s' % (from_room, - from_nick), - Status(show, status)) + self.core.on_user_changed_status_in_private( + '%s/%s' % (from_room, from_nick), Status(show, status)) self.users.remove(user) # finally, effectively change the user status user.update(affiliation, show, status, role) @@ -974,7 +972,7 @@ class MucTab(ChatTab): """ self.presence_buffer = [] self.users = [] - if self is not self.core.current_tab(): + if self is not self.core.tabs.current_tab: self.state = 'disconnected' self.joined = False self.disable_self_ping_event() @@ -1178,8 +1176,9 @@ class MucTab(ChatTab): info_win_height = self.core.information_win_size self.user_win.resize( - self.height - 3 - info_win_height - tab_win_height, self.width - - (self.width // 10) * 9 - 1, 1, (self.width // 10) * 9 + 1) + self.height - 3 - info_win_height - tab_win_height, + self.width - (self.width // 10) * 9 - 1, 1, + (self.width // 10) * 9 + 1) self.v_separator.resize( self.height - 3 - info_win_height - tab_win_height, 1, 1, 9 * (self.width // 10)) @@ -1223,15 +1222,16 @@ class MucTab(ChatTab): text_width = self.width else: text_width = (self.width // 10) * 9 - self.user_win.resize(self.height - 3 - self.core.information_win_size - - Tab.tab_win_height(), - self.width - (self.width // 10) * 9 - 1, 1, - (self.width // 10) * 9 + 1) + self.user_win.resize( + self.height - 3 - self.core.information_win_size - + Tab.tab_win_height(), self.width - (self.width // 10) * 9 - 1, 1, + (self.width // 10) * 9 + 1) self.v_separator.resize( self.height - 3 - self.core.information_win_size - Tab.tab_win_height(), 1, 1, 9 * (self.width // 10)) - self.text_win.resize(self.height - 3 - self.core.information_win_size - - Tab.tab_win_height(), text_width, 1, 0) + self.text_win.resize( + self.height - 3 - self.core.information_win_size - + Tab.tab_win_height(), text_width, 1, 0) self.info_header.resize( 1, self.width, self.height - 2 - self.core.information_win_size - Tab.tab_win_height(), 0) @@ -1329,8 +1329,9 @@ class MucTab(ChatTab): nick = args[0] color = args[1].lower() if nick == self.own_nick: - return self.core.information("You cannot change the color of your" - " own nick.", 'Error') + return self.core.information( + "You cannot change the color of your" + " own nick.", 'Error') elif color not in xhtml.colors and color not in ('unset', 'random'): return self.core.information("Unknown color: %s" % color, 'Error') self.set_nick_color(nick, color) @@ -1375,7 +1376,7 @@ class MucTab(ChatTab): """ message = args[0] self.leave_room(message) - if self == self.core.current_tab(): + if self == self.core.tabs.current_tab: self.refresh() self.core.doupdate() @@ -1405,7 +1406,7 @@ class MucTab(ChatTab): r = self.core.open_private_window(self.name, user.nick) if r and len(args) == 2: msg = args[1] - self.core.current_tab().command_say( + self.core.tabs.current_tab.command_say( xhtml.convert_simple_to_full_colors(msg)) if not r: self.core.information("Cannot find user: %s" % nick, 'Error') @@ -1446,9 +1447,9 @@ class MucTab(ChatTab): affiliation = aff.get(user.affiliation, get_theme().CHAR_AFFILIATION_NONE) color = colors.get(user.role, color_other) - buff.append('\x19%s}%s\x19o\x19%s}%s\x19o' % - (color, affiliation, dump_tuple(user.color), - user.nick)) + buff.append( + '\x19%s}%s\x19o\x19%s}%s\x19o' % + (color, affiliation, dump_tuple(user.color), user.nick)) buff.append('\n') message = ' '.join(buff) diff --git a/poezio/tabs/privatetab.py b/poezio/tabs/privatetab.py index d0a12232..bc7f31c7 100644 --- a/poezio/tabs/privatetab.py +++ b/poezio/tabs/privatetab.py @@ -60,7 +60,8 @@ class PrivateTab(OneToOneTab): 'Get the software version of the current interlocutor (usually its XMPP client and Operating System).', shortdesc='Get the software version of a jid.') self.resize() - self.parent_muc = self.core.get_tab_by_name(safeJID(name).bare, MucTab) + self.parent_muc = self.core.tabs.by_name_and_class( + safeJID(name).bare, MucTab) self.on = True self.update_commands() self.update_keys() @@ -275,7 +276,7 @@ class PrivateTab(OneToOneTab): empty_after = self.input.get_text() == '' or ( self.input.get_text().startswith('/') and not self.input.get_text().startswith('//')) - tab = self.core.get_tab_by_name(safeJID(self.name).bare, MucTab) + tab = self.core.tabs.by_name_and_class(safeJID(self.name).bare, MucTab) if tab and tab.joined: self.send_composing_chat_state(empty_after) return False @@ -288,7 +289,7 @@ class PrivateTab(OneToOneTab): self.text_win.remove_line_separator() self.text_win.add_line_separator(self._text_buffer) - tab = self.core.get_tab_by_name(safeJID(self.name).bare, MucTab) + tab = self.core.tabs.by_name_and_class(safeJID(self.name).bare, MucTab) if tab and tab.joined and config.get_by_tabname( 'send_chat_states', self.general_jid) and self.on: self.send_chat_state('inactive') @@ -297,7 +298,7 @@ class PrivateTab(OneToOneTab): def on_gain_focus(self): self.state = 'current' curses.curs_set(1) - tab = self.core.get_tab_by_name(safeJID(self.name).bare, MucTab) + tab = self.core.tabs.by_name_and_class(safeJID(self.name).bare, MucTab) if tab and tab.joined and config.get_by_tabname( 'send_chat_states', self.general_jid, @@ -307,8 +308,9 @@ class PrivateTab(OneToOneTab): def on_info_win_size_changed(self): if self.core.information_win_size >= self.height - 3: return - self.text_win.resize(self.height - 2 - self.core.information_win_size - - Tab.tab_win_height(), self.width, 0, 0) + self.text_win.resize( + self.height - 2 - self.core.information_win_size - + Tab.tab_win_height(), self.width, 0, 0) self.info_header.resize( 1, self.width, self.height - 2 - self.core.information_win_size - Tab.tab_win_height(), 0) @@ -333,7 +335,7 @@ class PrivateTab(OneToOneTab): typ=2) new_jid = safeJID(self.name).bare + '/' + user.nick self.name = new_jid - return self.core.current_tab() is self + return self.core.tabs.current_tab is self @refresh_wrapper.conditional def user_left(self, status_message, user): @@ -371,7 +373,7 @@ class PrivateTab(OneToOneTab): 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT) }, typ=2) - return self.core.current_tab() is self + return self.core.tabs.current_tab is self @refresh_wrapper.conditional def user_rejoined(self, nick): @@ -397,7 +399,7 @@ class PrivateTab(OneToOneTab): 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT) }, typ=2) - return self.core.current_tab() is self + return self.core.tabs.current_tab is self def activate(self, reason=None): self.on = True diff --git a/poezio/tabs/rostertab.py b/poezio/tabs/rostertab.py index c079d550..5e10cb52 100644 --- a/poezio/tabs/rostertab.py +++ b/poezio/tabs/rostertab.py @@ -271,8 +271,9 @@ class RosterInfoTab(Tab): if not certs: return self.core.information('No certificates found', 'Info') msg = 'Certificates:\n' - msg += '\n'.join(((' %s%s' % (item[0] + (': ' if item[1] else ''), - item[1])) for item in certs)) + msg += '\n'.join( + ((' %s%s' % (item[0] + (': ' if item[1] else ''), item[1])) + for item in certs)) self.core.information(msg, 'Info') self.core.xmpp.plugin['xep_0257'].get_certs(callback=cb, timeout=3) @@ -702,8 +703,8 @@ class RosterInfoTab(Tab): return jid = safeJID(safeJID(args[0]).bare) if not str(jid): - self.core.information('The provided JID (%s) is not valid' % - (args[0], ), 'Error') + self.core.information( + 'The provided JID (%s) is not valid' % (args[0], ), 'Error') return if jid in roster and roster[jid].subscription in ('to', 'both'): return self.core.information('Already subscribed.', 'Roster') @@ -1146,7 +1147,7 @@ class RosterInfoTab(Tab): def reset_help_message(self, _=None): self.input = self.default_help_message - if self.core.current_tab() is self: + if self.core.tabs.current_tab is self: curses.curs_set(0) self.input.refresh() self.core.doupdate() @@ -1266,8 +1267,9 @@ class RosterInfoTab(Tab): acc.append('Contact: %s (%s)' % (cont.bare_jid, res.presence if res else 'unavailable')) if res: - acc.append('%s connected resource%s' % - (len(cont), '' if len(cont) == 1 else 's')) + acc.append( + '%s connected resource%s' % (len(cont), '' + if len(cont) == 1 else 's')) acc.append('Current status: %s' % res.status) if cont.tune: acc.append('Tune: %s' % common.format_tune_string(cont.tune)) @@ -1276,8 +1278,8 @@ class RosterInfoTab(Tab): if cont.activity: acc.append('Activity: %s' % cont.activity) if cont.gaming: - acc.append('Game: %s' % - (common.format_gaming_string(cont.gaming))) + acc.append( + 'Game: %s' % (common.format_gaming_string(cont.gaming))) msg = '\n'.join(acc) elif isinstance(selected_row, Resource): res = selected_row diff --git a/poezio/tabs/xmltab.py b/poezio/tabs/xmltab.py index 223b6667..af091f68 100644 --- a/poezio/tabs/xmltab.py +++ b/poezio/tabs/xmltab.py @@ -261,8 +261,9 @@ class XMLTab(Tab): xml = self.filtered_buffer.messages[:] else: xml = self.core_buffer.messages[:] - text = '\n'.join(('%s %s %s' % (msg.str_time, msg.nickname, - clean_text(msg.txt)) for msg in xml)) + text = '\n'.join( + ('%s %s %s' % (msg.str_time, msg.nickname, clean_text(msg.txt)) + for msg in xml)) filename = os.path.expandvars(os.path.expanduser(args[0])) try: with open(filename, 'w') as fd: @@ -285,7 +286,7 @@ class XMLTab(Tab): def reset_help_message(self, _=None): if self.closed: return True - if self.core.current_tab() is self: + if self.core.tabs.current_tab is self: curses.curs_set(0) self.input = self.default_help_message return True @@ -375,8 +376,9 @@ class XMLTab(Tab): def on_info_win_size_changed(self): if self.core.information_win_size >= self.height - 3: return - self.text_win.resize(self.height - 2 - self.core.information_win_size - - Tab.tab_win_height(), self.width, 0, 0) + self.text_win.resize( + self.height - 2 - self.core.information_win_size - + Tab.tab_win_height(), self.width, 0, 0) self.info_header.resize( 1, self.width, self.height - 2 - self.core.information_win_size - Tab.tab_win_height(), 0) -- cgit v1.2.3