def test_init(self): string_parameter = StringParameter('28082014') string_parameter.name = 'Province Name' string_parameter.help_text = 'Name of province.' string_parameter.description = ( 'A <b>test _description</b> that is very long so that you need to ' 'read it for one minute and you will be tired after read this ' 'description. You are the best user so far. Even better if you ' 'read this description loudly so that all of your friends will ' 'be able to hear you') string_parameter.is_required = True string_parameter.value = 'Daerah Istimewa Yogyakarta' widget = StringParameterWidget(string_parameter) expected_value = string_parameter.name real_value = widget._label.text() message = 'Expected %s get %s' % (expected_value, real_value) self.assertEqual(expected_value, real_value, message) expected_value = string_parameter.value real_value = widget._line_edit_input.text() message = 'Expected %s get %s' % (expected_value, real_value) self.assertEqual(expected_value, real_value, message) # change value widget._line_edit_input.setText('Nusa Tenggara Barat') expected_value = 'Nusa Tenggara Barat' real_value = widget._line_edit_input.text() message = 'Expected %s get %s' % (expected_value, real_value) self.assertEqual(expected_value, real_value, message)
def target_field(): """Generator for the flooded target field parameter.""" field = StringParameter() field.name = 'Target Field' field.is_required = True field.help_text = ( 'This field of impact layer marks inundated roads by \'1\' value') field.description = ( 'This field of impact layer marks inundated roads by \'1\' value. ' 'This is the longer description of this parameter.') field.value = 'INUNDATED' # default value return field
def affected_value(): """Generator for parameter stating what values constitute 'affected'.""" field = StringParameter() field.name = 'Affected Value' field.is_required = True field.help_text = ( 'This value in \'affected_field\' of the hazard layer marks the areas ' 'as inundated') field.description = ( 'This value in \'affected_field\' of the hazard layer marks the areas ' 'as inundated. This is the longer description of this parameter.') field.value = '1' # default value return field
def affected_field(): """"Generator for selection of affected field parameter.""" field = StringParameter() field.name = 'Affected Field' field.is_required = True field.help_text = ( 'This field of the hazard layer contains information about inundated ' 'areas') field.description = ( 'This field of the hazard layer contains information about inundated ' 'areas. This is the longer description of this parameter.') field.value = 'affected' # default value return field
def test_boolean(self): """Test a bool parameter works properly. ..versionadded:: 2.2 """ parameter = StringParameter('1231231') parameter.name = 'String parameter' parameter.help_text = 'A string parameter' parameter.description = 'A test description' parameter.is_required = True parameter.value = 'Yogyakarta' self.assertEqual('Yogyakarta', parameter.value) with self.assertRaises(TypeError): parameter.value = 1
def set_up_resource_parameters(self): """Set up the resource parameter for the add/edit view. """ name_parameter = StringParameter('UUID-1') name_parameter.name = tr('Resource name') name_parameter.help_text = tr( 'Name of the resource that will be provided ' 'as part of minimum needs. ' 'e.g. Rice, Water etc.') name_parameter.description = tr( 'A <b>resource</b> is something that you provide to displaced ' 'persons in the event of a disaster. The resource will be made ' 'available at IDP camps and may need to be stockpiled by ' 'contingency planners in their preparations for a disaster.') name_parameter.is_required = True name_parameter.value = '' description_parameter = StringParameter('UUID-2') description_parameter.name = tr('Resource description') description_parameter.help_text = tr( 'Description of the resource that will be provided as part of ' 'minimum needs.') description_parameter.description = tr( 'This gives a detailed description of what the resource is and ') description_parameter.is_required = True description_parameter.value = '' unit_parameter = StringParameter('UUID-3') unit_parameter.name = tr('Unit') unit_parameter.help_text = tr( 'Single unit for the resources spelled out. e.g. litre, ' 'kilogram etc.') unit_parameter.description = tr( 'A <b>unit</b> is the basic measurement unit used for computing ' 'the allowance per individual. For example when planning water ' 'rations the unit would be single litre.') unit_parameter.is_required = True unit_parameter.value = '' units_parameter = StringParameter('UUID-4') units_parameter.name = tr('Units') units_parameter.help_text = tr( 'Multiple units for the resources spelled out. e.g. litres, ' 'kilogram etc.') units_parameter.description = tr( '<b>Units</b> are the basic measurement used for computing the ' 'allowance per individual. For example when planning water ' 'rations the units would be litres.') units_parameter.is_required = True units_parameter.value = '' unit_abbreviation_parameter = StringParameter('UUID-5') unit_abbreviation_parameter.name = tr('Unit abbreviation') unit_abbreviation_parameter.help_text = tr( 'Abbreviations of unit for the resources. e.g. l, kg etc.') unit_abbreviation_parameter.description = tr( "A <b>unti abbreviation</b> is the basic measurement unit's " "shortened. For example when planning water rations " "the units would be l.") unit_abbreviation_parameter.is_required = True unit_abbreviation_parameter.value = '' minimum_parameter = FloatParameter('UUID-6') minimum_parameter.name = tr('Minimum allowed') minimum_parameter.is_required = True minimum_parameter.precision = 2 minimum_parameter.minimum_allowed_value = -99999.0 minimum_parameter.maximum_allowed_value = 99999.0 minimum_parameter.help_text = tr( 'The minimum allowable quantity per person. ') minimum_parameter.description = tr( 'The <b>minimum</b> is the minimum allowed quantity of the ' 'resource per person. For example you may dictate that the water ' 'ration per person per day should never be allowed to be less ' 'than 0.5l. This is enforced when tweaking a minimum needs set ' 'before an impact evaluation') minimum_parameter.value = 0.00 maximum_parameter = FloatParameter('UUID-7') maximum_parameter.name = tr('Maximum allowed') maximum_parameter.is_required = True maximum_parameter.precision = 2 maximum_parameter.minimum_allowed_value = -99999.0 maximum_parameter.maximum_allowed_value = 99999.0 maximum_parameter.help_text = tr( 'The maximum allowable quantity per person. ') maximum_parameter.description = tr( 'The <b>maximum</b> is the maximum allowed quantity of the ' 'resource per person. For example you may dictate that the water ' 'ration per person per day should never be allowed to be more ' 'than 50l. This is enforced when tweaking a minimum needs set ' 'before an impact evaluation.') maximum_parameter.value = 100.0 default_parameter = FloatParameter('UUID-8') default_parameter.name = tr('Default') default_parameter.is_required = True default_parameter.precision = 2 default_parameter.minimum_allowed_value = -99999.0 default_parameter.maximum_allowed_value = 99999.0 default_parameter.help_text = tr( 'The default allowable quantity per person. ') default_parameter.description = tr( "The <b>default</b> is the default allowed quantity of the " "resource per person. For example you may indicate that the water " "ration per person weekly should be 67l.") default_parameter.value = 10.0 frequency_parameter = StringParameter('UUID-9') frequency_parameter.name = tr('Frequency') frequency_parameter.help_text = tr( "The frequency that this resource needs to be provided to a " "displaced person. e.g. weekly, daily, once etc.") frequency_parameter.description = tr( "The <b>frequency</b> informs the aid worker how regularly this " "resource needs to be provided to the displaced person.") frequency_parameter.is_required = True frequency_parameter.value = tr('weekly') sentence_parameter = TextParameter('UUID-10') sentence_parameter.name = tr('Readable sentence') sentence_parameter.help_text = tr( 'A readable presentation of the resource.') sentence_parameter.description = tr( "A <b>readable sentence</b> is a presentation of the resource " "that displays all pertinent information. If you are unsure then " "use the default. Properties should be included using double " "curly brackets '{{' '}}'. Including the resource name would be " "achieved by including e.g. {{ Resource name }}") sentence_parameter.is_required = True sentence_parameter.value = tr( "A displaced person should be provided with " "{{ Default }} {{ Unit }}/{{ Units }}/{{ Unit abbreviation }} of " "{{ Resource name }}. Though no less than {{ Minimum allowed }} " "and no more than {{ Maximum allowed }}. This should be provided " "{{ Frequency }}.") parameters = [ name_parameter, description_parameter, unit_parameter, units_parameter, unit_abbreviation_parameter, default_parameter, minimum_parameter, maximum_parameter, frequency_parameter, sentence_parameter ] parameter_container = ParameterContainer(parameters) parameter_container.setup_ui() layout = QGridLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addWidget(parameter_container) self.parameters_scrollarea.setLayout(layout)
def set_up_resource_parameters(self): """Set up the resource parameter for the add/edit view. """ name_parameter = StringParameter('UUID-1') name_parameter.name = 'Resource name' name_parameter.help_text = ( 'Name of the resource that will be provided ' 'as part of minimum needs. ' 'e.g. Rice, Water etc.') name_parameter.description = ( 'A <b>resource</b> is something that you provide to displaced ' 'persons in the event of a disaster. The resource will be made ' 'available at IDP camps and may need to be stockpiled by ' 'contingency planners in their preparations for a disaster.') name_parameter.is_required = True name_parameter.value = '' description_parameter = StringParameter('UUID-2') description_parameter.name = 'Resource description' description_parameter.help_text = ( 'Description of the resource that will be provided as part of ' 'minimum needs.') description_parameter.description = ( 'This gives a detailed description of what the resource is and ') description_parameter.is_required = True description_parameter.value = '' unit_parameter = StringParameter('UUID-3') unit_parameter.name = 'Unit' unit_parameter.help_text = ( 'Single unit for the resources spelled out. e.g. litre, ' 'kilogram etc.') unit_parameter.description = ( 'A <b>unit</b> is the basic measurement unit used for computing ' 'the allowance per individual. For example when planning water ' 'rations the unit would be single litre.') unit_parameter.is_required = True unit_parameter.value = '' units_parameter = StringParameter('UUID-4') units_parameter.name = 'Units' units_parameter.help_text = ( 'Multiple units for the resources spelled out. e.g. litres, ' 'kilogram etc.') units_parameter.description = ( '<b>Units</b> are the basic measurement used for computing the ' 'allowance per individual. For example when planning water ' 'rations the units would be litres.') units_parameter.is_required = True units_parameter.value = '' unit_abbreviation_parameter = StringParameter('UUID-5') unit_abbreviation_parameter.name = 'Unit abbreviation' unit_abbreviation_parameter.help_text = ( 'Abbreviations of unit for the resources. e.g. l, kg etc.') unit_abbreviation_parameter.description = ( "A <b>unti abbreviation</b> is the basic measurement unit's " "shortened. For example when planning water rations " "the units would be l.") unit_abbreviation_parameter.is_required = True unit_abbreviation_parameter.value = '' minimum_parameter = FloatParameter('UUID-6') minimum_parameter.name = 'Minimum allowed' minimum_parameter.is_required = True minimum_parameter.precision = 2 minimum_parameter.minimum_allowed_value = -99999.0 minimum_parameter.maximum_allowed_value = 99999.0 minimum_parameter.help_text = ( 'The minimum allowable quantity per person. ') minimum_parameter.description = ( 'The <b>minimum</b> is the minimum allowed quantity of the ' 'resource per person. For example you may dictate that the water ' 'ration per person per day should never be allowed to be less ' 'than 0.5l. This is enforced when tweaking a minimum needs set ' 'before an impact evaluation') minimum_parameter.value = 0.00 maximum_parameter = FloatParameter('UUID-7') maximum_parameter.name = 'Maximum allowed' maximum_parameter.is_required = True maximum_parameter.precision = 2 maximum_parameter.minimum_allowed_value = -99999.0 maximum_parameter.maximum_allowed_value = 99999.0 maximum_parameter.help_text = ( 'The maximum allowable quantity per person. ') maximum_parameter.description = ( 'The <b>maximum</b> is the maximum allowed quantity of the ' 'resource per person. For example you may dictate that the water ' 'ration per person per day should never be allowed to be more ' 'than 50l. This is enforced when tweaking a minimum needs set ' 'before an impact evaluation.') maximum_parameter.value = 100.0 default_parameter = FloatParameter('UUID-8') default_parameter.name = 'Default' default_parameter.is_required = True default_parameter.precision = 2 default_parameter.minimum_allowed_value = -99999.0 default_parameter.maximum_allowed_value = 99999.0 default_parameter.help_text = ( 'The default allowable quantity per person. ') default_parameter.description = ( "The <b>default</b> is the default allowed quantity of the " "resource per person. For example you may indicate that the water " "ration per person weekly should be 67l.") default_parameter.value = 10.0 frequency_parameter = StringParameter('UUID-9') frequency_parameter.name = 'Frequency' frequency_parameter.help_text = ( "The frequency that this resource needs to be provided to a " "displaced person. e.g. weekly, daily, once etc.") frequency_parameter.description = ( "The <b>frequency</b> informs the aid worker how regularly this " "resource needs to be provided to the displaced person.") frequency_parameter.is_required = True frequency_parameter.value = 'weekly' sentence_parameter = StringParameter('UUID-10') sentence_parameter.name = 'Readable sentence' sentence_parameter.help_text = ( 'A readable presentation of the resource.') sentence_parameter.description = ( "A <b>readable sentence</b> is a presentation of the resource " "that displays all pertinent information. If you are unsure then " "use the default. Properties should be included using double " "curly brackets '{{' '}}'. Including the resource name would be " "achieved by including e.g. {{ Resource name }}") sentence_parameter.is_required = True sentence_parameter.value = ( "A displaced person should be provided with " "{{ Default }} {{ Unit }}/{{ Units }}/{{ Unit abbreviation }} of " "{{ Resource name }}. Though no less than {{ Minimum allowed }} " "and no more than {{ Maximum allowed }}. This should be provided " "{{ Frequency }}.") parameters = [ name_parameter, description_parameter, unit_parameter, units_parameter, unit_abbreviation_parameter, default_parameter, minimum_parameter, maximum_parameter, frequency_parameter, sentence_parameter ] parameter_container = ParameterContainer(parameters) layout = QGridLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addWidget(parameter_container) self.resource_widget.setLayout(layout)