From 0da275bf1b1dd2c956fed9d4a1051dcf3365c382 Mon Sep 17 00:00:00 2001 From: tassaron Date: Sun, 2 Jul 2017 20:46:48 -0400 Subject: renamed component base --- src/components/__base__.py | 163 --------------------------------------------- src/components/color.py | 5 +- src/components/image.py | 5 +- src/components/original.py | 5 +- src/components/text.py | 5 +- src/components/video.py | 7 +- 6 files changed, 16 insertions(+), 174 deletions(-) delete mode 100644 src/components/__base__.py (limited to 'src/components') diff --git a/src/components/__base__.py b/src/components/__base__.py deleted file mode 100644 index b5e7d93..0000000 --- a/src/components/__base__.py +++ /dev/null @@ -1,163 +0,0 @@ -from PyQt5 import uic, QtCore, QtWidgets -from PIL import Image -import os - - -class Component(QtCore.QObject): - '''A base class for components to inherit from''' - - # modified = QtCore.pyqtSignal(int, bool) - - def __init__(self, moduleIndex, compPos, core): - super().__init__() - self.currentPreset = None - self.canceled = False - self.moduleIndex = moduleIndex - self.compPos = compPos - self.core = core - - def __str__(self): - return self.__doc__ - - def version(self): - # change this number to identify new versions of a component - return 1 - - def cancel(self): - # please stop any lengthy process in response to this variable - self.canceled = True - - def reset(self): - self.canceled = False - - def update(self): - self.modified.emit(self.compPos, self.savePreset()) - # read your widget values, then call super().update() - - def loadPreset(self, presetDict, presetName): - '''Subclasses take (presetDict, presetName=None) as args. - Must use super().loadPreset(presetDict, presetName) first, - then update self.page widgets using the preset dict. - ''' - self.currentPreset = presetName \ - if presetName is not None else presetDict['preset'] - - def preFrameRender(self, **kwargs): - '''Triggered only before a video is exported (video_thread.py) - self.worker = the video thread worker - self.completeAudioArray = a list of audio samples - self.sampleSize = number of audio samples per video frame - self.progressBarUpdate = signal to set progress bar number - self.progressBarSetText = signal to set progress bar text - Use the latter two signals to update the MainProgram if needed - for a long initialization procedure (i.e., for a visualizer) - ''' - for var, value in kwargs.items(): - exec('self.%s = value' % var) - - def command(self, arg): - '''Configure a component using argument from the commandline. - Use super().command(arg) at the end of a subclass's method, - if no arguments are found in that method first - ''' - if arg.startswith('preset='): - _, preset = arg.split('=', 1) - path = os.path.join(self.core.getPresetDir(self), preset) - if not os.path.exists(path): - print('Couldn\'t locate preset "%s"' % preset) - quit(1) - else: - print('Opening "%s" preset on layer %s' % ( - preset, self.compPos) - ) - self.core.openPreset(path, self.compPos, preset) - else: - print( - self.__doc__, 'Usage:\n' - 'Open a preset for this component:\n' - ' "preset=Preset Name"') - self.commandHelp() - quit(0) - - def commandHelp(self): - '''Print help text for this Component's commandline arguments''' - - def blankFrame(self, width, height): - return Image.new("RGBA", (width, height), (0, 0, 0, 0)) - - def pickColor(self): - '''Use color picker to get color input from the user, - and return this as an RGB string and QPushButton stylesheet. - In a subclass apply stylesheet to any color selection widgets - ''' - dialog = QtWidgets.QColorDialog() - dialog.setOption(QtWidgets.QColorDialog.ShowAlphaChannel, True) - color = dialog.getColor() - if color.isValid(): - RGBstring = '%s,%s,%s' % ( - str(color.red()), str(color.green()), str(color.blue())) - btnStyle = "QPushButton{background-color: %s; outline: none;}" \ - % color.name() - return RGBstring, btnStyle - else: - return None, None - - def RGBFromString(self, 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) - - 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) - - def widget(self, parent): - self.parent = parent - page = uic.loadUi(os.path.join( - os.path.dirname(os.path.realpath(__file__)), 'example.ui')) - # --- connect widget signals here --- - self.page = page - return page - - def update(self): - super().update() - self.parent.drawPreview() - - def previewRender(self, previewWorker): - width = int(previewWorker.core.settings.value('outputWidth')) - height = int(previewWorker.core.settings.value('outputHeight')) - image = Image.new("RGBA", (width, height), (0,0,0,0)) - return image - - def frameRender(self, moduleNo, frameNo): - width = int(self.worker.core.settings.value('outputWidth')) - height = int(self.worker.core.settings.value('outputHeight')) - image = Image.new("RGBA", (width, height), (0,0,0,0)) - return image - - @classmethod - def names(cls): - # Alternative names for renaming a component between project files - return [] - ''' - - -class BadComponentInit(Exception): - def __init__(self, arg, name): - string = '''################################ -Mandatory argument "%s" not specified - in %s instance initialization -###################################''' - print(string % (arg, name)) - quit() diff --git a/src/components/color.py b/src/components/color.py index 8a994db..bd45951 100644 --- a/src/components/color.py +++ b/src/components/color.py @@ -3,10 +3,11 @@ from PyQt5 import QtGui, QtCore, QtWidgets from PyQt5.QtGui import QColor from PIL.ImageQt import ImageQt import os -from . import __base__ +from component import Component -class Component(__base__.Component): + +class Component(Component): '''Color''' modified = QtCore.pyqtSignal(int, dict) diff --git a/src/components/image.py b/src/components/image.py index 4bb33b1..ba99113 100644 --- a/src/components/image.py +++ b/src/components/image.py @@ -1,10 +1,11 @@ from PIL import Image, ImageDraw from PyQt5 import QtGui, QtCore, QtWidgets import os -from . import __base__ +from component import Component -class Component(__base__.Component): + +class Component(Component): '''Image''' modified = QtCore.pyqtSignal(int, dict) diff --git a/src/components/original.py b/src/components/original.py index 1aa72c9..42049f3 100644 --- a/src/components/original.py +++ b/src/components/original.py @@ -3,12 +3,13 @@ from PIL import Image, ImageDraw from PyQt5 import QtGui, QtCore, QtWidgets from PyQt5.QtGui import QColor import os -from . import __base__ import time from copy import copy +from component import Component -class Component(__base__.Component): + +class Component(Component): '''Classic Visualizer''' modified = QtCore.pyqtSignal(int, dict) diff --git a/src/components/text.py b/src/components/text.py index 6c5c4eb..6be3120 100644 --- a/src/components/text.py +++ b/src/components/text.py @@ -4,10 +4,11 @@ from PyQt5 import QtGui, QtCore, QtWidgets from PIL.ImageQt import ImageQt import os import sys -from . import __base__ +from component import Component -class Component(__base__.Component): + +class Component(Component): '''Title Text''' modified = QtCore.pyqtSignal(int, dict) diff --git a/src/components/video.py b/src/components/video.py index 02bb44b..c5649c5 100644 --- a/src/components/video.py +++ b/src/components/video.py @@ -5,7 +5,8 @@ import math import subprocess import threading from queue import PriorityQueue -from . import __base__ + +from component import Component, BadComponentInit class Video: @@ -26,7 +27,7 @@ class Video: try: exec('self.%s = kwargs[arg]' % arg) except KeyError: - raise __base__.BadComponentInit(arg, self.__doc__) + raise BadComponentInit(arg, self.__doc__) self.frameNo = -1 self.currentFrame = 'None' @@ -102,7 +103,7 @@ class Video: self.lastFrame = self.currentFrame -class Component(__base__.Component): +class Component(Component): '''Video''' modified = QtCore.pyqtSignal(int, dict) -- cgit v1.2.3