component class now tracks colorwidgets
so adding new color-selection widgets is now simple
This commit is contained in:
parent
a472246dab
commit
3c1b52205f
2
setup.py
2
setup.py
|
@ -2,7 +2,7 @@ from setuptools import setup
|
|||
import os
|
||||
|
||||
|
||||
__version__ = '2.0.0.rc2'
|
||||
__version__ = '2.0.0.rc3'
|
||||
|
||||
|
||||
def package_files(directory):
|
||||
|
|
|
@ -3,18 +3,20 @@
|
|||
on making a valid component.
|
||||
'''
|
||||
from PyQt5 import uic, QtCore, QtWidgets
|
||||
from PyQt5.QtGui import QColor
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
from toolkit.frame import BlankFrame
|
||||
from toolkit import getWidgetValue, setWidgetValue, connectWidget
|
||||
from toolkit import (
|
||||
getWidgetValue, setWidgetValue, connectWidget, rgbFromString
|
||||
)
|
||||
|
||||
|
||||
class ComponentMetaclass(type(QtCore.QObject)):
|
||||
'''
|
||||
Checks the validity of each Component class imported, and
|
||||
mutates some attributes for easier use by the core program.
|
||||
Checks the validity of each Component class and mutates some attrs.
|
||||
E.g., takes only major version from version string & decorates methods
|
||||
'''
|
||||
|
||||
|
@ -173,6 +175,8 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass):
|
|||
self._trackedWidgets = {}
|
||||
self._presetNames = {}
|
||||
self._commandArgs = {}
|
||||
self._colorWidgets = {}
|
||||
self._relativeWidgets = {}
|
||||
self._lockedProperties = None
|
||||
self._lockedError = None
|
||||
|
||||
|
@ -188,7 +192,7 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass):
|
|||
)
|
||||
|
||||
# =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~==~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
||||
# Critical Methods
|
||||
# Render Methods
|
||||
# =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~==~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
||||
|
||||
def previewRender(self):
|
||||
|
@ -286,7 +290,17 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass):
|
|||
Call super() at the END if you need to subclass this.
|
||||
'''
|
||||
for attr, widget in self._trackedWidgets.items():
|
||||
if attr in self._colorWidgets:
|
||||
rgbTuple = rgbFromString(widget.text())
|
||||
setattr(self, attr, rgbTuple)
|
||||
btnStyle = (
|
||||
"QPushButton { background-color : %s; outline: none; }"
|
||||
% QColor(*rgbTuple).name()
|
||||
)
|
||||
self._colorWidgets[attr].setStyleSheet(btnStyle)
|
||||
else:
|
||||
setattr(self, attr, getWidgetValue(widget))
|
||||
|
||||
if not self.core.openingProject:
|
||||
self.parent.drawPreview()
|
||||
saveValueStore = self.savePreset()
|
||||
|
@ -305,6 +319,15 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass):
|
|||
key = attr if attr not in self._presetNames \
|
||||
else self._presetNames[attr]
|
||||
val = presetDict[key]
|
||||
|
||||
if attr in self._colorWidgets:
|
||||
widget.setText('%s,%s,%s' % val)
|
||||
btnStyle = (
|
||||
"QPushButton { background-color : %s; outline: none; }"
|
||||
% QColor(*val).name()
|
||||
)
|
||||
self._colorWidgets[attr].setStyleSheet(btnStyle)
|
||||
else:
|
||||
setWidgetValue(widget, val)
|
||||
|
||||
def savePreset(self):
|
||||
|
@ -352,7 +375,12 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass):
|
|||
self._trackedWidgets = trackDict
|
||||
for kwarg in kwargs:
|
||||
try:
|
||||
if kwarg in ('presetNames', 'commandArgs'):
|
||||
if kwarg in (
|
||||
'presetNames',
|
||||
'commandArgs',
|
||||
'colorWidgets',
|
||||
'relativeWidgets',
|
||||
):
|
||||
setattr(self, '_%s' % kwarg, kwargs[kwarg])
|
||||
else:
|
||||
raise ComponentError(
|
||||
|
@ -360,6 +388,37 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass):
|
|||
except ComponentError:
|
||||
continue
|
||||
|
||||
if kwarg == 'colorWidgets':
|
||||
def makeColorFunc(attr):
|
||||
def pickColor_():
|
||||
self.pickColor(
|
||||
self._trackedWidgets[attr],
|
||||
self._colorWidgets[attr]
|
||||
)
|
||||
return pickColor_
|
||||
self._colorFuncs = {
|
||||
attr: makeColorFunc(attr) for attr in kwargs[kwarg]
|
||||
}
|
||||
for attr, func in self._colorFuncs.items():
|
||||
self._colorWidgets[attr].clicked.connect(func)
|
||||
self._colorWidgets[attr].setStyleSheet(
|
||||
"QPushButton {"
|
||||
"background-color : #FFFFFF; outline: none; }"
|
||||
)
|
||||
|
||||
def pickColor(self, textWidget, button):
|
||||
'''Use color picker to get color input from the user.'''
|
||||
dialog = QtWidgets.QColorDialog()
|
||||
dialog.setOption(QtWidgets.QColorDialog.ShowAlphaChannel, True)
|
||||
color = dialog.getColor()
|
||||
if color.isValid():
|
||||
RGBstring = '%s,%s,%s' % (
|
||||
str(color.red()), str(color.green()), str(color.blue()))
|
||||
btnStyle = "QPushButton{background-color: %s; outline: none;}" \
|
||||
% color.name()
|
||||
textWidget.setText(RGBstring)
|
||||
button.setStyleSheet(btnStyle)
|
||||
|
||||
def lockProperties(self, propList):
|
||||
self._lockedProperties = propList
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import os
|
|||
|
||||
from component import Component
|
||||
from toolkit.frame import BlankFrame, FloodFrame, FramePainter, PaintColor
|
||||
from toolkit import rgbFromString, pickColor
|
||||
|
||||
|
||||
class Component(Component):
|
||||
|
@ -14,25 +13,12 @@ class Component(Component):
|
|||
version = '1.0.0'
|
||||
|
||||
def widget(self, *args):
|
||||
self.color1 = (0, 0, 0)
|
||||
self.color2 = (133, 133, 133)
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
super().widget(*args)
|
||||
|
||||
self.page.lineEdit_color1.setText('%s,%s,%s' % self.color1)
|
||||
self.page.lineEdit_color2.setText('%s,%s,%s' % self.color2)
|
||||
|
||||
btnStyle1 = "QPushButton { background-color : %s; outline: none; }" \
|
||||
% QColor(*self.color1).name()
|
||||
|
||||
btnStyle2 = "QPushButton { background-color : %s; outline: none; }" \
|
||||
% QColor(*self.color2).name()
|
||||
|
||||
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))
|
||||
self.page.lineEdit_color1.setText('0,0,0')
|
||||
self.page.lineEdit_color2.setText('133,133,133')
|
||||
|
||||
# disable color #2 until non-default 'fill' option gets changed
|
||||
self.page.lineEdit_color2.setDisabled(True)
|
||||
|
@ -66,16 +52,18 @@ class Component(Component):
|
|||
'LG_end': self.page.spinBox_linearGradient_end,
|
||||
'RG_centre': self.page.spinBox_radialGradient_spread,
|
||||
'fillType': self.page.comboBox_fill,
|
||||
'color1': self.page.lineEdit_color1,
|
||||
'color2': self.page.lineEdit_color2,
|
||||
}, presetNames={
|
||||
'sizeWidth': 'width',
|
||||
'sizeHeight': 'height',
|
||||
}
|
||||
}, colorWidgets={
|
||||
'color1': self.page.pushButton_color1,
|
||||
'color2': self.page.pushButton_color2,
|
||||
},
|
||||
)
|
||||
|
||||
def update(self):
|
||||
self.color1 = rgbFromString(self.page.lineEdit_color1.text())
|
||||
self.color2 = rgbFromString(self.page.lineEdit_color2.text())
|
||||
|
||||
fillType = self.page.comboBox_fill.currentIndex()
|
||||
if fillType == 0:
|
||||
self.page.lineEdit_color2.setEnabled(False)
|
||||
|
@ -161,36 +149,6 @@ class Component(Component):
|
|||
|
||||
return image.finalize()
|
||||
|
||||
def loadPreset(self, pr, *args):
|
||||
super().loadPreset(pr, *args)
|
||||
|
||||
self.page.lineEdit_color1.setText('%s,%s,%s' % pr['color1'])
|
||||
self.page.lineEdit_color2.setText('%s,%s,%s' % pr['color2'])
|
||||
|
||||
btnStyle1 = "QPushButton { background-color : %s; outline: none; }" \
|
||||
% QColor(*pr['color1']).name()
|
||||
btnStyle2 = "QPushButton { background-color : %s; outline: none; }" \
|
||||
% QColor(*pr['color2']).name()
|
||||
self.page.pushButton_color1.setStyleSheet(btnStyle1)
|
||||
self.page.pushButton_color2.setStyleSheet(btnStyle2)
|
||||
|
||||
def savePreset(self):
|
||||
saveValueStore = super().savePreset()
|
||||
saveValueStore['color1'] = self.color1
|
||||
saveValueStore['color2'] = self.color2
|
||||
return saveValueStore
|
||||
|
||||
def pickColor(self, num):
|
||||
RGBstring, btnStyle = pickColor()
|
||||
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)
|
||||
|
||||
def commandHelp(self):
|
||||
print('Specify a color:\n color=255,255,255')
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ from copy import copy
|
|||
|
||||
from component import Component
|
||||
from toolkit.frame import BlankFrame
|
||||
from toolkit import rgbFromString, pickColor
|
||||
|
||||
|
||||
class Component(Component):
|
||||
|
@ -22,7 +21,6 @@ class Component(Component):
|
|||
return ['pcm']
|
||||
|
||||
def widget(self, *args):
|
||||
self.visColor = (255, 255, 255)
|
||||
self.scale = 20
|
||||
self.y = 0
|
||||
super().widget(*args)
|
||||
|
@ -33,35 +31,17 @@ class Component(Component):
|
|||
self.page.comboBox_visLayout.addItem("Top")
|
||||
self.page.comboBox_visLayout.setCurrentIndex(0)
|
||||
|
||||
self.page.lineEdit_visColor.setText('%s,%s,%s' % self.visColor)
|
||||
self.page.pushButton_visColor.clicked.connect(lambda: self.pickColor())
|
||||
btnStyle = "QPushButton { background-color : %s; outline: none; }" \
|
||||
% QColor(*self.visColor).name()
|
||||
self.page.pushButton_visColor.setStyleSheet(btnStyle)
|
||||
self.page.lineEdit_visColor.setText('255,255,255')
|
||||
|
||||
self.trackWidgets({
|
||||
'visColor': self.page.lineEdit_visColor,
|
||||
'layout': self.page.comboBox_visLayout,
|
||||
'scale': self.page.spinBox_scale,
|
||||
'y': self.page.spinBox_y,
|
||||
}, colorWidgets={
|
||||
'visColor': self.page.pushButton_visColor,
|
||||
})
|
||||
|
||||
def update(self):
|
||||
self.visColor = rgbFromString(self.page.lineEdit_visColor.text())
|
||||
super().update()
|
||||
|
||||
def loadPreset(self, pr, *args):
|
||||
super().loadPreset(pr, *args)
|
||||
|
||||
self.page.lineEdit_visColor.setText('%s,%s,%s' % pr['visColor'])
|
||||
btnStyle = "QPushButton { background-color : %s; outline: none; }" \
|
||||
% QColor(*pr['visColor']).name()
|
||||
self.page.pushButton_visColor.setStyleSheet(btnStyle)
|
||||
|
||||
def savePreset(self):
|
||||
saveValueStore = super().savePreset()
|
||||
saveValueStore['visColor'] = self.visColor
|
||||
return saveValueStore
|
||||
|
||||
def previewRender(self):
|
||||
spectrum = numpy.fromfunction(
|
||||
lambda x: float(self.scale)/2500*(x-128)**2, (255,), dtype="int16")
|
||||
|
@ -99,13 +79,6 @@ class Component(Component):
|
|||
self.spectrumArray[arrayNo],
|
||||
self.visColor, self.layout)
|
||||
|
||||
def pickColor(self):
|
||||
RGBstring, btnStyle = pickColor()
|
||||
if not RGBstring:
|
||||
return
|
||||
self.page.lineEdit_visColor.setText(RGBstring)
|
||||
self.page.pushButton_visColor.setStyleSheet(btnStyle)
|
||||
|
||||
def transformData(
|
||||
self, i, completeAudioArray, sampleSize,
|
||||
smoothConstantDown, smoothConstantUp, lastSpectrum):
|
||||
|
|
|
@ -5,7 +5,6 @@ import os
|
|||
|
||||
from component import Component
|
||||
from toolkit.frame import FramePainter
|
||||
from toolkit import rgbFromString, pickColor
|
||||
|
||||
|
||||
class Component(Component):
|
||||
|
@ -33,11 +32,6 @@ class Component(Component):
|
|||
self.page.comboBox_textAlign.addItem("Right")
|
||||
|
||||
self.page.lineEdit_textColor.setText('%s,%s,%s' % self.textColor)
|
||||
self.page.pushButton_textColor.clicked.connect(self.pickColor)
|
||||
btnStyle = "QPushButton { background-color : %s; outline: none; }" \
|
||||
% QColor(*self.textColor).name()
|
||||
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))
|
||||
|
@ -48,21 +42,18 @@ class Component(Component):
|
|||
self.update
|
||||
)
|
||||
self.trackWidgets({
|
||||
'textColor': self.page.lineEdit_textColor,
|
||||
'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,
|
||||
}, colorWidgets={
|
||||
'textColor': self.page.pushButton_textColor,
|
||||
})
|
||||
|
||||
def update(self):
|
||||
self.titleFont = self.page.fontComboBox_titleFont.currentFont()
|
||||
self.textColor = rgbFromString(
|
||||
self.page.lineEdit_textColor.text())
|
||||
btnStyle = "QPushButton { background-color : %s; outline: none; }" \
|
||||
% QColor(*self.textColor).name()
|
||||
self.page.pushButton_textColor.setStyleSheet(btnStyle)
|
||||
|
||||
super().update()
|
||||
|
||||
def getXY(self):
|
||||
|
@ -86,15 +77,10 @@ class Component(Component):
|
|||
font = QFont()
|
||||
font.fromString(pr['titleFont'])
|
||||
self.page.fontComboBox_titleFont.setCurrentFont(font)
|
||||
self.page.lineEdit_textColor.setText('%s,%s,%s' % pr['textColor'])
|
||||
btnStyle = "QPushButton { background-color : %s; outline: none; }" \
|
||||
% QColor(*pr['textColor']).name()
|
||||
self.page.pushButton_textColor.setStyleSheet(btnStyle)
|
||||
|
||||
def savePreset(self):
|
||||
saveValueStore = super().savePreset()
|
||||
saveValueStore['titleFont'] = self.titleFont.toString()
|
||||
saveValueStore['textColor'] = self.textColor
|
||||
return saveValueStore
|
||||
|
||||
def previewRender(self):
|
||||
|
@ -122,13 +108,6 @@ class Component(Component):
|
|||
|
||||
return image.finalize()
|
||||
|
||||
def pickColor(self):
|
||||
RGBstring, btnStyle = pickColor()
|
||||
if not RGBstring:
|
||||
return
|
||||
self.page.lineEdit_textColor.setText(RGBstring)
|
||||
self.page.pushButton_textColor.setStyleSheet(btnStyle)
|
||||
|
||||
def commandHelp(self):
|
||||
print('Enter a string to use as centred white text:')
|
||||
print(' "title=User Error"')
|
||||
|
|
|
@ -7,7 +7,7 @@ import subprocess
|
|||
|
||||
from component import Component
|
||||
from toolkit.frame import BlankFrame, scale
|
||||
from toolkit import checkOutput, rgbFromString, pickColor
|
||||
from toolkit import checkOutput
|
||||
from toolkit.ffmpeg import (
|
||||
openPipe, closePipe, getAudioDuration, FfmpegVideo, exampleSound
|
||||
)
|
||||
|
@ -18,15 +18,9 @@ class Component(Component):
|
|||
version = '1.0.0'
|
||||
|
||||
def widget(self, *args):
|
||||
self.color = (255, 255, 255)
|
||||
super().widget(*args)
|
||||
|
||||
self.page.lineEdit_color.setText('%s,%s,%s' % self.color)
|
||||
btnStyle = "QPushButton { background-color : %s; outline: none; }" \
|
||||
% QColor(*self.color).name()
|
||||
self.page.pushButton_color.setStyleSheet(btnStyle)
|
||||
self.page.pushButton_color.clicked.connect(lambda: self.pickColor())
|
||||
self.page.spinBox_scale.valueChanged.connect(self.updateChunksize)
|
||||
self.page.lineEdit_color.setText('255,255,255')
|
||||
|
||||
if hasattr(self.parent, 'window'):
|
||||
self.parent.window.lineEdit_audioFile.textChanged.connect(
|
||||
|
@ -35,6 +29,7 @@ class Component(Component):
|
|||
|
||||
self.trackWidgets(
|
||||
{
|
||||
'color': self.page.lineEdit_color,
|
||||
'mode': self.page.comboBox_mode,
|
||||
'amplitude': self.page.comboBox_amplitude,
|
||||
'x': self.page.spinBox_x,
|
||||
|
@ -44,36 +39,11 @@ class Component(Component):
|
|||
'opacity': self.page.spinBox_opacity,
|
||||
'compress': self.page.checkBox_compress,
|
||||
'mono': self.page.checkBox_mono,
|
||||
}, colorWidgets={
|
||||
'color': self.page.pushButton_color,
|
||||
}
|
||||
)
|
||||
|
||||
def update(self):
|
||||
self.color = rgbFromString(self.page.lineEdit_color.text())
|
||||
btnStyle = "QPushButton { background-color : %s; outline: none; }" \
|
||||
% QColor(*self.color).name()
|
||||
self.page.pushButton_color.setStyleSheet(btnStyle)
|
||||
super().update()
|
||||
|
||||
def loadPreset(self, pr, *args):
|
||||
super().loadPreset(pr, *args)
|
||||
|
||||
self.page.lineEdit_color.setText('%s,%s,%s' % pr['color'])
|
||||
btnStyle = "QPushButton { background-color : %s; outline: none; }" \
|
||||
% QColor(*pr['color']).name()
|
||||
self.page.pushButton_color.setStyleSheet(btnStyle)
|
||||
|
||||
def savePreset(self):
|
||||
saveValueStore = super().savePreset()
|
||||
saveValueStore['color'] = self.color
|
||||
return saveValueStore
|
||||
|
||||
def pickColor(self):
|
||||
RGBstring, btnStyle = pickColor()
|
||||
if not RGBstring:
|
||||
return
|
||||
self.page.lineEdit_color.setText(RGBstring)
|
||||
self.page.pushButton_color.setStyleSheet(btnStyle)
|
||||
|
||||
def previewRender(self):
|
||||
self.updateChunksize()
|
||||
frame = self.getPreviewFrame(self.width, self.height)
|
||||
|
|
|
@ -74,25 +74,6 @@ def disableWhenOpeningProject(func):
|
|||
return decorator
|
||||
|
||||
|
||||
def pickColor():
|
||||
'''
|
||||
Use color picker to get color input from the user,
|
||||
and return this as an RGB string and QPushButton stylesheet.
|
||||
In a subclass apply stylesheet to any color selection widgets
|
||||
'''
|
||||
dialog = QtWidgets.QColorDialog()
|
||||
dialog.setOption(QtWidgets.QColorDialog.ShowAlphaChannel, True)
|
||||
color = dialog.getColor()
|
||||
if color.isValid():
|
||||
RGBstring = '%s,%s,%s' % (
|
||||
str(color.red()), str(color.green()), str(color.blue()))
|
||||
btnStyle = "QPushButton{background-color: %s; outline: none;}" \
|
||||
% color.name()
|
||||
return RGBstring, btnStyle
|
||||
else:
|
||||
return None, None
|
||||
|
||||
|
||||
def rgbFromString(string):
|
||||
'''Turns an RGB string like "255, 255, 255" into a tuple'''
|
||||
try:
|
||||
|
|
|
@ -42,9 +42,9 @@ class PaintColor(QtGui.QColor):
|
|||
super().__init__(b, g, r, a)
|
||||
|
||||
|
||||
def scale(scale, width, height, returntype=None):
|
||||
width = (float(width) / 100.0) * float(scale)
|
||||
height = (float(height) / 100.0) * float(scale)
|
||||
def scale(scalePercent, width, height, returntype=None):
|
||||
width = (float(width) / 100.0) * float(scalePercent)
|
||||
height = (float(height) / 100.0) * float(scalePercent)
|
||||
if returntype == str:
|
||||
return (str(math.ceil(width)), str(math.ceil(height)))
|
||||
elif returntype == int:
|
||||
|
|
Reference in New Issue