Ejemplo n.º 1
0
def load_config_file():
    options = QFileDialog.Option()
    options |= QFileDialog.DontUseNativeDialog
    fn_conf, _ = QFileDialog.getOpenFileName(tomo,
                                             "QFileDialog.getOpenFileName()",
                                             "",
                                             "json files (*.json)",
                                             options=options)
    if fn_conf:
        print(fn_conf)
        fn_relative = fn_conf.split('/')[-1]
        tomo.lb_conf.setText('{} loaded'.format(fn_relative))

        with open(fn_conf) as f:
            conf = json.load(f)
            tomo.tx_zd.setText(str(conf['ZONE_DIAMETER']))
            tomo.tx_zd.setStyleSheet('color: rgb(80, 80, 80);')
            tomo.tx_zw.setText(str(conf['OUT_ZONE_WIDTH']))
            tomo.tx_zw.setStyleSheet('color: rgb(80, 80, 80);')
            tomo.tx_mag.setText(str(conf['GLOBAL_MAG']))
            tomo.tx_mag.setStyleSheet('color: rgb(80, 80, 80);')
            tomo.tx_vlm.setText(str(conf['GLOBAL_VLM_MAG']))
            tomo.tx_vlm.setStyleSheet('color: rgb(80, 80, 80);')
            tomo.tx_elow.setText(str(conf['Eng_L']))
            tomo.tx_elow.setStyleSheet('color: rgb(80, 80, 80);')
            tomo.tx_ehigh.setText(str(conf['Eng_H']))
            tomo.tx_ehigh.setStyleSheet('color: rgb(80, 80, 80);')
        f.close()
Ejemplo n.º 2
0
    def set_dir(self):
        parent_path_old = self.path if self.folder_mode else str(
            Path(self.path[0]).parent)
        if self.folder_mode:
            options = QFileDialog.Option()
            options |= QFileDialog.ShowDirsOnly
            options |= QFileDialog.HideNameFilterDetails
            update_path = QFileDialog.getExistingDirectory(
                caption="Select Folder",
                directory=parent_path_old,
                options=options)
        elif self.multiple_files:
            paths = QFileDialog.getOpenFileNames(caption="Select Files",
                                                 directory=parent_path_old,
                                                 filter=self.file_ending)
            # qt returns a list of ([path, path, ...], filter) when we use a filter
            update_path = paths[0]
        else:
            paths = QFileDialog.getOpenFileName(caption="Select File",
                                                directory=parent_path_old,
                                                filter=self.file_ending)
            update_path = paths[0]

        # dont update path if cancel is pressed
        if update_path != [] and update_path != "":
            self.update_dir(update_path)
Ejemplo n.º 3
0
 def findDir(self):
     options = QFileDialog.Option()
     options |= QFileDialog.ShowDirsOnly
     working_path1 = QFileDialog.getExistingDirectory(self, "select Dir")
     global d1
     d1 = working_path1
     self.label_3.setText(working_path1)
     print(d1)
Ejemplo n.º 4
0
 def findDir2(self):
     options = QFileDialog.Option()
     options |= QFileDialog.ShowDirsOnly
     working_path2 = QFileDialog.getExistingDirectory(self, "select Dir")
     global d2
     d2 = working_path2
     self.label_4.setText(working_path2)
     print(d2)
