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


Python QFileSystemModel.data方法代码示例

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


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

示例1: AbstractPathCompleter

# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.QFileSystemModel import data [as 别名]
class AbstractPathCompleter(AbstractCompleter):
    """Base class for PathCompleter and GlobCompleter
    """
    
    # global object. Reused by all completers
    _fsModel = QFileSystemModel()

    _ERROR = 'error'
    _HEADER = 'currentDir'
    _STATUS = 'status'
    _DIRECTORY = 'directory'
    _FILE = 'file'
    
    def __init__(self, text):
        self._originalText = text
        self._dirs = []
        self._files = []
        self._error = None
        self._status = None
        
        """hlamer: my first approach is making self._model static member of class. But, sometimes it 
        returns incorrect icons. I really can't understand when and why.
        When it is private member of instance, it seems it works
        """
        self._model = None # can't construct in the construtor, must be constructed in GUI thread
    
    @staticmethod
    def _filterHidden(paths):
        """Remove hidden and ignored files from the list
        """
        return [path for path in paths \
                    if not os.path.basename(path).startswith('.') and \
                        not core.fileFilter().regExp().match(path)]

    def _classifyRowIndex(self, row):
        """Get list item type and index by it's row
        """

        if self._error:
            assert row == 0
            return (self._ERROR, 0)
        
        if row == 0:
            return (self._HEADER, 0)
        
        row -= 1
        if self._status:
            if row == 0:
                return (self._STATUS, 0)
            row -= 1
        
        if row in range(len(self._dirs)):
            return (self._DIRECTORY, row)
        row -= len(self._dirs)
        
        if row in range(len(self._files)):
            return (self._FILE, row)
        
        assert False

    def _formatHeader(self, text):
        """Format current directory for show it in the list of completions
        """
        return '<font style="background-color: %s; color: %s">%s</font>' % \
                (QApplication.instance().palette().color(QPalette.Window).name(),
                 QApplication.instance().palette().color(QPalette.WindowText).name(),
                 htmlEscape(text))

    def rowCount(self):
        """Row count in the list of completions
        """
        if self._error:
            return 1
        else:
            count = 1  # current directory
            if self._status:
                count += 1
            count += len(self._dirs)
            count += len(self._files)
            return count

    def _iconForPath(self, path):
        """Get icon for file or directory path. Uses QFileSystemModel
        """
        if self._model is None:
            self._model = QFileSystemModel()
        
        index = self._model.index(path)
        return self._model.data(index, Qt.DecorationRole)

    def text(self, row, column):
        """Item text in the list of completions
        """
        rowType, index = self._classifyRowIndex(row)
        if rowType == self._ERROR:
            return '<font color=red>%s</font>' % htmlEscape(self._error)
        elif rowType == self._HEADER:
            return self._formatHeader(self._headerText())
        elif rowType == self._STATUS:
            return '<i>%s</i>' % htmlEscape(self._status)
#.........这里部分代码省略.........
开发者ID:daffodil,项目名称:enki,代码行数:103,代码来源:pathcompleter.py

示例2: data

# 需要导入模块: from PyQt4.QtGui import QFileSystemModel [as 别名]
# 或者: from PyQt4.QtGui.QFileSystemModel import data [as 别名]
 def data(self, index, role):
     if role == Qt.ToolTipRole:
         return self.filePath(index)
     else:
         return QFileSystemModel.data(self, index, role)
开发者ID:adjustive,项目名称:enki,代码行数:7,代码来源:filebrowser.py


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