search box typing timer before searching

This commit is contained in:
billypom on debian 2025-05-05 07:01:43 -04:00
parent de260f3786
commit e7cc36f133
3 changed files with 24 additions and 19 deletions

View File

@ -142,7 +142,7 @@ class MusicTable(QTableView):
self.doubleClicked.connect(self.play_selected_audio_file)
self.enterKey.connect(self.play_selected_audio_file)
self.model2.dataChanged.connect(self.on_cell_data_changed) # editing cells
self.model2.layoutChanged.connect(self.restore_scroll_position)
# self.model2.layoutChanged.connect(self.restore_scroll_position)
self.horizontal_header.sectionResized.connect(self.on_header_resized)
# Final actions
# self.load_music_table()
@ -674,9 +674,6 @@ class MusicTable(QTableView):
hint: You get a `playlist_id` from the signal emitted from PlaylistsPane as a tuple (1,)
"""
debug(
f"load_music_table() | playlist id: \nTYPE: {type(playlist_id)}\nVALUE: {playlist_id}\n"
)
self.disconnect_data_changed()
self.disconnect_layout_changed()
self.vertical_scroll_position = self.verticalScrollBar().value() # type: ignore
@ -757,16 +754,16 @@ class MusicTable(QTableView):
# reloading the model destroys and makes new indexes
# so we look for the new index of the current song on load
current_song_filepath = self.get_current_song_filepath()
print(f"load music table current filepath: {current_song_filepath}")
debug(f"load_music_table() | current filepath: {current_song_filepath}")
for row in range(self.model2.rowCount()):
real_index = self.model2.index(
row, self.headers.user_fields.index("filepath")
)
if real_index.data() == current_song_filepath:
print("is it true?")
print(f"{real_index.data()} == {current_song_filepath}")
print("load music table real index:")
print(real_index)
# print("is it true?")
# print(f"{real_index.data()} == {current_song_filepath}")
# print("load music table real index:")
# print(real_index)
self.current_song_qmodel_index = real_index
self.model2.layoutChanged.emit() # emits a signal that the view should be updated
self.playlistStatsSignal.emit(f"Songs: {row_count} | Total time: {total_time}")

View File

@ -1,3 +1,4 @@
from PyQt5.QtCore import QTimer, pyqtSignal
from PyQt5.QtWidgets import QLineEdit
"""
@ -14,9 +15,15 @@ in MusicTable.py, when Ctrl+F is pressed, the line edit gets hidden or visible
class SearchLineEdit(QLineEdit):
textTypedSignal = pyqtSignal(str)
def __init__(self, parent=None):
super().__init__(parent)
self.setVisible(False)
self.timer = QTimer(self)
self.timer.setSingleShot(True)
self.timer.timeout.connect(self.on_typing_stopped)
self.textChanged.connect(self.on_text_changed)
def toggle_visibility(self) -> bool:
"""
@ -33,10 +40,10 @@ class SearchLineEdit(QLineEdit):
self.setText(None)
return False
# def toggle_visibility(self):
# if self.is_hidden:
# self.button.setVisible(True)
# self.is_hidden = False
# else:
# self.button.setVisible(False)
# self.is_hidden = True
def on_text_changed(self):
"""Reset a timer each time text is changed"""
self.timer.start(300)
def on_typing_stopped(self):
"""When timer reaches end, emit the text that is currently entered"""
self.textTypedSignal.emit(self.text())

View File

@ -67,6 +67,7 @@ from components import (
AudioVisualizer,
CreatePlaylistWindow,
ExportPlaylistWindow,
SearchLineEdit,
)
from utils.get_album_art import get_album_art
@ -266,14 +267,14 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
self.lineEditSearch: QLineEdit
## CONNECTIONS
self.lineEditSearch.textChanged.connect(self.handle_search_box_text)
self.lineEditSearch.textTypedSignal.connect(self.handle_search_box_text)
# tableView
self.tableView.playSignal.connect(self.play_audio_file)
self.tableView.playPauseSignal.connect(
self.on_play_clicked
) # Spacebar toggle play/pause signal
self.tableView.handleProgressSignal.connect(self.handle_progress)
self.tableView.searchBoxSignal.connect(self.handle_search_box)
self.tableView.searchBoxSignal.connect(self.handle_search_box_visibility)
self.tableView.playlistStatsSignal.connect(
self.set_permanent_status_bar_message
)
@ -489,7 +490,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
else:
self.status_bar.showMessage(message)
def handle_search_box(self):
def handle_search_box_visibility(self):
"""show or hide the searchbox"""
visible = self.lineEditSearch.toggle_visibility()
if visible: