From db1ea1fc4edf19589e82171d48c417742c61c74b Mon Sep 17 00:00:00 2001 From: tassaron Date: Sat, 29 Jul 2017 23:45:37 -0400 Subject: generic preview sound for waveform component with secret preference to use the audio file again --- src/core.py | 1 + 1 file changed, 1 insertion(+) (limited to 'src/core.py') diff --git a/src/core.py b/src/core.py index 1c29774..24bf097 100644 --- a/src/core.py +++ b/src/core.py @@ -506,6 +506,7 @@ class Core: "outputContainer": "MP4", "projectDir": os.path.join(cls.dataDir, 'projects'), "pref_insertCompAtTop": True, + "pref_genericPreview": True, } for parm, value in defaultSettings.items(): -- cgit v1.2.3 From ae8a547b77a618c793929701f9c1fa72d3300110 Mon Sep 17 00:00:00 2001 From: tassaron Date: Thu, 3 Aug 2017 18:08:49 -0400 Subject: max spinbox vals scale relatively & less errors when spamming res change w/h attrs are locked during render so preview thread always get correctly-sized frame --- src/component.py | 92 ++++++++++++++++++++++++++++++++++++------------- src/components/image.py | 2 +- src/components/text.ui | 3 ++ src/core.py | 6 ++-- src/preview_thread.py | 2 ++ 5 files changed, 77 insertions(+), 28 deletions(-) (limited to 'src/core.py') diff --git a/src/component.py b/src/component.py index c5bc44b..ea4b5ec 100644 --- a/src/component.py +++ b/src/component.py @@ -179,9 +179,14 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass): self._colorWidgets = {} self._colorFuncs = {} self._relativeWidgets = {} + # pixel values stored as floats self._relativeValues = {} + # maximum values of spinBoxes at 1080p (Core.resolutions[0]) + self._relativeMaximums = {} + self._lockedProperties = None self._lockedError = None + self._lockedSize = None # Stop lengthy processes in response to this variable self.canceled = False @@ -190,8 +195,12 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass): return self.__class__.name def __repr__(self): + try: + preset = self.savePreset() + except Exception as e: + preset = '%s occured while saving preset' % str(e) return '%s\n%s\n%s' % ( - self.__class__.name, str(self.__class__.version), self.savePreset() + self.__class__.name, str(self.__class__.version), preset ) # =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~==~=~=~=~=~=~=~=~=~=~=~=~=~=~ @@ -304,27 +313,7 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass): elif attr in self._relativeWidgets: # Relative widgets: number scales to fit export resolution - dimension = self.width - 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 + self.updateRelativeWidget(attr) setattr(self, attr, self._trackedWidgets[attr].value()) else: @@ -436,6 +425,13 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass): "background-color : #FFFFFF; outline: none; }" ) + if kwarg == 'relativeWidgets': + # store maximum values of spinBoxes to be scaled appropriately + for attr in kwargs[kwarg]: + self._relativeMaximums[attr] = \ + self._trackedWidgets[attr].maximum() + self.updateRelativeWidgetMaximum(attr) + def pickColor(self, textWidget, button): '''Use color picker to get color input from the user.''' dialog = QtWidgets.QColorDialog() @@ -455,23 +451,35 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass): def lockError(self, msg): self._lockedError = msg + def lockSize(self, w, h): + self._lockedSize = (w, h) + def unlockProperties(self): self._lockedProperties = None def unlockError(self): self._lockedError = None + def unlockSize(self): + self._lockedSize = None + def loadUi(self, filename): '''Load a Qt Designer ui file to use for this component's widget''' return uic.loadUi(os.path.join(self.core.componentsPath, filename)) @property def width(self): - return int(self.settings.value('outputWidth')) + if self._lockedSize is None: + return int(self.settings.value('outputWidth')) + else: + return self._lockedSize[0] @property def height(self): - return int(self.settings.value('outputHeight')) + if self._lockedSize is None: + return int(self.settings.value('outputHeight')) + else: + return self._lockedSize[1] def cancel(self): '''Stop any lengthy process in response to this variable.''' @@ -482,6 +490,42 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass): self.unlockProperties() self.unlockError() + 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 + + if attr in self._relativeValues: + oldRelativeVal = self._relativeValues[attr] + if oldUserValue == newUserValue \ + and oldRelativeVal != newRelativeVal: + # Float changed without pixel value changing, which + # means the pixel value needs to be updated + self._trackedWidgets[attr].blockSignals(True) + self.updateRelativeWidgetMaximum(attr) + self._trackedWidgets[attr].setValue( + math.ceil(dimension * oldRelativeVal)) + self._trackedWidgets[attr].blockSignals(False) + + if attr not in self._relativeValues \ + or oldUserValue != newUserValue: + self._relativeValues[attr] = newRelativeVal + + def updateRelativeWidgetMaximum(self, attr): + maxRes = int(self.core.resolutions[0].split('x')[0]) + newMaximumValue = self.width * ( + self._relativeMaximums[attr] / + maxRes + ) + self._trackedWidgets[attr].setMaximum(int(newMaximumValue)) + class ComponentError(RuntimeError): '''Gives the MainWindow a traceback to display, and cancels the export.''' diff --git a/src/components/image.py b/src/components/image.py index 19c4796..555dfb1 100644 --- a/src/components/image.py +++ b/src/components/image.py @@ -21,8 +21,8 @@ class Component(Component): 'xPosition': self.page.spinBox_x, 'yPosition': self.page.spinBox_y, 'stretched': self.page.checkBox_stretch, - }, presetNames={ 'mirror': self.page.checkBox_mirror, + }, presetNames={ 'imagePath': 'image', 'xPosition': 'x', 'yPosition': 'y', diff --git a/src/components/text.ui b/src/components/text.ui index 05e7f8e..bb5e5af 100644 --- a/src/components/text.ui +++ b/src/components/text.ui @@ -81,6 +81,9 @@ + + 1 + 500 diff --git a/src/core.py b/src/core.py index 24bf097..afb1e45 100644 --- a/src/core.py +++ b/src/core.py @@ -451,8 +451,8 @@ class Core: '1280x720', '854x480', ], - 'windowHasFocus': False, 'FFMPEG_BIN': findFfmpeg(), + 'windowHasFocus': False, 'canceled': False, } @@ -492,7 +492,7 @@ class Core: @classmethod def loadDefaultSettings(cls): - defaultSettings = { + cls.defaultSettings = { "outputWidth": 1280, "outputHeight": 720, "outputFrameRate": 30, @@ -509,7 +509,7 @@ class Core: "pref_genericPreview": True, } - for parm, value in defaultSettings.items(): + for parm, value in cls.defaultSettings.items(): if cls.settings.value(parm) is None: cls.settings.setValue(parm, value) diff --git a/src/preview_thread.py b/src/preview_thread.py index 0a6a856..bb22f0c 100644 --- a/src/preview_thread.py +++ b/src/preview_thread.py @@ -59,7 +59,9 @@ class Worker(QtCore.QObject): components = nextPreviewInformation["components"] for component in reversed(components): try: + component.lockSize(width, height) newFrame = component.previewRender() + component.unlockSize() frame = Image.alpha_composite( frame, newFrame ) -- 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/core.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