当前位置: 首页>>代码示例>>Python>>正文


Python settings.setting函数代码示例

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


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

示例1: prepare_impact_function

    def prepare_impact_function(self):
        """Create analysis as a representation of current situation of IFCW."""

        # Impact Functions
        impact_function = ImpactFunction()
        impact_function.callback = self.progress_callback

        # Layers
        impact_function.hazard = self.parent.hazard_layer
        impact_function.exposure = self.parent.exposure_layer
        aggregation = self.parent.aggregation_layer

        if aggregation:
            impact_function.aggregation = aggregation
            impact_function.use_selected_features_only = (
                setting('useSelectedFeaturesOnly', False, bool))
        else:
            mode = setting('analysis_extents_mode')
            if self.extent.user_extent:
                # This like a hack to transform a geometry to a rectangle.
                # self.extent.user_extent is a QgsGeometry.
                # impact_function.requested_extent needs a QgsRectangle.
                wkt = self.extent.user_extent.exportToWkt()
                impact_function.requested_extent = wkt_to_rectangle(wkt)
                impact_function.requested_extent_crs = self.extent.crs

            elif mode == HAZARD_EXPOSURE_VIEW:
                impact_function.requested_extent = (
                    self.iface.mapCanvas().extent())
                impact_function.requested_extent_crs = self.extent.crs

        # We don't have any checkbox in the wizard for the debug mode.
        impact_function.debug_mode = False

        return impact_function
开发者ID:ismailsunni,项目名称:inasafe,代码行数:35,代码来源:step_fc90_analysis.py

示例2: create_profile_layer

def create_profile_layer(profiling):
    """Create a tabular layer with the profiling.

    :param profiling: A dict containing benchmarking data.
    :type profiling: safe.messaging.message.Message

    :return: A tabular layer.
    :rtype: QgsVectorLayer
    """
    fields = [
        create_field_from_definition(profiling_function_field),
        create_field_from_definition(profiling_time_field)
    ]
    if setting(key='memory_profile', expected_type=bool):
        fields.append(create_field_from_definition(profiling_memory_field))
    tabular = create_memory_layer(
        'profiling',
        QgsWkbTypes.NullGeometry,
        fields=fields)

    # Generate profiling keywords
    tabular.keywords['layer_purpose'] = layer_purpose_profiling['key']
    tabular.keywords['title'] = layer_purpose_profiling['name']
    if qgis_version() >= 21800:
        tabular.setName(tabular.keywords['title'])
    else:
        tabular.setLayerName(tabular.keywords['title'])
    tabular.keywords['inasafe_fields'] = {
        profiling_function_field['key']:
            profiling_function_field['field_name'],
        profiling_time_field['key']:
            profiling_time_field['field_name'],
    }
    if setting(key='memory_profile', expected_type=bool):
        tabular.keywords['inasafe_fields'][
            profiling_memory_field['key']] = profiling_memory_field[
            'field_name']
    tabular.keywords[inasafe_keyword_version_key] = (
        inasafe_keyword_version)

    table = profiling.to_text().splitlines()[3:]
    tabular.startEditing()
    for line in table:
        feature = QgsFeature()
        items = line.split(', ')
        time = items[1].replace('-', '')
        if setting(key='memory_profile', expected_type=bool):
            memory = items[2].replace('-', '')
            feature.setAttributes([items[0], time, memory])
        else:
            feature.setAttributes([items[0], time])
        tabular.addFeature(feature)

    tabular.commitChanges()
    return tabular
开发者ID:inasafe,项目名称:inasafe,代码行数:55,代码来源:create_extra_layers.py

示例3: is_affected

def is_affected(hazard, classification, hazard_class, qsettings=None):
    """Get affected flag for hazard in classification in hazard class.

    :param hazard: The hazard key.
    :type hazard: basestring

    :param classification: The classification key.
    :type classification: basestring

    :param hazard_class: The hazard class key.
    :type hazard_class: basestring

    :param qsettings: A custom QSettings to use. If it's not defined, it will
        use the default one.
    :type qsettings: qgis.PyQt.QtCore.QSettings

    :returns: True if it's affected, else False. Default to False.
    :rtype: bool
    """
    preference_data = setting(
        'population_preference',
        default=generate_default_profile(),
        qsettings=qsettings)

    # Use default from the default profile
    default_profile = generate_default_profile()
    default_affected_value = default_profile.get(hazard, {}).get(
        classification, {}).get(hazard_class, {}).get(
        'affected', not_exposed_class['key'])
    # noinspection PyUnresolvedReferences
    return preference_data.get(hazard, {}).get(classification, {}).get(
        hazard_class, {}).get('affected', default_affected_value)
