Mercurial > hg > Feedworm
comparison MainWindowController.py @ 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 | 6f7003fc6e6d |
children | dcc8abff0694 |
comparison
equal
deleted
inserted
replaced
20:0b8398ca6cd0 | 21:c8bb3cee7935 |
---|---|
1 | 1 |
2 from DisplayModel import DisplayModel | |
2 from Feed import Feed | 3 from Feed import Feed |
3 from FeedEntry import FeedEntry | 4 from FeedEntry import FeedEntry |
4 from PyQt4 import QtCore, QtGui | 5 from PyQt4 import QtCore, QtGui |
5 from PyQt4.QtCore import QAbstractListModel, QModelIndex, QVariant, Qt, QUrl | 6 from PyQt4.QtCore import QUrl |
6 from Ui_MainWindow import Ui_MainWindow | 7 from Ui_MainWindow import Ui_MainWindow |
7 | 8 |
8 class MainWindowController(QtGui.QMainWindow): | 9 class MainWindowController(QtGui.QMainWindow): |
9 def __init__(self, session=None): | 10 def __init__(self, session=None): |
10 QtGui.QWidget.__init__(self, None) | 11 QtGui.QWidget.__init__(self, None) |
12 self.ui = Ui_MainWindow() | 13 self.ui = Ui_MainWindow() |
13 self.ui.setupUi(self) | 14 self.ui.setupUi(self) |
14 self.setupWidgets() | 15 self.setupWidgets() |
15 | 16 |
16 def setupWidgets(self): | 17 def setupWidgets(self): |
18 self.setupAddFeedMenuEntry() | |
17 self.setupFeedList() | 19 self.setupFeedList() |
18 self.setupFeedEntryList() | 20 self.setupFeedEntryList() |
19 | 21 |
22 def setupAddFeedMenuEntry(self): | |
23 self.connect(self.ui.actionAdd, QtCore.SIGNAL("activated(int)"), self.addFeed) | |
24 | |
20 def setupFeedList(self): | 25 def setupFeedList(self): |
21 self.allFeeds = Feed.all(self.session) | 26 self.allFeeds = Feed.all(self.session) |
22 feedModel = DisplayModel(self, self.allFeeds, Feed.userPresentableString) | 27 feedModel = DisplayModel(self, self.allFeeds, Feed.userPresentableString) |
23 self.ui.feedList.setModel(feedModel) | 28 self.ui.feedList.setModel(feedModel) |
24 self.connect(self.ui.feedList, QtCore.SIGNAL("clicked(QModelIndex)"), self.feedSelected) | 29 self.connect(self.ui.feedList, QtCore.SIGNAL("clicked(QModelIndex)"), self.feedSelected) |
35 def feedEntrySelected(self, index): | 40 def feedEntrySelected(self, index): |
36 row = index.row() | 41 row = index.row() |
37 entry = self.selectedFeed.entries[row] | 42 entry = self.selectedFeed.entries[row] |
38 baseUrl = QUrl(entry.link) # TODO this is the wrong base url, figure out the correct one | 43 baseUrl = QUrl(entry.link) # TODO this is the wrong base url, figure out the correct one |
39 self.ui.webView.setHtml(entry.summary, baseUrl) | 44 self.ui.webView.setHtml(entry.summary, baseUrl) |
40 | |
41 class DisplayModel(QAbstractListModel): | |
42 def __init__(self, parent=None, list=None, displayFunction=None, **args): | |
43 QAbstractListModel.__init__(self, parent, *args) | |
44 self.list = list | |
45 self.displayFunction = displayFunction | |
46 | |
47 def rowCount(self, parent=QModelIndex()): | |
48 return len(self.list) | |
49 | 45 |
50 def data(self, index, role): | 46 def addFeed(self): |
51 if index.isValid() and role == Qt.DisplayRole: | 47 pass |
52 row = index.row() | |
53 object = self.list[row] | |
54 displayString = self.displayFunction(object) | |
55 return QVariant(displayString) | |
56 else: | |
57 return QVariant() |