• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python defaults.get_defaults函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中safe.defaults.get_defaults函数的典型用法代码示例。如果您正苦于以下问题:Python get_defaults函数的具体用法?Python get_defaults怎么用?Python get_defaults使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_defaults函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_check_aggregation_single_attribute

    def test_check_aggregation_single_attribute(self):
        """Aggregation attribute is chosen correctly when there is only
        one attr available."""
        layer_path = os.path.join(
            TESTDATA, 'kabupaten_jakarta_singlepart_1_good_attr.shp')
        file_list = [layer_path]
        # add additional layers
        load_layers(file_list, clear_flag=False)
        attribute_key = get_defaults('AGGR_ATTR_KEY')

        # with 1 good aggregation attribute using
        # kabupaten_jakarta_singlepart_1_good_attr.shp
        result, message = setup_scenario(
            self.DOCK,
            hazard='Continuous Flood',
            exposure='Population',
            function_id='FloodEvacuationRasterHazardFunction',
            aggregation_layer='kabupaten jakarta singlepart 1 good attr')
        set_jakarta_extent(dock=self.DOCK)
        assert result, message
        # Press RUN
        # noinspection PyCallByClass,PyTypeChecker
        self.DOCK.accept()
        aggregator = self.DOCK.impact_function.aggregator
        attribute = aggregator.attributes[attribute_key]
        message = (
            'The aggregation should be KAB_NAME. Found: %s' % attribute)
        self.assertEqual(attribute, 'KAB_NAME', message)
开发者ID:jobel-openscience,项目名称:inasafe,代码行数:28,代码来源:test_aggregator.py


示例2: test_check_aggregation_no_attributes

 def test_check_aggregation_no_attributes(self):
     """Aggregation attribute chosen correctly when no attr available."""
     layer_path = os.path.join(
         TESTDATA, 'kabupaten_jakarta_singlepart_0_good_attr.shp')
     file_list = [layer_path]
     # add additional layers
     load_layers(file_list, clear_flag=False)
     attribute_key = get_defaults('AGGR_ATTR_KEY')
     # with no good aggregation attribute using
     # kabupaten_jakarta_singlepart_0_good_attr.shp
     result, message = setup_scenario(
         DOCK,
         hazard='A flood in Jakarta like in 2007',
         exposure='People',
         function_id='Flood Evacuation Function',
         aggregation_layer='kabupaten jakarta singlepart 0 good attr')
     set_jakarta_extent(dock=DOCK)
     assert result, message
     # Press RUN
     DOCK.accept()
     DOCK.runtime_keywords_dialog.accept()
     attribute = DOCK.analysis.aggregator.attributes[attribute_key]
     message = (
         'The aggregation should be None. Found: %s' % attribute)
     assert attribute is None, message
开发者ID:severinmenard,项目名称:inasafe,代码行数:25,代码来源:test_aggregator.py


示例3: setUp

    def setUp(self):
        """Fixture run before all tests"""
        register_impact_functions()
        self.maxDiff = None  # show full diff for assert errors
        os.environ['LANG'] = 'en'
        self.DOCK.show_only_visible_layers_flag = True
        load_standard_layers(self.DOCK)
        self.DOCK.cboHazard.setCurrentIndex(0)
        self.DOCK.cboExposure.setCurrentIndex(0)
        self.DOCK.cboFunction.setCurrentIndex(0)
        self.DOCK.run_in_thread_flag = False
        self.DOCK.show_only_visible_layers_flag = False
        self.DOCK.set_layer_from_title_flag = False
        self.DOCK.zoom_to_impact_flag = False
        self.DOCK.hide_exposure_flag = False
        self.DOCK.show_intermediate_layers = False
        set_jakarta_extent()

        self._keywordIO = KeywordIO()
        self._defaults = get_defaults()

        # Set extent as Jakarta extent
        geo_crs = QgsCoordinateReferenceSystem()
        geo_crs.createFromSrid(4326)
        self.extent = extent_to_geo_array(CANVAS.extent(), geo_crs)
