def add_authentication(self):
        """Slot for when the add auth button is clicked."""
        if qgis_version() >= 21200:
            from qgis.gui import QgsAuthConfigSelect

            dlg = QDialog(self)
            dlg.setWindowTitle(self.tr("Select Authentication"))
            layout = QVBoxLayout(dlg)

            acs = QgsAuthConfigSelect(dlg)
            if self.line_edit_auth_id.text():
                acs.setConfigId(self.line_edit_auth_id.text())
            layout.addWidget(acs)

            button_box = QDialogButtonBox(
                QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
                Qt.Horizontal,
                dlg)
            layout.addWidget(button_box)
            button_box.accepted.connect(dlg.accept)
            button_box.rejected.connect(dlg.close)

            dlg.setLayout(layout)
            dlg.setWindowModality(Qt.WindowModal)
            if dlg.exec_():
                self.line_edit_auth_id.setText(acs.configId())
            del dlg
Example #2
0
 def scripts_folder(self):
     """Return the default processing scripts folder."""
     # Copy the script
     if qgis_version() < 21600:
         return ScriptUtils.scriptsFolder()
     else:
         return ScriptUtils.defaultScriptsFolder()
    def add_authentication(self):
        """Slot for when the add auth button is clicked."""
        if qgis_version() >= 21200:
            from qgis.gui import QgsAuthConfigSelect

            dlg = QDialog(self)
            dlg.setWindowTitle(self.tr("Select Authentication"))
            layout = QVBoxLayout(dlg)

            acs = QgsAuthConfigSelect(dlg)
            if self.line_edit_auth_id.text():
                acs.setConfigId(self.line_edit_auth_id.text())
            layout.addWidget(acs)

            button_box = QDialogButtonBox(
                QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
                Qt.Horizontal,
                dlg)
            layout.addWidget(button_box)
            button_box.accepted.connect(dlg.accept)
            button_box.rejected.connect(dlg.close)

            dlg.setLayout(layout)
            dlg.setWindowModality(Qt.WindowModal)
            if dlg.exec_():
                self.line_edit_auth_id.setText(acs.configId())
            del dlg
Example #4
0
 def refresh_script_provider(self):
     """Refresh the processing script provider."""
     if qgis_version() < 21600:
         from processing.core.Processing import Processing
         Processing.updateAlgsList()
     else:
         from processing.core.alglist import algList
         algList.reloadProvider('script')
    def __init__(self, parent=None):
        """Create the dialog and configure the UI."""
        super(ManageRepositoryDialog, self).__init__(parent)
        self.setupUi(self)
        self.line_edit_url.setText('http://')
        self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
        self.line_edit_name.textChanged.connect(self.form_changed)
        self.line_edit_url.textChanged.connect(self.form_changed)
        self.button_add_auth.clicked.connect(self.add_authentication)
        self.button_clear_auth.clicked.connect(self.line_edit_auth_id.clear)

        if qgis_version() < 21200:
            self.disable_authentication()
    def __init__(self, parent=None):
        """Create the dialog and configure the UI."""
        super(ManageRepositoryDialog, self).__init__(parent)
        self.setupUi(self)
        self.line_edit_url.setText('http://')
        self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
        self.line_edit_name.textChanged.connect(self.form_changed)
        self.line_edit_url.textChanged.connect(self.form_changed)
        self.button_add_auth.clicked.connect(self.add_authentication)
        self.button_clear_auth.clicked.connect(self.line_edit_auth_id.clear)

        if qgis_version() < 21200:
            self.disable_authentication()
Example #7
0
    def fetch(self):
        """Fetch the content (in the background).
        :return: (status, error message)
        :rtype: (boolean, string)
        """
        # Initialize some properties again
        self._content = None
        self._network_finished = False
        self._network_timeout = False

        request = QNetworkRequest(QUrl(self._url))
        request.setAttribute(
            QNetworkRequest.CacheLoadControlAttribute,
            QNetworkRequest.AlwaysNetwork)

        if self._auth_cfg and qgis_version() >= 21200:
            LOGGER.debug('Update request with auth_cfg %s' % self._auth_cfg)
            QgsAuthManager.instance().updateNetworkRequest(
                request, self._auth_cfg
            )

        self._reply = self._network_manager.get(request)
        self._reply.finished.connect(self.fetch_finished)
        self._network_manager.requestTimedOut.connect(self.request_timeout)

        while not self._reply.isFinished():
            # noinspection PyArgumentList
            QCoreApplication.processEvents()

        # Finished
        description = None
        if self._reply.error() != QNetworkReply.NoError:
            status = False
            description = self._reply.errorString()
        else:
            status = True
            self._content = self._reply.readAll()

        self._reply.deleteLater()

        return status, description
