# HG changeset patch # User Dirk Olmes # Date 1272600114 -7200 # Node ID 5bb57caa8f664755c7557597edd4f6141e139d34 # Parent ee1432a911417ee5bb59edb54655f80c2cfbdc40 display a feed's entries sorted by their update date diff -r ee1432a91141 -r 5bb57caa8f66 Feed.py --- a/Feed.py Thu Apr 29 16:49:45 2010 +0200 +++ b/Feed.py Fri Apr 30 06:01:54 2010 +0200 @@ -1,3 +1,5 @@ + +import FeedEntry class Feed(object): @staticmethod @@ -13,3 +15,8 @@ def userPresentableString(self): return self.title + + def entriesSortedByUpdateDate(self): + sortedEntries = list(self.entries) + sortedEntries.sort(FeedEntry.compareByUpdateDate) + return sortedEntries \ No newline at end of file diff -r ee1432a91141 -r 5bb57caa8f66 FeedEntry.py --- a/FeedEntry.py Thu Apr 29 16:49:45 2010 +0200 +++ b/FeedEntry.py Fri Apr 30 06:01:54 2010 +0200 @@ -1,6 +1,9 @@ from datetime import datetime +def compareByUpdateDate(first, second): + return cmp(first.updated, second.updated) + class FeedEntry(object): @staticmethod def findById(id, session): diff -r ee1432a91141 -r 5bb57caa8f66 MainWindow.py --- a/MainWindow.py Thu Apr 29 16:49:45 2010 +0200 +++ b/MainWindow.py Fri Apr 30 06:01:54 2010 +0200 @@ -3,10 +3,11 @@ from DisplayModel import DisplayModel from Feed import Feed from FeedEntry import FeedEntry -import FeedUpdater from PyQt4 import QtGui from PyQt4.QtCore import QUrl +from PyQt4.QtGui import QFont from Ui_MainWindow import Ui_MainWindow +import FeedUpdater class MainWindow(QtGui.QMainWindow): def __init__(self, session=None): @@ -15,16 +16,23 @@ self.ui = Ui_MainWindow() self.ui.setupUi(self) self.updateFeedList() + self.initFeedEntryList() - def updateFeedList(self): + def updateFeedList(self): self.allFeeds = Feed.all(self.session) feedModel = DisplayModel(self, self.allFeeds, Feed.userPresentableString) self.ui.feedList.setModel(feedModel) self.ui.feedList.update() + def initFeedEntryList(self): + pass +# self.ui.feedEntryList.setItemDelegate() + # self.ui.feedList.setItemDelegate(CustomItemDelegate(self)) + def feedSelected(self, index): self.selectedFeed = self.allFeeds[index.row()] - model = DisplayModel(self, self.selectedFeed.entries, FeedEntry.userPresentableString) + sortedEntries = self.selectedFeed.entriesSortedByUpdateDate() + model = DisplayModel(self, sortedEntries, FeedEntry.userPresentableString) self.ui.feedEntryList.setModel(model) self.ui.feedEntryList.update() @@ -42,3 +50,12 @@ FeedUpdater.createNewFeed(url, self.session) # TODO get status from feedUpdater and display in status area of the main window self.updateFeedList() + +class CustomItemDelegate(QtGui.QStyledItemDelegate): + def __init__(self, parent): + print("init") + QtGui.QStyledItemDelegate.__init__(self, parent) + + def paint(self, painter, style, index): + style.font.setWeight(QFont.Bold) + QtGui.QStyledItemDelegate.paint(self, painter, style, index)