Ejemplo n.º 1
0
 def createDialog(self):
     print("")
     print("-------------------------")
     print("----- Create dialog -----")
     print("-------------------------")
     button = self.__options.checkedButton()
     mode = button.property("Mode")
     if mode == Mode.DEFAULT_FILEDIALOG:
         dialog = qt.QFileDialog(self)
         dialog.setAcceptMode(qt.QFileDialog.AcceptOpen)
     elif mode == Mode.IMAGEFILEDIALOG:
         dialog = ImageFileDialog(self)
     elif mode == Mode.DATAFILEDIALOG:
         dialog = DataFileDialog(self)
     elif mode == Mode.DATAFILEDIALOG_DATASET:
         dialog = DataFileDialog(self)
         dialog.setFilterMode(DataFileDialog.FilterMode.ExistingDataset)
     elif mode == Mode.DATAFILEDIALOG_GROUP:
         dialog = DataFileDialog(self)
         dialog.setFilterMode(DataFileDialog.FilterMode.ExistingGroup)
     elif mode == Mode.DATAFILEDIALOG_NXENTRY:
         def customFilter(obj):
             if "NX_class" in obj.attrs:
                 return obj.attrs["NX_class"] in [b"NXentry", u"NXentry"]
             return False
         dialog = DataFileDialog(self)
         dialog.setFilterMode(DataFileDialog.FilterMode.ExistingGroup)
         dialog.setFilterCallback(customFilter)
     else:
         assert(False)
     return dialog
Ejemplo n.º 2
0
    def read_or_write_file(self):

        value = self.H5_FILE_DUMP

        if value == 0:
            return
        elif value == 1: # write
            return
        elif value == 2: # read

            self.H5_FILE_DUMP = 0


            tmp = ConfirmDialog.confirmed(self,
                    message="Please select in a hdf5 file a data block\n(such as XOPPY_RADIATION)\nthat contains a 'Radiation' entry",
                    title="Confirm Action")
            if tmp == False: return

            dialog = DataFileDialog(self)
            dialog.setFilterMode(DataFileDialog.FilterMode.ExistingGroup)
            # dialog.setDirectory("")
            # Execute the dialog as modal
            result = dialog.exec_()

            if result:
                print("Selection:")
                print(dialog.selectedFile())
                print(dialog.selectedUrl())
                print(dialog.selectedDataUrl().data_path())

                calculation_output = self.extract_data_from_h5file(dialog.selectedFile(), dialog.selectedDataUrl().data_path() )


                if calculation_output is None:
                    raise Exception("Bad data from file.")
                else:
                    self.calculated_data = self.extract_data_from_xoppy_output(calculation_output)

                    try:
                        self.set_fields_from_h5file(dialog.selectedFile(), dialog.selectedDataUrl().data_path())
                    except:
                        pass

                    # self.add_specific_content_to_calculated_data(self.calculated_data)
                    #
                    self.setStatusMessage("Plotting Results")

                    self.plot_results(self.calculated_data, progressBarValue=60)

                    self.setStatusMessage("")

                    self.send("xoppy_data", self.calculated_data)


                self.set_enabled(True)
    def read_file(self):
        try:
            dialog = DataFileDialog(self)
            dialog.setFilterMode(DataFileDialog.FilterMode.ExistingGroup)

            path, filename = os.path.split(self.file_name)
            print("Setting path: ", path)
            dialog.setDirectory(path)

            # Execute the dialog as modal
            result = dialog.exec_()
            if result:
                print("Selection:")
                print(dialog.selectedFile())
                print(dialog.selectedUrl())
                print(dialog.selectedDataUrl().data_path())
                self.file_name = dialog.selectedFile()
                self.data_path = dialog.selectedDataUrl().data_path()
                self.send_data()
        except Exception as e:
            QMessageBox.critical(self, "Error", str(e.args[0]), QMessageBox.Ok)
