-
Notifications
You must be signed in to change notification settings - Fork 1
/
abstractparameters.py
104 lines (83 loc) · 3.14 KB
/
abstractparameters.py
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
103
104
class ItemWithParameters:
def __init__(self, name="-", ):
self.name=TextParameter(parent=self, name="Name", value=name)
self.selected=False
def getName(self):
return self.name
class EditableParameter:
def __init__(self, parent=None, name="", editable=True, callback=None):
self.name=name
self.parent=parent
self.value=None
self.selected=False
self.editable=editable
self.callback=callback
def updateValue(self, value):
#print "new value", value
self.value=value
if self.callback!=None:
self.callback(self)
def getValue(self):
return self.value
class TextParameter(EditableParameter):
def __init__(self, value="", formatString="{:s}", **kwargs):
self.formatString=formatString
EditableParameter.__init__(self, **kwargs)
self.value=value
class FileParameter(EditableParameter):
def __init__(self, value="", fileSelectionPattern="All files (*.*)", **kwargs):
EditableParameter.__init__(self, **kwargs)
self.value=value
self.fileSelectionPattern=fileSelectionPattern
class NumericalParameter(EditableParameter):
def __init__(self, value=0, min=None, max=None, step=0, enforceRange=False, enforceStep=False, **kwargs):
EditableParameter.__init__(self, **kwargs)
self.value=value
self.min=min
self.max=max
self.step=step
self.enforceRange=enforceRange
self.enforceStep=enforceStep
def updateValue(self, value):
#print "new value", value
self.value=value
if self.enforceRange:
self.value=min(max, max(min, self.value))
if self.enforceStep:
self.value=float(int(self.value/self.step)*self.step)
class ProgressParameter(EditableParameter):
def __init__(self, value=0, min=None, max=None, step=0, **kwargs):
EditableParameter.__init__(self, **kwargs)
self.value=value
self.min=min
self.max=max
self.step=step
def updateValue(self, value, min, max):
#print "new value", value
self.value=value
self.min=min
self.max=max
class ChoiceParameter(EditableParameter):
def __init__(self, value=None, choices=None, **kwargs):
EditableParameter.__init__(self, **kwargs)
self.value=value
self.choices=choices
def getChoiceStrings(self):
cs=[]
for c in self.choices:
if "name" in dir(c) and "value" in dir(c.name):
cs.append(c.name.value)
elif c.__class__.__name__=="str":
cs.append(c)
return cs
def updateValueByString(self, value):
strings=self.getChoiceStrings()
for i in range(0, len(self.choices)):
s=strings[i]
if s==value:
print i, s
self.value=self.choices[i]
print self.value
class ActionParameter(EditableParameter):
def __init__(self, **kwargs):
EditableParameter.__init__(self, **kwargs)