class Result(QFrame): def __init__(self, weboob, app, parent=None): QFrame.__init__(self, parent) self.ui = Ui_Result() self.ui.setupUi(self) self.parent = parent self.weboob = weboob self.app = app self.minis = [] self.current_info_widget = None # action history is composed by the last action and the action list # An action is a function, a list of arguments and a description string self.action_history = {'last_action': None, 'action_list': []} self.connect(self.ui.backButton, SIGNAL("clicked()"), self.doBack) self.ui.backButton.hide() def doAction(self, description, fun, args): ''' Call fun with args as arguments and save it in the action history ''' self.ui.currentActionLabel.setText(description) if self.action_history['last_action'] is not None: self.action_history['action_list'].append(self.action_history['last_action']) self.ui.backButton.setToolTip(self.action_history['last_action']['description']) self.ui.backButton.show() self.action_history['last_action'] = {'function': fun, 'args': args, 'description': description} return fun(*args) def doBack(self): ''' Go back in action history Basically call previous function and update history ''' if len(self.action_history['action_list']) > 0: todo = self.action_history['action_list'].pop() self.ui.currentActionLabel.setText(todo['description']) self.action_history['last_action'] = todo if len(self.action_history['action_list']) == 0: self.ui.backButton.hide() else: self.ui.backButton.setToolTip(self.action_history['action_list'][-1]['description']) return todo['function'](*todo['args']) 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, fb=self.processFinished) self.process.do('iter_movie_persons', id, role, backends=backend_name, caps=CapCinema) self.parent.ui.stopButton.show() def filmographyAction(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.addMovie, fb=self.processFinished) self.process.do('iter_person_movies', id, role, backends=backend_name, caps=CapCinema) self.parent.ui.stopButton.show() def search(self, tosearch, pattern, lang): if tosearch == 'person': self.searchPerson(pattern) elif tosearch == 'movie': self.searchMovie(pattern) elif tosearch == 'torrent': self.searchTorrent(pattern) elif tosearch == 'subtitle': self.searchSubtitle(lang, pattern) def searchMovie(self, pattern): if not pattern: return self.doAction(u'Search movie "%s"' % pattern, self.searchMovieAction, [pattern]) def searchMovieAction(self, 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.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() def stopProcess(self): self.process.process.finish_event.set() 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) def displayMovie(self, movie, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget(self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() wmovie = Movie(movie, backend, self) self.ui.info_content.layout().addWidget(wmovie) self.current_info_widget = wmovie QApplication.restoreOverrideCursor() def searchPerson(self, pattern): if not pattern: return self.doAction(u'Search person "%s"' % pattern, self.searchPersonAction, [pattern]) def searchPersonAction(self, 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.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, person): miniperson = MiniPerson(self.weboob, self.weboob[person.backend], person, self) self.ui.list_content.layout().addWidget(miniperson) self.minis.append(miniperson) def displayPerson(self, person, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget(self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() wperson = Person(person, backend, self) self.ui.info_content.layout().addWidget(wperson) self.current_info_widget = wperson QApplication.restoreOverrideCursor() def searchTorrent(self, pattern): if not pattern: return self.doAction(u'Search torrent "%s"' % pattern, self.searchTorrentAction, [pattern]) def searchTorrentAction(self, 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.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 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) def displayTorrent(self, torrent, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget(self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() wtorrent = Torrent(torrent, backend, self) self.ui.info_content.layout().addWidget(wtorrent) self.current_info_widget = wtorrent def searchSubtitle(self, lang, pattern): if not pattern: return self.doAction(u'Search subtitle "%s" (lang:%s)' % (pattern, lang), self.searchSubtitleAction, [lang, pattern]) 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, 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, subtitle): minisubtitle = MiniSubtitle(self.weboob, self.weboob[subtitle.backend], subtitle, self) self.ui.list_content.layout().addWidget(minisubtitle) self.minis.append(minisubtitle) def displaySubtitle(self, subtitle, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget(self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() wsubtitle = Subtitle(subtitle, backend, self) self.ui.info_content.layout().addWidget(wsubtitle) self.current_info_widget = wsubtitle def searchId(self, id, stype): QApplication.setOverrideCursor(Qt.WaitCursor) title_field = 'name' if stype == 'movie': cap = CapCinema title_field = 'original_title' elif stype == 'person': cap = CapCinema elif stype == 'torrent': cap = CapTorrent elif stype == 'subtitle': cap = CapSubtitle if '@' in id: backend_name = id.split('@')[1] id = id.split('@')[0] else: backend_name = None for backend in self.weboob.iter_backends(): if backend.has_caps(cap) and ((backend_name and backend.name == backend_name) or not backend_name): exec('object = backend.get_%s(id)' % (stype)) if object: func_display = 'self.display' + stype[0].upper() + stype[1:] exec("self.doAction('Details of %s \"%%s\"' %% object.%s, %s, [object, backend])" % (stype, title_field, func_display)) QApplication.restoreOverrideCursor()
class Result(QFrame): def __init__(self, weboob, app, parent=None): super(Result, self).__init__(parent) self.ui = Ui_Result() self.ui.setupUi(self) self.parent = parent self.weboob = weboob self.app = app self.minis = [] self.current_info_widget = None # action history is composed by the last action and the action list # An action is a function, a list of arguments and a description string self.action_history = {'last_action': None, 'action_list': []} self.ui.backButton.clicked.connect(self.doBack) self.ui.backButton.hide() def doAction(self, description, fun, args): ''' Call fun with args as arguments and save it in the action history ''' self.ui.currentActionLabel.setText(description) if self.action_history['last_action'] is not None: self.action_history['action_list'].append( self.action_history['last_action']) self.ui.backButton.setToolTip( self.action_history['last_action']['description']) self.ui.backButton.show() self.action_history['last_action'] = { 'function': fun, 'args': args, 'description': description } return fun(*args) @Slot() def doBack(self): ''' Go back in action history Basically call previous function and update history ''' if len(self.action_history['action_list']) > 0: todo = self.action_history['action_list'].pop() self.ui.currentActionLabel.setText(todo['description']) self.action_history['last_action'] = todo if len(self.action_history['action_list']) == 0: self.ui.backButton.hide() else: self.ui.backButton.setToolTip( self.action_history['action_list'][-1]['description']) return todo['function'](*todo['args']) 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, fb=self.processFinished) self.process.do('iter_movie_persons', id, role, backends=backend_name, caps=CapCinema) self.parent.ui.stopButton.show() def moviesInCommonAction(self, backend_name, id1, id2): 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) for a_backend in self.weboob.iter_backends(): if (backend_name and a_backend.name == backend_name): backend = a_backend person1 = backend.get_person(id1) person2 = backend.get_person(id2) lid1 = [] for p in backend.iter_person_movies_ids(id1): lid1.append(p) lid2 = [] for p in backend.iter_person_movies_ids(id2): lid2.append(p) inter = list(set(lid1) & set(lid2)) chrono_list = [] for common in inter: movie = backend.get_movie(common) movie.backend = backend_name role1 = movie.get_roles_by_person_id(person1.id) role2 = movie.get_roles_by_person_id(person2.id) if (movie.release_date != NotAvailable): year = movie.release_date.year else: year = '????' movie.short_description = '(%s) %s as %s ; %s as %s' % ( year, person1.name, ', '.join(role1), person2.name, ', '.join(role2)) i = 0 while (i < len(chrono_list) and movie.release_date != NotAvailable and (chrono_list[i].release_date == NotAvailable or year > chrono_list[i].release_date.year)): i += 1 chrono_list.insert(i, movie) for movie in chrono_list: self.addMovie(movie) self.processFinished() def personsInCommonAction(self, backend_name, id1, id2): 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) for a_backend in self.weboob.iter_backends(): if (backend_name and a_backend.name == backend_name): backend = a_backend movie1 = backend.get_movie(id1) movie2 = backend.get_movie(id2) lid1 = [] for p in backend.iter_movie_persons_ids(id1): lid1.append(p) lid2 = [] for p in backend.iter_movie_persons_ids(id2): lid2.append(p) inter = list(set(lid1) & set(lid2)) for common in inter: person = backend.get_person(common) person.backend = backend_name role1 = movie1.get_roles_by_person_id(person.id) role2 = movie2.get_roles_by_person_id(person.id) person.short_description = '%s in %s ; %s in %s' % ( ', '.join(role1), movie1.original_title, ', '.join(role2), movie2.original_title) self.addPerson(person) self.processFinished() def filmographyAction(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.addMovie, fb=self.processFinished) self.process.do('iter_person_movies', id, role, backends=backend_name, caps=CapCinema) self.parent.ui.stopButton.show() def search(self, tosearch, pattern, lang): if tosearch == 'person': self.searchPerson(pattern) elif tosearch == 'movie': self.searchMovie(pattern) elif tosearch == 'torrent': self.searchTorrent(pattern) elif tosearch == 'subtitle': self.searchSubtitle(lang, pattern) def searchMovie(self, pattern): if not pattern: return self.doAction(u'Search movie "%s"' % pattern, self.searchMovieAction, [pattern]) def searchMovieAction(self, 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 = self.parent.ui.backendEdit.itemData( self.parent.ui.backendEdit.currentIndex()) 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() def stopProcess(self): self.process.process.finish_event.set() def addMovie(self, movie): minimovie = MiniMovie(self.weboob, self.weboob[movie.backend], movie, self) self.ui.list_content.layout().insertWidget( self.ui.list_content.layout().count() - 1, minimovie) self.minis.append(minimovie) def displayMovie(self, movie, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget( self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() wmovie = Movie(movie, backend, self) self.ui.info_content.layout().addWidget(wmovie) self.current_info_widget = wmovie QApplication.restoreOverrideCursor() def searchPerson(self, pattern): if not pattern: return self.doAction(u'Search person "%s"' % pattern, self.searchPersonAction, [pattern]) def searchPersonAction(self, 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 = self.parent.ui.backendEdit.itemData( self.parent.ui.backendEdit.currentIndex()) 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, person): miniperson = MiniPerson(self.weboob, self.weboob[person.backend], person, self) self.ui.list_content.layout().insertWidget( self.ui.list_content.layout().count() - 1, miniperson) self.minis.append(miniperson) def displayPerson(self, person, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget( self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() wperson = Person(person, backend, self) self.ui.info_content.layout().addWidget(wperson) self.current_info_widget = wperson QApplication.restoreOverrideCursor() def searchTorrent(self, pattern): if not pattern: return self.doAction(u'Search torrent "%s"' % pattern, self.searchTorrentAction, [pattern]) def searchTorrentAction(self, 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 = self.parent.ui.backendEdit.itemData( self.parent.ui.backendEdit.currentIndex()) 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 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().insertWidget( self.ui.list_content.layout().count() - 1, minitorrent) self.minis.append(minitorrent) def displayTorrent(self, torrent, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget( self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() wtorrent = Torrent(torrent, backend, self) self.ui.info_content.layout().addWidget(wtorrent) self.current_info_widget = wtorrent def searchSubtitle(self, lang, pattern): if not pattern: return self.doAction(u'Search subtitle "%s" (lang:%s)' % (pattern, lang), self.searchSubtitleAction, [lang, pattern]) 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 = self.parent.ui.backendEdit.itemData( self.parent.ui.backendEdit.currentIndex()) 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, subtitle): minisubtitle = MiniSubtitle(self.weboob, self.weboob[subtitle.backend], subtitle, self) self.ui.list_content.layout().insertWidget( self.ui.list_content.layout().count() - 1, minisubtitle) self.minis.append(minisubtitle) def displaySubtitle(self, subtitle, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget( self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() wsubtitle = Subtitle(subtitle, backend, self) self.ui.info_content.layout().addWidget(wsubtitle) self.current_info_widget = wsubtitle def searchId(self, id, stype): QApplication.setOverrideCursor(Qt.WaitCursor) title_field = 'name' if stype == 'movie': cap = CapCinema title_field = 'original_title' elif stype == 'person': cap = CapCinema elif stype == 'torrent': cap = CapTorrent elif stype == 'subtitle': cap = CapSubtitle if '@' in id: backend_name = id.split('@')[1] id = id.split('@')[0] else: backend_name = None for backend in self.weboob.iter_backends(): if backend.has_caps(cap) and ( (backend_name and backend.name == backend_name) or not backend_name): exec('object = backend.get_%s(id)' % (stype)) if object: func_display = 'self.display' + stype[0].upper( ) + stype[1:] exec( "self.doAction('Details of %s \"%%s\"' %% object.%s, %s, [object, backend])" % (stype, title_field, func_display)) QApplication.restoreOverrideCursor()
class Result(QFrame): def __init__(self, weboob, app, parent=None): QFrame.__init__(self, parent) self.ui = Ui_Result() self.ui.setupUi(self) self.parent = parent self.weboob = weboob self.app = app self.minis = [] self.current_info_widget = None # action history is composed by the last action and the action list # An action is a function, a list of arguments and a description string self.action_history = {'last_action': None, 'action_list': []} self.connect(self.ui.backButton, SIGNAL("clicked()"), self.doBack) self.ui.backButton.hide() def doAction(self, description, fun, args): ''' Call fun with args as arguments and save it in the action history ''' self.ui.currentActionLabel.setText(description) if self.action_history['last_action'] is not None: self.action_history['action_list'].append( self.action_history['last_action']) self.ui.backButton.setToolTip( self.action_history['last_action']['description']) self.ui.backButton.show() self.action_history['last_action'] = { 'function': fun, 'args': args, 'description': description } return fun(*args) def doBack(self): ''' Go back in action history Basically call previous function and update history ''' if len(self.action_history['action_list']) > 0: todo = self.action_history['action_list'].pop() self.ui.currentActionLabel.setText(todo['description']) self.action_history['last_action'] = todo if len(self.action_history['action_list']) == 0: self.ui.backButton.hide() else: self.ui.backButton.setToolTip( self.action_history['action_list'][-1]['description']) return todo['function'](*todo['args']) 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 filmographyAction(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.addMovie) self.process.do('iter_person_movies', id, role, backends=backend_name, caps=ICapCinema) self.parent.ui.stopButton.show() def search(self, tosearch, pattern, lang): if tosearch == 'person': self.searchPerson(pattern) elif tosearch == 'movie': self.searchMovie(pattern) elif tosearch == 'torrent': self.searchTorrent(pattern) elif tosearch == 'subtitle': self.searchSubtitle(lang, pattern) def searchMovie(self, pattern): if not pattern: return self.doAction(u'Search movie "%s"' % pattern, self.searchMovieAction, [pattern]) def searchMovieAction(self, 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.addMovie) #self.process.do('iter_movies', pattern, backends=backend_name, caps=ICapCinema) self.process.do(self.app._do_complete, self.parent.getCount(), ('original_title'), 'iter_movies', pattern, backends=backend_name, caps=ICapCinema) self.parent.ui.stopButton.show() 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) self.ui.list_content.layout().addWidget(minimovie) self.minis.append(minimovie) def displayMovie(self, movie, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget( self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() wmovie = Movie(movie, backend, self) self.ui.info_content.layout().addWidget(wmovie) self.current_info_widget = wmovie QApplication.restoreOverrideCursor() def searchPerson(self, pattern): if not pattern: return self.doAction(u'Search person "%s"' % pattern, self.searchPersonAction, [pattern]) def searchPersonAction(self, 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.addPerson) #self.process.do('iter_persons', pattern, backends=backend_name, caps=ICapCinema) self.process.do(self.app._do_complete, self.parent.getCount(), ('name'), 'iter_persons', pattern, backends=backend_name, caps=ICapCinema) 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) self.ui.list_content.layout().addWidget(miniperson) self.minis.append(miniperson) def displayPerson(self, person, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget( self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() wperson = Person(person, backend, self) self.ui.info_content.layout().addWidget(wperson) self.current_info_widget = wperson QApplication.restoreOverrideCursor() def searchTorrent(self, pattern): if not pattern: return self.doAction(u'Search torrent "%s"' % pattern, self.searchTorrentAction, [pattern]) def searchTorrentAction(self, 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.addTorrent) #self.process.do('iter_torrents', pattern, backends=backend_name, caps=ICapTorrent) self.process.do(self.app._do_complete, self.parent.getCount(), ('name'), 'iter_torrents', pattern, backends=backend_name, caps=ICapTorrent) 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) self.ui.list_content.layout().addWidget(minitorrent) self.minis.append(minitorrent) def displayTorrent(self, torrent, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget( self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() wtorrent = Torrent(torrent, backend, self) self.ui.info_content.layout().addWidget(wtorrent) self.current_info_widget = wtorrent def searchSubtitle(self, lang, pattern): if not pattern: return self.doAction(u'Search subtitle "%s" (lang:%s)' % (pattern, lang), self.searchSubtitleAction, [lang, pattern]) 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 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) self.ui.list_content.layout().addWidget(minisubtitle) self.minis.append(minisubtitle) def displaySubtitle(self, subtitle, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget( self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() wsubtitle = Subtitle(subtitle, backend, self) self.ui.info_content.layout().addWidget(wsubtitle) self.current_info_widget = wsubtitle def searchId(self, id, stype): QApplication.setOverrideCursor(Qt.WaitCursor) title_field = 'name' if stype == 'movie': cap = ICapCinema title_field = 'original_title' elif stype == 'person': cap = ICapCinema elif stype == 'torrent': cap = ICapTorrent elif stype == 'subtitle': cap = ICapSubtitle if '@' in id: backend_name = id.split('@')[1] id = id.split('@')[0] else: backend_name = None for backend in self.weboob.iter_backends(): if backend.has_caps(cap) and ( (backend_name and backend.name == backend_name) or not backend_name): exec('object = backend.get_%s(id)' % (stype)) if object: func_display = 'self.display' + stype[0].upper( ) + stype[1:] exec( "self.doAction('Details of %s \"%%s\"' %% object.%s, %s, [object, backend])" % (stype, title_field, func_display)) QApplication.restoreOverrideCursor()
class Result(QFrame): def __init__(self, weboob, app, parent=None): super(Result, self).__init__(parent) self.ui = Ui_Result() self.ui.setupUi(self) self.parent = parent self.weboob = weboob self.app = app self.minis = [] self.current_info_widget = None # action history is composed by the last action and the action list # An action is a function, a list of arguments and a description string self.action_history = {'last_action': None, 'action_list': []} self.ui.backButton.clicked.connect(self.doBack) self.ui.backButton.hide() def doAction(self, description, fun, args): ''' Call fun with args as arguments and save it in the action history ''' self.ui.currentActionLabel.setText(description) if self.action_history['last_action'] is not None: self.action_history['action_list'].append(self.action_history['last_action']) self.ui.backButton.setToolTip(self.action_history['last_action']['description']) self.ui.backButton.show() self.action_history['last_action'] = {'function': fun, 'args': args, 'description': description} return fun(*args) @Slot() def doBack(self): ''' Go back in action history Basically call previous function and update history ''' if len(self.action_history['action_list']) > 0: todo = self.action_history['action_list'].pop() self.ui.currentActionLabel.setText(todo['description']) self.action_history['last_action'] = todo if len(self.action_history['action_list']) == 0: self.ui.backButton.hide() else: self.ui.backButton.setToolTip(self.action_history['action_list'][-1]['description']) return todo['function'](*todo['args']) 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, fb=self.processFinished) self.process.do('iter_movie_persons', id, role, backends=backend_name, caps=CapCinema) self.parent.ui.stopButton.show() def moviesInCommonAction(self, backend_name, id1, id2): 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) for a_backend in self.weboob.iter_backends(): if (backend_name and a_backend.name == backend_name): backend = a_backend person1 = backend.get_person(id1) person2 = backend.get_person(id2) lid1 = [] for p in backend.iter_person_movies_ids(id1): lid1.append(p) lid2 = [] for p in backend.iter_person_movies_ids(id2): lid2.append(p) inter = list(set(lid1) & set(lid2)) chrono_list = [] for common in inter: movie = backend.get_movie(common) movie.backend = backend_name role1 = movie.get_roles_by_person_id(person1.id) role2 = movie.get_roles_by_person_id(person2.id) if (movie.release_date != NotAvailable): year = movie.release_date.year else: year = '????' movie.short_description = '(%s) %s as %s ; %s as %s'%(year , person1.name, ', '.join(role1), person2.name, ', '.join(role2)) i = 0 while (i<len(chrono_list) and movie.release_date != NotAvailable and (chrono_list[i].release_date == NotAvailable or year > chrono_list[i].release_date.year)): i += 1 chrono_list.insert(i, movie) for movie in chrono_list: self.addMovie(movie) self.processFinished() def personsInCommonAction(self, backend_name, id1, id2): 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) for a_backend in self.weboob.iter_backends(): if (backend_name and a_backend.name == backend_name): backend = a_backend movie1 = backend.get_movie(id1) movie2 = backend.get_movie(id2) lid1 = [] for p in backend.iter_movie_persons_ids(id1): lid1.append(p) lid2 = [] for p in backend.iter_movie_persons_ids(id2): lid2.append(p) inter = list(set(lid1) & set(lid2)) for common in inter: person = backend.get_person(common) person.backend = backend_name role1 = movie1.get_roles_by_person_id(person.id) role2 = movie2.get_roles_by_person_id(person.id) person.short_description = '%s in %s ; %s in %s'%(', '.join(role1), movie1.original_title, ', '.join(role2), movie2.original_title) self.addPerson(person) self.processFinished() def filmographyAction(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.addMovie, fb=self.processFinished) self.process.do('iter_person_movies', id, role, backends=backend_name, caps=CapCinema) self.parent.ui.stopButton.show() def search(self, tosearch, pattern, lang): if tosearch == 'person': self.searchPerson(pattern) elif tosearch == 'movie': self.searchMovie(pattern) elif tosearch == 'torrent': self.searchTorrent(pattern) elif tosearch == 'subtitle': self.searchSubtitle(lang, pattern) def searchMovie(self, pattern): if not pattern: return self.doAction(u'Search movie "%s"' % pattern, self.searchMovieAction, [pattern]) def searchMovieAction(self, 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 = self.parent.ui.backendEdit.itemData(self.parent.ui.backendEdit.currentIndex()) 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() def stopProcess(self): self.process.process.finish_event.set() def addMovie(self, movie): minimovie = MiniMovie(self.weboob, self.weboob[movie.backend], movie, self) self.ui.list_content.layout().insertWidget(self.ui.list_content.layout().count()-1,minimovie) self.minis.append(minimovie) def displayMovie(self, movie, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget(self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() wmovie = Movie(movie, backend, self) self.ui.info_content.layout().addWidget(wmovie) self.current_info_widget = wmovie QApplication.restoreOverrideCursor() def searchPerson(self, pattern): if not pattern: return self.doAction(u'Search person "%s"' % pattern, self.searchPersonAction, [pattern]) def searchPersonAction(self, 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 = self.parent.ui.backendEdit.itemData(self.parent.ui.backendEdit.currentIndex()) 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, person): miniperson = MiniPerson(self.weboob, self.weboob[person.backend], person, self) self.ui.list_content.layout().insertWidget(self.ui.list_content.layout().count()-1,miniperson) self.minis.append(miniperson) def displayPerson(self, person, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget(self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() wperson = Person(person, backend, self) self.ui.info_content.layout().addWidget(wperson) self.current_info_widget = wperson QApplication.restoreOverrideCursor() def searchTorrent(self, pattern): if not pattern: return self.doAction(u'Search torrent "%s"' % pattern, self.searchTorrentAction, [pattern]) def searchTorrentAction(self, 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 = self.parent.ui.backendEdit.itemData(self.parent.ui.backendEdit.currentIndex()) 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 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().insertWidget(self.ui.list_content.layout().count()-1,minitorrent) self.minis.append(minitorrent) def displayTorrent(self, torrent, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget(self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() wtorrent = Torrent(torrent, backend, self) self.ui.info_content.layout().addWidget(wtorrent) self.current_info_widget = wtorrent def searchSubtitle(self, lang, pattern): if not pattern: return self.doAction(u'Search subtitle "%s" (lang:%s)' % (pattern, lang), self.searchSubtitleAction, [lang, pattern]) 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 = self.parent.ui.backendEdit.itemData(self.parent.ui.backendEdit.currentIndex()) 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, subtitle): minisubtitle = MiniSubtitle(self.weboob, self.weboob[subtitle.backend], subtitle, self) self.ui.list_content.layout().insertWidget(self.ui.list_content.layout().count()-1,minisubtitle) self.minis.append(minisubtitle) def displaySubtitle(self, subtitle, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget(self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() wsubtitle = Subtitle(subtitle, backend, self) self.ui.info_content.layout().addWidget(wsubtitle) self.current_info_widget = wsubtitle def searchId(self, id, stype): QApplication.setOverrideCursor(Qt.WaitCursor) title_field = 'name' if stype == 'movie': cap = CapCinema title_field = 'original_title' elif stype == 'person': cap = CapCinema elif stype == 'torrent': cap = CapTorrent elif stype == 'subtitle': cap = CapSubtitle if '@' in id: backend_name = id.split('@')[1] id = id.split('@')[0] else: backend_name = None for backend in self.weboob.iter_backends(): if backend.has_caps(cap) and ((backend_name and backend.name == backend_name) or not backend_name): exec('object = backend.get_%s(id)' % (stype)) if object: func_display = 'self.display' + stype[0].upper() + stype[1:] exec("self.doAction('Details of %s \"%%s\"' %% object.%s, %s, [object, backend])" % (stype, title_field, func_display)) QApplication.restoreOverrideCursor()