Skip to content

Commit

Permalink
Simplify logic for matching providers for calibration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Biddle authored and tshirtman committed Oct 5, 2018
1 parent e37e935 commit d12a24d
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions kivy/input/postproc/calibration.py
Expand Up @@ -100,33 +100,30 @@ def __init__(self):

def _get_provider_map(self):
"""Iterates through all registered input provider names and finds the
respective MotionEvent subclass for each. Returns a dict of provider
names mapped to their MotionEvent subclass.
respective MotionEvent subclass for each. Returns a dict of MotionEvent
subclasses mapped to their provider name.
"""
provider_map = {}
for input_provider in MotionEventFactory.list():
if not hasattr(providers, input_provider):
continue

p = getattr(providers, input_provider)
events = []
for m in p.__all__:
attr = getattr(p, m)
if issubclass(attr, MotionEvent):
events.append(attr)
if events:
provider_map[input_provider] = events
event = getattr(p, m)
if issubclass(event, MotionEvent):
provider_map[event] = input_provider

return provider_map

def _get_provider_key(self, event):
"""Idenitifes the provider name of a MotionEvent and returns the
corresponding key in self.devices if it exists.
"""Returns the provider key for the event if the provider is configured
for calibration.
"""
for input_type, ev_class in self.provider_map.items():
key = '({})'.format(input_type)
for ec in ev_class:
if isinstance(event, ec) and key in self.devices:
return key
input_type = self.provider_map.get(event.__class__)
key = '({})'.format(input_type)
if input_type and key in self.devices:
return key

def process(self, events):
# avoid doing any processing if there is no device to calibrate at all.
Expand Down

0 comments on commit d12a24d

Please sign in to comment.