-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariable.py
More file actions
96 lines (84 loc) · 2.16 KB
/
variable.py
File metadata and controls
96 lines (84 loc) · 2.16 KB
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
"""
a variable used to hold values
"""
import typing
from smartimage.smartimageXmlObject import SmartimageXmlObject
class Variable(SmartimageXmlObject):
"""
a variable used to hold values
"""
def __init__(self,parent:SmartimageXmlObject,xml:str):
SmartimageXmlObject.__init__(self,parent,xml)
self._value=None
@property
def name(self)->str:
"""
name of the variable
"""
return self._getProperty('name')
@property
def description(self)->str:
"""
optional description of this variable
"""
return self._getProperty('description','')
@property
def uiType(self)->str:
"""
an html input type like:
(checkbox color date datetime datetime-local email file hidden
image month number password radio range search tel text time
url week )
"""
return self._getProperty('type','text')
@property
def type(self)->str:
"""
the ui type of this variable
"""
return self.uiType
@property
def default(self)->typing.Any:
"""
default value for this variable
"""
return self._getProperty('default','')
@property
def value(self)->typing.Any:
"""
the current value of this variable
"""
if self._value is None:
return self.default
return self._value
@value.setter
def value(self,value):
self._value=value
def __int__(self)->int:
"""
convert to int
"""
return int(self.value)
def __float__(self)->float:
"""
convert to float
"""
return float(self.value)
def __repr__(self)->str:
"""
convert to string
"""
return str(self.value)
def __bool__(self)->bool:
"""
convert to bool
"""
# this doesn't seem to work right with python.
# must call toBool directly!
return self.toBool()
def toBool(self)->bool:
"""
convert to bool
"""
s=self.__repr__()
return s and s[0].lower() in ('y','t','1')