def test_OTBParameterChoice_Gui(self): """ This test is similar to GuiTests in processing that is done on other parameter widget in processing Main difference is this test uses create_wrapper_from_metadata() rather than create_wrapper_from_class() like rest of processing widgets. """ param = OtbParameterChoice('test') alg = QgsApplication.processingRegistry().createAlgorithmById('otb:Smoothing') # algorithm dialog dlg = AlgorithmDialog(alg) wrapper = WidgetWrapperFactory.create_wrapper_from_metadata(param, dlg) self.assertIsNotNone(wrapper) self.assertIsInstance(wrapper, OtbChoiceWidgetWrapper) self.assertEqual(wrapper.dialog, dlg) self.assertIsNotNone(wrapper.widget) alg = QgsApplication.processingRegistry().createAlgorithmById('otb:Smoothing') # batch dialog dlg = BatchAlgorithmDialog(alg) wrapper = WidgetWrapperFactory.create_wrapper_from_metadata(param, dlg) self.assertIsNotNone(wrapper) self.assertIsInstance(wrapper, OtbChoiceWidgetWrapper) self.assertEqual(wrapper.dialog, dlg) self.assertIsNotNone(wrapper.widget) alg = QgsApplication.processingRegistry().createAlgorithmById('otb:Smoothing') # modeler dialog model = QgsProcessingModelAlgorithm() dlg = ModelerParametersDialog(alg, model) wrapper = WidgetWrapperFactory.create_wrapper_from_metadata(param, dlg) self.assertIsNotNone(wrapper) self.assertIsInstance(wrapper, OtbChoiceWidgetWrapper) self.assertEqual(wrapper.dialog, dlg) self.assertIsNotNone(wrapper.widget)
def defineCharacteristicsFromFile(self): line = None try: with open(self._descriptionfile) as lines: line = lines.readline().strip('\n').strip() self._name = line.split('|')[0] self.appkey = self._name line = lines.readline().strip('\n').strip() self.doc = line self.i18n_doc = QCoreApplication.translate("OtbAlgorithm", self.doc) #self._name = self._name #+ " - " + self.doc self._display_name = self.tr(self._name) self.i18n_name = QCoreApplication.translate("OtbAlgorithm", self._name) line = lines.readline().strip('\n').strip() self._group = line self.i18n_group = QCoreApplication.translate("OtbAlgorithm", self._group) line = lines.readline().strip('\n').strip() while line != '': line = line.strip('\n').strip() if line.startswith('#'): line = lines.readline().strip('\n').strip() continue param = None if 'OTBParameterChoice' in line: tokens = line.split("|") params = [t if str(t) != str(None) else None for t in tokens[1:]] options = params[2].split(';') param = OtbParameterChoice(params[0], params[1], options, params[3], params[4]) else: param = getParameterFromString(line, 'OtbAlgorithm') #if parameter is None, then move to next line and continue if param is None: line = lines.readline().strip('\n').strip() continue name = param.name() if '.' in name and len(name.split('.')) > 2: p = name.split('.')[:-2] group_key = '.'.join(p) group_value = name.split('.')[-2] metadata = param.metadata() metadata['group_key'] = group_key metadata['group_value'] = group_value param.setMetadata(metadata) #'elev.dem.path', 'elev.dem', 'elev.dem.geoid', 'elev.geoid' are special! #Even though it is not typical for OTB to fix on parameter keys, #we current use below !hack! to set SRTM path and GEOID files #Future releases of OTB must follow this rule keep #compatibility or update this checklist. if name in ["elev.dem.path", "elev.dem"]: param.setDefaultValue(OtbUtils.srtmFolder()) if name in ["elev.dem.geoid", "elev.geoid"]: param.setDefaultValue(OtbUtils.geoidFile()) # outputpixeltype is a special parameter associated with raster output # reset list of options to 'self.pixelTypes'. if name == 'outputpixeltype': param.setOptions(self.pixelTypes) param.setDefaultValue(self.pixelTypes.index('float')) self.addParameter(param) #parameter is added now and we must move to next line line = lines.readline().strip('\n').strip() except BaseException as e: import traceback errmsg = "Could not open OTB algorithm from file: \n" + self._descriptionfile + "\nline=" + line + "\nError:\n" + traceback.format_exc() QgsMessageLog.logMessage(self.tr(errmsg), self.tr('Processing'), Qgis.Critical) raise e