Exemplo n.º 1
0
 def save_profile_as(self):
     """Save the minimum needs under a new profile name.
     """
     # noinspection PyCallByClass,PyTypeChecker
     file_name_dialog = QFileDialog(self)
     file_name_dialog.setAcceptMode(QFileDialog.AcceptSave)
     file_name_dialog.setNameFilter(self.tr('JSON files (*.json *.JSON)'))
     file_name_dialog.setDefaultSuffix('json')
     dir = os.path.join(QgsApplication.qgisSettingsDirPath(),
                        'inasafe', 'minimum_needs')
     file_name_dialog.setDirectory(expanduser(dir))
     if file_name_dialog.exec_():
         file_name = file_name_dialog.selectedFiles()[0]
     else:
         return
     file_name = basename(file_name)
     file_name = file_name.replace('.json', '')
     minimum_needs = {'resources': []}
     self.mark_current_profile_as_saved()
     for index in range(self.resources_list.count()):
         item = self.resources_list.item(index)
         minimum_needs['resources'].append(item.resource_full)
     minimum_needs['provenance'] = self.provenance.text()
     minimum_needs['profile'] = file_name
     self.minimum_needs.update_minimum_needs(minimum_needs)
     self.minimum_needs.save()
     self.minimum_needs.save_profile(file_name)
     if self.profile_combo.findText(file_name) == -1:
         self.profile_combo.addItem(file_name)
     self.profile_combo.setCurrentIndex(
         self.profile_combo.findText(file_name))
Exemplo n.º 2
0
 def on_selectFilePushButton_clicked(self):
     """
     Selects the correct way to choose files according to the type
     """
     fd = QFileDialog()
     fd.setDirectory(QDir.homePath())
     if self.type == 'multi':
         self.fileNameList = fd.getOpenFileNames(caption=self.caption,
                                                 filter=self.filter)
         selectedFiles = ', '.join(self.fileNameList[0])
     elif self.type == 'single':
         selectedFiles = fd.getOpenFileName(caption=self.caption,
                                            filter=self.filter)
         if selectedFiles != '':
             self.fileNameList = selectedFiles
     elif self.type == 'dir':
         selectedFiles = fd.getExistingDirectory(
             directory=os.path.expanduser('~'),
             caption=self.caption,
             options=QFileDialog.ShowDirsOnly)
         if selectedFiles != '':
             self.fileNameList = [selectedFiles]
     selectedFiles = selectedFiles[0] if isinstance(
         selectedFiles, tuple) else selectedFiles
     self.lineEdit.setText(selectedFiles)
     self.filesSelected.emit()
Exemplo n.º 3
0
 def save_profile_as(self):
     """Save the minimum needs under a new profile name.
     """
     # noinspection PyCallByClass,PyTypeChecker
     file_name_dialog = QFileDialog(self)
     file_name_dialog.setAcceptMode(QFileDialog.AcceptSave)
     file_name_dialog.setNameFilter(self.tr('JSON files (*.json *.JSON)'))
     file_name_dialog.setDefaultSuffix('json')
     dir = os.path.join(QgsApplication.qgisSettingsDirPath(),
                        'inasafe', 'minimum_needs')
     file_name_dialog.setDirectory(expanduser(dir))
     if file_name_dialog.exec_():
         file_name = file_name_dialog.selectedFiles()[0]
     else:
         return
     file_name = basename(file_name)
     file_name = file_name.replace('.json', '')
     minimum_needs = {'resources': []}
     self.mark_current_profile_as_saved()
     for index in range(self.resources_list.count()):
         item = self.resources_list.item(index)
         minimum_needs['resources'].append(item.resource_full)
     minimum_needs['provenance'] = self.provenance.text()
     minimum_needs['profile'] = file_name
     self.minimum_needs.update_minimum_needs(minimum_needs)
     self.minimum_needs.save()
     self.minimum_needs.save_profile(file_name)
     if self.profile_combo.findText(file_name) == -1:
         self.profile_combo.addItem(file_name)
     self.profile_combo.setCurrentIndex(
         self.profile_combo.findText(file_name))