Ejemplo n.º 5
0
 def on_bTest_clicked(self):
     """
     Private method to test the selected options.
     """
     if self.rOpenFile.isChecked() or self.rfOpenFile.isChecked():
         if not self.cSymlinks.isChecked():
             options = QFileDialog.Options(QFileDialog.DontResolveSymlinks)
         else:
             options = QFileDialog.Options()
         options = self.__adjustOptions(options)
         if self.rOpenFile.isChecked() and self.__pyqtVariant == 4:
             QFileDialog.getOpenFileName(None, self.eCaption.text(),
                                         self.eStartWith.text(),
                                         self.eFilters.text(), options)
         else:
             QFileDialog.getOpenFileNameAndFilter(
                 None, self.eCaption.text(), self.eStartWith.text(),
                 self.eFilters.text(), self.eInitialFilter.text(), options)
     elif self.rOpenFiles.isChecked() or self.rfOpenFiles.isChecked():
         if not self.cSymlinks.isChecked():
             options = QFileDialog.Options(QFileDialog.DontResolveSymlinks)
         else:
             options = QFileDialog.Options()
         options = self.__adjustOptions(options)
         if self.rOpenFiles.isChecked() and self.__pyqtVariant == 4:
             QFileDialog.getOpenFileNames(None, self.eCaption.text(),
                                          self.eStartWith.text(),
                                          self.eFilters.text(), options)
         else:
             QFileDialog.getOpenFileNamesAndFilter(
                 None, self.eCaption.text(), self.eStartWith.text(),
                 self.eFilters.text(), self.eInitialFilter.text(), options)
     elif self.rSaveFile.isChecked() or self.rfSaveFile.isChecked():
         if not self.cSymlinks.isChecked():
             options = QFileDialog.Options(QFileDialog.DontResolveSymlinks)
         else:
             options = QFileDialog.Options()
         options = self.__adjustOptions(options)
         if self.rSaveFile.isChecked() and self.__pyqtVariant == 4:
             QFileDialog.getSaveFileName(None, self.eCaption.text(),
                                         self.eStartWith.text(),
                                         self.eFilters.text(), options)
         else:
             QFileDialog.getSaveFileNameAndFilter(
                 None, self.eCaption.text(), self.eStartWith.text(),
                 self.eFilters.text(), self.eInitialFilter.text(), options)
     elif self.rDirectory.isChecked():
         options = QFileDialog.Options()
         if not self.cSymlinks.isChecked():
             options |= QFileDialog.Options(QFileDialog.DontResolveSymlinks)
         if self.cDirOnly.isChecked():
             options |= QFileDialog.Options(QFileDialog.ShowDirsOnly)
         else:
             options |= QFileDialog.Options(QFileDialog.Option(0))
         options = self.__adjustOptions(options)
         QFileDialog.getExistingDirectory(None, self.eCaption.text(),
                                          self.eWorkDir.text(), options)
Ejemplo n.º 6
0
 def dosya_ekle(self):
     options = QFileDialog.Option()
     options |= QFileDialog.DontUseNativeDialog
     filename, _ = QFileDialog.getSaveFileName(self,
                                               "",
                                               "",
                                               options=options)
     if filename:
         self.bli(filename + " Dosyası Eklendi ")
         self.FileName = filename
 def getfiles(self):
     dlg = QFileDialog.Option()
     fileName, _ = QFileDialog.getOpenFileName(
         self,
         "QFileDialog.getOpenFileName()",
         "",
         "All Files (*);;Python Files (*.py)",
         options=dlg)
     if fileName:
         print(fileName)
Ejemplo n.º 8
0
 def openFileNameDialog(self):
     options = QFileDialog.Option()
     options |= QFileDialog.DontUseNativeDialog
     filename, _ = QFileDialog.getOpenFileName(
         self.w,
         "Product Image",
         "",
         "PNG (*.png);;JPEG (*.jpg);;JPEG (*.jpeg)",
         options=options)
     if filename:
         self.filename = filename
         self.fname.emit(self)
Ejemplo n.º 9
0
 def saveFile(self):
     options = QFileDialog.Option()
     options |= QFileDialog.DontUseNativeDialog
     fileName, _ = QFileDialog.getSaveFileName(
         self,
         "QFileDialog.getSaveFileName()",
         "",
         "All Files(*);;Text Files(*.txt)",
         options=options)
     f = open(fileName, 'w')
     text = self.ui.textEdit.toPlainText()
     f.write(text)
     f.close()
Ejemplo n.º 10
0
 def abrirShp(
     self
 ):  #Funcion que abre cuadro de dialogo para buscar las muestras de entrenamiento
     options = QFileDialog.Option()
     options |= QFileDialog.DontUseNativeDialog
     fichero = QtWidgets.QFileDialog.getOpenFileName(
         self,
         "Abrir Fichero",
         "",
         "Mapa de referencia(*.tif);;All Files (*)",
         options=options)
     if fichero[0] != '':
         self.rutaSHPMuestras = fichero[0]
         self.mapa.addItem(self.rutaSHPMuestras, 1)
         self.mapa.setCurrentText(self.rutaSHPMuestras)
