diff --git a/core.py b/core.py
index 895d1a9..b362087 100644
--- a/core.py
+++ b/core.py
@@ -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()
diff --git a/main.py b/main.py
index 03e0f02..121efa0 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)
+ 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):
@@ -47,25 +47,51 @@ class Main(QtCore.QObject):
window.pushButton_createVideo.clicked.connect(self.createAudioVisualisation)
window.pushButton_selectBackground.clicked.connect(self.openBackgroundFileDialog)
- window.fontComboBox.currentFontChanged.connect(self.drawPreview)
- window.lineEdit_title.textChanged.connect(self.drawPreview)
-
window.progressBar_create.setValue(0)
window.setWindowTitle("Audio Visualizer")
window.pushButton_selectInput.setText("Select Input Music File")
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))
+
+ 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)
+
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):
diff --git a/main.ui b/main.ui
index f9e79c3..5b71d1c 100644
--- a/main.ui
+++ b/main.ui
@@ -171,6 +171,108 @@
+ -
+
+
-
+
+
+
+ 200
+ 0
+
+
+
+
+ 200
+ 16777215
+
+
+
+
+ 200
+ 0
+
+
+
+ QFrame::NoFrame
+
+
+
+
+
+
+ -
+
+
-
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+ 999
+
+
+
+ -
+
+
+ Qt::LeftToRight
+
+
+ X
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ -99999
+
+
+ 99999
+
+
+
+ -
+
+
+ Y
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+ -
+
+
+ -99999
+
+
+ 99999
+
+
+
+
+
+
+
-
-
@@ -209,8 +311,6 @@
- verticalLayoutWidget_2
- layoutWidget_2
-
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)