Mercurial > hg > Feedworm
comparison MainWindow.py @ 119:04a730f9d07d backend
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Sun, 21 Aug 2011 03:55:16 +0200 |
parents | e9145e8dd698 |
children | e830fa1cc7a2 |
comparison
equal
deleted
inserted
replaced
118:0e73adb2dec4 | 119:04a730f9d07d |
---|---|
1 | 1 |
2 from AddFeed import AddFeed | 2 #from AddFeed import AddFeed |
3 from DisplayModel import DisplayModel | 3 from DisplayModel import DisplayModel |
4 from Feed import Feed | |
5 from FeedEntryItemDelegate import FeedEntryItemDelegate | 4 from FeedEntryItemDelegate import FeedEntryItemDelegate |
6 from FeedEntryTableModel import FeedEntryTableModel | 5 from FeedEntryTableModel import FeedEntryTableModel |
7 from FeedSettings import FeedSettings | 6 from FeedSettings import FeedSettings |
8 from Preferences import Preferences | 7 #from PreferencesDialog import PreferencesDialog |
9 from PreferencesDialog import PreferencesDialog | |
10 from PyQt4.QtCore import QUrl | 8 from PyQt4.QtCore import QUrl |
11 from PyQt4.QtGui import QApplication | 9 from PyQt4.QtGui import QApplication |
12 from PyQt4.QtGui import QMainWindow | 10 from PyQt4.QtGui import QMainWindow |
13 from PyQt4.QtGui import QWidget | 11 from PyQt4.QtGui import QWidget |
14 from Ui_MainWindow import Ui_MainWindow | 12 from Ui_MainWindow import Ui_MainWindow |
15 import FeedList | |
16 import subprocess | 13 import subprocess |
17 | 14 |
18 STATUS_MESSAGE_DISPLAY_MILLIS = 20000 | 15 STATUS_MESSAGE_DISPLAY_MILLIS = 20000 |
19 | 16 |
20 class MainWindow(QMainWindow): | 17 class MainWindow(QMainWindow): |
21 def __init__(self, session=None): | 18 def __init__(self, backend=None): |
22 QWidget.__init__(self, None) | 19 QWidget.__init__(self, None) |
23 self.session = session | 20 self.backend = backend |
24 self.preferences = Preferences(session) | 21 self.preferences = backend.preferences() |
25 self.ui = Ui_MainWindow() | 22 self.ui = Ui_MainWindow() |
26 self.ui.setupUi(self) | 23 self.ui.setupUi(self) |
27 self.updateFeedList() | 24 self.updateFeedList() |
28 self.initFeedEntryList() | 25 self.initFeedEntryList() |
29 | 26 |
30 def updateFeedList(self): | 27 def updateFeedList(self): |
31 self.allFeeds = FeedList.getFeeds(self.session) | 28 self.allFeeds = self.backend.getFeeds() |
32 feedModel = DisplayModel(self, self.allFeeds, Feed.userPresentableString) | 29 feedModel = DisplayModel(self, self.allFeeds, "title") |
33 self.ui.feedList.setModel(feedModel) | 30 self.ui.feedList.setModel(feedModel) |
34 self.ui.feedList.update() | 31 self.ui.feedList.update() |
35 | 32 |
36 def initFeedEntryList(self): | 33 def initFeedEntryList(self): |
37 # setup the default row height. This must be called before a table model is set | 34 # setup the default row height. This must be called before a table model is set |
143 self.selectedEntry.markRead() | 140 self.selectedEntry.markRead() |
144 self.session.commit() | 141 self.session.commit() |
145 self.ui.feedEntryList.doItemsLayout() | 142 self.ui.feedEntryList.doItemsLayout() |
146 | 143 |
147 def addFeed(self): | 144 def addFeed(self): |
148 addFeed = AddFeed(self.session) | 145 pass |
149 success = addFeed.exec_() | 146 # addFeed = AddFeed(self.session) |
150 if not success: | 147 # success = addFeed.exec_() |
151 return | 148 # if not success: |
152 | 149 # return |
153 if addFeed.exception is not None: | 150 # |
154 message = "Error while adding feed: " + str(addFeed.exception) | 151 # if addFeed.exception is not None: |
155 self._updateStatusBar(message) | 152 # message = "Error while adding feed: " + str(addFeed.exception) |
156 else: | 153 # self._updateStatusBar(message) |
157 self.session.commit() | 154 # else: |
158 self.updateFeedList() | 155 # self.session.commit() |
156 # self.updateFeedList() | |
159 | 157 |
160 def deleteFeed(self): | 158 def deleteFeed(self): |
161 try: | 159 try: |
162 self.session.delete(self.selectedFeed) | 160 self.session.delete(self.selectedFeed) |
163 self.session.commit() | 161 self.session.commit() |
165 except Exception as exception: | 163 except Exception as exception: |
166 message = "Error while deleting feed: " + str(exception) | 164 message = "Error while deleting feed: " + str(exception) |
167 self._updateStatusBar(message) | 165 self._updateStatusBar(message) |
168 | 166 |
169 def showPreferences(self): | 167 def showPreferences(self): |
170 preferences = PreferencesDialog(self.session) | 168 pass |
171 preferences.exec_() | 169 # preferences = PreferencesDialog(self.session) |
170 # preferences.exec_() | |
172 | 171 |
173 def showFeedSettings(self): | 172 def showFeedSettings(self): |
174 feedSettings = FeedSettings(self.session, self.selectedFeed) | 173 feedSettings = FeedSettings(self.session, self.selectedFeed) |
175 feedSettings.exec_() | 174 feedSettings.exec_() |
176 | 175 |
177 def _updateStatusBar(self, message): | 176 def _updateStatusBar(self, message): |
178 self.ui.statusbar.showMessage(message, STATUS_MESSAGE_DISPLAY_MILLIS) | 177 self.ui.statusbar.showMessage(message, STATUS_MESSAGE_DISPLAY_MILLIS) |
179 | 178 |
180 def close(self): | 179 def close(self): |
181 # save all uncommitted state, just in case | 180 self.backend.dispose() |
182 self.session.commit() | |
183 QMainWindow.close(self) | 181 QMainWindow.close(self) |
184 | 182 |
185 def copyArticleURLToClipboard(self): | 183 def copyArticleURLToClipboard(self): |
186 clipboard = QApplication.clipboard() | 184 clipboard = QApplication.clipboard() |
187 clipboard.setText(self.selectedEntry.link) | 185 clipboard.setText(self.selectedEntry.link) |