Merge branch 'HunterwolfAT-font-settings#8'
This commit is contained in:
commit
01de150f74
15
core.py
15
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()
|
||||
|
|
50
main.py
50
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):
|
||||
|
|
104
main.ui
104
main.ui
|
@ -171,6 +171,108 @@
|
|||
</item>
|
||||
</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>
|
||||
|
@ -209,8 +311,6 @@
|
|||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>verticalLayoutWidget_2</zorder>
|
||||
<zorder>layoutWidget_2</zorder>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Reference in New Issue