Exemplo n.º 1
0
    def qmb_exclude_geometries():
        """
        :return:
        """
        msgBox = QMessageBox()
        msgBox.setText(
            'Choose which type of polygons you would like to delete? All polygons based on your selection will be deleted!'
        )
        msgBox.setWindowTitle("BAWS (%s) Question" % __version__)
        red_button = msgBox.addButton('Only red', QMessageBox.YesRole)
        yellow_button = msgBox.addButton('Only yellow', QMessageBox.NoRole)
        both_button = msgBox.addButton('Both red and yellow',
                                       QMessageBox.ActionRole)
        cancel_button = msgBox.addButton('Cancel', QMessageBox.RejectRole)
        msgBox.exec_()

        if msgBox.clickedButton() == red_button:
            return [3]
        elif msgBox.clickedButton() == yellow_button:
            return [2]
        elif msgBox.clickedButton() == both_button:
            return [2, 3]
        elif msgBox.clickedButton() == cancel_button:
            return []
        else:
            return []
Exemplo n.º 2
0
    def closeEvent(self, event):
        if self.isRecalculating or self.configurationHasChanged:
            return
        if self.unsavedChanges:
            msgBox = QMessageBox()
            msgBox.setIcon(QMessageBox.Information)
            msgBox.setWindowTitle(self.tr('Nicht gespeicherte Aenderungen'))
            msgBox.setText(self.tr('Moechten Sie die Ergebnisse speichern?'))
            msgBox.setStandardButtons(QMessageBox.Cancel | QMessageBox.No
                                      | QMessageBox.Yes)
            cancelBtn = msgBox.button(QMessageBox.Cancel)
            cancelBtn.setText(self.tr("Abbrechen"))
            noBtn = msgBox.button(QMessageBox.No)
            noBtn.setText(self.tr("Nein"))
            yesBtn = msgBox.button(QMessageBox.Yes)
            yesBtn.setText(self.tr("Ja"))
            msgBox.show()
            msgBox.exec()

            if msgBox.clickedButton() == yesBtn:
                self.onSave()
                self.drawTool.reset()
            elif msgBox.clickedButton() == cancelBtn:
                event.ignore()
                return
            elif msgBox.clickedButton() == noBtn:
                self.drawTool.reset()
        else:
            self.drawTool.reset()

        self.timer.stop()
Exemplo n.º 3
0
    def qmb_change_attribute_value():
        """
        :return:
        """
        msgBox = QMessageBox()
        msgBox.setText('Swap geometry class values with..')
        msgBox.setWindowTitle("BAWS (%s) Question" % __version__)
        red_button = msgBox.addButton('Red (3)', QMessageBox.YesRole)
        yellow_button = msgBox.addButton('Yellow (2)', QMessageBox.NoRole)
        cancel_button = msgBox.addButton('Cancel', QMessageBox.RejectRole)
        msgBox.exec_()

        if msgBox.clickedButton() == red_button:
            return 3
        elif msgBox.clickedButton() == yellow_button:
            return 2
        elif msgBox.clickedButton() == cancel_button:
            return None
        else:
            return None
Exemplo n.º 4
0
 def custom_ask(parent, title, question, *buttons_labels):
     """Ask for custom operation confirmation."""
     msg_box = QMessageBox(parent)
     msg_box.setIcon(QMessageBox.Question)
     msg_box.setWindowTitle(title)
     msg_box.setTextFormat(Qt.RichText)
     msg_box.setText(question)
     for button_txt in buttons_labels:
         msg_box.addButton(QPushButton(button_txt), QMessageBox.YesRole)
     msg_box.exec_()
     clicked_button = msg_box.clickedButton()
     clicked_button_text = clicked_button.text()
     return clicked_button_text
Exemplo n.º 5
0
    def qmb_reanalysis():
        """
        :return:
        """
        msgBox = QMessageBox()
        msgBox.setText(
            'You have selected an old date. \nWould you like to load raw data or old data from a previous production work?'
        )
        msgBox.setWindowTitle("BAWS (%s) Question" % __version__)
        raw_button = msgBox.addButton('Raw data', QMessageBox.YesRole)
        old_button = msgBox.addButton('Old production data',
                                      QMessageBox.NoRole)
        cancel_button = msgBox.addButton('Cancel', QMessageBox.RejectRole)
        msgBox.exec_()

        if msgBox.clickedButton() == raw_button:
            return 'raw'
        elif msgBox.clickedButton() == old_button:
            return 'old'
        elif msgBox.clickedButton() == cancel_button:
            return None
        else:
            return None
