diff --git a/app.py b/app.py index 7115ebc..86106f3 100755 --- a/app.py +++ b/app.py @@ -5,9 +5,9 @@ import vlc from datetime import datetime, timedelta from pydub import AudioSegment -from PyQt5.QtCore import QEvent +from PyQt5.QtCore import QEvent, Qt from PyQt5.QtWidgets import QApplication, QDialog, QMainWindow, QMessageBox -from PyQt5.QtWidgets import QTableWidgetItem, QFileDialog +from PyQt5.QtWidgets import QTableWidgetItem, QFileDialog, QListWidgetItem from PyQt5.uic import loadUi from threading import Timer from time import sleep @@ -24,22 +24,6 @@ import sqlalchemy from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base -# "Constants" -DISPLAY_SQL = False -MYSQL_CONNECT = "mysql+mysqldb://songdb:songdb@localhost/songdb" - - -# Declare mapping -Base = declarative_base() - -engine = sqlalchemy.create_engine(f"{MYSQL_CONNECT}?charset=utf8", - encoding='utf-8', - echo=DISPLAY_SQL) -Base.metadata.create_all(engine) - -# Create a Session -Session = sessionmaker(bind=engine) -session = Session() class RepeatedTimer: def __init__(self, interval, function, *args, **kwargs): @@ -47,7 +31,7 @@ class RepeatedTimer: self.interval = interval self.function = function self.args = args - self.kwargs = kwargsdlg_search_database_ui + self.kwargs = kwargs self.is_running = False self.start() @@ -66,6 +50,7 @@ class RepeatedTimer: self._timer.cancel() self.is_running = False + class Track: def __init__(self, path): self.path = path @@ -85,7 +70,7 @@ class Track: f" length={self.length}" f" start_gap={self.start_gap}" f" fade_at={self.fade_at}" - f" silence_at={sedlg_search_database_uilf.silence_at}" + f" silence_at={self.silence_at}" f" title={self.title}" f" artist={self.artist}" ) @@ -150,7 +135,6 @@ class Track: ROOT = "/home/kae/music/" - class Window(QMainWindow, Ui_MainWindow): def __init__(self, parent=None): super().__init__(parent) @@ -206,7 +190,7 @@ class Window(QMainWindow, Ui_MainWindow): dlg = QFileDialog() dlg.setFileMode(QFileDialog.ExistingFile) dlg.setViewMode(QFileDialog.Detail) - Gdlg.setDirectory(ROOT) + dlg.setDirectory(ROOT) dlg.setNameFilter("Music files (*.flac *.mp3)") if dlg.exec_(): @@ -234,22 +218,22 @@ class DbDialog(QDialog): self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.lineEdit.textEdited.connect(self.chars_typed) - # import ipdb; ipdb.set_trace() - # self.lineEdit.clicked.connect(self.selectFile) + self.ui.listWidget.itemDoubleClicked.connect(self.listdclick) def chars_typed(self, s): - print(f"chars_typed({s})") if len(s) >= 3: - # matches = Tracks.search_titles(s) - matches = session.query(Tracks).filter( - Tracks.title.ilike(f"%{s}%")).all() + matches = Tracks.search_titles(s) if matches: - # import ipdb; ipdb.set_trace() - songs = [t.title for t in matches] self.ui.listWidget.clear() - self.ui.listWidget.addItems(songs) - + for track in matches: + t = QListWidgetItem() + t.setText(track.title) + t.setData(Qt.UserRole, track.id) + self.ui.listWidget.addItem(t) + def listdclick(self, entry): + import ipdb; ipdb.set_trace() + print(f"clicked entry id={entry.data(Qt.UserRole)}") if __name__ == "__main__": app = QApplication(sys.argv) @@ -262,8 +246,8 @@ if __name__ == "__main__": # # # -## @tl.job(interval=timedelta(seconds=1)) -#def update_progress(player, talk_at, silent_at): +# # @tl.job(interval=timedelta(seconds=1)) +# def update_progress(player, talk_at, silent_at): # elapsed_time = player.get_time() # total_time = player.get_length() # remaining_time = total_time - elapsed_time @@ -280,16 +264,17 @@ if __name__ == "__main__": # , end="\r") # # -## Print name of current song, print name of next song. Play current when -## return pressed, Pri--current-song-output-lengthnt remaining time every -## second. When it ends, print name of new current and next song. +# # Print name of current song, print name of next song. Play current when +# # return pressed, Pri--current-song-output-lengthnt remaining time every +# # second. When it ends, print name of new current and next song. # # -#def test(): +# def test(): # track = "wibg.mp3" -# segment = AudioSegment.from_mp3(track) +# segment = AudioSegment.from_mp3(trm.ack) # print(f"Track: {track}") -# print(f"Leading silence: {ms_to_mmss(leading_silence(segment), decimals=1)}") +# print(f"Leading silence: {ms_to_mmss(leading_silence(segment), +# decimals=1)}") # talk_at = significant_fade(segment) # silent_at = trailing_silence(segment) # print(f"Talkover fade: {ms_to_mmss(talk_at)}")