feedreader / feedreader.py

# -*- coding:utf-8 -*-
import os
from PyQt4 import QtGui, QtCore, uic, QtWebKit
import feedparser
from feeds import *

uifile = os.path.join(os.path.dirname(__file__), 'mainwindow.ui')
Form, Base = uic.loadUiType(uifile)

class MainWindow(Base, Form):
    def __init__(self):
        super(Base, self).__init__()
        Form.setupUi(self, self)
        self.filename = None
        self.webView = QtWebKit.QWebView(self.feedEntryViewContainer)
        self.webView.setHtml(u"<html><body><h1>Feed Reader</h1><p>This is contents.</p></body></html>")

        self.setupFeedsTree()
        self.setupEntryList()


    def setupEntryList(self):
        self.entryModel = EntryListModel(self)
        self.entriesView.setModel(self.entryModel)

    def setupFeedsTree(self):
        urls = [
            (u'Aodag Blog', 'http://feeds.feedburner.jp/AodagBlog'),
            (u'aodagの日記', 'http://d.hatena.ne.jp/aodag/rss'),
            ]
        blog = FeedCategory('blog', [Feed(n, u) for n, u in urls])
        urls = [
            (u'Bicking Blog', 'http://blog.ianbicking.org/feed/atom/'),
            ]
        python = FeedCategory('python', [Feed(n, u) for n, u in urls])
        
        self.categoryTreeModel = FeedListModel([blog, python], self.categoryTreeView)
        self.categoryTreeView.setModel(self.categoryTreeModel)

    def on_categoryTreeView_activated(self, index):
        entries = index.internalPointer().entries
        self.entryModel.set_entries(list(entries))

    def on_entriesView_activated(self, index):
        entry = index.internalPointer()
        self.webView.setHtml('<h1>%s</h1><div>%s</div>' % (entry.title, entry.content[0].value))

def main():
    import sys
    app = QtGui.QApplication(sys.argv)


    win = MainWindow()
    win.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.