diff options
| author | tassaron | 2017-05-29 20:39:11 -0400 |
|---|---|---|
| committer | tassaron | 2017-05-29 20:39:11 -0400 |
| commit | 8dd7b7d59ab3ef3caf2bbd69dd0b2a7eb134edc7 (patch) | |
| tree | fe5c8b638bc3ddaa1ffc21ade7aee2a28c0c0542 /components | |
| parent | 6433f6d5804fa5021a4187f59905089b2c20bbb6 (diff) | |
added component base class
Diffstat (limited to 'components')
| -rw-r--r-- | components/__base__.py | 57 | ||||
| -rw-r--r-- | components/original.py | 35 | ||||
| -rw-r--r-- | components/text.py | 36 |
3 files changed, 72 insertions, 56 deletions
diff --git a/components/__base__.py b/components/__base__.py new file mode 100644 index 0000000..87440bb --- /dev/null +++ b/components/__base__.py @@ -0,0 +1,57 @@ +from PyQt4 import QtGui + +class Component: + def __str__(self): + return self.__doc__ + + def preFrameRender(self, **kwargs): + for kwarg, value in kwargs.items(): + exec('self.%s = value' % kwarg) + + 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() + return RGBstring, btnStyle + + def RGBFromString(self, 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) + + ''' + ### Reference methods for creating a new component + ### (Inherit from this class and define these) + + def widget(self, parent): + self.parent = parent + page = uic.loadUi(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'example.ui')) + # connect widgets signals + self.page = page + return page + + def update(self): + # read widget values + self.parent.drawPreview() + + def previewRender(self, previewWorker): + width = int(previewWorker.core.settings.value('outputWidth')) + height = int(previewWorker.core.settings.value('outputHeight')) + image = Image.new("RGBA", (width, height), (0,0,0,0)) + return image + + def frameRender(self, moduleNo, frameNo): + width = int(self.worker.core.settings.value('outputWidth')) + height = int(self.worker.core.settings.value('outputHeight')) + image = Image.new("RGBA", (width, height), (0,0,0,0)) + return image + ''' diff --git a/components/original.py b/components/original.py index e901c21..4a149e2 100644 --- a/components/original.py +++ b/components/original.py @@ -1,15 +1,13 @@ -''' Original Audio Visualization ''' import numpy from PIL import Image, ImageDraw from PyQt4 import uic, QtGui from PyQt4.QtGui import QColor import os, random +from . import __base__ -class Component: - def __str__(self): - return __doc__ - +class Component(__base__.Component): + '''Original Audio Visualization''' def widget(self, parent): self.parent = parent self.visColor = (255,255,255) @@ -31,7 +29,7 @@ class Component: def update(self): self.layout = self.page.comboBox_visLayout.currentIndex() - self.visColor = RGBFromString(self.page.lineEdit_visColor.text()) + self.visColor = self.RGBFromString(self.page.lineEdit_visColor.text()) self.parent.drawPreview() def previewRender(self, previewWorker): @@ -41,8 +39,7 @@ class Component: return drawBars(width, height, spectrum, self.visColor, self.layout) def preFrameRender(self, **kwargs): - for kwarg, value in kwargs.items(): - exec('self.%s = value' % kwarg) + super().preFrameRender(**kwargs) self.smoothConstantDown = 0.08 self.smoothConstantUp = 0.8 self.lastSpectrum = None @@ -55,12 +52,9 @@ class Component: 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) + RGBstring, btnStyle = super().pickColor() + 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): @@ -130,16 +124,3 @@ 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 eab33b2..1f5e222 100644 --- a/components/text.py +++ b/components/text.py @@ -1,15 +1,13 @@ -''' Title Text ''' from PIL import Image, ImageDraw from PyQt4.QtGui import QPainter, QColor, QFont from PyQt4 import uic, QtGui, QtCore from PIL.ImageQt import ImageQt import os, io +from . import __base__ -class Component: - def __str__(self): - return __doc__ - +class Component(__base__.Component): + '''Title Text''' def widget(self, parent): height = int(parent.settings.value('outputHeight')) width = int(parent.settings.value('outputWidth')) @@ -62,7 +60,7 @@ class Component: 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.textColor = self.RGBFromString(self.page.lineEdit_textColor.text()) fm = QtGui.QFontMetrics(self.titleFont) if self.alignment == 0: #Left self.xPosition = self.xPosition @@ -77,10 +75,6 @@ class Component: width = int(previewWorker.core.settings.value('outputWidth')) height = int(previewWorker.core.settings.value('outputHeight')) return self.addText(width, height) - - def preFrameRender(self, **kwargs): - for kwarg, value in kwargs.items(): - exec('self.%s = value' % kwarg) def frameRender(self, moduleNo, frameNo): width = int(self.worker.core.settings.value('outputWidth')) @@ -112,22 +106,6 @@ class Component: 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) + RGBstring, btnStyle = super().pickColor() + self.page.lineEdit_textColor.setText(RGBstring) + self.page.pushButton_textColor.setStyleSheet(btnStyle) |