开发者ID:inasafe,项目名称:inasafe,代码行数:32,代码来源:utilities.py

示例4: restore_population_parameters

    def restore_population_parameters(self, global_default=True):
        """Setup UI for population parameter page from setting.

        :param global_default: If True, set to original default (from
            the value in definitions).
        :type global_default: bool
        """
        if global_default:
            data = generate_default_profile()
        else:
            data = setting('population_preference', generate_default_profile())
        if not isinstance(data, dict):
            LOGGER.debug(
                'population parameter is not a dictionary. InaSAFE will use '
                'the default one.')
            data = generate_default_profile()
        try:
            self.profile_widget.data = data
        except KeyError as e:
            LOGGER.debug(
                'Population parameter is not in correct format. InaSAFE will '
                'use the default one.')
            LOGGER.debug(e)
            data = generate_default_profile()
            self.profile_widget.data = data
开发者ID:inasafe,项目名称:inasafe,代码行数:25,代码来源:options_dialog.py

示例5: test_read_write_setting

    def test_read_write_setting(self):
        """Test read and write setting."""
        # General Setting
        set_general_setting('key', 'value', self.qsettings)
        self.assertEqual(
            'value', general_setting('key', qsettings=self.qsettings))
        delete_general_setting('key', qsettings=self.qsettings)
        self.assertEqual('default', general_setting(
            'key', default='default', qsettings=self.qsettings))

        set_general_setting('key', 'True', self.qsettings)
        self.assertEqual(
            'True',
            general_setting(
                'key', qsettings=self.qsettings, expected_type=str))
        self.assertEqual(
            True,
            general_setting(
                'key', qsettings=self.qsettings, expected_type=bool))
        delete_general_setting('key', qsettings=self.qsettings)
        self.assertEqual('default', general_setting(
            'key', default='default', qsettings=self.qsettings))

        set_general_setting('key', 'false', self.qsettings)
        self.assertEqual(
            'false',
            general_setting(
                'key', qsettings=self.qsettings, expected_type=str))
        self.assertEqual(
            False,
            general_setting(
                'key', qsettings=self.qsettings, expected_type=bool))
        delete_general_setting('key', qsettings=self.qsettings)
        self.assertEqual('default', general_setting(
            'key', default='default', qsettings=self.qsettings))

        # Under InaSAFE scope
        set_setting('key', 'value', self.qsettings)
        self.assertEqual('value', setting('key', qsettings=self.qsettings))
        delete_setting('key', qsettings=self.qsettings)
        self.assertEqual('default', setting(
            'key', default='default', qsettings=self.qsettings))

        # Using InaSAFE setting default
        key = 'developer_mode'
        actual_value = inasafe_default_settings.get(key)
        self.assertEqual(actual_value, setting(key, qsettings=self.qsettings))
开发者ID:inasafe,项目名称:inasafe,代码行数:47,代码来源:test_settings.py

示例6: test_read_boolean_setting

    def test_read_boolean_setting(self):
        """Test read developer mode setting."""
        set_setting(
            'developer_mode',
            inasafe_default_settings['developer_mode'])

        actual_setting = setting(
            'developer_mode', inasafe_default_settings['developer_mode'])
        self.assertFalse(actual_setting)

        set_setting(
            'developer_mode',
            not(inasafe_default_settings['developer_mode']))

        actual_setting = setting(
            'developer_mode', inasafe_default_settings['developer_mode'])
        self.assertTrue(actual_setting)
开发者ID:ismailsunni,项目名称:inasafe,代码行数:17,代码来源:test_settings.py

示例7: restore_state

    def restore_state(self):
        """Restore GUI state from configuration file."""
        # restore last source path
        last_source_path = setting(
            'lastSourceDir', self.default_directory, expected_type=str)
        self.source_directory.setText(last_source_path)

        # restore path pdf output
        last_output_dir = setting(
            'lastOutputDir', self.default_directory, expected_type=str)
        self.output_directory.setText(last_output_dir)

        # restore default output dir combo box
        use_default_output_dir = bool(setting(
            'useDefaultOutputDir', True, expected_type=bool))
        self.scenario_directory_radio.setChecked(
            use_default_output_dir)
