本文整理汇总了Python中PyQt4.QtGui.QFileSystemModel.isDir方法的典型用法代码示例。如果您正苦于以下问题:Python QFileSystemModel.isDir方法的具体用法?Python QFileSystemModel.isDir怎么用?Python QFileSystemModel.isDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QFileSystemModel
的用法示例。
在下文中一共展示了QFileSystemModel.isDir方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Explorer
# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.QFileSystemModel import isDir [as 别名]
class Explorer(QTreeView):
def __init__(self, parent=None):
QTreeView.__init__(self)
self.header().setHidden(True)
self.setAnimated(True)
# Modelo
self.model = QFileSystemModel(self)
path = QDir.toNativeSeparators(QDir.homePath())
self.model.setRootPath(path)
self.setModel(self.model)
self.model.setNameFilters(["*.c", "*.h", "*.s"])
self.setRootIndex(QModelIndex(self.model.index(path)))
self.model.setNameFilterDisables(False)
# Se ocultan algunas columnas
self.hideColumn(1)
self.hideColumn(2)
self.hideColumn(3)
# Conexion
self.doubleClicked.connect(self._open_file)
Edis.load_lateral("explorer", self)
def _open_file(self, i):
if not self.model.isDir(i):
indice = self.model.index(i.row(), 0, i.parent())
archivo = self.model.filePath(indice)
principal = Edis.get_component("principal")
principal.open_file(archivo)
示例2: Explorador
# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.QFileSystemModel import isDir [as 别名]
class Explorador(custom_dock.CustomDock):
def __init__(self, parent=None):
custom_dock.CustomDock.__init__(self)
self.explorador = QTreeView()
self.setWidget(self.explorador)
self.explorador.header().setHidden(True)
self.explorador.setAnimated(True)
# Modelo
self.modelo = QFileSystemModel(self.explorador)
path = QDir.toNativeSeparators(QDir.homePath())
self.modelo.setRootPath(path)
self.explorador.setModel(self.modelo)
self.modelo.setNameFilters(["*.c", "*.h", "*.s"])
self.explorador.setRootIndex(QModelIndex(self.modelo.index(path)))
self.modelo.setNameFilterDisables(False)
# Se ocultan algunas columnas
self.explorador.hideColumn(1)
self.explorador.hideColumn(2)
self.explorador.hideColumn(3)
# Conexion
self.explorador.doubleClicked.connect(self._abrir_archivo)
EDIS.cargar_lateral("explorador", self)
def _abrir_archivo(self, i):
if not self.modelo.isDir(i):
indice = self.modelo.index(i.row(), 0, i.parent())
archivo = self.modelo.filePath(indice)
principal = EDIS.componente("principal")
principal.abrir_archivo(archivo)
示例3: DirectoryWidget
# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.QFileSystemModel import isDir [as 别名]
#.........这里部分代码省略.........
hbox.addWidget(setButton)
hbox.addWidget(hiddenButton)
vbox = QVBoxLayout(self)
vbox.addLayout(hbox)
vbox.addWidget(self.lineEdit)
vbox.addWidget(self.listView)
vbox.addWidget(filterLabel)
vbox.addWidget(filterLineEdit)
def toggleHidden(self, toggled):
base = QDir.AllDirs|QDir.AllEntries|QDir.NoDotAndDotDot
if toggled:
self.model.setFilter(base|QDir.Hidden)
else:
self.model.setFilter(base)
def gotoFolder(self):
text = self.lineEdit.text()
self.listView.setRootIndex(self.proxyModel.mapFromSource(self.model.index(text, 0)))
def rootChanged(self):
index1 = self.listView.rootIndex()
index2 = self.proxyModel.mapToSource(index1)
self.lineEdit.setText(self.model.filePath(index2))
self.listView.setCurrentIndex(index1)
def customContext(self, pos):
index = self.listView.indexAt(pos)
index = self.proxyModel.mapToSource(index)
if not index.isValid():
self.rmAction.setEnabled(False)
self.openAction.setEnabled(False)
self.loadAction.setEnabled(False)
elif not self.model.isDir(index):
info = self.model.fileInfo(index)
suffix = info.suffix()
if suffix in ("Rd","Rdata","RData"):
self.loadAction.setEnabled(True)
self.openAction.setEnabled(False)
self.loadExternal.setEnabled(False)
elif suffix in ("txt","csv","R","r"):
self.openAction.setEnabled(True)
self.loadAction.setEnabled(False)
self.loadExternal.setEnabled(True)
else:
self.loadAction.setEnabled(False)
self.openAction.setEnabled(False)
self.loadExternal.setEnabled(True)
menu = QMenu(self)
for action in self.actions:
menu.addAction(action)
menu.exec_(self.listView.mapToGlobal(pos))
def openItem(self):
index = self.listView.currentIndex()
index = self.proxyModel.mapToSource(index)
self.emit(SIGNAL("openFileRequest(QString)"),
self.model.filePath(index))
def loadItem(self):
index = self.listView.currentIndex()
index = self.proxyModel.mapToSource(index)
self.emit(SIGNAL("loadFileRequest(QString)"),
self.model.filePath(index))
def externalItem(self):
示例4: SourceFileTreeWidget
# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.QFileSystemModel import isDir [as 别名]
class SourceFileTreeWidget(QWidget):
""" Config window"""
def __init__(self, parent):
super(SourceFileTreeWidget, self).__init__(parent)
self.ui = Ui_SourceFileTreeWidget()
self.ui.setupUi(self)
self.file_model = QFileSystemModel()
#self.file_model.setFilter(QDir.AllEntries | QDir.NoDot)
self.set_filter()
self.ui.tree.setModel(self.file_model)
self.ui.tree.resizeColumnToContents(0)
self.ui.custom_root.setText(QDir.currentPath())
self.set_root()
header = self.ui.tree.header()
header.setResizeMode(QHeaderView.ResizeToContents)
#header.setStretchLastSection(True)
#header.setSortIndicator(0, Qt.AscendingOrder)
#header.setSortIndicatorShown(True)
#header.setClickable(True)
self.connect(self.ui.tree, QtCore.SIGNAL('doubleClicked(QModelIndex)'), self.open_file)
self.connect(self.ui.ok_filter, QtCore.SIGNAL('clicked()'), self.set_filter)
self.connect(self.ui.custom_filter, QtCore.SIGNAL('returnPressed()'), self.set_filter)
self.connect(self.ui.ok_root, QtCore.SIGNAL('clicked()'), self.set_root)
self.connect(self.ui.custom_root, QtCore.SIGNAL('returnPressed()'), self.set_root)
self.open_file_signal = None
def set_open_file_signal(self, signal):
""" callback to signal file opening """
self.open_file_signal = signal
def set_root(self, root=None, use_common_prefix=True):
""" set the root path of the widget """
curr = str(self.ui.custom_root.text())
if not root:
use_common_prefix = False # input text box will override it.
root = self.ui.custom_root.text()
else:
self.ui.custom_root.setText(root)
idx = self.file_model.index(root)
self.ui.tree.setExpanded(idx, True)
if use_common_prefix and curr == os.path.commonprefix([root, curr]):
return
idx = self.file_model.setRootPath(root)
if not idx.isValid():
logging.warn('Invalid path')
return
self.ui.tree.setRootIndex(idx)
self.ui.tree.setExpanded(idx, True)
def set_filter(self):
""" set filter by extension """
filters = str(self.ui.custom_filter.text()).split(';')
self.file_model.setNameFilters(filters)
self.file_model.setNameFilterDisables(False)
def open_file(self, idx):
""" emit file opening signal """
if self.file_model.isDir(idx):
return
fullpath = self.file_model.filePath(idx)
if self.open_file_signal:
self.open_file_signal.emit(str(fullpath), 0)
def set_file_selected(self, tab_idx):
""" slot to associate the file in active tab """
filename = self.sender().tabToolTip(tab_idx)
idx = self.file_model.index(filename)
if idx.isValid():
self.ui.tree.selectionModel().select(idx, QItemSelectionModel.ClearAndSelect)
示例5: mainInitial
# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.QFileSystemModel import isDir [as 别名]
class mainInitial(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow() #treeview UI
self.ui.setupUi(self)
self.showMaximized()
self.home=os.getcwd()
self.fileSystemModel = QFileSystemModel()
#self.home=self.home + "/connections"
#print (self.home)
self.fillGrid2(self.home)
#self.ui.treeWidget.isSortingEnabled()
#self.ui.treeWidget.setSortingEnabled(True)
self.ui.treeView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.connect(self.ui.treeView, QtCore.SIGNAL("customContextMenuRequested(const QPoint &)"), self.onclick)
#self.connect(self.ui.treeView.selectionModel(),
# SIGNAL("customContextMenuRequested(pressed)"), self.onclick)
# def eventFilter(self, obj, event):
# if event.type() in (QtCore.QEvent.MouseButtonPress, QtCore.QEvent.MouseButtonDblClick):
# if event.button() == QtCore.Qt.LeftButton:
# print "left"
# return True
# elif event.button() == QtCore.Qt.RightButton:
# print "Right"
# return True
# return super(mainInitial, self).eventFilter(obj, event)
#
# #self.button2.clicked.connect(self.on_button_clicked)
#
# #self.button1.installEventFilter(self)
@QtCore.pyqtSlot(QtCore.QModelIndex)
def onclick(self,selected):
index=self.ui.treeView.indexAt(selected)
#getSelected= self.ui.treeView.selectedItems()
print (index)
fileinfo = QtCore.QFileInfo(self.fileSystemModel.fileInfo(index) )
print (fileinfo)
path = self.fileSystemModel.filePath(index)
#pathABS =self.fileSystemModel.rootPath(index)
print path
#print pathABS
if self.fileSystemModel.isDir(index):
print ("es directorio")
else:
print ("es archivo")
menu=QtGui.QMenu(self)
action_1=menu.addAction("crear coneccion")
action_1.triggered.connect(self.action1)
action_2=menu.addAction("borrar coneccion")
action_3=menu.addAction("Modificar coneccion")
action_4=menu.addAction("Crear Carpeta")
menu.exec_(QtGui.QCursor.pos())
#menu1=self.menu.addAction(u'algo')
#menu1.triggered.connect(self.M1clear)
#print ("determinar si esta vacio, es archivo o carpeta derecho")
def action1(self, index):
print "accion lanzada action_1"
#self.fileSystemModel.mkdir()
#print (self.ui.treeView.indexAt(index))
def fillGrid2(self,home):
print (QDir.currentPath())
self.fileSystemModel.setRootPath(QDir.currentPath())
self.ui.treeView.setModel(self.fileSystemModel)
self.ui.treeView.setRootIndex(self.fileSystemModel.index(QDir.currentPath()))
self.ui.treeView.hideColumn(1)
self.ui.treeView.hideColumn(2)
self.ui.treeView.hideColumn(3)