Exemplo n.º 1
0
 def testSet2DListValue(self):
     table = [
         ['a0', 'a1', 'a2'],
         ['b0', 'b1', 'b2']
     ]
     parameter = ParameterFixedTable('myName', 'myDesc')
     self.assertTrue(parameter.setValue(table))
     self.assertEqual(parameter.value, 'a0,a1,a2,b0,b1,b2')
Exemplo n.º 2
0
 def testSet2DListValue(self):
     table = [
         ['a0', 'a1', 'a2'],
         ['b0', 'b1', 'b2']
     ]
     parameter = ParameterFixedTable('myName', 'myDesc')
     self.assertTrue(parameter.setValue(table))
     self.assertEqual(parameter.value, 'a0,a1,a2,b0,b1,b2')
Exemplo n.º 3
0
    def testTableToString(self):
        table = [["a0", "a1", "a2"], ["b0", "b1", "b2"]]
        self.assertEqual(ParameterFixedTable.tableToString(table), "a0,a1,a2,b0,b1,b2")

        table = [["a0"]]
        self.assertEqual(ParameterFixedTable.tableToString(table), "a0")

        table = [[]]
        self.assertEqual(ParameterFixedTable.tableToString(table), "")
Exemplo n.º 4
0
    def testTableToString(self):
        table = [['a0', 'a1', 'a2'], ['b0', 'b1', 'b2']]
        self.assertEqual(ParameterFixedTable.tableToString(table),
                         'a0,a1,a2,b0,b1,b2')

        table = [['a0']]
        self.assertEqual(ParameterFixedTable.tableToString(table), 'a0')

        table = [[]]
        self.assertEqual(ParameterFixedTable.tableToString(table), '')
Exemplo n.º 5
0
    def testTableToString(self):
        table = [
            ['a0', 'a1', 'a2'],
            ['b0', 'b1', 'b2']
        ]
        self.assertEqual(ParameterFixedTable.tableToString(table), 'a0,a1,a2,b0,b1,b2')

        table = [['a0']]
        self.assertEqual(ParameterFixedTable.tableToString(table), 'a0')

        table = [[]]
        self.assertEqual(ParameterFixedTable.tableToString(table), '')
Exemplo n.º 6
0
 def setParamValue(self, alg, param, widget):
     if isinstance(param,
                   (ParameterRaster, ParameterVector, ParameterTable)):
         return self.setParamValueLayerOrTable(alg, param, widget)
     elif isinstance(param, ParameterBoolean):
         if widget.currentIndex() < 2:
             value = widget.currentIndex() == 0
         else:
             value = widget.itemData(widget.currentIndex())
         alg.params[param.name] = value
         return True
     elif isinstance(param, ParameterString):
         return self.setParamStringValue(alg, param, widget)
     elif isinstance(param, ParameterNumber):
         return self.setParamNumberValue(alg, param, widget)
     elif isinstance(param, ParameterExtent):
         return self.setParamExtentValue(alg, param, widget)
     elif isinstance(param, ParameterPoint):
         return self.setParamPointValue(alg, param, widget)
     elif isinstance(param, ParameterFile):
         return self.setParamFileValue(alg, param, widget)
     elif isinstance(param, ParameterSelection):
         alg.params[param.name] = widget.currentIndex()
         return True
     elif isinstance(param, ParameterRange):
         alg.params[param.name] = widget.getValue()
         return True
     elif isinstance(param, ParameterCrs):
         authid = widget.getValue()
         if authid is None and not param.optional:
             return False
         alg.params[param.name] = authid
         return True
     elif isinstance(param, ParameterFixedTable):
         table = widget.table
         if not bool(table) and not param.optional:
             return False
         alg.params[param.name] = ParameterFixedTable.tableToString(table)
         return True
     elif isinstance(param,
                     (ParameterTableField, ParameterTableMultipleField)):
         return self.setParamTableFieldValue(alg, param, widget)
     elif isinstance(param, ParameterMultipleInput):
         if param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
             options = self.getAvailableValuesOfType(
                 ParameterVector, OutputVector)
         else:
             options = self.getAvailableValuesOfType(
                 ParameterRaster, OutputRaster)
         values = [options[i] for i in widget.selectedoptions]
         if len(values) == 0 and not param.optional:
             return False
         alg.params[param.name] = values
         return True
     elif isinstance(param, ParameterGeometryPredicate):
         alg.params[param.name] = widget.value()
         return True
     else:
         alg.params[param.name] = unicode(widget.text())
         return True
Exemplo n.º 7
0
 def value(self):
     if self.dialogType == DIALOG_MODELER:
         table = self.widget.table
         if not bool(table) and not self.param.optional:
             raise InvalidParameterValue()
         return ParameterFixedTable.tableToString(table)
     else:
         return self.widget.table
