Skip to content

Commit 5487319

Browse files
committed
Merge branch 'tassaron2-master'
2 parents c622f29 + 624ec8d commit 5487319

File tree

5 files changed

+195
-27
lines changed

5 files changed

+195
-27
lines changed

core.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def parseBaseImage(self, backgroundImage, preview=False):
4242
else:
4343
return self.getVideoFrames(backgroundImage, preview)
4444

45-
def drawBaseImage(self, backgroundFile, titleText, titleFont, fontSize, alignment, xOffset, yOffset):
45+
def drawBaseImage(self, backgroundFile, titleText, titleFont, fontSize, alignment,\
46+
xOffset, yOffset, textColor, visColor):
4647
if backgroundFile == '':
4748
im = Image.new("RGB", (1280, 720), "black")
4849
else:
@@ -62,7 +63,7 @@ def drawBaseImage(self, backgroundFile, titleText, titleFont, fontSize, alignmen
6263
font = titleFont
6364
font.setPixelSize(fontSize)
6465
painter.setFont(font)
65-
painter.setPen(QColor(255, 255, 255))
66+
painter.setPen(QColor(*textColor))
6667

6768
yPosition = yOffset
6869

@@ -86,13 +87,15 @@ def drawBaseImage(self, backgroundFile, titleText, titleFont, fontSize, alignmen
8687
strio.seek(0)
8788
return Image.open(strio)
8889

89-
def drawBars(self, spectrum, image):
90+
def drawBars(self, spectrum, image, color):
9091

9192
imTop = Image.new("RGBA", (1280, 360))
9293
draw = ImageDraw.Draw(imTop)
94+
r, g, b = color
95+
color2 = (r, g, b, 50)
9396
for j in range(0, 63):
94-
draw.rectangle((10 + j * 20, 325, 10 + j * 20 + 20, 325 - spectrum[j * 4] * 1 - 10), fill=(255, 255, 255, 50))
95-
draw.rectangle((15 + j * 20, 320, 15 + j * 20 + 10, 320 - spectrum[j * 4] * 1), fill="white")
97+
draw.rectangle((10 + j * 20, 325, 10 + j * 20 + 20, 325 - spectrum[j * 4] * 1 - 10), fill=color2)
98+
draw.rectangle((15 + j * 20, 320, 15 + j * 20 + 10, 320 - spectrum[j * 4] * 1), fill=color)
9699

97100

98101
imBottom = imTop.transpose(Image.FLIP_TOP_BOTTOM)
@@ -191,3 +194,17 @@ def getVideoFrames(self, videoPath, firstOnly=False):
191194
shell=True
192195
)
193196
return sorted([os.path.join(self.tempDir, f) for f in os.listdir(self.tempDir)])
197+
198+
@staticmethod
199+
def RGBFromString(string):
200+
''' turns an RGB string like "255, 255, 255" into a tuple '''
201+
try:
202+
tup = tuple([int(i) for i in string.split(',')])
203+
if len(tup) != 3:
204+
raise ValueError
205+
for i in tup:
206+
if i > 255 or i < 0:
207+
raise ValueError
208+
return tup
209+
except:
210+
return (255, 255, 255)

main.py

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class Command(QtCore.QObject):
1717

18-
videoTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, str, str)
18+
videoTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, tuple, tuple, str, str)
1919

2020
def __init__(self):
2121
QtCore.QObject.__init__(self)
@@ -28,12 +28,24 @@ def __init__(self):
2828
self.parser.add_argument('-t', '--text', dest='text', help='title text', required=True)
2929
self.parser.add_argument('-f', '--font', dest='font', help='title font', required=False)
3030
self.parser.add_argument('-s', '--fontsize', dest='fontsize', help='title font size', required=False)
31+
self.parser.add_argument('-c', '--textcolor', dest='textcolor', help='title text color in r,g,b format', required=False)
32+
self.parser.add_argument('-C', '--viscolor', dest='viscolor', help='visualization color in r,g,b format', required=False)
3133
self.parser.add_argument('-x', '--xposition', dest='xposition', help='x position', required=False)
3234
self.parser.add_argument('-y', '--yposition', dest='yposition', help='y position', required=False)
3335
self.parser.add_argument('-a', '--alignment', dest='alignment', help='title alignment', required=False, type=int, choices=[0, 1, 2])
3436
self.args = self.parser.parse_args()
3537

