Mercurial > hg > Feedworm
changeset 21:c8bb3cee7935
pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Thu, 29 Apr 2010 05:03:38 +0200 |
parents | 0b8398ca6cd0 |
children | cb9d8da0f307 |
files | DisplayModel.py MainWindowController.py |
diffstat | 2 files changed, 28 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DisplayModel.py Thu Apr 29 05:03:38 2010 +0200 @@ -0,0 +1,20 @@ + +from PyQt4.QtCore import QAbstractListModel, QModelIndex, QVariant, Qt + +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()
--- a/MainWindowController.py Wed Apr 28 04:00:56 2010 +0200 +++ b/MainWindowController.py Thu Apr 29 05:03:38 2010 +0200 @@ -1,8 +1,9 @@ +from DisplayModel import DisplayModel from Feed import Feed from FeedEntry import FeedEntry from PyQt4 import QtCore, QtGui -from PyQt4.QtCore import QAbstractListModel, QModelIndex, QVariant, Qt, QUrl +from PyQt4.QtCore import QUrl from Ui_MainWindow import Ui_MainWindow class MainWindowController(QtGui.QMainWindow): @@ -14,9 +15,13 @@ self.setupWidgets() def setupWidgets(self): + self.setupAddFeedMenuEntry() self.setupFeedList() self.setupFeedEntryList() + def setupAddFeedMenuEntry(self): + self.connect(self.ui.actionAdd, QtCore.SIGNAL("activated(int)"), self.addFeed) + def setupFeedList(self): self.allFeeds = Feed.all(self.session) feedModel = DisplayModel(self, self.allFeeds, Feed.userPresentableString) @@ -37,21 +42,6 @@ entry = self.selectedFeed.entries[row] baseUrl = QUrl(entry.link) # TODO this is the wrong base url, figure out the correct one self.ui.webView.setHtml(entry.summary, baseUrl) - -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() + def addFeed(self): + pass \ No newline at end of file