class Object(object):
class CanvasWidget(QtWidgets.QWidget):
class Stage(Object):
class KeyCode(object):
class UnityOfDictAndClass(object):
	def __init__(self):
	def _nonCopyableAttrs(self):
	def copyFrom(self, source):
	def __init__(self):
	def paintEvent(self, event):
	def mousePressEvent(self, event):
	def mouseMoveEvent(self, event):
	def mouseReleaseEvent(self, event):
	def mouseDoubleClickEvent(self, event):
	def keyPressEvent(self, event):
	def keyReleaseEvent(self, event):
	def __enterKeyboardEvent(self, event, eventType):
	def __enterMouseEvent(self, event, eventType):
	def __init__(self):
	def copyFrom(self, source):
	def _setCanvas(self, speed, title, width, height):
	def _onShow(self):
	def _showDisplayList(self, childList):
	def _enterMouseEvent(self, event, cd):
	def setFrameRate(self, speed):
	def addChild(self, child):
	def removeChild(self, child):
	def addEventListener(self, e, listener):
	def removeEventListener(self, e, listener = None):
	def __init__(self):
	def __init__(self):
	def set(obj, key, value):
	def get(obj, key):
	def has(obj, key):
def init(speed, title, width, height, callback):
def addChild(child):
def removeChild(child):
def getColor(color):
def removeItemsInList(theList, condition):
	PARENT = "stage_parent_root" class LoadManage(Object):
	delay = 50
	IMAGE_EXTENSION = ["png", "jpg", "jpeg", "bmp", "gif"]
	MEDIA_EXTENSION = [
		"aif", "cda", "mid", "midi", "mp3", "mpa", "wav", "ogg", "wma", "m4a",
		"avi", "flv", "m4v", "mkv", "mov", "mp4", "mpg", "mpeg", "swf", "vob", "wmv"
	]

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

	@staticmethod
	def load(loadList, onUpdate = None, onComplete = None):
		worker = LoadManageWorker()
		worker.load(loadList, onUpdate, onComplete) class MouseEvent(object):
	MOUSE_DOWN = Event("mouse_down")
	MOUSE_UP = Event("mouse_up")
	MOUSE_MOVE = Event("mouse_move")
	MOUSE_OVER = Event("mouse_over")
	MOUSE_OUT = Event("mouse_out")
	DOUBLE_CLICK = Event("mouse_dbclick")

	def __init__(self):
		raise Exception("MouseEvent cannot be instantiated.") class LoopEvent(object):
	ENTER_FRAME = Event("loop_enter_frame")
	EXIT_FRAME = Event("loop_exit_frame") class Sprite(DisplayObjectContainer):
	def __init__(self):
		super(Sprite, self).__init__()

		self.graphics = Graphics()
		self.graphics.parent = self
		self.useHandCursor = False
		self.shapes = None
		self._clipPath = self.graphics._clipPath
		self._loopEventList = []

	def _loopDraw(self, c):
		self.graphics._show(c)

		stage._showDisplayList(self.childList)

	def _loopFrame(self, e):
		self.dispatchEvent(e)

	def startX(self):
		left = self.graphics.startX()

		for o in self.childList:
			sx = o.startX()

			if sx < left:
				left = sx
		
		return left + self.x

	def startY(self):
		top = self.graphics.startY()

		for o in self.childList:
			sy = o.startY()

			if sy < top:
				top = sy
		
		return top + self.y

	def endX(self):
		right = self.graphics.endX()

		for o in self.childList:
			ex = o.endX()

			if ex > right:
				right = ex
		
		return right + self.x

	def endY(self):
		bottom = self.graphics.endY()

		for o in self.childList:
			ey = o.endY()

			if ey > bottom:
				bottom = ey
		
		return bottom + self.y

	def __getVisualCoordinate(self, origin, obj):
		return {
			"x" : origin["x"] + obj.x * origin["scaleX"],
			"y" : origin["y"] + obj.y * origin["scaleY"],
			"scaleX" : origin["scaleX"] * obj.scaleX,
			"scaleY" : origin["scaleY"] * obj.scaleY
		}

	def _isMouseOn(self, e, cd):
		if not self.visible:
			return

		childList = self.childList[::-1]
		
		if not self._hasMask():
			for o in childList:
				childCd = self.__getVisualCoordinate(cd, o)

				if o._isMouseOn(e, childCd):
					o._mouseIsOn = True

					e["target"] = o

					return True
				else:
					o._mouseIsOn = False

			graphicsCd = self.__getVisualCoordinate(cd, self.graphics)

			if (self.graphics._isMouseOn(e, graphicsCd)):
				self.graphics._mouseIsOn = True

				e["target"] = self.graphics

				return True
			else:
				self.graphics._mouseIsOn = False
		else:
			return self.mask._isMouseOn(e, cd)

		return False

	def _enterMouseEvent(self, e, cd, hasBeenOn = False):
		if not self.visible:
			return

		currentCd = self.__getVisualCoordinate(cd, self)

		isOn = hasBeenOn

		if not hasBeenOn:
			isOn = self._isMouseOn(e, currentCd)

		if isOn:
			if self.useHandCursor:
				stage._useHandCursor = True

			if e["eventType"] == MouseEvent.MOUSE_MOVE.eventType and not self._mouseOver:
				self._mouseOver = True

				e["eventType"] = MouseEvent.MOUSE_OVER.eventType

				self.__dispatchMouseEvent(e, currentCd)

				e["eventType"] = MouseEvent.MOUSE_MOVE.eventType

			if self.mouseChildren:
				for o in self.childList[::-1]:
					if (hasattr(o, "_enterMouseEvent") and hasattr(o._enterMouseEvent, "__call__") and o._enterMouseEvent(e, currentCd, o._mouseIsOn)):
						if e["eventType"] != MouseEvent.MOUSE_MOVE.eventType:
							break
						
			self.__dispatchMouseEvent(e, currentCd)

			if self.mouseShelter:
				return True
			else:
				return False
		elif e["eventType"] == MouseEvent.MOUSE_MOVE.eventType and self._mouseOver:
			self._mouseOutEvent(e, cd)

		return False

	def _mouseOutEvent(self, e, cd):
		if not self.visible:
			return

		currentCd = self.__getVisualCoordinate(cd, self)

		stage._useHandCursor = False

		self._mouseOver = False

		if self.mouseChildren:
			for o in self.childList[::-1]:
				if (hasattr(o, "_mouseOutEvent") and hasattr(o._mouseOutEvent, "__call__") and o._mouseOutEvent(e, currentCd)):
					break

		e["eventType"] = MouseEvent.MOUSE_OUT.eventType

		self.__dispatchMouseEvent(e, currentCd)

		e["eventType"] = MouseEvent.MOUSE_MOVE.eventType

	def __dispatchMouseEvent(self, e, cd):
		if not self.mouseEnabled:
			return

		eve = Event(e["eventType"])
		eve.offsetX = e["offsetX"]
		eve.offsetY = e["offsetY"]
		eve.selfX = (e["offsetX"] - cd["x"]) / cd["scaleX"]
		eve.selfY = (e["offsetY"] - cd["y"]) / cd["scaleY"]
		eve.target = e["target"]
		eve.currentTarget = self
		self.dispatchEvent(eve)

	def _getOriginalWidth(self):
		return self.endX() - self.startX()

	def _getOriginalHeight(self):
		return self.endY() - self.startY()

	def addShape(self, sh):
		if not isinstance(self.shapes, list):
			self.shapes = []

		if isinstance(sh, Rectangle):
			sh = Polygon(sh)

		self.shapes.append(sh)

	def clearShapes(self):
		self.shapes = None

	def hitTestObject(self, obj):
		shListA = None
		shListB = None
		mA = self.getRootMatrix()
		mB = obj.getRootMatrix()

		if not isinstance(self.shapes, list):
			shListA = [Polygon(Rectangle(0, 0, self._getOriginalWidth(), self._getOriginalHeight()))]
		else:
			shListA = self.shapes

		if not isinstance(obj.shapes, list):
			shListB = [Polygon(Rectangle(0, 0, obj._getOriginalWidth(), obj._getOriginalHeight()))]
		else:
			shListB = obj.shapes

		for itm in shListA:
			shA = itm.getTransform(mA)

			for ite in shListB:
				shB = ite.getTransform(mB)

				if SAT.hitTest(shA, shB):
					return True

		return False
	
	def __isLoopEvent(self, e):
		e = Event(e)
		return e.eventType.find("loop_") == 0

	def addEventListener(self, e, listener):
		if self.__isLoopEvent(e):
			self._addEventListenerInList(e, listener, self._loopEventList)
		else:
			super(Sprite, self).addEventListener(e, listener)

	def removeEventListener(self, e, listener):
		if self.__isLoopEvent(e):
			self._removeEventListenerInList(e, listener, self._loopEventList)
		else:
			super(Sprite, self).removeEventListener(e, listener)

	def removeAllEventListeners(self):
		self._loopEventList = []

		super(Sprite, self).removeAllEventListeners()

	def dispatchEvent(self, e):
		if self.__isLoopEvent(e):
			self._dispatchEventInList(e, self._loopEventList)
		else:
			super(Sprite, self).dispatchEvent(e)

	def hasEventListener(self, e, listener):
		if self.__isLoopEvent(e):
			return self._hasEventListenerInList(e, listener, self._loopEventList)
		else:
			return super(Sprite, self).hasEventListener(e, listener) class TextField(DisplayObject):
	def __init__(self):
		super(TextField, self).__init__()

		self.text = ""
		self.font = "Arial"
		self.size = 15
		self.textColor = "#000000"
		self.backgroundColor = None
		self.italic = False
		self.weight = TextFormatWeight.NORMAL
		self.textAlign = TextFormatAlign.LEFT
		self.textBaseline = TextFormatBaseline.TOP
		
	def _getOriginalWidth(self):
		font = self.__getFont()
		fontMetrics = QtGui.QFontMetrics(font)

		return fontMetrics.width(str(self.text))

	def _getOriginalHeight(self):
		font = self.__getFont()
		fontMetrics = QtGui.QFontMetrics(font)

		return fontMetrics.height()

	def __getFont(self):
		weight = self.weight

		if self.weight == TextFormatWeight.NORMAL:
			weight = QtGui.QFont.Normal
		elif self.weight == TextFormatWeight.BOLD:
			weight = QtGui.QFont.Bold
		elif self.weight == TextFormatWeight.BOLDER:
			weight = QtGui.QFont.Black
		elif self.weight == TextFormatWeight.LIGHTER:
			weight = QtGui.QFont.Light

		font = QtGui.QFont()
		font.setFamily(self.font)
		font.setPixelSize(self.size)
		font.setWeight(weight)
		font.setItalic(self.italic)

		return font

	def __getTextStartX(self):
		w = self._getOriginalWidth()

		if self.textAlign == TextFormatAlign.END or self.textAlign == TextFormatAlign.RIGHT:
			return -w
		elif self.textAlign == TextFormatAlign.CENTER:
			return -w / 2
		else:
			return 0

	def __getTextStartY(self):
		h = self._getOriginalHeight()

		if self.textBaseline == TextFormatBaseline.ALPHABETIC or self.textBaseline == TextFormatBaseline.MIDDLE:
			return -h
		elif self.textBaseline == TextFormatBaseline.MIDDLE:
			return -h / 2
		else:
			return 0

	def _loopDraw(self, c):
		font = self.__getFont()
		flags = QtCore.Qt.AlignCenter
		startX = self.__getTextStartX()
		startY = self.__getTextStartY()
		width = self._getOriginalWidth()
		height = self._getOriginalHeight()

		pen = QtGui.QPen()
		pen.setBrush(QtGui.QBrush(getColor(self.textColor)))

		if self.backgroundColor:
			brush = QtGui.QBrush()
			brush.setColor(getColor(self.backgroundColor))
			brush.setStyle(QtCore.Qt.SolidPattern)
			c.setBrush(brush)

			c.setPen(getColor("transparent"))

			c.drawRect(startX, startY, width, height)

		c.setFont(font)
		c.setPen(pen)
		c.drawText(startX, startY, width, height, flags, str(self.text)) class LoadingSample1(LoadingSample):
	def __init__(self, **opt):
		bg = None

		if "background" in opt:
			bg = opt["background"]

		super(LoadingSample1, self).__init__(bg)
		
		if not "background" in opt:
			self.background.graphics.beginFill("black")
			self.background.graphics.drawRect(0, 0, stage.width, stage.height)
			self.background.graphics.endFill()

		if not "vacantColor" in opt:
			opt["vacantColor"] = "white"

		if not "numberWidth" in opt:
			opt["numberWidth"] = stage.width * 0.1

		if not "numberHeight" in opt:
			opt["numberHeight"] = opt["numberWidth"] / 0.6

		self.__blockWidth = opt["numberWidth"] / 3
		self.__blockHeight = opt["numberHeight"] / 5
		self.progressBarWidth = self.__blockHeight * 7.5
		self.progressBarTotalHeight = self.__blockHeight * 5

		if not "progressColor" in opt:
			opt["progressColor"] = RadialGradientColor(self.__blockWidth * 7.5, self.__blockHeight * 2.5, self.__blockWidth * 7.5)
			opt["progressColor"].addColorStop(0, "red")
			opt["progressColor"].addColorStop(0.3, "orange")
			opt["progressColor"].addColorStop(0.4, "yellow")
			opt["progressColor"].addColorStop(0.5, "green")
			opt["progressColor"].addColorStop(0.8, "blue")
			opt["progressColor"].addColorStop(1, "violet")

		self.progressColor = opt["progressColor"]
		self.vacantColor = opt["vacantColor"]

		self.progressBar.mask = Graphics()

		self.__numberList = [
			[
				[1, 1, 1],
				[1, 0, 1],
				[1, 0, 1],
				[1, 0, 1],
				[1, 1, 1]
			],
			[
				[1, 1, 0],
				[0, 1, 0],
				[0, 1, 0],
				[0, 1, 0],
				[1, 1, 1]
			],
			[
				[1, 1, 1],
				[0, 0, 1],
				[1, 1, 1],
				[1, 0, 0],
				[1, 1, 1]
			],
			[
				[1, 1, 1],
				[0, 0, 1],
				[1, 1, 1],
				[0, 0, 1],
				[1, 1, 1]
			],
			[
				[1, 0, 1],
				[1, 0, 1],
				[1, 1, 1],
				[0, 0, 1],
				[0, 0, 1]
			],
			[
				[1, 1, 1],
				[1, 0, 0],
				[1, 1, 1],
				[0, 0, 1],
				[1, 1, 1]
			],
			[
				[1, 1, 1],
				[1, 0, 0],
				[1, 1, 1],
				[1, 0, 1],
				[1, 1, 1]
			],
			[
				[1, 1, 1],
				[0, 0, 1],
				[0, 0, 1],
				[0, 0, 1],
				[0, 0, 1]
			],
			[
				[1, 1, 1],
				[1, 0, 1],
				[1, 1, 1],
				[1, 0, 1],
				[1, 1, 1]
			],
			[
				[1, 1, 1],
				[1, 0, 1],
				[1, 1, 1],
				[0, 0, 1],
				[1, 1, 1]
			]
		]

	def setProgress(self, value):
		ratio = value / 100
		totalHeight = self.progressBarTotalHeight
		right = 0
		startY = totalHeight * (1 - ratio)
		mask = self.progressBar.mask
		blockW = self.__blockWidth
		blockH = self.__blockHeight

		mask.clear()

		for i in str(round(value)):
			numArray = self.__numberList[int(i)]

			for y, row in enumerate(numArray):
				for x, elem in enumerate(row):
					if elem == 1:
						mask.beginFill()
						mask.drawRect(right + x * blockW, y * self.__blockHeight, blockW, self.__blockHeight)
						mask.endFill()

			right += blockW * 4

		mask.beginFill()
		mask.drawCircle(right + blockW / 2, blockW / 2, blockW / 2)
		right += blockW
		mask.moveTo(right + blockW, 0)
		mask.lineTo(right + blockW * 2, 0)
		mask.lineTo(right, blockH * 5)
		mask.lineTo(right - blockW, blockH * 5)
		right += blockW
		mask.drawCircle(right + blockW / 2, totalHeight - blockW / 2, blockW / 2)
		right += blockW
		mask.endFill()

		self.progressBar.graphics.clear()

		self.progressBar.graphics.beginFill(self.vacantColor)
		self.progressBar.graphics.drawRect(0, 0, right, totalHeight)
		self.progressBar.graphics.endFill()

		self.progressBar.graphics.beginFill(self.progressColor)
		self.progressBar.graphics.drawRect(0, startY, right, totalHeight - startY)
		self.progressBar.graphics.endFill()

		self.progressBar.x = (stage.width - right) / 2
		self.progressBar.y = (stage.height - totalHeight) / 2 class LoadingSample2(LoadingSample):
	def __init__(self, **opt):
		bg = None

		if "background" in opt:
			bg = opt["background"]

		super(LoadingSample2, self).__init__(bg)
		
		if not "background" in opt:
			self.background.graphics.beginFill("black")
			self.background.graphics.drawRect(0, 0, stage.width, stage.height)
			self.background.graphics.endFill()

		if not "fontSize" in opt:
			opt["fontSize"] = stage.height * 0.2

		if not "vacantColor" in opt:
			opt["vacantColor"] = "white"

		txt = TextField()
		txt.size = opt["fontSize"]
		txt.text = "Loading..."
		txt.textColor = opt["vacantColor"]
		txt.weight = TextFormatWeight.BOLD
		txt.x = (stage.width - txt.width) / 2
		txt.y = (stage.height - txt.height) / 2 + 30
		self.progressBar.addChild(txt)

		self.progressBarTotalWidth = txt.width
		self.progressBarHeight = txt.height

		if not "progressColor" in opt:
			opt["progressColor"] = RadialGradientColor(txt.width / 2, txt.height / 2, txt.width / 2)
			opt["progressColor"].addColorStop(0, "red")
			opt["progressColor"].addColorStop(0.3, "orange")
			opt["progressColor"].addColorStop(0.4, "yellow")
			opt["progressColor"].addColorStop(0.5, "green")
			opt["progressColor"].addColorStop(0.8, "blue")
			opt["progressColor"].addColorStop(1, "violet")

		self.progressColor = opt["progressColor"]

		self.__coverTxt = TextField()
		self.__coverTxt.x = txt.x
		self.__coverTxt.y = txt.y
		self.__coverTxt.weight = txt.weight
		self.__coverTxt.size = opt["fontSize"]
		self.__coverTxt.text = txt.text
		self.__coverTxt.textColor = opt["progressColor"]
		self.__coverTxt.mask = Graphics()
		self.progressBar.addChild(self.__coverTxt)

		self.__coverTxt.mask.beginFill()
		self.__coverTxt.mask.drawRect(0, 0, 0, 0)
		self.__coverTxt.mask.endFill()

		self.label = TextField()
		self.label.text = "0%"
		self.label.textColor = "blue"
		self.label.size = 40
		self.label.x = (stage.width - self.label.width) / 2
		self.label.y = (stage.height - self.label.height) / 2 - 60
		self.addChild(self.label)
	
	def setProgress(self, value):
		ratio = value / 100
		totalWidth = self.progressBarTotalWidth

		self.label.text = "%s%%" % round(value)
		self.label.x = (stage.width - self.label.width) / 2

		self.__coverTxt.mask.clear()
		self.__coverTxt.mask.beginFill()
		self.__coverTxt.mask.drawRect(0, 0, totalWidth * ratio, self.progressBarHeight)
		self.__coverTxt.mask.endFill() class LoadingSample3(LoadingSample):
	def __init__(self, **opt):
		bg = None

		if "background" in opt:
			bg = opt["background"]

		super(LoadingSample3, self).__init__(bg)

		if not "background" in opt:
			self.background.graphics.beginFill("#CCCCCC")
			self.background.graphics.drawRect(0, 0, stage.width, stage.height)
			self.background.graphics.endFill()

		if not "progressColor" in opt:
			opt["progressColor"] = "#00A2E8"

		if not "borderColor" in opt:
			opt["borderColor"] = "gray"

		self.progressColor = opt["progressColor"]
		self.progressBarTotalWidth = stage.width * 0.6
		self.progressBarHeight = 20

		self.progressBar.graphics.beginFill()
		self.progressBar.graphics.lineStyle(3, opt["borderColor"])
		self.progressBar.graphics.drawRoundRect(0, 0, self.progressBarTotalWidth, self.progressBarHeight, 10)
		self.progressBar.graphics.endFill()

		self.progressBar.x = (stage.width - self.progressBar.width) / 2
		self.progressBar.y = (stage.height - self.progressBar.height) / 2 + 20

		self.__contentLayer = Sprite()
		self.progressBar.addChild(self.__contentLayer)

		self.label = TextField()
		self.label.text = "Loading... 0%"
		self.label.textColor = "#555555"
		self.label.size = 30
		self.label.weight = TextFormatWeight.BOLD
		self.label.x = (stage.width - self.label.width) / 2
		self.label.y = (stage.height - self.label.height) / 2 - 40
		self.addChild(self.label)

		if not "background" in opt:
			self.background.graphics.beginFill("#DEDEDE")
			self.background.graphics.drawRoundRect(self.progressBar.x - 60, self.label.y - 100, self.progressBar.width + 120, 300, 10)
			self.background.graphics.endFill()

	def setProgress(self, value):
		ratio = value / 100
		totalWidth = self.progressBarTotalWidth

		self.label.text = "Loading... %s%%" % round(value)
		self.label.x = (stage.width - self.label.width) / 2

		self.__contentLayer.graphics.clear()
		self.__contentLayer.graphics.beginFill(self.progressColor)
		self.__contentLayer.graphics.drawRoundRect(3, 3, totalWidth * ratio - 6, self.progressBarHeight - 6, 10, 7)
		self.__contentLayer.graphics.endFill() class ButtonSample(Button):
	def __init__(self, **kw):
		roundBorder = True
		backgroundColor = {"normalState" : "#DDDDDD", "overState" : "#E3E3E3"}
		lineColor = "#CCCCCC"

		if "roundBorder" in kw:
			roundBorder = kw["roundBorder"]

		if "backgroundColor" in kw:
			backgroundColor = kw["backgroundColor"]

			if not "normalState" in backgroundColor:
				backgroundColor["normalState"] = "#DDDDDD"

			if not "overState" in backgroundColor:
				backgroundColor["overState"] = "#E3E3E3"

		if "lineColor" in kw:
			lineColor = kw["lineColor"]

		txt = TextField()

		if "text" in kw:
			txt.text = kw["text"]

		if "textColor" in kw:
			txt.textColor = kw["textColor"]

		if "font" in kw:
			txt.font = kw["font"]

		if "size" in kw:
			txt.size = kw["size"]

		if "weight" in kw:
			txt.weight = kw["weight"]

		btnWidth = txt.width * 1.2
		btnHeight = txt.height * 1.2

		normalState = Sprite()
		normalState.graphics.beginFill(backgroundColor["normalState"])
		normalState.graphics.lineStyle(2, lineColor)
		if roundBorder:
			normalState.graphics.drawRoundRect(0, 0, btnWidth, btnHeight, 5)
		else:
			normalState.graphics.drawRect(0, 0, btnWidth, btnHeight)
		normalState.graphics.endFill()

		overState = Sprite()
		overState.graphics.beginFill(backgroundColor["overState"])
		overState.graphics.lineStyle(2, lineColor)
		if roundBorder:
			overState.graphics.drawRoundRect(0, 0, btnWidth, btnHeight, 5)
		else:
			overState.graphics.drawRect(0, 0, btnWidth, btnHeight)
		overState.graphics.endFill()

		super(ButtonSample, self).__init__(normalState, overState)

		txt.x = txt.width * 0.1
		txt.y = txt.height * 0.1
		self.addChild(txt)
from pylash.core import init, addChild, stage
from pylash.loaders import LoadManage
from pylash.events import MouseEvent, LoopEvent
from pylash.display import Sprite, TextField
from pylash.ui import LoadingSample1, LoadingSample2, LoadingSample3, ButtonSample
# !/usr/bin/env python3
# -*- coding: utf-8 -*-


loopFrameIndex = 0
loopFrameMax = 5
progress = 0

def main():
    controlLayer = Sprite()

    addChild(controlLayer)