Mercurial > hg > Feedworm
view MainWindowController.py @ 18:35225588b895
add a list view for displaying feed entries from the selected feed
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Wed, 28 Apr 2010 03:46:47 +0200 |
parents | 5fda8bd94fa8 |
children | 6f7003fc6e6d |
line wrap: on
line source
from Feed import Feed from FeedEntry import FeedEntry from PyQt4 import QtCore, QtGui from PyQt4.QtCore import QAbstractListModel, QModelIndex, QVariant, Qt 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.setupWidgets() def setupWidgets(self): self.setupFeedList() self.setupFeedEntryList() def setupFeedList(self): self.allFeeds = Feed.all(self.session) feedModel = DisplayModel(self, self.allFeeds, Feed.userPresentableString) self.ui.feedList.setModel(feedModel) self.connect(self.ui.feedList, QtCore.SIGNAL("clicked(QModelIndex)"), self.feedSelected) def setupFeedEntryList(self): pass def feedSelected(self, index): feed = self.allFeeds[index.row()] model = DisplayModel(self, feed.entries, FeedEntry.userPresentableString) self.ui.feedEntryList.setModel(model) self.ui.feedEntryList.update() class DisplayModel(QAbstractListModel): def __init__(self, parent=None, list=None, displayFunction=None, **args): QAbstractListModel.__init__(self, parent, *args) self.list = list self.displayFunction = displayFunction def rowCount(self, parent=QModelIndex()): return len(self.list) def data(self, index, role): if index.isValid() and role == Qt.DisplayRole: row = index.row() object = self.list[row] displayString = self.displayFunction(object) return QVariant(displayString) else: return QVariant()