diff --git a/core/input.py b/core/input.py index 18042e8..cc450c7 100644 --- a/core/input.py +++ b/core/input.py @@ -22,22 +22,19 @@ callbacks = {} class Object(object): def __init__(self): super(Object, self).__init__() - self._id = str(uuid.uuid4()) - - def id(self): - return self._id + self.id = str(uuid.uuid4()) def register(obj, button=None, cmd=None): - logging.debug('registering callback {} {}'.format(obj.id(), button)) - callbacks.setdefault(obj.id(), {}).setdefault(button, []).append(cmd) + logging.debug('registering callback {} {}'.format(obj.id, button)) + callbacks.setdefault(obj.id, {}).setdefault(button, []).append(cmd) def trigger(event): for field in ['instance', 'name']: if field in event: cb = callbacks.get(event[field]) - _invoke(event, cb) + __invoke(event, cb) -def _invoke(event, callback): +def __invoke(event, callback): if not callback: return if not 'button' in event: return diff --git a/core/output.py b/core/output.py index 6e84cc1..f93f7c1 100644 --- a/core/output.py +++ b/core/output.py @@ -65,8 +65,8 @@ class i3(object): 'border_left': self._theme.border_left(), 'border_right': self._theme.border_right(), 'border_bottom': self._theme.border_bottom(), - 'instance': widget.id(), - 'name': module.id(), + 'instance': widget.id, + 'name': module.id, } def __separator(self, module, widget): @@ -109,7 +109,7 @@ class i3(object): def update(self, affected_modules=None): now = time.time() for module in self._modules: - if affected_modules and not module.id() in affected_modules: + if affected_modules and not module.id in affected_modules: continue if not affected_modules and module.next_update: if now < module.next_update: diff --git a/doc/NOTES.md b/doc/NOTES.md index fc32cff..4440fe5 100644 --- a/doc/NOTES.md +++ b/doc/NOTES.md @@ -34,3 +34,4 @@ - theme: `load` vs. `__load` vs. `load_keywords` - themes: use colors to improve theme readability - brightness: read from CLI tools +- input: use events? diff --git a/tests/core/test_input.py b/tests/core/test_input.py index c9f2ff8..e469543 100644 --- a/tests/core/test_input.py +++ b/tests/core/test_input.py @@ -6,8 +6,8 @@ class config(unittest.TestCase): def setUp(self): self.inputObject = core.input.Object() self.anotherObject = core.input.Object() - self.someEvent = { 'button': core.input.LEFT_MOUSE, 'instance': self.inputObject.id() } - self.anotherEvent = { 'button': core.input.RIGHT_MOUSE, 'instance': self.inputObject.id() } + self.someEvent = { 'button': core.input.LEFT_MOUSE, 'instance': self.inputObject.id } + self.anotherEvent = { 'button': core.input.RIGHT_MOUSE, 'instance': self.inputObject.id} self.callback = unittest.mock.MagicMock() self.callback2 = unittest.mock.MagicMock() self.someCommand = 'some sample command'