From c772bf5583dec23513371392ca6d2018518483cb Mon Sep 17 00:00:00 2001 From: Maximilian Siess Date: Tue, 18 Apr 2017 13:35:29 +0200 Subject: Added text alignment option --- preview_thread.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'preview_thread.py') diff --git a/preview_thread.py b/preview_thread.py index 740f6c6..53bb608 100644 --- a/preview_thread.py +++ b/preview_thread.py @@ -19,13 +19,14 @@ class Worker(QtCore.QObject): self.queue = queue - @pyqtSlot(str, str, QtGui.QFont) - def createPreviewImage(self, backgroundImage, titleText, titleFont): + @pyqtSlot(str, str, QtGui.QFont, str) + def createPreviewImage(self, backgroundImage, titleText, titleFont, alignment): # print('worker thread id: {}'.format(QtCore.QThread.currentThreadId())) dic = { "backgroundImage": backgroundImage, "titleText": titleText, - "titleFont": titleFont + "titleFont": titleFont, + "alignment": alignment } self.queue.put(dic) @@ -42,7 +43,8 @@ class Worker(QtCore.QObject): im = self.core.drawBaseImage( nextPreviewInformation["backgroundImage"], nextPreviewInformation["titleText"], - nextPreviewInformation["titleFont"]) + nextPreviewInformation["titleFont"], + nextPreviewInformation["alignment"]) spectrum = numpy.fromfunction(lambda x: 0.008*(x-128)**2, (255,), dtype="int16") -- cgit v1.2.3 From f639760ffc8f3152b46c32a881303a7522b8daca Mon Sep 17 00:00:00 2001 From: Maximilian Siess Date: Thu, 20 Apr 2017 18:47:14 +0200 Subject: added x/y offset of text in preview --- core.py | 11 +++++++---- main.py | 8 ++++++-- preview_thread.py | 12 ++++++++---- 3 files changed, 21 insertions(+), 10 deletions(-) (limited to 'preview_thread.py') diff --git a/core.py b/core.py index 6bd533d..9ee4b71 100644 --- a/core.py +++ b/core.py @@ -26,7 +26,7 @@ class Core(): except: return "avconv" - def drawBaseImage(self, backgroundImage, titleText, titleFont, alignment): + def drawBaseImage(self, backgroundImage, titleText, titleFont, alignment, xOffset, yOffset): if self._image == None or not self.lastBackgroundImage == backgroundImage: self.lastBackgroundImage = backgroundImage @@ -49,13 +49,16 @@ class Core(): painter.setFont(font) painter.setPen(QColor(255, 255, 255)) + yPosition = 375 + yOffset + fm = QtGui.QFontMetrics(font) if alignment == "Left": - painter.drawText(70, 375, titleText) + xPosition = 70 + xOffset if alignment == "Middle": - painter.drawText(1280/2 - fm.width(titleText)/2, 375, titleText) + xPosition = xOffset + (1280/2 - fm.width(titleText)/2) if alignment == "Right": - painter.drawText(1210 - fm.width(titleText), 375, titleText) + xPosition = xOffset + (1210 - fm.width(titleText)) + painter.drawText(xPosition, yPosition, titleText) painter.end() buffer = QtCore.QBuffer() diff --git a/main.py b/main.py index 6e9358b..64c17e2 100644 --- a/main.py +++ b/main.py @@ -14,7 +14,7 @@ import preview_thread, core, video_thread class Main(QtCore.QObject): - newTask = QtCore.pyqtSignal(str, str, QFont, str) + newTask = QtCore.pyqtSignal(str, str, QFont, str, int, int) processTask = QtCore.pyqtSignal() videoTask = QtCore.pyqtSignal(str, str, QFont, str, str, str) @@ -50,6 +50,8 @@ class Main(QtCore.QObject): window.fontComboBox.currentFontChanged.connect(self.drawPreview) window.lineEdit_title.textChanged.connect(self.drawPreview) window.alignmentComboBox.currentIndexChanged.connect(self.drawPreview) + window.textXSpinBox.valueChanged.connect(self.drawPreview) + window.textYSpinBox.valueChanged.connect(self.drawPreview) window.progressBar_create.setValue(0) window.setWindowTitle("Audio Visualizer") @@ -145,7 +147,9 @@ class Main(QtCore.QObject): self.newTask.emit(self.window.label_background.text(), self.window.lineEdit_title.text(), self.window.fontComboBox.currentFont(), - self.window.alignmentComboBox.currentText()) + self.window.alignmentComboBox.currentText(), + self.window.textXSpinBox.value(), + self.window.textYSpinBox.value()) # self.processTask.emit() def showPreviewImage(self, image): diff --git a/preview_thread.py b/preview_thread.py index 53bb608..ddb5407 100644 --- a/preview_thread.py +++ b/preview_thread.py @@ -19,14 +19,16 @@ class Worker(QtCore.QObject): self.queue = queue - @pyqtSlot(str, str, QtGui.QFont, str) - def createPreviewImage(self, backgroundImage, titleText, titleFont, alignment): + @pyqtSlot(str, str, QtGui.QFont, str, int, int) + def createPreviewImage(self, backgroundImage, titleText, titleFont, alignment, xOffset, yOffset): # print('worker thread id: {}'.format(QtCore.QThread.currentThreadId())) dic = { "backgroundImage": backgroundImage, "titleText": titleText, "titleFont": titleFont, - "alignment": alignment + "alignment": alignment, + "xoffset": xOffset, + "yoffset": yOffset } self.queue.put(dic) @@ -44,7 +46,9 @@ class Worker(QtCore.QObject): nextPreviewInformation["backgroundImage"], nextPreviewInformation["titleText"], nextPreviewInformation["titleFont"], - nextPreviewInformation["alignment"]) + nextPreviewInformation["alignment"], + nextPreviewInformation["xoffset"], + nextPreviewInformation["yoffset"]) spectrum = numpy.fromfunction(lambda x: 0.008*(x-128)**2, (255,), dtype="int16") -- cgit v1.2.3 From 8423d958201f0230f4c4887a4b75f14f54a2161a Mon Sep 17 00:00:00 2001 From: Maximilian Siess Date: Thu, 20 Apr 2017 19:01:19 +0200 Subject: added font size of text in preview --- core.py | 12 ++++++------ main.py | 6 +++++- preview_thread.py | 6 ++++-- 3 files changed, 15 insertions(+), 9 deletions(-) (limited to 'preview_thread.py') diff --git a/core.py b/core.py index 9ee4b71..1dd6438 100644 --- a/core.py +++ b/core.py @@ -26,7 +26,7 @@ class Core(): except: return "avconv" - def drawBaseImage(self, backgroundImage, titleText, titleFont, alignment, xOffset, yOffset): + def drawBaseImage(self, backgroundImage, titleText, titleFont, fontSize, alignment, xOffset, yOffset): if self._image == None or not self.lastBackgroundImage == backgroundImage: self.lastBackgroundImage = backgroundImage @@ -45,19 +45,19 @@ class Core(): self._image1 = QtGui.QImage(self._image) painter = QPainter(self._image1) font = titleFont - font.setPointSizeF(35) + font.setPointSizeF(fontSize) painter.setFont(font) painter.setPen(QColor(255, 255, 255)) - yPosition = 375 + yOffset + yPosition = yOffset fm = QtGui.QFontMetrics(font) if alignment == "Left": - xPosition = 70 + xOffset + xPosition = xOffset if alignment == "Middle": - xPosition = xOffset + (1280/2 - fm.width(titleText)/2) + xPosition = xOffset - fm.width(titleText)/2 if alignment == "Right": - xPosition = xOffset + (1210 - fm.width(titleText)) + xPosition = xOffset - fm.width(titleText) painter.drawText(xPosition, yPosition, titleText) painter.end() diff --git a/main.py b/main.py index 64c17e2..bc0a015 100644 --- a/main.py +++ b/main.py @@ -14,7 +14,7 @@ import preview_thread, core, video_thread class Main(QtCore.QObject): - newTask = QtCore.pyqtSignal(str, str, QFont, str, int, int) + newTask = QtCore.pyqtSignal(str, str, QFont, int, str, int, int) processTask = QtCore.pyqtSignal() videoTask = QtCore.pyqtSignal(str, str, QFont, str, str, str) @@ -52,6 +52,7 @@ class Main(QtCore.QObject): window.alignmentComboBox.currentIndexChanged.connect(self.drawPreview) window.textXSpinBox.valueChanged.connect(self.drawPreview) window.textYSpinBox.valueChanged.connect(self.drawPreview) + window.fontsizeSpinBox.valueChanged.connect(self.drawPreview) window.progressBar_create.setValue(0) window.setWindowTitle("Audio Visualizer") @@ -70,6 +71,8 @@ class Main(QtCore.QObject): window.alignmentComboBox.addItem("Left"); window.alignmentComboBox.addItem("Middle"); window.alignmentComboBox.addItem("Right"); + window.textXSpinBox.setValue(70); + window.textYSpinBox.setValue(375); titleFont = self.settings.value("titleFont") if not titleFont == None: @@ -147,6 +150,7 @@ class Main(QtCore.QObject): self.newTask.emit(self.window.label_background.text(), self.window.lineEdit_title.text(), self.window.fontComboBox.currentFont(), + self.window.fontsizeSpinBox.value(), self.window.alignmentComboBox.currentText(), self.window.textXSpinBox.value(), self.window.textYSpinBox.value()) diff --git a/preview_thread.py b/preview_thread.py index ddb5407..8f759be 100644 --- a/preview_thread.py +++ b/preview_thread.py @@ -19,13 +19,14 @@ class Worker(QtCore.QObject): self.queue = queue - @pyqtSlot(str, str, QtGui.QFont, str, int, int) - def createPreviewImage(self, backgroundImage, titleText, titleFont, alignment, xOffset, yOffset): + @pyqtSlot(str, str, QtGui.QFont, int, str, int, int) + def createPreviewImage(self, backgroundImage, titleText, titleFont, fontSize, alignment, xOffset, yOffset): # print('worker thread id: {}'.format(QtCore.QThread.currentThreadId())) dic = { "backgroundImage": backgroundImage, "titleText": titleText, "titleFont": titleFont, + "fontSize": fontSize, "alignment": alignment, "xoffset": xOffset, "yoffset": yOffset @@ -46,6 +47,7 @@ class Worker(QtCore.QObject): nextPreviewInformation["backgroundImage"], nextPreviewInformation["titleText"], nextPreviewInformation["titleFont"], + nextPreviewInformation["fontSize"], nextPreviewInformation["alignment"], nextPreviewInformation["xoffset"], nextPreviewInformation["yoffset"]) -- cgit v1.2.3 From 4aef5bfdb7f04dde13b1c6a94172824ce143be6e Mon Sep 17 00:00:00 2001 From: Maximilian Siess Date: Fri, 21 Apr 2017 01:00:17 +0200 Subject: changed differentiater of text alignment from string to int --- core.py | 6 +++--- main.py | 8 ++++---- preview_thread.py | 2 +- video_thread.py | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'preview_thread.py') diff --git a/core.py b/core.py index 1dd6438..b362087 100644 --- a/core.py +++ b/core.py @@ -52,11 +52,11 @@ class Core(): yPosition = yOffset fm = QtGui.QFontMetrics(font) - if alignment == "Left": + if alignment == 0: #Left xPosition = xOffset - if alignment == "Middle": + if alignment == 1: #Middle xPosition = xOffset - fm.width(titleText)/2 - if alignment == "Right": + if alignment == 2: #Right xPosition = xOffset - fm.width(titleText) painter.drawText(xPosition, yPosition, titleText) painter.end() diff --git a/main.py b/main.py index ae85f50..8c1d48d 100644 --- a/main.py +++ b/main.py @@ -14,9 +14,9 @@ import preview_thread, core, video_thread class Main(QtCore.QObject): - newTask = QtCore.pyqtSignal(str, str, QFont, int, str, int, int) + newTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int) processTask = QtCore.pyqtSignal() - videoTask = QtCore.pyqtSignal(str, str, QFont, int, str, int, int, str, str) + videoTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, str, str) def __init__(self, window): @@ -153,7 +153,7 @@ class Main(QtCore.QObject): self.window.lineEdit_title.text(), self.window.fontComboBox.currentFont(), self.window.fontsizeSpinBox.value(), - self.window.alignmentComboBox.currentText(), + self.window.alignmentComboBox.currentIndex(), self.window.textXSpinBox.value(), self.window.textYSpinBox.value(), self.window.label_input.text(), @@ -172,7 +172,7 @@ class Main(QtCore.QObject): self.window.lineEdit_title.text(), self.window.fontComboBox.currentFont(), self.window.fontsizeSpinBox.value(), - self.window.alignmentComboBox.currentText(), + self.window.alignmentComboBox.currentIndex(), self.window.textXSpinBox.value(), self.window.textYSpinBox.value()) # self.processTask.emit() diff --git a/preview_thread.py b/preview_thread.py index 8f759be..9dc7e4c 100644 --- a/preview_thread.py +++ b/preview_thread.py @@ -19,7 +19,7 @@ class Worker(QtCore.QObject): self.queue = queue - @pyqtSlot(str, str, QtGui.QFont, int, str, int, int) + @pyqtSlot(str, str, QtGui.QFont, int, int, int, int) def createPreviewImage(self, backgroundImage, titleText, titleFont, fontSize, alignment, xOffset, yOffset): # print('worker thread id: {}'.format(QtCore.QThread.currentThreadId())) dic = { diff --git a/video_thread.py b/video_thread.py index 8f7c8d8..1d1d44b 100644 --- a/video_thread.py +++ b/video_thread.py @@ -18,7 +18,7 @@ class Worker(QtCore.QObject): self.core = core.Core() - @pyqtSlot(str, str, QtGui.QFont, int, str, int, int, str, str) + @pyqtSlot(str, str, QtGui.QFont, int, int, int, int, str, str) def createVideo(self, backgroundImage, titleText, titleFont, fontSize, alignment, xOffset, yOffset, inputFile, outputFile): # print('worker thread id: {}'.format(QtCore.QThread.currentThreadId())) -- cgit v1.2.3