annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
217
bb3c851b18b1 add source file endcoding header
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 148
diff changeset
1 # -*- coding: utf-8 -*-
21
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
2 from PyQt4.QtCore import QAbstractListModel, QModelIndex, QVariant, Qt
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
3
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
4 class DisplayModel(QAbstractListModel):
119
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
5 def __init__(self, parent=None, list=None, displayAttribute=None, **args):
218
699d8f1cebd4 unify imports, especially Qt imports. Use consistent super syntax
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 217
diff changeset
6 super(DisplayModel, self).__init__(parent, *args)
21
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
7 self.list = list
119
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
8 self.displayAttribute = displayAttribute
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
9
21
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
10 def rowCount(self, parent=QModelIndex()):
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
11 return len(self.list)
119
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
12
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
13 def data(self, index, role):
21
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
14 if index.isValid() and role == Qt.DisplayRole:
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
15 row = index.row()
148
c5a427d46703 displaying entries for a feed works now with the couchdb backend
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 119
diff changeset
16 item = self.list[row]
c5a427d46703 displaying entries for a feed works now with the couchdb backend
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 119
diff changeset
17 displayString = self._stringToDisplay(item)
21
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
18 return QVariant(displayString)
119
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
19 else:
21
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
20 return QVariant()
119
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
21
148
c5a427d46703 displaying entries for a feed works now with the couchdb backend
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 119
diff changeset
22 def _stringToDisplay(self, item):
c5a427d46703 displaying entries for a feed works now with the couchdb backend
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 119
diff changeset
23 if hasattr(item, self.displayAttribute):
c5a427d46703 displaying entries for a feed works now with the couchdb backend
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 119
diff changeset
24 return getattr(item, self.displayAttribute)
119
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
25 else:
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
26 return "invalid display attribute: " + self.displayAttribute