MusicTable clean up duplicate double click functionality
This commit is contained in:
parent
6cb1f79bf5
commit
ca5b9ad849
@ -21,7 +21,8 @@ class MusicTable(QTableView):
|
||||
self.qapp = None
|
||||
# self.tableView.resizeColumnsToContents()
|
||||
self.clicked.connect(self.set_selected_song_filepath)
|
||||
self.doubleClicked.connect(self.set_current_song_filepath) # listens for emitted signal, runs set_current_song_filepath
|
||||
# doubleClicked is a built in event for QTableView - we listen for this event and run set_current_song_filepath
|
||||
self.doubleClicked.connect(self.set_current_song_filepath)
|
||||
self.enterKey.connect(self.set_current_song_filepath)
|
||||
self.fetch_library()
|
||||
|
||||
@ -45,42 +46,11 @@ class MusicTable(QTableView):
|
||||
else: # Default behavior
|
||||
super().keyPressEvent(event)
|
||||
|
||||
def mousePressEvent(self, event):
|
||||
"""Press mouse button. Do thing"""
|
||||
self.last = "Click"
|
||||
QTableView.mousePressEvent(self, event) # Keep original functionality
|
||||
|
||||
def mouseReleaseEvent(self, event):
|
||||
"""Release mouse button. Do thing"""
|
||||
if self.last == "Click":
|
||||
QTimer.singleShot(self.qapp.instance().doubleClickInterval(),
|
||||
self.performSingleClickAction)
|
||||
else:
|
||||
# Perform double click action.
|
||||
self.set_current_song_filepath
|
||||
self.message = "Double Click"
|
||||
self.update()
|
||||
QTableView.mouseReleaseEvent(self, event) # Keep original functionality
|
||||
|
||||
def mouseDoubleClickEvent(self, event):
|
||||
self.last = "Double Click"
|
||||
self.doubleClicked.emit(self.selectionModel().currentIndex()) # emits the current index of the double clicked song
|
||||
QTableView.mouseDoubleClickEvent(self, event) # Keep original functionality
|
||||
|
||||
def performSingleClickAction(self):
|
||||
if self.last == "Click":
|
||||
self.message = "Click"
|
||||
self.update()
|
||||
|
||||
def toggle_play_pause(self):
|
||||
"""Toggles the currently playing song by emitting a signal"""
|
||||
if not self.current_song_filepath:
|
||||
self.set_current_song_filepath()
|
||||
self.playPauseSignal.emit()
|
||||
|
||||
def choose_new_song(self):
|
||||
"""Starts the playback of a new song by emitting a signal"""
|
||||
|
||||
|
||||
def get_selected_rows(self):
|
||||
"""Returns a list of indexes for every selected row"""
|
||||
@ -95,30 +65,30 @@ class MusicTable(QTableView):
|
||||
print(f'Selected song: {self.selected_song_filepath}')
|
||||
|
||||
def set_current_song_filepath(self):
|
||||
"""Sets the filepath of the currently playing/chosen song"""
|
||||
"""Sets the filepath of the currently playing song"""
|
||||
# Setting the current song filepath automatically plays that song
|
||||
# self.tableView listens to this function and plays the audio file located at self.current_song_filepath
|
||||
self.current_song_filepath = self.currentIndex().siblingAtColumn(self.headers.index('path')).data()
|
||||
print(f'Current song: {self.current_song_filepath}')
|
||||
|
||||
def get_selected_song_filepath(self):
|
||||
"""Returns the selected song filepath"""
|
||||
"""Returns the selected songs filepath"""
|
||||
return self.selected_song_filepath
|
||||
|
||||
def get_selected_song_metadata(self):
|
||||
"""Returns the current/chosen song's ID3 tags"""
|
||||
"""Returns the selected song's ID3 tags"""
|
||||
return get_id3_tags(self.selected_song_filepath)
|
||||
|
||||
def get_current_song_filepath(self):
|
||||
"""Returns the current/chosen song filepath"""
|
||||
"""Returns the currently playing song filepath"""
|
||||
return self.current_song_filepath
|
||||
|
||||
def get_current_song_metadata(self):
|
||||
"""Returns the current/chosen song's ID3 tags"""
|
||||
"""Returns the currently playing song's ID3 tags"""
|
||||
return get_id3_tags(self.current_song_filepath)
|
||||
|
||||
def get_current_song_album_art(self):
|
||||
"""Returns the APIC data for the currently playing song"""
|
||||
"""Returns the APIC data (album art lol) for the currently playing song"""
|
||||
return get_album_art(self.current_song_filepath)
|
||||
|
||||
|
||||
@ -150,6 +120,7 @@ class MusicTable(QTableView):
|
||||
|
||||
|
||||
def load_qapp(self, qapp):
|
||||
# why was this necessary again? :thinking:
|
||||
self.qapp = qapp
|
||||
|
||||
|
||||
|
||||
8
main.py
8
main.py
@ -1,4 +1,3 @@
|
||||
import DBA
|
||||
from ui import Ui_MainWindow
|
||||
from PyQt5.QtWidgets import QMainWindow, QApplication, QGraphicsScene, QHeaderView, QGraphicsPixmapItem
|
||||
import qdarktheme
|
||||
@ -76,9 +75,9 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self.actionClearDatabase.triggered.connect(self.clear_database) # Clear database
|
||||
## tableView
|
||||
# self.tableView.clicked.connect(self.set_clicked_cell_filepath)
|
||||
self.tableView.doubleClicked.connect(self.play_audio_file) # Listens for the double click event, and plays the song
|
||||
self.tableView.enterKey.connect(self.play_audio_file) # Press Enter to play song
|
||||
self.tableView.playPauseSignal.connect(self.on_play_clicked) # Spacebar toggle playpause signal
|
||||
self.tableView.doubleClicked.connect(self.play_audio_file) # Listens for the double click event, then plays the song
|
||||
self.tableView.enterKey.connect(self.play_audio_file) # Listens for the enter key event, then plays the song
|
||||
self.tableView.playPauseSignal.connect(self.on_play_clicked) # Spacebar toggle play/pause signal
|
||||
self.tableView.viewport().installEventFilter(self) # for drag & drop functionality
|
||||
# self.tableView.model.layoutChanged()
|
||||
### set column widths
|
||||
@ -117,7 +116,6 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
column_widths_as_string = ','.join(list_of_column_widths)
|
||||
self.config['table']['column_widths'] = column_widths_as_string
|
||||
|
||||
|
||||
# Save the config
|
||||
with open('config.ini', 'w') as configfile:
|
||||
self.config.write(configfile)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user