Mercurial > hg > Feedworm
comparison MainWindow.py @ 89:2eddb44920d1
When selecting a new feed, scroll its first entry to visible
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Fri, 24 Dec 2010 04:36:06 +0100 |
parents | bacf42da9e36 |
children | a1066e5a8f88 |
comparison
equal
deleted
inserted
replaced
88:48d1d7bba548 | 89:2eddb44920d1 |
---|---|
22 self.preferences = Preferences(session) | 22 self.preferences = Preferences(session) |
23 self.ui = Ui_MainWindow() | 23 self.ui = Ui_MainWindow() |
24 self.ui.setupUi(self) | 24 self.ui.setupUi(self) |
25 self.updateFeedList() | 25 self.updateFeedList() |
26 self.initFeedEntryList() | 26 self.initFeedEntryList() |
27 | 27 |
28 def updateFeedList(self): | 28 def updateFeedList(self): |
29 self.allFeeds = FeedList.getFeeds(self.session) | 29 self.allFeeds = FeedList.getFeeds(self.session) |
30 feedModel = DisplayModel(self, self.allFeeds, Feed.userPresentableString) | 30 feedModel = DisplayModel(self, self.allFeeds, Feed.userPresentableString) |
31 self.ui.feedList.setModel(feedModel) | 31 self.ui.feedList.setModel(feedModel) |
32 self.ui.feedList.update() | 32 self.ui.feedList.update() |
45 | 45 |
46 def setupFeedEntries(self): | 46 def setupFeedEntries(self): |
47 hideReadEntries = self.preferences.hideReadFeedEntries() | 47 hideReadEntries = self.preferences.hideReadFeedEntries() |
48 self.feedEntries = self.selectedFeed.entriesSortedByUpdateDate(hideReadEntries) | 48 self.feedEntries = self.selectedFeed.entriesSortedByUpdateDate(hideReadEntries) |
49 self.initFeedDisplayModel() | 49 self.initFeedDisplayModel() |
50 | 50 |
51 def initFeedDisplayModel(self): | 51 def initFeedDisplayModel(self): |
52 model = DisplayModel(self, self.feedEntries, FeedEntry.userPresentableString) | 52 model = DisplayModel(self, self.feedEntries, FeedEntry.userPresentableString) |
53 self.ui.feedEntryList.setModel(model) | 53 self.ui.feedEntryList.setModel(model) |
54 self.ui.feedEntryList.itemDelegate().entries = self.feedEntries | 54 self.ui.feedEntryList.itemDelegate().entries = self.feedEntries |
55 self.ui.feedEntryList.update() | 55 self.ui.feedEntryList.update() |
56 | 56 visibleIndex = model.createIndex(0, 0) |
57 self.ui.feedEntryList.scrollTo(visibleIndex) | |
58 | |
57 def feedEntrySelected(self, index): | 59 def feedEntrySelected(self, index): |
58 self.ui.menuArticle.setEnabled(True) | 60 self.ui.menuArticle.setEnabled(True) |
59 | 61 |
60 row = index.row() | 62 row = index.row() |
61 self.selectedEntry = self.feedEntries[row] | 63 self.selectedEntry = self.feedEntries[row] |
62 self.selectedEntry.markRead() | 64 self.selectedEntry.markRead() |
63 | 65 |
64 if self.selectedEntry.feed.auto_load_entry_link: | 66 if self.selectedEntry.feed.auto_load_entry_link: |
65 self.openLinkFromSelectedEntry() | 67 self.openLinkFromSelectedEntry() |
66 else: | 68 else: |
67 self.openSummaryFromSelectedEntry() | 69 self.openSummaryFromSelectedEntry() |
68 | 70 |
69 def openSummaryFromSelectedEntry(self): | 71 def openSummaryFromSelectedEntry(self): |
70 # TODO this is the wrong base url, figure out the correct one | 72 # TODO this is the wrong base url, figure out the correct one |
71 baseUrl = QUrl(self.selectedEntry.link) | 73 baseUrl = QUrl(self.selectedEntry.link) |
72 self.ui.webView.setHtml(self.selectedEntry.summary, baseUrl) | 74 self.ui.webView.setHtml(self.selectedEntry.summary, baseUrl) |
73 | 75 |
74 def openLinkFromSelectedEntry(self): | 76 def openLinkFromSelectedEntry(self): |
75 if self.selectedEntry.feed.always_open_in_browser: | 77 if self.selectedEntry.feed.always_open_in_browser: |
76 self.openSelectedEntryInBrowser() | 78 self.openSelectedEntryInBrowser() |
77 else: | 79 else: |
78 self.openSelectedEntryInWebView() | 80 self.openSelectedEntryInWebView() |
79 | 81 |
80 def openSelectedEntryInWebView(self): | 82 def openSelectedEntryInWebView(self): |
81 message = "Open %s ..." % (self.selectedEntry.title) | 83 message = "Open %s ..." % (self.selectedEntry.title) |
82 self._updateStatusBar(message) | 84 self._updateStatusBar(message) |
83 url = QUrl(self.selectedEntry.link) | 85 url = QUrl(self.selectedEntry.link) |
84 self.ui.webView.load(url) | 86 self.ui.webView.load(url) |
93 | 95 |
94 def toggleReadOnSelectedEntry(self): | 96 def toggleReadOnSelectedEntry(self): |
95 self.selectedEntry.toggleRead() | 97 self.selectedEntry.toggleRead() |
96 self.session.commit() | 98 self.session.commit() |
97 self.ui.feedEntryList.doItemsLayout() | 99 self.ui.feedEntryList.doItemsLayout() |
98 | 100 |
99 def markSelectedFeedRead(self): | 101 def markSelectedFeedRead(self): |
100 self.selectedFeed.markAllEntriesRead() | 102 self.selectedFeed.markAllEntriesRead() |
101 self.session.commit() | 103 self.session.commit() |
102 self.ui.feedEntryList.doItemsLayout() | 104 self.ui.feedEntryList.doItemsLayout() |
103 | 105 |
104 def addFeed(self): | 106 def addFeed(self): |
105 addFeed = AddFeed(self.session) | 107 addFeed = AddFeed(self.session) |
106 success = addFeed.exec_() | 108 success = addFeed.exec_() |
107 if not success: | 109 if not success: |
108 return | 110 return |
109 | 111 |
110 if addFeed.exception is not None: | 112 if addFeed.exception is not None: |
111 message = "Error while adding feed: " + str(addFeed.exception) | 113 message = "Error while adding feed: " + str(addFeed.exception) |
112 self._updateStatusBar(message) | 114 self._updateStatusBar(message) |
113 else: | 115 else: |
114 self.session.commit() | 116 self.session.commit() |
115 self.updateFeedList() | 117 self.updateFeedList() |
116 | 118 |
117 def showPreferences(self): | 119 def showPreferences(self): |
118 preferences = PreferencesDialog(self.session) | 120 preferences = PreferencesDialog(self.session) |
119 preferences.exec_() | 121 preferences.exec_() |
120 | 122 |
121 def showFeedSettings(self): | 123 def showFeedSettings(self): |
122 feedSettings = FeedSettings(self.session, self.selectedFeed) | 124 feedSettings = FeedSettings(self.session, self.selectedFeed) |
123 feedSettings.exec_() | 125 feedSettings.exec_() |
124 | 126 |
125 def _updateStatusBar(self, message): | 127 def _updateStatusBar(self, message): |
126 self.ui.statusbar.showMessage(message, STATUS_MESSAGE_DISPLAY_MILLIS) | 128 self.ui.statusbar.showMessage(message, STATUS_MESSAGE_DISPLAY_MILLIS) |
127 | 129 |