2017-06-03 20:39:32 -04:00
|
|
|
from PIL import Image, ImageDraw
|
|
|
|
from PyQt4 import uic, QtGui, QtCore
|
|
|
|
import os
|
|
|
|
from . import __base__
|
|
|
|
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-06-03 20:39:32 -04:00
|
|
|
class Component(__base__.Component):
|
|
|
|
'''Image'''
|
2017-06-12 22:34:37 -04:00
|
|
|
|
2017-06-13 22:47:18 -04:00
|
|
|
modified = QtCore.pyqtSignal(int, dict)
|
2017-06-12 22:34:37 -04:00
|
|
|
|
2017-06-03 20:39:32 -04:00
|
|
|
def widget(self, parent):
|
|
|
|
self.parent = parent
|
2017-06-03 22:58:40 -04:00
|
|
|
self.settings = parent.settings
|
2017-06-06 11:14:39 -04:00
|
|
|
page = uic.loadUi(os.path.join(
|
|
|
|
os.path.dirname(os.path.realpath(__file__)), 'image.ui'))
|
2017-06-03 22:58:40 -04:00
|
|
|
self.imagePath = ''
|
|
|
|
self.x = 0
|
|
|
|
self.y = 0
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-06-03 22:58:40 -04:00
|
|
|
page.lineEdit_image.textChanged.connect(self.update)
|
|
|
|
page.pushButton_image.clicked.connect(self.pickImage)
|
2017-06-14 19:37:47 -04:00
|
|
|
page.spinBox_scale.valueChanged.connect(self.update)
|
|
|
|
page.checkBox_stretch.stateChanged.connect(self.update)
|
|
|
|
page.spinBox_x.valueChanged.connect(self.update)
|
|
|
|
page.spinBox_y.valueChanged.connect(self.update)
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-06-03 20:39:32 -04:00
|
|
|
self.page = page
|
|
|
|
return page
|
|
|
|
|
|
|
|
def update(self):
|
2017-06-03 22:58:40 -04:00
|
|
|
self.imagePath = self.page.lineEdit_image.text()
|
2017-06-14 19:37:47 -04:00
|
|
|
self.scale = self.page.spinBox_scale.value()
|
|
|
|
self.xPosition = self.page.spinBox_x.value()
|
|
|
|
self.yPosition = self.page.spinBox_y.value()
|
|
|
|
self.stretched = self.page.checkBox_stretch.isChecked()
|
2017-06-03 20:39:32 -04:00
|
|
|
self.parent.drawPreview()
|
2017-06-13 22:47:18 -04:00
|
|
|
super().update()
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-06-03 20:39:32 -04:00
|
|
|
def previewRender(self, previewWorker):
|
2017-06-15 22:15:03 -04:00
|
|
|
self.imageFormats = previewWorker.core.imageFormats
|
2017-06-03 20:39:32 -04:00
|
|
|
width = int(previewWorker.core.settings.value('outputWidth'))
|
|
|
|
height = int(previewWorker.core.settings.value('outputHeight'))
|
|
|
|
return self.drawFrame(width, height)
|
2017-06-04 13:00:36 -04:00
|
|
|
|
|
|
|
def preFrameRender(self, **kwargs):
|
|
|
|
super().preFrameRender(**kwargs)
|
|
|
|
return ['static']
|
|
|
|
|
|
|
|
def frameRender(self, moduleNo, arrayNo, frameNo):
|
2017-06-03 20:39:32 -04:00
|
|
|
width = int(self.worker.core.settings.value('outputWidth'))
|
|
|
|
height = int(self.worker.core.settings.value('outputHeight'))
|
|
|
|
return self.drawFrame(width, height)
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-06-03 20:39:32 -04:00
|
|
|
def drawFrame(self, width, height):
|
2017-06-15 22:15:03 -04:00
|
|
|
frame = self.blankFrame(width, height)
|
2017-06-03 22:58:40 -04:00
|
|
|
if self.imagePath and os.path.exists(self.imagePath):
|
|
|
|
image = Image.open(self.imagePath)
|
2017-06-14 19:37:47 -04:00
|
|
|
if self.stretched and image.size != (width, height):
|
2017-06-03 22:58:40 -04:00
|
|
|
image = image.resize((width, height), Image.ANTIALIAS)
|
2017-06-14 19:37:47 -04:00
|
|
|
if self.scale != 100:
|
|
|
|
newHeight = int((image.height / 100) * self.scale)
|
|
|
|
newWidth = int((image.width / 100) * self.scale)
|
|
|
|
image = image.resize((newWidth, newHeight), Image.ANTIALIAS)
|
|
|
|
frame.paste(image, box=(self.xPosition, self.yPosition))
|
2017-06-03 22:58:40 -04:00
|
|
|
return frame
|
2017-06-03 20:39:32 -04:00
|
|
|
|
2017-06-07 23:22:55 -04:00
|
|
|
def loadPreset(self, pr, presetName=None):
|
2017-06-12 22:34:37 -04:00
|
|
|
super().loadPreset(pr, presetName)
|
2017-06-03 22:58:40 -04:00
|
|
|
self.page.lineEdit_image.setText(pr['image'])
|
2017-06-14 19:37:47 -04:00
|
|
|
self.page.spinBox_scale.setValue(pr['scale'])
|
|
|
|
self.page.spinBox_x.setValue(pr['x'])
|
|
|
|
self.page.spinBox_y.setValue(pr['y'])
|
|
|
|
self.page.checkBox_stretch.setChecked(pr['stretched'])
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-06-03 20:39:32 -04:00
|
|
|
def savePreset(self):
|
2017-06-03 22:58:40 -04:00
|
|
|
return {
|
2017-06-08 16:50:48 -04:00
|
|
|
'preset': self.currentPreset,
|
2017-06-06 11:14:39 -04:00
|
|
|
'image': self.imagePath,
|
2017-06-14 19:37:47 -04:00
|
|
|
'scale': self.scale,
|
|
|
|
'stretched': self.stretched,
|
|
|
|
'x': self.xPosition,
|
|
|
|
'y': self.yPosition,
|
2017-06-03 22:58:40 -04:00
|
|
|
}
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-06-03 22:58:40 -04:00
|
|
|
def pickImage(self):
|
|
|
|
imgDir = self.settings.value("backgroundDir", os.path.expanduser("~"))
|
2017-06-06 11:14:39 -04:00
|
|
|
filename = QtGui.QFileDialog.getOpenFileName(
|
2017-06-15 22:15:03 -04:00
|
|
|
self.page, "Choose Image", imgDir,
|
|
|
|
"Image Files (%s)" % " ".join(self.imageFormats))
|
2017-06-07 23:22:55 -04:00
|
|
|
if filename:
|
2017-06-03 22:58:40 -04:00
|
|
|
self.settings.setValue("backgroundDir", os.path.dirname(filename))
|
|
|
|
self.page.lineEdit_image.setText(filename)
|
|
|
|
self.update()
|