2017-05-28 07:34:34 -04:00
|
|
|
from PIL import Image, ImageDraw
|
2017-07-02 21:38:19 -04:00
|
|
|
from PyQt5.QtGui import QColor, QFont
|
2017-06-24 23:12:41 -04:00
|
|
|
from PyQt5 import QtGui, QtCore, QtWidgets
|
2017-06-06 09:53:27 -04:00
|
|
|
import os
|
2017-05-28 07:34:34 -04:00
|
|
|
|
2017-07-02 20:46:48 -04:00
|
|
|
from component import Component
|
2017-07-17 22:07:33 -04:00
|
|
|
from toolkit.frame import FramePainter
|
|
|
|
from toolkit import rgbFromString, pickColor
|
2017-05-28 07:34:34 -04:00
|
|
|
|
2017-07-02 20:46:48 -04:00
|
|
|
|
|
|
|
class Component(Component):
|
2017-07-20 20:31:38 -04:00
|
|
|
name = 'Title Text'
|
|
|
|
version = '1.0.0'
|
2017-06-12 22:34:37 -04:00
|
|
|
|
|
|
|
def __init__(self, *args):
|
|
|
|
super().__init__(*args)
|
2017-06-03 10:01:47 -04:00
|
|
|
self.titleFont = QFont()
|
|
|
|
|
2017-07-23 01:53:54 -04:00
|
|
|
def widget(self, *args):
|
|
|
|
super().widget(*args)
|
2017-07-13 00:05:11 -04:00
|
|
|
height = int(self.settings.value('outputHeight'))
|
|
|
|
width = int(self.settings.value('outputWidth'))
|
2017-06-06 09:53:27 -04:00
|
|
|
self.textColor = (255, 255, 255)
|
2017-05-28 14:19:28 -04:00
|
|
|
self.title = 'Text'
|
|
|
|
self.alignment = 1
|
2017-06-03 15:38:21 -04:00
|
|
|
self.fontSize = height / 13.5
|
2017-06-22 19:59:31 -04:00
|
|
|
fm = QtGui.QFontMetrics(self.titleFont)
|
|
|
|
self.xPosition = width / 2 - fm.width(self.title)/2
|
2017-06-03 15:38:21 -04:00
|
|
|
self.yPosition = height / 2 * 1.036
|
2017-06-06 09:53:27 -04:00
|
|
|
|
2017-07-23 01:53:54 -04:00
|
|
|
self.page.comboBox_textAlign.addItem("Left")
|
|
|
|
self.page.comboBox_textAlign.addItem("Middle")
|
|
|
|
self.page.comboBox_textAlign.addItem("Right")
|
2017-05-28 14:19:28 -04:00
|
|
|
|
2017-07-23 01:53:54 -04:00
|
|
|
self.page.lineEdit_textColor.setText('%s,%s,%s' % self.textColor)
|
|
|
|
self.page.pushButton_textColor.clicked.connect(self.pickColor)
|
2017-06-06 09:53:27 -04:00
|
|
|
btnStyle = "QPushButton { background-color : %s; outline: none; }" \
|
|
|
|
% QColor(*self.textColor).name()
|
2017-07-23 01:53:54 -04:00
|
|
|
self.page.pushButton_textColor.setStyleSheet(btnStyle)
|
|
|
|
|
|
|
|
self.page.lineEdit_title.setText(self.title)
|
|
|
|
self.page.comboBox_textAlign.setCurrentIndex(int(self.alignment))
|
|
|
|
self.page.spinBox_fontSize.setValue(int(self.fontSize))
|
|
|
|
self.page.spinBox_xTextAlign.setValue(int(self.xPosition))
|
|
|
|
self.page.spinBox_yTextAlign.setValue(int(self.yPosition))
|
|
|
|
|
|
|
|
self.page.fontComboBox_titleFont.currentFontChanged.connect(
|
|
|
|
self.update
|
|
|
|
)
|
|
|
|
self.trackWidgets({
|
|
|
|
'title': self.page.lineEdit_title,
|
|
|
|
'alignment': self.page.comboBox_textAlign,
|
|
|
|
'fontSize': self.page.spinBox_fontSize,
|
|
|
|
'xPosition': self.page.spinBox_xTextAlign,
|
|
|
|
'yPosition': self.page.spinBox_yTextAlign,
|
|
|
|
})
|
2017-05-28 14:19:28 -04:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
self.titleFont = self.page.fontComboBox_titleFont.currentFont()
|
2017-07-17 22:07:33 -04:00
|
|
|
self.textColor = rgbFromString(
|
2017-06-06 11:14:39 -04:00
|
|
|
self.page.lineEdit_textColor.text())
|
2017-07-01 01:01:29 -04:00
|
|
|
btnStyle = "QPushButton { background-color : %s; outline: none; }" \
|
|
|
|
% QColor(*self.textColor).name()
|
|
|
|
self.page.pushButton_textColor.setStyleSheet(btnStyle)
|
2017-07-13 21:59:23 -04:00
|
|
|
|
2017-06-13 22:47:18 -04:00
|
|
|
super().update()
|
2017-06-06 09:53:27 -04:00
|
|
|
|
2017-06-01 13:17:36 -04:00
|
|
|
def getXY(self):
|
|
|
|
'''Returns true x, y after considering alignment settings'''
|
2017-05-28 14:49:35 -04:00
|
|
|
fm = QtGui.QFontMetrics(self.titleFont)
|
2017-06-06 09:53:27 -04:00
|
|
|
if self.alignment == 0: # Left
|
2017-07-11 06:06:22 -04:00
|
|
|
x = int(self.xPosition)
|
2017-06-06 09:53:27 -04:00
|
|
|
|
|
|
|
if self.alignment == 1: # Middle
|
2017-07-13 00:05:11 -04:00
|
|
|
offset = int(fm.width(self.title)/2)
|
|
|
|
x = self.xPosition - offset
|
2017-06-06 09:53:27 -04:00
|
|
|
|
|
|
|
if self.alignment == 2: # Right
|
|
|
|
offset = fm.width(self.title)
|
2017-07-13 00:05:11 -04:00
|
|
|
x = self.xPosition - offset
|
2017-06-01 13:17:36 -04:00
|
|
|
return x, self.yPosition
|
2017-06-06 09:53:27 -04:00
|
|
|
|
2017-07-23 01:53:54 -04:00
|
|
|
def loadPreset(self, pr, *args):
|
|
|
|
super().loadPreset(pr, *args)
|
2017-06-12 22:34:37 -04:00
|
|
|
|
2017-06-06 09:53:27 -04:00
|
|
|
font = QFont()
|
|
|
|
font.fromString(pr['titleFont'])
|
2017-06-01 13:17:36 -04:00
|
|
|
self.page.fontComboBox_titleFont.setCurrentFont(font)
|
2017-05-30 22:05:56 -04:00
|
|
|
self.page.lineEdit_textColor.setText('%s,%s,%s' % pr['textColor'])
|
2017-06-06 09:53:27 -04:00
|
|
|
btnStyle = "QPushButton { background-color : %s; outline: none; }" \
|
|
|
|
% QColor(*pr['textColor']).name()
|
2017-05-30 22:05:56 -04:00
|
|
|
self.page.pushButton_textColor.setStyleSheet(btnStyle)
|
2017-06-06 09:53:27 -04:00
|
|
|
|
2017-05-28 21:24:51 -04:00
|
|
|
def savePreset(self):
|
2017-07-23 01:53:54 -04:00
|
|
|
saveValueStore = super().savePreset()
|
|
|
|
saveValueStore['titleFont'] = self.titleFont.toString()
|
|
|
|
saveValueStore['textColor'] = self.textColor
|
|
|
|
return saveValueStore
|
2017-05-28 21:24:51 -04:00
|
|
|
|
2017-05-28 14:19:28 -04:00
|
|
|
def previewRender(self, previewWorker):
|
2017-07-13 00:05:11 -04:00
|
|
|
width = int(self.settings.value('outputWidth'))
|
|
|
|
height = int(self.settings.value('outputHeight'))
|
2017-05-28 14:19:28 -04:00
|
|
|
return self.addText(width, height)
|
2017-05-28 07:34:34 -04:00
|
|
|
|
2017-07-09 21:27:29 -04:00
|
|
|
def properties(self):
|
2017-07-13 17:03:25 -04:00
|
|
|
props = ['static']
|
|
|
|
if not self.title:
|
|
|
|
props.append('error')
|
|
|
|
return props
|
|
|
|
|
|
|
|
def error(self):
|
|
|
|
return "No text provided."
|
2017-06-06 09:53:27 -04:00
|
|
|
|
2017-07-09 01:10:06 -04:00
|
|
|
def frameRender(self, layerNo, frameNo):
|
2017-07-13 00:05:11 -04:00
|
|
|
width = int(self.settings.value('outputWidth'))
|
|
|
|
height = int(self.settings.value('outputHeight'))
|
2017-05-28 14:19:28 -04:00
|
|
|
return self.addText(width, height)
|
|
|
|
|
|
|
|
def addText(self, width, height):
|
2017-06-06 09:53:27 -04:00
|
|
|
|
2017-07-11 06:06:22 -04:00
|
|
|
image = FramePainter(width, height)
|
2017-05-28 14:19:28 -04:00
|
|
|
self.titleFont.setPixelSize(self.fontSize)
|
2017-07-02 21:38:19 -04:00
|
|
|
image.setFont(self.titleFont)
|
|
|
|
image.setPen(self.textColor)
|
2017-07-11 06:06:22 -04:00
|
|
|
x, y = self.getXY()
|
2017-07-02 21:38:19 -04:00
|
|
|
image.drawText(x, y, self.title)
|
2017-05-28 07:34:34 -04:00
|
|
|
|
2017-07-02 21:38:19 -04:00
|
|
|
return image.finalize()
|
2017-05-28 14:19:28 -04:00
|
|
|
|
|
|
|
def pickColor(self):
|
2017-07-17 22:07:33 -04:00
|
|
|
RGBstring, btnStyle = pickColor()
|
2017-05-30 22:05:56 -04:00
|
|
|
if not RGBstring:
|
|
|
|
return
|
2017-05-29 20:39:11 -04:00
|
|
|
self.page.lineEdit_textColor.setText(RGBstring)
|
|
|
|
self.page.pushButton_textColor.setStyleSheet(btnStyle)
|
2017-06-22 18:40:34 -04:00
|
|
|
|
2017-06-22 22:23:04 -04:00
|
|
|
def commandHelp(self):
|
|
|
|
print('Enter a string to use as centred white text:')
|
|
|
|
print(' "title=User Error"')
|
|
|
|
print('Specify a text color:\n color=255,255,255')
|
|
|
|
print('Set custom x, y position:\n x=500 y=500')
|
2017-06-22 18:40:34 -04:00
|
|
|
|
|
|
|
def command(self, arg):
|
2017-07-23 01:53:54 -04:00
|
|
|
if '=' in arg:
|
2017-06-22 22:23:04 -04:00
|
|
|
key, arg = arg.split('=', 1)
|
|
|
|
if key == 'color':
|
|
|
|
self.page.lineEdit_textColor.setText(arg)
|
|
|
|
return
|
|
|
|
elif key == 'size':
|
|
|
|
self.page.spinBox_fontSize.setValue(int(arg))
|
|
|
|
return
|
|
|
|
elif key == 'x':
|
|
|
|
self.page.spinBox_xTextAlign.setValue(int(arg))
|
|
|
|
return
|
|
|
|
elif key == 'y':
|
|
|
|
self.page.spinBox_yTextAlign.setValue(int(arg))
|
|
|
|
return
|
|
|
|
elif key == 'title':
|
|
|
|
self.page.lineEdit_title.setText(arg)
|
|
|
|
return
|
2017-06-22 18:40:34 -04:00
|
|
|
super().command(arg)
|