changeset 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 ee1432a91141
children 500ba01e7f7a
files Feed.py FeedEntry.py MainWindow.py
diffstat 3 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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):
--- 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)