Mercurial > hg > Feedworm
annotate MainWindow.py @ 39:0c2578196643
Disable the article menu by default, enable it when the first article is selected
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Fri, 14 May 2010 06:48:48 +0200 |
parents | 22214d79ed41 |
children | c858aab71e5b |
rev | line source |
---|---|
14 | 1 |
27
bdd1296a4b8c
implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
24
diff
changeset
|
2 from AddFeed import AddFeed |
21
c8bb3cee7935
pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
19
diff
changeset
|
3 from DisplayModel import DisplayModel |
15
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
4 from Feed import Feed |
18
35225588b895
add a list view for displaying feed entries from the selected feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
17
diff
changeset
|
5 from FeedEntry import FeedEntry |
23
dcc8abff0694
All the wiring of slots is done through QtDesigner now, look how much code has just disappeared :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
21
diff
changeset
|
6 from PyQt4 import QtGui |
21
c8bb3cee7935
pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
19
diff
changeset
|
7 from PyQt4.QtCore import QUrl |
31
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
27
diff
changeset
|
8 from PyQt4.QtGui import QFont |
14 | 9 from Ui_MainWindow import Ui_MainWindow |
31
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
27
diff
changeset
|
10 import FeedUpdater |
37
22214d79ed41
database URL must be given as commandline argument now, no need for creating complicated config files. Add a menu entry for opening the selected article in browser.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
33
diff
changeset
|
11 import subprocess |
14 | 12 |
24
6b5ceffabe49
MainWindowController -> MainWindow
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
23
diff
changeset
|
13 class MainWindow(QtGui.QMainWindow): |
14 | 14 def __init__(self, session=None): |
15 QtGui.QWidget.__init__(self, None) | |
16 self.session = session | |
17 self.ui = Ui_MainWindow() | |
18 self.ui.setupUi(self) | |
27
bdd1296a4b8c
implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
24
diff
changeset
|
19 self.updateFeedList() |
31
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
27
diff
changeset
|
20 self.initFeedEntryList() |
17
5fda8bd94fa8
make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
16
diff
changeset
|
21 |
31
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
27
diff
changeset
|
22 def updateFeedList(self): |
17
5fda8bd94fa8
make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
16
diff
changeset
|
23 self.allFeeds = Feed.all(self.session) |
5fda8bd94fa8
make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
16
diff
changeset
|
24 feedModel = DisplayModel(self, self.allFeeds, Feed.userPresentableString) |
15
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
25 self.ui.feedList.setModel(feedModel) |
27
bdd1296a4b8c
implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
24
diff
changeset
|
26 self.ui.feedList.update() |
bdd1296a4b8c
implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
24
diff
changeset
|
27 |
31
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
27
diff
changeset
|
28 def initFeedEntryList(self): |
33
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
29 self.ui.feedEntryList.setItemDelegate(FeedEntryItemDelegate()) |
31
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
27
diff
changeset
|
30 |
17
5fda8bd94fa8
make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
16
diff
changeset
|
31 def feedSelected(self, index): |
19
6f7003fc6e6d
display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
18
diff
changeset
|
32 self.selectedFeed = self.allFeeds[index.row()] |
33
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
33 self.sortedEntries = self.selectedFeed.entriesSortedByUpdateDate() |
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
34 model = DisplayModel(self, self.sortedEntries, FeedEntry.userPresentableString) |
18
35225588b895
add a list view for displaying feed entries from the selected feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
17
diff
changeset
|
35 self.ui.feedEntryList.setModel(model) |
33
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
36 self.ui.feedEntryList.itemDelegate().entries = self.sortedEntries |
18
35225588b895
add a list view for displaying feed entries from the selected feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
17
diff
changeset
|
37 self.ui.feedEntryList.update() |
19
6f7003fc6e6d
display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
18
diff
changeset
|
38 |
6f7003fc6e6d
display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
18
diff
changeset
|
39 def feedEntrySelected(self, index): |
39
0c2578196643
Disable the article menu by default, enable it when the first article is selected
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
37
diff
changeset
|
40 self.ui.menuArticle.setEnabled(True) |
19
6f7003fc6e6d
display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
18
diff
changeset
|
41 row = index.row() |
33
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
42 self.selectedEntry = self.sortedEntries[row] |
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
43 baseUrl = QUrl(self.selectedEntry.link) # TODO this is the wrong base url, figure out the correct one |
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
44 self.ui.webView.setHtml(self.selectedEntry.summary, baseUrl) |
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
45 |
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
46 def toggleReadOnSelectedEntry(self): |
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
47 self.selectedEntry.toggleRead() |
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
48 self.session.commit() |
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
49 self.ui.feedList.update() |
15
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
50 |
21
c8bb3cee7935
pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
19
diff
changeset
|
51 def addFeed(self): |
27
bdd1296a4b8c
implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
24
diff
changeset
|
52 addFeed = AddFeed(self.session) |
bdd1296a4b8c
implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
24
diff
changeset
|
53 success = addFeed.exec_() |
bdd1296a4b8c
implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
24
diff
changeset
|
54 if success: |
bdd1296a4b8c
implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
24
diff
changeset
|
55 url = addFeed.getUrl() |
bdd1296a4b8c
implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
24
diff
changeset
|
56 FeedUpdater.createNewFeed(url, self.session) |
bdd1296a4b8c
implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
24
diff
changeset
|
57 # TODO get status from feedUpdater and display in status area of the main window |
bdd1296a4b8c
implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
24
diff
changeset
|
58 self.updateFeedList() |
31
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
27
diff
changeset
|
59 |
39
0c2578196643
Disable the article menu by default, enable it when the first article is selected
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
37
diff
changeset
|
60 def openSelectedEntryInBrowser(self): |
37
22214d79ed41
database URL must be given as commandline argument now, no need for creating complicated config files. Add a menu entry for opening the selected article in browser.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
33
diff
changeset
|
61 # TODO make browser configurable |
22214d79ed41
database URL must be given as commandline argument now, no need for creating complicated config files. Add a menu entry for opening the selected article in browser.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
33
diff
changeset
|
62 browser = "/usr/local/bin/opera" |
22214d79ed41
database URL must be given as commandline argument now, no need for creating complicated config files. Add a menu entry for opening the selected article in browser.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
33
diff
changeset
|
63 subprocess.Popen([browser, self.selectedEntry.link]) |
39
0c2578196643
Disable the article menu by default, enable it when the first article is selected
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
37
diff
changeset
|
64 |
0c2578196643
Disable the article menu by default, enable it when the first article is selected
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
37
diff
changeset
|
65 def openLinkFromSelectedEntry(self): |
0c2578196643
Disable the article menu by default, enable it when the first article is selected
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
37
diff
changeset
|
66 url = QUrl(self.selectedEntry.link) |
0c2578196643
Disable the article menu by default, enable it when the first article is selected
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
37
diff
changeset
|
67 self.ui.webView.load(url) |
0c2578196643
Disable the article menu by default, enable it when the first article is selected
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
37
diff
changeset
|
68 self.ui.webView.show() |
37
22214d79ed41
database URL must be given as commandline argument now, no need for creating complicated config files. Add a menu entry for opening the selected article in browser.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
33
diff
changeset
|
69 |
33
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
70 class FeedEntryItemDelegate(QtGui.QStyledItemDelegate): |
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
71 def __init__(self): |
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
72 QtGui.QStyledItemDelegate.__init__(self, None) |
31
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
27
diff
changeset
|
73 |
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
27
diff
changeset
|
74 def paint(self, painter, style, index): |
33
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
75 row = index.row() |
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
76 entry = self.entries[row] |
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
77 if entry.read: |
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
78 style.font.setWeight(QFont.Normal) |
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
79 else: |
f371d02fa09d
mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
31
diff
changeset
|
80 style.font.setWeight(QFont.Bold) |
31
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
27
diff
changeset
|
81 QtGui.QStyledItemDelegate.paint(self, painter, style, index) |