Exemplo n.º 6
0
    def mergePullRequest(self):
        # import pydevd
        # pydevd.settrace('localhost', port=65432, stdoutToServer=True, stderrToServer=True,
        #                 trace_only_current_thread=False, overwrite_prev_trace=True, patch_multiprocessing=True,
        #                 suspend=False)
        pr = self.prs[self.comboPr.currentText()]
        merged = self.server.mergePullRequest(self.user, self.repo, pr["id"])
        if not merged:
            msgBox = QMessageBox()
            msgBox.setText("Conflicts in PR")
            msgBox.setInformativeText(
                "There are conflicts.\n"
                "Source repo needs to be synchronized and conflicts solved.\n"
                "This will modify the source repo.")
            msgBox.setIcon(QMessageBox.Warning)
            syncButton = msgBox.addButton("Continue", QMessageBox.ActionRole)
            abortButton = msgBox.addButton(QMessageBox.Abort)

            msgBox.exec_()

            if msgBox.clickedButton() == syncButton:
                # do sync
                syncDialog = SynchronizeDialog(
                    pr["sourceRepo"]["owner"]["identity"],
                    pr["sourceRepo"]["identity"], self.server,
                    pr["targetRepo"]["owner"]["identity"],
                    pr["targetRepo"]["identity"], False)
                syncDialog.exec_()
                if syncDialog.synced:
                    self.mergePullRequest()
                else:
                    self.close()
            elif msgBox.clickedButton() == abortButton:
                self.close()
        else:
            self.close()
