comparison MainWindow.py @ 241:e0e7459556bc

use Qt to open the selected article in the system browser
author Dirk Olmes <dirk@xanthippe.ping.de>
date Tue, 28 Apr 2015 02:50:57 +0200
parents 9faa1f84e8c9
children f08fa6dcb86f
comparison
equal deleted inserted replaced
240:1b98925facf6 241:e0e7459556bc
5 from PyQtLib.GenericTableModel import GenericTableModel 5 from PyQtLib.GenericTableModel import GenericTableModel
6 from FeedEntryItemDelegate import FeedEntryItemDelegate 6 from FeedEntryItemDelegate import FeedEntryItemDelegate
7 from FeedSettings import FeedSettings 7 from FeedSettings import FeedSettings
8 from PreferencesDialog import PreferencesDialog 8 from PreferencesDialog import PreferencesDialog
9 from PyQt4.QtCore import QUrl 9 from PyQt4.QtCore import QUrl
10 from PyQt4.QtGui import QApplication, QMainWindow, QWidget 10 from PyQt4.QtGui import QApplication, QDesktopServices, QMainWindow, QWidget
11 from Ui_MainWindow import Ui_MainWindow 11 from Ui_MainWindow import Ui_MainWindow
12 12
13 STATUS_MESSAGE_DISPLAY_MILLIS = 20000 13 STATUS_MESSAGE_DISPLAY_MILLIS = 20000
14 14
15 class MainWindow(QMainWindow): 15 class MainWindow(QMainWindow):
26 allFeeds = self.backend.getFeeds() 26 allFeeds = self.backend.getFeeds()
27 feedModel = GenericListModel(self, allFeeds, 'title') 27 feedModel = GenericListModel(self, allFeeds, 'title')
28 self.ui.feedList.setModel(feedModel) 28 self.ui.feedList.setModel(feedModel)
29 self.ui.feedList.update() 29 self.ui.feedList.update()
30 self.__updateFeedCountLabel(allFeeds) 30 self.__updateFeedCountLabel(allFeeds)
31 31
32 def __updateFeedCountLabel(self, feeds): 32 def __updateFeedCountLabel(self, feeds):
33 feedCount = len(feeds) 33 feedCount = len(feeds)
34 text = '%d feed' % feedCount 34 text = '%d feed' % feedCount
35 if feedCount > 1: 35 if feedCount > 1:
36 text = text + 's' 36 text = text + 's'
37 self.ui.feedCountLabel.setText(text) 37 self.ui.feedCountLabel.setText(text)
38 38
39 def initFeedEntryTable(self): 39 def initFeedEntryTable(self):
40 # setup the default row height. This must be called before a table model is set 40 # setup the default row height. This must be called before a table model is set
41 self.ui.feedEntryTable.verticalHeader().setDefaultSectionSize(20) 41 self.ui.feedEntryTable.verticalHeader().setDefaultSectionSize(20)
42 42
43 self.ui.feedEntryTable.setItemDelegate(FeedEntryItemDelegate()) 43 self.ui.feedEntryTable.setItemDelegate(FeedEntryItemDelegate())
46 self.ui.feedEntryTable.horizontalHeader().setStretchLastSection(True) 46 self.ui.feedEntryTable.horizontalHeader().setStretchLastSection(True)
47 47
48 def __buildFeedEntryTableModel(self): 48 def __buildFeedEntryTableModel(self):
49 model = GenericTableModel(self, []) 49 model = GenericTableModel(self, [])
50 titleDisplay = lambda feedEntry: feedEntry.title 50 titleDisplay = lambda feedEntry: feedEntry.title
51 model.defineColumn('Title', titleDisplay) 51 model.defineColumn('Title', titleDisplay)
52 dateDisplay = lambda feedEntry: feedEntry.updated.strftime('%d.%m.%Y') 52 dateDisplay = lambda feedEntry: feedEntry.updated.strftime('%d.%m.%Y')
53 model.defineColumn('Date', dateDisplay) 53 model.defineColumn('Date', dateDisplay)
54 return model 54 return model
55 55
56 def feedSelected(self, index): 56 def feedSelected(self, index):
90 count = len(feedEntries) 90 count = len(feedEntries)
91 text = '%d Article' % count 91 text = '%d Article' % count
92 if count > 1: 92 if count > 1:
93 text = text + 's' 93 text = text + 's'
94 self.ui.feedEntryCountLabel.setText(text) 94 self.ui.feedEntryCountLabel.setText(text)
95 95
96 def feedEntrySelected(self, index): 96 def feedEntrySelected(self, index):
97 self.ui.webView.setZoomFactor(1.0) 97 self.ui.webView.setZoomFactor(1.0)
98 self.ui.menuArticle.setEnabled(True) 98 self.ui.menuArticle.setEnabled(True)
99 self.ui.actionOpenLink.setEnabled(True) 99 self.ui.actionOpenLink.setEnabled(True)
100 100
129 url = QUrl(feedEntry.link) 129 url = QUrl(feedEntry.link)
130 self.ui.webView.load(url) 130 self.ui.webView.load(url)
131 self.ui.webView.show() 131 self.ui.webView.show()
132 132
133 def openSelectedEntryInBrowser(self): 133 def openSelectedEntryInBrowser(self):
134 feedEntry = self.backend.selectedFeedEntry 134 article = self.backend.selectedFeedEntry
135 message = "Open %s in external browser" % (feedEntry.title) 135 message = "Open %s in external browser" % (article.title)
136 self._updateStatusBar(message) 136 self._updateStatusBar(message)
137 # TODO: make browser configurable 137 url = QUrl(article.link)
138 browser = "/usr/bin/chromium" 138 QDesktopServices.openUrl(url)
139 subprocess.Popen([browser, feedEntry.link])
140 139
141 def toggleReadOnSelectedEntry(self): 140 def toggleReadOnSelectedEntry(self):
142 self.backend.toggleSelectedFeedEntryRead() 141 self.backend.toggleSelectedFeedEntryRead()
143 self.ui.feedEntryTable.doItemsLayout() 142 self.ui.feedEntryTable.doItemsLayout()
144 143