@@ -57,7 +57,7 @@ class Parameter:
57
57
take as input.
58
58
"""
59
59
60
- def __init__ (self , name = '' , description = '' ):
60
+ def __init__ (self , name = '' , description = '' , optional = False ):
61
61
self .name = name
62
62
self .description = description
63
63
self .value = None
@@ -68,6 +68,7 @@ def __init__(self, name='', description=''):
68
68
# It can be used as any other parameter, but it will not be
69
69
# shown to the user
70
70
self .hidden = False
71
+ self .optional = optional
71
72
72
73
def setValue (self , obj ):
73
74
"""
@@ -109,8 +110,8 @@ def tr(self, string, context=''):
109
110
110
111
class ParameterBoolean (Parameter ):
111
112
112
- def __init__ (self , name = '' , description = '' , default = True ):
113
- Parameter .__init__ (self , name , description )
113
+ def __init__ (self , name = '' , description = '' , default = True , optional = False ):
114
+ Parameter .__init__ (self , name , description , optional )
114
115
self .default = parseBool (default )
115
116
self .value = None
116
117
@@ -129,12 +130,12 @@ def setValue(self, value):
129
130
130
131
class ParameterCrs (Parameter ):
131
132
132
- def __init__ (self , name = '' , description = '' , default = 'EPSG:4326' ):
133
+ def __init__ (self , name = '' , description = '' , default = 'EPSG:4326' , optional = False ):
133
134
'''The value is a string that uniquely identifies the
134
135
coordinate reference system. Typically it is the auth id of the CRS
135
136
(if the authority is EPSG) or proj4 string of the CRS (in case
136
137
of other authorities or user defined projections).'''
137
- Parameter .__init__ (self , name , description )
138
+ Parameter .__init__ (self , name , description , optional )
138
139
self .value = None
139
140
self .default = default
140
141
@@ -168,8 +169,8 @@ class ParameterExtent(Parameter):
168
169
169
170
USE_MIN_COVERING_EXTENT = 'USE_MIN_COVERING_EXTENT'
170
171
171
- def __init__ (self , name = '' , description = '' , default = '0,1,0,1' ):
172
- Parameter .__init__ (self , name , description )
172
+ def __init__ (self , name = '' , description = '' , default = '0,1,0,1' , optional = False ):
173
+ Parameter .__init__ (self , name , description , optional )
173
174
self .default = default
174
175
# The value is a string in the form "xmin, xmax, ymin, ymax"
175
176
self .value = None
@@ -200,11 +201,10 @@ def getValueAsCommandLineParameter(self):
200
201
class ParameterFile (Parameter ):
201
202
202
203
def __init__ (self , name = '' , description = '' , isFolder = False , optional = True , ext = None ):
203
- Parameter .__init__ (self , name , description )
204
+ Parameter .__init__ (self , name , description , parseBool ( optional ) )
204
205
self .value = None
205
206
self .ext = ext
206
207
self .isFolder = parseBool (isFolder )
207
- self .optional = parseBool (optional )
208
208
209
209
def getValueAsCommandLineParameter (self ):
210
210
return '"' + unicode (self .value ) + '"'
@@ -229,8 +229,8 @@ def typeName(self):
229
229
class ParameterFixedTable (Parameter ):
230
230
231
231
def __init__ (self , name = '' , description = '' , numRows = 3 ,
232
- cols = ['value' ], fixedNumOfRows = False ):
233
- Parameter .__init__ (self , name , description )
232
+ cols = ['value' ], fixedNumOfRows = False , optional = False ):
233
+ Parameter .__init__ (self , name , description , optional )
234
234
self .cols = cols
235
235
if isinstance (cols , basestring ):
236
236
self .cols = self .cols .split (";" )
@@ -282,9 +282,8 @@ class ParameterMultipleInput(ParameterDataObject):
282
282
TYPE_FILE = 4
283
283
284
284
def __init__ (self , name = '' , description = '' , datatype = - 1 , optional = False ):
285
- ParameterDataObject .__init__ (self , name , description )
285
+ ParameterDataObject .__init__ (self , name , description , optional )
286
286
self .datatype = int (float (datatype ))
287
- self .optional = parseBool (optional )
288
287
self .value = None
289
288
self .exported = None
290
289
@@ -411,8 +410,8 @@ def dataType(self):
411
410
class ParameterNumber (Parameter ):
412
411
413
412
def __init__ (self , name = '' , description = '' , minValue = None , maxValue = None ,
414
- default = 0.0 ):
415
- Parameter .__init__ (self , name , description )
413
+ default = 0.0 , optional = False ):
414
+ Parameter .__init__ (self , name , description , optional )
416
415
try :
417
416
self .default = int (unicode (default ))
418
417
self .isInteger = True
@@ -433,7 +432,7 @@ def setValue(self, n):
433
432
if n is None :
434
433
if not self .optional :
435
434
return False
436
- self .value = None
435
+ self .value = self . default
437
436
return True
438
437
try :
439
438
if float (n ) - int (float (n )) == 0 :
@@ -454,8 +453,8 @@ def setValue(self, n):
454
453
455
454
class ParameterRange (Parameter ):
456
455
457
- def __init__ (self , name = '' , description = '' , default = '0,1' ):
458
- Parameter .__init__ (self , name , description )
456
+ def __init__ (self , name = '' , description = '' , default = '0,1' , optional = False ):
457
+ Parameter .__init__ (self , name , description , optional )
459
458
self .default = default
460
459
self .value = None
461
460
@@ -491,9 +490,8 @@ def getValueAsCommandLineParameter(self):
491
490
class ParameterRaster (ParameterDataObject ):
492
491
493
492
def __init__ (self , name = '' , description = '' , optional = False , showSublayersDialog = True ):
494
- ParameterDataObject .__init__ (self , name , description )
493
+ ParameterDataObject .__init__ (self , name , description , optional )
495
494
self .showSublayersDialog = parseBool (showSublayersDialog )
496
- self .optional = parseBool (optional )
497
495
self .value = None
498
496
self .exported = None
499
497
@@ -548,8 +546,9 @@ def getFileFilter(self):
548
546
549
547
class ParameterSelection (Parameter ):
550
548
551
- def __init__ (self , name = '' , description = '' , options = [], default = 0 , isSource = False ):
552
- Parameter .__init__ (self , name , description )
549
+ def __init__ (self , name = '' , description = '' , options = [], default = 0 , isSource = False ,
550
+ optional = False ):
551
+ Parameter .__init__ (self , name , description , optional )
553
552
self .options = options
554
553
if isSource :
555
554
self .options = []
@@ -588,16 +587,15 @@ class ParameterString(Parameter):
588
587
589
588
def __init__ (self , name = '' , description = '' , default = '' , multiline = False ,
590
589
optional = False ):
591
- Parameter .__init__ (self , name , description )
590
+ Parameter .__init__ (self , name , description , optional )
592
591
self .default = default
593
592
self .value = None
594
593
self .multiline = parseBool (multiline )
595
- self .optional = parseBool (optional )
596
594
597
595
def setValue (self , obj ):
598
596
if obj is None :
599
597
if not self .optional :
600
- return false
598
+ return False
601
599
self .value = ''
602
600
return True
603
601
self .value = unicode (obj ).replace (
@@ -614,8 +612,7 @@ def getValueAsCommandLineParameter(self):
614
612
class ParameterTable (ParameterDataObject ):
615
613
616
614
def __init__ (self , name = '' , description = '' , optional = False ):
617
- ParameterDataObject .__init__ (self , name , description )
618
- self .optional = parseBool (optional )
615
+ ParameterDataObject .__init__ (self , name , description , optional )
619
616
self .value = None
620
617
self .exported = None
621
618
@@ -685,11 +682,10 @@ class ParameterTableField(Parameter):
685
682
686
683
def __init__ (self , name = '' , description = '' , parent = None , datatype = - 1 ,
687
684
optional = False ):
688
- Parameter .__init__ (self , name , description )
685
+ Parameter .__init__ (self , name , description , optional )
689
686
self .parent = parent
690
687
self .value = None
691
688
self .datatype = int (datatype )
692
- self .optional = parseBool (optional )
693
689
694
690
def getValueAsCommandLineParameter (self ):
695
691
return '"' + unicode (self .value ) + '"'
@@ -728,8 +724,7 @@ class ParameterVector(ParameterDataObject):
728
724
729
725
def __init__ (self , name = '' , description = '' , shapetype = [- 1 ],
730
726
optional = False ):
731
- ParameterDataObject .__init__ (self , name , description )
732
- self .optional = parseBool (optional )
727
+ ParameterDataObject .__init__ (self , name , description , optional )
733
728
if isinstance (shapetype , int ):
734
729
shapetype = [shapetype ]
735
730
elif isinstance (shapetype , basestring ):
@@ -818,12 +813,11 @@ class ParameterGeometryPredicate(Parameter):
818
813
819
814
def __init__ (self , name = '' , description = '' , left = None , right = None ,
820
815
optional = False , enabledPredicates = None ):
821
- Parameter .__init__ (self , name , description )
816
+ Parameter .__init__ (self , name , description , optional )
822
817
self .left = left
823
818
self .right = right
824
819
self .value = None
825
820
self .default = []
826
- self .optional = parseBool (optional )
827
821
self .enabledPredicates = enabledPredicates
828
822
if self .enabledPredicates is None :
829
823
self .enabledPredicates = self .predicates
0 commit comments