def test_build_form_minimum_needs(self):
        """Test that we can build a form by passing it params.
        """
        dialog = FunctionOptionsDialog()

        # Define threshold
        threshold = InputListParameter()
        threshold.name = 'Thresholds [m]'
        threshold.is_required = True
        threshold.element_type = float
        threshold.expected_type = list
        threshold.ordering = InputListParameter.AscendingOrder
        threshold.minimum_item_count = 1
        threshold.maximum_item_count = 3
        threshold.value = [1.0]  # default value

        parameters = {
            'thresholds': threshold,
            'postprocessors': OrderedDict([
                ('Gender', default_gender_postprocessor()),
                ('Age', age_postprocessor()),
                ('MinimumNeeds', minimum_needs_selector()),
                ])
        }

        dialog.build_form(parameters)

        assert dialog.tabWidget.count() == 2

        children = dialog.tabWidget.findChildren(QLineEdit)
        assert len(children) == 4
예제 #2
0
    def test_build_form_minimum_needs(self):
        """Test that we can build a form by passing it params.
        """
        dialog = FunctionOptionsDialog()

        # Define threshold
        threshold = InputListParameter()
        threshold.name = 'Thresholds [m]'
        threshold.is_required = True
        threshold.element_type = float
        threshold.expected_type = list
        threshold.ordering = InputListParameter.AscendingOrder
        threshold.minimum_item_count = 1
        threshold.maximum_item_count = 3
        threshold.value = [1.0]  # default value

        parameters = {
            'thresholds':
            threshold,
            'postprocessors':
            OrderedDict([
                ('Gender', default_gender_postprocessor()),
                ('Age', age_postprocessor()),
                ('MinimumNeeds', minimum_needs_selector()),
            ])
        }

        dialog.build_form(parameters)

        assert dialog.tabWidget.count() == 2

        children = dialog.tabWidget.findChildren(QLineEdit)
        assert len(children) == 4
예제 #3
0
class StepFcParams(WizardStep, FORM_CLASS):
    """Function Centric Wizard Step: Parameters"""
    def __init__(self, parent=None):
        """Constructor for the tab.

        :param parent: parent - widget to use as parent (Wizad Dialog).
        :type parent: QWidget

        """
        WizardStep.__init__(self, parent)
        self.parameter_dialog = None
        self.twParams = None

    def is_ready_to_next_step(self):
        """Check if the step is complete. If so, there is
            no reason to block the Next button.

        :returns: True if new step may be enabled.
        :rtype: bool
        """
        return True

    def get_next_step(self):
        """Find the proper step when user clicks the Next button.

        :returns: The step to be switched to
        :rtype: WizardStep instance or None
        """
        new_step = self.parent.step_fc_summary
        return new_step

    def set_widgets(self):
        """Set widgets on the Params tab"""

        # TODO Put the params to metadata! Now we need to import the IF class.
        # Notes: Why don't we store impact_function to class attribute?
        impact_function_id = self.parent.\
            step_fc_function.selected_function()['id']
        impact_function = self.impact_function_manager.get(impact_function_id)
        if not impact_function:
            return
        if_params = None
        if hasattr(impact_function, 'parameters'):
            if_params = impact_function.parameters

        text = self.tr(
            'Please set impact functions parameters.<br/>Parameters for '
            'impact function "%s" that can be modified are:' %
            impact_function_id)
        self.lblSelectIFParameters.setText(text)

        self.parameter_dialog = FunctionOptionsDialog(self)
        self.parameter_dialog.set_dialog_info(impact_function_id)
        self.parameter_dialog.build_form(if_params)

        if self.twParams:
            self.twParams.hide()

        self.twParams = self.parameter_dialog.tabWidget
        self.layoutIFParams.addWidget(self.twParams)
