def addHousing(self, backend, housing): if not backend: self.ui.queriesList.setEnabled(True) self.ui.bookmarksButton.setEnabled(True) self.process = None return if not housing: return item = HousingListWidgetItem(housing) item.setAttrs(self.storage) if housing.photos is NotLoaded: process = QtDo(self.weboob, lambda b, 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.do('fillobj', photo, ['data'], backends=housing.backend) self.process_photo[housing.id] = process self.ui.housingsList.addItem(item) if housing.fullid in self.process_bookmarks: self.process_bookmarks.pop(housing.fullid)
def addContact(self, contact): if not contact: self.ui.refreshButton.setEnabled(True) return status = '' if contact.status == Contact.STATUS_ONLINE: status = u'Online' status_color = 0x00aa00 elif contact.status == Contact.STATUS_OFFLINE: status = u'Offline' status_color = 0xff0000 elif contact.status == Contact.STATUS_AWAY: status = u'Away' status_color = 0xffad16 else: status = u'Unknown' status_color = 0xaaaaaa if contact.status_msg: status += u' — %s' % contact.status_msg item = QListWidgetItem() item.setText( '<h2>%s</h2><font color="#%06X">%s</font><br /><i>%s</i>' % (contact.name, status_color, status, contact.backend)) item.setData(Qt.UserRole, contact) if contact.photos is NotLoaded: process = QtDo(self.weboob, lambda b, 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.do('fillobj', photo, ['thumbnail_data'], backends=contact.backend) self.photo_processes[contact.id] = process for i in xrange(self.ui.contactList.count()): if self.ui.contactList.item(i).data( Qt.UserRole).toPyObject().status > contact.status: self.ui.contactList.insertItem(i, item) return self.ui.contactList.addItem(item)
def loadHistory(self): """ Loads the page's log into the 'History' tab """ if self.backend is None: return self.ui.loadHistoryButton.setEnabled(False) self.ui.loadHistoryButton.setText("Loading...") self.ui.historyTable.clear() self.ui.historyTable.setRowCount(0) self.ui.historyTable.setHorizontalHeaderLabels( ["Revision", "Time", "Author", "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, finished) self.process.do(self.app._do_complete, self.ui.nbRevBox.value(), (), 'iter_revisions', self.content.id, backends=(self.backend, ))
def refreshHousingsList(self): name = unicode(self.ui.queriesList.itemText(self.ui.queriesList.currentIndex())) q = self.config.get('queries', name) if q is None: return q self.ui.housingsList.clear() self.ui.queriesList.setEnabled(False) self.ui.bookmarksButton.setEnabled(False) query = Query() query.type = int(q.get('type', 0)) query.cities = [] for c in q['cities']: city = City(c['id']) city.backend = c['backend'] city.name = c['name'] query.cities.append(city) query.area_min = int(q['area_min']) or None query.area_max = int(q['area_max']) or None query.cost_min = int(q['cost_min']) or None 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.do('search_housings', query)
def search(self): pattern = unicode(self.ui.searchEdit.text()) if not pattern: return for minivideo in self.minivideos: self.ui.scrollAreaContent.layout().removeWidget(minivideo) minivideo.hide() minivideo.deleteLater() self.minivideos = [] self.ui.searchEdit.setEnabled(False) 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 saveNotes(self): text = unicode(self.ui.textEdit.toPlainText()) self.ui.saveButton.setEnabled(False) self.ui.textEdit.setEnabled(False) self.process = QtDo(self.weboob, self._saveNotes_cb, self._saveNotes_eb) self.process.do('save_notes', self.contact.id, text, backends=(self.contact.backend,))
def _sendPressed(self): if not self.ui.replyWidget.isVisible(): return text = unicode(self.ui.replyEdit.toPlainText()) title = unicode(self.ui.titleEdit.text()) self.ui.backendsList.setEnabled(False) self.ui.threadsList.setEnabled(False) self.ui.messagesTree.setEnabled(False) self.ui.replyButton.setEnabled(False) self.ui.replyWidget.setEnabled(False) self.ui.sendButton.setText(self.tr('Sending...')) flags = 0 if self.ui.htmlBox.currentIndex() == 0: flags = Message.IS_HTML m = Message(thread=self.thread, id=0, title=title, sender=None, receivers=None, content=text, parent=self.message, flags=flags) self.process_reply = QtDo(self.weboob, self._postReply_cb, self._postReply_eb) self.process_reply.do('post_message', m, backends=self.thread.backend)
def display_photo(self): if not self.housing.photos: self.ui.photosFrame.hide() return if self.displayed_photo_idx >= len(self.housing.photos): self.displayed_photo_idx = len(self.housing.photos) - 1 if self.displayed_photo_idx < 0: self.ui.photosFrame.hide() return self.ui.photosFrame.show() photo = self.housing.photos[self.displayed_photo_idx] if photo.data: data = photo.data 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].do('fillobj', photo, ['data'], backends=self.housing.backend) return img = QImage.fromData(data) img = img.scaledToWidth(self.width()/3) self.ui.photoLabel.setPixmap(QPixmap.fromImage(img)) if photo.url is not NotLoaded: text = '<a href="%s">%s</a>' % (photo.url, photo.url) self.ui.photoUrlLabel.setText(text)
def searchSubtitleAction(self, lang, pattern): self.ui.stackedWidget.setCurrentWidget(self.ui.list_page) for mini in self.minis: self.ui.list_content.layout().removeWidget(mini) mini.hide() mini.deleteLater() self.minis = [] self.parent.ui.searchEdit.setEnabled(False) QApplication.setOverrideCursor(Qt.WaitCursor) backend_name = str( self.parent.ui.backendEdit.itemData( self.parent.ui.backendEdit.currentIndex()).toString()) self.process = QtDo(self.weboob, self.addSubtitle) #self.process.do('iter_subtitles', lang, pattern, backends=backend_name, caps=ICapSubtitle) self.process.do(self.app._do_complete, self.parent.getCount(), ('name'), 'iter_subtitles', lang, pattern, backends=backend_name, caps=ICapSubtitle) self.parent.ui.stopButton.show()
def display_photo(self): if self.displayed_photo_idx >= len(self.contact.photos): self.displayed_photo_idx = len(self.contact.photos) - 1 if self.displayed_photo_idx < 0: self.ui.photoUrlLabel.setText('') return photo = self.contact.photos.values()[self.displayed_photo_idx] if photo.data: data = photo.data 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].do('fillobj', photo, ['data'], backends=self.contact.backend) if photo.thumbnail_data: data = photo.thumbnail_data else: return img = QImage.fromData(data) img = img.scaledToWidth(self.width() / 3) self.ui.photoLabel.setPixmap(QPixmap.fromImage(img)) if photo.url is not NotLoaded: text = '<a href="%s">%s</a>' % (photo.url, photo.url) if photo.hidden: text += '<br /><font color=#ff0000><i>(Hidden photo)</i></font>' self.ui.photoUrlLabel.setText(text)
def savePage(self): """ Saves the current page to the remote site """ if self.backend is None: return new_content = unicode(self.ui.contentEdit.toPlainText()) minor = self.ui.minorBox.isChecked() if new_content != self.content.content: self.ui.saveButton.setEnabled(False) self.ui.saveButton.setText('Saving...') 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, None, self._errorSavePage, finished) self.process.do('push_content', self.content, message, minor=minor, backends=self.backend)
def searchCity(self): pattern = unicode(self.ui.cityEdit.text()) self.ui.resultsList.clear() self.ui.cityEdit.clear() self.ui.cityEdit.setEnabled(False) self.search_process = QtDo(self.weboob, self.addResult) self.search_process.do('search_city', pattern)
def refreshMessages(self, fillobj=False): if self.process_msg: return self.ui.refreshButton.setEnabled(False) self.process_msg = QtDo(self.weboob, self.gotThread, self.gotError) if fillobj and self.thread: self.process_msg.do('fillobj', self.thread, ['root'], backends=self.contact.backend) else: self.process_msg.do('get_thread', self.contact.id, backends=self.contact.backend)
def retrieveContact(self, url): backend_name = unicode(self.ui.backendsList.currentText()) self.ui.urlButton.setEnabled(False) def finished(): self.url_process = None self.ui.urlButton.setEnabled(True) self.url_process = QtDo(self.weboob, self.retrieveContact_cb, self.retrieveContact_eb, finished) self.url_process.do('get_contact', url, backends=backend_name)
def iter_contacts(self, cb): if self.id == 'online': status = Contact.STATUS_ONLINE | Contact.STATUS_AWAY elif self.id == 'offline': status = Contact.STATUS_OFFLINE else: status = Contact.STATUS_ALL self.process = QtDo(self.weboob, lambda b, d: self.cb(cb, b, d)) self.process.do('iter_contacts', status, caps=ICapContact)
def displayBookmarks(self): self.ui.housingsList.clear() self.ui.queriesList.setEnabled(False) self.ui.queriesList.setCurrentIndex(-1) self.ui.bookmarksButton.setEnabled(False) 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].do('get_housing', _id, backends=backend_name)
def refreshThreadMessages(self, backend, id): self.ui.messagesTree.clear() self.ui.messageBody.clear() self.ui.backendsList.setEnabled(False) self.ui.threadsList.setEnabled(False) self.ui.replyButton.setEnabled(False) self.ui.profileButton.hide() self.hideReply() self.process = QtDo(self.weboob, self._gotThreadMessages) self.process.do('get_thread', id, backends=backend)
def refreshThreads(self): self.ui.messagesTree.clear() self.ui.threadsList.clear() self.hideReply() self.ui.profileButton.hide() self.ui.replyButton.setEnabled(False) self.ui.backendsList.setEnabled(False) self.ui.threadsList.setEnabled(False) self.process_threads = QtDo(self.weboob, self._gotThread) self.process_threads.do('iter_threads', backends=self.backend, caps=ICapMessages)
def loadPage(self): """ Loads a page's source into the 'content' QPlainTextEdit """ _id = unicode(self.ui.idEdit.text()) if not _id: return self.ui.loadButton.setEnabled(False) self.ui.loadButton.setText('Loading...') 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 postReply(self): text = unicode(self.ui.textEdit.toPlainText()) self.ui.textEdit.setEnabled(False) self.ui.sendButton.setEnabled(False) m = Message(thread=self.thread, id=0, title=u'', sender=None, 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.do('post_message', m, backends=self.contact.backend)
def __init__(self, weboob, contact, parent=None): QWidget.__init__(self, parent) self.ui = Ui_Notes() self.ui.setupUi(self) self.weboob = weboob self.contact = contact self.ui.textEdit.setEnabled(False) self.ui.saveButton.setEnabled(False) self.process = QtDo(self.weboob, self._getNotes_cb, self._getNotes_eb) self.process.do('get_notes', self.contact.id, backends=(self.contact.backend,)) self.connect(self.ui.saveButton, SIGNAL('clicked()'), self.saveNotes)
def jobSelected(self, item, prev): if item is not None: job = item.job self.ui.queriesFrame.setEnabled(False) self.process = QtDo(self.weboob, self.gotJob) self.process.do('fillobj', job, backends=job.backend) else: job = None self.setJob(job) if prev: prev.setAttrs(self.storage)
def doSearch(self): QApplication.setOverrideCursor(Qt.WaitCursor) pattern = unicode(self.ui.searchEdit.text()) # arbitrary max number of completion word if pattern: if len(self.search_history) > 50: self.search_history.pop(0) if pattern not in self.search_history: self.search_history.append(pattern) self.updateCompletion() self.ui.jobList.clear() self.process = QtDo(self.weboob, self.addJobSearch) self.process.do('search_job', pattern)
def jobSelected(self, item, prev): QApplication.setOverrideCursor(Qt.WaitCursor) if item is not None: job = item.job self.ui.queriesTabWidget.setEnabled(False) self.process = QtDo(self.weboob, self.gotJob) self.process.do('fillobj', job, backends=job.backend) else: job = None self.setJob(job) if prev: prev.setAttrs(self.storage)
def openJob(self): QApplication.setOverrideCursor(Qt.WaitCursor) url = unicode(self.ui.idEdit.text()) if not url: return for backend in self.weboob.iter_backends(): job = backend.get_job_advert(url) if job: self.process = QtDo(self.weboob, self.gotJob) self.process.do('fillobj', job, backends=job.backend) break self.setJob(job) self.ui.idEdit.clear() QApplication.restoreOverrideCursor()
def refreshMessages(self, fillobj=False): if self.process_msg: return self.ui.refreshButton.setEnabled(False) 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: self.process_msg.do('get_thread', self.contact.id, backends=self.contact.backend)
def refreshEventsList(self): self.ui.eventsList.clear() self.ui.refreshButton.setEnabled(False) if self.ui.typeBox.currentIndex() >= 0: # XXX strangely, in gotEvent() in the loop to check if there is already the # event type to try to introduce it in list, itemData() returns the right value. # But, I don't know why, here, it will ALWAYS return None... # So the filter does not work currently. self.events_filter = self.ui.typeBox.itemData( self.ui.typeBox.currentIndex()) else: self.event_filter = None self.ui.typeBox.setEnabled(False) self.ui.typeBox.clear() self.ui.typeBox.addItem('All', None) self.process = QtDo(self.weboob, self.gotEvent) self.process.do('iter_events')
def castingAction(self, backend_name, id, role): self.ui.stackedWidget.setCurrentWidget(self.ui.list_page) for mini in self.minis: self.ui.list_content.layout().removeWidget(mini) mini.hide() mini.deleteLater() self.minis = [] self.parent.ui.searchEdit.setEnabled(False) QApplication.setOverrideCursor(Qt.WaitCursor) self.process = QtDo(self.weboob, self.addPerson) self.process.do('iter_movie_persons', id, role, backends=backend_name, caps=ICapCinema) self.parent.ui.stopButton.show()
def __init__(self, weboob, contact, parent=None): QWidget.__init__(self, parent) self.ui = Ui_Profile() self.ui.setupUi(self) self.connect(self.ui.previousButton, SIGNAL('clicked()'), self.previousClicked) self.connect(self.ui.nextButton, SIGNAL('clicked()'), self.nextClicked) self.weboob = weboob self.contact = contact self.loaded_profile = False self.displayed_photo_idx = 0 self.process_photo = {} missing_fields = self.gotProfile(self.weboob.get_backend(contact.backend), 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)
def housingSelected(self, item, prev): if item is not None: housing = item.housing self.ui.queriesFrame.setEnabled(False) read = set(self.storage.get('read')) read.add(housing.fullid) self.storage.set('read', list(read)) self.storage.save() self.process = QtDo(self.weboob, self.gotHousing) self.process.do('fillobj', housing, backends=housing.backend) else: housing = None self.setHousing(housing) if prev: prev.setAttrs(self.storage)