Mercurial > hg > Feedworm
changeset 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 |
files | MainWindowController.py Ui_MainWindow.ui |
diffstat | 2 files changed, 50 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/MainWindowController.py Wed Apr 28 02:36:00 2010 +0200 +++ b/MainWindowController.py Wed Apr 28 02:57:41 2010 +0200 @@ -1,6 +1,11 @@ +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 -from PyQt4 import QtGui class MainWindowController(QtGui.QMainWindow): def __init__(self, session=None): @@ -8,3 +13,28 @@ 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() \ No newline at end of file
--- a/Ui_MainWindow.ui Wed Apr 28 02:36:00 2010 +0200 +++ b/Ui_MainWindow.ui Wed Apr 28 02:57:41 2010 +0200 @@ -13,7 +13,18 @@ <property name="windowTitle"> <string>Feedworm</string> </property> - <widget class="QWidget" name="centralwidget"/> + <widget class="QWidget" name="centralwidget"> + <widget class="QListView" name="feedList"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>221</width> + <height>551</height> + </rect> + </property> + </widget> + </widget> <widget class="QMenuBar" name="menubar"> <property name="geometry"> <rect> @@ -27,6 +38,8 @@ <property name="title"> <string>Feed</string> </property> + <addaction name="actionAdd"/> + <addaction name="separator"/> <addaction name="actionQuit"/> </widget> <addaction name="menuFeed"/> @@ -40,6 +53,11 @@ <string>Ctrl+Q</string> </property> </action> + <action name="actionAdd"> + <property name="text"> + <string>Add ...</string> + </property> + </action> </widget> <resources/> <connections>