[core/input] Remove "valid input required" logic from input

Accidentially committed a experimental way to enforce waiting for a
valid input, mainly for testing.

see #23
This commit is contained in:
Tobi-wan Kenobi 2016-12-10 18:22:05 +01:00
parent 12f5ce5977
commit 8f6bb7b45d

View file

@ -28,12 +28,10 @@ def read_input(inp):
try:
event = json.loads(line)
inp.callback(event)
inp.has_valid_event = True
inp.redraw()
except ValueError:
pass
inp.has_event = True
inp.has_valid_event = True
inp.clean_exit = True
class I3BarInput(object):
@ -44,15 +42,12 @@ class I3BarInput(object):
self.clean_exit = False
self.global_id = str(uuid.uuid4())
self.need_event = False
self.need_valid_event = False
self.has_event = False
self.has_valid_event = False
self._condition = threading.Condition()
def start(self):
"""Start asynchronous input processing"""
self.has_event = False
self.has_valid_event = False
self.running = True
self._condition.acquire()
self._thread = threading.Thread(target=read_input, args=(self,))
@ -70,20 +65,16 @@ class I3BarInput(object):
def wait(self, timeout):
self._condition.wait(timeout)
def _wait(self, valid=False):
def _wait(self):
while not self.has_event:
time.sleep(0.1)
if valid:
while not self.has_valid_event:
time.sleep(0.1)
self.has_event = False
self.has_valid_event = False
def stop(self):
"""Stop asynchronous input processing"""
self._condition.release()
if self.need_event:
self._wait(self.need_valid_event)
self._wait()
self.running = False
self._thread.join()
return self.clean_exit