# Path: pylash/core.py
# class Object(object):
# 	'''
# 	Base class of other classes in `pylash`, providing fundamental interfaces for `pylash` objects.
# 	'''
# 	
# 	latestObjectIndex = 0
# 	'''
# 	The ID number of the last instantiated `pylash` object. It also represents the number of
# 	instantiated `pylash` objects. Note: it is .
# 
# 	Type: `int`, read-only
# 	'''
# 
# 	def __init__(self):
# 		self.objectIndex = Object.latestObjectIndex
# 		'''
# 		The unique ID number of the object.
# 
# 		Type: `int`, read-only
# 		'''
# 
# 		self.name = "instance" + str(self.objectIndex)
# 		'''
# 		The name of the object. Default: `"instance" + str(self.objectIndex)`.
# 
# 		Type: `str`
# 		'''
# 
# 		Object.latestObjectIndex += 1
# 
# 	def _nonCopyableAttrs(self):
# 		return ["objectIndex", "name"]
# 	
# 	def copyFrom(self, source):
# 		'''
# 		Copies all instance attributes from `source` to self. The `source` should have the same
# 		type with selves, or be an object instantiated from the parent classes of the self class.
# 
# 		Parameters
# 		----------
# 		source : pylash.core.Object
# 			The source object to be copied from.
# 		
# 		'''
# 
# 		if not source or not isinstance(self, source.__class__):
# 			raise TypeError("Object.copyFrom(source): cannot copy from the parameter 'source'.")
# 		
# 		noncopyable = self._nonCopyableAttrs()
# 		attrs = source.__dict__
# 		for attr_name in attrs:
# 			if attr_name in noncopyable:
# 				continue
# 			
# 			setattr(self, attr_name, attrs[attr_name])
# 
# def removeItemsInList(theList, condition):
# 	if not hasattr(condition, "__call__") or not isinstance(theList, list):
# 		return
# 
# 	targetList = []
# 
# 	for o in theList:
# 		if condition(o):
# 			targetList.append(o)
# 
# 	for i in targetList:
# 		theList.remove(i)
# 
# 	return targetList


from .core import Object, removeItemsInList
	KEY_UP = Event("key_up")

	def __init__(self):
		raise Exception("KeyboardEvent cannot be instantiated.")


class EventDispatcher(Object):
	def __init__(self):
		super(EventDispatcher, self).__init__()
		
		self._eventList = []

	def __isEventTypeEqual(self, e1, e2):
		e1 = Event(e1)
		e2 = Event(e2)
		return e1.eventType == e2.eventType

	def _addEventListenerInList(self, e, listener, eventList):
		eventList.append({
			"eventType" : e,
			"listener" : listener
		})

	def _removeEventListenerInList(self, e, listener, eventList):
		def condition(o):
			t = o["eventType"]
			l = o["listener"]

			return (l == listener and self.__isEventTypeEqual(e, t))


# Path: pylash/core.py
# class Object(object):
# 	'''
# 	Base class of other classes in `pylash`, providing fundamental interfaces for `pylash` objects.
# 	'''
# 	
# 	latestObjectIndex = 0
# 	'''
# 	The ID number of the last instantiated `pylash` object. It also represents the number of
# 	instantiated `pylash` objects. Note: it is .
# 
# 	Type: `int`, read-only
# 	'''
# 
# 	def __init__(self):
# 		self.objectIndex = Object.latestObjectIndex
# 		'''
# 		The unique ID number of the object.
# 
# 		Type: `int`, read-only
# 		'''
# 
# 		self.name = "instance" + str(self.objectIndex)
# 		'''
# 		The name of the object. Default: `"instance" + str(self.objectIndex)`.
# 
# 		Type: `str`
# 		'''
# 
# 		Object.latestObjectIndex += 1
# 
# 	def _nonCopyableAttrs(self):
# 		return ["objectIndex", "name"]
# 	
# 	def copyFrom(self, source):
# 		'''
# 		Copies all instance attributes from `source` to self. The `source` should have the same
# 		type with selves, or be an object instantiated from the parent classes of the self class.
# 
# 		Parameters
# 		----------
# 		source : pylash.core.Object
# 			The source object to be copied from.
# 		
# 		'''
# 
# 		if not source or not isinstance(self, source.__class__):
# 			raise TypeError("Object.copyFrom(source): cannot copy from the parameter 'source'.")
# 		
# 		noncopyable = self._nonCopyableAttrs()
# 		attrs = source.__dict__
# 		for attr_name in attrs:
# 			if attr_name in noncopyable:
# 				continue
# 			
# 			setattr(self, attr_name, attrs[attr_name])
# 
# def removeItemsInList(theList, condition):
# 	if not hasattr(condition, "__call__") or not isinstance(theList, list):
# 		return
# 
# 	targetList = []
# 
# 	for o in theList:
# 		if condition(o):
# 			targetList.append(o)
# 
# 	for i in targetList:
# 		theList.remove(i)
# 
# 	return targetList


# Path: pylash/events.py
from .core import Object, removeItemsInList

	KEY_UP = Event("key_up")

	def __init__(self):
		raise Exception("KeyboardEvent cannot be instantiated.")


class EventDispatcher(Object):
	def __init__(self):
		super(EventDispatcher, self).__init__()
		
		self._eventList = []

	def __isEventTypeEqual(self, e1, e2):
		e1 = Event(e1)
		e2 = Event(e2)
		return e1.eventType == e2.eventType

	def _addEventListenerInList(self, e, listener, eventList):
		eventList.append({
			"eventType" : e,
			"listener" : listener
		})

	def _removeEventListenerInList(self, e, listener, eventList):
		def condition(o):
			t = o["eventType"]
			l = o["listener"]

			return (l == listener and self.__isEventTypeEqual(e, t))


		removeItemsInList(eventList, condition)