From c6cf2d08b7295a477d89d01535463d18103f6311 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 22 Jul 2018 16:17:06 +0200 Subject: Fix close_all and change_title plugins --- poezio/core/core.py | 10 +++++----- poezio/core/tabs.py | 31 +++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 13 deletions(-) (limited to 'poezio/core') diff --git a/poezio/core/core.py b/poezio/core/core.py index 480bf814..fffb5fb0 100644 --- a/poezio/core/core.py +++ b/poezio/core/core.py @@ -95,7 +95,11 @@ class Core: self.xml_tab = None self.xml_buffer = TextBuffer() - self.tabs = Tabs() + self.plugins_autoloaded = False + self.plugin_manager = PluginManager(self) + self.events = events.EventHandler() + + self.tabs = Tabs(self.events) self.previous_tab_nb = 0 own_nick = config.get('default_nick') @@ -104,10 +108,6 @@ class Core: own_nick = own_nick or 'poezio' self.own_nick = own_nick - self.plugins_autoloaded = False - self.plugin_manager = PluginManager(self) - self.events = events.EventHandler() - self.size = SizeManager(self) # Set to True whenever we consider that we have been disconnected diff --git a/poezio/core/tabs.py b/poezio/core/tabs.py index de5c44b8..e9646959 100644 --- a/poezio/core/tabs.py +++ b/poezio/core/tabs.py @@ -27,6 +27,7 @@ disabled. from typing import List, Dict, Type, Optional, Union from collections import defaultdict from poezio import tabs +from poezio.events import EventHandler class Tabs: @@ -34,11 +35,16 @@ class Tabs: Tab list class """ __slots__ = [ - '_current_index', '_current_tab', '_tabs', '_tab_types', '_tab_names', - '_previous_tab' + '_current_index', + '_current_tab', + '_tabs', + '_tab_types', + '_tab_names', + '_previous_tab', + '_events', ] - def __init__(self): + def __init__(self, events: EventHandler): """ Initialize the Tab List. Even though the list is initially empty, all methods are only valid once append() has been called @@ -53,6 +59,7 @@ class Tabs: self._tab_types = defaultdict( list) # type: Dict[Type[tabs.Tab], List[tabs.Tab]] self._tab_names = dict() # type: Dict[str, tabs.Tab] + self._events = events # type: EventHandler def __len__(self): return len(self._tabs) @@ -78,11 +85,7 @@ class Tabs: """Set the current tab index""" if 0 <= value < len(self._tabs): tab = self._tabs[value] - if not isinstance(tab, tabs.GapTab): - self._store_previous() - self._current_index = tab.nb - self._current_tab = tab - return True + return self.set_current_tab(tab) return False @property @@ -97,6 +100,10 @@ class Tabs: self._store_previous() self._current_index = tab.nb self._current_tab = tab + self._events.trigger( + 'tab_change', + old_tab=self._previous_tab, + new_tab=self._current_tab) return True return False @@ -170,6 +177,10 @@ class Tabs: self._inc_cursor() while isinstance(self.current_tab, tabs.GapTab): self._inc_cursor() + self._events.trigger( + 'tab_change', + old_tab=self._previous_tab, + new_tab=self._current_tab) def prev(self): """Go to the left of the tab list (circular)""" @@ -177,6 +188,10 @@ class Tabs: self._dec_cursor() while isinstance(self.current_tab, tabs.GapTab): self._dec_cursor() + self._events.trigger( + 'tab_change', + old_tab=self._previous_tab, + new_tab=self._current_tab) def append(self, tab: tabs.Tab): """ -- cgit v1.2.3