Exemplo n.º 8
0
 def value(self):
     if self.dialogType == DIALOG_MODELER:
         table = self.widget.table
         if not bool(table) and not self.param.optional:
             raise InvalidParameterValue()
         return ParameterFixedTable.tableToString(table)
     else:
         return self.widget.table
 def setParamValue(self, alg, param, widget):
     if isinstance(param, (ParameterRaster, ParameterVector,
                           ParameterTable)):
         return self.setParamValueLayerOrTable(alg, param, widget)
     elif isinstance(param, ParameterBoolean):
         if widget.currentIndex() < 2:
             value = widget.currentIndex() == 0
         else:
             value = widget.itemData(widget.currentIndex())
         alg.params[param.name] = value
         return True
     elif isinstance(param, ParameterString):
         return self.setParamStringValue(alg, param, widget)
     elif isinstance(param, ParameterNumber):
         return self.setParamNumberValue(alg, param, widget)
     elif isinstance(param, ParameterExtent):
         return self.setParamExtentValue(alg, param, widget)
     elif isinstance(param, ParameterPoint):
         return self.setParamPointValue(alg, param, widget)
     elif isinstance(param, ParameterFile):
         return self.setParamFileValue(alg, param, widget)
     elif isinstance(param, ParameterSelection):
         alg.params[param.name] = widget.currentIndex()
         return True
     elif isinstance(param, ParameterRange):
         alg.params[param.name] = widget.getValue()
         return True
     elif isinstance(param, ParameterCrs):
         authid = widget.getValue()
         if authid is None and not param.optional:
             return False
         alg.params[param.name] = authid
         return True
     elif isinstance(param, ParameterFixedTable):
         table = widget.table
         if not bool(table) and not param.optional:
             return False
         alg.params[param.name] = ParameterFixedTable.tableToString(table)
         return True
     elif isinstance(param, (ParameterTableField,
                             ParameterTableMultipleField)):
         return self.setParamTableFieldValue(alg, param, widget)
     elif isinstance(param, ParameterMultipleInput):
         if param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
             options = self.getAvailableValuesOfType(ParameterVector, OutputVector)
         else:
             options = self.getAvailableValuesOfType(ParameterRaster, OutputRaster)
         values = [options[i] for i in widget.selectedoptions]
         if len(values) == 0 and not param.optional:
             return False
         alg.params[param.name] = values
         return True
     elif isinstance(param, ParameterGeometryPredicate):
         alg.params[param.name] = widget.value()
         return True
     else:
         alg.params[param.name] = unicode(widget.text())
         return True
Exemplo n.º 10
0
    def testOptional(self):
        parameter = ParameterFixedTable('myName', 'myDesc', optional=True)
        self.assertTrue(parameter.setValue('1,2,3'))
        self.assertEqual(parameter.value, '1,2,3')

        self.assertTrue(parameter.setValue(None))
        self.assertEqual(parameter.value, None)

        parameter = ParameterFixedTable('myName', 'myDesc', optional=False)
        self.assertFalse(parameter.setValue(None))
        self.assertEqual(parameter.value, None)

        self.assertTrue(parameter.setValue('1,2,3'))
        self.assertEqual(parameter.value, '1,2,3')

        self.assertFalse(parameter.setValue(None))
        self.assertEqual(parameter.value, '1,2,3')
Exemplo n.º 11
0
    def testOptional(self):
        parameter = ParameterFixedTable("myName", "myDesc", optional=True)
        self.assertTrue(parameter.setValue("1,2,3"))
        self.assertEqual(parameter.value, "1,2,3")

        self.assertTrue(parameter.setValue(None))
        self.assertEqual(parameter.value, None)

        parameter = ParameterFixedTable("myName", "myDesc", optional=False)
        self.assertFalse(parameter.setValue(None))
        self.assertEqual(parameter.value, None)

        self.assertTrue(parameter.setValue("1,2,3"))
        self.assertEqual(parameter.value, "1,2,3")

        self.assertFalse(parameter.setValue(None))
        self.assertEqual(parameter.value, "1,2,3")
Exemplo n.º 12
0
    def testOptional(self):
        parameter = ParameterFixedTable('myName', 'myDesc', optional=True)
        self.assertTrue(parameter.setValue('1,2,3'))
        self.assertEqual(parameter.value, '1,2,3')

        self.assertTrue(parameter.setValue(None))
        self.assertEqual(parameter.value, None)

        parameter = ParameterFixedTable('myName', 'myDesc', optional=False)
        self.assertFalse(parameter.setValue(None))
        self.assertEqual(parameter.value, None)

        self.assertTrue(parameter.setValue('1,2,3'))
        self.assertEqual(parameter.value, '1,2,3')

        self.assertFalse(parameter.setValue(None))
        self.assertEqual(parameter.value, '1,2,3')
Exemplo n.º 13
0
 def testSetStringValue(self):
     parameter = ParameterFixedTable('myName', 'myDesc')
     self.assertTrue(parameter.setValue('1,2,3'))
     self.assertEqual(parameter.value, '1,2,3')
Exemplo n.º 14
0
 def testSet2DListValue(self):
     table = [["a0", "a1", "a2"], ["b0", "b1", "b2"]]
     parameter = ParameterFixedTable("myName", "myDesc")
     self.assertTrue(parameter.setValue(table))
     self.assertEqual(parameter.value, "a0,a1,a2,b0,b1,b2")
Exemplo n.º 15
0
 def testSetStringValue(self):
     parameter = ParameterFixedTable("myName", "myDesc")
     self.assertTrue(parameter.setValue("1,2,3"))
     self.assertEqual(parameter.value, "1,2,3")
Exemplo n.º 16
0
 def testSetStringValue(self):
     parameter = ParameterFixedTable('myName', 'myDesc')
     self.assertTrue(parameter.setValue('1,2,3'))
     self.assertEqual(parameter.value, '1,2,3')