Mercurial > hg > Feedworm
comparison MainWindow.py @ 228:94a902de5266
use GenericTableModel instead of FeedEntryTableModel
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Sat, 31 May 2014 04:23:53 +0200 |
parents | 016c89dfd488 |
children | 9faa1f84e8c9 |
comparison
equal
deleted
inserted
replaced
227:6ce0e081094a | 228:94a902de5266 |
---|---|
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 import subprocess | 2 import subprocess |
3 from AddFeed import AddFeed | 3 from AddFeed import AddFeed |
4 from PyQtLib.GenericListModel import GenericListModel | 4 from PyQtLib.GenericListModel import GenericListModel |
5 from PyQtLib.GenericTableModel import GenericTableModel | |
5 from FeedEntryItemDelegate import FeedEntryItemDelegate | 6 from FeedEntryItemDelegate import FeedEntryItemDelegate |
6 from FeedEntryTableModel import FeedEntryTableModel | |
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, QMainWindow, QWidget |
11 from Ui_MainWindow import Ui_MainWindow | 11 from Ui_MainWindow import Ui_MainWindow |
18 self.backend = backend | 18 self.backend = backend |
19 self.preferences = backend.preferences() | 19 self.preferences = backend.preferences() |
20 self.ui = Ui_MainWindow() | 20 self.ui = Ui_MainWindow() |
21 self.ui.setupUi(self) | 21 self.ui.setupUi(self) |
22 self.updateFeedList() | 22 self.updateFeedList() |
23 self.initFeedEntryList() | 23 self.initFeedEntryTable() |
24 | 24 |
25 def updateFeedList(self): | 25 def updateFeedList(self): |
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 | 30 |
31 def initFeedEntryList(self): | 31 def initFeedEntryTable(self): |
32 # setup the default row height. This must be called before a table model is set | 32 # setup the default row height. This must be called before a table model is set |
33 self.ui.feedEntryList.verticalHeader().setDefaultSectionSize(20) | 33 self.ui.feedEntryTable.verticalHeader().setDefaultSectionSize(20) |
34 | 34 |
35 self.ui.feedEntryList.setItemDelegate(FeedEntryItemDelegate()) | 35 self.ui.feedEntryTable.setItemDelegate(FeedEntryItemDelegate()) |
36 self.ui.feedEntryList.setModel(FeedEntryTableModel([])) | 36 model = self.__buildFeedEntryTableModel() |
37 self.ui.feedEntryList.horizontalHeader().setStretchLastSection(True) | 37 self.ui.feedEntryTable.setModel(model) |
38 self.ui.feedEntryTable.horizontalHeader().setStretchLastSection(True) | |
39 | |
40 def __buildFeedEntryTableModel(self): | |
41 model = GenericTableModel(self, []) | |
42 titleDisplay = lambda feedEntry: feedEntry.title | |
43 model.defineColumn('Title', titleDisplay) | |
44 dateDisplay = lambda feedEntry: feedEntry.updated.strftime('%d.%m.%Y') | |
45 model.defineColumn('Date', dateDisplay) | |
46 return model | |
38 | 47 |
39 def feedSelected(self, index): | 48 def feedSelected(self, index): |
40 self.backend.selectFeed(index.row()) | 49 self.backend.selectFeed(index.row()) |
41 self.enableFeedRelatedWidgets() | 50 self.enableFeedRelatedWidgets() |
42 self.setupFeedEntries() | 51 self.setupFeedEntries() |
47 self.ui.actionMarkSelectedEntriesRead.setEnabled(True) | 56 self.ui.actionMarkSelectedEntriesRead.setEnabled(True) |
48 self.ui.actionDeleteFeed.setEnabled(True) | 57 self.ui.actionDeleteFeed.setEnabled(True) |
49 | 58 |
50 def setupFeedEntries(self): | 59 def setupFeedEntries(self): |
51 self.setupFeedEntriesTableModel() | 60 self.setupFeedEntriesTableModel() |
52 self.ui.feedEntryList.update() | 61 self.ui.feedEntryTable.update() |
53 self.setupFeedEntriesTableHeaderWidths() | 62 self.setupFeedEntriesTableHeaderWidths() |
54 self.scrollFirstRowInFeedEntriesTableToVisible() | 63 self.scrollFirstRowInFeedEntriesTableToVisible() |
55 | 64 |
56 def setupFeedEntriesTableModel(self): | 65 def setupFeedEntriesTableModel(self): |
57 feedEntries = self.backend.entriesForSelectedFeed() | 66 feedEntries = self.backend.entriesForSelectedFeed() |
58 model = FeedEntryTableModel(feedEntries) | 67 model = self.ui.feedEntryTable.model() |
59 self.ui.feedEntryList.setModel(model) | 68 model.setDisplayedObjects(feedEntries) |
60 | 69 |
61 def setupFeedEntriesTableHeaderWidths(self): | 70 def setupFeedEntriesTableHeaderWidths(self): |
62 width = self.ui.feedEntryList.width() | 71 width = self.ui.feedEntryTable.width() |
63 firstColumnWidth = int(width * 0.8) | 72 firstColumnWidth = int(width * 0.8) |
64 self.ui.feedEntryList.setColumnWidth(0, firstColumnWidth) | 73 self.ui.feedEntryTable.setColumnWidth(0, firstColumnWidth) |
65 | 74 |
66 def scrollFirstRowInFeedEntriesTableToVisible(self): | 75 def scrollFirstRowInFeedEntriesTableToVisible(self): |
67 model = self.ui.feedEntryList.model() | 76 model = self.ui.feedEntryTable.model() |
68 visibleIndex = model.createIndex(0, 0) | 77 visibleIndex = model.createIndex(0, 0) |
69 self.ui.feedEntryList.scrollTo(visibleIndex) | 78 self.ui.feedEntryTable.scrollTo(visibleIndex) |
70 | 79 |
71 def feedEntrySelected(self, index): | 80 def feedEntrySelected(self, index): |
72 self.ui.webView.setZoomFactor(1.0) | 81 self.ui.webView.setZoomFactor(1.0) |
73 self.ui.menuArticle.setEnabled(True) | 82 self.ui.menuArticle.setEnabled(True) |
74 self.ui.actionOpenLink.setEnabled(True) | 83 self.ui.actionOpenLink.setEnabled(True) |
113 browser = "/usr/bin/chromium" | 122 browser = "/usr/bin/chromium" |
114 subprocess.Popen([browser, feedEntry.link]) | 123 subprocess.Popen([browser, feedEntry.link]) |
115 | 124 |
116 def toggleReadOnSelectedEntry(self): | 125 def toggleReadOnSelectedEntry(self): |
117 self.backend.toggleSelectedFeedEntryRead() | 126 self.backend.toggleSelectedFeedEntryRead() |
118 self.ui.feedEntryList.doItemsLayout() | 127 self.ui.feedEntryTable.doItemsLayout() |
119 | 128 |
120 def markSelectedFeedRead(self): | 129 def markSelectedFeedRead(self): |
121 self.backend.markSelectedFeedAsRead() | 130 self.backend.markSelectedFeedAsRead() |
122 self.ui.feedEntryList.doItemsLayout() | 131 self.ui.feedEntryTable.doItemsLayout() |
123 | 132 |
124 def markSelectedEntriesRead(self): | 133 def markSelectedEntriesRead(self): |
125 indexes = [] | 134 indexes = [] |
126 selectedIndexes = self.ui.feedEntryList.selectedIndexes() | 135 selectedIndexes = self.ui.feedEntryTable.selectedIndexes() |
127 for index in selectedIndexes: | 136 for index in selectedIndexes: |
128 # selectedIndexes returns one QModelIndex instance per row/column combo. | 137 # selectedIndexes returns one QModelIndex instance per row/column combo. |
129 # We are only interested in the rows here so just operate on the first | 138 # We are only interested in the rows here so just operate on the first |
130 # column | 139 # column |
131 if index.column() == 0: | 140 if index.column() == 0: |
132 row = index.row() | 141 row = index.row() |
133 indexes.append(row) | 142 indexes.append(row) |
134 self.backend.markFeedEntriesAsRead(indexes) | 143 self.backend.markFeedEntriesAsRead(indexes) |
135 self.ui.feedEntryList.doItemsLayout() | 144 self.ui.feedEntryTable.doItemsLayout() |
136 | 145 |
137 def addFeed(self): | 146 def addFeed(self): |
138 addFeed = AddFeed(self.backend) | 147 addFeed = AddFeed(self.backend) |
139 success = addFeed.exec_() | 148 success = addFeed.exec_() |
140 if not success: | 149 if not success: |