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


Python QDirModel.fileInfo方法代码示例

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


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

示例1: FileSystemBrowser

# 需要导入模块: from PyQt4.QtGui import QDirModel [as 别名]
# 或者: from PyQt4.QtGui.QDirModel import fileInfo [as 别名]
class FileSystemBrowser(QTreeView):
    """simple file system browser"""

    def __init__(self):
        QTreeView.__init__(self)
        self.model = QDirModel()
        self.setModel(self.model)
        self.setSortingEnabled(True)
        self.setAlternatingRowColors(True)
        self.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.setContextMenuPolicy(Qt.CustomContextMenu)
        self.setAutoExpandDelay(500)
        i = self.model.index(os.getcwd())
        self.scrollTo(i)
        self.expand(i)
        self.setCurrentIndex(i)
        for i in range(self.model.columnCount()):
            self.resizeColumnToContents(i)
        self.connect(self, SIGNAL("doubleClicked(QModelIndex)"), self.itemAction)
        self.connect(self, SIGNAL("customContextMenuRequested(QPoint)"), self.showContextMenu)


    def itemAction(self, mi):
        """default action (on doubleclick) for item at model index mi"""
        fi = self.model.fileInfo(mi)
        if self.model.isDir(mi):
            return
        path = str(fi.absoluteFilePath())
        if not SimuVis4.Globals.fileTypeActions.openFile(path):
            self.openExternal(path)

    def showContextMenu(self, pos):
        """show context menu for item at pos"""
        mi = self.indexAt(pos)
        fi = self.model.fileInfo(mi)
        m = QMenu()
        self.path = str(fi.absoluteFilePath())
        if self.model.isDir(mi):
            m.addAction(QCoreApplication.translate('DataBrowser', 'Refresh'),
                lambda x=mi: self.model.refresh(x))
        else:
            for a in SimuVis4.Globals.fileTypeActions.getActions(self.path):
                # this is weird, ... but it works
                m.addAction(a[0], lambda x=a[1]: x(self.path))
        m.addSeparator()
        m.addAction(QCoreApplication.translate('DataBrowser', 'Open external'),
            self.openExternal)
        a = m.exec_(self.mapToGlobal(pos))

    def openExternal(self, path=None):
        if not path:
            path = self.path
        QDesktopServices.openUrl(QUrl.fromLocalFile(path))
开发者ID:BackupTheBerlios,项目名称:simuvis4-svn,代码行数:55,代码来源:Browser.py

示例2: filexplorerPluginMain

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

#.........这里部分代码省略.........
        print(" INFO: OK: QProcess finished . . . ")

    def search(self):
        ' function to search python files '
        # get search results of python filenames local or remote
        pypi_url = 'http://pypi.python.org/pypi'
        # pypi query
        pypi = xmlrpclib.ServerProxy(pypi_url, transport=ProxyTransport())
        try:
            pypi_query = pypi.search({'name': str(self.srch.text()).lower()})
            pypi_fls = list(set(['pypi.python.org/pypi/' + a['name'] +
                   ' | pip install ' + a['name'] for a in pypi_query]))
        except:
            pypi_fls = '<b> ERROR: Internet not available! ಠ_ಠ </b>'
        s_out = ('<br> <br> <br> <h3> Search Local Python files: </h3> <hr> ' +
        # Jedi list comprehension for LOCAL search
        str(["{}/{}".format(root, f) for root, f in list(itertools.chain(*
            [list(itertools.product([root], files))
            for root, dirs, files in walk(str(
            QFileDialog.getExistingDirectory(self.dock,
            'Open Directory to Search', path.expanduser("~"))))]))
            if f.endswith(('.py', '.pyw', '.pth')) and not f.startswith('.')
            and str(self.srch.text()).lower().strip() in f]
        ).replace(',', '<br>') + '<hr><h3> Search PyPI Python files: </h3>' +
        # wraped pypi query REMOTE search
        str(pypi_fls).replace(',', '<br>') + '<hr>Auto-Proxy:ON,DoNotTrack:ON')
        # print(s_out)
        try:
            call('notify-send fileXplorer Searching...', shell=True)
        except:
            pass
        self.srch.clear()
        self.textBrowser.setGeometry(self.dock.geometry())
        self.textBrowser.setHtml(s_out)
        self.textBrowser.show()
        tmr = QTimer(self.fileView)
        tmr.timeout.connect(self.textBrowser.hide)
        tmr.start(20000)

    def iconChooser(self):
        ' Choose a Icon and copy it to clipboard '
        #
        from .std_icon_naming import std_icon_naming as a
        #
        prv = QDialog(self.dock)
        prv.setWindowFlags(Qt.FramelessWindowHint)
        prv.setAutoFillBackground(True)
        prv.setGeometry(self.fileView.geometry())
        table = QTableWidget(prv)
        table.setColumnCount(1)
        table.setRowCount(len(a))
        table.verticalHeader().setVisible(True)
        table.horizontalHeader().setVisible(False)
        table.setShowGrid(True)
        table.setIconSize(QSize(128, 128))
        for index, icon in enumerate(a):
            item = QTableWidgetItem(QIcon.fromTheme(icon), '')
            # item.setData(Qt.UserRole, '')
            item.setToolTip(icon)
            table.setItem(index, 0, item)
        table.clicked.connect(lambda: QApplication.clipboard().setText(
          'QtGui.QIcon.fromTheme("{}")'.format(table.currentItem().toolTip())))
        table.doubleClicked.connect(prv.close)
        table.resizeColumnsToContents()
        table.resizeRowsToContents()
        QLabel('<h3> <br> 1 Click Copy, 2 Clicks Close </h3>', table)
        table.resize(prv.size())
        prv.exec_()

    def runfile(self, index):
        ' run the choosed file '
        s = str(file(self.model.filePath(index), 'r').read().strip())
        f = str(self.model.filePath(index))
        # ctime is NOT crossplatform,metadata change on *nix,creation on Window
        # http://docs.python.org/library/os.path.html#os.path.getctime
        m = ''.join((f, N, str(path.getsize(f) / 1024), ' Kilobytes', N,
            str(len(file(f, 'r').readlines())), ' Lines', N,
            str(len(s.replace(N, ''))), ' Characters', N,
            str(len([a for a in sub('[^a-zA-Z0-9 ]', '', s).split(' ')
                if a != ''])), ' Words', N,
            str(len([a for a in s if a in punctuation])), ' Punctuation', N,
            oct(stat(f).st_mode)[-3:], ' Permissions', N,
            time.ctime(path.getatime(f)), ' Accessed', N,
            time.ctime(path.getmtime(f)), ' Modified', N,
            'Owner: ', str(self.model.fileInfo(index).owner()), N,
            'Is Writable: ', str(self.model.fileInfo(index).isWritable()), N,
            'Is Executable: ', str(self.model.fileInfo(index).isExecutable()),
            N, 'Is Hidden: ', str(self.model.fileInfo(index).isHidden()), N,
            'Is SymLink: ', str(self.model.fileInfo(index).isSymLink()), N,
            'File Extension: ', str(self.model.fileInfo(index).suffix())
        ))
        #print(m)
        self.preview.setToolTip(m)
        self.preview.setText(s)
        self.preview.resize(self.preview.size().width(),
                            self.dock.size().height())
        self.process.start('xdg-open {}'.format(f))
        if not self.process.waitForStarted():
            print((" ERROR: Process {} Failed ! ".format(str(f))))
            return
开发者ID:juancarlospaco,项目名称:fileXplorer,代码行数:104,代码来源:gui.py


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