开发者ID:jobel-openscience,项目名称:inasafe,代码行数:25,代码来源:test_aggregator.py


示例4: test_get_defaults

    def test_get_defaults(self):
        """Test we can get the defaults.
        """
        expected = {
            'ADULT_RATIO_KEY': 'adult ratio default',
            'ADULT_RATIO_ATTR_KEY': 'adult ratio attribute',
            'ADULT_RATIO': 0.659,

            'FEMALE_RATIO_KEY': 'female ratio default',
            'FEMALE_RATIO_ATTR_KEY': 'female ratio attribute',
            'FEMALE_RATIO': 0.5,

            'ELDERLY_RATIO_ATTR_KEY': 'elderly ratio attribute',
            'ELDERLY_RATIO_KEY': 'elderly ratio default',
            'ELDERLY_RATIO': 0.078,

            'YOUTH_RATIO': 0.263,
            'YOUTH_RATIO_ATTR_KEY': 'youth ratio attribute',
            'YOUTH_RATIO_KEY': 'youth ratio default',

            'NO_DATA': u'No data',

            'AGGR_ATTR_KEY': 'aggregation attribute',
            'ISO19115_EMAIL': '[email protected]',
            'ISO19115_LICENSE': 'Free use with accreditation',
            'ISO19115_ORGANIZATION': 'InaSAFE.org',
            'ISO19115_TITLE': 'InaSAFE analysis result',
            'ISO19115_URL': 'http://inasafe.org'}

        actual = get_defaults()
        self.maxDiff = None
        self.assertDictEqual(expected, actual)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:32,代码来源:test_defaults.py


示例5: test_check_aggregation_no_attributes

 def test_check_aggregation_no_attributes(self):
     """Aggregation attribute chosen correctly when no attr available."""
     layer_path = os.path.join(
         TESTDATA, 'kabupaten_jakarta_singlepart_0_good_attr.shp')
     file_list = [layer_path]
     # add additional layers
     load_layers(file_list, clear_flag=False)
     attribute_key = get_defaults('AGGR_ATTR_KEY')
     # with no good aggregation attribute using
     # kabupaten_jakarta_singlepart_0_good_attr.shp
     result, message = setup_scenario(
         self.DOCK,
         hazard='Continuous Flood',
         exposure='Population',
         function_id='FloodEvacuationRasterHazardFunction',
         aggregation_layer='kabupaten jakarta singlepart 0 good attr')
     set_jakarta_extent(dock=self.DOCK)
     self.assertTrue(result, message)
     # Press RUN
     self.DOCK.accept()
     aggregator = self.DOCK.impact_function.aggregator
     attribute = aggregator.attributes[attribute_key]
     message = (
         'The aggregation should be None. Found: %s' % attribute)
     self.assertIsNone(attribute, message)
开发者ID:jobel-openscience,项目名称:inasafe,代码行数:25,代码来源:test_aggregator.py


示例6: test_get_defaults

    def test_get_defaults(self):
        """Test we can get the defaults.
        """
        expected = {
            "ADULT_RATIO_KEY": "adult ratio default",
            "ADULT_RATIO_ATTR_KEY": "adult ratio attribute",
            "ADULT_RATIO": 0.659,
            "FEMALE_RATIO_KEY": "female ratio default",
            "FEMALE_RATIO_ATTR_KEY": "female ratio attribute",
            "FEMALE_RATIO": 0.5,
            "ELDERLY_RATIO_ATTR_KEY": "elderly ratio attribute",
            "ELDERLY_RATIO_KEY": "elderly ratio default",
            "ELDERLY_RATIO": 0.078,
            "YOUTH_RATIO": 0.263,
            "YOUTH_RATIO_ATTR_KEY": "youth ratio attribute",
            "YOUTH_RATIO_KEY": "youth ratio default",
            "NO_DATA": u"No data",
            "AGGR_ATTR_KEY": "aggregation attribute",
            "ISO19115_EMAIL": "[email protected]",
            "ISO19115_LICENSE": "Free use with accreditation",
            "ISO19115_ORGANIZATION": "InaSAFE.org",
            "ISO19115_TITLE": "InaSAFE analysis result",
            "ISO19115_URL": "http://inasafe.org",
        }

        actual = get_defaults()
        self.maxDiff = None
        self.assertDictEqual(expected, actual)
开发者ID:Mloweedgar,项目名称:inasafe,代码行数:28,代码来源:test_defaults.py


示例7: setup

    def setup(self, params):
        """concrete implementation it takes care of the needed parameters being
         initialized

        Args:
            params: dict of parameters to pass to the post processor
        Returns:
            None
        Raises:
            None
        """
        AbstractPostprocessor.setup(self, None)
        if self.impact_total is not None:
            self._raise_error('clear needs to be called before setup')

        self.impact_total = params['impact_total']
        try:
            #either all 3 ratio are custom set or we use defaults
            self.youth_ratio = params['youth_ratio']
            self.adult_ratio = params['adult_ratio']
            self.elder_ratio = params['elder_ratio']
        except KeyError:
            self._log_message('either all 3 age ratio are custom set or we'
                              ' use defaults')
            defaults = get_defaults()
            self.youth_ratio = defaults['YOUTH_RATIO']
            self.adult_ratio = defaults['ADULT_RATIO']
            self.elder_ratio = defaults['ELDER_RATIO']
开发者ID:borysiasty,项目名称:inasafe,代码行数:28,代码来源:age_postprocessor.py


示例8: test_check_aggregation_single_attribute

    def test_check_aggregation_single_attribute(self):
        """Aggregation attribute is chosen correctly when there is only
        one attr available."""
        layer_path = os.path.join(
            TESTDATA, 'kabupaten_jakarta_singlepart_1_good_attr.shp')
        file_list = [layer_path]
        # add additional layers
        load_layers(file_list, clear_flag=False)
        attribute_key = get_defaults('AGGR_ATTR_KEY')

        # with 1 good aggregation attribute using
        # kabupaten_jakarta_singlepart_1_good_attr.shp
        result, message = setup_scenario(
            DOCK,
            hazard='A flood in Jakarta like in 2007',
            exposure='People',
            function_id='Flood Evacuation Function',
            aggregation_layer='kabupaten jakarta singlepart 1 good attr')
        set_jakarta_extent(dock=DOCK)
        assert result, message
        # Press RUN
        # noinspection PyCallByClass,PyTypeChecker
        DOCK.accept()
        DOCK.runtime_keywords_dialog.accept()
        print attribute_key
        print DOCK.analysis.aggregator.attributes
        attribute = DOCK.analysis.aggregator.attributes[attribute_key]
        message = (
            'The aggregation should be KAB_NAME. Found: %s' % attribute)
        self.assertEqual(attribute, 'KAB_NAME', message)
开发者ID:severinmenard,项目名称:inasafe,代码行数:30,代码来源:test_aggregator.py


