本文整理汇总了Python中unit.Unit.load_dictionary方法的典型用法代码示例。如果您正苦于以下问题:Python Unit.load_dictionary方法的具体用法?Python Unit.load_dictionary怎么用?Python Unit.load_dictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unit.Unit
的用法示例。
在下文中一共展示了Unit.load_dictionary方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from unit import Unit [as 别名]
# 或者: from unit.Unit import load_dictionary [as 别名]
def main():
"""Main function"""
app = QApplication([])
unit_feet = Unit('130790')
unit_feet.load_dictionary(unit_feet_depth)
unit_metres = Unit('900713')
unit_metres.load_dictionary(unit_metres_depth)
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'
boolean_parameter = BooleanParameter('1231231')
boolean_parameter.name = 'Post processor'
boolean_parameter.help_text = 'This is post processor parameter.'
boolean_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')
boolean_parameter.is_required = True
boolean_parameter.value = True
float_parameter = FloatParameter()
float_parameter.name = 'Flood Depth'
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 = 'The depth of flood.'
float_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')
float_parameter.unit = unit_feet
float_parameter.allowed_units = [unit_metres, unit_feet]
float_parameter.value = 1.12
integer_parameter = IntegerParameter()
integer_parameter.name = 'Paper'
integer_parameter.is_required = True
integer_parameter.minimum_allowed_value = 1
integer_parameter.maximum_allowed_value = 5
integer_parameter.help_text = 'Number of paper'
integer_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')
integer_parameter.unit = unit_feet
integer_parameter.allowed_units = [unit_feet]
integer_parameter.value = 3
parameters = [
string_parameter,
integer_parameter,
boolean_parameter,
float_parameter,
float_parameter,
boolean_parameter,
integer_parameter]
parameter_container = ParameterContainer(parameters)
widget = QWidget()
layout = QGridLayout()
layout.addWidget(parameter_container)
widget.setLayout(layout)
widget.setGeometry(0, 0, 500, 500)
widget.show()
new_parameters = parameter_container.get_parameters()
for new_parameter in new_parameters:
print new_parameter.name, new_parameter.value
sys.exit(app.exec_())
示例2: test_init
# 需要导入模块: from unit import Unit [as 别名]
# 或者: from unit.Unit import load_dictionary [as 别名]
def test_init(self):
unit_feet = Unit('130790')
unit_feet.load_dictionary(unit_feet_depth)
unit_metres = Unit('900713')
unit_metres.load_dictionary(unit_metres_depth)
float_parameter = FloatParameter()
float_parameter.name = 'Flood Depth'
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 = 'The depth of flood.'
float_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')
float_parameter.unit = unit_feet
float_parameter.allowed_units = [unit_metres, unit_feet]
float_parameter.value = 1.12
widget = FloatParameterWidget(float_parameter)
expected_value = float_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 = float_parameter.value
real_value = widget.get_parameter().value
message = 'Expected %s get %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
widget._input.setValue(1.5)
expected_value = 1.5
real_value = widget.get_parameter().value
message = 'Expected %s get %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
widget._input.setValue(1.55555)
expected_value = 1.556
real_value = widget.get_parameter().value
message = 'Expected %s get %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
widget._input.setValue(7)
expected_value = 2
real_value = widget.get_parameter().value
message = 'Expected %s get %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
expected_value = 'QComboBox'
real_value = widget._unit_widget.__class__.__name__
message = 'Expected %s get %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
expected_value = 'feet'
real_value = widget.get_parameter().unit.name
message = 'Expected %s get %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
expected_value = 'metres'
widget._unit_widget.setCurrentIndex(0)
real_value = widget.get_parameter().unit.name
message = 'Expected %s get %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
示例3: main
# 需要导入模块: from unit import Unit [as 别名]
# 或者: from unit.Unit import load_dictionary [as 别名]
def main():
"""Main function"""
app = QApplication([])
def validate_min_max(parent_container):
"""
:param parent_container: The container that use this validator.
:type parent_container: ParameterContainer
:return:
"""
min_value_parameter = parent_container.get_parameter_by_guid(
min_integer_parameter.guid)
max_value_parameter = parent_container.get_parameter_by_guid(
max_integer_parameter.guid)
min_value = min_value_parameter.value
max_value = max_value_parameter.value
print 'min', min_value
print 'max', max_value
if min_value > max_value:
print 'Not valid'
return {
'valid': False,
'message': (
'Your minimum value (%d) should be less than your maximum '
'value (%d)' % (min_value, max_value))
}
print 'Valid'
return {'valid': True, 'message': ''}
unit_feet = Unit('130790')
unit_feet.load_dictionary(unit_feet_depth)
unit_metres = Unit('900713')
unit_metres.load_dictionary(unit_metres_depth)
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'
boolean_parameter = BooleanParameter('1231231')
boolean_parameter.name = 'Post processor'
boolean_parameter.help_text = 'This is post processor parameter.'
boolean_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')
boolean_parameter.is_required = True
boolean_parameter.value = True
float_parameter = FloatParameter()
float_parameter.name = 'Flood Depth'
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 = 'The depth of flood.'
float_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')
float_parameter.unit = unit_feet
float_parameter.allowed_units = [unit_metres, unit_feet]
float_parameter.value = 1.12
integer_parameter = IntegerParameter()
integer_parameter.name = 'Paper'
integer_parameter.is_required = True
integer_parameter.minimum_allowed_value = 1
integer_parameter.maximum_allowed_value = 5
integer_parameter.help_text = 'Number of paper'
integer_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')
integer_parameter.unit = unit_feet
integer_parameter.allowed_units = [unit_feet]
integer_parameter.value = 3
point_parameter = PointParameter()
point_parameter.name = 'Point Parameter'
point_parameter.is_required = True
point_parameter.help_text = 'Short help.'
point_parameter.description = 'Long description for parameter.'
#.........这里部分代码省略.........
示例4: test_init
# 需要导入模块: from unit import Unit [as 别名]
# 或者: from unit.Unit import load_dictionary [as 别名]
def test_init(self):
unit_feet = Unit('130790')
unit_feet.load_dictionary(unit_feet_depth)
unit_metres = Unit('900713')
unit_metres.load_dictionary(unit_metres_depth)
integer_parameter = IntegerParameter()
integer_parameter.name = 'Paper'
integer_parameter.is_required = True
integer_parameter.minimum_allowed_value = 1
integer_parameter.maximum_allowed_value = 5
integer_parameter.help_text = 'Number of paper'
integer_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')
integer_parameter.unit = unit_feet
integer_parameter.allowed_units = [unit_feet]
integer_parameter.value = 3
widget = IntegerParameterWidget(integer_parameter)
expected_value = integer_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 = integer_parameter.value
real_value = widget.get_parameter().value
message = 'Expected %s get %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
widget._input.setValue(1.5)
expected_value = 1
real_value = widget.get_parameter().value
message = 'Expected %s get %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
widget._input.setValue(1.55555)
expected_value = 1
real_value = widget.get_parameter().value
message = 'Expected %s get %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
widget._input.setValue(7)
expected_value = 5
real_value = widget.get_parameter().value
message = 'Expected %s get %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
expected_value = 'QLabel'
real_value = widget._unit_widget.__class__.__name__
message = 'Expected %s get %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)
expected_value = 'feet'
real_value = widget._unit_widget.text()
message = 'Expected %s get %s' % (expected_value, real_value)
self.assertEqual(expected_value, real_value, message)