(self, prefixname=None, directory=None)
Open a file dialog and select a user specified file.
Open a file dialog and select a user specified file.
Open a file dialog and select a user specified file .
def browse(self, prefixname=None, directory=None):
        """
        Open a file dialog and select a user specified file.
        """
        dlg = self._browse_dialog()
        if directory is not None:
            dlg.setDirectory(directory)

        status = dlg.exec()
        dlg.deleteLater()
        if status == QFileDialog.Accepted:
            selected_filter = dlg.selectedFileFormat()
            path = dlg.selectedFiles()[0]
            if prefixname:
                _prefixpath = self._replacements().get(prefixname, "")
                if not isprefixed(_prefixpath, path):
                    mb = self._path_must_be_relative_mb(_prefixpath)
                    mb.show()
                    return
                varpath = VarPath(prefixname, os.path.relpath(path, _prefixpath))
            else:
                varpath = PathItem.AbsPath(path)

            # pre-flight check; try to determine the nature of the file
            mtype = _mime_type_for_path(path)
            if not mtype.inherits("text/plain"):
                mb = self._might_be_binary_mb(path)
                if mb.exec() == QMessageBox.Cancel:
                    return
            # initialize options based on selected format
            options = default_options_for_mime_type(
                path, selected_filter.mime_type,
            )
            # Search for path in history.
            # If found use the stored params to initialize the import dialog
            items = self.itemsFromSettings()
            idx = index_where(items, lambda t: samepath(t[0], path))
            if idx is not None:
                _, options_ = items[idx]
                if options_ is not None:
                    options = options_
            dlg = CSVImportDialog(
                self, windowTitle="Import Options", sizeGripEnabled=True)
            dlg.setWindowModality(Qt.WindowModal)
            dlg.setPath(path)
            dlg.setOptions(options)
            status = dlg.exec()
            dlg.deleteLater()
            if status == QDialog.Accepted:
                self.set_selected_file(path, dlg.options())
                self.current_item().setVarPath(varpath)
def browse ( self , prefixname = None , directory = None ) : dlg = self . _browse_dialog ( ) if directory is not None : dlg . setDirectory ( directory ) status = dlg . exec ( ) dlg . deleteLater ( ) if status == QFileDialog . Accepted : selected_filter = dlg . selectedFileFormat ( ) path = dlg . selectedFiles ( ) [ 0 ] if prefixname : _prefixpath = self . _replacements ( ) . get ( prefixname , "" ) if not isprefixed ( _prefixpath , path ) : mb = self . _path_must_be_relative_mb ( _prefixpath ) mb . show ( ) return varpath = VarPath ( prefixname , os . path . relpath ( path , _prefixpath ) ) else : varpath = PathItem . AbsPath ( path ) # pre-flight check; try to determine the nature of the file mtype = _mime_type_for_path ( path ) if not mtype . inherits ( "text/plain" ) : mb = self . _might_be_binary_mb ( path ) if mb . exec ( ) == QMessageBox . Cancel : return # initialize options based on selected format options = default_options_for_mime_type ( path , selected_filter . mime_type , ) # Search for path in history. # If found use the stored params to initialize the import dialog items = self . itemsFromSettings ( ) idx = index_where ( items , lambda t : samepath ( t [ 0 ] , path ) ) if idx is not None : _ , options_ = items [ idx ] if options_ is not None : options = options_ dlg = CSVImportDialog ( self , windowTitle = "Import Options" , sizeGripEnabled = True ) dlg . setWindowModality ( Qt . WindowModal ) dlg . setPath ( path ) dlg . setOptions ( options ) status = dlg . exec ( ) dlg . deleteLater ( ) if status == QDialog . Accepted : self . set_selected_file ( path , dlg . options ( ) ) self . current_item ( ) . setVarPath ( varpath )