# Path: pylash/core.py
# def init(speed, title, width, height, callback):
# 	'''
# 	The initialization function of `pylash`. This function will create a game window, set its
# 	size to \\(width \\times height\\) and window title to `title`. The game window will repaint
# 	per `speed` milliseconds. After the setup of the game window, `callback` will be
# 	invoked, which is the entrance function of your game.
# 
# 	Parameters
# 	----------
# 	speed : float
# 		The window repainting rate. Generally, it is supposed to be \\(1000 / FPS\\).
# 	title : str
# 		The window title.
# 	width : int
# 		The window's width.
# 	height : int
# 		The window's height.
# 	callback : funtion
# 		The callback function invoked after the setup of game window.
# 
# 	Example
# 	-------
# 	```
# 	def main():
# 		print("Hello, world!")
# 	
# 	init(1000 / 60, "Init Test", 100, 100, main)
# 	```
# 	'''
# 
# 	stage.app = QtWidgets.QApplication(sys.argv)
# 
# 	stage._setCanvas(speed, title, width, height)
# 
# 	if not hasattr(callback, "__call__"):
# 		raise TypeError("init(speed, title, width, height, callback): parameter 'callback' must be a function.")
# 
# 	callback()
# 
# 	sys.exit(stage.app.exec_())
# 
# def addChild(self, child):
# 	'''
# 	Appends `child` to the `stage`'s display list, then the `child` object will be rendered
# 	on the game window.
# 
# 	Parameters
# 	----------
# 	child : pylash.display.DisplayObject
# 		The display object to be added to the stage.
# 	'''
# 
# 	if child is not None:
# 		child.parent = self
# 			
# 		self.childList.append(child)
# 	else:
# 		raise TypeError("Stage.addChild(child): parameter 'child' must be a display object.")
# 
# Path: pylash/display.py
# 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 TextFormatWeight(object):
# 	NORMAL = "normal"
# 	BOLD = "bold"
# 	BOLDER = "bolder"
# 	LIGHTER = "lighter"
# 
# 	def __init__(self):
# 		raise Exception("TextFormatWeight cannot be instantiated.")


from pylash.core import init, addChild
from pylash.display import TextField, TextFormatWeight
# !/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
	t1 = TextField()
	t1.x = t1.y = 50
	t1.size = 30
	t1.text = "Hello World!"

# Path: pylash/core.py
# def init(speed, title, width, height, callback):
# 	'''
# 	The initialization function of `pylash`. This function will create a game window, set its
# 	size to \\(width \\times height\\) and window title to `title`. The game window will repaint
# 	per `speed` milliseconds. After the setup of the game window, `callback` will be
# 	invoked, which is the entrance function of your game.
# 
# 	Parameters
# 	----------
# 	speed : float
# 		The window repainting rate. Generally, it is supposed to be \\(1000 / FPS\\).
# 	title : str
# 		The window title.
# 	width : int
# 		The window's width.
# 	height : int
# 		The window's height.
# 	callback : funtion
# 		The callback function invoked after the setup of game window.
# 
# 	Example
# 	-------
# 	```
# 	def main():
# 		print("Hello, world!")
# 	
# 	init(1000 / 60, "Init Test", 100, 100, main)
# 	```
# 	'''
# 
# 	stage.app = QtWidgets.QApplication(sys.argv)
# 
# 	stage._setCanvas(speed, title, width, height)
# 
# 	if not hasattr(callback, "__call__"):
# 		raise TypeError("init(speed, title, width, height, callback): parameter 'callback' must be a function.")
# 
# 	callback()
# 
# 	sys.exit(stage.app.exec_())
# 
# def addChild(self, child):
# 	'''
# 	Appends `child` to the `stage`'s display list, then the `child` object will be rendered
# 	on the game window.
# 
# 	Parameters
# 	----------
# 	child : pylash.display.DisplayObject
# 		The display object to be added to the stage.
# 	'''
# 
# 	if child is not None:
# 		child.parent = self
# 			
# 		self.childList.append(child)
# 	else:
# 		raise TypeError("Stage.addChild(child): parameter 'child' must be a display object.")
# 
# Path: pylash/display.py
# 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 TextFormatWeight(object):
# 	NORMAL = "normal"
# 	BOLD = "bold"
# 	BOLDER = "bolder"
# 	LIGHTER = "lighter"
# 
# 	def __init__(self):
# 		raise Exception("TextFormatWeight cannot be instantiated.")


# Path: demo/TextField/Main.py
from pylash.core import init, addChild
from pylash.display import TextField, TextFormatWeight

# !/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
	t1 = TextField()
	t1.x = t1.y = 50
	t1.size = 30
	t1.text = "Hello World!"

	addChild(t1)