From 3c1b52205f183e9a2c943c5f666ed2c01db3aaf5 Mon Sep 17 00:00:00 2001 From: tassaron Date: Tue, 1 Aug 2017 17:57:39 -0400 Subject: component class now tracks colorwidgets so adding new color-selection widgets is now simple --- src/components/text.py | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) (limited to 'src/components/text.py') diff --git a/src/components/text.py b/src/components/text.py index 8a302ff..1fe3467 100644 --- a/src/components/text.py +++ b/src/components/text.py @@ -5,7 +5,6 @@ import os from component import Component from toolkit.frame import FramePainter -from toolkit import rgbFromString, pickColor class Component(Component): @@ -33,11 +32,6 @@ class Component(Component): self.page.comboBox_textAlign.addItem("Right") self.page.lineEdit_textColor.setText('%s,%s,%s' % self.textColor) - self.page.pushButton_textColor.clicked.connect(self.pickColor) - btnStyle = "QPushButton { background-color : %s; outline: none; }" \ - % QColor(*self.textColor).name() - self.page.pushButton_textColor.setStyleSheet(btnStyle) - self.page.lineEdit_title.setText(self.title) self.page.comboBox_textAlign.setCurrentIndex(int(self.alignment)) self.page.spinBox_fontSize.setValue(int(self.fontSize)) @@ -48,21 +42,18 @@ class Component(Component): self.update ) self.trackWidgets({ + 'textColor': self.page.lineEdit_textColor, 'title': self.page.lineEdit_title, 'alignment': self.page.comboBox_textAlign, 'fontSize': self.page.spinBox_fontSize, 'xPosition': self.page.spinBox_xTextAlign, 'yPosition': self.page.spinBox_yTextAlign, + }, colorWidgets={ + 'textColor': self.page.pushButton_textColor, }) def update(self): self.titleFont = self.page.fontComboBox_titleFont.currentFont() - self.textColor = rgbFromString( - self.page.lineEdit_textColor.text()) - btnStyle = "QPushButton { background-color : %s; outline: none; }" \ - % QColor(*self.textColor).name() - self.page.pushButton_textColor.setStyleSheet(btnStyle) - super().update() def getXY(self): @@ -86,15 +77,10 @@ class Component(Component): font = QFont() font.fromString(pr['titleFont']) self.page.fontComboBox_titleFont.setCurrentFont(font) - self.page.lineEdit_textColor.setText('%s,%s,%s' % pr['textColor']) - btnStyle = "QPushButton { background-color : %s; outline: none; }" \ - % QColor(*pr['textColor']).name() - self.page.pushButton_textColor.setStyleSheet(btnStyle) def savePreset(self): saveValueStore = super().savePreset() saveValueStore['titleFont'] = self.titleFont.toString() - saveValueStore['textColor'] = self.textColor return saveValueStore def previewRender(self): @@ -122,13 +108,6 @@ class Component(Component): return image.finalize() - def pickColor(self): - RGBstring, btnStyle = pickColor() - if not RGBstring: - return - self.page.lineEdit_textColor.setText(RGBstring) - self.page.pushButton_textColor.setStyleSheet(btnStyle) - def commandHelp(self): print('Enter a string to use as centred white text:') print(' "title=User Error"') -- cgit v1.2.3 From 5784cdbcf87556b61519782cd1fc27065ffbc631 Mon Sep 17 00:00:00 2001 From: tassaron Date: Tue, 1 Aug 2017 21:57:36 -0400 Subject: x/y pixel values update to match output resolution --- src/component.py | 39 ++++++++++++++++++++++++++++++++++++--- src/components/color.py | 3 +++ src/components/image.py | 3 +++ src/components/original.py | 2 ++ src/components/spectrum.py | 3 +++ src/components/text.py | 19 +++++++++++-------- src/components/video.py | 3 +++ src/components/waveform.py | 3 +++ src/mainwindow.py | 5 ++++- 9 files changed, 68 insertions(+), 12 deletions(-) (limited to 'src/components/text.py') diff --git a/src/component.py b/src/component.py index d47aeae..5dfe2ab 100644 --- a/src/component.py +++ b/src/component.py @@ -6,6 +6,7 @@ from PyQt5 import uic, QtCore, QtWidgets from PyQt5.QtGui import QColor import os import sys +import math import time from toolkit.frame import BlankFrame @@ -176,7 +177,9 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass): self._presetNames = {} self._commandArgs = {} self._colorWidgets = {} + self._colorFuncs = {} self._relativeWidgets = {} + self._relativeValues = {} self._lockedProperties = None self._lockedError = None @@ -291,14 +294,44 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass): ''' for attr, widget in self._trackedWidgets.items(): if attr in self._colorWidgets: + # Color Widgets: text stored as tuple & update the button color rgbTuple = rgbFromString(widget.text()) - setattr(self, attr, rgbTuple) btnStyle = ( "QPushButton { background-color : %s; outline: none; }" - % QColor(*rgbTuple).name() - ) + % QColor(*rgbTuple).name()) self._colorWidgets[attr].setStyleSheet(btnStyle) + setattr(self, attr, rgbTuple) + + elif attr in self._relativeWidgets: + # Relative widgets: number scales to fit export resolution + if self._relativeWidgets[attr] == 'x': + dimension = self.width + else: + dimension = self.height + try: + oldUserValue = getattr(self, attr) + except AttributeError: + oldUserValue = self._trackedWidgets[attr].value() + newUserValue = self._trackedWidgets[attr].value() + newRelativeVal = newUserValue / dimension + + if attr in self._relativeValues: + if oldUserValue == newUserValue: + oldRelativeVal = self._relativeValues[attr] + if oldRelativeVal != newRelativeVal: + # Float changed without pixel value changing, which + # means the pixel value needs to be updated + self._trackedWidgets[attr].blockSignals(True) + self._trackedWidgets[attr].setValue( + math.ceil(dimension * oldRelativeVal)) + self._trackedWidgets[attr].blockSignals(False) + if oldUserValue != newUserValue \ + or attr not in self._relativeValues: + self._relativeValues[attr] = newRelativeVal + setattr(self, attr, self._trackedWidgets[attr].value()) + else: + # Normal tracked widget setattr(self, attr, getWidgetValue(widget)) if not self.core.openingProject: diff --git a/src/components/color.py b/src/components/color.py index d6fffc6..703caca 100644 --- a/src/components/color.py +++ b/src/components/color.py @@ -60,6 +60,9 @@ class Component(Component): }, colorWidgets={ 'color1': self.page.pushButton_color1, 'color2': self.page.pushButton_color2, + }, relativeWidgets={ + 'x': 'x', + 'y': 'y', }, ) diff --git a/src/components/image.py b/src/components/image.py index a96f127..2ffa5a1 100644 --- a/src/components/image.py +++ b/src/components/image.py @@ -28,6 +28,9 @@ class Component(Component): 'imagePath': 'image', 'xPosition': 'x', 'yPosition': 'y', + }, relativeWidgets={ + 'xPosition': 'x', + 'yPosition': 'y', }, ) diff --git a/src/components/original.py b/src/components/original.py index 950ac7b..67e3239 100644 --- a/src/components/original.py +++ b/src/components/original.py @@ -40,6 +40,8 @@ class Component(Component): 'y': self.page.spinBox_y, }, colorWidgets={ 'visColor': self.page.pushButton_visColor, + }, relativeWidgets={ + 'y': 'y', }) def previewRender(self): diff --git a/src/components/spectrum.py b/src/components/spectrum.py index 8ab8404..2cc641d 100644 --- a/src/components/spectrum.py +++ b/src/components/spectrum.py @@ -49,6 +49,9 @@ class Component(Component): 'compress': self.page.checkBox_compress, 'mono': self.page.checkBox_mono, 'hue': self.page.spinBox_hue, + }, relativeWidgets={ + 'x': 'x', + 'y': 'y', } ) for widget in self._trackedWidgets.values(): diff --git a/src/components/text.py b/src/components/text.py index 1fe3467..0f87038 100644 --- a/src/components/text.py +++ b/src/components/text.py @@ -17,15 +17,12 @@ class Component(Component): def widget(self, *args): super().widget(*args) - height = int(self.settings.value('outputHeight')) - width = int(self.settings.value('outputWidth')) + # height = int(self.settings.value('outputHeight')) + # width = int(self.settings.value('outputWidth')) self.textColor = (255, 255, 255) self.title = 'Text' self.alignment = 1 - self.fontSize = height / 13.5 - fm = QtGui.QFontMetrics(self.titleFont) - self.xPosition = width / 2 - fm.width(self.title)/2 - self.yPosition = height / 2 * 1.036 + self.fontSize = self.height / 13.5 self.page.comboBox_textAlign.addItem("Left") self.page.comboBox_textAlign.addItem("Middle") @@ -35,8 +32,11 @@ class Component(Component): self.page.lineEdit_title.setText(self.title) self.page.comboBox_textAlign.setCurrentIndex(int(self.alignment)) self.page.spinBox_fontSize.setValue(int(self.fontSize)) - self.page.spinBox_xTextAlign.setValue(int(self.xPosition)) - self.page.spinBox_yTextAlign.setValue(int(self.yPosition)) + + fm = QtGui.QFontMetrics(self.titleFont) + self.page.spinBox_xTextAlign.setValue( + self.width / 2 - fm.width(self.title)/2) + self.page.spinBox_yTextAlign.setValue(self.height / 2 * 1.036) self.page.fontComboBox_titleFont.currentFontChanged.connect( self.update @@ -50,6 +50,9 @@ class Component(Component): 'yPosition': self.page.spinBox_yTextAlign, }, colorWidgets={ 'textColor': self.page.pushButton_textColor, + }, relativeWidgets={ + 'xPosition': 'x', + 'yPosition': 'y', }) def update(self): diff --git a/src/components/video.py b/src/components/video.py index 6cd16e5..3569d17 100644 --- a/src/components/video.py +++ b/src/components/video.py @@ -38,6 +38,9 @@ class Component(Component): 'loopVideo': 'loop', 'xPosition': 'x', 'yPosition': 'y', + }, relativeWidgets={ + 'xPosition': 'x', + 'yPosition': 'y', } ) diff --git a/src/components/waveform.py b/src/components/waveform.py index 9c3cf86..a25116b 100644 --- a/src/components/waveform.py +++ b/src/components/waveform.py @@ -41,6 +41,9 @@ class Component(Component): 'mono': self.page.checkBox_mono, }, colorWidgets={ 'color': self.page.pushButton_color, + }, relativeWidgets={ + 'x': 'x', + 'y': 'y', } ) diff --git a/src/mainwindow.py b/src/mainwindow.py index d9e95e2..1c8806d 100644 --- a/src/mainwindow.py +++ b/src/mainwindow.py @@ -644,9 +644,12 @@ class MainWindow(QtWidgets.QMainWindow): def updateResolution(self): resIndex = int(self.window.comboBox_resolution.currentIndex()) res = Core.resolutions[resIndex].split('x') + changed = res[0] != self.settings.value("outputWidth") self.settings.setValue('outputWidth', res[0]) self.settings.setValue('outputHeight', res[1]) - self.drawPreview() + if changed: + for i in range(len(self.core.selectedComponents)): + self.core.updateComponent(i) def drawPreview(self, force=False, **kwargs): '''Use autosave keyword arg to force saving or not saving if needed''' -- cgit v1.2.3 From 62431a3cfebdc8490b7010d71b8e646dd6bd0d35 Mon Sep 17 00:00:00 2001 From: tassaron Date: Tue, 1 Aug 2017 22:07:49 -0400 Subject: fontsize is also relative --- src/components/text.py | 1 + 1 file changed, 1 insertion(+) (limited to 'src/components/text.py') diff --git a/src/components/text.py b/src/components/text.py index 0f87038..be4de4a 100644 --- a/src/components/text.py +++ b/src/components/text.py @@ -53,6 +53,7 @@ class Component(Component): }, relativeWidgets={ 'xPosition': 'x', 'yPosition': 'y', + 'fontSize': 'y', }) def update(self): -- cgit v1.2.3 From 6611492b30a7daf7bdbe77f6e12f9d322bdd90c1 Mon Sep 17 00:00:00 2001 From: tassaron Date: Thu, 3 Aug 2017 00:44:46 -0400 Subject: relative gradients & last good frame used for preview errors --- src/components/color.py | 5 +++++ src/components/spectrum.py | 15 ++++++++++----- src/components/text.py | 2 -- src/components/video.py | 15 ++++----------- src/components/waveform.py | 15 ++++++++++----- 5 files changed, 29 insertions(+), 23 deletions(-) (limited to 'src/components/text.py') diff --git a/src/components/color.py b/src/components/color.py index 2b100d9..f5d618e 100644 --- a/src/components/color.py +++ b/src/components/color.py @@ -65,6 +65,11 @@ class Component(Component): 'y': 'y', 'sizeWidth': 'x', 'sizeHeight': 'y', + 'RG_start': 'x', + 'LG_start': 'x', + 'RG_end': 'x', + 'LG_end': 'x', + 'RG_centre': 'x', }, ) diff --git a/src/components/spectrum.py b/src/components/spectrum.py index 2cc641d..9a0c59a 100644 --- a/src/components/spectrum.py +++ b/src/components/spectrum.py @@ -20,6 +20,7 @@ class Component(Component): def widget(self, *args): self.previewFrame = None super().widget(*args) + self._image = BlankFrame(self.width, self.height) self.chunkSize = 4 * self.width * self.height self.changedOptions = True @@ -268,11 +269,15 @@ class Component(Component): return changed def finalizeFrame(self, imageData): - image = Image.frombytes( - 'RGBA', - scale(self.scale, self.width, self.height, int), - imageData - ) + try: + image = Image.frombytes( + 'RGBA', + scale(self.scale, self.width, self.height, int), + imageData + ) + self._image = image + except ValueError: + image = self._image if self.scale != 100 \ or self.x != 0 or self.y != 0: frame = BlankFrame(self.width, self.height) diff --git a/src/components/text.py b/src/components/text.py index be4de4a..2a5d433 100644 --- a/src/components/text.py +++ b/src/components/text.py @@ -17,8 +17,6 @@ class Component(Component): def widget(self, *args): super().widget(*args) - # height = int(self.settings.value('outputHeight')) - # width = int(self.settings.value('outputWidth')) self.textColor = (255, 255, 255) self.title = 'Text' self.alignment = 1 diff --git a/src/components/video.py b/src/components/video.py index 3569d17..2cd67c6 100644 --- a/src/components/video.py +++ b/src/components/video.py @@ -16,12 +16,12 @@ class Component(Component): def widget(self, *args): self.videoPath = '' - self.badVideo = False self.badAudio = False self.x = 0 self.y = 0 self.loopVideo = False super().widget(*args) + self._image = BlankFrame(self.width, self.height) self.page.pushButton_video.clicked.connect(self.pickVideo) self.trackWidgets( { @@ -70,8 +70,6 @@ class Component(Component): if not self.videoPath: self.lockError("There is no video selected.") - elif self.badVideo: - self.lockError("Could not identify an audio stream in this video.") elif not os.path.exists(self.videoPath): self.lockError("The video selected does not exist!") elif os.path.realpath(self.videoPath) == os.path.realpath(outputFile): @@ -199,14 +197,10 @@ class Component(Component): 'RGBA', scale(self.scale, self.width, self.height, int), imageData) - + self._image = image except ValueError: - print( - '### BAD VIDEO SELECTED ###\n' - 'Video will not export with these settings' - ) - self.badVideo = True - return BlankFrame(self.width, self.height) + # use last good frame + image = self._image if self.scale != 100 \ or self.xPosition != 0 or self.yPosition != 0: @@ -214,5 +208,4 @@ class Component(Component): frame.paste(image, box=(self.xPosition, self.yPosition)) else: frame = image - self.badVideo = False return frame diff --git a/src/components/waveform.py b/src/components/waveform.py index a25116b..526e6fb 100644 --- a/src/components/waveform.py +++ b/src/components/waveform.py @@ -19,6 +19,7 @@ class Component(Component): def widget(self, *args): super().widget(*args) + self._image = BlankFrame(self.width, self.height) self.page.lineEdit_color.setText('255,255,255') @@ -178,11 +179,15 @@ class Component(Component): self.chunkSize = 4 * width * height def finalizeFrame(self, imageData): - image = Image.frombytes( - 'RGBA', - scale(self.scale, self.width, self.height, int), - imageData - ) + try: + image = Image.frombytes( + 'RGBA', + scale(self.scale, self.width, self.height, int), + imageData + ) + self._image = image + except ValueError: + image = self._image if self.scale != 100 \ or self.x != 0 or self.y != 0: frame = BlankFrame(self.width, self.height) -- cgit v1.2.3 From 219e846984bb10e9674432fa7aeac4157635c743 Mon Sep 17 00:00:00 2001 From: tassaron Date: Thu, 3 Aug 2017 12:16:57 -0400 Subject: relativeWidgets might as well be a list --- src/component.py | 5 +--- src/components/color.py | 63 +++++++++++++++++++++------------------------- src/components/image.py | 36 ++++++++++++-------------- src/components/original.py | 6 ++--- src/components/spectrum.py | 47 ++++++++++++++++------------------ src/components/text.py | 8 +++--- src/components/video.py | 37 +++++++++++++-------------- src/components/waveform.py | 35 ++++++++++++-------------- 8 files changed, 106 insertions(+), 131 deletions(-) (limited to 'src/components/text.py') diff --git a/src/component.py b/src/component.py index 5dfe2ab..c5bc44b 100644 --- a/src/component.py +++ b/src/component.py @@ -304,10 +304,7 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass): elif attr in self._relativeWidgets: # Relative widgets: number scales to fit export resolution - if self._relativeWidgets[attr] == 'x': - dimension = self.width - else: - dimension = self.height + dimension = self.width try: oldUserValue = getattr(self, attr) except AttributeError: diff --git a/src/components/color.py b/src/components/color.py index f5d618e..5d1233e 100644 --- a/src/components/color.py +++ b/src/components/color.py @@ -37,41 +37,34 @@ class Component(Component): self.page.comboBox_fill.addItem(label) self.page.comboBox_fill.setCurrentIndex(0) - self.trackWidgets( - { - 'x': self.page.spinBox_x, - 'y': self.page.spinBox_y, - 'sizeWidth': self.page.spinBox_width, - 'sizeHeight': self.page.spinBox_height, - 'trans': self.page.checkBox_trans, - 'spread': self.page.comboBox_spread, - 'stretch': self.page.checkBox_stretch, - 'RG_start': self.page.spinBox_radialGradient_start, - 'LG_start': self.page.spinBox_linearGradient_start, - 'RG_end': self.page.spinBox_radialGradient_end, - 'LG_end': self.page.spinBox_linearGradient_end, - 'RG_centre': self.page.spinBox_radialGradient_spread, - 'fillType': self.page.comboBox_fill, - 'color1': self.page.lineEdit_color1, - 'color2': self.page.lineEdit_color2, - }, presetNames={ - 'sizeWidth': 'width', - 'sizeHeight': 'height', - }, colorWidgets={ - 'color1': self.page.pushButton_color1, - 'color2': self.page.pushButton_color2, - }, relativeWidgets={ - 'x': 'x', - 'y': 'y', - 'sizeWidth': 'x', - 'sizeHeight': 'y', - 'RG_start': 'x', - 'LG_start': 'x', - 'RG_end': 'x', - 'LG_end': 'x', - 'RG_centre': 'x', - }, - ) + self.trackWidgets({ + 'x': self.page.spinBox_x, + 'y': self.page.spinBox_y, + 'sizeWidth': self.page.spinBox_width, + 'sizeHeight': self.page.spinBox_height, + 'trans': self.page.checkBox_trans, + 'spread': self.page.comboBox_spread, + 'stretch': self.page.checkBox_stretch, + 'RG_start': self.page.spinBox_radialGradient_start, + 'LG_start': self.page.spinBox_linearGradient_start, + 'RG_end': self.page.spinBox_radialGradient_end, + 'LG_end': self.page.spinBox_linearGradient_end, + 'RG_centre': self.page.spinBox_radialGradient_spread, + 'fillType': self.page.comboBox_fill, + 'color1': self.page.lineEdit_color1, + 'color2': self.page.lineEdit_color2, + }, presetNames={ + 'sizeWidth': 'width', + 'sizeHeight': 'height', + }, colorWidgets={ + 'color1': self.page.pushButton_color1, + 'color2': self.page.pushButton_color2, + }, relativeWidgets=[ + 'x', 'y', + 'sizeWidth', 'sizeHeight', + 'LG_start', 'LG_end', + 'RG_start', 'RG_end', 'RG_centre', + ]) def update(self): fillType = self.page.comboBox_fill.currentIndex() diff --git a/src/components/image.py b/src/components/image.py index 2ffa5a1..19c4796 100644 --- a/src/components/image.py +++ b/src/components/image.py @@ -13,26 +13,22 @@ class Component(Component): def widget(self, *args): super().widget(*args) self.page.pushButton_image.clicked.connect(self.pickImage) - self.trackWidgets( - { - 'imagePath': self.page.lineEdit_image, - 'scale': self.page.spinBox_scale, - 'rotate': self.page.spinBox_rotate, - 'color': self.page.spinBox_color, - 'xPosition': self.page.spinBox_x, - 'yPosition': self.page.spinBox_y, - 'stretched': self.page.checkBox_stretch, - 'mirror': self.page.checkBox_mirror, - }, - presetNames={ - 'imagePath': 'image', - 'xPosition': 'x', - 'yPosition': 'y', - }, relativeWidgets={ - 'xPosition': 'x', - 'yPosition': 'y', - }, - ) + self.trackWidgets({ + 'imagePath': self.page.lineEdit_image, + 'scale': self.page.spinBox_scale, + 'rotate': self.page.spinBox_rotate, + 'color': self.page.spinBox_color, + 'xPosition': self.page.spinBox_x, + 'yPosition': self.page.spinBox_y, + 'stretched': self.page.checkBox_stretch, + }, presetNames={ + 'mirror': self.page.checkBox_mirror, + 'imagePath': 'image', + 'xPosition': 'x', + 'yPosition': 'y', + }, relativeWidgets=[ + 'xPosition', 'yPosition', + ]) def previewRender(self): return self.drawFrame(self.width, self.height) diff --git a/src/components/original.py b/src/components/original.py index 67e3239..f886374 100644 --- a/src/components/original.py +++ b/src/components/original.py @@ -40,9 +40,9 @@ class Component(Component): 'y': self.page.spinBox_y, }, colorWidgets={ 'visColor': self.page.pushButton_visColor, - }, relativeWidgets={ - 'y': 'y', - }) + }, relativeWidgets=[ + 'y', + ]) def previewRender(self): spectrum = numpy.fromfunction( diff --git a/src/components/spectrum.py b/src/components/spectrum.py index 9a0c59a..666e20a 100644 --- a/src/components/spectrum.py +++ b/src/components/spectrum.py @@ -30,31 +30,28 @@ class Component(Component): self.update ) - self.trackWidgets( - { - 'filterType': self.page.comboBox_filterType, - 'window': self.page.comboBox_window, - 'mode': self.page.comboBox_mode, - 'amplitude': self.page.comboBox_amplitude0, - 'amplitude1': self.page.comboBox_amplitude1, - 'amplitude2': self.page.comboBox_amplitude2, - 'display': self.page.comboBox_display, - 'zoom': self.page.spinBox_zoom, - 'tc': self.page.spinBox_tc, - 'x': self.page.spinBox_x, - 'y': self.page.spinBox_y, - 'mirror': self.page.checkBox_mirror, - 'draw': self.page.checkBox_draw, - 'scale': self.page.spinBox_scale, - 'color': self.page.comboBox_color, - 'compress': self.page.checkBox_compress, - 'mono': self.page.checkBox_mono, - 'hue': self.page.spinBox_hue, - }, relativeWidgets={ - 'x': 'x', - 'y': 'y', - } - ) + self.trackWidgets({ + 'filterType': self.page.comboBox_filterType, + 'window': self.page.comboBox_window, + 'mode': self.page.comboBox_mode, + 'amplitude': self.page.comboBox_amplitude0, + 'amplitude1': self.page.comboBox_amplitude1, + 'amplitude2': self.page.comboBox_amplitude2, + 'display': self.page.comboBox_display, + 'zoom': self.page.spinBox_zoom, + 'tc': self.page.spinBox_tc, + 'x': self.page.spinBox_x, + 'y': self.page.spinBox_y, + 'mirror': self.page.checkBox_mirror, + 'draw': self.page.checkBox_draw, + 'scale': self.page.spinBox_scale, + 'color': self.page.comboBox_color, + 'compress': self.page.checkBox_compress, + 'mono': self.page.checkBox_mono, + 'hue': self.page.spinBox_hue, + }, relativeWidgets=[ + 'x', 'y', + ]) for widget in self._trackedWidgets.values(): connectWidget(widget, lambda: self.changed()) diff --git a/src/components/text.py b/src/components/text.py index 2a5d433..b7c244e 100644 --- a/src/components/text.py +++ b/src/components/text.py @@ -48,11 +48,9 @@ class Component(Component): 'yPosition': self.page.spinBox_yTextAlign, }, colorWidgets={ 'textColor': self.page.pushButton_textColor, - }, relativeWidgets={ - 'xPosition': 'x', - 'yPosition': 'y', - 'fontSize': 'y', - }) + }, relativeWidgets=[ + 'xPosition', 'yPosition', 'fontSize', + ]) def update(self): self.titleFont = self.page.fontComboBox_titleFont.currentFont() diff --git a/src/components/video.py b/src/components/video.py index 2cd67c6..b6bdd52 100644 --- a/src/components/video.py +++ b/src/components/video.py @@ -23,26 +23,23 @@ class Component(Component): super().widget(*args) self._image = BlankFrame(self.width, self.height) self.page.pushButton_video.clicked.connect(self.pickVideo) - self.trackWidgets( - { - 'videoPath': self.page.lineEdit_video, - 'loopVideo': self.page.checkBox_loop, - 'useAudio': self.page.checkBox_useAudio, - 'distort': self.page.checkBox_distort, - 'scale': self.page.spinBox_scale, - 'volume': self.page.spinBox_volume, - 'xPosition': self.page.spinBox_x, - 'yPosition': self.page.spinBox_y, - }, presetNames={ - 'videoPath': 'video', - 'loopVideo': 'loop', - 'xPosition': 'x', - 'yPosition': 'y', - }, relativeWidgets={ - 'xPosition': 'x', - 'yPosition': 'y', - } - ) + self.trackWidgets({ + 'videoPath': self.page.lineEdit_video, + 'loopVideo': self.page.checkBox_loop, + 'useAudio': self.page.checkBox_useAudio, + 'distort': self.page.checkBox_distort, + 'scale': self.page.spinBox_scale, + 'volume': self.page.spinBox_volume, + 'xPosition': self.page.spinBox_x, + 'yPosition': self.page.spinBox_y, + }, presetNames={ + 'videoPath': 'video', + 'loopVideo': 'loop', + 'xPosition': 'x', + 'yPosition': 'y', + }, relativeWidgets=[ + 'xPosition', 'yPosition', + ]) def update(self): if self.page.checkBox_useAudio.isChecked(): diff --git a/src/components/waveform.py b/src/components/waveform.py index 526e6fb..71cbcac 100644 --- a/src/components/waveform.py +++ b/src/components/waveform.py @@ -28,25 +28,22 @@ class Component(Component): self.update ) - self.trackWidgets( - { - 'color': self.page.lineEdit_color, - 'mode': self.page.comboBox_mode, - 'amplitude': self.page.comboBox_amplitude, - 'x': self.page.spinBox_x, - 'y': self.page.spinBox_y, - 'mirror': self.page.checkBox_mirror, - 'scale': self.page.spinBox_scale, - 'opacity': self.page.spinBox_opacity, - 'compress': self.page.checkBox_compress, - 'mono': self.page.checkBox_mono, - }, colorWidgets={ - 'color': self.page.pushButton_color, - }, relativeWidgets={ - 'x': 'x', - 'y': 'y', - } - ) + self.trackWidgets({ + 'color': self.page.lineEdit_color, + 'mode': self.page.comboBox_mode, + 'amplitude': self.page.comboBox_amplitude, + 'x': self.page.spinBox_x, + 'y': self.page.spinBox_y, + 'mirror': self.page.checkBox_mirror, + 'scale': self.page.spinBox_scale, + 'opacity': self.page.spinBox_opacity, + 'compress': self.page.checkBox_compress, + 'mono': self.page.checkBox_mono, + }, colorWidgets={ + 'color': self.page.pushButton_color, + }, relativeWidgets=[ + 'x', 'y', + ]) def previewRender(self): self.updateChunksize() -- cgit v1.2.3 From 98a47a21d986ccede574baececd179be7550c9d6 Mon Sep 17 00:00:00 2001 From: tassaron Date: Thu, 3 Aug 2017 20:43:23 -0400 Subject: save presets as floats so project resolution is not relevant unfortunately this breaks old projects and presets --- src/component.py | 56 ++++++++++++++++++++---- src/components/text.py | 18 ++++---- src/components/text.ui | 114 ++++++++++++++++++++++++++++++------------------- src/core.py | 2 +- 4 files changed, 127 insertions(+), 63 deletions(-) (limited to 'src/components/text.py') diff --git a/src/component.py b/src/component.py index ea4b5ec..5b38473 100644 --- a/src/component.py +++ b/src/component.py @@ -346,16 +346,29 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass): % QColor(*val).name() ) self._colorWidgets[attr].setStyleSheet(btnStyle) + elif attr in self._relativeWidgets: + self._relativeValues[attr] = val + pixelVal = self.pixelValForAttr(attr, val) + setWidgetValue(widget, pixelVal) else: setWidgetValue(widget, val) def savePreset(self): saveValueStore = {} for attr, widget in self._trackedWidgets.items(): - saveValueStore[ + presetAttrName = ( attr if attr not in self._presetNames else self._presetNames[attr] - ] = getattr(self, attr) + ) + if attr in self._relativeWidgets: + try: + val = self._relativeValues[attr] + except AttributeError: + val = self.floatValForAttr(attr) + else: + val = getattr(self, attr) + + saveValueStore[presetAttrName] = val return saveValueStore def commandHelp(self): @@ -490,17 +503,42 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass): self.unlockProperties() self.unlockError() + def relativeWidgetAxis(func): + def relativeWidgetAxis(self, attr, *args, **kwargs): + if 'axis' not in kwargs: + axis = self.width + if 'height' in attr.lower() \ + or 'ypos' in attr.lower() or attr == 'y': + axis = self.height + kwargs['axis'] = axis + return func(self, attr, *args, **kwargs) + return relativeWidgetAxis + + @relativeWidgetAxis + def pixelValForAttr(self, attr, val=None, **kwargs): + if val is None: + val = self._relativeValues[attr] + return math.ceil(kwargs['axis'] * val) + + @relativeWidgetAxis + def floatValForAttr(self, attr, val=None, **kwargs): + if val is None: + val = self._trackedWidgets[attr].value() + return val / kwargs['axis'] + + def setRelativeWidget(self, attr, floatVal): + '''Set a relative widget using a float''' + pixelVal = self.pixelValForAttr(attr, floatVal) + self._trackedWidgets[attr].setValue(pixelVal) + + def updateRelativeWidget(self, attr): - dimension = self.width - if 'height' in attr.lower() \ - or 'ypos' in attr.lower() or attr == 'y': - dimension = self.height try: oldUserValue = getattr(self, attr) except AttributeError: oldUserValue = self._trackedWidgets[attr].value() newUserValue = self._trackedWidgets[attr].value() - newRelativeVal = newUserValue / dimension + newRelativeVal = self.floatValForAttr(attr, newUserValue) if attr in self._relativeValues: oldRelativeVal = self._relativeValues[attr] @@ -510,8 +548,8 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass): # means the pixel value needs to be updated self._trackedWidgets[attr].blockSignals(True) self.updateRelativeWidgetMaximum(attr) - self._trackedWidgets[attr].setValue( - math.ceil(dimension * oldRelativeVal)) + pixelVal = self.pixelValForAttr(attr, oldRelativeVal) + self._trackedWidgets[attr].setValue(pixelVal) self._trackedWidgets[attr].blockSignals(False) if attr not in self._relativeValues \ diff --git a/src/components/text.py b/src/components/text.py index b7c244e..c3f3bdc 100644 --- a/src/components/text.py +++ b/src/components/text.py @@ -9,7 +9,7 @@ from toolkit.frame import FramePainter class Component(Component): name = 'Title Text' - version = '1.0.0' + version = '1.0.1' def __init__(self, *args): super().__init__(*args) @@ -25,20 +25,17 @@ class Component(Component): self.page.comboBox_textAlign.addItem("Left") self.page.comboBox_textAlign.addItem("Middle") self.page.comboBox_textAlign.addItem("Right") + self.page.comboBox_textAlign.setCurrentIndex(int(self.alignment)) self.page.lineEdit_textColor.setText('%s,%s,%s' % self.textColor) - self.page.lineEdit_title.setText(self.title) - self.page.comboBox_textAlign.setCurrentIndex(int(self.alignment)) self.page.spinBox_fontSize.setValue(int(self.fontSize)) + self.page.lineEdit_title.setText(self.title) - fm = QtGui.QFontMetrics(self.titleFont) - self.page.spinBox_xTextAlign.setValue( - self.width / 2 - fm.width(self.title)/2) - self.page.spinBox_yTextAlign.setValue(self.height / 2 * 1.036) - + self.page.pushButton_center.clicked.connect(self.centerXY) self.page.fontComboBox_titleFont.currentFontChanged.connect( self.update ) + self.trackWidgets({ 'textColor': self.page.lineEdit_textColor, 'title': self.page.lineEdit_title, @@ -51,11 +48,16 @@ class Component(Component): }, relativeWidgets=[ 'xPosition', 'yPosition', 'fontSize', ]) + self.centerXY() def update(self): self.titleFont = self.page.fontComboBox_titleFont.currentFont() super().update() + def centerXY(self): + self.setRelativeWidget('xPosition', 0.5) + self.setRelativeWidget('yPosition', 0.5) + def getXY(self): '''Returns true x, y after considering alignment settings''' fm = QtGui.QFontMetrics(self.titleFont) diff --git a/src/components/text.ui b/src/components/text.ui index bb5e5af..f76979c 100644 --- a/src/components/text.ui +++ b/src/components/text.ui @@ -19,6 +19,36 @@ 4 + + + + + + Title + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + Testing New GUI + + + + + @@ -93,38 +123,6 @@ - - - - - 0 - 0 - - - - Text Layout - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 5 - 20 - - - - @@ -132,6 +130,9 @@ + + + @@ -152,7 +153,17 @@ - + + + Qt::Horizontal + + + + 40 + 20 + + + @@ -162,28 +173,41 @@ 0 - + + + + 0 + 0 + + - Title + Text Layout - - - - 0 - 0 - + + + + + + Qt::Horizontal - + + QSizePolicy::Fixed + + - 0 - 0 + 5 + 20 + + + + - Testing New GUI + Center diff --git a/src/core.py b/src/core.py index afb1e45..61905eb 100644 --- a/src/core.py +++ b/src/core.py @@ -161,7 +161,7 @@ class Core: for widget, value in data['WindowFields']: widget = eval('loader.window.%s' % widget) widget.blockSignals(True) - widget.setText(value) + toolkit.setWidgetValue(widget, value) widget.blockSignals(False) for key, value in data['Settings']: -- cgit v1.2.3