view 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 source


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

class MainWindowController(QtGui.QMainWindow):
    def __init__(self, session=None):
        QtGui.QWidget.__init__(self, None)
        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()