MCPcopy
hub / github.com/CadQuery/cadquery / InputParameter

Class InputParameter

cadquery/cqgi.py:226–321  ·  view source on GitHub ↗

Defines a parameter that can be supplied when the model is executed. Name, varType, and default_value are always available, because they are computed from a variable assignment line of code: The others are only available if the script has used define_parameter() to provide add

Source from the content-addressed store, hash-verified

224
225
226class InputParameter:
227 """
228 Defines a parameter that can be supplied when the model is executed.
229
230 Name, varType, and default_value are always available, because they are computed
231 from a variable assignment line of code:
232
233 The others are only available if the script has used define_parameter() to
234 provide additional metadata
235
236 """
237
238 def __init__(self):
239
240 #: the default value for the variable.
241 self.default_value = None
242
243 #: the name of the parameter.
244 self.name = None
245
246 #: type of the variable: BooleanParameter, StringParameter, NumericParameter
247 self.varType = None
248
249 #: help text describing the variable. Only available if the script used describe_parameter()
250 self.desc = None
251
252 #: valid values for the variable. Only available if the script used describe_parameter()
253 self.valid_values = []
254
255 self.ast_node = None
256
257 @staticmethod
258 def create(
259 ast_node, var_name, var_type, default_value, valid_values=None, desc=None
260 ):
261
262 if valid_values is None:
263 valid_values = []
264
265 p = InputParameter()
266 p.ast_node = ast_node
267 p.default_value = default_value
268 p.name = var_name
269 p.desc = desc
270 p.varType = var_type
271 p.valid_values = valid_values
272 return p
273
274 def set_value(self, new_value):
275 if len(self.valid_values) > 0 and new_value not in self.valid_values:
276 raise InvalidParameterError(
277 "Cannot set value '{0:s}' for parameter '{1:s}': not a valid value. Valid values are {2:s} ".format(
278 str(new_value), self.name, str(self.valid_values)
279 )
280 )
281
282 if self.varType == NumberParameterType:
283 try:

Callers 1

createMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected