Пример #1
0
 def save_to_filewriter_json(self):
     filename = file_dialog(True, "Save Filewriter JSON File",
                            JSON_FILE_TYPES)
     if filename:
         with open(filename, "w") as file:
             filewriter_json_writer.write_nexus_structure_to_json(
                 self.instrument, file)
Пример #2
0
 def save_to_forwarder_json(self):
     filename = file_dialog(True, "Save Forwarder JSON File",
                            JSON_FILE_TYPES)
     if filename:
         provider_type, ok_pressed = QInputDialog.getItem(
             None,
             "Provider type",
             "Select provider type for PVs",
             ["ca", "pva"],
             0,
             False,
         )
         default_broker, ok_pressed = QInputDialog.getText(
             None,
             "Default broker",
             "Default Broker: (This will only be used for streams that do not already have a broker)",
             text="broker:port",
             echo=QLineEdit.Normal,
         )
         if ok_pressed:
             with open(filename, "w") as file:
                 nexus_constructor.json.forwarder_json_writer.generate_forwarder_command(
                     file,
                     self.instrument.nexus.entry,
                     provider_type=provider_type,
                     default_broker=default_broker,
                 )
Пример #3
0
    def save_to_filewriter_json(self):
        filename = file_dialog(True, "Save Filewriter JSON File",
                               JSON_FILE_TYPES)
        if filename:
            dialog = QDialog()
            dialog.setModal(True)
            dialog.setLayout(QGridLayout())
            command_widget = FilewriterCommandWidget()
            dialog.layout().addWidget(command_widget)

            dialog.exec_()
            (
                nexus_file_name,
                broker,
                start_time,
                stop_time,
                service_id,
                abort_on_uninitialised_stream,
                use_swmr,
            ) = command_widget.get_arguments()
            with open(filename, "w") as file:
                filewriter_json_writer.generate_json(
                    self.instrument,
                    file,
                    nexus_file_name=nexus_file_name,
                    broker=broker,
                    start_time=start_time,
                    stop_time=stop_time,
                    service_id=service_id,
                    abort_uninitialised=abort_on_uninitialised_stream,
                    use_swmr=use_swmr,
                )
 def mesh_file_picker(self):
     """
     Opens the mesh file picker. Sets the file name line edit to the file path.
     :return: None
     """
     filename = file_dialog(False, "Open Mesh", GEOMETRY_FILE_TYPES)
     self.cad_file_name = filename
     self.fileLineEdit.setText(filename)
Пример #5
0
    def save_to_filewriter_json(self):
        filename = file_dialog(True, "Save File writer JSON File",
                               JSON_FILE_TYPES)

        if filename:
            if not filename.endswith(".json"):
                filename += ".json"
            error_collector: List[str] = []
            data_dump = json.dumps(self.model.as_dict(error_collector),
                                   indent=2)
            if error_collector:
                show_errors_message(error_collector)
                return
            with open(filename, "w") as file:
                file.write(data_dump)
Пример #6
0
 def open_json_file(self):
     filename = file_dialog(False, "Open File Writer JSON File",
                            JSON_FILE_TYPES)
     if filename:
         reader = JSONReader()
         success = reader.load_model_from_json(filename)
         if reader.warnings:
             show_warning_dialog(
                 "\n".join((json_warning.message
                            for json_warning in reader.warnings)),
                 "Warnings encountered loading JSON",
                 parent=self,
             )
         if success:
             self.model = reader.model
             self._setup_model_signals()
             self._update_views()
Пример #7
0
    def open_json_file(self):
        filename = file_dialog(False, "Open File Writer JSON File",
                               JSON_FILE_TYPES)
        if filename:
            with open(filename, "r") as json_file:
                json_data = json_file.read()

                try:
                    nexus_file = json_to_nexus(json_data)
                except Exception as exception:
                    show_warning_dialog(
                        "Provided file not recognised as valid JSON",
                        "Invalid JSON",
                        f"{exception}",
                        parent=self,
                    )
                    return

                existing_file = self.instrument.nexus.nexus_file
                if self.instrument.nexus.load_nexus_file(nexus_file):
                    self._update_views()
                    existing_file.close()
Пример #8
0
 def open_nexus_file(self):
     filename = file_dialog(False, "Open Nexus File", NEXUS_FILE_TYPES)
     existing_file = self.instrument.nexus.nexus_file
     if self.instrument.nexus.open_file(filename):
         self._update_views()
         existing_file.close()
Пример #9
0
 def open_idf_file(self):
     filename = file_dialog(False, "Open IDF file", {"IDF files": ["xml"]})
     self._load_idf(filename)
Пример #10
0
 def save_to_nexus_file(self):
     filename = file_dialog(True, "Save Nexus File", NEXUS_FILE_TYPES)
     self.instrument.nexus.save_file(filename)