Exemplo n.º 4
0
 def selectDatasource(self):
     """
     Opens dialog for file/directory selection.
     """
     # model of implementation for reimplementation
     fd = QFileDialog()
     fd.setDirectory(QDir.homePath())
     fd.setFileMode(QFileDialog.AnyFile)
     filename, __ = fd.getSaveFileName(caption=self.caption,
                                       filter=self.filter)
     if filename:
         self.dsLineEdit.setText(filename)
     self.loadDatabase(currentText=filename)
 def chooseMPIDir(self) -> None:
     """Choose MPI directory."""
     title = QSWATUtils.trans('Select MPI bin directory')
     if self._dlg.MPIBox.text() != '':
         startDir = os.path.split(self._dlg.MPIBox.text())[0]
     elif os.path.isdir(self.mpiexecDir):
         startDir = os.path.split(self.mpiexecDir)[0]
     else:
         startDir = None
     dlg = QFileDialog(None, title)
     if startDir is not None:
         dlg.setDirectory(startDir)
     dlg.setFileMode(QFileDialog.Directory)
     if dlg.exec_():
         dirs = dlg.selectedFiles()
         mpiexecDir = dirs[0]
         self._dlg.MPIBox.setText(mpiexecDir)
         self.mpiexecDir = mpiexecDir
Exemplo n.º 6
0
def GetOutputFileName(clss, box_name, file_types, default_type, start_path):
    dlg = QFileDialog(clss)
    dlg.setDirectory(start_path)
    dlg.setWindowTitle(box_name)
    dlg.setViewMode(QFileDialog.Detail)
    a = []
    for i in file_types:
        a.append(clss.tr(i))
    dlg.setNameFilters(a)
    dlg.setDefaultSuffix(default_type)
    new_name = None
    extension = None
    if dlg.exec_():
        new_name = dlg.selectedFiles()[0]
        new_name = new_name.replace("..", ".")
        if new_name[-4] == ".":
            extension = new_name[-3:]
        else:
            extension = new_name[-4:]
    return new_name, extension
Exemplo n.º 7
0
    def import_profile(self):
        """ Import minimum needs from an existing json file.

        The minimum needs are loaded from a file into the table. This state
        is only saved if the form is accepted.
        """
        # noinspection PyCallByClass,PyTypeChecker
        file_name_dialog = QFileDialog(self)
        file_name_dialog.setAcceptMode(QFileDialog.AcceptOpen)
        file_name_dialog.setNameFilter(self.tr('JSON files (*.json *.JSON)'))
        file_name_dialog.setDefaultSuffix('json')
        path_name = resources_path('minimum_needs')
        file_name_dialog.setDirectory(path_name)
        if file_name_dialog.exec_():
            file_name = file_name_dialog.selectedFiles()[0]
        else:
            return -1

        if self.minimum_needs.read_from_file(file_name) == -1:
            return -1

        self.clear_resource_list()
        self.populate_resource_list()
        self.switch_context(self.profile_edit_page)
Exemplo n.º 8
0
    def import_profile(self):
        """ Import minimum needs from an existing json file.

        The minimum needs are loaded from a file into the table. This state
        is only saved if the form is accepted.
        """
        # noinspection PyCallByClass,PyTypeChecker
        file_name_dialog = QFileDialog(self)
        file_name_dialog.setAcceptMode(QFileDialog.AcceptOpen)
        file_name_dialog.setNameFilter(self.tr('JSON files (*.json *.JSON)'))
        file_name_dialog.setDefaultSuffix('json')
        path_name = resources_path('minimum_needs')
        file_name_dialog.setDirectory(path_name)
        if file_name_dialog.exec_():
            file_name = file_name_dialog.selectedFiles()[0]
        else:
            return -1

        if self.minimum_needs.read_from_file(file_name) == -1:
            return -1

        self.clear_resource_list()
        self.populate_resource_list()
        self.switch_context(self.profile_edit_page)