2017-06-12 22:34:37 -04:00
|
|
|
from PyQt4 import QtGui, QtCore
|
2017-06-15 22:15:03 -04:00
|
|
|
from PIL import Image
|
2017-05-29 20:39:11 -04:00
|
|
|
|
2017-06-13 22:47:18 -04:00
|
|
|
|
2017-06-12 22:34:37 -04:00
|
|
|
class Component(QtCore.QObject):
|
|
|
|
'''A base class for components to inherit from'''
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-06-12 22:34:37 -04:00
|
|
|
# modified = QtCore.pyqtSignal(int, bool)
|
|
|
|
|
|
|
|
def __init__(self, moduleIndex, compPos):
|
|
|
|
super().__init__()
|
2017-06-07 23:22:55 -04:00
|
|
|
self.currentPreset = None
|
2017-06-12 22:34:37 -04:00
|
|
|
self.moduleIndex = moduleIndex
|
|
|
|
self.compPos = compPos
|
2017-06-07 23:22:55 -04:00
|
|
|
|
2017-05-29 20:39:11 -04:00
|
|
|
def __str__(self):
|
|
|
|
return self.__doc__
|
2017-05-30 19:31:10 -04:00
|
|
|
|
|
|
|
def version(self):
|
2017-05-30 22:05:56 -04:00
|
|
|
# change this number to identify new versions of a component
|
2017-05-30 19:31:10 -04:00
|
|
|
return 1
|
2017-06-04 13:00:36 -04:00
|
|
|
|
|
|
|
def cancel(self):
|
2017-06-12 22:34:37 -04:00
|
|
|
# please stop any lengthy process in response to this variable
|
2017-06-04 13:00:36 -04:00
|
|
|
self.canceled = True
|
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
self.canceled = False
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-06-12 22:34:37 -04:00
|
|
|
def update(self):
|
2017-06-13 22:47:18 -04:00
|
|
|
self.modified.emit(self.compPos, self.savePreset())
|
|
|
|
# read your widget values, then call super().update()
|
2017-06-12 22:34:37 -04:00
|
|
|
|
|
|
|
def loadPreset(self, presetDict, presetName):
|
|
|
|
'''Children should take (presetDict, presetName=None) as args'''
|
|
|
|
|
|
|
|
# Use super().loadPreset(presetDict, presetName)
|
|
|
|
# Then update your widgets using the preset dict
|
|
|
|
self.currentPreset = presetName \
|
|
|
|
if presetName != None else presetDict['preset']
|
2017-06-13 22:47:18 -04:00
|
|
|
'''
|
2017-06-12 22:34:37 -04:00
|
|
|
def savePreset(self):
|
|
|
|
return {}
|
2017-06-13 22:47:18 -04:00
|
|
|
'''
|
2017-05-29 20:39:11 -04:00
|
|
|
def preFrameRender(self, **kwargs):
|
2017-05-31 18:00:10 -04:00
|
|
|
for var, value in kwargs.items():
|
|
|
|
exec('self.%s = value' % var)
|
2017-05-29 20:39:11 -04:00
|
|
|
|
2017-06-15 22:15:03 -04:00
|
|
|
def blankFrame(self, width, height):
|
|
|
|
return Image.new("RGBA", (width, height), (0, 0, 0, 0))
|
|
|
|
|
2017-05-29 20:39:11 -04:00
|
|
|
def pickColor(self):
|
2017-06-11 12:52:29 -04:00
|
|
|
dialog = QtGui.QColorDialog()
|
|
|
|
dialog.setOption(QtGui.QColorDialog.ShowAlphaChannel, True)
|
|
|
|
color = dialog.getColor()
|
2017-05-29 20:39:11 -04:00
|
|
|
if color.isValid():
|
2017-06-06 11:14:39 -04:00
|
|
|
RGBstring = '%s,%s,%s' % (
|
|
|
|
str(color.red()), str(color.green()), str(color.blue()))
|
|
|
|
btnStyle = "QPushButton{background-color: %s; outline: none;}" \
|
|
|
|
% color.name()
|
2017-05-30 22:05:56 -04:00
|
|
|
return RGBstring, btnStyle
|
|
|
|
else:
|
|
|
|
return None, None
|
2017-05-29 20:39:11 -04:00
|
|
|
|
|
|
|
def RGBFromString(self, string):
|
2017-06-06 11:14:39 -04:00
|
|
|
''' 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)
|
2017-05-29 20:39:11 -04:00
|
|
|
|
|
|
|
'''
|
|
|
|
### Reference methods for creating a new component
|
|
|
|
### (Inherit from this class and define these)
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-05-29 20:39:11 -04:00
|
|
|
def widget(self, parent):
|
|
|
|
self.parent = parent
|
2017-06-06 11:14:39 -04:00
|
|
|
page = uic.loadUi(os.path.join(
|
|
|
|
os.path.dirname(os.path.realpath(__file__)), 'example.ui'))
|
2017-05-29 20:39:11 -04:00
|
|
|
# connect widgets signals
|
|
|
|
self.page = page
|
|
|
|
return page
|
|
|
|
|
|
|
|
def update(self):
|
2017-06-12 22:34:37 -04:00
|
|
|
super().update()
|
2017-05-29 20:39:11 -04:00
|
|
|
self.parent.drawPreview()
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-05-29 20:39:11 -04:00
|
|
|
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
|
2017-06-06 11:14:39 -04:00
|
|
|
|
2017-05-29 20:39:11 -04:00
|
|
|
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
|
2017-05-30 19:31:10 -04:00
|
|
|
|
2017-06-03 20:39:32 -04:00
|
|
|
def cancel(self):
|
|
|
|
self.canceled = True
|
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
self.canceled = False
|
2017-05-29 20:39:11 -04:00
|
|
|
'''
|
2017-06-06 20:50:53 -04:00
|
|
|
|
|
|
|
class BadComponentInit(Exception):
|
|
|
|
def __init__(self, arg, name):
|
|
|
|
string = \
|
|
|
|
'''################################
|
|
|
|
Mandatory argument "%s" not specified
|
|
|
|
in %s instance initialization
|
|
|
|
###################################'''
|
|
|
|
print(string % (arg, name))
|
|
|
|
quit()
|