예제 #4
0
    def test_build_form(self):
        """Test that we can build a form by passing params.
        """

        dialog = FunctionOptionsDialog()

        # Define rice for minimum needs
        rice = ResourceParameter()
        rice.value = 2.8
        rice.frequency = 'weekly'
        rice.minimum_allowed_value = 1.4
        rice.maximum_allowed_value = 5.6
        rice.name = 'Rice'
        rice.unit.abbreviation = 'kg'
        rice.unit.name = 'kilogram'
        rice.unit.plural = 'kilograms'

        # Define threshold
        threshold = InputListParameter()
        threshold.name = 'Thresholds [m]'
        threshold.is_required = True
        threshold.element_type = float
        threshold.expected_type = list
        threshold.ordering = InputListParameter.AscendingOrder
        threshold.minimum_item_count = 1
        threshold.maximum_item_count = 3
        threshold.value = [1.0]  # default value

        parameter = {
            'thresholds':
            threshold,
            'postprocessors':
            OrderedDict([
                ('Gender', default_gender_postprocessor()),
                ('Age', age_postprocessor()),
                ('MinimumNeeds', minimum_needs_selector()),
            ]),
            'minimum needs': [rice]
        }

        dialog.build_form(parameter)

        message = 'There should be %s tabwidget but got %s' % (
            3, dialog.tabWidget.count())
        self.assertEqual(dialog.tabWidget.count(), 3, message)

        children = dialog.tabWidget.findChildren(QLineEdit)
        message = 'There should be %s QLineEdit but got %s' % (5,
                                                               len(children))
        self.assertEqual(len(children), 5, message)
    def test_build_form(self):
        """Test that we can build a form by passing params.
        """

        dialog = FunctionOptionsDialog()

        # Define rice for minimum needs
        rice = ResourceParameter()
        rice.value = 2.8
        rice.frequency = 'weekly'
        rice.minimum_allowed_value = 1.4
        rice.maximum_allowed_value = 5.6
        rice.name = 'Rice'
        rice.unit.abbreviation = 'kg'
        rice.unit.name = 'kilogram'
        rice.unit.plural = 'kilograms'

        # Define threshold
        threshold = InputListParameter()
        threshold.name = 'Thresholds [m]'
        threshold.is_required = True
        threshold.element_type = float
        threshold.expected_type = list
        threshold.ordering = InputListParameter.AscendingOrder
        threshold.minimum_item_count = 1
        threshold.maximum_item_count = 3
        threshold.value = [1.0]  # default value

        parameter = {
            'thresholds': threshold,
            'postprocessors': OrderedDict([
                ('Gender', default_gender_postprocessor()),
                ('Age', age_postprocessor()),
                ('MinimumNeeds', minimum_needs_selector()),
                ]),
            'minimum needs': [rice]
        }

        dialog.build_form(parameter)

        message = 'There should be %s tabwidget but got %s' % (
            3, dialog.tabWidget.count())
        self.assertEqual(dialog.tabWidget.count(), 3, message)

        children = dialog.tabWidget.findChildren(QLineEdit)
        message = 'There should be %s QLineEdit but got %s' % (
            5, len(children))
        self.assertEqual(len(children), 5, message)
예제 #6
0
class StepFcParams(WizardStep, FORM_CLASS):
    """Function Centric Wizard Step: Parameters"""

    def __init__(self, parent=None):
        """Constructor for the tab.

        :param parent: parent - widget to use as parent (Wizad Dialog).
        :type parent: QWidget

        """
        WizardStep.__init__(self, parent)
        self.parameter_dialog = None
        self.twParams = None

    def is_ready_to_next_step(self):
        """Check if the step is complete. If so, there is
            no reason to block the Next button.

        :returns: True if new step may be enabled.
        :rtype: bool
        """
        return True

    def get_previous_step(self):
        """Find the proper step when user clicks the Previous button.

        :returns: The step to be switched to
        :rtype: WizardStep instance or None
        """
        new_step = self.parent.step_fc_extent
        return new_step

    def get_next_step(self):
        """Find the proper step when user clicks the Next button.

        :returns: The step to be switched to
        :rtype: WizardStep instance or None
        """
        new_step = self.parent.step_fc_summary
        return new_step

    def set_widgets(self):
        """Set widgets on the Params tab"""

        # TODO Put the params to metadata! Now we need to import the IF class.
        # Notes: Why don't we store impact_function to class attribute?
        impact_function_id = self.parent.\
            step_fc_function.selected_function()['id']
        impact_function = self.impact_function_manager.get(
            impact_function_id)
        if not impact_function:
            return
        if_params = None
        if hasattr(impact_function, 'parameters'):
            if_params = impact_function.parameters

        text = self.tr(
            'Please set impact functions parameters.<br/>Parameters for '
            'impact function "%s" that can be modified are:' %
            impact_function_id)
        self.lblSelectIFParameters.setText(text)

        self.parameter_dialog = FunctionOptionsDialog(self)
        self.parameter_dialog.set_dialog_info(impact_function_id)
        self.parameter_dialog.build_form(if_params)

        if self.twParams:
            self.twParams.hide()

        self.twParams = self.parameter_dialog.tabWidget
        self.layoutIFParams.addWidget(self.twParams)