3638
self.settings = QSettings('settings.ini', QSettings.IniFormat)
39+
40+
# load colours as tuples from comma-separated strings
41+
self.textColor = core.Core.RGBFromString(self.settings.value("textColor", '255, 255, 255'))
42+
self.visColor = core.Core.RGBFromString(self.settings.value("visColor", '255, 255, 255'))
43+
if self.args.textcolor:
44+
self.textColor = core.Core.RGBFromString(self.args.textcolor)
45+
if self.args.viscolor:
46+
self.visColor = core.Core.RGBFromString(self.args.viscolor)
47+
48+
# font settings
3749
if self.args.font:
3850
self.font = QFont(self.args.font)
3951
else:
@@ -43,7 +55,6 @@ def __init__(self):
4355
self.fontsize = int(self.args.fontsize)
4456
else:
4557
self.fontsize = int(self.settings.value("fontSize", 35))
46-
4758
if self.args.alignment:
4859
self.alignment = int(self.args.alignment)
4960
else:
@@ -75,6 +86,8 @@ def __init__(self):
7586
self.alignment,
7687
self.textX,
7788
self.textY,
89+
self.textColor,
90+
self.visColor,
7891
self.args.input,
7992
self.args.output)
8093

@@ -89,23 +102,27 @@ def cleanUp(self):
89102
self.settings.setValue("fontSize", str(self.fontsize))
90103
self.settings.setValue("xPosition", str(self.textX))
91104
self.settings.setValue("yPosition", str(self.textY))
105+
self.settings.setValue("visColor", '%s,%s,%s' % self.visColor)
106+
self.settings.setValue("textColor", '%s,%s,%s' % self.textColor)
92107
sys.exit(0)
93108

94109
class Main(QtCore.QObject):
95110

96-
newTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int)
111+
newTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, tuple, tuple)
97112
processTask = QtCore.pyqtSignal()
98-
videoTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, str, str)
113+
videoTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, tuple, tuple, str, str)
99114

100115
def __init__(self, window):
101-
102116
QtCore.QObject.__init__(self)
103117

104118
# print('main thread id: {}'.format(QtCore.QThread.currentThreadId()))
105119
self.window = window
106120
self.core = core.Core()
107-
108121
self.settings = QSettings('settings.ini', QSettings.IniFormat)
122+
123+
# load colors as tuples from a comma-separated string
124+
self.textColor = core.Core.RGBFromString(self.settings.value("textColor", '255, 255, 255'))
125+
self.visColor = core.Core.RGBFromString(self.settings.value("visColor", '255, 255, 255'))
109126

110127
self.previewQueue = Queue()
111128

@@ -133,8 +150,11 @@ def __init__(self, window):
133150
window.pushButton_selectBackground.setText("Select Background Image")
134151
window.label_font.setText("Title Font")
135152
window.label_alignment.setText("Title Options")
153+
window.label_colorOptions.setText("Colors")
136154
window.label_fontsize.setText("Fontsize")
137155
window.label_title.setText("Title Text")
156+
window.label_textColor.setText("Text:")
157+
window.label_visColor.setText("Visualizer:")
138158
window.pushButton_createVideo.setText("Create Video")
139159
window.groupBox_create.setTitle("Create")
140160
window.groupBox_settings.setTitle("Settings")
@@ -146,6 +166,14 @@ def __init__(self, window):
146166
window.fontsizeSpinBox.setValue(35)
147167
window.textXSpinBox.setValue(70)
148168
window.textYSpinBox.setValue(375)
169+
window.lineEdit_textColor.setText('%s,%s,%s' % self.textColor)
170+
window.lineEdit_visColor.setText('%s,%s,%s' % self.visColor)
171+
window.pushButton_textColor.clicked.connect(lambda: self.pickColor('text'))
172+
window.pushButton_visColor.clicked.connect(lambda: self.pickColor('vis'))
173+
btnStyle = "QPushButton { background-color : %s; outline: none; }" % QColor(*self.textColor).name()
174+
window.pushButton_textColor.setStyleSheet(btnStyle)
175+
btnStyle = "QPushButton { background-color : %s; outline: none; }" % QColor(*self.visColor).name()
176+
window.pushButton_visColor.setStyleSheet(btnStyle)
149177