Ejemplo n.º 11
0
 def saveCSVFileDialog(self):
     options = QFileDialog.Option()
     options |= QFileDialog.DontUseNativeDialog
     fileName, _ = QFileDialog.getSaveFileName(
         self,
         "QFileDialog.getSaveFileName()",
         "",
         "All Files(*);;Text Files (*.txt)",
         options=options)
     msg = self.logTextBox.getTexttoFile()  #retrieve the current list
     if fileName:
         splitMsg = msg.split('\n')  #split msg if they are in new row
         with open(fileName, 'w', newline='') as outfile:
             writer = csv.writer(outfile)
             for text in splitMsg:
                 writer.writerow([text])
Ejemplo n.º 12
0
 def pegarArquivo(self):
     self.lineEdit.setText("")
     option = QFileDialog.Option()
     widget = QWidget()
     self.file = QFileDialog.getOpenFileName(widget,
                                             "Pegar legenda",
                                             "",
                                             "srt (*.srt)",
                                             options=option)
     self.lineEdit.setText(self.file[0])
     self.label_2.setStyleSheet(
         "background-color: rgb(255, 255, 255);\n"
         "image: url(:/newPrefix/icons8-baby-yoda-50.png);")
     self.labelSucesso.setText("")
     self.pushButton.isEnabled = True
     self.pushButton.setText("Limpar")
Ejemplo n.º 13
0
 def abrirShp(
     self
 ):  #Funcion que abre cuadro de dialogo para buscar las muestras de entrenamiento
     options = QFileDialog.Option()
     options |= QFileDialog.DontUseNativeDialog
     fichero = QtWidgets.QFileDialog.getOpenFileName(
         self,
         "Abrir Fichero",
         "",
         "Shapefile Muestras(*.shp);;All Files (*)",
         options=options)
     if fichero[0] != '':
         self.rutaSHPMuestras = fichero[0]
         self.itemLayers.addItem(self.rutaSHPMuestras, 1)
         self.itemLayers.setCurrentText(self.rutaSHPMuestras)
         #self.textMuestras.setText(self.rutaSHPMuestras)
         self.actualizarComboBox()
Ejemplo n.º 14
0
    def saveFile(self):
        #Guardar archivo txt

        options = QFileDialog.Option()
        #Ventana distinta a la nativa
        options = QFileDialog.DontUseNativeDialog

        filesave, _ = QFileDialog.getSaveFileName(self,
                                                  "Guardar archivo",
                                                  "c:\\",
                                                  "Archivos txt (*.txt)",
                                                  options=options)

        #filesave ----> directorio

        f = open(filesave, 'w')
        with f:
            #Guardamos el archivo con la información de textedit
            f.write(self.textedit.toPlainText())  #Indica texto plano
Ejemplo n.º 15
0
 def abrir(
     self
 ):  #Funcion que abre cuadro de dialogo para el mapa de cobertura del suelo (raster o vector)
     options = QFileDialog.Option()
     options |= QFileDialog.DontUseNativeDialog
     fichero = QtWidgets.QFileDialog.getOpenFileName(self,
                                                     "Abrir Fichero",
                                                     "",
                                                     ";;All Files (*)",
                                                     options=options)
     if fichero[0] != '':
         if str(os.path.splitext(fichero[0])[1]) == ".tif" or str(
                 os.path.splitext(fichero[0])[1]) == ".TIF" or str(
                     os.path.splitext(fichero[0])[1]) == ".shp" or str(
                         os.path.splitext(fichero[0])[1]) == ".SHP":
             self.rutaCSVSuperficie = fichero[0]
             self.itemSuperficie.addItem(self.rutaCSVSuperficie, 1)
             self.itemSuperficie.setCurrentText(self.rutaCSVSuperficie)
         else:
             QMessageBox.information(self, "Error",
                                     "Tipo de archivo no permitido",
                                     QMessageBox.Ok)