示例9: __init__

    def __init__(self, iface, dock=None, parent=None):
        """Constructor for the dialog.

        :param iface: A Quantum GIS QGisAppInterface instance.
        :type iface: QGisAppInterface

        :param parent: Parent widget of this dialog
        :type parent: QWidget

        :param dock: Optional dock widget instance that we can notify of
            changes to the keywords.
        :type dock: Dock
        """

        QtGui.QDialog.__init__(self, parent)
        self.setupUi(self)
        self.setWindowTitle(self.tr('InaSAFE %s Options' % get_version()))
        # Save reference to the QGIS interface and parent
        self.iface = iface
        self.parent = parent
        self.dock = dock
        self.keyword_io = KeywordIO()
        self.defaults = get_defaults()

        # Set up things for context help
        self.help_button = self.button_box.button(QtGui.QDialogButtonBox.Help)
        # Allow toggling the help button
        self.help_button.setCheckable(True)
        self.help_button.toggled.connect(self.help_toggled)
        self.main_stacked_widget.setCurrentIndex(1)

        self.grpNotImplemented.hide()
        self.adjustSize()
        self.restore_state()
        # hack prevent showing use thread visible and set it false see #557
        self.cbxUseThread.setChecked(True)
        self.cbxUseThread.setVisible(False)

        # Set up listener for various UI
        self.custom_org_logo_checkbox.toggled.connect(
            self.set_organisation_logo)
        self.custom_north_arrow_checkbox.toggled.connect(self.set_north_arrow)
        self.custom_UseUserDirectory_checkbox.toggled.connect(
            self.set_user_dir)
        self.custom_templates_dir_checkbox.toggled.connect(
            self.set_templates_dir)
        self.custom_org_disclaimer_checkbox.toggled.connect(
            self.set_org_disclaimer)
开发者ID:dynaryu,项目名称:inasafe,代码行数:48,代码来源:options_dialog.py


示例10: test_on_rad_postprocessing_toggled

    def test_on_rad_postprocessing_toggled(self):
        """Test postprocessing radio button toggle behaviour works"""
        layer = clone_shp_layer(
            name='district_osm_jakarta',
            include_keywords=True,
            source_directory=test_data_path('boundaries'))
        defaults = get_defaults()
        dialog = KeywordsDialog(PARENT, IFACE, layer=layer)
        # Click hazard/exposure button first so that it won't take default
        # from keywords file
        dialog.radExposure.click()

        # Now click the postprocessing button
        button = dialog.radPostprocessing
        button.click()
        message = (
            'Toggling the postprocessing radio did not add a '
            'category to the keywords list.')
        self.assertEqual(
            dialog.get_value_for_key('category'), 'postprocessing', message)

        message = (
            'Toggling the postprocessing radio did not add an '
            'aggregation attribute to the keywords list.')
        self.assertEqual(
            dialog.get_value_for_key(defaults['AGGR_ATTR_KEY']),
            'KAB_NAME',
            message)

        message = (
            'Toggling the postprocessing radio did not add a '
            'female ratio attribute to the keywords list.')
        self.assertEqual(
            dialog.get_value_for_key(defaults['FEMALE_RATIO_ATTR_KEY']),
            dialog.global_default_string,
            message)

        message = (
            'Toggling the postprocessing radio did not add a '
            'female ratio default value to the keywords list.')
        self.assertEqual(
            float(dialog.get_value_for_key(defaults['FEMALE_RATIO_KEY'])),
            defaults['FEMALE_RATIO'],
            message)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:44,代码来源:test_keywords_dialog.py


示例11: test_aggregation_attribute_in_keywords

    def test_aggregation_attribute_in_keywords(self):
        """Aggregation attribute is chosen correctly when present in keywords.
        """
        attribute_key = get_defaults('AGGR_ATTR_KEY')

        # with KAB_NAME aggregation attribute defined in .keyword using
        # kabupaten_jakarta_singlepart.shp
        result, message = setup_scenario(
            self.DOCK,
            hazard='Continuous Flood',
            exposure='Population',
            function_id='FloodEvacuationRasterHazardFunction',
            aggregation_layer=u"Dístríct's of Jakarta",
            aggregation_enabled_flag=True)
        set_jakarta_extent(dock=self.DOCK)
        assert result, message
        # Press RUN
        self.DOCK.accept()
        attribute = self.DOCK.analysis.aggregator.attributes[attribute_key]
        message = ('The aggregation should be KAB_NAME. Found: %s' % attribute)
        self.assertEqual(attribute, 'KAB_NAME', message)
开发者ID:codeforresilience,项目名称:inasafe,代码行数:21,代码来源:test_aggregator.py


