#!/usr/bin/env python
"""
Footprint PCB layouting program
Copyright (C) 2012 Danny Milosavljevic
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

from __future__ import generators
from primitives import From, MList
import metafile
from ll import Object
import ll
def selectImageFile(parent, prevName):
	return ll.getOpenFilename(parent, "Add Picture", prevName)
	# or:
	return ll.selectFromList(parent, "Add", ["Picture"], [(a, a) for a in sorted(find(os.getenv("HOME")))
	                                                                 if not a.startswith(".")], prevName, set(), searchColumn = 1)


class ImageLayer(Object):
	def __init__(self, name = None, rotateRadians = 0.0, offsetX = 0.0, offsetY = 0.0, scaleX = 1.0, scaleY = 1.0):
		Object.__init__(self)
		self.name = name
		self.rotateRadians = rotateRadians
		self.offsetX = offsetX
		self.offsetY = offsetY
		self.scaleX = scaleX
		self.scaleY = scaleY
		# TODO if any of those change, notify.
	def repaint(self):
		yield metafile.makeOperation("pixmap", self.name, self.rotateRadians, self.offsetX, self.offsetY, self.scaleX, self.scaleY, 0, 0)
	@classmethod
	def getCreationParameters(klass):
		yield ("name", selectImageFile, "Name")
		yield ("rotateRadians", None, "Rotation")
		yield ("offsetX", None, "X offset")
		yield ("offsetY", None, "X offset")
		yield ("scaleX", None, "X scaling")
		yield ("scaleY", None, "Y scaling")
