aboutsummaryrefslogtreecommitdiff
path: root/src/toolkit
diff options
context:
space:
mode:
Diffstat (limited to 'src/toolkit')
-rw-r--r--src/toolkit/common.py54
-rw-r--r--src/toolkit/ffmpeg.py24
-rw-r--r--src/toolkit/frame.py6
3 files changed, 72 insertions, 12 deletions
diff --git a/src/toolkit/common.py b/src/toolkit/common.py
index eba57d9..2e800eb 100644
--- a/src/toolkit/common.py
+++ b/src/toolkit/common.py
@@ -6,9 +6,59 @@ import string
import os
import sys
import subprocess
+import logging
+from copy import copy
from collections import OrderedDict
+log = logging.getLogger('AVP.Toolkit.Common')
+
+
+class blockSignals:
+ '''
+ Context manager to temporarily block list of QtWidgets from updating,
+ and guarantee restoring the previous state afterwards.
+ '''
+ def __init__(self, widgets):
+ if type(widgets) is dict:
+ self.widgets = concatDictVals(widgets)
+ else:
+ self.widgets = (
+ widgets if hasattr(widgets, '__iter__')
+ else [widgets]
+ )
+
+ def __enter__(self):
+ log.verbose(
+ 'Blocking signals for %s',
+ ", ".join([
+ str(w.__class__.__name__) for w in self.widgets
+ ])
+ )
+ self.oldStates = [w.signalsBlocked() for w in self.widgets]
+ for w in self.widgets:
+ w.blockSignals(True)
+
+ def __exit__(self, *args):
+ log.verbose(
+ 'Resetting blockSignals to %s', str(bool(sum(self.oldStates))))
+ for w, state in zip(self.widgets, self.oldStates):
+ w.blockSignals(state)
+
+
+def concatDictVals(d):
+ '''Concatenates all values in given dict into one list.'''
+ key, value = d.popitem()
+ d[key] = value
+ final = copy(value)
+ if type(final) is not list:
+ final = [final]
+ final.extend([val for val in d.values()])
+ else:
+ value.extend([item for val in d.values() for item in val])
+ return final
+
+
def badName(name):
'''Returns whether a name contains non-alphanumeric chars'''
return any([letter in string.punctuation for letter in name])
@@ -34,6 +84,7 @@ def appendUppercase(lst):
lst.append(form.upper())
return lst
+
def pipeWrapper(func):
'''A decorator to insert proper kwargs into Popen objects.'''
def pipeWrapper(commandList, **kwargs):
@@ -107,12 +158,14 @@ def connectWidget(widget, func):
elif type(widget) == QtWidgets.QComboBox:
widget.currentIndexChanged.connect(func)
else:
+ log.warning('Failed to connect %s ', str(widget.__class__.__name__))
return False
return True
def setWidgetValue(widget, val):
'''Generic setValue method for use with any typical QtWidget'''
+ log.verbose('Setting %s to %s' % (str(widget.__class__.__name__), val))
if type(widget) == QtWidgets.QLineEdit:
widget.setText(val)
elif type(widget) == QtWidgets.QSpinBox \
@@ -123,6 +176,7 @@ def setWidgetValue(widget, val):
elif type(widget) == QtWidgets.QComboBox:
widget.setCurrentIndex(val)
else:
+ log.warning('Failed to set %s ', str(widget.__class__.__name__))
return False
return True
diff --git a/src/toolkit/ffmpeg.py b/src/toolkit/ffmpeg.py
index 8fe9148..d78d803 100644
--- a/src/toolkit/ffmpeg.py
+++ b/src/toolkit/ffmpeg.py
@@ -91,16 +91,24 @@ class FfmpegVideo:
def fillBuffer(self):
from component import ComponentError
- logFilename = os.path.join(
- core.Core.logDir, 'render_%s.log' % str(self.component.compPos))
- log.debug('Creating ffmpeg process (log at %s)' % logFilename)
- with open(logFilename, 'w') as logf:
- logf.write(" ".join(self.command) + '\n\n')
- with open(logFilename, 'a') as logf:
+ if core.Core.logEnabled:
+ logFilename = os.path.join(
+ core.Core.logDir, 'render_%s.log' % str(self.component.compPos)
+ )
+ log.debug('Creating ffmpeg process (log at %s)', logFilename)
+ with open(logFilename, 'w') as logf:
+ logf.write(" ".join(self.command) + '\n\n')
+ with open(logFilename, 'a') as logf:
+ self.pipe = openPipe(
+ self.command, stdin=subprocess.DEVNULL,
+ stdout=subprocess.PIPE, stderr=logf, bufsize=10**8
+ )
+ else:
self.pipe = openPipe(
self.command, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE,
- stderr=logf, bufsize=10**8
+ stderr=subprocess.DEVNULL, bufsize=10**8
)
+
while True:
if self.parent.canceled:
break
@@ -157,7 +165,7 @@ def findFfmpeg():
['ffmpeg', '-version'], stderr=f
)
return "ffmpeg"
- except subprocess.CalledProcessError:
+ except (subprocess.CalledProcessError, FileNotFoundError):
return "avconv"
diff --git a/src/toolkit/frame.py b/src/toolkit/frame.py
index ad8537c..0e200b5 100644
--- a/src/toolkit/frame.py
+++ b/src/toolkit/frame.py
@@ -21,7 +21,6 @@ class FramePainter(QtGui.QPainter):
Pillow image with finalize()
'''
def __init__(self, width, height):
- log.verbose('Creating new FramePainter')
image = BlankFrame(width, height)
self.image = QtGui.QImage(ImageQt(image))
super().__init__(self.image)
@@ -33,6 +32,7 @@ class FramePainter(QtGui.QPainter):
super().setPen(penStyle)
def finalize(self):
+ log.verbose("Finalizing FramePainter")
imBytes = self.image.bits().asstring(self.image.byteCount())
frame = Image.frombytes(
'RGBA', (self.image.width(), self.image.height()), imBytes
@@ -78,8 +78,6 @@ def defaultSize(framefunc):
def FloodFrame(width, height, RgbaTuple):
- log.verbose('Creating new %s*%s %s flood frame' % (
- width, height, RgbaTuple))
return Image.new("RGBA", (width, height), RgbaTuple)
@@ -98,7 +96,7 @@ def Checkerboard(width, height):
log.debug('Creating new %s*%s checkerboard' % (width, height))
image = FloodFrame(1920, 1080, (0, 0, 0, 0))
image.paste(Image.open(
- os.path.join(core.Core.wd, "background.png")),
+ os.path.join(core.Core.wd, 'gui', "background.png")),
(0, 0)
)
image = image.resize((width, height))