diff options
author | mathieui <mathieui@mathieui.net> | 2014-04-30 20:37:18 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2014-04-30 20:37:18 +0200 |
commit | d859ec2ea19654603075b556094c6b59aad8e73a (patch) | |
tree | e9c84ee768c0edb24f4f49695154eb8bad4f4e18 | |
parent | 4e4ab569cf07fabf76339eeace1f6694f3414eff (diff) | |
download | poezio-d859ec2ea19654603075b556094c6b59aad8e73a.tar.gz poezio-d859ec2ea19654603075b556094c6b59aad8e73a.tar.bz2 poezio-d859ec2ea19654603075b556094c6b59aad8e73a.tar.xz poezio-d859ec2ea19654603075b556094c6b59aad8e73a.zip |
Add a 'tab_change' event
-rw-r--r-- | doc/source/dev/events.rst | 6 | ||||
-rw-r--r-- | src/core/core.py | 3 | ||||
-rw-r--r-- | src/events.py | 2 |
3 files changed, 11 insertions, 0 deletions
diff --git a/doc/source/dev/events.rst b/doc/source/dev/events.rst index dda25561..7092d66b 100644 --- a/doc/source/dev/events.rst +++ b/doc/source/dev/events.rst @@ -7,6 +7,12 @@ The following events are poezio-only events, for SleekXMPP events, check out .. glossary:: :sorted: + tab_change + - **old_tab_nb:** :py:class:`int` Old current tab number. + - **new_tab_nb:** :py:class:`int` New current tab number. + + Triggered whenever the user switches between tabs. + muc_say - **message:** :py:class:`~sleekxmpp.Message` that will be sent - **tab:** :py:class:`~tabs.MucTab` source diff --git a/src/core/core.py b/src/core/core.py index 19eb9b16..4ffb0213 100644 --- a/src/core/core.py +++ b/src/core/core.py @@ -1098,12 +1098,15 @@ class Core(object): Prevents the tab number from going over the total number of opened tabs, or under 0 """ + old = self._current_tab_nb if value >= len(self.tabs): self._current_tab_nb = 0 elif value < 0: self._current_tab_nb = len(self.tabs) - 1 else: self._current_tab_nb = value + if old != self._current_tab_nb: + self.events.trigger('tab_change', old, self._current_tab_nb) ### Opening actions ### diff --git a/src/events.py b/src/events.py index 71687d14..50711022 100644 --- a/src/events.py +++ b/src/events.py @@ -45,6 +45,7 @@ class EventHandler(object): 'muc_ban': [], 'send_normal_presence': [], 'ignored_private': [], + 'tab_change': [], } def add_event_handler(self, name, callback, position=0): @@ -72,6 +73,7 @@ class EventHandler(object): if callbacks is None: log.debug('%s: No such event.', name) return + log.debug('Event %s triggered, callbacks: %s', name, callbacks) for callback in callbacks: callback(*args, **kwargs) |