Exemplo n.º 7
0
 def onRemoveParameterSet(self):
     currParamset = self.fieldParamSet.currentText()
     # No action if there is no parameter set specified
     if currParamset == '':
         return
     # Standard set cannot be deleted
     if currParamset == self.paramHandler.defaultSet:
         QMessageBox.critical(self, self.tr('Parameterset loeschen'),
             self.tr('Standardparameterset kann nicht geloescht werden.'), QMessageBox.Ok)
         return
     
     # Ask before removing
     msgBox = QMessageBox()
     msgBox.setIcon(QMessageBox.Information)
     msgBox.setWindowTitle(self.tr('Parameterset loeschen'))
     msgBox.setText(self.tr('Moechten Sie das Parameterset wirklich loeschen?'))
     msgBox.setStandardButtons(QMessageBox.No | QMessageBox.Yes)
     noBtn = msgBox.button(QMessageBox.No)
     noBtn.setText(self.tr("Nein"))
     yesBtn = msgBox.button(QMessageBox.Yes)
     yesBtn.setText(self.tr("Ja"))
     msgBox.show()
     msgBox.exec()
     
     if msgBox.clickedButton() == yesBtn:
         success = self.paramHandler.removeParameterSet(currParamset)
         if not success:
             QMessageBox.critical(self, self.tr('Parameterset loeschen'),
                 self.tr('Ein Fehler ist aufgetreten. Parameterset kann nicht geloescht werden.'), QMessageBox.Ok)
         else:
             # Set default set
             self.paramHandler.setParameterSet(self.paramHandler.defaultSet)
             # Update drop down list to remove set
             self.fillParametersetList()
             # Fill in values of default set
             self.fillInValues()
             # Deactivate / Activate status of field HMKran depending on
             #  point type of start point
             self.updateHMKran(self.projectHandler.A_type)
    def installFromZipFile(self, filePath):
        if not os.path.isfile(filePath):
            return

        settings = QgsSettings()
        settings.setValue(settingsGroup + '/lastZipDirectory',
                          QFileInfo(filePath).absoluteDir().absolutePath())

        with zipfile.ZipFile(filePath, 'r') as zf:
            pluginName = os.path.split(zf.namelist()[0])[0]

        pluginFileName = os.path.splitext(os.path.basename(filePath))[0]

        if not pluginName:
            msg_box = QMessageBox()
            msg_box.setIcon(QMessageBox.Warning)
            msg_box.setWindowTitle(self.tr("QGIS Python Install from ZIP Plugin Installer"))
            msg_box.setText(self.tr("The Zip file is not a valid QGIS python plugin. No root folder was found inside."))
            msg_box.setStandardButtons(QMessageBox.Ok)
            more_info_btn = msg_box.addButton(self.tr("More Information"), QMessageBox.HelpRole)
            msg_box.exec()
            if msg_box.clickedButton() == more_info_btn:
                QgsHelp.openHelp("plugins/plugins.html#the-install-from-zip-tab")
            return

        pluginsDirectory = qgis.utils.home_plugin_path
        if not QDir(pluginsDirectory).exists():
            QDir().mkpath(pluginsDirectory)

        pluginDirectory = QDir.cleanPath(os.path.join(pluginsDirectory, pluginName))

        # If the target directory already exists as a link,
        # remove the link without resolving
        QFile(pluginDirectory).remove()

        password = None
        infoString = None
        success = False
        keepTrying = True

        while keepTrying:
            try:
                # Test extraction. If fails, then exception will be raised and no removing occurs
                unzip(filePath, pluginsDirectory, password)
                # Removing old plugin files if exist
                removeDir(pluginDirectory)
                # Extract new files
                unzip(filePath, pluginsDirectory, password)
                keepTrying = False
                success = True
            except Exception as e:
                success = False
                if 'password' in str(e):
                    infoString = self.tr('Aborted by user')
                    if 'Bad password' in str(e):
                        msg = self.tr('Wrong password. Please enter a correct password to the zip file.')
                    else:
                        msg = self.tr('The zip file is encrypted. Please enter password.')
                    # Display a password dialog with QgsPasswordLineEdit
                    dlg = QDialog()
                    dlg.setWindowTitle(self.tr('Enter password'))
                    buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal)
                    buttonBox.rejected.connect(dlg.reject)
                    buttonBox.accepted.connect(dlg.accept)
                    lePass = QgsPasswordLineEdit()
                    layout = QVBoxLayout()
                    layout.addWidget(QLabel(msg))
                    layout.addWidget(lePass)
                    layout.addWidget(buttonBox)
                    dlg.setLayout(layout)
                    keepTrying = dlg.exec_()
                    password = lePass.text()
                else:
                    infoString = self.tr("Failed to unzip the plugin package\n{}.\nProbably it is broken".format(filePath))
                    keepTrying = False

        if success:
            updateAvailablePlugins()
            self.processDependencies(pluginName)
            loadPlugin(pluginName)
            plugins.getAllInstalled()
            plugins.rebuild()

            if settings.contains('/PythonPlugins/' + pluginName):
                if settings.value('/PythonPlugins/' + pluginName, False, bool):
                    startPlugin(pluginName)
                    reloadPlugin(pluginName)
                else:
                    unloadPlugin(pluginName)
                    loadPlugin(pluginName)
            else:
                if startPlugin(pluginName):
                    settings.setValue('/PythonPlugins/' + pluginName, True)

            self.exportPluginsToManager()
            msg = "<b>%s</b>" % self.tr("Plugin installed successfully")
        else:
            msg = "<b>%s:</b> %s" % (self.tr("Plugin installation failed"), infoString)

        level = Qgis.Info if success else Qgis.Critical
        iface.pluginManagerInterface().pushMessage(msg, level)
    def installBaseMap(self):
        authcfg = get_oauth_authcfg()
        if authcfg is None:
            self._showMessage('Could not find a valid authentication configuration!',
                              QgsMessageBar.WARNING)
            return False

        authId = authcfg.id()
        mapBoxStreets = basemaputils.getMapBoxStreetsMap(self.token)

        if os.path.isfile(basemaputils.defaultProjectPath()):
            # default project already exists, make a backup copy
            backup = basemaputils.defaultProjectPath().replace(
                '.qgs', '-%s.qgs' % datetime.now().strftime('%Y-%m-%d-%H_%M_%S'))
            shutil.copy2(basemaputils.defaultProjectPath(), backup)
            self._showMessage("A backup copy of the previous default project "
                              "has been saved to {}".format(backup))

            msgBox = QMessageBox()
            msgBox.setIcon(QMessageBox.Question)
            msgBox.setText("A default project already exists.  Do you "
                           "wish to add the Boundless basemap to your "
                           "existing default project or create a new "
                           "default project?")
            btnAdd = msgBox.addButton("Add", QMessageBox.ActionRole)
            btnCreateNew = msgBox.addButton("Create New", QMessageBox.ActionRole)
            msgBox.exec_()
            if msgBox.clickedButton() == btnAdd:
                if not basemaputils.addToDefaultProject([mapBoxStreets], ["Mapbox Streets"], authId):
                    self._showMessage("Could not update default project with basemap!",
                                      QgsMessageBar.WARNING)
                    return False
            elif msgBox.clickedButton() == btnCreateNew:
                template = basemaputils.PROJECT_DEFAULT_TEMPLATE

                prj = basemaputils.createDefaultProject([mapBoxStreets], ["Mapbox Streets"],
                                                        template, authId)
                if prj is None or prj == '':
                    self._showMessage("Could not create a valid default project from the template '{}'!".format(template),
                                      QgsMessageBar.WARNING)
                    return False

                if not basemaputils.writeDefaultProject(prj):
                    self._showMessage("Could not write the default project on disk!",
                                      QgsMessageBar.WARNING)
                    return False
        else:
            # no default project, create one
            template = basemaputils.PROJECT_DEFAULT_TEMPLATE

            prj = basemaputils.createDefaultProject([mapBoxStreets], ["Mapbox Streets"],
                                               template, authId)
            if prj is None or prj == '':
                self._showMessage("Could not create a valid default project from the template '{}'!".format(template),
                                  QgsMessageBar.WARNING)
                return False

            if not basemaputils.writeDefaultProject(prj):
                self._showMessage("Could not write the default project on disk!",
                                  QgsMessageBar.WARNING)
                return False

        self._showMessage("Basemap added to the default project.")
        return True