annotate MainWindowController.py @ 18:35225588b895

add a list view for displaying feed entries from the selected feed
author Dirk Olmes <dirk@xanthippe.ping.de>
date Wed, 28 Apr 2010 03:46:47 +0200
parents 5fda8bd94fa8
children 6f7003fc6e6d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
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
18
35225588b895 add a list view for displaying feed entries from the selected feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
3 from FeedEntry import FeedEntry
17
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
4 from PyQt4 import QtCore, QtGui
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
5 from PyQt4.QtCore import QAbstractListModel, QModelIndex, QVariant, Qt
14
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
6 from Ui_MainWindow import Ui_MainWindow
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
7
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
8 class MainWindowController(QtGui.QMainWindow):
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
9 def __init__(self, session=None):
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
10 QtGui.QWidget.__init__(self, None)
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
11 self.session = session
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
12 self.ui = Ui_MainWindow()
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
13 self.ui.setupUi(self)
17
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
14 self.setupWidgets()
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
15
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
16 def setupWidgets(self):
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
17 self.setupFeedList()
18
35225588b895 add a list view for displaying feed entries from the selected feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
18 self.setupFeedEntryList()
15
b1aeb98824c1 Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 14
diff changeset
19
17
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
20 def setupFeedList(self):
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
21 self.allFeeds = Feed.all(self.session)
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
22 feedModel = DisplayModel(self, self.allFeeds, Feed.userPresentableString)
15
b1aeb98824c1 Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 14
diff changeset
23 self.ui.feedList.setModel(feedModel)
17
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
24 self.connect(self.ui.feedList, QtCore.SIGNAL("clicked(QModelIndex)"), self.feedSelected)
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
25
18
35225588b895 add a list view for displaying feed entries from the selected feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
26 def setupFeedEntryList(self):
35225588b895 add a list view for displaying feed entries from the selected feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
27 pass
35225588b895 add a list view for displaying feed entries from the selected feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
28
17
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
29 def feedSelected(self, index):
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
30 feed = self.allFeeds[index.row()]
18
35225588b895 add a list view for displaying feed entries from the selected feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
31 model = DisplayModel(self, feed.entries, FeedEntry.userPresentableString)
35225588b895 add a list view for displaying feed entries from the selected feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
32 self.ui.feedEntryList.setModel(model)
35225588b895 add a list view for displaying feed entries from the selected feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
33 self.ui.feedEntryList.update()
15
b1aeb98824c1 Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 14
diff changeset
34
17
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
35 class DisplayModel(QAbstractListModel):
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
36 def __init__(self, parent=None, list=None, displayFunction=None, **args):
15
b1aeb98824c1 Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 14
diff changeset
37 QAbstractListModel.__init__(self, parent, *args)
17
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
38 self.list = list
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
39 self.displayFunction = displayFunction
16
3ffecc709da9 move fetch logic into Feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 15
diff changeset
40
15
b1aeb98824c1 Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 14
diff changeset
41 def rowCount(self, parent=QModelIndex()):
17
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
42 return len(self.list)
15
b1aeb98824c1 Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 14
diff changeset
43
b1aeb98824c1 Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 14
diff changeset
44 def data(self, index, role):
b1aeb98824c1 Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 14
diff changeset
45 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
46 row = index.row()
17
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
47 object = self.list[row]
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
48 displayString = self.displayFunction(object)
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
49 return QVariant(displayString)
15
b1aeb98824c1 Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 14
diff changeset
50 else:
17
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
51 return QVariant()