Ejemplo n.º 16
0
    def load_image(self):
        options = QFileDialog.Option()
        options |= QFileDialog.DontUseNativeDialog
        if self.rd_hdf.isChecked() == True: file_type = 'hdf files (*.h5)'
        else: file_type = 'tiff files (*.tif)'

        fn, _ = QFileDialog.getOpenFileName(tomo,
                                            "QFileDialog.getOpenFileName()",
                                            "",
                                            file_type,
                                            options=options)
        self.img_bkg = np.array([])
        self.img_tomo = np.array([])
        self.img_align = np.array([])
        self.img_recon = np.array([])
        if fn:
            print(fn)
            fn_relative = fn.split('/')[-1]
            self.lb_ip.setText('{} loaded'.format(fn_relative))
            if self.rd_hdf.isChecked() == True:  # read hdf file
                f = h5py.File(fn, 'r')
                try:
                    self.img_tomo = np.array(f['img_tomo'])
                except:
                    self.img_tomo = np.zeros([1, 100, 100])
                    print('bkg image not exist')
                try:
                    self.img_bkg = np.array(f['img_bkg_raw'])
                except:
                    self.img_bkg = np.zeros([self.img_tomo.shape])
                    print('tomo image not exist')

                f.close()
            else:  # read tiff file
                self.img_tomo = np.array(io.imread(fn))

            if self.img_tomo.shape[0] > 0:
                print('total images: ' + str(self.img_tomo.shape[0]))
Ejemplo n.º 17
0
 def openImageBrowser(self):
     try:
         ImageBrowser = QFileDialog()
         options = ImageBrowser.Option()
         options |= ImageBrowser.DontUseNativeDialog
         ImageBrowser.setFileMode(QFileDialog.ExistingFiles)
         ImageBrowser.setNameFilter(
             ("All Files (*);;Images (*.jpeg *.jpg *.png *.gif)"))
         if ImageBrowser.exec_():
             self.SelectedFileList = ImageBrowser.selectedFiles()
         if len(self.SelectedFileList) == 0:
             return
         self.SelectedFile = self.SelectedFileList[0]
         if self.SelectedFile.split('.')[-1] not in [
                 "jpeg", "jpg", "png", "gif"
         ]:
             QMessageBox.information(None, "Warning",
                                     "Not a valid image file",
                                     QMessageBox.Ok)
         self.ImageEdit.setText(self.SelectedFile)
     except Exception as err:
         print(err)
         QMessageBox.information(None, "Warning", "File did not selected",
                                 QMessageBox.Ok)
