本文整理汇总了Python中PyQt5.QtWidgets.QFileSystemModel.setFilter方法的典型用法代码示例。如果您正苦于以下问题:Python QFileSystemModel.setFilter方法的具体用法?Python QFileSystemModel.setFilter怎么用?Python QFileSystemModel.setFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QFileSystemModel
的用法示例。
在下文中一共展示了QFileSystemModel.setFilter方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LocalPathView
# 需要导入模块: from PyQt5.QtWidgets import QFileSystemModel [as 别名]
# 或者: from PyQt5.QtWidgets.QFileSystemModel import setFilter [as 别名]
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])
示例2: E5DirCompleter
# 需要导入模块: from PyQt5.QtWidgets import QFileSystemModel [as 别名]
# 或者: from PyQt5.QtWidgets.QFileSystemModel import setFilter [as 别名]
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: createDockWindows
# 需要导入模块: from PyQt5.QtWidgets import QFileSystemModel [as 别名]
# 或者: from PyQt5.QtWidgets.QFileSystemModel import setFilter [as 别名]
def createDockWindows(self):
dock = QDockWidget("Folders", self)
dock.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
#Code to Create FileView Colums and FolderTree
self.FileView = QtWidgets.QColumnView()
self.FileView.setGeometry(QtCore.QRect(240, 10, 291, 281))
self.FolderTree = QtWidgets.QTreeView()
self.FolderTree.setGeometry(QtCore.QRect(10, 10, 221, 281))
FolderTree = self.FolderTree
#FolderTree.hidecolumn(1),... ?? to show only name column
#include FolderTree to a Dock at the left side
dock.setWidget(FolderTree)
self.addDockWidget(Qt.LeftDockWidgetArea, dock)
#set the model and rootpath for filling the FolderTree from self.ui
dirmodel = QFileSystemModel()
#set filter to show only folders
dirmodel.setFilter(QDir.NoDotAndDotDot | QDir.AllDirs)
dirmodel.setRootPath(rootpath)
#filemodel and filter for only files on right side
filemodel = QFileSystemModel()
filemodel.setFilter(QDir.NoDotAndDotDot | QDir.Files)
filemodel.setRootPath(rootpath)
FolderView = self.FolderTree
FolderView.setModel(dirmodel)
FolderView.setRootIndex(dirmodel.index(rootpath))
FileView = self.FileView
FileView.setModel(filemodel)
dock = QDockWidget("Files", self)
dock.setWidget(FileView)
self.addDockWidget(Qt.RightDockWidgetArea, dock)
#important lines for the connection, which does not work
self.FolderTree.clicked['QModelIndex'].connect(self.setpathonclick)
示例4: FileChooser
# 需要导入模块: from PyQt5.QtWidgets import QFileSystemModel [as 别名]
# 或者: from PyQt5.QtWidgets.QFileSystemModel import setFilter [as 别名]
class FileChooser(QWidget):
fileOpened = pyqtSignal(str)
def __init__(self, parent=None):
super().__init__(parent)
self.folderBox = QComboBox(self)
self.explorerTree = FileTreeView(self)
self.explorerTree.doubleClickCallback = self._fileOpened
self.explorerModel = QFileSystemModel(self)
self.explorerModel.setFilter(
QDir.AllDirs | QDir.Files | QDir.NoDotAndDotDot)
self.explorerModel.setNameFilters(["*.py"])
self.explorerModel.setNameFilterDisables(False)
self.explorerTree.setModel(self.explorerModel)
for index in range(1, self.explorerModel.columnCount()):
self.explorerTree.hideColumn(index)
self.setCurrentFolder()
self.folderBox.currentIndexChanged[int].connect(
self.updateCurrentFolder)
layout = QVBoxLayout(self)
layout.addWidget(self.folderBox)
layout.addWidget(self.explorerTree)
layout.setContentsMargins(5, 5, 0, 0)
def _fileOpened(self, modelIndex):
path = self.explorerModel.filePath(modelIndex)
if os.path.isfile(path):
self.fileOpened.emit(path)
def currentFolder(self):
return self.explorerModel.rootPath()
def setCurrentFolder(self, path=None):
if path is None:
app = QApplication.instance()
path = app.getScriptsDirectory()
else:
assert os.path.isdir(path)
self.explorerModel.setRootPath(path)
self.explorerTree.setRootIndex(self.explorerModel.index(path))
self.folderBox.blockSignals(True)
self.folderBox.clear()
style = self.style()
dirIcon = style.standardIcon(style.SP_DirIcon)
self.folderBox.addItem(dirIcon, os.path.basename(path))
self.folderBox.insertSeparator(1)
self.folderBox.addItem(self.tr("Browse…"))
self.folderBox.setCurrentIndex(0)
self.folderBox.blockSignals(False)
def updateCurrentFolder(self, index):
if index < self.folderBox.count() - 1:
return
path = QFileDialog.getExistingDirectory(
self, self.tr("Choose Directory"), self.currentFolder(),
QFileDialog.ShowDirsOnly)
if path:
QSettings().setValue("scripting/path", path)
self.setCurrentFolder(path)
示例5: E5FileCompleter
# 需要导入模块: from PyQt5.QtWidgets import QFileSystemModel [as 别名]
# 或者: from PyQt5.QtWidgets.QFileSystemModel import setFilter [as 别名]
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()
示例6: AssetBrowser
# 需要导入模块: from PyQt5.QtWidgets import QFileSystemModel [as 别名]
# 或者: from PyQt5.QtWidgets.QFileSystemModel import setFilter [as 别名]
class AssetBrowser(QMainWindow, Ui_MainWindow):
asset_clicked = pyqtSignal(str, str, name='assetClicked')
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)
def open_project(self, project_dir):
path = os.path.join(project_dir)
self.dir_model.setRootPath(path)
self.file_model.setRootPath(path)
self.dir_view.setRootIndex(self.dir_model.index(path))
self.file_view.setRootIndex(self.file_model.index(path))
def dir_clicked(self, idx):
path = self.dir_model.fileInfo(idx).absoluteFilePath()
self.file_view.setRootIndex(self.file_model.setRootPath(path))
def file_doubleclicked(self, idx):
fileinfo = self.file_model.fileInfo(idx)
path = fileinfo.absoluteFilePath()
ext = fileinfo.suffix()
self.asset_clicked.emit(path, ext)
示例7: open_project
# 需要导入模块: from PyQt5.QtWidgets import QFileSystemModel [as 别名]
# 或者: from PyQt5.QtWidgets.QFileSystemModel import setFilter [as 别名]
def open_project(self, project):
project_path = project.path
qfsm = None # Should end up having a QFileSystemModel
if project_path not in self.__projects:
qfsm = QFileSystemModel()
project.model = qfsm
qfsm.setRootPath(project_path)
qfsm.setFilter(QDir.AllDirs | QDir.Files | QDir.NoDotAndDotDot)
# If set to true items that dont match are displayed disabled
qfsm.setNameFilterDisables(False)
pext = ["*{0}".format(x) for x in project.extensions]
logger.debug(pext)
qfsm.setNameFilters(pext)
self.__projects[project_path] = project
self.__check_files_for(project_path)
self.projectOpened.emit(project_path)
else:
qfsm = self.__projects[project_path]
return qfsm
示例8: load_tree
# 需要导入模块: from PyQt5.QtWidgets import QFileSystemModel [as 别名]
# 或者: from PyQt5.QtWidgets.QFileSystemModel import setFilter [as 别名]
def load_tree(self, project):
"""Load the tree view on the right based on the project selected."""
qfsm = QFileSystemModel()
qfsm.setRootPath(project.path)
load_index = qfsm.index(qfsm.rootPath())
qfsm.setFilter(QDir.AllDirs | QDir.NoDotAndDotDot)
qfsm.setNameFilterDisables(False)
pext = ["*{0}".format(x) for x in project.extensions]
qfsm.setNameFilters(pext)
self._tree.setModel(qfsm)
self._tree.setRootIndex(load_index)
t_header = self._tree.header()
t_header.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)
t_header.setSectionResizeMode(0, QHeaderView.Stretch)
t_header.setStretchLastSection(False)
t_header.setClickable(True)
self._tree.hideColumn(1) # Size
self._tree.hideColumn(2) # Type
self._tree.hideColumn(3) # Modification date
示例9: AssetBrowser
# 需要导入模块: from PyQt5.QtWidgets import QFileSystemModel [as 别名]
# 或者: from PyQt5.QtWidgets.QFileSystemModel import setFilter [as 别名]
class AssetBrowser(QMainWindow, Ui_MainWindow, PlaygroundModule):
Name = "asset_browser"
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)
def on_open_project(self, project):
project_dir = project.project_dir
path = os.path.join(project_dir)
self.dir_model.setRootPath(path)
self.file_model.setRootPath(path)
self.dir_view.setRootIndex(self.dir_model.index(path))
self.file_view.setRootIndex(self.file_model.index(path))
def dir_clicked(self, idx):
path = self.dir_model.fileInfo(idx).absoluteFilePath()
self.file_view.setRootIndex(self.file_model.setRootPath(path))
def file_doubleclicked(self, idx):
fileinfo = self.file_model.fileInfo(idx)
path = fileinfo.absoluteFilePath()
ext = fileinfo.suffix()
asset_name = path.replace(self.project_manager.project_dir, '').replace('/src/', '').split('.')[0]
self.modules_manager.open_asset(path, asset_name, ext)
def file_clicked(self, idx):
fileinfo = self.file_model.fileInfo(idx)
path = fileinfo.absoluteFilePath()
ext = fileinfo.suffix()
asset_name = path.replace(self.project_manager.project_dir, '').replace('/src/', '').split('.')[0]
self.modules_manager.show_asset(path, asset_name, ext)
示例10: MainView
# 需要导入模块: from PyQt5.QtWidgets import QFileSystemModel [as 别名]
# 或者: from PyQt5.QtWidgets.QFileSystemModel import setFilter [as 别名]
class MainView(QMainWindow):
resizeCompleted = pyqtSignal()
def __init__(self, model, controller, image_path):
self.settings = SettingsModel()
self.slideshow = SlideshowModel()
self.model = model
self.canvas = self.model.canvas
self.main_controller = controller
self.canvas_controller = CanvasController(self.canvas)
super(MainView, self).__init__()
self.build_ui()
self.center_ui()
# Resize timer to prevent laggy updates
self.resize_timer = None
self.resizeCompleted.connect(self.resize_completed)
# Slideshow
if self.settings.get('Slideshow', 'reverse') == 'True':
self.slideshow.updateSignal.connect(self.on_previous_item)
else:
self.slideshow.updateSignal.connect(self.on_next_item)
self.model.subscribe_update_func(self.update_ui_from_model)
self.arguments = {
'image_path': image_path
}
def build_ui(self):
self.ui = Ui_Hitagi()
self.ui.setupUi(self)
# File menu
self.ui.actionSet_as_wallpaper.triggered.connect(self.on_set_as_wallpaper)
self.ui.actionCopy_to_clipboard.triggered.connect(self.on_clipboard)
self.ui.actionOpen_current_directory.triggered.connect(self.on_current_dir)
self.ui.actionOptions.triggered.connect(self.on_options)
self.ui.actionExit.triggered.connect(self.on_close)
# Folder menu
self.ui.actionOpen_next.triggered.connect(self.on_next_item)
self.ui.actionOpen_previous.triggered.connect(self.on_previous_item)
self.ui.actionChange_directory.triggered.connect(self.on_change_directory)
self.ui.actionSlideshow.triggered.connect(self.on_slideshow)
# View menu
self.ui.actionZoom_in.triggered.connect(self.on_zoom_in)
self.ui.actionZoom_out.triggered.connect(self.on_zoom_out)
self.ui.actionOriginal_size.triggered.connect(self.on_zoom_original)
self.ui.actionRotate_clockwise.triggered.connect(self.on_rotate_clockwise)
self.ui.actionRotate_counterclockwise.triggered.connect(self.on_rotate_counterclockwise)
self.ui.actionFlip_horizontally.triggered.connect(self.on_flip_horizontal)
self.ui.actionFlip_vertically.triggered.connect(self.on_flip_vertical)
self.ui.actionFit_image_width.triggered.connect(self.on_scale_image_to_width)
self.ui.actionFit_image_height.triggered.connect(self.on_scale_image_to_height)
self.ui.actionFile_list.triggered.connect(self.on_toggle_filelist)
self.ui.actionFullscreen.triggered.connect(self.on_fullscreen)
# Favorite menu
self.ui.actionAdd_to_favorites.triggered.connect(self.on_add_to_favorites)
self.ui.actionRemove_from_favorites.triggered.connect(self.on_remove_from_favorites)
# Help menu
self.ui.actionChangelog.triggered.connect(self.on_changelog)
self.ui.actionAbout.triggered.connect(self.on_about)
# Load stylesheet
stylesheet_dir = "resources/hitagi.stylesheet"
with open(stylesheet_dir, "r") as sh:
self.setStyleSheet(sh.read())
# File listing
self.file_model = QFileSystemModel()
self.file_model.setFilter(QDir.NoDotAndDotDot | QDir.AllDirs | QDir.Files)
self.file_model.setNameFilters(['*.bmp', '*.gif', '*.jpg', '*.jpeg', '*.png', '*.png', '*.pbm', '*.pgm', '*.ppm', '*.xbm', '*.xpm'])
self.file_model.setNameFilterDisables(False)
self.file_model.setRootPath(self.settings.get('Directory', 'default'))
self.ui.treeView.setModel(self.file_model)
self.ui.treeView.setColumnWidth(0, 120)
self.ui.treeView.setColumnWidth(1, 120)
self.ui.treeView.hideColumn(1)
self.ui.treeView.hideColumn(2)
# Double click
self.ui.treeView.activated.connect(self.on_dir_list_activated)
# Update file list
self.ui.treeView.clicked.connect(self.on_dir_list_clicked)
# Open parent
self.ui.pushButton_open_parent.clicked.connect(self.on_open_parent)
self.ui.pushButton_favorite.clicked.connect(self.on_manage_favorite)
# Shortcuts
_translate = QCoreApplication.translate
self.ui.actionExit.setShortcut(_translate("Hitagi", self.settings.get('Hotkeys', 'Exit')))
#.........这里部分代码省略.........
示例11: NProject
# 需要导入模块: from PyQt5.QtWidgets import QFileSystemModel [as 别名]
# 或者: from PyQt5.QtWidgets.QFileSystemModel import setFilter [as 别名]
#.........这里部分代码省略.........
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)
def _get_name(self):
return self._name
def _set_name(self, name):
if name == '':
self._name = file_manager.get_basename(self.path)
else:
self._name = name
self.projectNameUpdated.emit(self._name)
name = property(_get_name, _set_name)
def save_project_properties(self):
#save project properties
project = {}
project['name'] = self._name
project['description'] = self.description
project['url'] = self.url
project['license'] = self.license
project['mainFile'] = self.main_file
project['project-type'] = self.project_type
project['supported-extensions'] = self.extensions
project['indentation'] = self.indentation
project['use-tabs'] = self.use_tabs
project['pythonExec'] = self.python_exec # FIXME
project['PYTHONPATH'] = self.python_path
project['additional_builtins'] = self.additional_builtins
project['preExecScript'] = self.pre_exec_script
project['postExecScript'] = self.post_exec_script
project['venv'] = self.venv
project['programParams'] = self.program_params
project['relatedProjects'] = self.related_projects
if file_manager.file_exists(self.path, self._name + '.nja'):
file_manager.delete_file(self.path, self._name + '.nja')
json_manager.create_ninja_project(self.path, self._name, project)
#TODO: update project tree on extensions changed
@property
def full_path(self):
'''
Returns the full path of the project
'''
project_file = json_manager.get_ninja_project_file(self.path)
if not project_file: # FIXME: If we dont have a project file
project_file = '' # we should do SOMETHING! like kill zombies!
return os.path.join(self.path, project_file)
@property
def python_exec_command(self):
'''
Returns the python exec command of the project
'''
if self.venv is '':
return self.venv
return self.python_exec
@property
def model(self):
return self.__model
@model.setter
def model(self, model): # lint:ok
self.__model = model
self.__model.setFilter(QDir.AllDirs | QDir.NoDotAndDotDot |
QDir.AllEntries)
self.__model.setNameFilters(self.extensions)
@model.deleter
def model(self): # lint:ok
del(self.__model)