diff options
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/__base__.py | 5 | ||||
| -rw-r--r-- | src/components/color.py | 7 | ||||
| -rw-r--r-- | src/components/image.py | 5 | ||||
| -rw-r--r-- | src/components/original.py | 5 | ||||
| -rw-r--r-- | src/components/text.py | 5 | ||||
| -rw-r--r-- | src/components/video.py | 27 |
6 files changed, 30 insertions, 24 deletions
diff --git a/src/components/__base__.py b/src/components/__base__.py index 9b7b958..84d41c8 100644 --- a/src/components/__base__.py +++ b/src/components/__base__.py @@ -1,4 +1,4 @@ -from PyQt5 import QtGui, QtCore, QtWidgets +from PyQt5 import uic, QtGui, QtCore, QtWidgets from PIL import Image import os @@ -114,6 +114,9 @@ class Component(QtCore.QObject): except: return (255, 255, 255) + def loadUi(self, filename): + return uic.loadUi(os.path.join(self.core.componentsPath, filename)) + ''' ### Reference methods for creating a new component ### (Inherit from this class and define these) diff --git a/src/components/color.py b/src/components/color.py index f1fb2b2..253ac83 100644 --- a/src/components/color.py +++ b/src/components/color.py @@ -1,5 +1,5 @@ from PIL import Image, ImageDraw -from PyQt5 import uic, QtGui, QtCore, QtWidgets +from PyQt5 import QtGui, QtCore, QtWidgets from PyQt5.QtGui import QColor from PIL.ImageQt import ImageQt import os @@ -13,8 +13,7 @@ class Component(__base__.Component): def widget(self, parent): self.parent = parent - page = uic.loadUi(os.path.join( - os.path.dirname(os.path.realpath(__file__)), 'color.ui')) + page = self.loadUi('color.ui') self.color1 = (0, 0, 0) self.color2 = (133, 133, 133) @@ -177,7 +176,7 @@ class Component(__base__.Component): self.sizeWidth, self.sizeHeight ) painter.end() - imBytes = image.bits().asstring(image.numBytes()) + imBytes = image.bits().asstring(image.byteCount()) return Image.frombytes('RGBA', (width, height), imBytes) def loadPreset(self, pr, presetName=None): diff --git a/src/components/image.py b/src/components/image.py index 3517af6..143ae59 100644 --- a/src/components/image.py +++ b/src/components/image.py @@ -1,5 +1,5 @@ from PIL import Image, ImageDraw -from PyQt5 import uic, QtGui, QtCore, QtWidgets +from PyQt5 import QtGui, QtCore, QtWidgets import os from . import __base__ @@ -12,8 +12,7 @@ class Component(__base__.Component): def widget(self, parent): self.parent = parent self.settings = parent.settings - page = uic.loadUi(os.path.join( - os.path.dirname(os.path.realpath(__file__)), 'image.ui')) + page = self.loadUi('image.ui') self.imagePath = '' self.x = 0 self.y = 0 diff --git a/src/components/original.py b/src/components/original.py index 0d5001c..0185e0d 100644 --- a/src/components/original.py +++ b/src/components/original.py @@ -1,6 +1,6 @@ import numpy from PIL import Image, ImageDraw -from PyQt5 import uic, QtGui, QtCore, QtWidgets +from PyQt5 import QtGui, QtCore, QtWidgets from PyQt5.QtGui import QColor import os from . import __base__ @@ -17,8 +17,7 @@ class Component(__base__.Component): self.parent = parent self.visColor = (255, 255, 255) - page = uic.loadUi(os.path.join( - os.path.dirname(os.path.realpath(__file__)), 'original.ui')) + page = self.loadUi('original.ui') page.comboBox_visLayout.addItem("Classic") page.comboBox_visLayout.addItem("Split") page.comboBox_visLayout.addItem("Bottom") diff --git a/src/components/text.py b/src/components/text.py index 76961c9..7f4659f 100644 --- a/src/components/text.py +++ b/src/components/text.py @@ -1,6 +1,6 @@ from PIL import Image, ImageDraw from PyQt5.QtGui import QPainter, QColor, QFont -from PyQt5 import uic, QtGui, QtCore, QtWidgets +from PyQt5 import QtGui, QtCore, QtWidgets from PIL.ImageQt import ImageQt import os import io @@ -29,8 +29,7 @@ class Component(__base__.Component): self.xPosition = width / 2 - fm.width(self.title)/2 self.yPosition = height / 2 * 1.036 - page = uic.loadUi(os.path.join( - os.path.dirname(os.path.realpath(__file__)), 'text.ui')) + page = self.loadUi('text.ui') page.comboBox_textAlign.addItem("Left") page.comboBox_textAlign.addItem("Middle") page.comboBox_textAlign.addItem("Right") diff --git a/src/components/video.py b/src/components/video.py index 70247e1..3e87d2e 100644 --- a/src/components/video.py +++ b/src/components/video.py @@ -1,6 +1,7 @@ from PIL import Image, ImageDraw -from PyQt5 import uic, QtGui, QtCore, QtWidgets +from PyQt5 import QtGui, QtCore, QtWidgets import os +import math import subprocess import threading from queue import PriorityQueue @@ -79,9 +80,18 @@ class Video: self.frameNo += 1 # If we run out of frames, use the last good frame and loop. - if len(self.currentFrame) == 0: - self.frameBuffer.put((self.frameNo-1, self.lastFrame)) - continue + try: + if len(self.currentFrame) == 0: + self.frameBuffer.put((self.frameNo-1, self.lastFrame)) + continue + except AttributeError as e: + self.parent.showMessage( + msg='%s couldn\'t be loaded.' % os.path.basename( + self.videoPath + ), + detail=str(e) + ) + self.parent.stopVideo() self.currentFrame = pipe.stdout.read(self.chunkSize) if len(self.currentFrame) != 0: @@ -97,10 +107,7 @@ class Component(__base__.Component): def widget(self, parent): self.parent = parent self.settings = parent.settings - page = uic.loadUi(os.path.join( - os.path.dirname(os.path.realpath(__file__)), - 'video.ui' - )) + page = self.loadUi('video.ui') self.videoPath = '' self.x = 0 self.y = 0 @@ -243,9 +250,9 @@ def scale(scale, width, height, returntype=None): width = (float(width) / 100.0) * float(scale) height = (float(height) / 100.0) * float(scale) if returntype == str: - return (str(int(width)), str(int(height))) + return (str(math.ceil(width)), str(math.ceil(height))) elif returntype == int: - return (int(width), int(height)) + return (math.ceil(width), math.ceil(height)) else: return (width, height) |