示例12: test_aggregation_attribute_in_keywords

    def test_aggregation_attribute_in_keywords(self):
        """Aggregation attribute is chosen correctly when present in keywords.
        """
        attribute_key = get_defaults('AGGR_ATTR_KEY')

        # with KAB_NAME aggregation attribute defined in .keyword using
        # kabupaten_jakarta_singlepart.shp
        result, message = setup_scenario(
            DOCK,
            hazard='A flood in Jakarta like in 2007',
            exposure='People',
            function_id='Flood Evacuation Function',
            aggregation_layer='kabupaten jakarta singlepart',
            aggregation_enabled_flag=True)
        set_jakarta_extent(dock=DOCK)
        assert result, message
        # Press RUN
        DOCK.accept()
        DOCK.runtime_keywords_dialog.accept()
        attribute = DOCK.analysis.aggregator.attributes[attribute_key]
        message = ('The aggregation should be KAB_NAME. Found: %s' % attribute)
        self.assertEqual(attribute, 'KAB_NAME', message)
开发者ID:severinmenard,项目名称:inasafe,代码行数:22,代码来源:test_aggregator.py


示例13: test_check_aggregation_none_in_keywords

 def test_check_aggregation_none_in_keywords(self):
     """Aggregation attribute is chosen correctly when None in keywords."""
     layer_path = os.path.join(
         TESTDATA, 'kabupaten_jakarta_singlepart_with_None_keyword.shp')
     file_list = [layer_path]
     # add additional layers
     load_layers(file_list, clear_flag=False)
     attribute_key = get_defaults('AGGR_ATTR_KEY')
     # with None aggregation attribute defined in .keyword using
     # kabupaten_jakarta_singlepart_with_None_keyword.shp
     result, message = setup_scenario(
         self.DOCK,
         hazard='Continuous Flood',
         exposure='Population',
         function_id='FloodEvacuationRasterHazardFunction',
         aggregation_layer='kabupaten jakarta singlepart with None keyword')
     set_jakarta_extent(dock=self.DOCK)
     assert result, message
     # Press RUN
     self.DOCK.accept()
     attribute = self.DOCK.analysis.aggregator.attributes[attribute_key]
     message = ('The aggregation should be None. Found: %s' % attribute)
     assert attribute is None, message
开发者ID:codeforresilience,项目名称:inasafe,代码行数:23,代码来源:test_aggregator.py


示例14: test_clip_vector_with_unicode

    def test_clip_vector_with_unicode(self):
        """Test clipping vector layer with unicode attribute in feature.

        This issue is described at Github #2262 and #2233
        TODO: FIXME:
        This is a hacky fix. See above ticket for further explanation.
        To fix this, we should be able to specify UTF-8 encoding for
        QgsVectorFileWriter
        """
        # this layer contains unicode values in the
        layer_path = standard_data_path(
            'boundaries', 'district_osm_jakarta.shp')
        vector_layer = QgsVectorLayer(layer_path, 'District Jakarta', 'ogr')
        keyword_io = KeywordIO()
        aggregation_keyword = get_defaults()['AGGR_ATTR_KEY']
        aggregation_attribute = keyword_io.read_keywords(
            vector_layer, keyword=aggregation_keyword)
        source_extent = vector_layer.extent()
        extent = [source_extent.xMinimum(), source_extent.yMinimum(),
                  source_extent.xMaximum(), source_extent.yMaximum()]
        clipped_layer = clip_layer(
            layer=vector_layer,
            extent=extent,
            explode_flag=True,
            explode_attribute=aggregation_attribute)

        # cross check vector layer attribute in clipped layer
        vector_values = []
        for f in vector_layer.getFeatures():
            vector_values.append(f.attributes())

        clipped_values = []
        for f in clipped_layer.getFeatures():
            clipped_values.append(f.attributes())

        for val in clipped_values:
            self.assertIn(val, vector_values)
开发者ID:easmetz,项目名称:inasafe,代码行数:37,代码来源:test_clipper.py


