[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:
parent
12f5ce5977
commit
8f6bb7b45d
1 changed files with 2 additions and 11 deletions
|
@ -28,12 +28,10 @@ def read_input(inp):
|
||||||
try:
|
try:
|
||||||
event = json.loads(line)
|
event = json.loads(line)
|
||||||
inp.callback(event)
|
inp.callback(event)
|
||||||
inp.has_valid_event = True
|
|
||||||
inp.redraw()
|
inp.redraw()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
inp.has_event = True
|
inp.has_event = True
|
||||||
inp.has_valid_event = True
|
|
||||||
inp.clean_exit = True
|
inp.clean_exit = True
|
||||||
|
|
||||||
class I3BarInput(object):
|
class I3BarInput(object):
|
||||||
|
@ -44,15 +42,12 @@ class I3BarInput(object):
|
||||||
self.clean_exit = False
|
self.clean_exit = False
|
||||||
self.global_id = str(uuid.uuid4())
|
self.global_id = str(uuid.uuid4())
|
||||||
self.need_event = False
|
self.need_event = False
|
||||||
self.need_valid_event = False
|
|
||||||
self.has_event = False
|
self.has_event = False
|
||||||
self.has_valid_event = False
|
|
||||||
self._condition = threading.Condition()
|
self._condition = threading.Condition()
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Start asynchronous input processing"""
|
"""Start asynchronous input processing"""
|
||||||
self.has_event = False
|
self.has_event = False
|
||||||
self.has_valid_event = False
|
|
||||||
self.running = True
|
self.running = True
|
||||||
self._condition.acquire()
|
self._condition.acquire()
|
||||||
self._thread = threading.Thread(target=read_input, args=(self,))
|
self._thread = threading.Thread(target=read_input, args=(self,))
|
||||||
|
@ -70,20 +65,16 @@ class I3BarInput(object):
|
||||||
def wait(self, timeout):
|
def wait(self, timeout):
|
||||||
self._condition.wait(timeout)
|
self._condition.wait(timeout)
|
||||||
|
|
||||||
def _wait(self, valid=False):
|
def _wait(self):
|
||||||
while not self.has_event:
|
while not self.has_event:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
if valid:
|
|
||||||
while not self.has_valid_event:
|
|
||||||
time.sleep(0.1)
|
|
||||||
self.has_event = False
|
self.has_event = False
|
||||||
self.has_valid_event = False
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
"""Stop asynchronous input processing"""
|
"""Stop asynchronous input processing"""
|
||||||
self._condition.release()
|
self._condition.release()
|
||||||
if self.need_event:
|
if self.need_event:
|
||||||
self._wait(self.need_valid_event)
|
self._wait()
|
||||||
self.running = False
|
self.running = False
|
||||||
self._thread.join()
|
self._thread.join()
|
||||||
return self.clean_exit
|
return self.clean_exit
|
||||||
|
|
Loading…
Reference in a new issue