Example #8
0
 def uninstall(self):
     """Uninstall the symbols from QGIS."""
     # Get the parent group id (not relevant for QGIS 3)
     group_or_tag_id = self._get_parent_group_or_tag()
     # Get the ids of the groups / tags that contain symbols
     child_groups_or_tags_ids = self._get_child_groups_tags_ids()
     for child_group_id in child_groups_or_tags_ids:
         # Get all the symbols from this tag / child group and remove them
         symbols = self._get_symbols_for_group_or_tag(
             QgsStyle.SymbolEntity, child_group_id)
         for symbol in symbols:
             self.style.removeSymbol(symbol)
         # Get all the colorramps for this tag / child group and remove them
         colorramps = self._get_symbols_for_group_or_tag(
             QgsStyle.ColorrampEntity, child_group_id)
         for colorramp in colorramps:
             self.style.removeColorRamp(colorramp)
         # textformat and labelsettings were introduced in QGIS 3.10
         if qgis_version() < 31000:
             # Remove this tag / child group
             self._group_or_tag_remove(child_group_id)
             continue
         # Get all the textformats for this tag / child group
         # and remove them
         textformats = self._get_symbols_for_group_or_tag(
             QgsStyle.TextFormatEntity, child_group_id)
         for textformat in textformats:
             self.style.removeTextFormat(textformat)
         # Get all the labelsettings for this tag / child group
         # and remove them
         labelsettings = self._get_symbols_for_group_or_tag(
             QgsStyle.LabelSettingsEntity, child_group_id)
         for labelsetting in labelsettings:
             self.style.removeLabelSettings(labelsetting)
         # Remove this tag / child group
         self._group_or_tag_remove(child_group_id)
     # Remove the group / tag:
     self._group_or_tag_remove(group_or_tag_id)
    def fetch(self):
        """Fetch the content."""
        # Initialize some properties again
        self._content = None
        self._network_finished = False
        self._network_timeout = False

        request = QNetworkRequest(QUrl(self._url))
        request.setAttribute(
            QNetworkRequest.CacheLoadControlAttribute,
            QNetworkRequest.AlwaysNetwork)

        if self._auth_cfg and qgis_version() >= 21200:
            LOGGER.info('Update request with auth_cfg %s' % self._auth_cfg)
            QgsAuthManager.instance().updateNetworkRequest(
                request, self._auth_cfg
            )

        self._reply = self._network_manager.get(request)
        self._reply.finished.connect(self.fetch_finished)
        self._network_manager.requestTimedOut.connect(self.request_timeout)

        while not self._reply.isFinished():
            # noinspection PyArgumentList
            QCoreApplication.processEvents()

        # Finished
        description = None
        if self._reply.error() != QNetworkReply.NoError:
            status = False
            description = self._reply.errorString()
        else:
            status = True
            self._content = self._reply.readAll()

        self._reply.deleteLater()

        return status, description
Example #10
0
    def install(self):
        """Install the symbols from this collection in the QGIS default style.

        For QGIS 2, a group with the name of the collection is created,
        and for each of the XML files in the collection, a child group
        is created, where the symbols and colorramps defined in the XML
        file are stored.
        For QGIS 3, for each of the XML files in the collection, a tag
        is created, and the tag is used for the symbols and colorramps
        defined in that XML file.
        """
        # Skip installation if the directory does not exist
        if not Path(self.resource_dir).exists():
            return
        # Uninstall first (in case it is a reinstall)
        self.uninstall()
        # Get all the symbol XML files in the collection
        symbol_files = []
        valid = 0
        for item in Path(self.resource_dir).glob("*.xml"):
            symbol_files.append(item)
            valid += 1
        # If there are no symbol files, there is nothing to do
        if len(symbol_files) == 0:
            return
        # Only relevant for QGIS 2!
        group_or_tag_id = self._get_parent_group_or_tag()
        for symbol_file in symbol_files:
            file_name = symbol_file.stem
            # Groups in QGIS2, tags in QGIS3...
            groupOrTag_id = self._get_child_group_tag(group_or_tag_id,
                                                      file_name)
            # Modify the symbol file to fix image and SVG paths
            self.resolve_dependency(str(symbol_file))
            # Add all symbols and colorramps and group / tag them
            symbol_xml_extractor = SymbolXMLExtractor(str(symbol_file))
            for symbol in symbol_xml_extractor.symbols:
                symbol_name = "%s (%s)" % (
                    symbol["name"],
                    self.collection["repository_name"],
                )
                # self.resolve_dependency(symbol[SYMBOL])
                if self.style.addSymbol(symbol_name, symbol[SYMBOL], True):
                    self._group_or_tag(QgsStyle.SymbolEntity, symbol_name,
                                       groupOrTag_id)
            for colorramp in symbol_xml_extractor.colorramps:
                colorramp_name = "%s (%s)" % (
                    colorramp["name"],
                    self.collection["repository_name"],
                )
                if self.style.addColorRamp(colorramp_name,
                                           colorramp["colorramp"], True):
                    self._group_or_tag(QgsStyle.ColorrampEntity,
                                       colorramp_name, groupOrTag_id)
            # textformat and labelsettings were introduced in QGIS 3.10
            if qgis_version() < 31000:
                continue
            for textformat in symbol_xml_extractor.textformats:
                textformat_name = "%s (%s)" % (
                    textformat["name"],
                    self.collection["repository_name"],
                )
                if self.style.addTextFormat(textformat_name,
                                            textformat["textformat"], True):
                    self._group_or_tag(QgsStyle.TextFormatEntity,
                                       textformat_name, groupOrTag_id)
            for labelsetting in symbol_xml_extractor.labelsettings:
                labelsetting_name = "%s (%s)" % (
                    labelsetting["name"],
                    self.collection["repository_name"],
                )
                if self.style.addLabelSettings(labelsetting_name,
                                               labelsetting["labelsettings"],
                                               True):
                    self._group_or_tag(QgsStyle.LabelSettingsEntity,
                                       labelsetting_name, groupOrTag_id)
        if valid >= 0:
            self.collection[SYMBOL] = valid