Ejemplo n.º 18
0
 def on_bTest_clicked(self):
     """
     Private method to test the selected options.
     """
     if self.rOpenFile.isChecked() or self.rfOpenFile.isChecked():
         if not self.cSymlinks.isChecked():
             options = QFileDialog.Options(QFileDialog.DontResolveSymlinks)
         else:
             options = QFileDialog.Options()
         options = self.__adjustOptions(options)
         QFileDialog.getOpenFileName(None, self.eCaption.text(),
                                     self.eStartWith.text(),
                                     self.eFilters.text(),
                                     self.eInitialFilter.text(), options)
     elif self.rOpenFileUrl.isChecked():
         if not self.cSymlinks.isChecked():
             options = QFileDialog.Options(QFileDialog.DontResolveSymlinks)
         else:
             options = QFileDialog.Options()
         options = self.__adjustOptions(options)
         try:
             QFileDialog.getOpenFileUrl(None, self.eCaption.text(),
                                        QUrl(self.eStartWith.text()),
                                        self.eFilters.text(),
                                        self.eInitialFilter.text(), options,
                                        self.schemesEdit.text().split())
         except TypeError:
             # PyQt5 < 5.13.0 contains an error
             QFileDialog.getOpenFileUrl(None, self.eCaption.text(),
                                        self.eStartWith.text(),
                                        self.eFilters.text(),
                                        self.eInitialFilter.text(), options,
                                        self.schemesEdit.text().split())
     elif self.rOpenFiles.isChecked() or self.rfOpenFiles.isChecked():
         if not self.cSymlinks.isChecked():
             options = QFileDialog.Options(QFileDialog.DontResolveSymlinks)
         else:
             options = QFileDialog.Options()
         options = self.__adjustOptions(options)
         QFileDialog.getOpenFileNames(None, self.eCaption.text(),
                                      self.eStartWith.text(),
                                      self.eFilters.text(),
                                      self.eInitialFilter.text(), options)
     elif self.rOpenFileUrls.isChecked():
         if not self.cSymlinks.isChecked():
             options = QFileDialog.Options(QFileDialog.DontResolveSymlinks)
         else:
             options = QFileDialog.Options()
         options = self.__adjustOptions(options)
         try:
             QFileDialog.getOpenFileUrls(None, self.eCaption.text(),
                                         QUrl(self.eStartWith.text()),
                                         self.eFilters.text(),
                                         self.eInitialFilter.text(),
                                         options,
                                         self.schemesEdit.text().split())
         except TypeError:
             # PyQt5 < 5.13.0 contains an error
             QFileDialog.getOpenFileUrls(None, self.eCaption.text(),
                                         self.eStartWith.text(),
                                         self.eFilters.text(),
                                         self.eInitialFilter.text(),
                                         options,
                                         self.schemesEdit.text().split())
     elif self.rSaveFile.isChecked() or self.rfSaveFile.isChecked():
         if not self.cSymlinks.isChecked():
             options = QFileDialog.Options(QFileDialog.DontResolveSymlinks)
         else:
             options = QFileDialog.Options()
         options = self.__adjustOptions(options)
         QFileDialog.getSaveFileName(None, self.eCaption.text(),
                                     self.eStartWith.text(),
                                     self.eFilters.text(),
                                     self.eInitialFilter.text(), options)
     elif self.rSaveFileUrl.isChecked():
         if not self.cSymlinks.isChecked():
             options = QFileDialog.Options(QFileDialog.DontResolveSymlinks)
         else:
             options = QFileDialog.Options()
         options = self.__adjustOptions(options)
         try:
             QFileDialog.getSaveFileUrl(None, self.eCaption.text(),
                                        QUrl(self.eStartWith.text()),
                                        self.eFilters.text(),
                                        self.eInitialFilter.text(), options,
                                        self.schemesEdit.text().split())
         except TypeError:
             # PyQt5 < 5.13.0 contains an error
             QFileDialog.getSaveFileUrl(None, self.eCaption.text(),
                                        self.eStartWith.text(),
                                        self.eFilters.text(),
                                        self.eInitialFilter.text(), options,
                                        self.schemesEdit.text().split())
     elif self.rDirectory.isChecked():
         options = QFileDialog.Options()
         if not self.cSymlinks.isChecked():
             options |= QFileDialog.Options(QFileDialog.DontResolveSymlinks)
         if self.cDirOnly.isChecked():
             options |= QFileDialog.Options(QFileDialog.ShowDirsOnly)
         else:
             options |= QFileDialog.Options(QFileDialog.Option(0))
         options = self.__adjustOptions(options)
         QFileDialog.getExistingDirectory(None, self.eCaption.text(),
                                          self.eWorkDir.text(), options)
     elif self.rDirectoryUrl.isChecked():
         options = QFileDialog.Options()
         if not self.cSymlinks.isChecked():
             options |= QFileDialog.Options(QFileDialog.DontResolveSymlinks)
         if self.cDirOnly.isChecked():
             options |= QFileDialog.Options(QFileDialog.ShowDirsOnly)
         else:
             options |= QFileDialog.Options(QFileDialog.Option(0))
         options = self.__adjustOptions(options)
         try:
             QFileDialog.getExistingDirectoryUrl(
                 None, self.eCaption.text(), QUrl(self.eWorkDir.text()),
                 options,
                 self.schemesEdit.text().split())
         except TypeError:
             # PyQt5 < 5.13.0 contains an error
             QFileDialog.getExistingDirectoryUrl(
                 None, self.eCaption.text(), self.eWorkDir.text(), options,
                 self.schemesEdit.text().split())
Ejemplo n.º 19
0
 def saveFileDialog(self):
     options = QFileDialog.Option()
     #options |= QFileDialog.DontUseNativeDialog
     saveFile, _ = QFileDialog.getSaveFileName(self,"Save Output As: ","K:/A & A/Cardiff/Audit/Clients/Open/S/Spotlight/2. Staff Folders/JWalters/__Python/Test Data and VBA/Formatted.csv","All Files (*);;CSV Files (*.csv)", options=options)
     self.linePathSave.setText(left(saveFile, len(saveFile) -4)) 
     self.saveFile = saveFile