view DisplayModel.py @ 219:38d1898e7d82

include the time when logging
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sun, 27 Apr 2014 06:19:04 +0200
parents 699d8f1cebd4
children f6dcc85cd8ca
line wrap: on
line source

# -*- coding: utf-8 -*-
from PyQt4.QtCore import QAbstractListModel, QModelIndex, QVariant, Qt

class DisplayModel(QAbstractListModel):
    def __init__(self, parent=None, list=None, displayAttribute=None, **args):
        super(DisplayModel, self).__init__(parent, *args)
        self.list = list
        self.displayAttribute = displayAttribute

    def rowCount(self, parent=QModelIndex()):
        return len(self.list)

    def data(self, index, role):
        if index.isValid() and role == Qt.DisplayRole:
            row = index.row()
            item = self.list[row]
            displayString = self._stringToDisplay(item)
            return QVariant(displayString)
        else:
            return QVariant()

    def _stringToDisplay(self, item):
        if hasattr(item, self.displayAttribute):
            return getattr(item, self.displayAttribute)
        else:
            return "invalid display attribute: " + self.displayAttribute