-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabs.py
71 lines (54 loc) · 1.89 KB
/
tabs.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
__kupfer_name__ = _("SearchTabs")
__kupfer_actions__ = ("SearchTabs", "TabActivation", )
__description__ = _("Browser Tabs")
__version__ = "2024.2"
__author__ = "Thorsten Mueller"
import subprocess
from time import sleep
from kupfer.obj import Leaf, Action, Source, TextLeaf
class SearchTabs(Action):
def __init__(self):
Action.__init__(self, _("SearchTabs"))
def is_factory(self):
return True
def activate(self, leaf, iobj=None, ctx=None):
return TabLeaf(leaf.object)
def item_types(self):
yield TextLeaf
def get_description(self):
return _("Tabs")
def get_icon_name(self):
return "web-browser"
class TabLeaf(Source):
def __init__(self, query):
Source.__init__(self, name=_("Results for '%s'") % query)
self.text = query
def repr_key(self):
return self.text
def get_items(self):
command = ("brotab index")
p1 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
command = ("brotab search '%s'" % self.text)
p1 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
out, ignored_err = p1.communicate()
for t in out.split(b'\n'):
if t != b'':
k = t.decode('UTF-8').split('\t')
yield TabEntry(k[0], k[1])
class TabEntry (Leaf):
def __init__(self, tabid, name):
self.tabid = tabid
super().__init__(tabid, name)
def get_actions(self):
yield TabActivation()
def get_icon_name(self):
return "web-browser"
class TabActivation(Action):
def __init__(self):
super().__init__(_("Activate Tab"))
def activate(self, leaf):
command = ("brotab activate %s" % leaf.tabid)
p1 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
out, ignored_err = p1.communicate()
def get_icon_name(self):
return "go-jump"