本文整理汇总了Python中PyQt4.QtGui.QFileSystemModel.setFilter方法的典型用法代码示例。如果您正苦于以下问题:Python QFileSystemModel.setFilter方法的具体用法?Python QFileSystemModel.setFilter怎么用?Python QFileSystemModel.setFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QFileSystemModel
的用法示例。
在下文中一共展示了QFileSystemModel.setFilter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: E4DirCompleter
# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.QFileSystemModel import setFilter [as 别名]
class E4DirCompleter(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)
"""
QCompleter.__init__(self, 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)
示例2: AttachmentView
# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.QFileSystemModel import setFilter [as 别名]
class AttachmentView(QListView):
""" A dockWidget displaying attachments of the current note.
"""
def __init__(self, parent=None):
super(AttachmentView, self).__init__(parent)
self.parent = parent
self.settings = parent.settings
self.model = QFileSystemModel()
self.model.setFilter(QDir.Files)
self.model.setRootPath(self.settings.attachmentPath)
self.setModel(self.model)
# self.setRootIndex(self.model.index(self.settings.attachmentPath))
self.setViewMode(QListView.IconMode)
self.setUniformItemSizes(True)
self.setResizeMode(QListView.Adjust)
self.setItemDelegate(AttachmentItemDelegate(self))
self.clicked.connect(self.click)
def contextMenuEvent(self, event):
menu = QMenu()
indice = self.selectedIndexes()
if len(indice):
menu.addAction("Insert into note", self.insert)
menu.addAction("Delete", self.delete)
else:
pass
menu.exec_(event.globalPos())
def mousePressEvent(self, event):
""" Trigger click() when an item is pressed.
"""
self.clearSelection()
QListView.mousePressEvent(self, event)
def mouseReleaseEvent(self, event):
""" Trigger click() when an item is pressed.
"""
self.clearSelection()
QListView.mouseReleaseEvent(self, event)
def insert(self):
indice = self.selectedIndexes()
for i in indice:
filePath = self.model.filePath(i)
filePath = filePath.replace(self.settings.notebookPath, "..")
fileName = os.path.basename(filePath)
text = "![%s](%s)" % (fileName, filePath)
self.parent.notesEdit.insertPlainText(text)
def delete(self):
indice = self.selectedIndexes()
for i in indice:
filePath = self.model.filePath(i)
QFile(filePath).remove()
def click(self, index):
self.setCurrentIndex(index)
示例3: update_dirmodel
# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.QFileSystemModel import setFilter [as 别名]
def update_dirmodel(self, path):
dirmodel = QFileSystemModel()
dirmodel.setFilter(QDir.NoDotAndDotDot | QDir.AllEntries)
filefilter = ["*.zip"]
dirmodel.setNameFilters(filefilter)
dirmodel.sort(0, Qt.AscendingOrder)
self.file_treeView.setModel(dirmodel)
self.file_treeView.header().setResizeMode(3)
self.file_treeView.model().setRootPath(path)
self.file_treeView.setRootIndex(self.file_treeView.model().index(path))
示例4: FSLineEdit
# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.QFileSystemModel import setFilter [as 别名]
class FSLineEdit(QLineEdit):
"""
A line edit with auto completion for file system folders.
"""
def __init__(self, parent=None):
QLineEdit.__init__(self, parent)
self.fsmodel = QFileSystemModel()
self.fsmodel.setRootPath("")
self.completer = QCompleter()
self.completer.setModel(self.fsmodel)
self.setCompleter(self.completer)
self.fsmodel.setFilter(QDir.Drives | QDir.AllDirs | QDir.Hidden |
QDir.NoDotAndDotDot)
def setPath(self, path):
self.setText(path)
self.fsmodel.setRootPath(path)
示例5: open_project
# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.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.emit(SIGNAL("projectOpened(PyQt_PyObject)"), project)
else:
qfsm = self.__projects[project_path]
return qfsm
示例6: load_tree
# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.QFileSystemModel import setFilter [as 别名]
def load_tree(self, project):
"""Load the tree view on the right based on the project selected."""
qfsm = QFileSystemModel()
#FIXME it's not loading the proper folder, just the root /
qfsm.setRootPath(project.path)
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)
t_header = self._tree.header()
t_header.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)
t_header.setResizeMode(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
示例7: DirectoryWidget
# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.QFileSystemModel import setFilter [as 别名]
class DirectoryWidget(RWidget):
def __init__(self, parent, base="."):
RWidget.__init__(self, parent)
self.base = base
self.model = QFileSystemModel()
self.model.setRootPath(QDir.rootPath())
self.proxyModel = FileSystemProxyModel()
self.proxyModel.setDynamicSortFilter(True)
self.proxyModel.setFilterKeyColumn(0)
self.proxyModel.setSourceModel(self.model)
self.listView = QListView(self)
self.listView.setModel(self.proxyModel)
index = self.model.index(QDir.currentPath())
self.listView.setRootIndex(self.proxyModel.mapFromSource(index))
self.listView.setContextMenuPolicy(Qt.CustomContextMenu)
self.lineEdit = QLineEdit(self)
filterLineEdit = QLineEdit()
filterLabel = QLabel("Filter:")
self.connect(filterLineEdit, SIGNAL("textChanged(QString)"),
self.proxyModel.setFilterWildcard)
self.actions = []
self.upAction = QAction("&Up", self)
self.upAction.setStatusTip("Move to parent directory")
self.upAction.setToolTip("Move to parent directory")
self.upAction.setIcon(QIcon(":go-up"))
self.upAction.setEnabled(True)
self.actions.append(self.upAction)
self.newAction = QAction("&New Directory", self)
self.newAction.setStatusTip("Create new directory")
self.newAction.setToolTip("Create new directory")
self.newAction.setIcon(QIcon(":folder-new"))
self.newAction.setEnabled(True)
self.actions.append(self.newAction)
self.synchAction = QAction("&Synch", self)
self.synchAction.setStatusTip("Synch with current working directory")
self.synchAction.setToolTip("Synch with current working directory")
self.synchAction.setIcon(QIcon(":view-refresh"))
self.synchAction.setEnabled(True)
self.actions.append(self.synchAction)
self.rmAction = QAction("&Delete", self)
self.rmAction.setStatusTip("Delete selected item")
self.rmAction.setToolTip("delete selected item")
self.rmAction.setIcon(QIcon(":edit-delete"))
self.rmAction.setEnabled(True)
self.actions.append(self.rmAction)
self.openAction = QAction("&Open", self)
self.openAction.setStatusTip("Open selected R script")
self.openAction.setToolTip("Open selected R script")
self.openAction.setIcon(QIcon(":document-open"))
self.openAction.setEnabled(True)
self.actions.append(self.openAction)
self.loadAction = QAction("&Load", self)
self.loadAction.setStatusTip("Load selected R data")
self.loadAction.setToolTip("Load selected R data")
self.loadAction.setIcon(QIcon(":document-open"))
self.loadAction.setEnabled(True)
self.actions.append(self.loadAction)
self.setAction = QAction("Set as ¤t", self)
self.setAction.setStatusTip("Set folder as R working directory")
self.setAction.setToolTip("Set folder as R working directory")
self.setAction.setIcon(QIcon(":folder-home"))
self.setAction.setEnabled(True)
self.actions.append(self.setAction)
self.loadExternal = QAction("Open &Externally", self)
self.loadExternal.setStatusTip("Load file in external application")
self.loadExternal.setToolTip("Load file in external application")
self.loadExternal.setIcon(QIcon(":folder-system"))
self.loadExternal.setEnabled(True)
self.actions.append(self.loadExternal)
self.rootChanged()
hiddenAction = QAction("Toggle hidden files", self)
hiddenAction.setStatusTip("Show/hide hidden files and folders")
hiddenAction.setToolTip("Show/hide hidden files and folders")
hiddenAction.setIcon(QIcon(":stock_keyring"))
hiddenAction.setCheckable(True)
self.connect(self.newAction, SIGNAL("triggered()"), self.newFolder)
self.connect(self.upAction, SIGNAL("triggered()"), self.upFolder)
self.connect(self.synchAction, SIGNAL("triggered()"), self.synchFolder)
self.connect(self.rmAction, SIGNAL("triggered()"), self.rmItem)
self.connect(self.openAction, SIGNAL("triggered()"), self.openItem)
self.connect(self.loadAction, SIGNAL("triggered()"), self.loadItem)
self.connect(self.loadExternal, SIGNAL("triggered()"), self.externalItem)
self.connect(self.setAction, SIGNAL("triggered()"), self.setFolder)
self.connect(hiddenAction, SIGNAL("toggled(bool)"), self.toggleHidden)
self.connect(self.listView, SIGNAL("activated(QModelIndex)"), self.cdFolder)
self.connect(self.listView, SIGNAL("customContextMenuRequested(QPoint)"), self.customContext)
self.connect(self.lineEdit, SIGNAL("returnPressed()"), self.gotoFolder)
upButton = QToolButton()
upButton.setDefaultAction(self.upAction)
upButton.setAutoRaise(True)
newButton = QToolButton()
newButton.setDefaultAction(self.newAction)
newButton.setAutoRaise(True)
#.........这里部分代码省略.........
示例8: DirView
# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.QFileSystemModel import setFilter [as 别名]
class DirView(QTreeView):
"""Base file/directory tree view"""
def __init__(self, parent=None):
super(DirView, self).__init__(parent)
self.name_filters = None
self.parent_widget = parent
self.valid_types = None
self.show_all = None
self.menu = None
self.common_actions = None
self.__expanded_state = None
self._to_be_loaded = None
self.fsmodel = None
self.setup_fs_model()
self._scrollbar_positions = None
# ---- Model
def setup_fs_model(self):
"""Setup filesystem model"""
filters = QDir.AllDirs | QDir.Files | QDir.Drives | QDir.NoDotAndDotDot
self.fsmodel = QFileSystemModel(self)
self.fsmodel.setFilter(filters)
self.fsmodel.setNameFilterDisables(False)
def install_model(self):
"""Install filesystem model"""
self.setModel(self.fsmodel)
def setup_view(self):
"""Setup view"""
self.install_model()
self.connect(self.fsmodel, SIGNAL("directoryLoaded(QString)"), lambda: self.resizeColumnToContents(0))
self.setAnimated(False)
self.setSortingEnabled(True)
self.sortByColumn(0, Qt.AscendingOrder)
def set_name_filters(self, name_filters):
"""Set name filters"""
self.name_filters = name_filters
self.fsmodel.setNameFilters(name_filters)
def set_show_all(self, state):
"""Toggle 'show all files' state"""
if state:
self.fsmodel.setNameFilters([])
else:
self.fsmodel.setNameFilters(self.name_filters)
def get_filename(self, index):
"""Return filename associated with *index*"""
if index:
return osp.normpath(unicode(self.fsmodel.filePath(index)))
def get_index(self, filename):
"""Return index associated with filename"""
return self.fsmodel.index(filename)
def get_selected_filenames(self):
"""Return selected filenames"""
if self.selectionMode() == self.ExtendedSelection:
return [self.get_filename(idx) for idx in self.selectedIndexes()]
else:
return [self.get_filename(self.currentIndex())]
def get_dirname(self, index):
"""Return dirname associated with *index*"""
fname = self.get_filename(index)
if fname:
if osp.isdir(fname):
return fname
else:
return osp.dirname(fname)
# ---- Tree view widget
def setup(self, name_filters=["*.py", "*.pyw"], valid_types=(".py", ".pyw"), show_all=False):
"""Setup tree widget"""
self.setup_view()
self.set_name_filters(name_filters)
self.valid_types = valid_types
self.show_all = show_all
# Setup context menu
self.menu = QMenu(self)
self.common_actions = self.setup_common_actions()
# ---- Context menu
def setup_common_actions(self):
"""Setup context menu common actions"""
# Filters
filters_action = create_action(
self, _("Edit filename filters..."), None, get_icon("filter.png"), triggered=self.edit_filter
)
# Show all files
all_action = create_action(self, _("Show all files"), toggled=self.toggle_all)
all_action.setChecked(self.show_all)
self.toggle_all(self.show_all)
return [filters_action, all_action]
#.........这里部分代码省略.........
示例9: MainWindow
# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.QFileSystemModel import setFilter [as 别名]
class MainWindow(QWidget):
'''
The initial method creates the window and connects the rename method.
'''
def __init__(self):
QWidget.__init__(self)
self.setWindowTitle("cuteRenamer")
#Set Data-Model for showing the directories
self.dirModel = QFileSystemModel()
self.dirModel.setRootPath('/')
self.dirModel.setFilter(QDir.AllDirs | QDir.NoDotAndDotDot)#Show only directories without '.' and '..'
#Set the view for the directories
self.dirView = QTreeView()
self.dirView.setModel(self.dirModel)
#Show only the directories in the view
self.dirView.setColumnHidden(1, True)
self.dirView.setColumnHidden(2, True)
self.dirView.setColumnHidden(3, True)
self.dirView.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
#Listedit for the optional listfile
listPathLabel = QLabel("Path to list:")
self.listPathEdit = QLineEdit()
#Start renaming with number...
startLabel = QLabel("Start (default is 1)")
self.startEdit = QLineEdit()
#LineEdit for the prefix
prefixLabel = QLabel("Prefix")
self.prefixEdit = QLineEdit()
#LineEdit for the postfix
postfixLabel = QLabel("Postfix")
self.postfixEdit = QLineEdit()
#Checkbox to conserve file extensions
self.checkboxConserve = QCheckBox("Conserve file extensions")
checkboxLayout = QHBoxLayout()
checkboxLayout.addStretch(1)
checkboxLayout.addWidget(self.checkboxConserve)
#The button to start renaming
renameButton = QPushButton('Rename!')
buttonsLayout = QHBoxLayout()
buttonsLayout.addStretch(1)
buttonsLayout.addWidget(renameButton)
vertical = QVBoxLayout()
vertical.addWidget(self.dirView)
vertical.addSpacing(10)
vertical.addWidget(listPathLabel)
vertical.addWidget(self.listPathEdit)
vertical.addSpacing(10)
vertical.addWidget(startLabel)
vertical.addWidget(self.startEdit)
vertical.addSpacing(10)
vertical.addWidget(prefixLabel)
vertical.addWidget(self.prefixEdit)
vertical.addSpacing(10)
vertical.addWidget(postfixLabel)
vertical.addWidget(self.postfixEdit)
vertical.addSpacing(10)
vertical.addLayout(checkboxLayout)
vertical.addSpacing(20)
vertical.addLayout(buttonsLayout)
self.setLayout(vertical)
#If the button is clicked start the renaming
self.connect(renameButton, SIGNAL('clicked()'), self.rename)
'''
This method prepares all options and starts the rename progress.
'''
def rename(self):
selectedIndex = self.dirView.selectedIndexes()
if self.listPathEdit.text() == "":
print "Read the whole directory"
files = os.listdir(self.dirModel.filePath(selectedIndex[0]))
elif (not self.listPathEdit.text() == "") and os.path.isfile(self.listPathEdit.text()):
print "Read filenames from %s" % self.listPathEdit.text()
files = [i.rstrip('\n') for i in open(self.listPathEdit.text(), "r")]
else:
print "Path to list doesn't exist or is not a file!"
if not self.startEdit.text() == "":
start = int(self.startEdit.text())
else:
start = 1
#.........这里部分代码省略.........