示例15: setup

    def setup(self, params):
        """Concrete implementation to ensure needed parameters are initialized.

        :param params: Dict of parameters to pass to the post processor.
        :type params: dict

        """
        AbstractPostprocessor.setup(self, None)
        if self.impact_total is not None:
            self._raise_error('clear needs to be called before setup')

        self.impact_total = params['impact_total']
        try:
            # either all 3 ratio are custom set or we use defaults
            self.youth_ratio = params['youth_ratio']
            self.adult_ratio = params['adult_ratio']
            self.elderly_ratio = params['elderly_ratio']

            ratios_total = (self.youth_ratio +
                            self.adult_ratio +
                            self.elderly_ratio)
            if ratios_total > 1:
                self._raise_error(
                    'Age ratios should sum up to 1. Found: '
                    '%s + %s + %s = %s ' % (
                        self.youth_ratio,
                        self.adult_ratio,
                        self.elderly_ratio,
                        ratios_total))
        except KeyError:
            self._log_message('either all 3 age ratio are custom set or we'
                              ' use defaults')
            defaults = get_defaults()
            self.youth_ratio = defaults['YOUTH_RATIO']
            self.adult_ratio = defaults['ADULT_RATIO']
            self.elderly_ratio = defaults['ELDERLY_RATIO']
开发者ID:felix-yew,项目名称:inasafe,代码行数:36,代码来源:age_postprocessor.py


示例16: generate_iso_metadata

def generate_iso_metadata(keywords=None):
    """Make a valid ISO 19115 XML using the values of safe.get_defaults

    This method will create XML based on the iso_19115_template.py template
    The $placeholders there will be replaced by the values returned from
    safe.defaults.get_defaults. Note that get_defaults takes care of using the
    values set in QGIS settings if available.

    :param keywords: The metadata keywords to write (which should be
            provided as a dict of key value pairs).
    :type keywords: dict

    :return: str valid XML
    """

    # get defaults from settings
    template_replacements = copy.copy(get_defaults())

    # create runtime based replacement values
    template_replacements['ISO19115_TODAY_DATE'] = time.strftime("%Y-%m-%d")
    if keywords is not None:
        template_replacements['INASAFE_KEYWORDS'] = '<![CDATA[%s]]>' % \
                                                    json.dumps(keywords)
        try:
            template_replacements['ISO19115_TITLE'] = keywords['title']
        except KeyError:
            pass
        try:
            template_replacements['ISO19115_LINEAGE'] = keywords['source']
        except KeyError:
            template_replacements['ISO19115_LINEAGE'] = ''

    else:
        template_replacements['INASAFE_KEYWORDS'] = ''

    return ISO_METADATA_XML_TEMPLATE.safe_substitute(template_replacements)
开发者ID:severinmenard,项目名称:inasafe,代码行数:36,代码来源:metadata_utilities.py


示例17: import

from safe.common.version import get_version
from safe.common.exceptions import InaSAFEError
from safe.defaults import get_defaults
from safe.utilities.keyword_io import KeywordIO
from safe.utilities.help import show_context_help
from safe.utilities.utilities import get_error_message
from safe.utilities.gis import layer_attribute_names, is_polygon_layer
from safe.utilities.resources import get_ui_class
from safe.common.exceptions import (
    InvalidParameterError,
    HashNotFoundError,
    NoKeywordsFoundError)
from safe import metadata

# Aggregations' keywords
DEFAULTS = get_defaults()
female_ratio_attribute_key = DEFAULTS['FEMALE_RATIO_ATTR_KEY']
female_ratio_default_key = DEFAULTS['FEMALE_RATIO_KEY']
youth_ratio_attribute_key = DEFAULTS['YOUTH_RATIO_ATTR_KEY']
youth_ratio_default_key = DEFAULTS['YOUTH_RATIO_KEY']
adult_ratio_attribute_key = DEFAULTS['ADULT_RATIO_ATTR_KEY']
adult_ratio_default_key = DEFAULTS['ADULT_RATIO_KEY']
elderly_ratio_attribute_key = DEFAULTS['ELDERLY_RATIO_ATTR_KEY']
elderly_ratio_default_key = DEFAULTS['ELDERLY_RATIO_KEY']

