blob: 40621833ceb747384a1fe0dd20dbbf98df5f2da2 [file] [log] [blame]
# Copyright 2016 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""The Queue object of key-press events and chameleon events to display UI."""
from queue import Queue
import threading
# Global queue object for LCM UI finite state machine.
LcmEventQueue = Queue()
class LcmEventError(Exception):
"""Exception raise when any unexpected behavior happened on LcmEvent."""
class LcmEvent(object):
"""A event class of LcmEventQueue for LcmFsm processing."""
def __init__(self, notice, key_index=None):
"""Constructs a LcmEvent object.
notice: The string of notice.
key_index: The index of pressed key event. None if this event is not a
key-press event.
self.notice = notice
self._key_index = key_index
self._event = threading.Event()
def Clear(self):
"""Resets the internal flag to false of event."""
def Set(self):
"""Sets the internal flag to true of event."""
def Wait(self):
"""Waits until the internal flag of event is true."""
def IsKeyPressed(self):
"""Checks whether this is key-press event.
True if this is key-press event; otherwise False.
return bool(self._key_index)
def GetKeyIndex(self):
"""Gets key index and Sets the event internal flag to true."""
if not self.IsKeyPressed():
raise LcmEventError('GetKeyIndex() error, this is not key event!!')
return self._key_index