150178
titleFont = self.settings.value("titleFont")
151179
if not titleFont == None:
@@ -170,6 +198,8 @@ def __init__(self, window):
170198
window.textXSpinBox.valueChanged.connect(self.drawPreview)
171199
window.textYSpinBox.valueChanged.connect(self.drawPreview)
172200
window.fontsizeSpinBox.valueChanged.connect(self.drawPreview)
201+
window.lineEdit_textColor.textChanged.connect(self.drawPreview)
202+
window.lineEdit_visColor.textChanged.connect(self.drawPreview)
173203

174204
self.drawPreview()
175205

@@ -179,13 +209,14 @@ def cleanUp(self):
179209
self.timer.stop()
180210
self.previewThread.quit()
181211
self.previewThread.wait()
182-
212+
183213
self.settings.setValue("titleFont", self.window.fontComboBox.currentFont().toString())
184214
self.settings.setValue("alignment", str(self.window.alignmentComboBox.currentIndex()))
185215
self.settings.setValue("fontSize", str(self.window.fontsizeSpinBox.value()))
186216
self.settings.setValue("xPosition", str(self.window.textXSpinBox.value()))
187217
self.settings.setValue("yPosition", str(self.window.textYSpinBox.value()))
188-
sys.exit(0)
218+
self.settings.setValue("visColor", self.window.lineEdit_visColor.text())
219+
self.settings.setValue("textColor", self.window.lineEdit_textColor.text())
189220

190221
def openInputFileDialog(self):
191222
inputDir = self.settings.value("inputDir", expanduser("~"))
@@ -237,6 +268,8 @@ def createAudioVisualisation(self):
237268
self.window.alignmentComboBox.currentIndex(),
238269
self.window.textXSpinBox.value(),
239270
self.window.textYSpinBox.value(),
271+
core.Core.RGBFromString(self.window.lineEdit_textColor.text()),
272+
core.Core.RGBFromString(self.window.lineEdit_visColor.text()),
240273
self.window.label_input.text(),
241274
self.window.label_output.text())
242275

@@ -258,7 +291,9 @@ def drawPreview(self):
258291
self.window.fontsizeSpinBox.value(),
259292
self.window.alignmentComboBox.currentIndex(),
260293
self.window.textXSpinBox.value(),
261-
self.window.textYSpinBox.value())
294+
self.window.textYSpinBox.value(),
295+
core.Core.RGBFromString(self.window.lineEdit_textColor.text()),
296+
core.Core.RGBFromString(self.window.lineEdit_visColor.text()))
262297
# self.processTask.emit()
263298

264299
def showPreviewImage(self, image):
@@ -267,6 +302,18 @@ def showPreviewImage(self, image):
267302

268303
self.window.label_preview.setPixmap(self._previewPixmap)
269304

305+
def pickColor(self, colorTarget):
306+
color = QtGui.QColorDialog.getColor()
307+
if color.isValid():
308+
RGBstring = '%s,%s,%s' % (str(color.red()), str(color.green()), str(color.blue()))
309+
btnStyle = "QPushButton { background-color : %s; outline: none; }" % color.name()
310+
if colorTarget == 'text':
311+
self.window.lineEdit_textColor.setText(RGBstring)
312+
window.pushButton_textColor.setStyleSheet(btnStyle)
313+
elif colorTarget == 'vis':
314+
self.window.lineEdit_visColor.setText(RGBstring)
315+
window.pushButton_visColor.setStyleSheet(btnStyle)
316+
270317
if len(sys.argv) > 1:
271318
# command line mode
272319
app = QtGui.QApplication(sys.argv, False)