LOGGER = logging.getLogger('InaSAFE')

FORM_CLASS = get_ui_class('keywords_dialog_base.ui')


class KeywordsDialog(QtGui.QDialog, FORM_CLASS):
开发者ID:severinmenard,项目名称:inasafe,代码行数:31,代码来源:keywords_dialog.py


示例18: __init__

    def __init__(self, parent, iface, dock=None, layer=None):
        """Constructor for the dialog.

        .. note:: In QtDesigner the advanced editor's predefined keywords
           list should be shown in english always, so when adding entries to
           cboKeyword, be sure to choose :safe_qgis:`Properties<<` and untick
           the :safe_qgis:`translatable` property.

        :param parent: Parent widget of this dialog.
        :type parent: QWidget

        :param iface: Quantum GIS QGisAppInterface instance.
        :type iface: QGisAppInterface

        :param dock: Dock widget instance that we can notify of changes to
            the keywords. Optional.
        :type dock: Dock
        """
        QtGui.QDialog.__init__(self, parent)
        self.setupUi(self)
        self.setWindowTitle(self.tr(
            'InaSAFE %s Keywords Editor' % get_version()))
        # Save reference to the QGIS interface and parent
        self.iface = iface
        self.parent = parent
        self.dock = dock
        self.defaults = None

        # string constants
        self.global_default_string = metadata.global_default_attribute['name']
        self.do_not_use_string = metadata.do_not_use_attribute['name']
        self.global_default_data = metadata.global_default_attribute['id']
        self.do_not_use_data = metadata.do_not_use_attribute['id']

        if layer is None:
            self.layer = self.iface.activeLayer()
        else:
            self.layer = layer

        self.keyword_io = KeywordIO()

        # note the keys should remain untranslated as we need to write
        # english to the keywords file. The keys will be written as user data
        # in the combo entries.
        # .. seealso:: http://www.voidspace.org.uk/python/odict.html
        self.standard_exposure_list = OrderedDict(
            [('population', self.tr('population')),
             ('structure', self.tr('structure')),
             ('road', self.tr('road')),
             ('Not Set', self.tr('Not Set'))])
        self.standard_hazard_list = OrderedDict(
            [('earthquake [MMI]', self.tr('earthquake [MMI]')),
             ('tsunami [m]', self.tr('tsunami [m]')),
             ('tsunami [wet/dry]', self.tr('tsunami [wet/dry]')),
             ('tsunami [feet]', self.tr('tsunami [feet]')),
             ('flood [m]', self.tr('flood [m]')),
             ('flood [wet/dry]', self.tr('flood [wet/dry]')),
             ('flood [feet]', self.tr('flood [feet]')),
             ('tephra [kg2/m2]', self.tr('tephra [kg2/m2]')),
             ('volcano', self.tr('volcano')),
             ('generic [categorised]', self.tr('generic [categorised]')),
             ('Not Set', self.tr('Not Set'))])

        # noinspection PyUnresolvedReferences
        self.lstKeywords.itemClicked.connect(self.edit_key_value_pair)

        # Set up help dialog showing logic.
        help_button = self.buttonBox.button(QtGui.QDialogButtonBox.Help)
        help_button.clicked.connect(self.show_help)

        if self.layer is not None and is_polygon_layer(self.layer):
            # set some initial ui state:
            self.defaults = get_defaults()
            self.radPredefined.setChecked(True)
            self.dsbFemaleRatioDefault.blockSignals(True)
            self.dsbFemaleRatioDefault.setValue(self.defaults['FEMALE_RATIO'])
            self.dsbFemaleRatioDefault.blockSignals(False)

            self.dsbYouthRatioDefault.blockSignals(True)
            self.dsbYouthRatioDefault.setValue(self.defaults['YOUTH_RATIO'])
            self.dsbYouthRatioDefault.blockSignals(False)

            self.dsbAdultRatioDefault.blockSignals(True)
            self.dsbAdultRatioDefault.setValue(self.defaults['ADULT_RATIO'])
            self.dsbAdultRatioDefault.blockSignals(False)

            self.dsbElderlyRatioDefault.blockSignals(True)
            self.dsbElderlyRatioDefault.setValue(
                self.defaults['ELDERLY_RATIO'])
            self.dsbElderlyRatioDefault.blockSignals(False)
        else:
            self.radPostprocessing.hide()
            self.tab_widget.removeTab(1)

        if self.layer:
            self.load_state_from_keywords()

        # add a reload from keywords button
        reload_button = self.buttonBox.addButton(
            self.tr('Reload'), QtGui.QDialogButtonBox.ActionRole)
