[core/output] Start implementation of a partial update
Add a "patch()" method that eventually will only update affected modules.
This commit is contained in:
parent
cc0139e517
commit
5810a12944
2 changed files with 15 additions and 11 deletions
|
@ -11,13 +11,14 @@ import core.output
|
||||||
import core.module
|
import core.module
|
||||||
import core.input
|
import core.input
|
||||||
|
|
||||||
def handle_input():
|
def handle_input(output):
|
||||||
poll = select.poll()
|
poll = select.poll()
|
||||||
poll.register(sys.stdin.fileno(), select.POLLIN)
|
poll.register(sys.stdin.fileno(), select.POLLIN)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
events = poll.poll()
|
events = poll.poll()
|
||||||
|
|
||||||
|
modules = {}
|
||||||
for fileno, event in events:
|
for fileno, event in events:
|
||||||
line = '['
|
line = '['
|
||||||
while line.startswith('['):
|
while line.startswith('['):
|
||||||
|
@ -26,8 +27,11 @@ def handle_input():
|
||||||
try:
|
try:
|
||||||
event = json.loads(line)
|
event = json.loads(line)
|
||||||
core.input.trigger(event)
|
core.input.trigger(event)
|
||||||
|
if 'name' in event:
|
||||||
|
modules[event['name']] = True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
output.draw('patch', modules.keys())
|
||||||
|
|
||||||
poll.unregister(sys.stdin.fileno())
|
poll.unregister(sys.stdin.fileno())
|
||||||
|
|
||||||
|
@ -42,7 +46,7 @@ def main():
|
||||||
output = core.output.i3()
|
output = core.output.i3()
|
||||||
modules = []
|
modules = []
|
||||||
|
|
||||||
input_thread = threading.Thread(target=handle_input)
|
input_thread = threading.Thread(target=handle_input, args=(output,))
|
||||||
input_thread.daemon = True
|
input_thread.daemon = True
|
||||||
input_thread.start()
|
input_thread.start()
|
||||||
|
|
||||||
|
@ -51,7 +55,6 @@ def main():
|
||||||
output.modules(modules)
|
output.modules(modules)
|
||||||
output.draw('start')
|
output.draw('start')
|
||||||
while True:
|
while True:
|
||||||
output.clear()
|
|
||||||
for module in modules:
|
for module in modules:
|
||||||
module.update()
|
module.update()
|
||||||
output.draw('statusline')
|
output.draw('statusline')
|
||||||
|
|
|
@ -5,15 +5,16 @@ import time
|
||||||
class i3(object):
|
class i3(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._modules = []
|
self._modules = []
|
||||||
self.clear()
|
self._status = []
|
||||||
|
|
||||||
def modules(self, modules=None):
|
def modules(self, modules=None):
|
||||||
if not modules:
|
if not modules:
|
||||||
return self._modules
|
return self._modules
|
||||||
self._modules = modules if isinstance(modules, list) else [ modules ]
|
self._modules = modules if isinstance(modules, list) else [ modules ]
|
||||||
|
|
||||||
def draw(self, what):
|
def draw(self, what, args=None):
|
||||||
data = getattr(self, what)()
|
cb = getattr(self, what)
|
||||||
|
data = cb(args) if args else cb()
|
||||||
if 'data' in data:
|
if 'data' in data:
|
||||||
sys.stdout.write(json.dumps(data['data']))
|
sys.stdout.write(json.dumps(data['data']))
|
||||||
if 'suffix' in data:
|
if 'suffix' in data:
|
||||||
|
@ -30,20 +31,20 @@ class i3(object):
|
||||||
def stop(self):
|
def stop(self):
|
||||||
return { 'suffix': '\n]' }
|
return { 'suffix': '\n]' }
|
||||||
|
|
||||||
def clear(self):
|
def patch(self, affected_modules):
|
||||||
self._statusline = []
|
pass # TODO
|
||||||
|
|
||||||
def statusline(self):
|
def statusline(self):
|
||||||
status = []
|
self._status = []
|
||||||
for module in self._modules:
|
for module in self._modules:
|
||||||
for widget in module.widgets():
|
for widget in module.widgets():
|
||||||
status.append({
|
self._status.append({
|
||||||
'full_text': widget.full_text(),
|
'full_text': widget.full_text(),
|
||||||
'instance': widget.id(),
|
'instance': widget.id(),
|
||||||
'name': module.id(),
|
'name': module.id(),
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
'data': status,
|
'data': self._status,
|
||||||
'suffix': ','
|
'suffix': ','
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue