本文整理汇总了Python中safe_extras.parameters.boolean_parameter.BooleanParameter类的典型用法代码示例。如果您正苦于以下问题:Python BooleanParameter类的具体用法?Python BooleanParameter怎么用?Python BooleanParameter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BooleanParameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: road_type_postprocessor
def road_type_postprocessor():
"""Get road-type parameter for postprocessing.
:return: A list of boolean parameter.
:rtype: list
"""
road_type = BooleanParameter()
road_type.name = tr('Road type')
road_type.value = True
road_type.description = tr(
'Check this option to enable reporting break down by road type.'
)
return [road_type]
示例2: default_gender_postprocessor
def default_gender_postprocessor():
"""Get gender postprocessor selector.
:return: A selector to activate gender postprocessor.
:rtype: list
"""
gender = BooleanParameter()
gender.name = 'Gender'
gender.value = True
gender.description = tr(
'Check this option if you wish to calculate the gender breakdown '
'on the affected population.'
)
return [gender]
示例3: default_gender_postprocessor
def default_gender_postprocessor():
"""Get gender postprocessor selector.
:return: A selector to activate gender postprocessor.
:rtype: list
"""
gender = BooleanParameter()
gender.name = "Gender"
gender.value = True
gender.help_text = tr("Gender ratio breakdown.")
gender.description = tr(
"Check this option if you wish to calculate a breakdown by gender " "for the affected population."
)
return [gender]
示例4: age_postprocessor
def age_postprocessor():
"""Get age postprocessor selectors.
:return: Selectors to activate age postprocessor.
:rtype: list
"""
age = BooleanParameter()
age.name = 'Age'
age.value = True
youth_ratio = FloatParameter()
youth_ratio.name = 'Youth ratio'
youth_ratio.value = get_defaults('YOUTH_RATIO')
youth_ratio.description = tr(
'Youth ratio defines what proportion of the population have not yet '
'achieved financial independence. The age threshold for youth can '
'vary by region - please consult with your local census bureau to find'
'out what the relevant threshold is in your region. InaSAFE does not '
'impose a particular age ratio scheme - it will break down the '
'population according to the thresholds you define for your locality.'
)
adult_ratio = FloatParameter()
adult_ratio.name = 'Adult ratio'
adult_ratio.value = get_defaults('ADULT_RATIO')
adult_ratio.description = tr(
'Adult ratio defines what proportion of the population have '
'passed into adulthood and are not yet aged. The age threshold for '
'adults can vary by region - please consult with your local census '
'bureau to find out what the relevant threshold is in your region. '
'InaSAFE does not impose a particular age ratio scheme - it will '
'break down the population according to the thresholds you define for '
'your locality.'
)
elderly_ratio = FloatParameter()
elderly_ratio.name = 'Elderly ratio'
elderly_ratio.value = get_defaults('ELDERLY_RATIO')
elderly_ratio.description = tr(
'Elderly ratio defines what proportion of the population have '
'passed from adulthood into their later life stage. The age '
'threshold for being considered elderly can vary by region - please '
'consult with your local census bureau to find out what the relevant '
'threshold is in your region. InaSAFE does not impose a particular '
'age ratio scheme - it will break down the population according to '
'the thresholds you define for your locality.'
)
return [age, youth_ratio, adult_ratio, elderly_ratio]
示例5: building_type_postprocessor
def building_type_postprocessor():
"""Get building-type parameter for postprocessing.
:return: A list of boolean parameter.
:rtype: list
"""
building_type = BooleanParameter()
building_type.name = tr('Building type')
building_type.value = True
building_type.description = tr(
'Check this option if you want to enable a building impact report'
'broken down by building type for each aggregation area.'
)
return [building_type]
示例6: minimum_needs_selector
def minimum_needs_selector():
"""Get minimum needs postprocessor selector.
:return: A selector to activate minimum needs postprocessor.
:rtype: list
"""
minimum_needs_flag = BooleanParameter()
minimum_needs_flag.name = 'MinimumNeeds'
minimum_needs_flag.value = True
minimum_needs_flag.description = tr(
'Check this option if you wish to calculate minimum needs for the '
'affected population. Minimum needs will be calculated according to '
'the defaults defined in the minimum needs configuration tool.'
)
return [minimum_needs_flag]
示例7: building_type_postprocessor
def building_type_postprocessor():
"""Get building-type parameter for postprocessing.
:return: Selectors to activate building breakdown postprocessor.
:rtype: list
"""
building_type = BooleanParameter()
building_type.name = tr("Building type")
building_type.value = True
building_type.description = tr(
"Check this option if you want to enable a building impact report "
"broken down by building type for each aggregation area."
)
return [building_type]
示例8: road_type_postprocessor
def road_type_postprocessor():
"""Get road-type parameter for postprocessing.
:return: A list of boolean parameter.
:rtype: list
"""
road_type = BooleanParameter()
road_type.name = tr("Road type")
road_type.value = True
road_type.help_text = tr("Road breakdown by type.")
road_type.description = tr(
"Check this option if you want to enable a road impact report broken " "down by road type."
)
return [road_type]
示例9: aggregation_categorical_postprocessor
def aggregation_categorical_postprocessor():
"""Get aggregation categorical postprocessor selectors.
:return: List of boolean parameter.
:rtype: list
"""
aggregation_categorical = BooleanParameter()
aggregation_categorical.name = tr('Aggregation categorical')
aggregation_categorical.value = True
aggregation_categorical.description = tr(
'Enable the aggregation by categories. For example if you have '
'roads classified by type, you will get a breakdown by type of roads'
'per aggregation area.'
)
return [aggregation_categorical]
示例10: minimum_needs_selector
def minimum_needs_selector():
"""Get minimum needs postprocessor selector.
:return: A selector to activate minimum needs postprocessor.
:rtype: list
"""
minimum_needs_flag = BooleanParameter()
minimum_needs_flag.name = "MinimumNeeds"
minimum_needs_flag.value = True
minimum_needs_flag.help_text = tr("Minimum needs breakdown.")
minimum_needs_flag.description = tr(
"Check this option if you wish to calculate minimum needs for the "
"affected population. Minimum needs will be calculated according to "
"the defaults defined in the minimum needs configuration tool."
)
return [minimum_needs_flag]
示例11: test_init
def test_init(self):
"""Test initialize qt4 parameter factory."""
boolean_parameter = BooleanParameter('1231231')
boolean_parameter.name = 'Boolean'
boolean_parameter.help_text = 'A boolean parameter'
boolean_parameter.description = 'A test _description'
boolean_parameter.is_required = True
boolean_parameter.value = True
float_parameter = FloatParameter()
float_parameter.name = 'Float Parameter'
float_parameter.is_required = True
float_parameter.precision = 3
float_parameter.minimum_allowed_value = 1.0
float_parameter.maximum_allowed_value = 2.0
float_parameter.help_text = 'Short help.'
float_parameter.description = 'Long description for parameter.'
float_parameter.unit = 'metres'
float_parameter.value = 1.1
parameters = [boolean_parameter, float_parameter]
qt4_parameter_factory = Qt4ParameterFactory()
widgets = []
widget_classes = []
for parameter in parameters:
widget = qt4_parameter_factory.get_widget(parameter)
widgets.append(widget)
widget_classes.append(widget.__class__)
expected_classes = [BooleanParameterWidget, FloatParameterWidget]
message = 'Expected %s got %s' % (expected_classes, widget_classes)
self.assertListEqual(widget_classes, expected_classes, message)
示例12: test_init
def test_init(self):
parameter = BooleanParameter('1231231')
parameter.name = 'Boolean'
parameter.help_text = 'A boolean parameter'
parameter.description = 'A test _description'
parameter.is_required = True
parameter.value = True
widget = BooleanParameterWidget(parameter)
expected_value = 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 = parameter.value
real_value = widget._check_box_input.isChecked()
message = 'Expected %s get %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
# change value
widget._check_box_input.setChecked(False)
expected_value = False
real_value = widget._check_box_input.isChecked()
message = 'Expected %s get %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
示例13: test_boolean
def test_boolean(self):
"""Test a bool parameter works properly.
.. versionadded:: 2.2
"""
parameter = BooleanParameter('1231231')
parameter.name = 'Boolean'
parameter.help_text = 'A boolean parameter'
parameter.description = 'A test _description'
parameter.is_required = True
parameter.value = True
self.assertEqual(True, parameter.value)
with self.assertRaises(TypeError):
parameter.value = 'Test'
示例14: test_build_widget
def test_build_widget(self):
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 = [2.3] # default value
value = dialog.build_widget(dialog.configLayout, 'foo', threshold)
widget = dialog.findChild(QLineEdit)
add_button = dialog.findChildren(QPushButton)[0]
remove_button = dialog.findChildren(QPushButton)[1]
list_widget = dialog.findChild(QListWidget)
# initial value must be same with default
expected_value = [2.3]
real_value = value().value
message = 'Expected %s but got %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
# change to 5.9
# select 2.3 list item
self.click_list_widget_item(list_widget, '2.3')
# remove 2.3 list item
remove_button.click()
# typing 5.9
widget.setText('5.9')
# add it to list
add_button.click()
expected_value = [5.9]
real_value = value().value
message = 'Expected %s but got %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
# add 70
widget.setText('70')
# add it to list
add_button.click()
expected_value = [5.9, 70]
real_value = value().value
message = 'Expected %s but got %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
widget.setText('bar')
self.assertEqual('bar', widget.text())
def trigger_error(error):
message = 'Expected %s type but got %s' % (
ValueError, type(error))
self.assertIsInstance(error, ValueError, message)
threshold.add_row_error_handler = trigger_error
add_button.click()
bool_param = BooleanParameter()
bool_param.name = 'boolean checkbox'
bool_param.value = True
dialog = FunctionOptionsDialog()
value = dialog.build_widget(dialog.configLayout, 'foo', bool_param)
widget = dialog.findChild(QCheckBox)
# initial value must be same with default
expected_value = True
real_value = value().value
message = 'Expected %s but got %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
widget.setChecked(False)
expected_value = False
real_value = value().value
message = 'Expected %s but got %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
dict_param = DictParameter()
dict_param.name = 'Dictionary tree'
dict_param.element_type = int
dict_param.value = {'a': 1, 'b': 2}
dialog = FunctionOptionsDialog()
value = dialog.build_widget(dialog.configLayout, 'foo', dict_param)
widget = dialog.findChild(QTreeWidget)
# initial value must be same with default
expected_value = {'a': 1, 'b': 2}
real_value = value().value
message = 'Expected %s but got %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
expected_value = {'a': 2, 'b': 1}
# get tree items
tree_items = widget.invisibleRootItem()
# set the input
tree_items.child(0).setText(1, str(2))
tree_items.child(1).setText(1, str(1))
#.........这里部分代码省略.........
示例15: building_type_field
def building_type_field():
field = BooleanParameter()
field.name = 'Building Type Field'
field.is_required = True
field.value = True
return field