From e92e9d79f95ad67e83074ef318278c3486601eac Mon Sep 17 00:00:00 2001 From: DH4 Date: Fri, 23 Jun 2017 17:38:05 -0500 Subject: QT5 Conversion + Directory Structure --- src/components/__base__.py | 153 +++++++++++ src/components/__init__.py | 1 + src/components/color.py | 246 +++++++++++++++++ src/components/color.ui | 660 +++++++++++++++++++++++++++++++++++++++++++++ src/components/image.py | 111 ++++++++ src/components/image.ui | 259 ++++++++++++++++++ src/components/original.py | 204 ++++++++++++++ src/components/original.ui | 108 ++++++++ src/components/text.py | 176 ++++++++++++ src/components/text.ui | 316 ++++++++++++++++++++++ src/components/video.py | 273 +++++++++++++++++++ src/components/video.ui | 266 ++++++++++++++++++ 12 files changed, 2773 insertions(+) create mode 100644 src/components/__base__.py create mode 100644 src/components/__init__.py create mode 100644 src/components/color.py create mode 100644 src/components/color.ui create mode 100644 src/components/image.py create mode 100644 src/components/image.ui create mode 100644 src/components/original.py create mode 100644 src/components/original.ui create mode 100644 src/components/text.py create mode 100644 src/components/text.ui create mode 100644 src/components/video.py create mode 100644 src/components/video.ui (limited to 'src/components') diff --git a/src/components/__base__.py b/src/components/__base__.py new file mode 100644 index 0000000..a4677b1 --- /dev/null +++ b/src/components/__base__.py @@ -0,0 +1,153 @@ +from PyQt5 import QtGui, QtCore, QtWidgets +from PIL import Image +import os + + +class Component(QtCore.QObject): + '''A base class for components to inherit from''' + + # modified = QtCore.pyqtSignal(int, bool) + + def __init__(self, moduleIndex, compPos, core): + super().__init__() + self.currentPreset = None + self.moduleIndex = moduleIndex + self.compPos = compPos + self.core = core + + def __str__(self): + return self.__doc__ + + def version(self): + # change this number to identify new versions of a component + return 1 + + def cancel(self): + # please stop any lengthy process in response to this variable + self.canceled = True + + def reset(self): + self.canceled = False + + def update(self): + self.modified.emit(self.compPos, self.savePreset()) + # read your widget values, then call super().update() + + def loadPreset(self, presetDict, presetName): + '''Subclasses take (presetDict, presetName=None) as args. + Must use super().loadPreset(presetDict, presetName) first, + then update self.page widgets using the preset dict. + ''' + self.currentPreset = presetName \ + if presetName != None else presetDict['preset'] + + def preFrameRender(self, **kwargs): + '''Triggered only before a video is exported (video_thread.py) + self.worker = the video thread worker + self.completeAudioArray = a list of audio samples + self.sampleSize = number of audio samples per video frame + self.progressBarUpdate = signal to set progress bar number + self.progressBarSetText = signal to set progress bar text + Use the latter two signals to update the MainProgram if needed + for a long initialization procedure (i.e., for a visualizer) + ''' + for var, value in kwargs.items(): + exec('self.%s = value' % var) + + def command(self, arg): + '''Configure a component using argument from the commandline. + Use super().command(arg) at the end of a subclass's method, + if no arguments are found in that method first + ''' + if arg.startswith('preset='): + _, preset = arg.split('=', 1) + path = os.path.join(self.core.getPresetDir(self), preset) + if not os.path.exists(path): + print('Couldn\'t locate preset "%s"' % preset) + quit(1) + else: + print('Opening "%s" preset on layer %s' % \ + (preset, self.compPos)) + self.core.openPreset(path, self.compPos, preset) + else: + print( + self.__doc__, 'Usage:\n' + 'Open a preset for this component:\n' + ' "preset=Preset Name"') + self.commandHelp() + quit(0) + + def commandHelp(self): + '''Print help text for this Component's commandline arguments''' + + def blankFrame(self, width, height): + return Image.new("RGBA", (width, height), (0, 0, 0, 0)) + + def pickColor(self): + '''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 = QtGui.QColorDialog() + dialog.setOption(QtGui.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(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 widget signals here --- + self.page = page + return page + + def update(self): + super().update() + 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 + ''' + +class BadComponentInit(Exception): + def __init__(self, arg, name): + string = \ +'''################################ +Mandatory argument "%s" not specified + in %s instance initialization +###################################''' + print(string % (arg, name)) + quit() diff --git a/src/components/__init__.py b/src/components/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/components/__init__.py @@ -0,0 +1 @@ + diff --git a/src/components/color.py b/src/components/color.py new file mode 100644 index 0000000..8f9a1d1 --- /dev/null +++ b/src/components/color.py @@ -0,0 +1,246 @@ +from PIL import Image, ImageDraw +from PyQt5 import uic, QtGui, QtCore +from PyQt5.QtGui import QColor +from PIL.ImageQt import ImageQt +import os +from . import __base__ + + +class Component(__base__.Component): + '''Color''' + + modified = QtCore.pyqtSignal(int, dict) + + def widget(self, parent): + self.parent = parent + page = uic.loadUi(os.path.join( + os.path.dirname(os.path.realpath(__file__)), 'color.ui')) + + self.color1 = (0, 0, 0) + self.color2 = (133, 133, 133) + self.x = 0 + self.y = 0 + + page.lineEdit_color1.setText('%s,%s,%s' % self.color1) + 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() + + page.pushButton_color1.setStyleSheet(btnStyle1) + page.pushButton_color2.setStyleSheet(btnStyle2) + page.pushButton_color1.clicked.connect(lambda: self.pickColor(1)) + page.pushButton_color2.clicked.connect(lambda: self.pickColor(2)) + + # disable color #2 until non-default 'fill' option gets changed + page.lineEdit_color2.setDisabled(True) + page.pushButton_color2.setDisabled(True) + page.spinBox_x.valueChanged.connect(self.update) + page.spinBox_y.valueChanged.connect(self.update) + page.spinBox_width.setValue( + int(parent.settings.value("outputWidth"))) + page.spinBox_height.setValue( + int(parent.settings.value("outputHeight"))) + + page.lineEdit_color1.textChanged.connect(self.update) + page.lineEdit_color2.textChanged.connect(self.update) + page.spinBox_x.valueChanged.connect(self.update) + page.spinBox_y.valueChanged.connect(self.update) + page.spinBox_width.valueChanged.connect(self.update) + page.spinBox_height.valueChanged.connect(self.update) + page.checkBox_trans.stateChanged.connect(self.update) + + self.fillLabels = [ \ + 'Solid', + 'Linear Gradient', + 'Radial Gradient', + ] + for label in self.fillLabels: + page.comboBox_fill.addItem(label) + page.comboBox_fill.setCurrentIndex(0) + page.comboBox_fill.currentIndexChanged.connect(self.update) + page.comboBox_spread.currentIndexChanged.connect(self.update) + page.spinBox_radialGradient_end.valueChanged.connect(self.update) + page.spinBox_radialGradient_start.valueChanged.connect(self.update) + page.spinBox_radialGradient_spread.valueChanged.connect(self.update) + page.spinBox_linearGradient_end.valueChanged.connect(self.update) + page.spinBox_linearGradient_start.valueChanged.connect(self.update) + page.checkBox_stretch.stateChanged.connect(self.update) + + self.page = page + return page + + def update(self): + self.color1 = self.RGBFromString(self.page.lineEdit_color1.text()) + self.color2 = self.RGBFromString(self.page.lineEdit_color2.text()) + self.x = self.page.spinBox_x.value() + self.y = self.page.spinBox_y.value() + self.sizeWidth = self.page.spinBox_width.value() + self.sizeHeight = self.page.spinBox_height.value() + self.trans = self.page.checkBox_trans.isChecked() + self.spread = self.page.comboBox_spread.currentIndex() + + self.RG_start = self.page.spinBox_radialGradient_start.value() + self.RG_end = self.page.spinBox_radialGradient_end.value() + self.RG_centre = self.page.spinBox_radialGradient_spread.value() + self.stretch = self.page.checkBox_stretch.isChecked() + self.LG_start = self.page.spinBox_linearGradient_start.value() + self.LG_end = self.page.spinBox_linearGradient_end.value() + + self.fillType = self.page.comboBox_fill.currentIndex() + if self.fillType == 0: + self.page.lineEdit_color2.setEnabled(False) + self.page.pushButton_color2.setEnabled(False) + self.page.checkBox_trans.setEnabled(False) + self.page.checkBox_stretch.setEnabled(False) + self.page.comboBox_spread.setEnabled(False) + 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) + self.page.comboBox_spread.setEnabled(True) + self.page.fillWidget.setCurrentIndex(self.fillType) + + self.parent.drawPreview() + super().update() + + def previewRender(self, previewWorker): + width = int(previewWorker.core.settings.value('outputWidth')) + height = int(previewWorker.core.settings.value('outputHeight')) + return self.drawFrame(width, height) + + def preFrameRender(self, **kwargs): + super().preFrameRender(**kwargs) + return ['static'] + + def frameRender(self, moduleNo, arrayNo, frameNo): + width = int(self.worker.core.settings.value('outputWidth')) + height = int(self.worker.core.settings.value('outputHeight')) + return self.drawFrame(width, height) + + def drawFrame(self, width, height): + r, g, b = self.color1 + shapeSize = (self.sizeWidth, self.sizeHeight) + # in default state, skip all this logic and return a plain fill + if self.fillType==0 and shapeSize == (width, height) \ + and self.x == 0 and self.y == 0: + return Image.new("RGBA", (width, height), (r, g, b, 255)) + + frame = self.blankFrame(width, height) + + # Return a solid image at x, y + if self.fillType == 0: + 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: + image = ImageQt(frame) + painter = QtGui.QPainter(image) + if self.stretch: + w = width; h = height + else: + w = self.sizeWidth; h = self.sizeWidth + + if self.fillType == 1: # Linear Gradient + brush = QtGui.QLinearGradient( + self.LG_start, + self.LG_start, + self.LG_start+width/3, + self.LG_end) + + elif self.fillType == 2: # Radial Gradient + brush = QtGui.QRadialGradient( + self.RG_start, + self.RG_end, + w, h, + self.RG_centre) + + brush.setSpread(self.spread) + brush.setColorAt(0.0, QColor(*self.color1)) + if self.trans: + brush.setColorAt(1.0, QColor(0, 0, 0, 0)) + elif self.fillType == 1 and self.stretch: + brush.setColorAt(0.2, QColor(*self.color2)) + else: + brush.setColorAt(1.0, QColor(*self.color2)) + painter.setBrush(brush) + painter.drawRect(self.x, self.y, + self.sizeWidth, self.sizeHeight) + painter.end() + imBytes = image.bits().asstring(image.numBytes()) + return Image.frombytes('RGBA', (width, height), imBytes) + + def loadPreset(self, pr, presetName=None): + super().loadPreset(pr, presetName) + + self.page.comboBox_fill.setCurrentIndex(pr['fillType']) + self.page.lineEdit_color1.setText('%s,%s,%s' % pr['color1']) + self.page.lineEdit_color2.setText('%s,%s,%s' % pr['color2']) + self.page.spinBox_x.setValue(pr['x']) + self.page.spinBox_y.setValue(pr['y']) + self.page.spinBox_width.setValue(pr['width']) + self.page.spinBox_height.setValue(pr['height']) + self.page.checkBox_trans.setChecked(pr['trans']) + + self.page.spinBox_radialGradient_start.setValue(pr['RG_start']) + self.page.spinBox_radialGradient_end.setValue(pr['RG_end']) + self.page.spinBox_radialGradient_spread.setValue(pr['RG_centre']) + self.page.spinBox_linearGradient_start.setValue(pr['LG_start']) + self.page.spinBox_linearGradient_end.setValue(pr['LG_end']) + self.page.checkBox_stretch.setChecked(pr['stretch']) + self.page.comboBox_spread.setCurrentIndex(pr['spread']) + + 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): + return { + 'preset': self.currentPreset, + 'color1': self.color1, + 'color2': self.color2, + 'x': self.x, + 'y': self.y, + 'fillType': self.fillType, + 'width': self.sizeWidth, + 'height': self.sizeHeight, + 'trans': self.trans, + 'stretch': self.stretch, + 'spread': self.spread, + 'RG_start': self.RG_start, + 'RG_end': self.RG_end, + 'RG_centre': self.RG_centre, + 'LG_start': self.LG_start, + 'LG_end': self.LG_end, + } + + def pickColor(self, num): + RGBstring, btnStyle = super().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') + + def command(self, arg): + if not arg.startswith('preset=') and '=' in arg: + key, arg = arg.split('=', 1) + if key == 'color': + self.page.lineEdit_color1.setText(arg) + return + super().command(arg) diff --git a/src/components/color.ui b/src/components/color.ui new file mode 100644 index 0000000..a9dacea --- /dev/null +++ b/src/components/color.ui @@ -0,0 +1,660 @@ + + + Form + + + + 0 + 0 + 586 + 197 + + + + Form + + + + + + 4 + + + + + + + + 0 + 0 + + + + + 31 + 0 + + + + Color #1 + + + + + + + + 32 + 32 + + + + + + + + 32 + 32 + + + + + + + + + 0 + 0 + + + + + 1 + 0 + + + + 12 + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 5 + 20 + + + + + + + + + 0 + 0 + + + + + 31 + 0 + + + + Color #2 + + + + + + + + 32 + 32 + + + + + + + + 32 + 32 + + + + + + + + + 0 + 0 + + + + + 1 + 0 + + + + 12 + + + + + + + + + 0 + + + + + + 0 + 0 + + + + Width + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 80 + 16777215 + + + + + 0 + 0 + + + + 0 + + + 999999999 + + + 0 + + + + + + + + 0 + 0 + + + + Height + + + + + + + + 0 + 0 + + + + + 80 + 16777215 + + + + 999999999 + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 5 + 20 + + + + + + + + + 0 + 0 + + + + X + + + + + + + + 0 + 0 + + + + + 80 + 16777215 + + + + + 0 + 0 + + + + -10000 + + + 10000 + + + 0 + + + + + + + + 0 + 0 + + + + Y + + + + + + + + 0 + 0 + + + + + 80 + 16777215 + + + + -10000 + + + 10000 + + + + + + + + + 0 + + + + + + 0 + 0 + + + + Fill + + + + + + + + 0 + 0 + + + + -1 + + + QComboBox::AdjustToContentsOnFirstShow + + + + + + + + 0 + 0 + + + + Transparent + + + + + + + + 0 + 0 + + + + Stretch + + + + + + + + Pad + + + + + Reflect + + + + + Repeat + + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + 0 + + + 2 + + + + + + + -1 + 0 + 561 + 31 + + + + + + + + 0 + 0 + + + + Start + + + + + + + -10000 + + + 10000 + + + 10 + + + + + + + + 0 + 0 + + + + End + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + -10000 + + + 10000 + + + 10 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + -1 + -1 + 561 + 31 + + + + + + + + 0 + 0 + + + + Start + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + -10000 + + + 10000 + + + 10 + + + + + + + + 0 + 0 + + + + End + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + -10000 + + + 10000 + + + 10 + + + + + + + + 0 + 0 + + + + Centre + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + QAbstractSpinBox::PlusMinus + + + -10000 + + + 10000 + + + 3 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + + diff --git a/src/components/image.py b/src/components/image.py new file mode 100644 index 0000000..8ca88d3 --- /dev/null +++ b/src/components/image.py @@ -0,0 +1,111 @@ +from PIL import Image, ImageDraw +from PyQt5 import uic, QtGui, QtCore, QtWidgets +import os +from . import __base__ + + +class Component(__base__.Component): + '''Image''' + + modified = QtCore.pyqtSignal(int, dict) + + def widget(self, parent): + self.parent = parent + self.settings = parent.settings + page = uic.loadUi(os.path.join( + os.path.dirname(os.path.realpath(__file__)), 'image.ui')) + self.imagePath = '' + self.x = 0 + self.y = 0 + + page.lineEdit_image.textChanged.connect(self.update) + page.pushButton_image.clicked.connect(self.pickImage) + page.spinBox_scale.valueChanged.connect(self.update) + page.checkBox_stretch.stateChanged.connect(self.update) + page.spinBox_x.valueChanged.connect(self.update) + page.spinBox_y.valueChanged.connect(self.update) + + self.page = page + return page + + def update(self): + self.imagePath = self.page.lineEdit_image.text() + self.scale = self.page.spinBox_scale.value() + self.xPosition = self.page.spinBox_x.value() + self.yPosition = self.page.spinBox_y.value() + self.stretched = self.page.checkBox_stretch.isChecked() + self.parent.drawPreview() + super().update() + + def previewRender(self, previewWorker): + self.imageFormats = previewWorker.core.imageFormats + width = int(previewWorker.core.settings.value('outputWidth')) + height = int(previewWorker.core.settings.value('outputHeight')) + return self.drawFrame(width, height) + + def preFrameRender(self, **kwargs): + super().preFrameRender(**kwargs) + return ['static'] + + def frameRender(self, moduleNo, arrayNo, frameNo): + width = int(self.worker.core.settings.value('outputWidth')) + height = int(self.worker.core.settings.value('outputHeight')) + return self.drawFrame(width, height) + + def drawFrame(self, width, height): + frame = self.blankFrame(width, height) + if self.imagePath and os.path.exists(self.imagePath): + image = Image.open(self.imagePath) + if self.stretched and image.size != (width, height): + image = image.resize((width, height), Image.ANTIALIAS) + if self.scale != 100: + newHeight = int((image.height / 100) * self.scale) + newWidth = int((image.width / 100) * self.scale) + image = image.resize((newWidth, newHeight), Image.ANTIALIAS) + frame.paste(image, box=(self.xPosition, self.yPosition)) + return frame + + def loadPreset(self, pr, presetName=None): + super().loadPreset(pr, presetName) + self.page.lineEdit_image.setText(pr['image']) + self.page.spinBox_scale.setValue(pr['scale']) + self.page.spinBox_x.setValue(pr['x']) + self.page.spinBox_y.setValue(pr['y']) + self.page.checkBox_stretch.setChecked(pr['stretched']) + + def savePreset(self): + return { + 'preset': self.currentPreset, + 'image': self.imagePath, + 'scale': self.scale, + 'stretched': self.stretched, + 'x': self.xPosition, + 'y': self.yPosition, + } + + def pickImage(self): + imgDir = self.settings.value("backgroundDir", os.path.expanduser("~")) + filename = QtGui.QFileDialog.getOpenFileName( + self.page, "Choose Image", imgDir, + "Image Files (%s)" % " ".join(self.imageFormats)) + if filename: + self.settings.setValue("backgroundDir", os.path.dirname(filename)) + self.page.lineEdit_image.setText(filename) + self.update() + + def command(self, arg): + if not arg.startswith('preset=') and '=' in arg: + key, arg = arg.split('=', 1) + if key == 'path' and os.path.exists(arg): + try: + Image.open(arg) + self.page.lineEdit_image.setText(arg) + self.page.checkBox_stretch.setChecked(True) + return + except OSError as e: + print("Not a supported image format") + quit(1) + super().command(arg) + + def commandHelp(self): + print('Load an image:\n path=/filepath/to/image.png') diff --git a/src/components/image.ui b/src/components/image.ui new file mode 100644 index 0000000..6df03a5 --- /dev/null +++ b/src/components/image.ui @@ -0,0 +1,259 @@ + + + Form + + + + 0 + 0 + 586 + 197 + + + + Form + + + + + + 4 + + + + + + + + 0 + 0 + + + + + 31 + 0 + + + + Image + + + + + + + + 1 + 0 + + + + + + + + + 0 + 0 + + + + + 1 + 0 + + + + + 32 + 32 + + + + ... + + + + 32 + 32 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 5 + 20 + + + + + + + + + 0 + 0 + + + + X + + + + + + + + 0 + 0 + + + + + 80 + 16777215 + + + + -10000 + + + 10000 + + + + + + + + 0 + 0 + + + + Y + + + + + + + + 0 + 0 + + + + + 80 + 16777215 + + + + + 0 + 0 + + + + -1000 + + + 1000 + + + 0 + + + + + + + + + + + + + Stretch + + + false + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 5 + 20 + + + + + + + + Scale + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + QAbstractSpinBox::UpDownArrows + + + % + + + 10 + + + 400 + + + 100 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/src/components/original.py b/src/components/original.py new file mode 100644 index 0000000..61f463d --- /dev/null +++ b/src/components/original.py @@ -0,0 +1,204 @@ +import numpy +from PIL import Image, ImageDraw +from PyQt5 import uic, QtGui, QtCore +from PyQt5.QtGui import QColor +import os +from . import __base__ +import time +from copy import copy + + +class Component(__base__.Component): + '''Original Audio Visualization''' + + modified = QtCore.pyqtSignal(int, dict) + + 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") + page.comboBox_visLayout.addItem("Split") + page.comboBox_visLayout.addItem("Bottom") + 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 + self.canceled = False + return page + + def update(self): + self.layout = self.page.comboBox_visLayout.currentIndex() + self.visColor = self.RGBFromString(self.page.lineEdit_visColor.text()) + self.parent.drawPreview() + super().update() + + def loadPreset(self, pr, presetName=None): + super().loadPreset(pr, presetName) + + 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) + self.page.comboBox_visLayout.setCurrentIndex(pr['layout']) + + def savePreset(self): + return { + 'preset': self.currentPreset, + 'layout': self.layout, + 'visColor': self.visColor, + } + + 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 self.drawBars( + width, height, spectrum, self.visColor, self.layout) + + def preFrameRender(self, **kwargs): + super().preFrameRender(**kwargs) + self.smoothConstantDown = 0.08 + self.smoothConstantUp = 0.8 + self.lastSpectrum = None + self.spectrumArray = {} + self.width = int(self.worker.core.settings.value('outputWidth')) + self.height = int(self.worker.core.settings.value('outputHeight')) + + for i in range(0, len(self.completeAudioArray), self.sampleSize): + if self.canceled: + break + self.lastSpectrum = self.transformData( + i, self.completeAudioArray, self.sampleSize, + self.smoothConstantDown, self.smoothConstantUp, + self.lastSpectrum) + self.spectrumArray[i] = copy(self.lastSpectrum) + + progress = int(100*(i/len(self.completeAudioArray))) + if progress >= 100: + progress = 100 + pStr = "Analyzing audio: "+str(progress)+'%' + self.progressBarSetText.emit(pStr) + self.progressBarUpdate.emit(int(progress)) + + def frameRender(self, moduleNo, arrayNo, frameNo): + return self.drawBars( + self.width, self.height, + self.spectrumArray[arrayNo], + self.visColor, self.layout) + + def pickColor(self): + RGBstring, btnStyle = super().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): + if len(completeAudioArray) < (i + sampleSize): + sampleSize = len(completeAudioArray) - i + + window = numpy.hanning(sampleSize) + data = completeAudioArray[i:i+sampleSize][::1] * window + paddedSampleSize = 2048 + paddedData = numpy.pad( + data, (0, paddedSampleSize - sampleSize), 'constant') + spectrum = numpy.fft.fft(paddedData) + sample_rate = 44100 + frequencies = numpy.fft.fftfreq(len(spectrum), 1./sample_rate) + + y = abs(spectrum[0:int(paddedSampleSize/2) - 1]) + + # filter the noise away + # y[y<80] = 0 + + y = 20 * numpy.log10(y) + y[numpy.isinf(y)] = 0 + + if lastSpectrum is not None: + lastSpectrum[y < lastSpectrum] = \ + y[y < lastSpectrum] * smoothConstantDown + \ + lastSpectrum[y < lastSpectrum] * (1 - smoothConstantDown) + + lastSpectrum[y >= lastSpectrum] = \ + y[y >= lastSpectrum] * smoothConstantUp + \ + lastSpectrum[y >= lastSpectrum] * (1 - smoothConstantUp) + else: + lastSpectrum = y + + x = frequencies[0:int(paddedSampleSize/2) - 1] + + return lastSpectrum + + def drawBars(self, width, height, spectrum, color, layout): + vH = height-height/8 + bF = width / 64 + bH = bF / 2 + bQ = bF / 4 + imTop = self.blankFrame(width, height) + draw = ImageDraw.Draw(imTop) + r, g, b = color + color2 = (r, g, b, 125) + + bP = height / 1200 + + for j in range(0, 63): + draw.rectangle(( + bH + j * bF, vH+bQ, bH + j * bF + bF, vH + bQ - + spectrum[j * 4] * bP - bH), fill=color2) + + draw.rectangle(( + bH + bQ + j * bF, vH, bH + bQ + j * bF + bH, vH - + spectrum[j * 4] * bP), fill=color) + + imBottom = imTop.transpose(Image.FLIP_TOP_BOTTOM) + + im = self.blankFrame(width, height) + + if layout == 0: + y = 0 - int(height/100*43) + im.paste(imTop, (0, y), mask=imTop) + y = 0 + int(height/100*43) + im.paste(imBottom, (0, y), mask=imBottom) + + if layout == 1: + y = 0 + int(height/100*10) + im.paste(imTop, (0, y), mask=imTop) + y = 0 - int(height/100*10) + im.paste(imBottom, (0, y), mask=imBottom) + + if layout == 2: + y = 0 + int(height/100*10) + im.paste(imTop, (0, y), mask=imTop) + + return im + + def command(self, arg): + if not arg.startswith('preset=') and '=' in arg: + key, arg = arg.split('=', 1) + if key == 'color': + self.page.lineEdit_visColor.setText(arg) + return + elif key == 'layout': + if arg == 'classic': + self.page.comboBox_visLayout.setCurrentIndex(0) + elif arg == 'split': + self.page.comboBox_visLayout.setCurrentIndex(1) + elif arg == 'bottom': + self.page.comboBox_visLayout.setCurrentIndex(2) + return + super().command(arg) + + def commandHelp(self): + print('Give a layout name:\n layout=[classic/split/bottom]') + print('Specify a color:\n color=255,255,255') diff --git a/src/components/original.ui b/src/components/original.ui new file mode 100644 index 0000000..5808653 --- /dev/null +++ b/src/components/original.ui @@ -0,0 +1,108 @@ + + + Form + + + + 0 + 0 + 633 + 178 + + + + + 180 + 0 + + + + Form + + + + + + 4 + + + + + + 0 + 0 + + + + Visualizer Layout + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 5 + 20 + + + + + + + + Visualizer Color + + + + + + + + 32 + 32 + + + + + + + + 32 + 32 + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/src/components/text.py b/src/components/text.py new file mode 100644 index 0000000..0f599ed --- /dev/null +++ b/src/components/text.py @@ -0,0 +1,176 @@ +from PIL import Image, ImageDraw +from PyQt5.QtGui import QPainter, QColor, QFont +from PyQt5 import uic, QtGui, QtCore +from PIL.ImageQt import ImageQt +import os +import io +from . import __base__ + + +class Component(__base__.Component): + '''Title Text''' + + modified = QtCore.pyqtSignal(int, dict) + + def __init__(self, *args): + super().__init__(*args) + self.titleFont = QFont() + + 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.alignment = 1 + self.fontSize = height / 13.5 + fm = QtGui.QFontMetrics(self.titleFont) + self.xPosition = width / 2 - fm.width(self.title)/2 + self.yPosition = height / 2 * 1.036 + + 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.lineEdit_textColor.setText('%s,%s,%s' % self.textColor) + page.pushButton_textColor.clicked.connect(self.pickColor) + btnStyle = "QPushButton { background-color : %s; outline: none; }" \ + % QColor(*self.textColor).name() + page.pushButton_textColor.setStyleSheet(btnStyle) + + page.lineEdit_title.setText(self.title) + 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 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 = self.RGBFromString( + self.page.lineEdit_textColor.text()) + self.parent.drawPreview() + super().update() + + def getXY(self): + '''Returns true x, y after considering alignment settings''' + fm = QtGui.QFontMetrics(self.titleFont) + if self.alignment == 0: # Left + x = self.xPosition + + if self.alignment == 1: # Middle + offset = fm.width(self.title)/2 + x = self.xPosition - offset + + if self.alignment == 2: # Right + offset = fm.width(self.title) + x = self.xPosition - offset + return x, self.yPosition + + def loadPreset(self, pr, presetName=None): + super().loadPreset(pr, presetName) + + self.page.lineEdit_title.setText(pr['title']) + font = QFont() + font.fromString(pr['titleFont']) + self.page.fontComboBox_titleFont.setCurrentFont(font) + self.page.spinBox_fontSize.setValue(pr['fontSize']) + self.page.comboBox_textAlign.setCurrentIndex(pr['alignment']) + self.page.spinBox_xTextAlign.setValue(pr['xPosition']) + self.page.spinBox_yTextAlign.setValue(pr['yPosition']) + 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): + return { + 'preset': self.currentPreset, + 'title': self.title, + 'titleFont': self.titleFont.toString(), + 'alignment': self.alignment, + 'fontSize': self.fontSize, + 'xPosition': self.xPosition, + 'yPosition': self.yPosition, + 'textColor': self.textColor + } + + def previewRender(self, previewWorker): + width = int(previewWorker.core.settings.value('outputWidth')) + height = int(previewWorker.core.settings.value('outputHeight')) + return self.addText(width, height) + + def preFrameRender(self, **kwargs): + super().preFrameRender(**kwargs) + return ['static'] + + def frameRender(self, moduleNo, arrayNo, frameNo): + 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): + x, y = self.getXY() + im = self.blankFrame(width, height) + image = ImageQt(im) + + painter = QPainter(image) + self.titleFont.setPixelSize(self.fontSize) + painter.setFont(self.titleFont) + painter.setPen(QColor(*self.textColor)) + painter.drawText(x, y, self.title) + painter.end() + + imBytes = image.bits().asstring(image.numBytes()) + + return Image.frombytes('RGBA', (width, height), imBytes) + + def pickColor(self): + RGBstring, btnStyle = super().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"') + print('Specify a text color:\n color=255,255,255') + print('Set custom x, y position:\n x=500 y=500') + + def command(self, arg): + if not arg.startswith('preset=') and '=' in arg: + 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 + super().command(arg) diff --git a/src/components/text.ui b/src/components/text.ui new file mode 100644 index 0000000..05e7f8e --- /dev/null +++ b/src/components/text.ui @@ -0,0 +1,316 @@ + + + Form + + + + 0 + 0 + 586 + 197 + + + + Form + + + + + + 4 + + + + + + + + 0 + 0 + + + + Font + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 5 + 20 + + + + + + + + + 0 + 0 + + + + Font Size + + + + + + + 500 + + + + + + + + + + + + 0 + 0 + + + + Text Layout + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 5 + 20 + + + + + + + + Text Color + + + + + + + + 32 + 32 + + + + + + + + 32 + 32 + + + + + + + + + + + + + 0 + + + + + Title + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + Testing New GUI + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 5 + 20 + + + + + + + + + 0 + 0 + + + + X + + + + + + + + 0 + 0 + + + + + 80 + 16777215 + + + + + 0 + 0 + + + + 0 + + + 999999999 + + + 0 + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 5 + 20 + + + + + + + + + 0 + 0 + + + + Y + + + + + + + + 0 + 0 + + + + + 80 + 16777215 + + + + 999999999 + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/src/components/video.py b/src/components/video.py new file mode 100644 index 0000000..58ce7a3 --- /dev/null +++ b/src/components/video.py @@ -0,0 +1,273 @@ +from PIL import Image, ImageDraw +from PyQt5 import uic, QtGui, QtCore +import os +import subprocess +import threading +from queue import PriorityQueue +from . import __base__ + + +class Video: + '''Video Component Frame-Fetcher''' + def __init__(self, **kwargs): + mandatoryArgs = [ + 'ffmpeg', # path to ffmpeg, usually core.FFMPEG_BIN + 'videoPath', + 'width', + 'height', + 'scale', # percentage scale + 'frameRate', # frames per second + 'chunkSize', # number of bytes in one frame + 'parent', # mainwindow object + 'component', # component object + ] + for arg in mandatoryArgs: + try: + exec('self.%s = kwargs[arg]' % arg) + except KeyError: + raise __base__.BadComponentInit(arg, self.__doc__) + + self.frameNo = -1 + self.currentFrame = 'None' + if 'loopVideo' in kwargs and kwargs['loopVideo']: + self.loopValue = '-1' + else: + self.loopValue = '0' + self.command = [ + self.ffmpeg, + '-thread_queue_size', '512', + '-r', str(self.frameRate), + '-stream_loop', self.loopValue, + '-i', self.videoPath, + '-f', 'image2pipe', + '-pix_fmt', 'rgba', + '-filter:v', 'scale=%s:%s' % + scale(self.scale, self.width, self.height, str), + '-vcodec', 'rawvideo', '-', + ] + + self.frameBuffer = PriorityQueue() + self.frameBuffer.maxsize = self.frameRate + self.finishedFrames = {} + + self.thread = threading.Thread( + target=self.fillBuffer, + name=self.__doc__ + ) + self.thread.daemon = True + self.thread.start() + + def frame(self, num): + while True: + if num in self.finishedFrames: + image = self.finishedFrames.pop(num) + return finalizeFrame( + self.component, image, self.width, self.height) + + i, image = self.frameBuffer.get() + self.finishedFrames[i] = image + self.frameBuffer.task_done() + + def fillBuffer(self): + pipe = subprocess.Popen( + self.command, stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL, bufsize=10**8 + ) + while True: + if self.parent.canceled: + break + self.frameNo += 1 + + # If we run out of frames, use the last good frame and loop. + if len(self.currentFrame) == 0: + self.frameBuffer.put((self.frameNo-1, self.lastFrame)) + continue + + self.currentFrame = pipe.stdout.read(self.chunkSize) + if len(self.currentFrame) != 0: + self.frameBuffer.put((self.frameNo, self.currentFrame)) + self.lastFrame = self.currentFrame + + +class Component(__base__.Component): + '''Video''' + + modified = QtCore.pyqtSignal(int, dict) + + def widget(self, parent): + self.parent = parent + self.settings = parent.settings + page = uic.loadUi(os.path.join( + os.path.dirname(os.path.realpath(__file__)), + 'video.ui' + )) + self.videoPath = '' + self.x = 0 + self.y = 0 + self.loopVideo = False + + page.lineEdit_video.textChanged.connect(self.update) + page.pushButton_video.clicked.connect(self.pickVideo) + page.checkBox_loop.stateChanged.connect(self.update) + page.checkBox_distort.stateChanged.connect(self.update) + page.spinBox_scale.valueChanged.connect(self.update) + page.spinBox_x.valueChanged.connect(self.update) + page.spinBox_y.valueChanged.connect(self.update) + + self.page = page + return page + + def update(self): + self.videoPath = self.page.lineEdit_video.text() + self.loopVideo = self.page.checkBox_loop.isChecked() + self.distort = self.page.checkBox_distort.isChecked() + self.scale = self.page.spinBox_scale.value() + self.xPosition = self.page.spinBox_x.value() + self.yPosition = self.page.spinBox_y.value() + self.parent.drawPreview() + super().update() + + def previewRender(self, previewWorker): + self.videoFormats = previewWorker.core.videoFormats + width = int(previewWorker.core.settings.value('outputWidth')) + height = int(previewWorker.core.settings.value('outputHeight')) + self.updateChunksize(width, height) + frame = self.getPreviewFrame(width, height) + if not frame: + return self.blankFrame(width, height) + else: + return frame + + def preFrameRender(self, **kwargs): + super().preFrameRender(**kwargs) + width = int(self.worker.core.settings.value('outputWidth')) + height = int(self.worker.core.settings.value('outputHeight')) + self.blankFrame_ = self.blankFrame(width, height) + self.updateChunksize(width, height) + self.video = Video( + ffmpeg=self.parent.core.FFMPEG_BIN, videoPath=self.videoPath, + width=width, height=height, chunkSize=self.chunkSize, + frameRate=int(self.settings.value("outputFrameRate")), + parent=self.parent, loopVideo=self.loopVideo, + component=self, scale=self.scale + ) if os.path.exists(self.videoPath) else None + + def frameRender(self, moduleNo, arrayNo, frameNo): + if self.video: + return self.video.frame(frameNo) + else: + return self.blankFrame_ + + def loadPreset(self, pr, presetName=None): + super().loadPreset(pr, presetName) + self.page.lineEdit_video.setText(pr['video']) + self.page.checkBox_loop.setChecked(pr['loop']) + self.page.checkBox_distort.setChecked(pr['distort']) + self.page.spinBox_scale.setValue(pr['scale']) + self.page.spinBox_x.setValue(pr['x']) + self.page.spinBox_y.setValue(pr['y']) + + def savePreset(self): + return { + 'preset': self.currentPreset, + 'video': self.videoPath, + 'loop': self.loopVideo, + 'distort': self.distort, + 'scale': self.scale, + 'x': self.xPosition, + 'y': self.yPosition, + } + + def pickVideo(self): + imgDir = self.settings.value("backgroundDir", os.path.expanduser("~")) + filename = QtGui.QFileDialog.getOpenFileName( + self.page, "Choose Video", + imgDir, "Video Files (%s)" % " ".join(self.videoFormats) + ) + if filename: + self.settings.setValue("backgroundDir", os.path.dirname(filename)) + self.page.lineEdit_video.setText(filename) + self.update() + + def getPreviewFrame(self, width, height): + if not self.videoPath or not os.path.exists(self.videoPath): + return + + command = [ + self.parent.core.FFMPEG_BIN, + '-thread_queue_size', '512', + '-i', self.videoPath, + '-f', 'image2pipe', + '-pix_fmt', 'rgba', + '-filter:v', 'scale=%s:%s' % + scale(self.scale, width, height, str), + '-vcodec', 'rawvideo', '-', + '-ss', '90', + '-vframes', '1', + ] + pipe = subprocess.Popen( + command, stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL, bufsize=10**8 + ) + byteFrame = pipe.stdout.read(self.chunkSize) + frame = finalizeFrame(self, byteFrame, width, height) + pipe.stdout.close() + pipe.kill() + + return frame + + def updateChunksize(self, width, height): + if self.scale != 100 and not self.distort: + width, height = scale(self.scale, width, height, int) + self.chunkSize = 4*width*height + + def command(self, arg): + if not arg.startswith('preset=') and '=' in arg: + key, arg = arg.split('=', 1) + if key == 'path' and os.path.exists(arg): + if os.path.splitext(arg)[1] in self.core.videoFormats: + self.page.lineEdit_video.setText(arg) + self.page.spinBox_scale.setValue(100) + self.page.checkBox_loop.setChecked(True) + return + else: + print("Not a supported video format") + quit(1) + super().command(arg) + + def commandHelp(self): + print('Load a video:\n path=/filepath/to/video.mp4') + +def scale(scale, width, height, returntype=None): + width = (float(width) / 100.0) * float(scale) + height = (float(height) / 100.0) * float(scale) + if returntype == str: + return (str(int(width)), str(int(height))) + elif returntype == int: + return (int(width), int(height)) + else: + return (width, height) + +def finalizeFrame(self, imageData, width, height): + if self.distort: + try: + image = Image.frombytes( + 'RGBA', + (width, height), + imageData) + except ValueError: + print('#### ignored invalid data caused by distortion ####') + image = self.blankFrame(width, height) + else: + image = Image.frombytes( + 'RGBA', + scale(self.scale, width, height, int), + imageData) + + if self.scale != 100 \ + or self.xPosition != 0 or self.yPosition != 0: + frame = self.blankFrame(width, height) + frame.paste(image, box=(self.xPosition, self.yPosition)) + else: + frame = image + return frame diff --git a/src/components/video.ui b/src/components/video.ui new file mode 100644 index 0000000..f05e8a5 --- /dev/null +++ b/src/components/video.ui @@ -0,0 +1,266 @@ + + + Form + + + + 0 + 0 + 586 + 197 + + + + Form + + + + + + 4 + + + + + + + + 0 + 0 + + + + + 31 + 0 + + + + Video + + + + + + + + 1 + 0 + + + + + + + + + 0 + 0 + + + + + 1 + 0 + + + + + 32 + 32 + + + + ... + + + + 32 + 32 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 5 + 20 + + + + + + + + + 0 + 0 + + + + X + + + + + + + + 0 + 0 + + + + + 80 + 16777215 + + + + -10000 + + + 10000 + + + + + + + + 0 + 0 + + + + Y + + + + + + + + 0 + 0 + + + + + 80 + 16777215 + + + + + 0 + 0 + + + + -10000 + + + 10000 + + + 0 + + + + + + + + + + + + + Loop + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 5 + 20 + + + + + + + + Distort by scale + + + + + + + Scale + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + QAbstractSpinBox::UpDownArrows + + + % + + + 10 + + + 400 + + + 100 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + -- cgit v1.2.3 From 680214f5180a12f2250d8e266df9375ce99b9f80 Mon Sep 17 00:00:00 2001 From: tassaron Date: Fri, 23 Jun 2017 23:00:24 -0400 Subject: qt5 fixes also pep8 compliance --- src/command.py | 15 +++---- src/components/__base__.py | 14 +++---- src/components/color.py | 15 ++++--- src/components/image.py | 2 +- src/components/video.py | 14 ++++--- src/core.py | 28 +++++++------ src/main.py | 6 +-- src/mainwindow.py | 100 ++++++++++++++++++++++++++------------------- src/presetmanager.py | 55 +++++++++++++------------ src/video_thread.py | 11 ++--- 10 files changed, 143 insertions(+), 117 deletions(-) (limited to 'src/components') diff --git a/src/command.py b/src/command.py index 1a1e810..2f71f31 100644 --- a/src/command.py +++ b/src/command.py @@ -22,9 +22,9 @@ class Command(QtCore.QObject): self.parser = argparse.ArgumentParser( description='Create a visualization for an audio file', epilog='EXAMPLE COMMAND: main.py myvideotemplate.avp ' - '-i ~/Music/song.mp3 -o ~/video.mp4 ' - '-c 0 image path=~/Pictures/thisWeeksPicture.jpg ' - '-c 1 video "preset=My Logo" -c 2 vis layout=classic') + '-i ~/Music/song.mp3 -o ~/video.mp4 ' + '-c 0 image path=~/Pictures/thisWeeksPicture.jpg ' + '-c 1 video "preset=My Logo" -c 2 vis layout=classic') self.parser.add_argument( '-i', '--input', metavar='SOUND', help='input audio file') @@ -113,10 +113,11 @@ class Command(QtCore.QObject): if name.capitalize() in compName: return compName - compFileNames = [ \ - os.path.splitext(os.path.basename( - mod.__file__))[0] \ - for mod in self.core.modules \ + compFileNames = [ + os.path.splitext( + os.path.basename(mod.__file__) + )[0] + for mod in self.core.modules ] for i, compFileName in enumerate(compFileNames): if name.lower() in compFileName: diff --git a/src/components/__base__.py b/src/components/__base__.py index a4677b1..a24af40 100644 --- a/src/components/__base__.py +++ b/src/components/__base__.py @@ -39,7 +39,7 @@ class Component(QtCore.QObject): then update self.page widgets using the preset dict. ''' self.currentPreset = presetName \ - if presetName != None else presetDict['preset'] + if presetName is not None else presetDict['preset'] def preFrameRender(self, **kwargs): '''Triggered only before a video is exported (video_thread.py) @@ -66,8 +66,8 @@ class Component(QtCore.QObject): print('Couldn\'t locate preset "%s"' % preset) quit(1) else: - print('Opening "%s" preset on layer %s' % \ - (preset, self.compPos)) + print('Opening "%s" preset on layer %s' % ( + preset, self.compPos)) self.core.openPreset(path, self.compPos, preset) else: print( @@ -88,8 +88,8 @@ class Component(QtCore.QObject): and return this as an RGB string and QPushButton stylesheet. In a subclass apply stylesheet to any color selection widgets ''' - dialog = QtGui.QColorDialog() - dialog.setOption(QtGui.QColorDialog.ShowAlphaChannel, True) + dialog = QtWidgets.QColorDialog() + dialog.setOption(QtWidgets.QColorDialog.ShowAlphaChannel, True) color = dialog.getColor() if color.isValid(): RGBstring = '%s,%s,%s' % ( @@ -142,10 +142,10 @@ class Component(QtCore.QObject): return image ''' + class BadComponentInit(Exception): def __init__(self, arg, name): - string = \ -'''################################ + string = '''################################ Mandatory argument "%s" not specified in %s instance initialization ###################################''' diff --git a/src/components/color.py b/src/components/color.py index 8f9a1d1..2e3902a 100644 --- a/src/components/color.py +++ b/src/components/color.py @@ -53,7 +53,7 @@ class Component(__base__.Component): page.spinBox_height.valueChanged.connect(self.update) page.checkBox_trans.stateChanged.connect(self.update) - self.fillLabels = [ \ + self.fillLabels = [ 'Solid', 'Linear Gradient', 'Radial Gradient', @@ -126,8 +126,8 @@ class Component(__base__.Component): r, g, b = self.color1 shapeSize = (self.sizeWidth, self.sizeHeight) # in default state, skip all this logic and return a plain fill - if self.fillType==0 and shapeSize == (width, height) \ - and self.x == 0 and self.y == 0: + if self.fillType == 0 and shapeSize == (width, height) \ + and self.x == 0 and self.y == 0: return Image.new("RGBA", (width, height), (r, g, b, 255)) frame = self.blankFrame(width, height) @@ -143,9 +143,11 @@ class Component(__base__.Component): image = ImageQt(frame) painter = QtGui.QPainter(image) if self.stretch: - w = width; h = height + w = width + h = height else: - w = self.sizeWidth; h = self.sizeWidth + w = self.sizeWidth + h = self.sizeWidth if self.fillType == 1: # Linear Gradient brush = QtGui.QLinearGradient( @@ -170,7 +172,8 @@ class Component(__base__.Component): else: brush.setColorAt(1.0, QColor(*self.color2)) painter.setBrush(brush) - painter.drawRect(self.x, self.y, + painter.drawRect( + self.x, self.y, self.sizeWidth, self.sizeHeight) painter.end() imBytes = image.bits().asstring(image.numBytes()) diff --git a/src/components/image.py b/src/components/image.py index 8ca88d3..3517af6 100644 --- a/src/components/image.py +++ b/src/components/image.py @@ -85,7 +85,7 @@ class Component(__base__.Component): def pickImage(self): imgDir = self.settings.value("backgroundDir", os.path.expanduser("~")) - filename = QtGui.QFileDialog.getOpenFileName( + filename, _ = QtWidgets.QFileDialog.getOpenFileName( self.page, "Choose Image", imgDir, "Image Files (%s)" % " ".join(self.imageFormats)) if filename: diff --git a/src/components/video.py b/src/components/video.py index 58ce7a3..0090426 100644 --- a/src/components/video.py +++ b/src/components/video.py @@ -41,8 +41,8 @@ class Video: '-i', self.videoPath, '-f', 'image2pipe', '-pix_fmt', 'rgba', - '-filter:v', 'scale=%s:%s' % - scale(self.scale, self.width, self.height, str), + '-filter:v', 'scale=%s:%s' % scale( + self.scale, self.width, self.height, str), '-vcodec', 'rawvideo', '-', ] @@ -180,7 +180,7 @@ class Component(__base__.Component): def pickVideo(self): imgDir = self.settings.value("backgroundDir", os.path.expanduser("~")) - filename = QtGui.QFileDialog.getOpenFileName( + filename, _ = QtWidgets.QFileDialog.getOpenFileName( self.page, "Choose Video", imgDir, "Video Files (%s)" % " ".join(self.videoFormats) ) @@ -199,8 +199,8 @@ class Component(__base__.Component): '-i', self.videoPath, '-f', 'image2pipe', '-pix_fmt', 'rgba', - '-filter:v', 'scale=%s:%s' % - scale(self.scale, width, height, str), + '-filter:v', 'scale=%s:%s' % scale( + self.scale, width, height, str), '-vcodec', 'rawvideo', '-', '-ss', '90', '-vframes', '1', @@ -238,6 +238,7 @@ class Component(__base__.Component): def commandHelp(self): print('Load a video:\n path=/filepath/to/video.mp4') + def scale(scale, width, height, returntype=None): width = (float(width) / 100.0) * float(scale) height = (float(height) / 100.0) * float(scale) @@ -248,6 +249,7 @@ def scale(scale, width, height, returntype=None): else: return (width, height) + def finalizeFrame(self, imageData, width, height): if self.distort: try: @@ -265,7 +267,7 @@ def finalizeFrame(self, imageData, width, height): imageData) if self.scale != 100 \ - or self.xPosition != 0 or self.yPosition != 0: + or self.xPosition != 0 or self.yPosition != 0: frame = self.blankFrame(width, height) frame.paste(image, box=(self.xPosition, self.yPosition)) else: diff --git a/src/core.py b/src/core.py index bb5d351..670a3c5 100644 --- a/src/core.py +++ b/src/core.py @@ -179,7 +179,7 @@ class Core(): clearThis = False # add loaded named presets to savedPresets dict - if 'preset' in preset and preset['preset'] != None: + if 'preset' in preset and preset['preset'] is not None: nam = preset['preset'] filepath2 = os.path.join( self.presetDir, name, str(vers), nam) @@ -195,12 +195,12 @@ class Core(): -1, self.moduleIndexFor(name), loader) - if i == None: + if i is None: loader.showMessage(msg="Too many components!") break try: - if 'preset' in preset and preset['preset'] != None: + if 'preset' in preset and preset['preset'] is not None: self.selectedComponents[i].loadPreset( preset ) @@ -210,8 +210,8 @@ class Core(): preset['preset'] ) except KeyError as e: - print('%s missing value %s' % - (self.selectedComponents[i], e)) + print('%s missing value %s' % ( + self.selectedComponents[i], e)) if clearThis: self.clearPreset(i) @@ -221,7 +221,6 @@ class Core(): errcode = 1 data = sys.exc_info() - if errcode == 1: typ, value, _ = data if typ.__name__ == KeyError: @@ -274,11 +273,11 @@ class Core(): i += 1 elif i == 2: lastCompPreset = Core.presetFromString(line) - data[section].append( - (lastCompName, + data[section].append(( + lastCompName, lastCompVers, - lastCompPreset) - ) + lastCompPreset + )) i = 0 return 0, data except: @@ -309,7 +308,9 @@ class Core(): return False, '' def exportPreset(self, exportPath, compName, vers, origName): - internalPath = os.path.join(self.presetDir, compName, str(vers), origName) + internalPath = os.path.join( + self.presetDir, compName, str(vers), origName + ) if not os.path.exists(internalPath): return if os.path.exists(exportPath): @@ -328,7 +329,7 @@ class Core(): return False def createPresetFile( - self, compName, vers, presetName, saveValueStore, filepath=''): + self, compName, vers, presetName, saveValueStore, filepath=''): '''Create a preset file (.avl) at filepath using args. Or if filepath is empty, create an internal preset using args''' if not filepath: @@ -463,7 +464,8 @@ class Core(): @staticmethod def presetToString(dictionary): '''Alphabetizes a dict into OrderedDict & returns string repr''' - return repr(OrderedDict(sorted(dictionary.items(), key=lambda t: t[0]))) + return repr( + OrderedDict(sorted(dictionary.items(), key=lambda t: t[0]))) @staticmethod def presetFromString(string): diff --git a/src/main.py b/src/main.py index 4bf26db..58fdb46 100644 --- a/src/main.py +++ b/src/main.py @@ -30,7 +30,6 @@ def LoadDefaultSettings(self): } for parm, value in default.items(): - #print(parm, self.settings.value(parm)) if self.settings.value(parm) is None: self.settings.setValue(parm, value) @@ -51,7 +50,7 @@ if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) app.setApplicationName("audio-visualizer") - app.setOrganizationName("audio-visualizer") + # app.setOrganizationName("audio-visualizer") if mode == 'cmd': from command import * @@ -76,7 +75,8 @@ if __name__ == "__main__": dpi = desc.physicalDpiX() topMargin = 0 if (dpi == 96) else int(10 * (dpi / 96)) - window.resize(window.width() * (dpi / 96), window.height() * (dpi / 96)) + window.resize( + window.width() * (dpi / 96), window.height() * (dpi / 96)) # window.verticalLayout_2.setContentsMargins(0, topMargin, 0, 0) main = MainWindow(window, proj) diff --git a/src/mainwindow.py b/src/mainwindow.py index a52a0f4..7a9e397 100644 --- a/src/mainwindow.py +++ b/src/mainwindow.py @@ -116,7 +116,6 @@ class MainWindow(QtWidgets.QMainWindow): codec = window.comboBox_videoCodec.itemText(i) if codec == self.settings.value('outputVideoCodec'): window.comboBox_videoCodec.setCurrentIndex(i) - #print(codec) for i in range(window.comboBox_audioCodec.count()): codec = window.comboBox_audioCodec.itemText(i) @@ -146,10 +145,11 @@ class MainWindow(QtWidgets.QMainWindow): # Make component buttons self.compMenu = QMenu() + self.compActions = [] for i, comp in enumerate(self.core.modules): action = self.compMenu.addAction(comp.Component.__doc__) action.triggered.connect( - lambda item=i: self.core.insertComponent(0, item, self)) + lambda _, item=i: self.core.insertComponent(0, item, self)) self.window.pushButton_addComponent.setMenu(self.compMenu) @@ -160,9 +160,10 @@ class MainWindow(QtWidgets.QMainWindow): self.window.pushButton_removeComponent.clicked.connect( lambda _: self.removeComponent()) - componentList.setContextMenuPolicy( - QtCore.Qt.CustomContextMenu) - componentList.customContextMenuRequested.connect(self.componentContextMenu) + componentList.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) + componentList.customContextMenuRequested.connect( + self.componentContextMenu + ) currentRes = str(self.settings.value('outputWidth'))+'x' + \ str(self.settings.value('outputHeight')) @@ -245,19 +246,30 @@ class MainWindow(QtWidgets.QMainWindow): QtWidgets.QShortcut("Ctrl+O", self.window, self.openOpenProjectDialog) QtWidgets.QShortcut("Ctrl+N", self.window, self.createNewProject) - QtWidgets.QShortcut("Ctrl+T", self.window, activated=lambda: - self.window.pushButton_addComponent.click()) - QtWidgets.QShortcut("Ctrl+Space", self.window, activated=lambda: - self.window.listWidget_componentList.setFocus()) - QtWidgets.QShortcut("Ctrl+Shift+S", self.window, - self.presetManager.openSavePresetDialog) - QtWidgets.QShortcut("Ctrl+Shift+C", self.window, - self.presetManager.clearPreset) - - QtWidgets.QShortcut("Ctrl+Up", self.window, - activated=lambda: self.moveComponent(-1)) - QtWidgets.QShortcut("Ctrl+Down", self.window, - activated=lambda: self.moveComponent(1)) + QtWidgets.QShortcut( + "Ctrl+T", self.window, + activated=lambda: self.window.pushButton_addComponent.click() + ) + QtWidgets.QShortcut( + "Ctrl+Space", self.window, + activated=lambda: self.window.listWidget_componentList.setFocus() + ) + QtWidgets.QShortcut( + "Ctrl+Shift+S", self.window, + self.presetManager.openSavePresetDialog + ) + QtWidgets.QShortcut( + "Ctrl+Shift+C", self.window, self.presetManager.clearPreset + ) + + QtWidgets.QShortcut( + "Ctrl+Up", self.window, + activated=lambda: self.moveComponent(-1) + ) + QtWidgets.QShortcut( + "Ctrl+Down", self.window, + activated=lambda: self.moveComponent(1) + ) QtWidgets.QShortcut("Ctrl+Home", self.window, self.moveComponentTop) QtWidgets.QShortcut("Ctrl+End", self.window, self.moveComponentBottom) QtWidgets.QShortcut("Ctrl+r", self.window, self.removeComponent) @@ -280,7 +292,7 @@ class MainWindow(QtWidgets.QMainWindow): def updateComponentTitle(self, pos, presetStore=False): if type(presetStore) == dict: name = presetStore['preset'] - if name == None or name not in self.core.savedPresets: + if name is None or name not in self.core.savedPresets: modified = False else: modified = (presetStore != self.core.savedPresets[name]) @@ -362,21 +374,22 @@ class MainWindow(QtWidgets.QMainWindow): def openInputFileDialog(self): inputDir = self.settings.value("inputDir", os.path.expanduser("~")) - fileName = QtGui.QFileDialog.getOpenFileName( + fileName, _ = QtWidgets.QFileDialog.getOpenFileName( self.window, "Open Audio File", inputDir, "Audio Files (%s)" % " ".join(self.core.audioFormats)) - if not fileName == "": + if fileName: self.settings.setValue("inputDir", os.path.dirname(fileName)) self.window.lineEdit_audioFile.setText(fileName) def openOutputFileDialog(self): outputDir = self.settings.value("outputDir", os.path.expanduser("~")) - fileName = QtGui.QFileDialog.getSaveFileName( + fileName, _ = QtWidgets.QFileDialog.getSaveFileName( self.window, "Set Output Video File", outputDir, - "Video Files (%s);; All Files (*)" % " ".join(self.core.videoFormats)) + "Video Files (%s);; All Files (*)" % " ".join( + self.core.videoFormats)) if not fileName == "": self.settings.setValue("outputDir", os.path.dirname(fileName)) @@ -547,13 +560,13 @@ class MainWindow(QtWidgets.QMainWindow): '''Drop event for the component listwidget''' componentList = self.window.listWidget_componentList - modelIndexes = [ \ - componentList.model().index(i) \ - for i in range(componentList.count()) \ + modelIndexes = [ + componentList.model().index(i) + for i in range(componentList.count()) ] - rects = [ \ - componentList.visualRect(modelIndex) \ - for modelIndex in modelIndexes \ + rects = [ + componentList.visualRect(modelIndex) + for modelIndex in modelIndexes ] rowPos = [rect.contains(event.pos()) for rect in rects] @@ -602,9 +615,10 @@ class MainWindow(QtWidgets.QMainWindow): if self.autosaveExists(identical=False): ch = self.showMessage( msg="You have unsaved changes in project '%s'. " - "Save before %s?" % \ - (os.path.basename(self.currentProject)[:-4], - phrase), + "Save before %s?" % ( + os.path.basename(self.currentProject)[:-4], + phrase + ), showCancel=True) if ch: success = self.saveProjectChanges() @@ -613,7 +627,7 @@ class MainWindow(QtWidgets.QMainWindow): os.remove(self.autosavePath) def openSaveProjectDialog(self): - filename = QtGui.QFileDialog.getSaveFileName( + filename, _ = QtWidgets.QFileDialog.getSaveFileName( self.window, "Create Project File", self.settings.value("projectDir"), "Project Files (*.avp)") @@ -628,7 +642,7 @@ class MainWindow(QtWidgets.QMainWindow): self.core.createProjectFile(filename) def openOpenProjectDialog(self): - filename = QtGui.QFileDialog.getOpenFileName( + filename, _ = QtWidgets.QFileDialog.getOpenFileName( self.window, "Open Project File", self.settings.value("projectDir"), "Project Files (*.avp)") @@ -657,17 +671,19 @@ class MainWindow(QtWidgets.QMainWindow): def showMessage(self, **kwargs): parent = kwargs['parent'] if 'parent' in kwargs else self.window - msg = QtGui.QMessageBox(parent) + msg = QtWidgets.QMessageBox(parent) msg.setModal(True) msg.setText(kwargs['msg']) msg.setIcon( - kwargs['icon'] if 'icon' in kwargs else QtGui.QMessageBox.Information) + kwargs['icon'] + if 'icon' in kwargs else QtWidgets.QMessageBox.Information + ) msg.setDetailedText(kwargs['detail'] if 'detail' in kwargs else None) if 'showCancel'in kwargs and kwargs['showCancel']: msg.setStandardButtons( - QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel) + QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel) else: - msg.setStandardButtons(QtGui.QMessageBox.Ok) + msg.setStandardButtons(QtWidgets.QMessageBox.Ok) ch = msg.exec_() if ch == 1024: return True @@ -687,7 +703,7 @@ class MainWindow(QtWidgets.QMainWindow): return self.presetManager.findPresets() - self.menu = QtGui.QMenu() + self.menu = QMenu() menuItem = self.menu.addAction("Save Preset") menuItem.triggered.connect( self.presetManager.openSavePresetDialog @@ -695,8 +711,10 @@ class MainWindow(QtWidgets.QMainWindow): # submenu for opening presets try: - presets = self.presetManager.presets[str(self.core.selectedComponents[index])] - self.submenu = QtGui.QMenu("Open Preset") + presets = self.presetManager.presets[ + str(self.core.selectedComponents[index]) + ] + self.submenu = QMenu("Open Preset") self.menu.addMenu(self.submenu) for version, presetName in presets: diff --git a/src/presetmanager.py b/src/presetmanager.py index ec3f5cd..97f6e0e 100644 --- a/src/presetmanager.py +++ b/src/presetmanager.py @@ -1,4 +1,4 @@ -from PyQt5 import QtGui, QtCore, QtWidgets +from PyQt5 import QtCore, QtWidgets import string import os @@ -21,13 +21,15 @@ class PresetManager(QtWidgets.QDialog): # window self.lastFilter = '*' - self.presetRows = [] # list of (comp, vers, name) tuples + self.presetRows = [] # list of (comp, vers, name) tuples self.window = window self.window.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) # connect button signals - self.window.pushButton_delete.clicked.connect(self.openDeletePresetDialog) - self.window.pushButton_rename.clicked.connect(self.openRenamePresetDialog) + self.window.pushButton_delete.clicked.connect( + self.openDeletePresetDialog) + self.window.pushButton_rename.clicked.connect( + self.openRenamePresetDialog) self.window.pushButton_import.clicked.connect(self.openImportDialog) self.window.pushButton_export.clicked.connect(self.openExportDialog) self.window.pushButton_close.clicked.connect(self.window.close) @@ -36,7 +38,8 @@ class PresetManager(QtWidgets.QDialog): self.drawFilterList() self.window.comboBox_filter.currentIndexChanged.connect( lambda: self.drawPresetList( - self.window.comboBox_filter.currentText(), self.window.lineEdit_search.text() + self.window.comboBox_filter.currentText(), + self.window.lineEdit_search.text() ) ) @@ -47,7 +50,8 @@ class PresetManager(QtWidgets.QDialog): self.window.lineEdit_search.setCompleter(completer) self.window.lineEdit_search.textChanged.connect( lambda: self.drawPresetList( - self.window.comboBox_filter.currentText(), self.window.lineEdit_search.text() + self.window.comboBox_filter.currentText(), + self.window.lineEdit_search.text() ) ) self.drawPresetList('*') @@ -72,16 +76,14 @@ class PresetManager(QtWidgets.QDialog): parseList.append((compName, int(compVers), preset)) except ValueError: continue - self.presets =\ - { - compName : \ - [ - (vers, preset) \ - for name, vers, preset in parseList \ - if name == compName \ - ] \ - for compName, _, __ in parseList \ - } + self.presets = { + compName: [ + (vers, preset) + for name, vers, preset in parseList + if name == compName + ] + for compName, _, __ in parseList + } def drawPresetList(self, compFilter=None, presetFilter=''): self.window.listWidget_presets.clear() @@ -96,7 +98,8 @@ class PresetManager(QtWidgets.QDialog): continue for vers, preset in presets: if not presetFilter or presetFilter in preset: - self.window.listWidget_presets.addItem('%s: %s' % (component, preset)) + self.window.listWidget_presets.addItem( + '%s: %s' % (component, preset)) self.presetRows.append((component, vers, preset)) if preset not in presetNames: presetNames.append(preset) @@ -124,11 +127,11 @@ class PresetManager(QtWidgets.QDialog): while True: index = componentList.currentRow() currentPreset = selectedComponents[index].currentPreset - newName, OK = QtGui.QInputDialog.getText( + newName, OK = QtWidgets.QInputDialog.getText( self.parent.window, 'Audio Visualizer', 'New Preset Name:', - QtGui.QLineEdit.Normal, + QtWidgets.QLineEdit.Normal, currentPreset ) if OK: @@ -149,7 +152,7 @@ class PresetManager(QtWidgets.QDialog): break def createNewPreset( - self, compName, vers, filename, saveValueStore, **kwargs): + self, compName, vers, filename, saveValueStore, **kwargs): path = os.path.join(self.presetDir, compName, str(vers), filename) if self.presetExists(path, **kwargs): return @@ -163,7 +166,7 @@ class PresetManager(QtWidgets.QDialog): msg="%s already exists! Overwrite it?" % os.path.basename(path), showCancel=True, - icon=QtGui.QMessageBox.Warning, + icon=QtWidgets.QMessageBox.Warning, parent=window) if not ch: # user clicked cancel @@ -196,7 +199,7 @@ class PresetManager(QtWidgets.QDialog): ch = self.parent.showMessage( msg='Really delete %s?' % name, showCancel=True, - icon=QtGui.QMessageBox.Warning, + icon=QtWidgets.QMessageBox.Warning, parent=self.window ) if not ch: @@ -223,11 +226,11 @@ class PresetManager(QtWidgets.QDialog): while True: index = presetList.currentRow() - newName, OK = QtGui.QInputDialog.getText( + newName, OK = QtWidgets.QInputDialog.getText( self.window, 'Preset Manager', 'Rename Preset:', - QtGui.QLineEdit.Normal, + QtWidgets.QLineEdit.Normal, self.presetRows[index][2] ) if OK: @@ -250,7 +253,7 @@ class PresetManager(QtWidgets.QDialog): break def openImportDialog(self): - filename = QtGui.QFileDialog.getOpenFileName( + filename, _ = QtWidgets.QFileDialog.getOpenFileName( self.window, "Import Preset File", self.settings.value("presetDir"), "Preset Files (*.avl)") @@ -275,7 +278,7 @@ class PresetManager(QtWidgets.QDialog): def openExportDialog(self): if not self.window.listWidget_presets.selectedItems(): return - filename = QtGui.QFileDialog.getSaveFileName( + filename, _ = QtWidgets.QFileDialog.getSaveFileName( self.window, "Export Preset", self.settings.value("presetDir"), "Preset Files (*.avl)") diff --git a/src/video_thread.py b/src/video_thread.py index 5ea6d21..b45381c 100644 --- a/src/video_thread.py +++ b/src/video_thread.py @@ -121,15 +121,12 @@ class Worker(QtCore.QObject): vencoders = options['video-codecs'][vcodec] aencoders = options['audio-codecs'][acodec] - #print(encoders) for encoder in vencoders: - #print(encoder) if encoder in encoders: vencoder = encoder break for encoder in aencoders: - #print(encoder) if encoder in encoders: aencoder = encoder break @@ -167,10 +164,10 @@ class Worker(QtCore.QObject): numpy.seterr(divide='ignore') # Call preFrameRender on all components - print('Loaded Components:', ", ".join( - ["%s) %s" % (num, str(component)) \ - for num, component in enumerate(reversed(self.components)) - ])) + print('Loaded Components:', ", ".join([ + "%s) %s" % (num, str(component)) + for num, component in enumerate(reversed(self.components)) + ])) self.staticComponents = {} numComps = len(self.components) for compNo, comp in enumerate(self.components): -- cgit v1.2.3 From 83d55593d005cd540b042b27e6141a3d506d4215 Mon Sep 17 00:00:00 2001 From: DH4 Date: Fri, 23 Jun 2017 23:39:22 -0500 Subject: Fixed QtWidgets not imported on some components. --- src/components/color.py | 2 +- src/components/original.py | 2 +- src/components/text.py | 4 ++-- src/components/video.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/components') diff --git a/src/components/color.py b/src/components/color.py index 2e3902a..44ed82e 100644 --- a/src/components/color.py +++ b/src/components/color.py @@ -1,5 +1,5 @@ from PIL import Image, ImageDraw -from PyQt5 import uic, QtGui, QtCore +from PyQt5 import uic, QtGui, QtCore, QtWidgets from PyQt5.QtGui import QColor from PIL.ImageQt import ImageQt import os diff --git a/src/components/original.py b/src/components/original.py index 61f463d..0d5001c 100644 --- a/src/components/original.py +++ b/src/components/original.py @@ -1,6 +1,6 @@ import numpy from PIL import Image, ImageDraw -from PyQt5 import uic, QtGui, QtCore +from PyQt5 import uic, QtGui, QtCore, QtWidgets from PyQt5.QtGui import QColor import os from . import __base__ diff --git a/src/components/text.py b/src/components/text.py index 0f599ed..76961c9 100644 --- a/src/components/text.py +++ b/src/components/text.py @@ -1,6 +1,6 @@ from PIL import Image, ImageDraw from PyQt5.QtGui import QPainter, QColor, QFont -from PyQt5 import uic, QtGui, QtCore +from PyQt5 import uic, QtGui, QtCore, QtWidgets from PIL.ImageQt import ImageQt import os import io @@ -138,7 +138,7 @@ class Component(__base__.Component): painter.drawText(x, y, self.title) painter.end() - imBytes = image.bits().asstring(image.numBytes()) + imBytes = image.bits().asstring(image.byteCount()) return Image.frombytes('RGBA', (width, height), imBytes) diff --git a/src/components/video.py b/src/components/video.py index 0090426..70247e1 100644 --- a/src/components/video.py +++ b/src/components/video.py @@ -1,5 +1,5 @@ from PIL import Image, ImageDraw -from PyQt5 import uic, QtGui, QtCore +from PyQt5 import uic, QtGui, QtCore, QtWidgets import os import subprocess import threading -- cgit v1.2.3