From 9f939859b732b18c46972dc4ca01aa2212b2a62b Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sat, 26 Dec 2015 16:33:29 +0200 Subject: [PATCH 1/2] [Songs Plugin] Add a stop button to the SongSelect importer to stop searching. --- .../plugins/songs/forms/songselectdialog.py | 12 +++++- openlp/plugins/songs/forms/songselectform.py | 19 ++++++++- openlp/plugins/songs/lib/songselect.py | 10 ++++- resources/images/openlp-2.qrc | 1 + resources/images/song_search_stop.png | Bin 0 -> 722 bytes .../openlp_plugins/songs/test_songselect.py | 39 ++++++++++++++++-- 6 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 resources/images/song_search_stop.png diff --git a/openlp/plugins/songs/forms/songselectdialog.py b/openlp/plugins/songs/forms/songselectdialog.py index b1bd9b143..a2985a061 100644 --- a/openlp/plugins/songs/forms/songselectdialog.py +++ b/openlp/plugins/songs/forms/songselectdialog.py @@ -114,12 +114,19 @@ class Ui_SongSelectDialog(object): self.search_button.setObjectName('search_button') self.search_input_layout.addWidget(self.search_button) self.search_layout.addLayout(self.search_input_layout) + self.search_progress_layout = QtWidgets.QHBoxLayout() + self.search_progress_layout.setSpacing(8) + self.search_progress_layout.setObjectName('search_progress_layout') self.search_progress_bar = QtWidgets.QProgressBar(self.search_page) self.search_progress_bar.setMinimum(0) self.search_progress_bar.setMaximum(3) self.search_progress_bar.setValue(0) - self.search_progress_bar.setVisible(False) - self.search_layout.addWidget(self.search_progress_bar) + self.search_progress_layout.addWidget(self.search_progress_bar) + self.stop_button = QtWidgets.QPushButton(self.search_page) + self.stop_button.setIcon(build_icon(':/songs/song_search_stop.png')) + self.stop_button.setObjectName('stop_button') + self.search_progress_layout.addWidget(self.stop_button) + self.search_layout.addLayout(self.search_progress_layout) self.search_results_widget = QtWidgets.QListWidget(self.search_page) self.search_results_widget.setProperty("showDropIndicator", False) self.search_results_widget.setAlternatingRowColors(True) @@ -234,6 +241,7 @@ class Ui_SongSelectDialog(object): self.login_button.setText(translate('SongsPlugin.SongSelectForm', 'Login')) self.search_label.setText(translate('SongsPlugin.SongSelectForm', 'Search Text:')) self.search_button.setText(translate('SongsPlugin.SongSelectForm', 'Search')) + self.stop_button.setText(translate('SongsPlugin.SongSelectForm', 'Stop')) self.result_count_label.setText(translate('SongsPlugin.SongSelectForm', 'Found %s song(s)') % 0) self.logout_button.setText(translate('SongsPlugin.SongSelectForm', 'Logout')) self.view_button.setText(translate('SongsPlugin.SongSelectForm', 'View')) diff --git a/openlp/plugins/songs/forms/songselectform.py b/openlp/plugins/songs/forms/songselectform.py index b8d410c43..71111de7f 100755 --- a/openlp/plugins/songs/forms/songselectform.py +++ b/openlp/plugins/songs/forms/songselectform.py @@ -94,11 +94,13 @@ class SongSelectForm(QtWidgets.QDialog, Ui_SongSelectDialog): self.worker = None self.song_count = 0 self.song = None + self.set_progress_visible(False) self.song_select_importer = SongSelectImport(self.db_manager) self.save_password_checkbox.toggled.connect(self.on_save_password_checkbox_toggled) self.login_button.clicked.connect(self.on_login_button_clicked) self.search_button.clicked.connect(self.on_search_button_clicked) self.search_combobox.returnPressed.connect(self.on_search_button_clicked) + self.stop_button.clicked.connect(self.on_stop_button_clicked) self.logout_button.clicked.connect(self.done) self.search_results_widget.itemDoubleClicked.connect(self.on_search_results_widget_double_clicked) self.search_results_widget.itemSelectionChanged.connect(self.on_search_results_widget_selection_changed) @@ -288,7 +290,7 @@ class SongSelectForm(QtWidgets.QDialog, Ui_SongSelectDialog): self.search_progress_bar.setMinimum(0) self.search_progress_bar.setMaximum(0) self.search_progress_bar.setValue(0) - self.search_progress_bar.setVisible(True) + self.set_progress_visible(True) self.search_results_widget.clear() self.result_count_label.setText(translate('SongsPlugin.SongSelectForm', 'Found %s song(s)') % self.song_count) self.application.process_events() @@ -308,6 +310,12 @@ class SongSelectForm(QtWidgets.QDialog, Ui_SongSelectDialog): self.thread.finished.connect(self.thread.deleteLater) self.thread.start() + def on_stop_button_clicked(self): + """ + Stop the search when the stop button is clicked. + """ + self.song_select_importer.stop() + def on_search_show_info(self, title, message): """ Show an informational message from the search thread @@ -332,7 +340,7 @@ class SongSelectForm(QtWidgets.QDialog, Ui_SongSelectDialog): Slot which is called when the search is completed. """ self.application.process_events() - self.search_progress_bar.setVisible(False) + self.set_progress_visible(False) self.search_button.setEnabled(True) self.application.process_events() @@ -380,6 +388,13 @@ class SongSelectForm(QtWidgets.QDialog, Ui_SongSelectDialog): self.application.process_events() self.done(QtWidgets.QDialog.Accepted) + def set_progress_visible(self, is_visible): + """ + Show or hide the search progress, including the stop button. + """ + self.search_progress_bar.setVisible(is_visible) + self.stop_button.setVisible(is_visible) + @property def application(self): """ diff --git a/openlp/plugins/songs/lib/songselect.py b/openlp/plugins/songs/lib/songselect.py index d2cdcd901..1cd7bab62 100644 --- a/openlp/plugins/songs/lib/songselect.py +++ b/openlp/plugins/songs/lib/songselect.py @@ -61,6 +61,7 @@ class SongSelectImport(object): self.html_parser = HTMLParser() self.opener = build_opener(HTTPCookieProcessor(CookieJar())) self.opener.addheaders = [('User-Agent', USER_AGENT)] + self.run_search = True def login(self, username, password, callback=None): """ @@ -115,10 +116,11 @@ class SongSelectImport(object): :param callback: A method which is called when each song is found, with the song as a parameter. :return: List of songs """ + self.run_search = True params = {'allowredirect': 'false', 'SearchTerm': search_text} current_page = 1 songs = [] - while True: + while self.run_search: if current_page > 1: params['page'] = current_page try: @@ -221,3 +223,9 @@ class SongSelectImport(object): self.db_manager.save_object(db_song) return db_song + def stop(self): + """ + Stop the search. + """ + self.run_search = False + diff --git a/resources/images/openlp-2.qrc b/resources/images/openlp-2.qrc index 11c3482da..82c6234aa 100644 --- a/resources/images/openlp-2.qrc +++ b/resources/images/openlp-2.qrc @@ -1,5 +1,6 @@ + song_search_stop.png song_search_all.png song_search_author.png song_search_lyrics.png diff --git a/resources/images/song_search_stop.png b/resources/images/song_search_stop.png new file mode 100644 index 0000000000000000000000000000000000000000..5b4c488bdfde337177a0fa697d72b92c91bfb4ff GIT binary patch literal 722 zcmV;@0xkWCP)T3ZYmz(SzqVG|c5sBvYC8;yxO zSMFq|3m+?&Il=G#E*49tb+=foJF~O)o2zJAzY&PF{ zcQn;xSqPzlrXf8Sr($<54-e-N;#i|37$JfeySwr|H*TiPjViKU2hYP-r|-JdeIIGH zvULAmHS=RRl4$?nxsLQ$&+S_&y<9>lNLMW?6?D~xf(rKqNMIPx zd#_(jYV!-|zE9h^AzFuq)IAV+w4c8~=fz8y0^G?-dasQn115Tdn&%~|A0}vNX+xMM zI1WZ8gLU}|!H6++cMEgqtE(6)(Z>6UZ6-?KfMBzVR#`_c{$geH4(`G{Mt4TRS=_}1 z)}K5ku0+iP0~os4W}*Zhh?V?Xnv7=Z$s~F<8$KdoN!Mj#`V-#t6m{EXEfF$}36PsM z{9MLeU!(oOL(IN@{(Swi-DdxO(vP0vC*p_z(nBUnAYrSfv!k{YxOn;`zVFlX@->=i zA^`zZ^pJ`6U`mLC?_!J(Hk0VGLEG0J+JjFDxRwQa41O0`O2Ldx?YPU)!&1&fixf!S zn2aCUOCnPtj4HxY0=|T$7Qx3gSv%o`aN{OMl2=M{z*k99Nn-Ihx?xcFJjw_rSIV_h z4e)M3BpHVn>L*IXElUe#_Z Date: Mon, 4 Jan 2016 22:28:41 +0200 Subject: [PATCH 2/2] [song select] Stop search on viewing a song. --- openlp/plugins/songs/forms/songselectform.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/openlp/plugins/songs/forms/songselectform.py b/openlp/plugins/songs/forms/songselectform.py index 71111de7f..9ef3019f3 100755 --- a/openlp/plugins/songs/forms/songselectform.py +++ b/openlp/plugins/songs/forms/songselectform.py @@ -155,18 +155,30 @@ class SongSelectForm(QtWidgets.QDialog, Ui_SongSelectDialog): return QtWidgets.QDialog.done(self, r) def _update_login_progress(self): + """ + Update the progress bar as the user logs in. + """ self.login_progress_bar.setValue(self.login_progress_bar.value() + 1) self.application.process_events() def _update_song_progress(self): + """ + Update the progress bar as the song is being downloaded. + """ self.song_progress_bar.setValue(self.song_progress_bar.value() + 1) self.application.process_events() def _view_song(self, current_item): + """ + Load a song into the song view. + """ if not current_item: return else: current_item = current_item.data(QtCore.Qt.UserRole) + # Stop the current search, if it's running + self.song_select_importer.stop() + # Clear up the UI self.song_progress_bar.setVisible(True) self.import_button.setEnabled(False) self.back_button.setEnabled(False)