blob: c1d1ec8b9604a112620d80a6b7c6440aa1c86727 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
"""
``close_all`` plugin: close all tabs except chatrooms and the contact list.
Commands
--------
.. glossary::
/closeall
**Usage:** ``/closeall``
Close all tabs except the roster and chatroom tabs.
"""
from poezio.plugin import BasePlugin
from poezio import tabs
from poezio.decorators import command_args_parser
class Plugin(BasePlugin):
def init(self):
self.api.add_command(
'closeall',
self.command_closeall,
help='Close all non-chatroom tabs.')
@command_args_parser.ignored
def command_closeall(self):
"""
/closeall
"""
current = self.api.current_tab()
if not isinstance(current, (tabs.RosterInfoTab, tabs.MucTab)):
self.core.go_to_roster()
current = self.api.current_tab()
def filter_func(x):
return not isinstance(x, (tabs.RosterInfoTab, tabs.MucTab))
matching_tabs = list(filter(filter_func, self.core.tabs.get_tabs()))
length = len(matching_tabs)
for tab in matching_tabs:
self.core.close_tab(tab)
self.api.information('%s tabs closed.' % length, 'Info')
self.core.refresh_window()
|