[core/input] Separate module/widget update and retrieval
To make it easier to update individual modules, separate the call to update() and the call to actually drawing the status. Additionally, this avoids the "side effect" of updating when drawing the status line.
This commit is contained in:
parent
5810a12944
commit
4e2a645bd3
3 changed files with 15 additions and 14 deletions
|
@ -31,7 +31,8 @@ def handle_input(output):
|
||||||
modules[event['name']] = True
|
modules[event['name']] = True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
output.draw('patch', modules.keys())
|
output.update(modules.keys())
|
||||||
|
output.draw('statusline')
|
||||||
|
|
||||||
poll.unregister(sys.stdin.fileno())
|
poll.unregister(sys.stdin.fileno())
|
||||||
|
|
||||||
|
@ -55,8 +56,7 @@ def main():
|
||||||
output.modules(modules)
|
output.modules(modules)
|
||||||
output.draw('start')
|
output.draw('start')
|
||||||
while True:
|
while True:
|
||||||
for module in modules:
|
output.update()
|
||||||
module.update()
|
|
||||||
output.draw('statusline')
|
output.draw('statusline')
|
||||||
output.wait(config.interval())
|
output.wait(config.interval())
|
||||||
output.draw('stop')
|
output.draw('stop')
|
||||||
|
|
|
@ -5,7 +5,7 @@ import time
|
||||||
class i3(object):
|
class i3(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._modules = []
|
self._modules = []
|
||||||
self._status = []
|
self._status = {}
|
||||||
|
|
||||||
def modules(self, modules=None):
|
def modules(self, modules=None):
|
||||||
if not modules:
|
if not modules:
|
||||||
|
@ -31,20 +31,23 @@ class i3(object):
|
||||||
def stop(self):
|
def stop(self):
|
||||||
return { 'suffix': '\n]' }
|
return { 'suffix': '\n]' }
|
||||||
|
|
||||||
def patch(self, affected_modules):
|
def update(self, affected_modules=None):
|
||||||
pass # TODO
|
|
||||||
|
|
||||||
def statusline(self):
|
|
||||||
self._status = []
|
|
||||||
for module in self._modules:
|
for module in self._modules:
|
||||||
|
module.update()
|
||||||
|
self._status[module] = []
|
||||||
for widget in module.widgets():
|
for widget in module.widgets():
|
||||||
self._status.append({
|
self._status[module].append({
|
||||||
'full_text': widget.full_text(),
|
'full_text': widget.full_text(),
|
||||||
'instance': widget.id(),
|
'instance': widget.id(),
|
||||||
'name': module.id(),
|
'name': module.id(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def statusline(self):
|
||||||
|
widgets = []
|
||||||
|
for module in self._modules:
|
||||||
|
widgets += self._status[module]
|
||||||
return {
|
return {
|
||||||
'data': self._status,
|
'data': widgets,
|
||||||
'suffix': ','
|
'suffix': ','
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,6 @@ class i3(unittest.TestCase):
|
||||||
widget.full_text.return_value = "test"
|
widget.full_text.return_value = "test"
|
||||||
self.someModule = TestModule(widgets=[widget, widget, widget])
|
self.someModule = TestModule(widgets=[widget, widget, widget])
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_start(self):
|
def test_start(self):
|
||||||
all_data = self.i3.start()
|
all_data = self.i3.start()
|
||||||
data = all_data['data']
|
data = all_data['data']
|
||||||
|
@ -52,6 +49,7 @@ class i3(unittest.TestCase):
|
||||||
|
|
||||||
def test_statusline(self):
|
def test_statusline(self):
|
||||||
self.i3.modules([ self.someModule, self.someModule, self.someModule ])
|
self.i3.modules([ self.someModule, self.someModule, self.someModule ])
|
||||||
|
self.i3.update()
|
||||||
data = self.i3.statusline()
|
data = self.i3.statusline()
|
||||||
self.assertEqual(len(self.someModule.widgets())*3, len(data['data']), 'wrong number of widgets')
|
self.assertEqual(len(self.someModule.widgets())*3, len(data['data']), 'wrong number of widgets')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue