annotate MainWindow.py @ 31:5bb57caa8f66

display a feed's entries sorted by their update date
author Dirk Olmes <dirk@xanthippe.ping.de>
date Fri, 30 Apr 2010 06:01:54 +0200
parents bdd1296a4b8c
children f371d02fa09d
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
27
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
2 from AddFeed import AddFeed
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: 19
diff changeset
3 from DisplayModel import DisplayModel
15
b1aeb98824c1 Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 14
diff changeset
4 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
5 from FeedEntry import FeedEntry
23
dcc8abff0694 All the wiring of slots is done through QtDesigner now, look how much code has just disappeared :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
6 from PyQt4 import QtGui
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: 19
diff changeset
7 from PyQt4.QtCore import QUrl
31
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
8 from PyQt4.QtGui import QFont
14
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
9 from Ui_MainWindow import Ui_MainWindow
31
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
10 import FeedUpdater
14
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
11
24
6b5ceffabe49 MainWindowController -> MainWindow
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 23
diff changeset
12 class MainWindow(QtGui.QMainWindow):
14
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
13 def __init__(self, session=None):
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
14 QtGui.QWidget.__init__(self, None)
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
15 self.session = session
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
16 self.ui = Ui_MainWindow()
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
17 self.ui.setupUi(self)
27
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
18 self.updateFeedList()
31
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
19 self.initFeedEntryList()
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
31
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
21 def updateFeedList(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
22 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
23 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
24 self.ui.feedList.setModel(feedModel)
27
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
25 self.ui.feedList.update()
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
26
31
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
27 def initFeedEntryList(self):
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
28 pass
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
29 # self.ui.feedEntryList.setItemDelegate()
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
30 # self.ui.feedList.setItemDelegate(CustomItemDelegate(self))
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
31
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
32 def feedSelected(self, index):
19
6f7003fc6e6d display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 18
diff changeset
33 self.selectedFeed = self.allFeeds[index.row()]
31
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
34 sortedEntries = self.selectedFeed.entriesSortedByUpdateDate()
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
35 model = DisplayModel(self, sortedEntries, FeedEntry.userPresentableString)
18
35225588b895 add a list view for displaying feed entries from the selected feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
36 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
37 self.ui.feedEntryList.update()
19
6f7003fc6e6d display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 18
diff changeset
38
6f7003fc6e6d display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 18
diff changeset
39 def feedEntrySelected(self, index):
6f7003fc6e6d display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 18
diff changeset
40 row = index.row()
6f7003fc6e6d display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 18
diff changeset
41 entry = self.selectedFeed.entries[row]
6f7003fc6e6d display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 18
diff changeset
42 baseUrl = QUrl(entry.link) # TODO this is the wrong base url, figure out the correct one
6f7003fc6e6d display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 18
diff changeset
43 self.ui.webView.setHtml(entry.summary, baseUrl)
15
b1aeb98824c1 Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 14
diff changeset
44
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: 19
diff changeset
45 def addFeed(self):
27
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
46 addFeed = AddFeed(self.session)
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
47 success = addFeed.exec_()
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
48 if success:
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
49 url = addFeed.getUrl()
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
50 FeedUpdater.createNewFeed(url, self.session)
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
51 # TODO get status from feedUpdater and display in status area of the main window
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
52 self.updateFeedList()
31
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
53
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
54 class CustomItemDelegate(QtGui.QStyledItemDelegate):
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
55 def __init__(self, parent):
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
56 print("init")
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
57 QtGui.QStyledItemDelegate.__init__(self, parent)
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
58
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
59 def paint(self, painter, style, index):
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
60 style.font.setWeight(QFont.Bold)
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
61 QtGui.QStyledItemDelegate.paint(self, painter, style, index)