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


Python QDirModel.columnCount方法代码示例

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


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

示例1: FileSystemBrowser

# 需要导入模块: from PyQt4.QtGui import QDirModel [as 别名]
# 或者: from PyQt4.QtGui.QDirModel import columnCount [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: FileSystemBrowser

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

    def __init__(self):
        QTreeView.__init__(self)
        self.model = QDirModel()
        self.setModel(self.model)
        self.setSortingEnabled(True)
        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)
开发者ID:BackupTheBerlios,项目名称:simuvis4-svn,代码行数:16,代码来源:Browser.py


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