예제 #1
0
 def on_restore_default_settings_btn_clicked(self):
     msg = ("All current settings will be deleted and replaced by defaults."
            " Are you sure?")
     reply = QMessageBox.question(self, 'Warning', msg, QMessageBox.Yes,
                                  QMessageBox.No)
     if reply == QMessageBox.Yes:
         self.restore_state(restore_defaults=True)
예제 #2
0
 def delete(self):
     ret = QMessageBox.question(self.tree, 'Delete layer',
             'Are you sure you want to delete this layer from this branch?',
             QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
     if ret == QMessageBox.No:
         return
     execute(lambda: self._removeLayer())
 def on_calc_action_btn_clicked(self, calc_id, action):
     # NOTE: while scrolling through the list of calculations, the tool
     # keeps polling and refreshing the list, without losing the current
     # scrolling.  But if you click on any button, at the next refresh, the
     # view is scrolled to the top. Therefore we need to keep track of which
     # line was selected, in order to scroll to that line.
     self.current_calc_id = self.pointed_calc_id = calc_id
     self._set_show_calc_params_btn()
     self.highlight_and_scroll_to_calc_id(calc_id)
     if action == 'Console':
         self.update_output_list(calc_id)
         self.console_dlg = ShowConsoleDialog(self, calc_id)
         self.console_dlg.setWindowTitle(
             'Console log of calculation %s' % calc_id)
         self.console_dlg.show()
     elif action == 'Remove':
         confirmed = QMessageBox.question(
             self,
             'Remove calculation?',
             'The calculation will be removed permanently. Are you sure?',
             QMessageBox.Yes | QMessageBox.No)
         if confirmed == QMessageBox.Yes:
             self.remove_calc(calc_id)
             if self.current_calc_id == calc_id:
                 self.clear_output_list()
     elif action == 'Outputs':
         self.update_output_list(calc_id)
     elif action == 'Continue':
         self.update_output_list(calc_id)
         self.run_calc(calc_id)
     else:
         raise NotImplementedError(action)
 def on_purge_chk_stateChanged(self, state):
     if state:
         reply = QMessageBox.question(
             self, 'Warning!',
             "Are you sure to delete the empty zones from the zonal layer?",
             QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
         if reply == QMessageBox.No:
             self.purge_chk.setCheckState(0)
예제 #5
0
 def on_reload_homepage_btn_clicked(self):
     msg = ("Reloading the homepage, all current changes will be discarded."
            " Are you sure?")
     reply = QMessageBox.question(self, 'Warning', msg, QMessageBox.Yes,
                                  QMessageBox.No)
     if reply == QMessageBox.Yes:
         self.set_host()
         self.load_homepage()
예제 #6
0
 def delete(self):
     ret = QMessageBox.question(self.tree, 'Delete branch',
             'Are you sure you want to delete this branch?',
             QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
     if ret == QMessageBox.No:
         return
     self.repo.deletebranch(self.branch)
     repoWatcher.repoChanged.emit(self.repo)
예제 #7
0
def confirm_overwrite(parent, files):
    """
    Open a dialog to ask for user's confirmation on file overwriting
    """
    return QMessageBox.question(
        parent, 'Overwrite existing files?',
        'If you continue the following files will be '
        'overwritten: %s\n\n'
        'Continue?' % '\n'.join(files), QMessageBox.Yes | QMessageBox.No)
예제 #8
0
    def deleteCurrentElement(self):
        if len(self.repoTree.selectedItems()) == 0:
            return

        item = self.repoTree.selectedItems()[0]
        if isinstance(item, RepoItem):
            ret = QMessageBox.warning(
                config.iface.mainWindow(), "Remove repository",
                "Are you sure you want to remove this repository and all the data in it?",
                QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
            if ret == QMessageBox.No:
                return
            tracked = getTrackedPathsForRepo(item.repo)
            item.repo.delete()
            removeRepo(item.repo)
            removeTrackedForRepo(item.repo)
            layers = getVectorLayers()
            for layer in layers:
                if formatSource(layer) in tracked:
                    setAsNonRepoLayer(layer)
            parent = item.parent()
            parent.removeChild(item)
            self.updateCurrentRepo(None)
        elif isinstance(item, GroupItem):
            self._removeRepoEndpoint(item)
        elif isinstance(item, BranchItem):
            ret = QMessageBox.question(
                self, 'Delete branch',
                'Are you sure you want to delete this branch?',
                QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
            if ret == QMessageBox.No:
                return
            item.repo.deletebranch(item.branch)
            repoWatcher.repoChanged.emit(item.repo)

        elif isinstance(item, LayerItem):
            ret = QMessageBox.question(
                self, 'Delete layer',
                'Are you sure you want to delete this layer from the selected branch?',
                QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
            if ret == QMessageBox.No:
                return
            execute(lambda: self._removeLayer(item))
 def deleteGeoGigServer(self):
     group = self.comboEndpoint.currentText()
     res = QMessageBox.question(
         None, "Delete server?", "Are you sure you want to remove the "
         "'{}' GeoGig server from the list?".format(group),
         QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
     if res == QMessageBox.Yes:
         removeRepoEndpoint(group)
         self.comboEndpoint.removeItem(self.comboEndpoint.currentIndex())
         self.fillTree()
         self._enableOrDisableButtons()
 def deleteGeoGigServer(self):
     group = self.comboEndpoint.currentText()
     res = QMessageBox.question(None,
                               "Delete server?",
                               "Are you sure you want to remove the "
                               "'{}' GeoGig server from the list?".format(group),
                               QMessageBox.Yes | QMessageBox.No,
                               QMessageBox.No)
     if res == QMessageBox.Yes:
         removeRepoEndpoint(group)
         self.comboEndpoint.removeItem(self.comboEndpoint.currentIndex())
         self.fillTree()
         self._enableOrDisableButtons()
예제 #11
0
 def remove_selected_profile(self, platform_or_engine):
     assert platform_or_engine in ('platform', 'engine'), platform_or_engine
     if QMessageBox.question(
             self, 'Remove connection profile',
         ('If you continue, the selected profile will be permanently'
          ' deleted. Are you sure?'),
             QMessageBox.Yes | QMessageBox.No) != QMessageBox.Yes:
         return
     profiles = json.loads(QSettings().value('irmt/%s_profiles' %
                                             platform_or_engine))
     if platform_or_engine == 'platform':
         cur_profile = self.platform_profile_cbx.currentText()
     else:  # engine
         cur_profile = self.engine_profile_cbx.currentText()
     del profiles[cur_profile]
     QSettings().remove('irmt/current_%s_profile' % platform_or_engine)
     self.save_profiles(platform_or_engine, profiles)
     self.refresh_profile_cbxs(platform_or_engine)
예제 #12
0
def confirmation_on_close(parent, event=None):
    """
    Open a QMessageBox to confirm closing a dialog discarding changes

    :param parent: the parent dialog that is being closed
    :param event: event that triggered this dialog (e.g. reject or closeEvent)
    """
    msg = tr("WARNING: all unsaved changes will be lost. Are you sure?")
    reply = QMessageBox.question(parent, 'Message', msg, QMessageBox.Yes,
                                 QMessageBox.No)
    if event is not None:
        if reply == QMessageBox.Yes:
            event.accept()
        else:
            event.ignore()
    else:
        if reply == QMessageBox.Yes:
            parent.__class__.__base__.reject(parent)
예제 #13
0
    def accept(self):
        project_name = self.project_name_le.text()
        if project_name.endswith('.qgs'):
            project_name = project_name[:-4]
        if not project_name:
            QMessageBox.critical(self, self.tr("OQ-Consolidate: Error"),
                                 self.tr("Please specify the project name"))
            return

        outputDir = self.leOutputDir.text()
        if not outputDir:
            QMessageBox.critical(
                self, self.tr("OQ-Consolidate: Error"),
                self.tr("Please specify the output directory."))
            return
        outputDir = os.path.join(outputDir, get_valid_filename(project_name))

        # create main directory if not exists
        d = QDir(outputDir)
        if not d.exists():
            if not d.mkpath("."):
                QMessageBox.critical(
                    self, self.tr("OQ-Consolidate: Error"),
                    self.tr("Can't create directory to store the project."))
                return

        # create directory for layers if not exists
        if d.exists("layers"):
            res = QMessageBox.question(
                self, self.tr("Directory exists"),
                self.tr("Output directory already contains 'layers'"
                        " subdirectory. Maybe this directory was used to"
                        " consolidate another project. Continue?"),
                QMessageBox.Yes | QMessageBox.No)
            if res == QMessageBox.No:
                return
        else:
            if not d.mkdir("layers"):
                QMessageBox.critical(
                    self, self.tr("OQ-Consolidate: Error"),
                    self.tr("Can't create directory for layers."))
                return

        # copy project file
        projectFile = QgsProject.instance().fileName()
        if projectFile:
            f = QFile(projectFile)
            newProjectFile = os.path.join(outputDir, '%s.qgs' % project_name)
            f.copy(newProjectFile)
        else:
            newProjectFile = os.path.join(outputDir, '%s.qgs' % project_name)
            f = QFileInfo(newProjectFile)
            p = QgsProject.instance()
            p.write(f)

        # start consolidate thread that does all real work
        self.workThread = consolidatethread.ConsolidateThread(
            self.iface, outputDir, newProjectFile,
            self.checkBoxZip.isChecked())
        self.workThread.rangeChanged.connect(self.setProgressRange)
        self.workThread.updateProgress.connect(self.updateProgress)
        self.workThread.processFinished.connect(self.processFinished)
        self.workThread.processInterrupted.connect(self.processInterrupted)
        self.workThread.processError.connect(self.processError)
        self.workThread.exceptionOccurred.connect(self.exceptionOccurred)

        self.btnClose.setText(self.tr("Cancel"))
        self.btnOk.setEnabled(False)
        self.buttonBox.rejected.disconnect(self.reject)
        self.btnClose.clicked.connect(self.stopProcessing)

        self.workThread.start()
예제 #14
0
    def accept(self):

        # Check the user entered a folder path
        inputFolder = self.inputLineEdit.text()
        if len(inputFolder) == 0:
            QMessageBox.critical(None, 'No Input Folder Selected',
                                 'Please select an input folder.')
            return
        if not os.path.isdir(inputFolder):
            QMessageBox.critical(
                None, 'Invalid Input Folder',
                '%s is not a valid folder path.' % inputFolder)
            return

        # Check a connection is selected
        if self.postgisConnectionComboBox.count() == 0:
            QMessageBox.critical(
                None, 'No PostGIS Connection Selected',
                'No PostGIS connection was selected. Please configure a connection through Layer > Add PostGIS Layers...'
            )
            return
        self.extractPgConnectionDetails()

        # Ensure destination schema exists - prompt to create it
        self.schema_name = str(self.destSchema.text())
        if len(self.schema_name) == 0:
            QMessageBox.critical(None, 'No Schema Specified',
                                 'Please specify a destination schema.')
            return
        if self.schema_name[0] in string.digits:
            QMessageBox.critical(None, 'Unsupported Schema Name',
                                 'Schema names must not start with a number.')
            return
        for ch in self.schema_name:
            if not ch in string.ascii_lowercase and not ch in string.digits and not ch == '_':
                QMessageBox.critical(
                    None, 'Unsupported Schema Name',
                    'Schema names must currently consist of lower case characters, numbers and underscores.'
                )
                return
        if len(self.schema_name) == 0:
            errMsg = 'No destination schema was specified. Do you wish to import into the public schema?'
            reply = QMessageBox.question(self.parent, 'No Schema Specified',
                                         errMsg,
                                         QMessageBox.Yes | QMessageBox.No,
                                         QMessageBox.No)
            if reply == QMessageBox.No:
                return
            self.schema_name = 'public'

        try:
            cur = get_db_cur(self.dbDetails,
                             self.postgisConnectionComboBox.currentText())
        except:
            QMessageBox.critical(
                None, 'Failed to Connect to Database',
                'Failed to make a connection to the database, detailed error was:\n\n%s'
                % traceback.format_exc())
            return

        for schemaName in [self.schema_name, self.schema_name + '_tmp']:
            try:
                qDic = {'schema_name': schemaName}
                cur.execute(
                    """SELECT schema_name FROM information_schema.schemata WHERE schema_name = %(schema_name)s;""",
                    qDic)
            except:
                QMessageBox.critical(
                    None, 'Failed to Query Schemas',
                    'Failed to determine whether destination already exists, detailed error was:\n\n%s'
                    % traceback.format_exc())
                return
            if cur.rowcount < 1:
                # The schema does not already exist - create it
                try:
                    if not create_schema(cur, schemaName):
                        raise Exception()
                except:
                    QMessageBox.critical(
                        None, 'Failed to Create Schema',
                        'Failed to create schema, detailed error was:\n\n%s' %
                        traceback.format_exc())
                    return

        gfsFilePath = self.buildGfs()

        # If mode is create or replace, issue a warning
        if self.modeComboBox.currentText() == 'Create or Replace':
            qDic['schema_name'] = self.schema_name
            # See if the table exists
            existingTables = []
            for dTable in self.destTables:
                try:
                    qDic['table_name'] = dTable
                    cur.execute(
                        """ SELECT table_name FROM information_schema.tables
                                    WHERE table_schema = %(schema_name)s AND 
                                    table_name = %(table_name)s;""", qDic)
                except:
                    QMessageBox.critical(
                        None, 'Failed to Query Tables',
                        'Failed to determine whether destination table already exists, detailed error was:\n\n%s'
                        % traceback.format_exc())
                    return
                if cur.rowcount > 0:
                    existingTables.append(dTable)
            if len(existingTables) > 0:
                errMsg = "The following tables will be permanently overwritten:\n\n"
                for exTab in existingTables:
                    errMsg += '%s.%s' % (self.schema_name, exTab) + '\n'
                errMsg += "\nDo you wish to proceed?"
                reply = QMessageBox.question(self.parent, 'Overwriting Tables',
                                             errMsg,
                                             QMessageBox.Yes | QMessageBox.No,
                                             QMessageBox.No)
                if reply == QMessageBox.No:
                    return

        inputFiles = get_input_files(str(self.inputLineEdit.text()))
        # Insert a 'pioneer' file which contains a feature of each table type
        inputFiles.insert(
            0, get_pioneer_file(str(self.datasetComboBox.currentText())))

        # Ensure the user has selected some files
        if len(inputFiles) == 0:
            QMessageBox.critical(
                None, 'No Input Files Selected',
                'Failed to find any GML files under the selected folder.')
            return
        """ Add the jobs to the import manager """

        if len(self.dbDetails['user']) == 0:
            user, password = credentials_user_pass(
                self.postgisConnectionComboBox.currentText())
        else:
            user, password = self.dbDetails['user'], self.dbDetails['password']
        pgSource = 'PG:dbname=\'%s\' host=\'%s\' port=\'%d\' active_schema=%s user=\'%s\' password=\'%s\'' % \
            (self.dbDetails['database'], self.dbDetails['host'], self.dbDetails['port'], self.schema_name + '_tmp', user, password)
        # Note we are loading into a temporary schema

        self.im.reset()

        for arg in build_args(inputFiles, gfsFilePath, pgSource,
                              self.ignoreFidCheckBox.checkState()):
            self.im.add(arg)

        try:
            self.im.start(self.simultaneousJobsSpinBox.value())
        except:
            QMessageBox.critical(
                None, 'Failed to Start Process',
                'Failed to start the import process - please ensure you have ogr2ogr installed.'
            )
            return
        self.freezeUi()
        self.progressBar.setEnabled(True)
        self.progressBar.setValue(0)
        self.statusLabel.setText('Loading - grab a snack..')