Esempio 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))
Esempio n. 2
0
    def do_export_plan_action(self, count_id):
        plan_creator = PlanCreator(self.layers)
        file_dialog = QFileDialog()
        file_dialog.setDefaultSuffix('*.PDF')
        title = 'Exporter plan de pose'
        path = os.path.join(self.settings.value('config_export_directory'),
                            "{}.pdf".format("plan_de_pose"))
        file = QFileDialog.getSaveFileName(file_dialog, title, path,
                                           "Config file (*.PDF)")[0]

        if not file:
            return

        # Highlight the current sections and installation in the layout
        previous_highlightes_sections = self.layers.highlighted_sections
        self.layers.highlighted_sections = \
            self.layers.get_section_ids_of_count(count_id)
        QgsExpressionContextUtils.setProjectVariable(
            QgsProject.instance(), 'highlighted_installation',
            self.layers.get_installation_name_of_count(count_id))

        plan_creator.export_pdf(count_id, file)

        self.layers.highlighted_sections = previous_highlightes_sections
        QgsExpressionContextUtils.setProjectVariable(
            QgsProject.instance(), 'highlighted_installation', '')
        self.layers.layers['section'].triggerRepaint()
Esempio 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))
Esempio n. 4
0
 def saveDataToFile(self, data: List[List[Any]]) -> None:
     """
     Write data to a  file.
     """
     file_window = QFileDialog()
     file_window.setAcceptMode(1)
     file_window.setDefaultSuffix('csv')
     file_window.setNameFilters(['CSV Files (*.csv)', 'All Files (*)'])
     if file_window.exec_() == 0:
         return
     file_name = file_window.selectedFiles()[0]
     csv_file = open(file_name, 'wt')
     csv_writer = csv.writer(csv_file, delimiter=',')
     for i in data:
         csv_writer.writerow([x for x in i])
     csv_file.close()
Esempio n. 5
0
    def export_profile(self):
        """ Export minimum needs to a json file.

        This method will save the current state of the minimum needs setup.
        Then open a dialog allowing the user to browse to the desired
        destination location and allow the user to save the needs as a json
        file.
        """
        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')
        file_name = None
        if file_name_dialog.exec_():
            file_name = file_name_dialog.selectedFiles()[0]
        if file_name != '' and file_name is not None:
            self.minimum_needs.write_to_file(file_name)
Esempio n. 6
0
    def export_profile(self):
        """ Export minimum needs to a json file.

        This method will save the current state of the minimum needs setup.
        Then open a dialog allowing the user to browse to the desired
        destination location and allow the user to save the needs as a json
        file.
        """
        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')
        file_name = None
        if file_name_dialog.exec_():
            file_name = file_name_dialog.selectedFiles()[0]
        if file_name != '' and file_name is not None:
            self.minimum_needs.write_to_file(file_name)
Esempio n. 7
0
    def do_export_configuration_action(self, count_id):
        config_creator = ConfigCreatorCmd(self.layers, count_id)
        config_creator.set_section_commands()

        installation_name = self.layers.get_installation_name_of_count(
            count_id)

        file_dialog = QFileDialog()
        file_dialog.setDefaultSuffix('*.CMD')
        title = 'Exporter la configuration'
        path = os.path.join(self.settings.value('config_export_directory'),
                            "{}.CMD".format(installation_name))
        file = QFileDialog.getSaveFileName(file_dialog, title, path,
                                           "Config file (*.CMD)")[0]

        if not file:
            return

        config_creator.write_file(file)
        push_info('Written config file {}'.format(file))
Esempio n. 8
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
Esempio n. 9
0
    def do_generate_report_action(self, count_id):
        if self.tm.countActiveTasks() > 0:
            push_info(("Veuillez patienter jusqu'à ce que l'importation "
                       "soit terminée."))
            return
        file_dialog = QFileDialog()
        file_dialog.setDefaultSuffix('*.xlsx')
        title = 'Exporter un rapport'
        path = os.path.join(
            self.settings.value('report_export_directory'),
            "{}.xlsx".format("report"))
        file_path = QFileDialog.getSaveFileName(
            file_dialog, title, path, "Rapport (*.XLSX)")[0]

        if not file_path:
            return

        report_creator = ReportCreator(count_id, file_path, self.layers)
        report_creator.run()
        push_info(("Exportation rappport terminée."))
Esempio n. 10
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)
Esempio n. 11
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)