def _createInputForWeights(self, layout): relative_iteration_weights_model = StringModel(self.getSimulationModel().getWeights()) self._relative_iteration_weights_box = StringBox(relative_iteration_weights_model, "Custom iteration weights", help_link="config/simulation/iteration_weights", continuous_update=True) self._relative_iteration_weights_box.setValidator(NumberListStringArgument()) layout.addRow("Relative Weights:", self._relative_iteration_weights_box) def updateModelWithRelativeWeights(): weights = relative_iteration_weights_model.getValue() self.getSimulationModel().setWeights(weights) relative_iteration_weights_model.observable().attach(StringModel.VALUE_CHANGED_EVENT, updateModelWithRelativeWeights) normalized_weights_model = StringModel() normalized_weights_model.setValue("") normalized_weights_widget = ActiveLabel(normalized_weights_model, help_link="config/simulation/iteration_weights") layout.addRow('Normalized weights:', normalized_weights_widget) def updateVisualizationOfNormalizedWeights(): if self._relative_iteration_weights_box.isValid(): weights = MultipleDataAssimilation.parseWeights(relative_iteration_weights_model.getValue()) normalized_weights = MultipleDataAssimilation.normalizeWeights(weights) normalized_weights_model.setValue(", ".join("%.2f" % x for x in normalized_weights)) else: normalized_weights_model.setValue("The weights are invalid!") self._relative_iteration_weights_box.validationChanged.connect(updateVisualizationOfNormalizedWeights) updateVisualizationOfNormalizedWeights() # To normalize the default weights