Mercurial > hg > Feedworm
comparison MainWindow.py @ 33:f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Fri, 30 Apr 2010 06:22:33 +0200 |
parents | 5bb57caa8f66 |
children | 22214d79ed41 |
comparison
equal
deleted
inserted
replaced
32:500ba01e7f7a | 33:f371d02fa09d |
---|---|
23 feedModel = DisplayModel(self, self.allFeeds, Feed.userPresentableString) | 23 feedModel = DisplayModel(self, self.allFeeds, Feed.userPresentableString) |
24 self.ui.feedList.setModel(feedModel) | 24 self.ui.feedList.setModel(feedModel) |
25 self.ui.feedList.update() | 25 self.ui.feedList.update() |
26 | 26 |
27 def initFeedEntryList(self): | 27 def initFeedEntryList(self): |
28 pass | 28 self.ui.feedEntryList.setItemDelegate(FeedEntryItemDelegate()) |
29 # self.ui.feedEntryList.setItemDelegate() | |
30 # self.ui.feedList.setItemDelegate(CustomItemDelegate(self)) | |
31 | 29 |
32 def feedSelected(self, index): | 30 def feedSelected(self, index): |
33 self.selectedFeed = self.allFeeds[index.row()] | 31 self.selectedFeed = self.allFeeds[index.row()] |
34 sortedEntries = self.selectedFeed.entriesSortedByUpdateDate() | 32 self.sortedEntries = self.selectedFeed.entriesSortedByUpdateDate() |
35 model = DisplayModel(self, sortedEntries, FeedEntry.userPresentableString) | 33 model = DisplayModel(self, self.sortedEntries, FeedEntry.userPresentableString) |
36 self.ui.feedEntryList.setModel(model) | 34 self.ui.feedEntryList.setModel(model) |
35 self.ui.feedEntryList.itemDelegate().entries = self.sortedEntries | |
37 self.ui.feedEntryList.update() | 36 self.ui.feedEntryList.update() |
38 | 37 |
39 def feedEntrySelected(self, index): | 38 def feedEntrySelected(self, index): |
40 row = index.row() | 39 row = index.row() |
41 entry = self.selectedFeed.entries[row] | 40 self.selectedEntry = self.sortedEntries[row] |
42 baseUrl = QUrl(entry.link) # TODO this is the wrong base url, figure out the correct one | 41 baseUrl = QUrl(self.selectedEntry.link) # TODO this is the wrong base url, figure out the correct one |
43 self.ui.webView.setHtml(entry.summary, baseUrl) | 42 self.ui.webView.setHtml(self.selectedEntry.summary, baseUrl) |
43 | |
44 def toggleReadOnSelectedEntry(self): | |
45 self.selectedEntry.toggleRead() | |
46 self.session.commit() | |
47 self.ui.feedList.update() | |
44 | 48 |
45 def addFeed(self): | 49 def addFeed(self): |
46 addFeed = AddFeed(self.session) | 50 addFeed = AddFeed(self.session) |
47 success = addFeed.exec_() | 51 success = addFeed.exec_() |
48 if success: | 52 if success: |
49 url = addFeed.getUrl() | 53 url = addFeed.getUrl() |
50 FeedUpdater.createNewFeed(url, self.session) | 54 FeedUpdater.createNewFeed(url, self.session) |
51 # TODO get status from feedUpdater and display in status area of the main window | 55 # TODO get status from feedUpdater and display in status area of the main window |
52 self.updateFeedList() | 56 self.updateFeedList() |
53 | 57 |
54 class CustomItemDelegate(QtGui.QStyledItemDelegate): | 58 class FeedEntryItemDelegate(QtGui.QStyledItemDelegate): |
55 def __init__(self, parent): | 59 def __init__(self): |
56 print("init") | 60 QtGui.QStyledItemDelegate.__init__(self, None) |
57 QtGui.QStyledItemDelegate.__init__(self, parent) | |
58 | 61 |
59 def paint(self, painter, style, index): | 62 def paint(self, painter, style, index): |
60 style.font.setWeight(QFont.Bold) | 63 row = index.row() |
64 entry = self.entries[row] | |
65 if entry.read: | |
66 style.font.setWeight(QFont.Normal) | |
67 else: | |
68 style.font.setWeight(QFont.Bold) | |
61 QtGui.QStyledItemDelegate.paint(self, painter, style, index) | 69 QtGui.QStyledItemDelegate.paint(self, painter, style, index) |