Mercurial > hg > Feedworm
annotate MainWindow.py @ 60:d063e4814357
When clicking an entry, it's marked as read
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Fri, 23 Jul 2010 17:41:05 +0200 |
parents | daa2731967fe |
children | db35ab7753f0 |
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 |
55
0f9b3e57cff0
pull out FeedEntryItemDelegate into its own file
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
53
diff
changeset
|
6 from FeedEntryItemDelegate import FeedEntryItemDelegate |
48 | 7 from FeedSettings import FeedSettings |
42
0c0d1760b737
Rename Preferences to PreferencesDialog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
40
diff
changeset
|
8 from PreferencesDialog import PreferencesDialog |
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
|
9 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
|
10 from PyQt4.QtCore import QUrl |
14 | 11 from Ui_MainWindow import Ui_MainWindow |
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
|
12 import subprocess |
14 | 13 |
50
4b0d686493fb
better error handling while adding feeds: data is only saved if a feed could be created and entries could be retrieved. MainWindow displays feedback in the status bar if an exception occurred while adding a feed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
49
diff
changeset
|
14 STATUS_MESSAGE_DISPLAY_MILLIS = 20000 |
4b0d686493fb
better error handling while adding feeds: data is only saved if a feed could be created and entries could be retrieved. MainWindow displays feedback in the status bar if an exception occurred while adding a feed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
49
diff
changeset
|
15 |
24
6b5ceffabe49
MainWindowController -> MainWindow
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
23
diff
changeset
|
16 class MainWindow(QtGui.QMainWindow): |
14 | 17 def __init__(self, session=None): |
18 QtGui.QWidget.__init__(self, None) | |
19 self.session = session | |
20 self.ui = Ui_MainWindow() | |
21 self.ui.setupUi(self) | |
27
bdd1296a4b8c
implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
24
diff
changeset
|
22 self.updateFeedList() |
31
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
27
diff
changeset
|
23 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
|
24 |
31
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
27
diff
changeset
|
25 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
|
26 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
|
27 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
|
28 self.ui.feedList.setModel(feedModel) |
27
bdd1296a4b8c
implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
24
diff
changeset
|
29 self.ui.feedList.update() |
bdd1296a4b8c
implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
24
diff
changeset
|
30 |
31
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
27
diff
changeset
|
31 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
|
32 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
|
33 |
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
|
34 def feedSelected(self, index): |
19
6f7003fc6e6d
display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
18
diff
changeset
|
35 self.selectedFeed = self.allFeeds[index.row()] |
53
8cca4585eb33
the feed settings menu item starts out disabled and gets enabled once a feed is selected
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
50
diff
changeset
|
36 |
8cca4585eb33
the feed settings menu item starts out disabled and gets enabled once a feed is selected
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
50
diff
changeset
|
37 self.ui.actionFeedSettings.setEnabled(True) |
56
c82f5538733c
add a menu item to mark all entries in a feed as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
55
diff
changeset
|
38 self.ui.actionMarkFeedRead.setEnabled(True) |
53
8cca4585eb33
the feed settings menu item starts out disabled and gets enabled once a feed is selected
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
50
diff
changeset
|
39 |
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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 self.ui.feedEntryList.update() |
19
6f7003fc6e6d
display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
18
diff
changeset
|
45 |
6f7003fc6e6d
display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
18
diff
changeset
|
46 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
|
47 self.ui.menuArticle.setEnabled(True) |
47
a8442c3487b5
add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
42
diff
changeset
|
48 |
19
6f7003fc6e6d
display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
18
diff
changeset
|
49 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
|
50 self.selectedEntry = self.sortedEntries[row] |
60
d063e4814357
When clicking an entry, it's marked as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
51 self.selectedEntry.markRead() |
47
a8442c3487b5
add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
42
diff
changeset
|
52 |
a8442c3487b5
add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
42
diff
changeset
|
53 if self.selectedEntry.feed.auto_load_entry_link: |
a8442c3487b5
add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
42
diff
changeset
|
54 self.openLinkFromSelectedEntry() |
a8442c3487b5
add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
42
diff
changeset
|
55 else: |
a8442c3487b5
add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
42
diff
changeset
|
56 self.openSummaryFromSelectedEntry() |
a8442c3487b5
add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
42
diff
changeset
|
57 |
a8442c3487b5
add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
42
diff
changeset
|
58 def openSummaryFromSelectedEntry(self): |
a8442c3487b5
add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
42
diff
changeset
|
59 # TODO this is the wrong base url, figure out the correct one |
a8442c3487b5
add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
42
diff
changeset
|
60 baseUrl = QUrl(self.selectedEntry.link) |
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
|
61 self.ui.webView.setHtml(self.selectedEntry.summary, baseUrl) |
47
a8442c3487b5
add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
42
diff
changeset
|
62 |
a8442c3487b5
add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
42
diff
changeset
|
63 def openLinkFromSelectedEntry(self): |
a8442c3487b5
add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
42
diff
changeset
|
64 url = QUrl(self.selectedEntry.link) |
a8442c3487b5
add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
42
diff
changeset
|
65 self.ui.webView.load(url) |
a8442c3487b5
add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
42
diff
changeset
|
66 self.ui.webView.show() |
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
|
67 |
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
|
68 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
|
69 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
|
70 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
|
71 self.ui.feedList.update() |
56
c82f5538733c
add a menu item to mark all entries in a feed as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
55
diff
changeset
|
72 |
59
daa2731967fe
Marking all articles in a feed as read doesn't toggle any more ... it marks all articles as read.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
56
diff
changeset
|
73 def markSelectedFeedRead(self): |
daa2731967fe
Marking all articles in a feed as read doesn't toggle any more ... it marks all articles as read.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
56
diff
changeset
|
74 self.selectedFeed.markAllEntriesRead() |
56
c82f5538733c
add a menu item to mark all entries in a feed as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
55
diff
changeset
|
75 self.session.commit() |
c82f5538733c
add a menu item to mark all entries in a feed as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
55
diff
changeset
|
76 self.ui.feedEntryList.update() |
15
b1aeb98824c1
Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
14
diff
changeset
|
77 |
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
|
78 def addFeed(self): |
27
bdd1296a4b8c
implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
24
diff
changeset
|
79 addFeed = AddFeed(self.session) |
bdd1296a4b8c
implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
24
diff
changeset
|
80 success = addFeed.exec_() |
50
4b0d686493fb
better error handling while adding feeds: data is only saved if a feed could be created and entries could be retrieved. MainWindow displays feedback in the status bar if an exception occurred while adding a feed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
49
diff
changeset
|
81 if not success: |
4b0d686493fb
better error handling while adding feeds: data is only saved if a feed could be created and entries could be retrieved. MainWindow displays feedback in the status bar if an exception occurred while adding a feed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
49
diff
changeset
|
82 return |
4b0d686493fb
better error handling while adding feeds: data is only saved if a feed could be created and entries could be retrieved. MainWindow displays feedback in the status bar if an exception occurred while adding a feed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
49
diff
changeset
|
83 |
4b0d686493fb
better error handling while adding feeds: data is only saved if a feed could be created and entries could be retrieved. MainWindow displays feedback in the status bar if an exception occurred while adding a feed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
49
diff
changeset
|
84 if addFeed.exception is not None: |
4b0d686493fb
better error handling while adding feeds: data is only saved if a feed could be created and entries could be retrieved. MainWindow displays feedback in the status bar if an exception occurred while adding a feed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
49
diff
changeset
|
85 message = "Error while adding feed: " + str(addFeed.exception) |
4b0d686493fb
better error handling while adding feeds: data is only saved if a feed could be created and entries could be retrieved. MainWindow displays feedback in the status bar if an exception occurred while adding a feed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
49
diff
changeset
|
86 self.ui.statusbar.showMessage(message, STATUS_MESSAGE_DISPLAY_MILLIS) |
4b0d686493fb
better error handling while adding feeds: data is only saved if a feed could be created and entries could be retrieved. MainWindow displays feedback in the status bar if an exception occurred while adding a feed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
49
diff
changeset
|
87 else: |
4b0d686493fb
better error handling while adding feeds: data is only saved if a feed could be created and entries could be retrieved. MainWindow displays feedback in the status bar if an exception occurred while adding a feed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
49
diff
changeset
|
88 self.session.commit() |
27
bdd1296a4b8c
implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
24
diff
changeset
|
89 self.updateFeedList() |
31
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
27
diff
changeset
|
90 |
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
|
91 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
|
92 # 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
|
93 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
|
94 subprocess.Popen([browser, self.selectedEntry.link]) |
47
a8442c3487b5
add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
42
diff
changeset
|
95 |
40 | 96 def showPreferences(self): |
42
0c0d1760b737
Rename Preferences to PreferencesDialog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
40
diff
changeset
|
97 preferences = PreferencesDialog(self.session) |
40 | 98 preferences.exec_() |
99 | |
48 | 100 def showFeedSettings(self): |
101 feedSettings = FeedSettings(self.session, self.selectedFeed) | |
102 feedSettings.exec_() | |
103 | |
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
|
104 |