本文整理汇总了Python中PyQt5.QtWidgets.QFileSystemModel类的典型用法代码示例。如果您正苦于以下问题:Python QFileSystemModel类的具体用法?Python QFileSystemModel怎么用?Python QFileSystemModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QFileSystemModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_file_tree
def update_file_tree(self):
model = QFileSystemModel()
model.setRootPath(self._root_dir)
self.localFilesTreeView.setModel(model)
local_selection_model = self.localFilesTreeView.selectionModel()
local_selection_model.selectionChanged.connect(self.local_file_selection_changed)
self.localFilesTreeView.setRootIndex(model.index(self._root_dir))
示例2: E5DirCompleter
class E5DirCompleter(QCompleter):
"""
Class implementing a completer for directory names.
"""
def __init__(self, parent=None, completionMode=QCompleter.PopupCompletion, showHidden=False):
"""
Constructor
@param parent parent widget of the completer (QWidget)
@keyparam completionMode completion mode of the
completer (QCompleter.CompletionMode)
@keyparam showHidden flag indicating to show hidden entries as well
(boolean)
"""
super(E5DirCompleter, self).__init__(parent)
self.__model = QFileSystemModel(self)
if showHidden:
self.__model.setFilter(QDir.Filters(QDir.Drives | QDir.AllDirs | QDir.Hidden))
else:
self.__model.setFilter(QDir.Filters(QDir.Drives | QDir.AllDirs))
self.setModel(self.__model)
self.setCompletionMode(completionMode)
if isWindowsPlatform():
self.setCaseSensitivity(Qt.CaseInsensitive)
if parent:
parent.setCompleter(self)
示例3: __init__
def __init__(self, module_manager):
super(AssetBrowser, self).__init__()
self.setupUi(self)
self.init_module(module_manager)
self.dir_model = QFileSystemModel()
self.dir_model.setFilter(QDir.NoDotAndDotDot | QDir.AllDirs)
self.dir_model.setReadOnly(False)
self.dir_view.setModel(self.dir_model)
self.dir_view.hideColumn(1)
self.dir_view.hideColumn(2)
self.dir_view.hideColumn(3)
self.file_model = QFileSystemModel()
self.file_model.setFilter(QDir.NoDotAndDotDot | QDir.Files)
self.file_model.setReadOnly(False)
self.file_view.setModel(self.file_model)
self.dock = self.modules_manager.new_docked(self, self.Name, "Asset browser",
Qt.BottomDockWidgetArea)
self.modules_manager.main_window.splitDockWidget(self.dock,
self.modules_manager["asset_view"].dock, Qt.Horizontal)
示例4: FileTree
class FileTree(QTreeView):
def __init__(self):
super(FileTree, self).__init__()
self.model = QFileSystemModel()
self.model.setRootPath('')
self.setModel(self.model)
self.setAnimated(False)
self.setIndentation(20)
self.setSortingEnabled(True)
示例5: initRootDir
def initRootDir(self,indexDir):
if not indexDir:
return
self.indexDir = indexDir
model = QFileSystemModel()
model.setRootPath('')
self.setModel(model)
self.setAnimated(False)
self.setIndentation(20)
self.setSortingEnabled(True)
self.setRootIndex(model.index(self.indexDir))
for i in range(1,model.columnCount()):
self.hideColumn(i)
示例6: E5FileCompleter
class E5FileCompleter(QCompleter):
"""
Class implementing a completer for file names.
"""
def __init__(self, parent=None,
completionMode=QCompleter.PopupCompletion,
showHidden=False):
"""
Constructor
@param parent parent widget of the completer (QWidget)
@keyparam completionMode completion mode of the
completer (QCompleter.CompletionMode)
@keyparam showHidden flag indicating to show hidden entries as well
(boolean)
"""
super(E5FileCompleter, self).__init__(parent)
self.__model = QFileSystemModel(self)
if showHidden:
self.__model.setFilter(
QDir.Filters(QDir.Dirs | QDir.Files | QDir.Drives |
QDir.AllDirs | QDir.Hidden))
else:
self.__model.setFilter(QDir.Filters(
QDir.Dirs | QDir.Files | QDir.Drives | QDir.AllDirs))
self.__model.directoryLoaded.connect(self.complete)
self.__model.setRootPath("")
self.setModel(self.__model)
self.setCompletionMode(completionMode)
if isWindowsPlatform():
self.setCaseSensitivity(Qt.CaseInsensitive)
if parent:
parent.setCompleter(self)
def setRootPath(self, path):
"""
Public method to set the root path of the model.
@param path root path for the model
@type str
"""
if not os.path.isdir(path):
path = os.path.dirname(path)
self.__model.setRootPath(path)
def rootPath(self):
"""
Public method to get the root path of the model.
@return root path of the model
@rtype str
"""
return self.__model.rootPath()
示例7: dropMimeData
def dropMimeData(self, data, action, row, column, parent):
# print 'dropMimeData %s %s %s %s' % (data.data('text/uri-list'), action, row, parent)
# print data.text()
# print data.formats()
# print data.data('text/uri-list')
# print row, "row"
# print column, "col"
# print action, "action"
# print parent, "parent"
# print parent.data(Qt.DisplayRole),"parent"
filePath = data.data('text/uri-list').data()[7:]
# filesFolderPath = filePath # canonical , os path parent falan
fileName = os.path.basename(filePath)
# fileName = ""
# print type(filePath.data())
# print fileName
# os.path.normpath(unicode(self.model().fileInfo(self.selectedIndexes()[0]).absoluteFilePath()))
# dfolder = self.fileInfo(parent).absoluteFilePath()
destFinalPath = os.path.normpath("%s/%s" % (self.filePath(parent), fileName))
# ya da emit.fileMoved filepath move to destFolder+filename
self.fileDraggedAndMoved.emit("%s --------> %s" % (filePath, destFinalPath))
# return True
return QFileSystemModel.dropMimeData(self, data, action, row, column, parent)
示例8: _init_ui
def _init_ui(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
model = QFileSystemModel(self)
model.setRootPath('')
view = QTreeView()
view.setModel(model)
view.setAnimated(False)
view.setIndentation(20)
view.setSortingEnabled(True)
layout = QVBoxLayout()
layout.addWidget(view)
self.setLayout(layout)
示例9: __init__
def __init__(self, path):
super(NProject, self).__init__()
project = json_manager.read_ninja_project(path)
self.path = path
self._name = project.get('name', '')
if self._name == '':
self._name = file_manager.get_basename(path)
self.project_type = project.get('project-type', '')
self.description = project.get('description', '')
if self.description == '':
self.description = translations.TR_NO_DESCRIPTION
self.url = project.get('url', '')
self.license = project.get('license', '')
self.main_file = project.get('mainFile', '')
self.pre_exec_script = project.get('preExecScript', '')
self.post_exec_script = project.get('postExecScript', '')
self.indentation = project.get('indentation', settings.INDENT)
self.use_tabs = project.get('use-tabs', settings.USE_TABS)
self.extensions = project.get('supported-extensions',
settings.SUPPORTED_EXTENSIONS)
self.python_exec = project.get('pythonExec', settings.PYTHON_EXEC)
self.python_path = project.get('PYTHONPATH', '')
self.additional_builtins = project.get('additional_builtins', [])
self.program_params = project.get('programParams', '')
self.venv = project.get('venv', '')
self.related_projects = project.get('relatedProjects', [])
self.added_to_console = False
self.is_current = False
#Model is a QFileSystemModel to be set on runtime
self.__model = QFileSystemModel()
self.__model.setRootPath(path)
示例10: _iconForPath
def _iconForPath(self, path):
"""Get icon for file or directory path. Uses QFileSystemModel
"""
if self._model is None:
self._model = QFileSystemModel()
index = self._model.index(path)
return self._model.data(index, Qt.DecorationRole)
示例11: __init__
def __init__(self):
super(AssetBrowser, self).__init__()
self.setupUi(self)
self.dir_model = QFileSystemModel()
self.dir_model.setFilter(QDir.NoDotAndDotDot | QDir.AllDirs)
self.dir_model.setReadOnly(False)
self.dir_view.setModel(self.dir_model)
self.dir_view.hideColumn(1)
self.dir_view.hideColumn(2)
self.dir_view.hideColumn(3)
self.file_model = QFileSystemModel()
self.file_model.setFilter(QDir.NoDotAndDotDot | QDir.Files)
self.file_model.setReadOnly(False)
self.file_view.setModel(self.file_model)
示例12: load_dir
def load_dir(self, dir_path):
if dir_path == self.dir_path:
return
self.dir_path = dir_path
model = QFileSystemModel()
model.setRootPath(dir_path)
self.setModel(model)
index_root = model.index(model.rootPath())
self.setRootIndex(index_root)
# hide unwanted info
self.hideColumn(1)
self.hideColumn(2)
self.hideColumn(3)
self.setHeaderHidden(True)
示例13: ComplexDialog
class ComplexDialog(QDialog, Ui_ComplexForm):
def __init__(self, parent=None):
super(ComplexDialog, self).__init__(parent)
self.setupUi(self)
self.file_model = QFileSystemModel()
self.bundle_model = QStringListModel()
bundle_lists = []
self.bundle_model.setStringList(bundle_lists)
root = self.file_model.setRootPath("/Volumes")
self.columnView_files.setModel(self.file_model)
self.columnView_files.setRootIndex(root)
self.listView_files.setModel(self.bundle_model)
# connect the buttons
self.pushButton_add_file.clicked.connect(self._add_to_bundle)
self.pushButton_remove_file.clicked.connect(self._remove_from_bundle)
self.pushButton_cancle.clicked.connect(self.close_window)
self.pushButton_add_object.clicked.connect(self.return_bundle)
def _add_to_bundle(self):
selection = self.columnView_files.selectedIndexes()
files = self.bundle_model.stringList()
model = self.columnView_files.model()
for index in selection:
# path = os.path.join()
if model.isDir(index):
continue
newfile = model.filePath(index)
files.append(newfile)
self.bundle_model.setStringList(files)
# self.bundle_model.inser
def _remove_from_bundle(self):
selection = self.listView_files.selectedIndexes()
model = self.listView_files.model()
for index in selection:
row = index.row()
model.removeRows(row, 1)
def return_bundle(self):
self.close_window()
@property
def bundle(self):
return self.bundle_model.stringList()
def close_window(self):
self.close()
示例14: __init__
def __init__(self):
super(FileSystemOpener, self).__init__()
hbox = QHBoxLayout(self)
hbox.setContentsMargins(0, 0, 0, 0)
self.btnClose = QPushButton(
self.style().standardIcon(QStyle.SP_DialogCloseButton), '')
self.completer = QCompleter(self)
self.pathLine = ui_tools.LineEditTabCompleter(self.completer)
fileModel = QFileSystemModel(self.completer)
fileModel.setRootPath("")
self.completer.setModel(fileModel)
self.pathLine.setCompleter(self.completer)
self.btnOpen = QPushButton(
self.style().standardIcon(QStyle.SP_ArrowRight), 'Open!')
hbox.addWidget(self.btnClose)
hbox.addWidget(QLabel(_translate("FileSystemOpener", "Path:")))
hbox.addWidget(self.pathLine)
hbox.addWidget(self.btnOpen)
self.pathLine.returnPressed.connect(self._open_file)
self.btnOpen.clicked['bool'].connect(self._open_file)
示例15: LocalPathView
class LocalPathView(QTreeView):
def __init__ (self):
super(LocalPathView, self).__init__()
self._model = QFileSystemModel()
self._model.setFilter(QDir.Dirs | QDir.Drives | QDir.NoDotAndDotDot | QDir.AllDirs)
self._model.setRootPath('')
self.setModel(self._model )
self.hideColumn(1); # removing Size Column
self.hideColumn(2); # removing Type Column
self.setAnimated(False)
self.setSortingEnabled(True)
self.header().setSortIndicator(0, Qt.AscendingOrder)
width = self.size().width() >> 1
self.setColumnWidth(0, width*0.7)
self.setColumnWidth(1, width*0.3)
index = self._model.index(QDir.currentPath())
self.selectionModel().setCurrentIndex(index, QItemSelectionModel.Select | QItemSelectionModel.Rows)
self.expand(index)
self.scrollTo(index)
@property
def selectedDir(self):
return self._model.filePath(self.selectionModel().selectedIndexes()[0])