diff MainWindowController.py @ 15:b1aeb98824c1

Add a list view displaying all feeds
author Dirk Olmes <dirk@xanthippe.ping.de>
date Wed, 28 Apr 2010 02:57:41 +0200
parents 42a225be7e56
children 3ffecc709da9
line wrap: on
line diff
--- a/MainWindowController.py	Wed Apr 28 02:36:00 2010 +0200
+++ b/MainWindowController.py	Wed Apr 28 02:57:41 2010 +0200
@@ -1,6 +1,11 @@
 
+from Feed import Feed
+from PyQt4 import QtGui
+from PyQt4.QtCore import QAbstractListModel
+from PyQt4.QtCore import QModelIndex
+from PyQt4.QtCore import Qt
+from PyQt4.QtCore import QVariant
 from Ui_MainWindow import Ui_MainWindow
-from PyQt4 import QtGui
 
 class MainWindowController(QtGui.QMainWindow):
     def __init__(self, session=None):
@@ -8,3 +13,28 @@
         self.session = session
         self.ui = Ui_MainWindow()
         self.ui.setupUi(self)
+        self.connectWidgets()
+        
+    def connectWidgets(self):
+        feedModel = FeedModel(self)
+        self.ui.feedList.setModel(feedModel)
+
+class FeedModel(QAbstractListModel):
+    def __init__(self, parent=None, **args):
+        QAbstractListModel.__init__(self, parent, *args)
+        self.session = parent.session
+        self.fetchAllFeeds()
+        
+    def fetchAllFeeds(self):
+        self.allFeeds = self.session.query(Feed).all()
+        
+    def rowCount(self, parent=QModelIndex()):
+        return len(self.allFeeds)
+    
+    def data(self, index, role): 
+        if index.isValid() and role == Qt.DisplayRole:
+            row = index.row()
+            feed = self.allFeeds[row]
+            return QVariant(feed.title)
+        else: 
+            return QVariant()
\ No newline at end of file