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
|
# -*- python -*-
from common import *
class MyCG(Entry):
def __init__(self, title, command, cg_class, *args, priority = None, **kwargs):
self.title = title
self.cg_class = cg_class
rule = '::'.join(cg_class.split('::')[2:])
self.start_command = [command, '-R', rule]
if priority is not None:
self.start_command.extend(['-p', str(priority)])
self.stop_command = [command, '-R', rule, '-x']
Entry.__init__(self, *args, **kwargs)
def action(self, col, button, x, y):
proc = subprocess.Popen(['cg-query', '-c', '?'], stdout = subprocess.PIPE)
output = []
while True:
chunk = proc.stdout.read(128)
if not chunk:
break
output.append(chunk)
proc.stdout.close()
proc.wait()
output = b''.join(output).decode('utf-8', 'replace')
crtcs = output.split('\n')
output = []
for crtc in crtcs:
if not crtc:
continue
proc = subprocess.Popen(['cg-query', '-c', crtc], stdout = subprocess.PIPE)
while True:
chunk = proc.stdout.read(128)
if not chunk:
break
output.append(chunk)
proc.stdout.close()
proc.wait()
output = b''.join(output).decode('utf-8', 'replace')
active = ('\n Class: %s\n' % self.cg_class) in output
del output
print(active)
print(repr(self.stop_command if active else self.start_command))
subprocess.Popen(self.stop_command if active else self.start_command).wait()
def function(self):
return self.title
class MyCGNegative(MyCG):
def __init__(self, *args, title = 'Negative', rule = 'xpybar', priority = None, **kwargs):
MyCG.__init__(self, title, 'cg-negative', 'cg-tools::cg-negative::' + rule, *args, priority = priority, **kwargs)
|