comparison 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
comparison
equal deleted inserted replaced
14:42a225be7e56 15:b1aeb98824c1
1 1
2 from Feed import Feed
3 from PyQt4 import QtGui
4 from PyQt4.QtCore import QAbstractListModel
5 from PyQt4.QtCore import QModelIndex
6 from PyQt4.QtCore import Qt
7 from PyQt4.QtCore import QVariant
2 from Ui_MainWindow import Ui_MainWindow 8 from Ui_MainWindow import Ui_MainWindow
3 from PyQt4 import QtGui
4 9
5 class MainWindowController(QtGui.QMainWindow): 10 class MainWindowController(QtGui.QMainWindow):
6 def __init__(self, session=None): 11 def __init__(self, session=None):
7 QtGui.QWidget.__init__(self, None) 12 QtGui.QWidget.__init__(self, None)
8 self.session = session 13 self.session = session
9 self.ui = Ui_MainWindow() 14 self.ui = Ui_MainWindow()
10 self.ui.setupUi(self) 15 self.ui.setupUi(self)
16 self.connectWidgets()
17
18 def connectWidgets(self):
19 feedModel = FeedModel(self)
20 self.ui.feedList.setModel(feedModel)
21
22 class FeedModel(QAbstractListModel):
23 def __init__(self, parent=None, **args):
24 QAbstractListModel.__init__(self, parent, *args)
25 self.session = parent.session
26 self.fetchAllFeeds()
27
28 def fetchAllFeeds(self):
29 self.allFeeds = self.session.query(Feed).all()
30
31 def rowCount(self, parent=QModelIndex()):
32 return len(self.allFeeds)
33
34 def data(self, index, role):
35 if index.isValid() and role == Qt.DisplayRole:
36 row = index.row()
37 feed = self.allFeeds[row]
38 return QVariant(feed.title)
39 else:
40 return QVariant()