Mercurial > hg > Feedworm
annotate MainWindowController.py @ 15:b1aeb98824c1
Add a list view displaying all feeds
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Wed, 28 Apr 2010 02:57:41 +0200 |
parents | 42a225be7e56 |
children | 3ffecc709da9 |
rev | line source |
---|---|
14 | 1 |
15
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
2 from Feed import Feed |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
3 from PyQt4 import QtGui |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
4 from PyQt4.QtCore import QAbstractListModel |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
5 from PyQt4.QtCore import QModelIndex |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
6 from PyQt4.QtCore import Qt |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
7 from PyQt4.QtCore import QVariant |
14 | 8 from Ui_MainWindow import Ui_MainWindow |
9 | |
10 class MainWindowController(QtGui.QMainWindow): | |
11 def __init__(self, session=None): | |
12 QtGui.QWidget.__init__(self, None) | |
13 self.session = session | |
14 self.ui = Ui_MainWindow() | |
15 self.ui.setupUi(self) | |
15
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
16 self.connectWidgets() |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
17 |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
18 def connectWidgets(self): |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
19 feedModel = FeedModel(self) |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
20 self.ui.feedList.setModel(feedModel) |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
21 |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
22 class FeedModel(QAbstractListModel): |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
23 def __init__(self, parent=None, **args): |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
24 QAbstractListModel.__init__(self, parent, *args) |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
25 self.session = parent.session |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
26 self.fetchAllFeeds() |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
27 |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
28 def fetchAllFeeds(self): |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
29 self.allFeeds = self.session.query(Feed).all() |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
30 |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
31 def rowCount(self, parent=QModelIndex()): |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
32 return len(self.allFeeds) |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
33 |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
34 def data(self, index, role): |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
35 if index.isValid() and role == Qt.DisplayRole: |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
36 row = index.row() |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
37 feed = self.allFeeds[row] |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
38 return QVariant(feed.title) |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
39 else: |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
40 return QVariant() |