view 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
line wrap: on
line source


from DisplayModel import DisplayModel
from Feed import Feed
from FeedEntry import FeedEntry
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import QUrl
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.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)
        self.ui.feedList.setModel(feedModel)
        self.connect(self.ui.feedList, QtCore.SIGNAL("clicked(QModelIndex)"), self.feedSelected)
        
    def setupFeedEntryList(self):
        self.connect(self.ui.feedEntryList, QtCore.SIGNAL("clicked(QModelIndex)"), self.feedEntrySelected)
        
    def feedSelected(self, index):
        self.selectedFeed = self.allFeeds[index.row()]
        model = DisplayModel(self, self.selectedFeed.entries, FeedEntry.userPresentableString)
        self.ui.feedEntryList.setModel(model)
        self.ui.feedEntryList.update()
        
    def feedEntrySelected(self, index):
        row = index.row()
        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)
    
    def addFeed(self):
        pass