开发者ID:inasafe,项目名称:inasafe,代码行数:17,代码来源:batch_dialog.py

示例8: __init__

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

        .. versionadded: 3.3

        :param parent: Optional widget to use as parent.
        :type parent: QWidget

        :param iface: An instance of QGisInterface.
        :type iface: QGisInterface
        """
        QDialog.__init__(self, parent)
        self.parent = parent
        self.setupUi(self)

        title = self.tr('PetaBencana Downloader')
        self.setWindowTitle(title)

        self.iface = iface

        self.source = None

        self.radio_button_group = QButtonGroup()
        self.radio_button_group.addButton(self.radio_button_production)
        self.radio_button_group.addButton(self.radio_button_development)

        self.radio_button_group.setExclusive(True)
        self.radio_button_production.setChecked(True)
        self.populate_combo_box()

        developer_mode = setting('developer_mode', False, bool)
        if not developer_mode:
            self.radio_button_widget.hide()
            self.source_label.hide()
            self.output_group.adjustSize()

        # signals
        self.radio_button_production.clicked.connect(self.populate_combo_box)
        self.radio_button_development.clicked.connect(self.populate_combo_box)

        # creating progress dialog for download
        self.progress_dialog = QProgressDialog(self)
        self.progress_dialog.setAutoClose(False)
        self.progress_dialog.setWindowTitle(title)

        # 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)

        # set up the validator for the file name prefix
        expression = QRegExp('^[A-Za-z0-9-_]*$')
        validator = QRegExpValidator(expression, self.filename_prefix)
        self.filename_prefix.setValidator(validator)
        self.time_stamp = None
        self.restore_state()
开发者ID:akbargumbira,项目名称:inasafe,代码行数:58,代码来源:peta_bencana_dialog.py

示例9: generate_impact_map_report

def generate_impact_map_report(impact_function, iface):
    """Generate impact map pdf from impact function.

    :param impact_function: The impact function used.
    :type impact_function: ImpactFunction

    :param iface: QGIS QGisAppInterface instance.
    :type iface: QGisAppInterface
    """
    # create impact report instance
    report_metadata = ReportMetadata(
        metadata_dict=map_report_component(report_a4_blue))
    impact_report = ImpactReport(
        iface,
        report_metadata,
        impact_function=impact_function)

    # Get other setting
    logo_path = setting('organisation_logo_path', None, str)
    impact_report.inasafe_context.organisation_logo = logo_path

    disclaimer_text = setting('reportDisclaimer', None, str)
    impact_report.inasafe_context.disclaimer = disclaimer_text

    north_arrow_path = setting('north_arrow_path', None, str)
    impact_report.inasafe_context.north_arrow = north_arrow_path

    # get the extent of impact layer
    impact_report.qgis_composition_context.extent = \
        impact_function.impact.extent()

    # generate report folder

    # no other option for now
    # TODO: retrieve the information from data store
    if isinstance(impact_function.datastore.uri, QDir):
        layer_dir = impact_function.datastore.uri.absolutePath()
    else:
        # No other way for now
        return

    # We will generate it on the fly without storing it after datastore
    # supports
    impact_report.output_folder = os.path.join(layer_dir, 'output')
    return impact_report.process_components()
开发者ID:ismailsunni,项目名称:inasafe,代码行数:45,代码来源:analysis_utilities.py

示例10: add_impact_layers_to_canvas

def add_impact_layers_to_canvas(impact_function, group=None, iface=None):
    """Helper method to add impact layer to QGIS from impact function.

    :param impact_function: The impact function used.
    :type impact_function: ImpactFunction

    :param group: An existing group as a parent, optional.
    :type group: QgsLayerTreeGroup

    :param iface: QGIS QgisAppInterface instance.
    :type iface: QgisAppInterface
    """
    layers = impact_function.outputs
    name = impact_function.name

    if group:
        group_analysis = group
    else:
        # noinspection PyArgumentList
        root = QgsProject.instance().layerTreeRoot()
        group_analysis = root.insertGroup(0, name)
        group_analysis.setItemVisibilityChecked(True)

    group_analysis.setExpanded(group is None)

    for layer in layers:
        # noinspection PyArgumentList
        QgsProject.instance().addMapLayer(layer, False)
        layer_node = group_analysis.addLayer(layer)

        # set layer title if any
        try:
            title = layer.keywords['title']
            if qgis_version() >= 21800:
                layer.setName(title)
            else:
                layer.setLayerName(title)
        except KeyError:
            pass

        visible_layers = [impact_function.impact.id()]
        print_atlas = setting('print_atlas_report', False, bool)
        if print_atlas:
            visible_layers.append(impact_function.aggregation_summary.id())
        # Let's enable only the more detailed layer. See #2925
        if layer.id() in visible_layers:
            layer_node.setItemVisibilityChecked(True)
        else:
            layer_node.setItemVisibilityChecked(False)

        # we need to set analysis_impacted as an active layer because we need
        # to get all qgis variables that we need from this layer for
        # infographic.
        if iface:
            iface.setActiveLayer(impact_function.analysis_impacted)
开发者ID:inasafe,项目名称:inasafe,代码行数:55,代码来源:analysis_utilities.py

示例11: restore_boolean_setting

    def restore_boolean_setting(self, key, check_box):
        """Set check_box according to setting of key.

        :param key: Key to retrieve setting value.
        :type key: str

        :param check_box: Check box to show and set the setting.
        :type check_box: PyQt5.QtWidgets.QCheckBox.QCheckBox
        """
        flag = setting(key, expected_type=bool, qsettings=self.settings)
        check_box.setChecked(flag)
开发者ID:inasafe,项目名称:inasafe,代码行数:11,代码来源:options_dialog.py

示例12: restore_text_setting

    def restore_text_setting(self, key, line_edit):
        """Set line_edit text according to setting of key.

        :param key: Key to retrieve setting value.
        :type key: str

        :param line_edit: Line edit for user to edit the setting
        :type line_edit: PyQt5.QtWidgets.QLineEdit.QLineEdit
        """
        value = setting(key, expected_type=str, qsettings=self.settings)
        line_edit.setText(value)
开发者ID:inasafe,项目名称:inasafe,代码行数:11,代码来源:options_dialog.py

示例13: test_get_value

    def test_get_value(self):
        """Test we can get a value from a QSettings."""
        # The expected type does not match the default value.
        try:
            self.assertEqual(
                'default_value',
                setting('test', 'default_value', bool, self.qsetting))
        except Exception:
            self.assertTrue(True)
        else:
            self.assertTrue(False)

        self.assertEqual(
            'default_value',
            setting('test', 'default_value', str, self.qsetting))

        self.assertIsNone(
            setting('test', None, str, self.qsetting))

        # Without default value.
        self.assertIsNone(setting('test', qsettings=self.qsetting))
开发者ID:ismailsunni,项目名称:inasafe,代码行数:21,代码来源:test_settings.py

示例14: read_settings

    def read_settings(self):
        """Set the IF state from QSettings."""
        extent = setting('user_extent', None, str)
        if extent:
            extent = QgsGeometry.fromWkt(extent)
            if not extent.isGeosValid():
                extent = None

        crs = setting('user_extent_crs', None, str)
        if crs:
            crs = QgsCoordinateReferenceSystem(crs)
            if not crs.isValid():
                crs = None

        mode = setting('analysis_extents_mode', HAZARD_EXPOSURE_VIEW)
        if crs and extent and mode == HAZARD_EXPOSURE_BOUNDINGBOX:
            self.extent.set_user_extent(extent, crs)

        self.extent.show_rubber_bands = setting(
            'showRubberBands', False, bool)

        self.zoom_to_impact_flag = setting('setZoomToImpactFlag', True, bool)

        # whether exposure layer should be hidden after model completes
        self.hide_exposure_flag = setting('setHideExposureFlag', False, bool)
开发者ID:timlinux,项目名称:inasafe,代码行数:25,代码来源:step_fc90_analysis.py

示例15: current_earthquake_model_name

def current_earthquake_model_name():
    """Human friendly name for the currently active earthquake fatality model.

    :returns: Name of the current EQ fatality model as defined in users
        settings.
    """
    default_earthquake_function = setting(
        'earthquake_function', expected_type=str)
    current_function = None
    for model in EARTHQUAKE_FUNCTIONS:
        if model['key'] == default_earthquake_function:
            current_function = model['name']
    return current_function
开发者ID:ismailsunni,项目名称:inasafe,代码行数:13,代码来源:earthquake.py


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