def create_file(self):
        """
        Creates a file under the current directory.
        """
        src = self.get_current_path()
        name, status = QtWidgets.QInputDialog.getText(
            self.tree_view, _('Create new file'), _('File name:'),
            QtWidgets.QLineEdit.Normal, '')
        if status:
            fatal_names = ['.', '..', os.sep]
            for i in fatal_names:
                if i == name:
                    QtWidgets.QMessageBox.critical(
                        self.tree_view, _("Error"), _("Wrong directory name"))
                    return

            if os.path.isfile(src):
                src = os.path.dirname(src)
            path = os.path.join(src, name)
            try:
                with open(path, 'w'):
                    pass
            except OSError as e:
                QtWidgets.QMessageBox.warning(
                    self.tree_view, _('Failed to create new file'),
                    _('Failed to create file: "%s".\n\n%s') % (path, str(e)))
            else:
                self.tree_view.file_created.emit(os.path.normpath(path))
def create_file ( self ) : src = self . get_current_path ( ) name , status = QtWidgets . QInputDialog . getText ( self . tree_view , _ ( 'Create new file' ) , _ ( 'File name:' ) , QtWidgets . QLineEdit . Normal , '' ) if status : fatal_names = [ '.' , '..' , os . sep ] for i in fatal_names : if i == name : QtWidgets . QMessageBox . critical ( self . tree_view , _ ( "Error" ) , _ ( "Wrong directory name" ) ) return if os . path . isfile ( src ) : src = os . path . dirname ( src ) path = os . path . join ( src , name ) try : with open ( path , 'w' ) : pass except OSError as e : QtWidgets . QMessageBox . warning ( self . tree_view , _ ( 'Failed to create new file' ) , _ ( 'Failed to create file: "%s".\n\n%s' ) % ( path , str ( e ) ) ) else : self . tree_view . file_created . emit ( os . path . normpath ( path ) )
Creates a file under the current directory.