main.ui

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@
336336
<item>
337337
<layout class="QHBoxLayout" name="horizontalLayout_6">
338338
<item>
339-
<widget class="QLabel" name="label_title">
339+
<widget class="QLabel" name="label_colorOptions">
340340
<property name="minimumSize">
341341
<size>
342342
<width>200</width>
@@ -364,12 +364,108 @@
364364
</widget>
365365
</item>
366366
<item>
367-
<widget class="QLineEdit" name="lineEdit_title"/>
367+
<widget class="QLabel" name="label_textColor">
368+
<property name="text">
369+
<string/>
370+
</property>
371+
<property name="alignment">
372+
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
373+
</property>
374+
</widget>
375+
</item>
376+
<item>
377+
<widget class="QPushButton" name="pushButton_textColor">
378+
<property name="maximumSize">
379+
<size>
380+
<width>32</width>
381+
<height>32</height>
382+
</size>
383+
</property>
384+
<property name="text">
385+
<string/>
386+
</property>
387+
<property name="MaximumSize" stdset="0">
388+
<size>
389+
<width>32</width>
390+
<height>32</height>
391+
</size>
392+
</property>
393+
</widget>
394+
</item>
395+
<item>
396+
<widget class="QLineEdit" name="lineEdit_textColor"/>
397+
</item>
398+
<item>
399+
<widget class="QLabel" name="label_visColor">
400+
<property name="text">
401+
<string/>
402+
</property>
403+
<property name="alignment">
404+
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
405+
</property>
406+
</widget>
407+
</item>
408+
<item>
409+
<widget class="QPushButton" name="pushButton_visColor">
410+
<property name="maximumSize">
411+
<size>
412+
<width>32</width>
413+
<height>32</height>
414+
</size>
415+
</property>
416+
<property name="text">
417+
<string/>
418+
</property>
419+
<property name="MaximumSize" stdset="0">
420+
<size>
421+
<width>32</width>
422+
<height>32</height>
423+
</size>
424+
</property>
425+
</widget>
426+
</item>
427+
<item>
428+
<widget class="QLineEdit" name="lineEdit_visColor"/>
368429
</item>
369430
</layout>
370431
</item>
371432
</layout>
372433
</item>
434+
<item>
435+
<layout class="QHBoxLayout" name="horizontalLayout_7">
436+
<item>
437+
<widget class="QLabel" name="label_title">
438+
<property name="minimumSize">
439+
<size>
440+
<width>200</width>
441+
<height>0</height>
442+
</size>
443+
</property>
444+
<property name="maximumSize">
445+
<size>
446+
<width>200</width>
447+
<height>16777215</height>
448+
</size>
449+
</property>
450+
<property name="baseSize">
451+
<size>
452+
<width>200</width>
453+
<height>0</height>
454+
</size>
455+
</property>
456+
<property name="frameShape">
457+
<enum>QFrame::NoFrame</enum>
458+
</property>
459+
<property name="text">
460+
<string/>
461+
</property>
462+
</widget>
463+
</item>
464+
<item>
465+
<widget class="QLineEdit" name="lineEdit_title"/>
466+
</item>
467+
</layout>
468+
</item>
373469
</layout>
374470
</widget>
375471
</item>

preview_thread.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ def __init__(self, parent=None, queue=None):
1919
self.queue = queue
2020

2121

22-
@pyqtSlot(str, str, QtGui.QFont, int, int, int, int)
23-
def createPreviewImage(self, backgroundImage, titleText, titleFont, fontSize, alignment, xOffset, yOffset):
22+
@pyqtSlot(str, str, QtGui.QFont, int, int, int, int, tuple, tuple)
23+
def createPreviewImage(self, backgroundImage, titleText, titleFont, fontSize,\
24+
alignment, xOffset, yOffset, textColor, visColor):
2425
# print('worker thread id: {}'.format(QtCore.QThread.currentThreadId()))
2526
dic = {
2627
"backgroundImage": backgroundImage,
@@ -29,7 +30,9 @@ def createPreviewImage(self, backgroundImage, titleText, titleFont, fontSize, al
2930
"fontSize": fontSize,
3031
"alignment": alignment,
3132
"xoffset": xOffset,
32-
"yoffset": yOffset
33+
"yoffset": yOffset,
34+
"textColor" : textColor,
35+
"visColor" : visColor
3336
}
3437
self.queue.put(dic)
3538

@@ -59,11 +62,12 @@ def process(self):
5962
nextPreviewInformation["fontSize"],
6063
nextPreviewInformation["alignment"],
6164
nextPreviewInformation["xoffset"],
62-
nextPreviewInformation["yoffset"])
63-
65+
nextPreviewInformation["yoffset"],
66+
nextPreviewInformation["textColor"],
67+
nextPreviewInformation["visColor"])
6468
spectrum = numpy.fromfunction(lambda x: 0.008*(x-128)**2, (255,), dtype="int16")
6569

66-
im = self.core.drawBars(spectrum, im)
70+
im = self.core.drawBars(spectrum, im, nextPreviewInformation["visColor"])
6771

6872
self._image = ImageQt(im)
6973
self._previewImage = QtGui.QImage(self._image)

0 commit comments

Comments
 (0)