#.........这里部分代码省略.........
开发者ID:severinmenard,项目名称:inasafe,代码行数:101,代码来源:keywords_dialog.py


示例19: test_on_dsb_female_ratio_default_value_changed

    def test_on_dsb_female_ratio_default_value_changed(self):
        """Test hazard radio button toggle behaviour works"""
        layer = clone_shp_layer(
            name='district_osm_jakarta',
            include_keywords=True,
            source_directory=test_data_path('boundaries'))
        defaults = get_defaults()
        dialog = KeywordsDialog(PARENT, IFACE, layer=layer)
        button = dialog.radPostprocessing
        button.setChecked(False)
        button.click()
        female_ratio_box = dialog.cboFemaleRatioAttribute

        # set to Don't use
        index = female_ratio_box.findText(dialog.do_not_use_string)
        message = (dialog.do_not_use_string + ' not found')
        self.assertNotEqual(index, -1, message)
        female_ratio_box.setCurrentIndex(index)

        message = (
            'Toggling the female ratio attribute combo to'
            ' "Don\'t use" did not add it to the keywords list.')
        self.assertEqual(
            dialog.get_value_for_key(defaults['FEMALE_RATIO_ATTR_KEY']),
            dialog.do_not_use_string,
            message)

        message = (
            'Toggling the female ratio attribute combo to'
            ' "Don\'t use" did not disable dsbFemaleRatioDefault.')
        is_enabled = dialog.dsbFemaleRatioDefault.isEnabled()
        assert not is_enabled, message

        message = (
            'Toggling the female ratio attribute combo to'
            ' "Don\'t use" did not remove the keyword.')
        assert (dialog.get_value_for_key(defaults['FEMALE_RATIO']) is None), \
            message

        # set to PEREMPUAN attribute
        attribute = 'PEREMPUAN'
        index = female_ratio_box.findText(attribute)
        message = 'The attribute %s is not found in the layer' % attribute
        self.assertNotEqual(index, -1, message)

        female_ratio_box.setCurrentIndex(index)
        message = (
            'Toggling the female ratio attribute combo to %s'
            ' did not add it to the keywords list.') % attribute
        self.assertEqual(
            dialog.get_value_for_key(defaults['FEMALE_RATIO_ATTR_KEY']),
            attribute,
            message)

        message = (
            'Toggling the female ratio attribute combo to %s'
            ' did not disable dsbFemaleRatioDefault.') % attribute
        is_enabled = dialog.dsbFemaleRatioDefault.isEnabled()
        self.assertFalse(is_enabled, message)

        message = (
            'Toggling the female ratio attribute combo to %s'
            ' did not remove the keyword.') % attribute
        self.assertIsNone(
            dialog.get_value_for_key(defaults['FEMALE_RATIO']), message)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:65,代码来源:test_keywords_dialog.py



注:本文中的safe.defaults.get_defaults函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utilities.definition函数代码示例发布时间:2022-05-27
下一篇:
Python defaults.disclaimer函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap