From b1f20b548970997870040debbe105eeb4045a770 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Fri, 10 Oct 2014 17:34:48 +0200 Subject: [PATCH] fix bcall to to new behavior of do(), and fix QtDo too, and all Qt applications... --- .../applications/qboobmsg/messages_manager.py | 35 ++++---- weboob/applications/qcineoob/main_window.py | 58 +++++-------- weboob/applications/qcookboob/main_window.py | 18 ++-- weboob/applications/qflatboob/main_window.py | 30 +++---- weboob/applications/qflatboob/query.py | 12 +-- weboob/applications/qhandjoob/main_window.py | 38 ++++----- weboob/applications/qhavedate/contacts.py | 85 +++++++++---------- weboob/applications/qhavedate/events.py | 20 +++-- weboob/applications/qhavedate/search.py | 11 +-- weboob/applications/qhavedate/status.py | 21 ++--- weboob/applications/qvideoob/main_window.py | 14 +-- weboob/applications/qvideoob/minivideo.py | 5 +- .../qwebcontentedit/main_window.py | 63 +++++++------- weboob/browser/filters/standard.py | 1 + weboob/core/bcall.py | 29 ++++--- weboob/tools/application/qt/qt.py | 34 +++++--- 16 files changed, 223 insertions(+), 251 deletions(-) diff --git a/weboob/applications/qboobmsg/messages_manager.py b/weboob/applications/qboobmsg/messages_manager.py index 12aa71f1..655fb0ac 100644 --- a/weboob/applications/qboobmsg/messages_manager.py +++ b/weboob/applications/qboobmsg/messages_manager.py @@ -88,16 +88,15 @@ class MessagesManager(QWidget): self.ui.backendsList.setEnabled(False) self.ui.threadsList.setEnabled(False) - self.process_threads = QtDo(self.weboob, self._gotThread) + self.process_threads = QtDo(self.weboob, self._gotThread, fb=self._gotThreadsEnd) self.process_threads.do('iter_threads', backends=self.backend, caps=CapMessages) - def _gotThread(self, backend, thread): - if not backend: - self.process_threads = None - self.ui.backendsList.setEnabled(True) - self.ui.threadsList.setEnabled(True) - return + def _gotThreadsEnd(self): + self.process_threads = None + self.ui.backendsList.setEnabled(True) + self.ui.threadsList.setEnabled(True) + def _gotThread(self, thread): item = QListWidgetItem(thread.title) item.setData(Qt.UserRole, (thread.backend, thread.id)) self.ui.threadsList.addItem(item) @@ -120,16 +119,15 @@ class MessagesManager(QWidget): self.ui.profileButton.hide() self.hideReply() - self.process = QtDo(self.weboob, self._gotThreadMessages) + self.process = QtDo(self.weboob, self._gotThreadMessages, fb=self._gotThreadMessagesEnd) self.process.do('get_thread', id, backends=backend) - def _gotThreadMessages(self, backend, thread): - if thread is None: - self.ui.backendsList.setEnabled(True) - self.ui.threadsList.setEnabled(True) - self.process = None - return + def _gotThreadMessagesEnd(self): + self.ui.backendsList.setEnabled(True) + self.ui.threadsList.setEnabled(True) + self.process = None + def _gotThreadMessages(self, thread): self.thread = thread if thread.flags & thread.IS_THREADS: top = self.ui.messagesTree.invisibleRootItem() @@ -253,13 +251,10 @@ class MessagesManager(QWidget): content=text, parent=self.message, flags=flags) - self.process_reply = QtDo(self.weboob, self._postReply_cb, self._postReply_eb) + self.process_reply = QtDo(self.weboob, None, self._postReply_eb, self._postReply_fb) self.process_reply.do('post_message', m, backends=self.thread.backend) - def _postReply_cb(self, backend, ignored): - if not backend: - return - + def _postReply_fb(self): self.ui.backendsList.setEnabled(True) self.ui.threadsList.setEnabled(True) self.ui.messagesTree.setEnabled(True) @@ -269,7 +264,7 @@ class MessagesManager(QWidget): self.ui.sendButton.setText(self.tr('Send')) self.hideReply() self.process_reply = None - self.refreshThreadMessages(backend.name, self.thread.id) + self.refreshThreadMessages(self.thread.backend, self.thread.id) def _postReply_eb(self, backend, error, backtrace): content = unicode(self.tr('Unable to send message:\n%s\n')) % to_unicode(error) diff --git a/weboob/applications/qcineoob/main_window.py b/weboob/applications/qcineoob/main_window.py index 54935f0f..0e1748a7 100644 --- a/weboob/applications/qcineoob/main_window.py +++ b/weboob/applications/qcineoob/main_window.py @@ -98,7 +98,7 @@ class Result(QFrame): self.parent.ui.searchEdit.setEnabled(False) QApplication.setOverrideCursor(Qt.WaitCursor) - self.process = QtDo(self.weboob, self.addPerson) + self.process = QtDo(self.weboob, self.addPerson, fb=self.processFinished) self.process.do('iter_movie_persons', id, role, backends=backend_name, caps=CapCinema) self.parent.ui.stopButton.show() @@ -113,7 +113,7 @@ class Result(QFrame): self.parent.ui.searchEdit.setEnabled(False) QApplication.setOverrideCursor(Qt.WaitCursor) - self.process = QtDo(self.weboob, self.addMovie) + self.process = QtDo(self.weboob, self.addMovie, fb=self.processFinished) self.process.do('iter_person_movies', id, role, backends=backend_name, caps=CapCinema) self.parent.ui.stopButton.show() @@ -145,7 +145,7 @@ class Result(QFrame): backend_name = str(self.parent.ui.backendEdit.itemData(self.parent.ui.backendEdit.currentIndex()).toString()) - self.process = QtDo(self.weboob, self.addMovie) + self.process = QtDo(self.weboob, self.addMovie, fb=self.processFinished) #self.process.do('iter_movies', pattern, backends=backend_name, caps=CapCinema) self.process.do(self.app._do_complete, self.parent.getCount(), ('original_title'), 'iter_movies', pattern, backends=backend_name, caps=CapCinema) self.parent.ui.stopButton.show() @@ -153,14 +153,8 @@ class Result(QFrame): def stopProcess(self): self.process.process.finish_event.set() - def addMovie(self, backend, movie): - if not backend: - self.parent.ui.searchEdit.setEnabled(True) - QApplication.restoreOverrideCursor() - self.process = None - self.parent.ui.stopButton.hide() - return - minimovie = MiniMovie(self.weboob, backend, movie, self) + def addMovie(self, movie): + minimovie = MiniMovie(self.weboob, self.weboob[movie.backend], movie, self) self.ui.list_content.layout().addWidget(minimovie) self.minis.append(minimovie) @@ -193,19 +187,13 @@ class Result(QFrame): backend_name = str(self.parent.ui.backendEdit.itemData(self.parent.ui.backendEdit.currentIndex()).toString()) - self.process = QtDo(self.weboob, self.addPerson) + self.process = QtDo(self.weboob, self.addPerson, fb=self.processFinished) #self.process.do('iter_persons', pattern, backends=backend_name, caps=CapCinema) self.process.do(self.app._do_complete, self.parent.getCount(), ('name'), 'iter_persons', pattern, backends=backend_name, caps=CapCinema) self.parent.ui.stopButton.show() - def addPerson(self, backend, person): - if not backend: - self.parent.ui.searchEdit.setEnabled(True) - QApplication.restoreOverrideCursor() - self.process = None - self.parent.ui.stopButton.hide() - return - miniperson = MiniPerson(self.weboob, backend, person, self) + def addPerson(self, person): + miniperson = MiniPerson(self.weboob, self.weboob[person.backend], person, self) self.ui.list_content.layout().addWidget(miniperson) self.minis.append(miniperson) @@ -238,19 +226,19 @@ class Result(QFrame): backend_name = str(self.parent.ui.backendEdit.itemData(self.parent.ui.backendEdit.currentIndex()).toString()) - self.process = QtDo(self.weboob, self.addTorrent) + self.process = QtDo(self.weboob, self.addTorrent, fb=self.processFinished) #self.process.do('iter_torrents', pattern, backends=backend_name, caps=CapTorrent) self.process.do(self.app._do_complete, self.parent.getCount(), ('name'), 'iter_torrents', pattern, backends=backend_name, caps=CapTorrent) self.parent.ui.stopButton.show() - def addTorrent(self, backend, torrent): - if not backend: - self.parent.ui.searchEdit.setEnabled(True) - QApplication.restoreOverrideCursor() - self.process = None - self.parent.ui.stopButton.hide() - return - minitorrent = MiniTorrent(self.weboob, backend, torrent, self) + def processFinished(self): + self.parent.ui.searchEdit.setEnabled(True) + QApplication.restoreOverrideCursor() + self.process = None + self.parent.ui.stopButton.hide() + + def addTorrent(self, torrent): + minitorrent = MiniTorrent(self.weboob, self.weboob[torrent.backend], torrent, self) self.ui.list_content.layout().addWidget(minitorrent) self.minis.append(minitorrent) @@ -282,19 +270,13 @@ class Result(QFrame): backend_name = str(self.parent.ui.backendEdit.itemData(self.parent.ui.backendEdit.currentIndex()).toString()) - self.process = QtDo(self.weboob, self.addSubtitle) + self.process = QtDo(self.weboob, self.addSubtitle, fb=self.processFinished) #self.process.do('iter_subtitles', lang, pattern, backends=backend_name, caps=CapSubtitle) self.process.do(self.app._do_complete, self.parent.getCount(), ('name'), 'iter_subtitles', lang, pattern, backends=backend_name, caps=CapSubtitle) self.parent.ui.stopButton.show() - def addSubtitle(self, backend, subtitle): - if not backend: - self.parent.ui.searchEdit.setEnabled(True) - QApplication.restoreOverrideCursor() - self.process = None - self.parent.ui.stopButton.hide() - return - minisubtitle = MiniSubtitle(self.weboob, backend, subtitle, self) + def addSubtitle(self, subtitle): + minisubtitle = MiniSubtitle(self.weboob, self.weboob[subtitle.backend], subtitle, self) self.ui.list_content.layout().addWidget(minisubtitle) self.minis.append(minisubtitle) diff --git a/weboob/applications/qcookboob/main_window.py b/weboob/applications/qcookboob/main_window.py index b7ce3ad3..3b7dd8d5 100644 --- a/weboob/applications/qcookboob/main_window.py +++ b/weboob/applications/qcookboob/main_window.py @@ -183,18 +183,18 @@ class MainWindow(QtMainWindow): backend_name = str(self.ui.backendEdit.itemData(self.ui.backendEdit.currentIndex()).toString()) - self.process = QtDo(self.weboob, self.addRecipe) + self.process = QtDo(self.weboob, self.addRecipe, fb=self.addRecipeEnd) self.process.do(self.app._do_complete, self.getCount(), ('title'), 'iter_recipes', pattern, backends=backend_name, caps=CapRecipe) self.ui.stopButton.show() - def addRecipe(self, backend, recipe): - if not backend: - self.ui.searchEdit.setEnabled(True) - QApplication.restoreOverrideCursor() - self.process = None - self.ui.stopButton.hide() - return - minirecipe = MiniRecipe(self.weboob, backend, recipe, self) + def addRecipeEnd(self): + self.ui.searchEdit.setEnabled(True) + QApplication.restoreOverrideCursor() + self.process = None + self.ui.stopButton.hide() + + def addRecipe(self, recipe): + minirecipe = MiniRecipe(self.weboob, self.weboob[recipe.backend], recipe, self) self.ui.list_content.layout().addWidget(minirecipe) self.minis.append(minirecipe) diff --git a/weboob/applications/qflatboob/main_window.py b/weboob/applications/qflatboob/main_window.py index 35032bfb..deb2c53e 100644 --- a/weboob/applications/qflatboob/main_window.py +++ b/weboob/applications/qflatboob/main_window.py @@ -203,7 +203,7 @@ class MainWindow(QtMainWindow): query.cost_max = int(q['cost_max']) or None query.nb_rooms = int(q['nb_rooms']) or None - self.process = QtDo(self.weboob, self.addHousing) + self.process = QtDo(self.weboob, self.addHousing, fb=self.addHousingEnd) self.process.do(self.app._do_complete, 20, (), 'search_housings', query) def displayBookmarks(self): @@ -215,16 +215,15 @@ class MainWindow(QtMainWindow): self.processes = {} for id in self.storage.get('bookmarks'): _id, backend_name = id.rsplit('@', 1) - self.process_bookmarks[id] = QtDo(self.weboob, self.addHousing) + self.process_bookmarks[id] = QtDo(self.weboob, self.addHousing, fb=self.addHousingEnd) self.process_bookmarks[id].do('get_housing', _id, backends=backend_name) - def addHousing(self, backend, housing): - if not backend: - self.ui.queriesList.setEnabled(True) - self.ui.bookmarksButton.setEnabled(True) - self.process = None - return + def addHousingEnd(self): + self.ui.queriesList.setEnabled(True) + self.ui.bookmarksButton.setEnabled(True) + self.process = None + def addHousing(self, housing): if not housing: return @@ -232,13 +231,13 @@ class MainWindow(QtMainWindow): item.setAttrs(self.storage) if housing.photos is NotLoaded: - process = QtDo(self.weboob, lambda b, c: self.setPhoto(c, item)) + process = QtDo(self.weboob, lambda c: self.setPhoto(c, item)) process.do('fillobj', housing, ['photos'], backends=housing.backend) self.process_photo[housing.id] = process elif housing.photos is not NotAvailable and len(housing.photos) > 0: if not self.setPhoto(housing, item): photo = housing.photos[0] - process = QtDo(self.weboob, lambda b, p: self.setPhoto(housing, item)) + process = QtDo(self.weboob, lambda p: self.setPhoto(housing, item)) process.do('fillobj', photo, ['data'], backends=housing.backend) self.process_photo[housing.id] = process @@ -334,13 +333,10 @@ class MainWindow(QtMainWindow): label.setTextInteractionFlags(Qt.TextSelectableByMouse|Qt.LinksAccessibleByMouse) self.ui.detailsFrame.layout().addRow('%s:' % key, label) - def gotHousing(self, backend, housing): - if not backend: - self.ui.queriesFrame.setEnabled(True) - self.process = None - return - + def gotHousing(self, housing): self.setHousing(housing, nottext='') + self.ui.queriesFrame.setEnabled(True) + self.process = None def bookmarkChanged(self, state): bookmarks = set(self.storage.get('bookmarks')) @@ -392,7 +388,7 @@ class MainWindow(QtMainWindow): if photo.id in self.process_photo: self.process_photo.pop(photo.id) else: - self.process_photo[photo.id] = QtDo(self.weboob, lambda b,p: self.display_photo()) + self.process_photo[photo.id] = QtDo(self.weboob, lambda p: self.display_photo()) self.process_photo[photo.id].do('fillobj', photo, ['data'], backends=self.housing.backend) return diff --git a/weboob/applications/qflatboob/query.py b/weboob/applications/qflatboob/query.py index b9100488..0e45e6ac 100644 --- a/weboob/applications/qflatboob/query.py +++ b/weboob/applications/qflatboob/query.py @@ -63,13 +63,15 @@ class QueryDialog(QDialog): self.ui.cityEdit.clear() self.ui.cityEdit.setEnabled(False) - self.search_process = QtDo(self.weboob, self.addResult) + self.search_process = QtDo(self.weboob, self.addResult, fb=self.addResultEnd) self.search_process.do('search_city', pattern) - def addResult(self, backend, city): - if not backend or not city: - self.search_process = None - self.ui.cityEdit.setEnabled(True) + def addResultEnd(self): + self.search_process = None + self.ui.cityEdit.setEnabled(True) + + def addResult(self, city): + if not city: return item = self.buildCityItem(city) self.ui.resultsList.addItem(item) diff --git a/weboob/applications/qhandjoob/main_window.py b/weboob/applications/qhandjoob/main_window.py index 66ddb519..a6ac6e88 100644 --- a/weboob/applications/qhandjoob/main_window.py +++ b/weboob/applications/qhandjoob/main_window.py @@ -112,10 +112,15 @@ class MainWindow(QtMainWindow): if index == 1: self.doAdvancedSearch() + def searchFinished(self): + self.process = None + QApplication.restoreOverrideCursor() + def doAdvancedSearch(self): QApplication.setOverrideCursor(Qt.WaitCursor) self.ui.jobListAdvancedSearch.clear() - self.process = QtDo(self.weboob, self.addJobAdvancedSearch) + + self.process = QtDo(self.weboob, self.addJobAdvancedSearch, fb=self.searchFinished) self.process.do('advanced_search_job') def doSearch(self): @@ -131,30 +136,20 @@ class MainWindow(QtMainWindow): self.updateCompletion() self.ui.jobList.clear() - self.process = QtDo(self.weboob, self.addJobSearch) + self.process = QtDo(self.weboob, self.addJobSearch, fb=self.searchFinished) self.process.do('search_job', pattern) - def addJobSearch(self, backend, job): - item = self.addJob(backend, job) + def addJobSearch(self, job): + item = self.addJob(job) if item: self.ui.jobList.addItem(item) - if not backend: - QApplication.restoreOverrideCursor() - - def addJobAdvancedSearch(self, backend, job): - item = self.addJob(backend, job) + def addJobAdvancedSearch(self, job): + item = self.addJob(job) if item: self.ui.jobListAdvancedSearch.addItem(item) - if not backend: - QApplication.restoreOverrideCursor() - - def addJob(self, backend, job): - if not backend: - self.process = None - return - + def addJob(self, job): if not job: return @@ -205,13 +200,10 @@ class MainWindow(QtMainWindow): self.ui.idEdit.clear() QApplication.restoreOverrideCursor() - def gotJob(self, backend, job): - if not backend: - self.ui.queriesTabWidget.setEnabled(True) - self.process = None - return - + def gotJob(self, job): self.setJob(job) + self.ui.queriesTabWidget.setEnabled(True) + self.process = None def setJob(self, job): if job: diff --git a/weboob/applications/qhavedate/contacts.py b/weboob/applications/qhavedate/contacts.py index c716316b..1c0a590f 100644 --- a/weboob/applications/qhavedate/contacts.py +++ b/weboob/applications/qhavedate/contacts.py @@ -101,7 +101,13 @@ class ContactThread(QWidget): return self.ui.refreshButton.setEnabled(False) - self.process_msg = QtDo(self.weboob, self.gotThread, self.gotError) + def finished(): + #v = self.ui.scrollArea.verticalScrollBar() + #print v.minimum(), v.value(), v.maximum(), v.sliderPosition() + #self.ui.scrollArea.verticalScrollBar().setValue(self.ui.scrollArea.verticalScrollBar().maximum()) + self.process_msg = None + + self.process_msg = QtDo(self.weboob, self.gotThread, self.gotError, finished) if fillobj and self.thread: self.process_msg.do('fillobj', self.thread, ['root'], backends=self.contact.backend) else: @@ -112,14 +118,7 @@ class ContactThread(QWidget): self.ui.sendButton.setEnabled(False) self.ui.refreshButton.setEnabled(True) - def gotThread(self, backend, thread): - if not thread: - #v = self.ui.scrollArea.verticalScrollBar() - #print v.minimum(), v.value(), v.maximum(), v.sliderPosition() - #self.ui.scrollArea.verticalScrollBar().setValue(self.ui.scrollArea.verticalScrollBar().maximum()) - self.process_msg = None - return - + def gotThread(self, thread): self.ui.textEdit.setEnabled(True) self.ui.sendButton.setEnabled(True) self.ui.refreshButton.setEnabled(True) @@ -179,12 +178,10 @@ class ContactThread(QWidget): receivers=None, content=text, parent=self.messages[0].message if len(self.messages) > 0 else None) - self.process_reply = QtDo(self.weboob, self._postReply_cb, self._postReply_eb) + self.process_reply = QtDo(self.weboob, None, self._postReply_eb, self._postReply_fb) self.process_reply.do('post_message', m, backends=self.contact.backend) - def _postReply_cb(self, backend, ignored): - if not backend: - return + def _postReply_fb(self): self.ui.textEdit.clear() self.ui.textEdit.setEnabled(True) self.ui.sendButton.setEnabled(True) @@ -216,7 +213,7 @@ class ContactProfile(QWidget): self.displayed_photo_idx = 0 self.process_photo = {} - missing_fields = self.gotProfile(self.weboob.get_backend(contact.backend), contact) + missing_fields = self.gotProfile(contact) if len(missing_fields) > 0: self.process_contact = QtDo(self.weboob, self.gotProfile, self.gotError) self.process_contact.do('fillobj', self.contact, missing_fields, backends=self.contact.backend) @@ -225,10 +222,7 @@ class ContactProfile(QWidget): self.ui.frame_photo.hide() self.ui.descriptionEdit.setText('

Unable to show profile

%s

' % to_unicode(error)) - def gotProfile(self, backend, contact): - if not backend: - return [] - + def gotProfile(self, contact): missing_fields = set() self.display_photo() @@ -325,7 +319,7 @@ class ContactProfile(QWidget): if photo.id in self.process_photo: self.process_photo.pop(photo.id) else: - self.process_photo[photo.id] = QtDo(self.weboob, lambda b,p: self.display_photo()) + self.process_photo[photo.id] = QtDo(self.weboob, lambda p: self.display_photo()) self.process_photo[photo.id].do('fillobj', photo, ['data'], backends=self.contact.backend) if photo.thumbnail_data: @@ -357,19 +351,20 @@ class ContactNotes(QWidget): self.ui.textEdit.setEnabled(False) self.ui.saveButton.setEnabled(False) - self.process = QtDo(self.weboob, self._getNotes_cb, self._getNotes_eb) + + def finished(): + self.process = None + self.ui.textEdit.setEnabled(True) + self.ui.saveButton.setEnabled(True) + + self.process = QtDo(self.weboob, self._getNotes_cb, self._getNotes_eb, finished) self.process.do('get_notes', self.contact.id, backends=(self.contact.backend,)) self.connect(self.ui.saveButton, SIGNAL('clicked()'), self.saveNotes) - def _getNotes_cb(self, backend, data): - if not backend or not data: - self.process = None - self.ui.textEdit.setEnabled(True) - self.ui.saveButton.setEnabled(True) - return - - self.ui.textEdit.setText(data) + def _getNotes_cb(self, data): + if data: + self.ui.textEdit.setText(data) def _getNotes_eb(self, backend, error, backtrace): if isinstance(error, NotImplementedError): @@ -388,17 +383,14 @@ class ContactNotes(QWidget): self.ui.saveButton.setEnabled(False) self.ui.textEdit.setEnabled(False) - self.process = QtDo(self.weboob, self._saveNotes_cb, self._saveNotes_eb) + self.process = QtDo(self.weboob, None, self._saveNotes_eb, self._saveNotes_fb) self.process.do('save_notes', self.contact.id, text, backends=(self.contact.backend,)) - def _saveNotes_cb(self, backend, data): + def _saveNotes_fb(self): self.ui.saveButton.setEnabled(True) self.ui.textEdit.setEnabled(True) - pass def _saveNotes_eb(self, backend, error, backtrace): - self.ui.saveButton.setEnabled(True) - self.ui.textEdit.setEnabled(True) content = unicode(self.tr('Unable to save notes:\n%s\n')) % to_unicode(error) if logging.root.level <= logging.DEBUG: content += '\n%s\n' % to_unicode(backtrace) @@ -425,15 +417,17 @@ class MetaGroup(IGroup): else: status = Contact.STATUS_ALL - self.process = QtDo(self.weboob, lambda b, d: self.cb(cb, b, d)) + self.process = QtDo(self.weboob, lambda d: self.cb(cb, d), fb=lambda: self.fb(cb)) self.process.do('iter_contacts', status, caps=CapContact) - def cb(self, cb, backend, contact): + def cb(self, cb, contact): if contact: cb(contact) - elif not backend: - self.process = None - cb(None) + + def fb(self, fb): + self.process = None + if fb: + fb(None) class ContactsWidget(QWidget): @@ -523,13 +517,13 @@ class ContactsWidget(QWidget): item.setData(Qt.UserRole, contact) if contact.photos is NotLoaded: - process = QtDo(self.weboob, lambda b, c: self.setPhoto(c, item)) + process = QtDo(self.weboob, lambda c: self.setPhoto(c, item)) process.do('fillobj', contact, ['photos'], backends=contact.backend) self.photo_processes[contact.id] = process elif len(contact.photos) > 0: if not self.setPhoto(contact, item): photo = contact.photos.values()[0] - process = QtDo(self.weboob, lambda b, p: self.setPhoto(contact, item)) + process = QtDo(self.weboob, lambda p: self.setPhoto(contact, item)) process.do('fillobj', photo, ['thumbnail_data'], backends=contact.backend) self.photo_processes[contact.id] = process @@ -578,15 +572,14 @@ class ContactsWidget(QWidget): def retrieveContact(self, url): backend_name = unicode(self.ui.backendsList.currentText()) self.ui.urlButton.setEnabled(False) - self.url_process = QtDo(self.weboob, self.retrieveContact_cb, self.retrieveContact_eb) - self.url_process.do('get_contact', url, backends=backend_name) - - def retrieveContact_cb(self, backend, contact): - if not backend: + def finished(): self.url_process = None self.ui.urlButton.setEnabled(True) - return + self.url_process = QtDo(self.weboob, self.retrieveContact_cb, self.retrieveContact_eb, finished) + self.url_process.do('get_contact', url, backends=backend_name) + + def retrieveContact_cb(self, contact): self.ui.urlEdit.clear() self.setContact(contact) diff --git a/weboob/applications/qhavedate/events.py b/weboob/applications/qhavedate/events.py index d5bfda4e..27923878 100644 --- a/weboob/applications/qhavedate/events.py +++ b/weboob/applications/qhavedate/events.py @@ -66,7 +66,11 @@ class EventsWidget(QWidget): self.ui.typeBox.setEnabled(False) self.ui.typeBox.clear() self.ui.typeBox.addItem('All', None) - self.process = QtDo(self.weboob, self.gotEvent) + def finished(): + self.ui.refreshButton.setEnabled(True) + self.ui.typeBox.setEnabled(True) + + self.process = QtDo(self.weboob, self.gotEvent, fb=finished) self.process.do('iter_events') def setPhoto(self, contact, item): @@ -91,12 +95,7 @@ class EventsWidget(QWidget): return False - def gotEvent(self, backend, event): - if not backend: - self.ui.refreshButton.setEnabled(True) - self.ui.typeBox.setEnabled(True) - return - + def gotEvent(self, event): found = False for i in xrange(self.ui.typeBox.count()): s = self.ui.typeBox.itemData(i) @@ -111,6 +110,9 @@ class EventsWidget(QWidget): if self.event_filter and self.event_filter != event.type: return + if not event.contact: + return + contact = event.contact contact.backend = event.backend status = '' @@ -139,13 +141,13 @@ class EventsWidget(QWidget): item = QTreeWidgetItem(None, [name, date, type, message]) item.setData(0, Qt.UserRole, event) if contact.photos is NotLoaded: - process = QtDo(self.weboob, lambda b, c: self.setPhoto(c, item)) + process = QtDo(self.weboob, lambda c: self.setPhoto(c, item)) process.do('fillobj', contact, ['photos'], backends=contact.backend) self.photo_processes[contact.id] = process elif len(contact.photos) > 0: if not self.setPhoto(contact, item): photo = contact.photos.values()[0] - process = QtDo(self.weboob, lambda b, p: self.setPhoto(contact, item)) + process = QtDo(self.weboob, lambda p: self.setPhoto(contact, item)) process.do('fillobj', photo, ['thumbnail_data'], backends=contact.backend) self.photo_processes[contact.id] = process diff --git a/weboob/applications/qhavedate/search.py b/weboob/applications/qhavedate/search.py index a1514bc7..398ebde4 100644 --- a/weboob/applications/qhavedate/search.py +++ b/weboob/applications/qhavedate/search.py @@ -68,10 +68,7 @@ class SearchWidget(QWidget): self.newprofiles_process = QtDo(self.weboob, self.retrieveNewContacts_cb) self.newprofiles_process.do('iter_new_contacts') - def retrieveNewContacts_cb(self, backend, contact): - if not backend: - return - + def retrieveNewContacts_cb(self, contact): self.contacts.insert(0, contact) self.ui.queueLabel.setText('%d' % len(self.contacts)) if self.current is None: @@ -96,9 +93,5 @@ class SearchWidget(QWidget): self.ui.scrollArea.setWidget(None) def sendQuery(self): - self.newprofiles_process = QtDo(self.weboob, self.querySent) + self.newprofiles_process = QtDo(self.weboob, None, fb=self.next) self.newprofiles_process.do('send_query', self.current.id, backends=[self.current.backend]) - - def querySent(self, backend, query): - if backend is None: - self.next() diff --git a/weboob/applications/qhavedate/status.py b/weboob/applications/qhavedate/status.py index 3498327f..01e1aefa 100644 --- a/weboob/applications/qhavedate/status.py +++ b/weboob/applications/qhavedate/status.py @@ -44,9 +44,11 @@ class Account(QFrame): self.title = QLabel(u'

%s — %s

' % (backend.name, backend.DESCRIPTION)) self.body = QLabel() - if backend.ICON: + minfo = self.weboob.repositories.get_module_info(backend.NAME) + icon_path = self.weboob.repositories.get_module_icon_path(minfo) + if icon_path: self.icon = QLabel() - img = QImage(backend.ICON) + img = QImage(icon_path) self.icon.setPixmap(QPixmap.fromImage(img)) head.addWidget(self.icon) @@ -66,21 +68,20 @@ class Account(QFrame): self.weboob.stop(self.timer) def updateStats(self): - self.process = QtDo(self.weboob, self.updateStats_cb, self.updateStats_eb) + self.process = QtDo(self.weboob, self.updateStats_cb, self.updateStats_eb, self.updateStats_fb) self.process.body = u'' self.process.in_p = False self.process.do('get_account_status', backends=self.backend) - def updateStats_cb(self, backend, field): - if not field: - if self.process.in_p: - self.process.body += u"

" + def updateStats_fb(self): + if self.process.in_p: + self.process.body += u"

" - self.body.setText(self.process.body) + self.body.setText(self.process.body) - self.process = None - return + self.process = None + def updateStats_cb(self, field): if field.flags & StatusField.FIELD_HTML: value = u'%s' % field.value else: diff --git a/weboob/applications/qvideoob/main_window.py b/weboob/applications/qvideoob/main_window.py index 4fcc80f7..ecef217b 100644 --- a/weboob/applications/qvideoob/main_window.py +++ b/weboob/applications/qvideoob/main_window.py @@ -109,15 +109,15 @@ class MainWindow(QtMainWindow): backend_name = str(self.ui.backendEdit.itemData(self.ui.backendEdit.currentIndex()).toString()) - self.process = QtDo(self.weboob, self.addVideo) - self.process.do(self.app._do_complete, 20, (), 'search_videos', pattern, self.ui.sortbyEdit.currentIndex(), nsfw=True, backends=backend_name) - - def addVideo(self, backend, video): - if not backend: + def finished(): self.ui.searchEdit.setEnabled(True) self.process = None - return - minivideo = MiniVideo(self.weboob, backend, video) + + self.process = QtDo(self.weboob, self.addVideo, fb=finished) + self.process.do(self.app._do_complete, 20, (), 'search_videos', pattern, self.ui.sortbyEdit.currentIndex(), nsfw=True, backends=backend_name) + + def addVideo(self, video): + minivideo = MiniVideo(self.weboob, self.weboob[video.backend], video) self.ui.scrollAreaContent.layout().addWidget(minivideo) self.minivideos.append(minivideo) if (video.nsfw and not self.ui.nsfwCheckBox.isChecked() or diff --git a/weboob/applications/qvideoob/minivideo.py b/weboob/applications/qvideoob/minivideo.py index 3c846750..1875cf8c 100644 --- a/weboob/applications/qvideoob/minivideo.py +++ b/weboob/applications/qvideoob/minivideo.py @@ -47,10 +47,7 @@ class MiniVideo(QFrame): self.process_thumbnail = QtDo(self.weboob, self.gotThumbnail) self.process_thumbnail.do('fillobj', self.video, ['thumbnail'], backends=backend) - def gotThumbnail(self, backend, video): - if not backend: - return - + def gotThumbnail(self, video): if video.thumbnail and video.thumbnail.data: img = QImage.fromData(video.thumbnail.data) self.ui.imageLabel.setPixmap(QPixmap.fromImage(img)) diff --git a/weboob/applications/qwebcontentedit/main_window.py b/weboob/applications/qwebcontentedit/main_window.py index 64742ce9..2f659b10 100644 --- a/weboob/applications/qwebcontentedit/main_window.py +++ b/weboob/applications/qwebcontentedit/main_window.py @@ -111,21 +111,22 @@ class MainWindow(QtMainWindow): self.ui.contentEdit.setReadOnly(True) backend = str(self.ui.backendBox.currentText()) - self.process = QtDo(self.weboob, - self._loadedPage, - self._errorLoadPage) - self.process.do('get_content', _id, backends=(backend,)) - def _loadedPage(self, backend, data): - """ Callback for loadPage """ - if not backend: - # Loading is finished + def finished(): self.process = None if self.backend: self.ui.contentEdit.setReadOnly(False) self.ui.loadButton.setEnabled(True) self.ui.loadButton.setText('Load') - return + + self.process = QtDo(self.weboob, + self._loadedPage, + self._errorLoadPage, + finished) + self.process.do('get_content', _id, backends=(backend,)) + + def _loadedPage(self, data): + """ Callback for loadPage """ if not data: self.content = None self.backend = None @@ -139,8 +140,8 @@ class MainWindow(QtMainWindow): self.content = data self.ui.contentEdit.setPlainText(self.content.content) self.setWindowTitle("QWebcontentedit - %s@%s" %(self.content.id, - backend.name)) - self.backend = backend + self.content.backend)) + self.backend = self.weboob[self.content.backend] def _errorLoadPage(self, backend, error, backtrace): """ Error callback for loadPage """ @@ -164,25 +165,23 @@ class MainWindow(QtMainWindow): self.ui.contentEdit.setReadOnly(True) self.content.content = new_content message = unicode(self.ui.descriptionEdit.text()) + + def finished(): + self.process = None + self.ui.saveButton.setText('Saved') + self.ui.descriptionEdit.clear() + self.ui.contentEdit.setReadOnly(False) + self.process = QtDo(self.weboob, - self._savedPage, - self._errorSavePage) + None, + self._errorSavePage, + finished) self.process.do('push_content', self.content, message, minor=minor, backends=self.backend) - def _savedPage(self, backend, data): - """ Callback for savePage's QtDo """ - if not backend: - # saving has finished - self.process = None - self.ui.saveButton.setText('Saved') - self.ui.contentEdit.setReadOnly(False) - return - self.ui.descriptionEdit.clear() - def _errorSavePage(self, backend, error, backtrace): """ """ content = unicode(self.tr('Unable to save page:\n%s\n')) % to_unicode(error) @@ -216,9 +215,16 @@ class MainWindow(QtMainWindow): "Summary"]) self.ui.historyTable.setColumnWidth(3, 1000) + def finished(): + self.process = None + self.ui.loadHistoryButton.setEnabled(True) + self.ui.loadHistoryButton.setText("Reload") + + self.process = QtDo(self.weboob, self._gotRevision, - self._errorHistory) + self._errorHistory, + finished) self.process.do(self.app._do_complete, self.ui.nbRevBox.value(), (), @@ -226,15 +232,8 @@ class MainWindow(QtMainWindow): self.content.id, backends=(self.backend,)) - def _gotRevision(self, backend, revision): + def _gotRevision(self, revision): """ Callback for loadHistory's QtDo """ - if not backend: - # The last revision has been processed - self.process = None - self.ui.loadHistoryButton.setEnabled(True) - self.ui.loadHistoryButton.setText("Reload") - return - # we set the flags to Qt.ItemIsEnabled so that the items # are not modifiable (they are modifiable by default) item_revision = QTableWidgetItem(revision.id) diff --git a/weboob/browser/filters/standard.py b/weboob/browser/filters/standard.py index ec8a61b7..0f4ad031 100644 --- a/weboob/browser/filters/standard.py +++ b/weboob/browser/filters/standard.py @@ -214,6 +214,7 @@ class Async(_Filter): class Base(Filter): """ Change the base element used in filters. + >>> Base(Env('header'), CleanText('./h1')) # doctest: +SKIP """ def __call__(self, item): diff --git a/weboob/core/bcall.py b/weboob/core/bcall.py index 4985f4a5..4f00f839 100644 --- a/weboob/core/bcall.py +++ b/weboob/core/bcall.py @@ -65,6 +65,9 @@ class BackendsCall(object): self.tasks.put(backend) def store_result(self, backend, result): + if result is None: + return + if isinstance(result, BaseObject): result.backend = backend.name self.responses.put(result) @@ -75,16 +78,16 @@ class BackendsCall(object): try: # Call method on backend try: - self.logger.debug('%s: Calling function %s' % (backend, function)) + self.logger.debug('%s: Calling function %s', backend, function) if callable(function): result = function(backend, *args, **kwargs) else: result = getattr(backend, function)(*args, **kwargs) except Exception as error: - self.logger.debug('%s: Called function %s raised an error: %r' % (backend, function, error)) + self.logger.debug('%s: Called function %s raised an error: %r', backend, function, error) self.errors.append((backend, error, get_backtrace(error))) else: - self.logger.debug('%s: Called function %s returned: %r' % (backend, function, result)) + self.logger.debug('%s: Called function %s returned: %r', backend, function, result) if hasattr(result, '__iter__') and not isinstance(result, basestring): # Loop on iterator @@ -98,20 +101,23 @@ class BackendsCall(object): finally: self.tasks.task_done() - def _callback_thread_run(self, callback, errback): + def _callback_thread_run(self, callback, errback, finishback): while self.tasks.unfinished_tasks or not self.responses.empty(): try: - callback(*self.responses.get(timeout=0.1)) + response = self.responses.get(timeout=0.1) + if callback: + callback(response) except Queue.Empty: continue # Raise errors - while self.errors: + while errback and self.errors: errback(*self.errors.pop(0)) - callback(None, None) + if finishback: + finishback() - def callback_thread(self, callback, errback=None): + def callback_thread(self, callback, errback=None, finishback=None): """ Call this method to create a thread which will callback a specified function everytimes a new result comes. @@ -120,11 +126,12 @@ class BackendsCall(object): both arguments set to None. The functions prototypes: - def callback(backend, result) - def errback(backend, error) + def callback(result) + def errback(backend, error, backtrace) + def finishback() """ - thread = Thread(target=self._callback_thread_run, args=(callback, errback)) + thread = Thread(target=self._callback_thread_run, args=(callback, errback, finishback)) thread.start() return thread diff --git a/weboob/tools/application/qt/qt.py b/weboob/tools/application/qt/qt.py index d084caa4..29de8796 100644 --- a/weboob/tools/application/qt/qt.py +++ b/weboob/tools/application/qt/qt.py @@ -184,7 +184,7 @@ class QtMainWindow(QMainWindow): class QtDo(QObject): - def __init__(self, weboob, cb, eb=None): + def __init__(self, weboob, cb, eb=None, fb=None): QObject.__init__(self) if not eb: @@ -194,13 +194,15 @@ class QtDo(QObject): self.process = None self.cb = cb self.eb = eb + self.fb = fb self.connect(self, SIGNAL('cb'), self.local_cb) self.connect(self, SIGNAL('eb'), self.local_eb) + self.connect(self, SIGNAL('fb'), self.local_fb) def do(self, *args, **kwargs): self.process = self.weboob.do(*args, **kwargs) - self.process.callback_thread(self.thread_cb, self.thread_eb) + self.process.callback_thread(self.thread_cb, self.thread_eb, self.thread_fb) def default_eb(self, backend, error, backtrace): if isinstance(error, MoreResultsAvailable): @@ -244,22 +246,32 @@ class QtDo(QObject): QMessageBox.critical(None, unicode(self.tr('Error with backend %s')) % backend.name, msg, QMessageBox.Ok) - def local_cb(self, backend, data): - self.cb(backend, data) - if not backend: - self.disconnect(self, SIGNAL('cb'), self.local_cb) - self.disconnect(self, SIGNAL('eb'), self.local_eb) - self.process = None + def local_cb(self, data): + if self.cb: + self.cb(data) def local_eb(self, backend, error, backtrace): - self.eb(backend, error, backtrace) + if self.eb: + self.eb(backend, error, backtrace) - def thread_cb(self, backend, data): - self.emit(SIGNAL('cb'), backend, data) + def local_fb(self): + if self.fb: + self.fb() + + self.disconnect(self, SIGNAL('cb'), self.local_cb) + self.disconnect(self, SIGNAL('eb'), self.local_eb) + self.disconnect(self, SIGNAL('fb'), self.local_fb) + self.process = None + + def thread_cb(self, data): + self.emit(SIGNAL('cb'), data) def thread_eb(self, backend, error, backtrace): self.emit(SIGNAL('eb'), backend, error, backtrace) + def thread_fb(self): + self.emit(SIGNAL('fb')) + class HTMLDelegate(QStyledItemDelegate): def paint(self, painter, option, index):