aboutsummaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authortassaron2017-05-28 14:19:28 -0400
committertassaron2017-05-28 14:19:28 -0400
commite0eed5bff4316910a93937d904f1a913f365a252 (patch)
tree5ed9ebe270c5bde6ca716916e15c7720e75cce38 /components
parentd9a5f2dd34c0bf14bfc99b58183b00d43217d889 (diff)
title text is now a component
plus numerous bugs removed and added
Diffstat (limited to 'components')
-rw-r--r--components/original.py46
-rw-r--r--components/text.py160
2 files changed, 155 insertions, 51 deletions
diff --git a/components/original.py b/components/original.py
index d1caa7b..e901c21 100644
--- a/components/original.py
+++ b/components/original.py
@@ -1,13 +1,18 @@
''' Original Audio Visualization '''
import numpy
from PIL import Image, ImageDraw
-from PyQt4 import uic
+from PyQt4 import uic, QtGui
+from PyQt4.QtGui import QColor
import os, random
class Component:
- def widget(self,parent):
+ def __str__(self):
+ return __doc__
+
+ def widget(self, parent):
self.parent = parent
+ self.visColor = (255,255,255)
page = uic.loadUi(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'original.ui'))
page.comboBox_visLayout.addItem("Classic")
@@ -16,18 +21,24 @@ class Component:
#visLayoutValue = int(self.settings.value('visLayout'))
page.comboBox_visLayout.setCurrentIndex(0)
page.comboBox_visLayout.currentIndexChanged.connect(self.update)
-
+ page.lineEdit_visColor.setText('%s,%s,%s' % self.visColor)
+ page.pushButton_visColor.clicked.connect(lambda: self.pickColor())
+ btnStyle = "QPushButton { background-color : %s; outline: none; }" % QColor(*self.visColor).name()
+ page.pushButton_visColor.setStyleSheet(btnStyle)
+ page.lineEdit_visColor.textChanged.connect(self.update)
+ self.page = page
return page
+
def update(self):
self.layout = self.page.comboBox_visLayout.currentIndex()
- print(self.layout)
+ self.visColor = RGBFromString(self.page.lineEdit_visColor.text())
self.parent.drawPreview()
- def previewRender(self, previewWorker, widget):
+ def previewRender(self, previewWorker):
spectrum = numpy.fromfunction(lambda x: 0.008*(x-128)**2, (255,), dtype="int16")
width = int(previewWorker.core.settings.value('outputWidth'))
height = int(previewWorker.core.settings.value('outputHeight'))
- return drawBars(width, height, spectrum, (255, 255, 255), self.layout)
+ return drawBars(width, height, spectrum, self.visColor, self.layout)
def preFrameRender(self, **kwargs):
for kwarg, value in kwargs.items():
@@ -41,7 +52,15 @@ class Component:
self.smoothConstantDown, self.smoothConstantUp, self.lastSpectrum)
width = int(self.worker.core.settings.value('outputWidth'))
height = int(self.worker.core.settings.value('outputHeight'))
- return drawBars(width, height, self.lastSpectrum, (255,255,255), self.layout)
+ return drawBars(width, height, self.lastSpectrum, self.visColor, self.layout)
+
+ def pickColor(self):
+ color = QtGui.QColorDialog.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()
+ self.page.lineEdit_visColor.setText(RGBstring)
+ self.page.pushButton_visColor.setStyleSheet(btnStyle)
def transformData(i, completeAudioArray, sampleSize, smoothConstantDown, smoothConstantUp, lastSpectrum):
if len(completeAudioArray) < (i + sampleSize):
@@ -111,3 +130,16 @@ def drawBars(width, height, spectrum, color, layout):
im.paste(imTop, (0, y), mask=imTop)
return im
+
+def RGBFromString(string):
+ ''' turns an RGB string like "255, 255, 255" into a tuple '''
+ try:
+ tup = tuple([int(i) for i in string.split(',')])
+ if len(tup) != 3:
+ raise ValueError
+ for i in tup:
+ if i > 255 or i < 0:
+ raise ValueError
+ return tup
+ except:
+ return (255, 255, 255)
diff --git a/components/text.py b/components/text.py
index 68b02fe..814e13f 100644
--- a/components/text.py
+++ b/components/text.py
@@ -1,59 +1,131 @@
''' Title Text '''
-import numpy
from PIL import Image, ImageDraw
-from PyQt4 import uic
-import os
+from PyQt4.QtGui import QPainter, QColor, QFont
+from PyQt4 import uic, QtGui, QtCore
+from PIL.ImageQt import ImageQt
+import os, io
class Component:
- def widget(self,parent):
+ def __str__(self):
+ return __doc__
+
+ def widget(self, parent):
+ height = int(parent.settings.value('outputHeight'))
+ width = int(parent.settings.value('outputWidth'))
+ self.parent = parent
+ self.textColor = (255,255,255)
+ self.title = 'Text'
+ self.titleFont = None
+ self.alignment = 1
+ self.fontSize = height / 16
+ self.xPosition = width / 2
+ self.yPosition = height / 2
+
page = uic.loadUi(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'text.ui'))
+ page.comboBox_textAlign.addItem("Left")
+ page.comboBox_textAlign.addItem("Middle")
+ page.comboBox_textAlign.addItem("Right")
+ page.comboBox_textAlign.setCurrentIndex(1)
+
+ page.spinBox_fontSize.setValue(int(int(parent.settings.value("outputHeight")) / 14 ))
+ page.spinBox_xTextAlign.setValue(int(int(parent.settings.value('outputWidth'))/2))
+ page.spinBox_yTextAlign.setValue(int(int(parent.settings.value('outputHeight'))/2))
+
+ page.lineEdit_textColor.setText('%s,%s,%s' % self.textColor)
+ page.pushButton_textColor.clicked.connect(lambda: self.pickColor())
+ btnStyle = "QPushButton { background-color : %s; outline: none; }" % QColor(*self.textColor).name()
+ page.pushButton_textColor.setStyleSheet(btnStyle)
+
+ page.lineEdit_title.setText(self.title)
+ if not self.titleFont == None:
+ page.fontComboBox_titleFont.setCurrentFont(QFont(self.titleFont))
+ page.comboBox_textAlign.setCurrentIndex(int(self.alignment))
+ page.spinBox_fontSize.setValue(int(self.fontSize))
+ page.spinBox_xTextAlign.setValue(int(self.xPosition))
+ page.spinBox_yTextAlign.setValue(int(self.yPosition))
+
+ page.fontComboBox_titleFont.currentFontChanged.connect(self.update)
+ page.lineEdit_title.textChanged.connect(self.update)
+ page.comboBox_textAlign.currentIndexChanged.connect(self.update)
+ page.spinBox_xTextAlign.valueChanged.connect(self.update)
+ page.spinBox_yTextAlign.valueChanged.connect(self.update)
+ page.spinBox_fontSize.valueChanged.connect(self.update)
+ page.lineEdit_textColor.textChanged.connect(self.update)
+ self.page = page
return page
- def previewRender(self, previewWorker, widget):
+
+ def update(self):
+ self.title = self.page.lineEdit_title.text()
+ self.alignment = self.page.comboBox_textAlign.currentIndex()
+ self.titleFont = self.page.fontComboBox_titleFont.currentFont()
+ self.fontSize = self.page.spinBox_fontSize.value()
+ self.xPosition = self.page.spinBox_xTextAlign.value()
+ self.yPosition = self.page.spinBox_yTextAlign.value()
+ self.textColor = RGBFromString(self.page.lineEdit_textColor.text())
+ self.parent.drawPreview()
+
+ def previewRender(self, previewWorker):
width = int(previewWorker.core.settings.value('outputWidth'))
height = int(previewWorker.core.settings.value('outputHeight'))
- im = Image.new("RGBA", (width, height),(0,0,0,0))
-
- return im
+ return self.addText(width, height)
def preFrameRender(self, **kwargs):
- pass
+ for kwarg, value in kwargs.items():
+ exec('self.%s = value' % kwarg)
+
def frameRender(self, moduleNo, frameNo):
- width = int(previewWorker.core.settings.value('outputWidth'))
- height = int(previewWorker.core.settings.value('outputHeight'))
+ width = int(self.worker.core.settings.value('outputWidth'))
+ height = int(self.worker.core.settings.value('outputHeight'))
+ return self.addText(width, height)
+
+ def addText(self, width, height):
im = Image.new("RGBA", (width, height),(0,0,0,0))
+ image = ImageQt(im)
+
+ image1 = QtGui.QImage(image)
+ painter = QPainter(image1)
+ self.titleFont.setPixelSize(self.fontSize)
+ painter.setFont(self.titleFont)
+ painter.setPen(QColor(*self.textColor))
- return im
+ fm = QtGui.QFontMetrics(self.titleFont)
+ if self.alignment == 0: #Left
+ self.xPosition = self.xPosition
+ if self.alignment == 1: #Middle
+ self.xPosition = self.xPosition - fm.width(self.title)/2
+ if self.alignment == 2: #Right
+ self.xPosition = self.xPosition - fm.width(self.title)
+ painter.drawText(self.xPosition, self.yPosition, self.title)
+ painter.end()
- '''
- self._image = ImageQt(im)
-
- self._image1 = QtGui.QImage(self._image)
- painter = QPainter(self._image1)
- font = titleFont
- font.setPixelSize(fontSize)
- painter.setFont(font)
- painter.setPen(QColor(*textColor))
-
- yPosition = yOffset
-
- fm = QtGui.QFontMetrics(font)
- if alignment == 0: #Left
- xPosition = xOffset
- if alignment == 1: #Middle
- xPosition = xOffset - fm.width(titleText)/2
- if alignment == 2: #Right
- xPosition = xOffset - fm.width(titleText)
- painter.drawText(xPosition, yPosition, titleText)
- painter.end()
-
- buffer = QtCore.QBuffer()
- buffer.open(QtCore.QIODevice.ReadWrite)
- self._image1.save(buffer, "PNG")
-
- strio = io.BytesIO()
- strio.write(buffer.data())
- buffer.close()
- strio.seek(0)
- return Image.open(strio)
- '''
+ buffer = QtCore.QBuffer()
+ buffer.open(QtCore.QIODevice.ReadWrite)
+ image1.save(buffer, "PNG")
+
+ strio = io.BytesIO()
+ strio.write(buffer.data())
+ buffer.close()
+ strio.seek(0)
+ return Image.open(strio)
+
+ def pickColor(self):
+ color = QtGui.QColorDialog.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()
+ self.page.lineEdit_textColor.setText(RGBstring)
+ self.page.pushButton_textColor.setStyleSheet(btnStyle)
+
+def RGBFromString(string):
+ ''' turns an RGB string like "255, 255, 255" into a tuple '''
+ try:
+ tup = tuple([int(i) for i in string.split(',')])
+ if len(tup) != 3:
+ raise ValueError
+ for i in tup:
+ if i > 255 or i < 0:
+ raise ValueError
+ return tup
+ except:
+ return (255, 255, 255)