2017-06-03 20:39:32 -04:00
|
|
|
from PIL import Image, ImageDraw
|
2017-06-24 23:12:41 -04:00
|
|
|
from PyQt5 import QtGui, QtCore, QtWidgets
|
2017-06-23 18:38:05 -04:00
|
|
|
from PyQt5.QtGui import QColor
|
2017-06-16 20:01:27 -04:00
|
|
|
from PIL.ImageQt import ImageQt
|
2017-06-03 20:39:32 -04:00
|
|
|
import os
|
|
|
|
|
2017-07-02 20:46:48 -04:00
|
|
|
from component import Component
|
2017-07-17 22:07:33 -04:00
|
|
|
from toolkit.frame import BlankFrame, FloodFrame, FramePainter, PaintColor
|
|
|
|
from toolkit import rgbFromString, pickColor
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-07-02 20:46:48 -04:00
|
|
|
|
|
|
|
class Component(Component):
|
2017-07-20 20:31:38 -04:00
|
|
|
name = 'Color'
|
|
|
|
version = '1.0.0'
|
2017-06-12 22:34:37 -04:00
|
|
|
|
2017-07-23 01:53:54 -04:00
|
|
|
def widget(self, *args):
|
2017-06-06 11:14:39 -04:00
|
|
|
self.color1 = (0, 0, 0)
|
|
|
|
self.color2 = (133, 133, 133)
|
2017-06-03 20:39:32 -04:00
|
|
|
self.x = 0
|
|
|
|
self.y = 0
|
2017-07-23 01:53:54 -04:00
|
|
|
super().widget(*args)
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-07-23 01:53:54 -04:00
|
|
|
self.page.lineEdit_color1.setText('%s,%s,%s' % self.color1)
|
|
|
|
self.page.lineEdit_color2.setText('%s,%s,%s' % self.color2)
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-06-08 20:32:25 -04:00
|
|
|
btnStyle1 = "QPushButton { background-color : %s; outline: none; }" \
|
2017-06-06 11:14:39 -04:00
|
|
|
% QColor(*self.color1).name()
|
|
|
|
|
2017-06-08 20:32:25 -04:00
|
|
|
btnStyle2 = "QPushButton { background-color : %s; outline: none; }" \
|
2017-06-06 11:14:39 -04:00
|
|
|
% QColor(*self.color2).name()
|
|
|
|
|
2017-07-23 01:53:54 -04:00
|
|
|
self.page.pushButton_color1.setStyleSheet(btnStyle1)
|
|
|
|
self.page.pushButton_color2.setStyleSheet(btnStyle2)
|
|
|
|
self.page.pushButton_color1.clicked.connect(lambda: self.pickColor(1))
|
|
|
|
self.page.pushButton_color2.clicked.connect(lambda: self.pickColor(2))
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-06-03 20:39:32 -04:00
|
|
|
# disable color #2 until non-default 'fill' option gets changed
|
2017-07-23 01:53:54 -04:00
|
|
|
self.page.lineEdit_color2.setDisabled(True)
|
|
|
|
self.page.pushButton_color2.setDisabled(True)
|
|
|
|
self.page.spinBox_width.setValue(
|
2017-07-13 00:05:11 -04:00
|
|
|
int(self.settings.value("outputWidth")))
|
2017-07-23 01:53:54 -04:00
|
|
|
self.page.spinBox_height.setValue(
|
2017-07-13 00:05:11 -04:00
|
|
|
int(self.settings.value("outputHeight")))
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-06-23 23:00:24 -04:00
|
|
|
self.fillLabels = [
|
2017-06-16 20:01:27 -04:00
|
|
|
'Solid',
|
|
|
|
'Linear Gradient',
|
|
|
|
'Radial Gradient',
|
|
|
|
]
|
|
|
|
for label in self.fillLabels:
|
2017-07-23 01:53:54 -04:00
|
|
|
self.page.comboBox_fill.addItem(label)
|
|
|
|
self.page.comboBox_fill.setCurrentIndex(0)
|
|
|
|
|
|
|
|
self.trackWidgets(
|
|
|
|
{
|
|
|
|
'x': self.page.spinBox_x,
|
|
|
|
'y': self.page.spinBox_y,
|
|
|
|
'sizeWidth': self.page.spinBox_width,
|
|
|
|
'sizeHeight': self.page.spinBox_height,
|
|
|
|
'trans': self.page.checkBox_trans,
|
|
|
|
'spread': self.page.comboBox_spread,
|
|
|
|
'stretch': self.page.checkBox_stretch,
|
|
|
|
'RG_start': self.page.spinBox_radialGradient_start,
|
|
|
|
'LG_start': self.page.spinBox_linearGradient_start,
|
|
|
|
'RG_end': self.page.spinBox_radialGradient_end,
|
|
|
|
'LG_end': self.page.spinBox_linearGradient_end,
|
|
|
|
'RG_centre': self.page.spinBox_radialGradient_spread,
|
|
|
|
'fillType': self.page.comboBox_fill,
|
|
|
|
}, presetNames={
|
|
|
|
'sizeWidth': 'width',
|
|
|
|
'sizeHeight': 'height',
|
|
|
|
}
|
|
|
|
)
|
2017-06-03 20:39:32 -04:00
|
|
|
|
|
|
|
def update(self):
|
2017-07-17 22:07:33 -04:00
|
|
|
self.color1 = rgbFromString(self.page.lineEdit_color1.text())
|
|
|
|
self.color2 = rgbFromString(self.page.lineEdit_color2.text())
|
2017-07-23 01:53:54 -04:00
|
|
|
|
|
|
|
fillType = self.page.comboBox_fill.currentIndex()
|
|
|
|
if fillType == 0:
|
2017-06-16 20:01:27 -04:00
|
|
|
self.page.lineEdit_color2.setEnabled(False)
|
|
|
|
self.page.pushButton_color2.setEnabled(False)
|
|
|
|
self.page.checkBox_trans.setEnabled(False)
|
|
|
|
self.page.checkBox_stretch.setEnabled(False)
|
2017-06-17 11:15:24 -04:00
|
|
|
self.page.comboBox_spread.setEnabled(False)
|
2017-06-16 20:01:27 -04:00
|
|
|
else:
|
|
|
|
self.page.lineEdit_color2.setEnabled(True)
|
|
|
|
self.page.pushButton_color2.setEnabled(True)
|
|
|
|
self.page.checkBox_trans.setEnabled(True)
|
|
|
|
self.page.checkBox_stretch.setEnabled(True)
|
2017-06-17 11:15:24 -04:00
|
|
|
self.page.comboBox_spread.setEnabled(True)
|
2017-07-23 01:53:54 -04:00
|
|
|
if self.page.checkBox_trans.isChecked():
|
2017-07-09 01:10:06 -04:00
|
|
|
self.page.lineEdit_color2.setEnabled(False)
|
|
|
|
self.page.pushButton_color2.setEnabled(False)
|
2017-07-23 01:53:54 -04:00
|
|
|
self.page.fillWidget.setCurrentIndex(fillType)
|
2017-06-16 20:01:27 -04:00
|
|
|
|
2017-06-13 22:47:18 -04:00
|
|
|
super().update()
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-07-27 17:49:08 -04:00
|
|
|
def previewRender(self):
|
|
|
|
return self.drawFrame(self.width, self.height)
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-07-09 21:27:29 -04:00
|
|
|
def properties(self):
|
2017-06-04 13:00:36 -04:00
|
|
|
return ['static']
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-07-27 17:49:08 -04:00
|
|
|
def frameRender(self, frameNo):
|
|
|
|
return self.drawFrame(self.width, self.height)
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-06-03 20:39:32 -04:00
|
|
|
def drawFrame(self, width, height):
|
2017-06-06 11:14:39 -04:00
|
|
|
r, g, b = self.color1
|
2017-06-16 20:01:27 -04:00
|
|
|
shapeSize = (self.sizeWidth, self.sizeHeight)
|
|
|
|
# in default state, skip all this logic and return a plain fill
|
2017-06-23 23:00:24 -04:00
|
|
|
if self.fillType == 0 and shapeSize == (width, height) \
|
|
|
|
and self.x == 0 and self.y == 0:
|
2017-07-02 21:38:19 -04:00
|
|
|
return FloodFrame(width, height, (r, g, b, 255))
|
2017-06-16 20:01:27 -04:00
|
|
|
|
|
|
|
# Return a solid image at x, y
|
|
|
|
if self.fillType == 0:
|
2017-07-02 21:38:19 -04:00
|
|
|
frame = BlankFrame(width, height)
|
2017-06-16 20:01:27 -04:00
|
|
|
image = Image.new("RGBA", shapeSize, (r, g, b, 255))
|
|
|
|
frame.paste(image, box=(self.x, self.y))
|
|
|
|
return frame
|
|
|
|
|
|
|
|
# Now fills that require using Qt...
|
|
|
|
elif self.fillType > 0:
|
2017-07-02 21:38:19 -04:00
|
|
|
image = FramePainter(width, height)
|
|
|
|
|
2017-06-16 20:01:27 -04:00
|
|
|
if self.stretch:
|
2017-06-23 23:00:24 -04:00
|
|
|
w = width
|
|
|
|
h = height
|
2017-06-16 20:01:27 -04:00
|
|
|
else:
|
2017-06-23 23:00:24 -04:00
|
|
|
w = self.sizeWidth
|
|
|
|
h = self.sizeWidth
|
2017-06-16 20:01:27 -04:00
|
|
|
|
|
|
|
if self.fillType == 1: # Linear Gradient
|
|
|
|
brush = QtGui.QLinearGradient(
|
|
|
|
self.LG_start,
|
2017-06-16 20:43:40 -04:00
|
|
|
self.LG_start,
|
2017-06-25 19:38:58 -04:00
|
|
|
self.LG_end+width/3,
|
2017-06-16 20:43:40 -04:00
|
|
|
self.LG_end)
|
2017-06-16 20:01:27 -04:00
|
|
|
|
|
|
|
elif self.fillType == 2: # Radial Gradient
|
|
|
|
brush = QtGui.QRadialGradient(
|
|
|
|
self.RG_start,
|
|
|
|
self.RG_end,
|
|
|
|
w, h,
|
2017-06-16 20:43:40 -04:00
|
|
|
self.RG_centre)
|
2017-06-16 20:01:27 -04:00
|
|
|
|
2017-06-16 20:43:40 -04:00
|
|
|
brush.setSpread(self.spread)
|
2017-07-02 21:38:19 -04:00
|
|
|
brush.setColorAt(0.0, PaintColor(*self.color1))
|
2017-06-16 20:01:27 -04:00
|
|
|
if self.trans:
|
2017-07-02 21:38:19 -04:00
|
|
|
brush.setColorAt(1.0, PaintColor(0, 0, 0, 0))
|
2017-06-16 20:43:40 -04:00
|
|
|
elif self.fillType == 1 and self.stretch:
|
2017-07-02 21:38:19 -04:00
|
|
|
brush.setColorAt(0.2, PaintColor(*self.color2))
|
2017-06-16 20:01:27 -04:00
|
|
|
else:
|
2017-07-02 21:38:19 -04:00
|
|
|
brush.setColorAt(1.0, PaintColor(*self.color2))
|
|
|
|
image.setBrush(brush)
|
|
|
|
image.drawRect(
|
2017-06-23 23:00:24 -04:00
|
|
|
self.x, self.y,
|
2017-06-23 17:14:39 -04:00
|
|
|
self.sizeWidth, self.sizeHeight
|
|
|
|
)
|
2017-07-02 21:38:19 -04:00
|
|
|
|
|
|
|
return image.finalize()
|
2017-06-03 20:39:32 -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-03 22:58:40 -04:00
|
|
|
self.page.lineEdit_color1.setText('%s,%s,%s' % pr['color1'])
|
|
|
|
self.page.lineEdit_color2.setText('%s,%s,%s' % pr['color2'])
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-06-08 20:32:25 -04:00
|
|
|
btnStyle1 = "QPushButton { background-color : %s; outline: none; }" \
|
2017-06-06 11:14:39 -04:00
|
|
|
% QColor(*pr['color1']).name()
|
2017-06-08 20:32:25 -04:00
|
|
|
btnStyle2 = "QPushButton { background-color : %s; outline: none; }" \
|
2017-06-06 11:14:39 -04:00
|
|
|
% QColor(*pr['color2']).name()
|
2017-06-08 20:32:25 -04:00
|
|
|
self.page.pushButton_color1.setStyleSheet(btnStyle1)
|
|
|
|
self.page.pushButton_color2.setStyleSheet(btnStyle2)
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-06-03 20:39:32 -04:00
|
|
|
def savePreset(self):
|
2017-07-23 01:53:54 -04:00
|
|
|
saveValueStore = super().savePreset()
|
|
|
|
saveValueStore['color1'] = self.color1
|
|
|
|
saveValueStore['color2'] = self.color2
|
|
|
|
return saveValueStore
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-06-03 20:39:32 -04:00
|
|
|
def pickColor(self, num):
|
2017-07-17 22:07:33 -04:00
|
|
|
RGBstring, btnStyle = pickColor()
|
2017-06-03 20:39:32 -04:00
|
|
|
if not RGBstring:
|
|
|
|
return
|
|
|
|
if num == 1:
|
|
|
|
self.page.lineEdit_color1.setText(RGBstring)
|
|
|
|
self.page.pushButton_color1.setStyleSheet(btnStyle)
|
|
|
|
else:
|
|
|
|
self.page.lineEdit_color2.setText(RGBstring)
|
|
|
|
self.page.pushButton_color2.setStyleSheet(btnStyle)
|
2017-06-22 22:23:04 -04:00
|
|
|
|
|
|
|
def commandHelp(self):
|
|
|
|
print('Specify a color:\n color=255,255,255')
|
|
|
|
|
|
|
|
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_color1.setText(arg)
|
|
|
|
return
|
|
|
|
super().command(arg)
|