Mercurial > hg > Feedworm
annotate MainWindowController.py @ 16:3ffecc709da9
move fetch logic into Feed
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Wed, 28 Apr 2010 03:00:11 +0200 |
parents | b1aeb98824c1 |
children | 5fda8bd94fa8 |
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 |
16
3ffecc709da9
move fetch logic into Feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
15
diff
changeset
|
26 self.allFeeds = Feed.all(parent.session) |
3ffecc709da9
move fetch logic into Feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
15
diff
changeset
|
27 |
15
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
28 def rowCount(self, parent=QModelIndex()): |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
29 return len(self.allFeeds) |
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 data(self, index, role): |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
32 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
|
33 row = index.row() |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
34 feed = self.allFeeds[row] |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
35 return QVariant(feed.title) |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
36 else: |
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
37 return QVariant() |