[core/input] __ for private variables, use id as property

This commit is contained in:
tobi-wan-kenobi 2020-03-29 14:43:04 +02:00
parent 428b627daf
commit 95410e4adf
4 changed files with 11 additions and 13 deletions

View file

@ -22,22 +22,19 @@ callbacks = {}
class Object(object): class Object(object):
def __init__(self): def __init__(self):
super(Object, self).__init__() super(Object, self).__init__()
self._id = str(uuid.uuid4()) self.id = str(uuid.uuid4())
def id(self):
return self._id
def register(obj, button=None, cmd=None): def register(obj, button=None, cmd=None):
logging.debug('registering callback {} {}'.format(obj.id(), button)) logging.debug('registering callback {} {}'.format(obj.id, button))
callbacks.setdefault(obj.id(), {}).setdefault(button, []).append(cmd) callbacks.setdefault(obj.id, {}).setdefault(button, []).append(cmd)
def trigger(event): def trigger(event):
for field in ['instance', 'name']: for field in ['instance', 'name']:
if field in event: if field in event:
cb = callbacks.get(event[field]) 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 callback: return
if not 'button' in event: return if not 'button' in event: return

View file

@ -65,8 +65,8 @@ class i3(object):
'border_left': self._theme.border_left(), 'border_left': self._theme.border_left(),
'border_right': self._theme.border_right(), 'border_right': self._theme.border_right(),
'border_bottom': self._theme.border_bottom(), 'border_bottom': self._theme.border_bottom(),
'instance': widget.id(), 'instance': widget.id,
'name': module.id(), 'name': module.id,
} }
def __separator(self, module, widget): def __separator(self, module, widget):
@ -109,7 +109,7 @@ class i3(object):
def update(self, affected_modules=None): def update(self, affected_modules=None):
now = time.time() now = time.time()
for module in self._modules: 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 continue
if not affected_modules and module.next_update: if not affected_modules and module.next_update:
if now < module.next_update: if now < module.next_update:

View file

@ -34,3 +34,4 @@
- theme: `load` vs. `__load` vs. `load_keywords` - theme: `load` vs. `__load` vs. `load_keywords`
- themes: use colors to improve theme readability - themes: use colors to improve theme readability
- brightness: read from CLI tools - brightness: read from CLI tools
- input: use events?

View file

@ -6,8 +6,8 @@ class config(unittest.TestCase):
def setUp(self): def setUp(self):
self.inputObject = core.input.Object() self.inputObject = core.input.Object()
self.anotherObject = core.input.Object() self.anotherObject = core.input.Object()
self.someEvent = { 'button': core.input.LEFT_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.anotherEvent = { 'button': core.input.RIGHT_MOUSE, 'instance': self.inputObject.id}
self.callback = unittest.mock.MagicMock() self.callback = unittest.mock.MagicMock()
self.callback2 = unittest.mock.MagicMock() self.callback2 = unittest.mock.MagicMock()
self.someCommand = 'some sample command' self.someCommand = 'some sample command'