1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
from PyQt4 import QtGui
class Component:
def __init__(self):
self.currentPreset = None
def __str__(self):
return self.__doc__
def version(self):
# change this number to identify new versions of a component
return 1
def cancel(self):
# make sure your component responds to these variables in frameRender()
self.canceled = True
def reset(self):
self.canceled = False
def preFrameRender(self, **kwargs):
for var, value in kwargs.items():
exec('self.%s = value' % var)
def pickColor(self):
dialog = QtGui.QColorDialog()
dialog.setOption(QtGui.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)
'''
### 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 widgets signals
self.page = page
return page
def update(self):
# read widget values
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
def loadPreset(self, presetDict, presetName=None):
self.currentPreset = presetName
# update widgets using a preset dict
def savePreset(self):
return {}
def cancel(self):
self.canceled = True
def reset(self):
self.canceled = False
'''
class BadComponentInit(Exception):
def __init__(self, arg, name):
string = \
'''################################
Mandatory argument "%s" not specified
in %s instance initialization
###################################'''
print(string % (arg, name))
quit()
|