当前位置: 首页>>代码示例>>Python>>正文


Python QFileSystemModel.fileInfo方法代码示例

本文整理汇总了Python中PyQt4.QtGui.QFileSystemModel.fileInfo方法的典型用法代码示例。如果您正苦于以下问题:Python QFileSystemModel.fileInfo方法的具体用法?Python QFileSystemModel.fileInfo怎么用?Python QFileSystemModel.fileInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtGui.QFileSystemModel的用法示例。


在下文中一共展示了QFileSystemModel.fileInfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DirectoryWidget

# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.QFileSystemModel import fileInfo [as 别名]

#.........这里部分代码省略.........
        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):
        index = self.listView.currentIndex()
开发者ID:wioota,项目名称:ftools-qgis,代码行数:70,代码来源:widgets.py

示例2: mainInitial

# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.QFileSystemModel import fileInfo [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)
开发者ID:yeimiJuarez,项目名称:SSHingON,代码行数:78,代码来源:SSHingON.py


注:本文中的PyQt4.QtGui.QFileSystemModel.fileInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。