Mercurial > hg > Feedworm
annotate DisplayModel.py @ 77:d292ab61ed6f
Add another setting to feed: when opening a feed entry in browser, you can force opening it in an external browser now. This is because some sites just crash the QWebView.
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Sat, 14 Aug 2010 02:53:49 +0200 |
parents | c8bb3cee7935 |
children | 04a730f9d07d |
rev | line source |
---|---|
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
|
1 |
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): |
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
|
5 def __init__(self, parent=None, list=None, displayFunction=None, **args): |
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
|
6 QAbstractListModel.__init__(self, parent, *args) |
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 |
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
|
8 self.displayFunction = displayFunction |
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
|
9 |
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) |
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
|
12 |
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
|
13 def data(self, index, role): |
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() |
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
|
16 object = self.list[row] |
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
|
17 displayString = self.displayFunction(object) |
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) |
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
|
19 else: |
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() |