From 431b9f63048850f6e3151b1bfd8650143f50dfe7 Mon Sep 17 00:00:00 2001 From: tassaron Date: Mon, 22 May 2017 22:25:38 -0400 Subject: colors are configurable in the GUI any invalid RGB tuple entered will result in white --- core.py | 14 ++++++++++++++ main.py | 42 ++++++++++++++++++++++++++---------------- main.ui | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 100 insertions(+), 18 deletions(-) diff --git a/core.py b/core.py index b693837..6981b87 100644 --- a/core.py +++ b/core.py @@ -194,3 +194,17 @@ class Core(): shell=True ) return sorted([os.path.join(self.tempDir, f) for f in os.listdir(self.tempDir)]) + + @staticmethod + def RGBFromString(string): + ''' turns an RGB string like "255, 255, 255" into a tuple ''' + try: + tup = tuple([int(i) for i in string.split(',')]) + if len(tup) != 3: + raise ValueError + for i in tup: + if i > 255 or i < 0: + raise ValueError + return tup + except: + return (255, 255, 255) diff --git a/main.py b/main.py index c9c4db5..0a37351 100644 --- a/main.py +++ b/main.py @@ -39,23 +39,23 @@ class Command(QtCore.QObject): # colour settings RGBError = 'Bad RGB input (use two commas)' - self.textcolor = (255, 255, 255) - self.viscolor = (255, 255, 255) + # load colors as tuples from a comma-separated string + self.textColor = tuple([int(i) for i in self.settings.value("textColor", '255, 255, 255').split(',')]) + self.visColor = tuple([int(i) for i in self.settings.value("visColor", '255, 255, 255').split(',')]) if self.args.textcolor: try: r, g, b = self.args.textcolor.split(',') except: print(RGBError) else: - self.textcolor = (int(r), int(g), int(b)) - + self.textColor = (int(r), int(g), int(b)) if self.args.viscolor: try: r, g, b = self.args.viscolor.split(',') except: print(RGBError) else: - self.viscolor = (int(r), int(g), int(b)) + self.visColor = (int(r), int(g), int(b)) # font settings if self.args.font: @@ -98,8 +98,8 @@ class Command(QtCore.QObject): self.alignment, self.textX, self.textY, - self.textcolor, - self.viscolor, + self.textColor, + self.visColor, self.args.input, self.args.output) @@ -114,6 +114,8 @@ class Command(QtCore.QObject): self.settings.setValue("fontSize", str(self.fontsize)) self.settings.setValue("xPosition", str(self.textX)) self.settings.setValue("yPosition", str(self.textY)) + self.settings.setValue("visColor", '%s,%s,%s' % self.visColor) + self.settings.setValue("textColor", '%s,%s,%s' % self.textColor) sys.exit(0) class Main(QtCore.QObject): @@ -123,16 +125,16 @@ class Main(QtCore.QObject): videoTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, tuple, tuple, str, str) def __init__(self, window): - QtCore.QObject.__init__(self) # print('main thread id: {}'.format(QtCore.QThread.currentThreadId())) self.window = window self.core = core.Core() - self.settings = QSettings('settings.ini', QSettings.IniFormat) - self.textcolor = (255, 255, 255) - self.viscolor = (255, 255, 255) + + # load colors as tuples from a comma-separated string + self.textColor = core.Core.RGBFromString(self.settings.value("textColor", '255, 255, 255')) + self.visColor = core.Core.RGBFromString(self.settings.value("visColor", '255, 255, 255')) self.previewQueue = Queue() @@ -162,6 +164,8 @@ class Main(QtCore.QObject): window.label_alignment.setText("Title Options") window.label_fontsize.setText("Fontsize") window.label_title.setText("Title Text") + window.label_textColor.setText("Text color:") + window.label_visColor.setText("Visualizer color:") window.pushButton_createVideo.setText("Create Video") window.groupBox_create.setTitle("Create") window.groupBox_settings.setTitle("Settings") @@ -173,6 +177,8 @@ class Main(QtCore.QObject): window.fontsizeSpinBox.setValue(35) window.textXSpinBox.setValue(70) window.textYSpinBox.setValue(375) + window.lineEdit_textColor.setText('%s,%s,%s' % self.textColor) + window.lineEdit_visColor.setText('%s,%s,%s' % self.visColor) titleFont = self.settings.value("titleFont") if not titleFont == None: @@ -197,6 +203,8 @@ class Main(QtCore.QObject): window.textXSpinBox.valueChanged.connect(self.drawPreview) window.textYSpinBox.valueChanged.connect(self.drawPreview) window.fontsizeSpinBox.valueChanged.connect(self.drawPreview) + window.lineEdit_textColor.textChanged.connect(self.drawPreview) + window.lineEdit_visColor.textChanged.connect(self.drawPreview) self.drawPreview() @@ -206,12 +214,14 @@ class Main(QtCore.QObject): self.timer.stop() self.previewThread.quit() 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())) + self.settings.setValue("visColor", self.window.lineEdit_visColor.text()) + self.settings.setValue("textColor", self.window.lineEdit_textColor.text()) def openInputFileDialog(self): inputDir = self.settings.value("inputDir", expanduser("~")) @@ -263,8 +273,8 @@ class Main(QtCore.QObject): self.window.alignmentComboBox.currentIndex(), self.window.textXSpinBox.value(), self.window.textYSpinBox.value(), - self.textcolor, - self.viscolor, + core.Core.RGBFromString(self.window.lineEdit_textColor.text()), + core.Core.RGBFromString(self.window.lineEdit_visColor.text()), self.window.label_input.text(), self.window.label_output.text()) @@ -287,8 +297,8 @@ class Main(QtCore.QObject): self.window.alignmentComboBox.currentIndex(), self.window.textXSpinBox.value(), self.window.textYSpinBox.value(), - self.textcolor, - self.viscolor) + core.Core.RGBFromString(self.window.lineEdit_textColor.text()), + core.Core.RGBFromString(self.window.lineEdit_visColor.text())) # self.processTask.emit() def showPreviewImage(self, image): diff --git a/main.ui b/main.ui index c500905..88d5173 100644 --- a/main.ui +++ b/main.ui @@ -276,7 +276,7 @@ - + 200 @@ -303,13 +303,71 @@ + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + - + + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + 200 + 0 + + + + + 200 + 16777215 + + + + + 200 + 0 + + + + QFrame::NoFrame + + + + + + + + + + + -- cgit v1.2.3