diff options
| author | Martin Kaistra | 2017-04-22 10:42:31 +0200 |
|---|---|---|
| committer | Martin Kaistra | 2017-04-22 10:42:31 +0200 |
| commit | 6eb601ca9ab2d9efbe591e5f6ae0f19e732260a6 (patch) | |
| tree | 9677c2cf51695134e6ffbfc288e33fb74a7ba667 | |
| parent | 19cf45785461ffd44c8bdec7ae4634bf828e75ed (diff) | |
| parent | 4aef5bfdb7f04dde13b1c6a94172824ce143be6e (diff) | |
Merge branch 'font-settings#8' of https://github.com/HunterwolfAT/audio-visualizer-python into HunterwolfAT-font-settings#8
| -rw-r--r-- | core.py | 15 | ||||
| -rw-r--r-- | main.py | 44 | ||||
| -rw-r--r-- | main.ui | 104 | ||||
| -rw-r--r-- | preview_thread.py | 16 | ||||
| -rw-r--r-- | video_thread.py | 10 |
5 files changed, 174 insertions, 15 deletions
@@ -26,7 +26,7 @@ class Core(): except: return "avconv" - def drawBaseImage(self, backgroundImage, titleText, titleFont): + def drawBaseImage(self, backgroundImage, titleText, titleFont, fontSize, alignment, xOffset, yOffset): if self._image == None or not self.lastBackgroundImage == backgroundImage: self.lastBackgroundImage = backgroundImage @@ -45,11 +45,20 @@ 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)) - painter.drawText(70, 375, titleText) + 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() @@ -14,9 +14,9 @@ import preview_thread, core, video_thread class Main(QtCore.QObject): - newTask = QtCore.pyqtSignal(str, str, QFont) + newTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int) processTask = QtCore.pyqtSignal() - videoTask = QtCore.pyqtSignal(str, str, QFont, str, str) + videoTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, str, str) def __init__(self, window): @@ -49,6 +49,10 @@ 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.fontsizeSpinBox.valueChanged.connect(self.drawPreview) window.progressBar_create.setValue(0) window.setWindowTitle("Audio Visualizer") @@ -56,16 +60,38 @@ class Main(QtCore.QObject): window.pushButton_selectOutput.setText("Select Output Video File") window.pushButton_selectBackground.setText("Select Background Image") window.label_font.setText("Title Font") + window.label_alignment.setText("Title Options") + window.label_fontsize.setText("Fontsize") window.label_title.setText("Title Text") window.pushButton_createVideo.setText("Create Video") window.groupBox_create.setTitle("Create") window.groupBox_settings.setTitle("Settings") window.groupBox_preview.setTitle("Preview") + window.alignmentComboBox.addItem("Left") + window.alignmentComboBox.addItem("Middle") + window.alignmentComboBox.addItem("Right") + window.fontsizeSpinBox.setValue(35) + window.textXSpinBox.setValue(70) + window.textYSpinBox.setValue(375) + titleFont = self.settings.value("titleFont") if not titleFont == None: window.fontComboBox.setCurrentFont(QFont(titleFont)) + alignment = self.settings.value("alignment") + if not alignment == None: + window.alignmentComboBox.setCurrentIndex(int(alignment)) + fontSize = self.settings.value("fontSize") + if not fontSize == None: + window.fontsizeSpinBox.setValue(int(fontSize)) + xPosition = self.settings.value("xPosition") + if not xPosition == None: + window.textXSpinBox.setValue(int(xPosition)) + yPosition = self.settings.value("yPosition") + if not yPosition == None: + window.textYSpinBox.setValue(int(yPosition)) + self.drawPreview() window.show() @@ -76,6 +102,10 @@ class Main(QtCore.QObject): self.previewThread.wait() self.settings.setValue("titleFont", self.window.fontComboBox.currentFont().toString()) + self.settings.setValue("alignment", str(self.window.alignmentComboBox.currentIndex())) + self.settings.setValue("fontSize", str(self.window.fontsizeSpinBox.value())) + self.settings.setValue("xPosition", str(self.window.textXSpinBox.value())) + self.settings.setValue("yPosition", str(self.window.textYSpinBox.value())) def openInputFileDialog(self): inputDir = self.settings.value("inputDir", expanduser("~")) @@ -122,6 +152,10 @@ class Main(QtCore.QObject): self.videoTask.emit(self.window.label_background.text(), self.window.lineEdit_title.text(), self.window.fontComboBox.currentFont(), + self.window.fontsizeSpinBox.value(), + self.window.alignmentComboBox.currentIndex(), + self.window.textXSpinBox.value(), + self.window.textYSpinBox.value(), self.window.label_input.text(), self.window.label_output.text()) @@ -136,7 +170,11 @@ class Main(QtCore.QObject): def drawPreview(self): self.newTask.emit(self.window.label_background.text(), self.window.lineEdit_title.text(), - self.window.fontComboBox.currentFont()) + self.window.fontComboBox.currentFont(), + self.window.fontsizeSpinBox.value(), + self.window.alignmentComboBox.currentIndex(), + self.window.textXSpinBox.value(), + self.window.textYSpinBox.value()) # self.processTask.emit() def showPreviewImage(self, image): @@ -172,6 +172,108 @@ </layout> </item> <item> + <layout class="QHBoxLayout" name="horizontalLayout_5"> + <item> + <widget class="QLabel" name="label_alignment"> + <property name="minimumSize"> + <size> + <width>200</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>200</width> + <height>16777215</height> + </size> + </property> + <property name="baseSize"> + <size> + <width>200</width> + <height>0</height> + </size> + </property> + <property name="frameShape"> + <enum>QFrame::NoFrame</enum> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QComboBox" name="alignmentComboBox"/> + </item> + <item> + <widget class="QLabel" name="label_fontsize"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="fontsizeSpinBox"> + <property name="maximum"> + <number>999</number> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_textX"> + <property name="layoutDirection"> + <enum>Qt::LeftToRight</enum> + </property> + <property name="text"> + <string>X</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="textXSpinBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimum"> + <number>-99999</number> + </property> + <property name="maximum"> + <number>99999</number> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_textY"> + <property name="text"> + <string>Y</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="textYSpinBox"> + <property name="minimum"> + <number>-99999</number> + </property> + <property name="maximum"> + <number>99999</number> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + <item> <layout class="QHBoxLayout" name="horizontalLayout_6"> <item> <widget class="QLabel" name="label_title"> @@ -209,8 +311,6 @@ </layout> </item> </layout> - <zorder>verticalLayoutWidget_2</zorder> - <zorder>layoutWidget_2</zorder> </widget> </item> <item> diff --git a/preview_thread.py b/preview_thread.py index 740f6c6..9dc7e4c 100644 --- a/preview_thread.py +++ b/preview_thread.py @@ -19,13 +19,17 @@ class Worker(QtCore.QObject): self.queue = queue - @pyqtSlot(str, str, QtGui.QFont) - def createPreviewImage(self, backgroundImage, titleText, titleFont): + @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 = { "backgroundImage": backgroundImage, "titleText": titleText, - "titleFont": titleFont + "titleFont": titleFont, + "fontSize": fontSize, + "alignment": alignment, + "xoffset": xOffset, + "yoffset": yOffset } self.queue.put(dic) @@ -42,7 +46,11 @@ class Worker(QtCore.QObject): im = self.core.drawBaseImage( nextPreviewInformation["backgroundImage"], nextPreviewInformation["titleText"], - nextPreviewInformation["titleFont"]) + nextPreviewInformation["titleFont"], + nextPreviewInformation["fontSize"], + nextPreviewInformation["alignment"], + nextPreviewInformation["xoffset"], + nextPreviewInformation["yoffset"]) spectrum = numpy.fromfunction(lambda x: 0.008*(x-128)**2, (255,), dtype="int16") diff --git a/video_thread.py b/video_thread.py index 9f4ce7b..1d1d44b 100644 --- a/video_thread.py +++ b/video_thread.py @@ -18,14 +18,18 @@ class Worker(QtCore.QObject): self.core = core.Core() - @pyqtSlot(str, str, QtGui.QFont, str, str) - def createVideo(self, backgroundImage, titleText, titleFont, inputFile, outputFile): + @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())) imBackground = self.core.drawBaseImage( backgroundImage, titleText, - titleFont) + titleFont, + fontSize, + alignment, + xOffset, + yOffset) self.progressBarUpdate.emit(0) |