Ejemplo n.º 4
0
    def read_or_write_file(self):

        value = self.H5_FILE_DUMP

        if value == 0:
            return
        elif value == 1:  # write
            return
        elif value == 2:  # read

            self.H5_FILE_DUMP = 0

            tmp = ConfirmDialog.confirmed(
                self,
                message=
                "Please select in a hdf5 file a data block\n(such as XOPPY_RADIATION)\nthat contains a 'Radiation' entry",
                title="Confirm Action")
            if tmp == False: return

            dialog = DataFileDialog(self)
            dialog.setFilterMode(DataFileDialog.FilterMode.ExistingGroup)
            # dialog.setDirectory("")
            # Execute the dialog as modal
            result = dialog.exec_()

            if result:
                print("Selection:")
                print(dialog.selectedFile())
                print(dialog.selectedUrl())
                print(dialog.selectedDataUrl().data_path())

                calculation_output = self.extract_data_from_h5file(
                    dialog.selectedFile(),
                    dialog.selectedDataUrl().data_path())

                if calculation_output is None:
                    raise Exception("Bad data from file.")
                else:
                    self.calculated_data = self.extract_data_from_xoppy_output(
                        calculation_output)

                    try:
                        self.set_fields_from_h5file(
                            dialog.selectedFile(),
                            dialog.selectedDataUrl().data_path())
                    except:
                        pass

                    # self.add_specific_content_to_calculated_data(self.calculated_data)
                    #
                    self.setStatusMessage("Plotting Results")

                    self.plot_results(self.calculated_data,
                                      progressBarValue=60)

                    self.setStatusMessage("")

                    self.send("xoppy_data", self.calculated_data)

                self.set_enabled(True)
Ejemplo n.º 5
0
    def read_or_write_file(self):

        value = self.H5_FILE_DUMP

        if value == 0:
            return
        elif value == 1:  # write
            return
        elif value == 2:  # read

            self.H5_FILE_DUMP = 0

            use_silx_file_dialog = False  # silx dialog is freezing the linux system, change to traditional

            if use_silx_file_dialog:
                tmp = ConfirmDialog.confirmed(
                    self,
                    message=
                    "Please select in a hdf5 file a data block\n(such as XOPPY_RADIATION)\nthat contains a 'Radiation' entry",
                    title="Confirm Action")
                if tmp == False: return
                dialog = DataFileDialog(self)
                dialog.setFilterMode(DataFileDialog.FilterMode.ExistingGroup)
                result = dialog.exec_()
                if not result:
                    return
                print(dialog.selectedFile())
                print(dialog.selectedUrl())
                print(dialog.selectedDataUrl().data_path())
                calculation_output = self.extract_data_from_h5file(
                    dialog.selectedFile(),
                    dialog.selectedDataUrl().data_path())
                self.filename = dialog.selectedFile()
            else:
                tmp = ConfirmDialog.confirmed(
                    self,
                    message=
                    "Please select a hdf5 file containing a data block\n named XOPPY_RADIATION which includes 'Radiation' entry",
                    title="Confirm Action")
                if tmp == False: return

                self.filename = oasysgui.selectFileFromDialog(
                    self,
                    previous_file_path=self.filename,
                    message="Open hdf5 File",
                    start_directory="",
                    file_extension_filter="*.*5")
                if self.filename == "":
                    return

                try:
                    calculation_output = self.extract_data_from_h5file(
                        self.filename, "/XOPPY_RADIATION")
                except:
                    QMessageBox.critical(
                        self, "Error",
                        str("Failed to load hdf5 /XOPPY_RADIATION"),
                        QMessageBox.Ok)
                    calculation_output = None

            if calculation_output is None:
                QMessageBox.critical(self, "Error", str("Bad data from file."),
                                     QMessageBox.Ok)
            else:
                self.calculated_data = self.extract_data_from_xoppy_output(
                    calculation_output)
                try:
                    self.set_fields_from_h5file(self.filename,
                                                "/XOPPY_RADIATION")
                except:
                    QMessageBox.critical(
                        self, "Error",
                        "Failed to set fields hdf5 /XOPPY_RADIATION/parameters \n",
                        QMessageBox.Ok)

                # self.add_specific_content_to_calculated_data(self.calculated_data)
                #
                self.setStatusMessage("Plotting Results")

                self.plot_results(self.calculated_data, progressBarValue=60)

                self.setStatusMessage("")

                # p, e, h, v = self.calculated_data.get_content("xoppy_data")
                # traj = self.calculated_data.get_content("xoppy_data")
                # data_to_send = DataExchangeObject("XOPPY", self.get_data_exchange_widget_name())
                # data_to_send.add_content("xoppy_data", [p, e, h, v, traj])
                self.send("xoppy_data", self.calculated_data)

            self.set_enabled(True)