This commit is contained in:
Keith Edmunds 2022-12-29 08:56:58 +00:00
parent aa405cd6d9
commit f1c27e0e8c
4 changed files with 52 additions and 58 deletions

View File

@ -69,6 +69,24 @@ def file_is_readable(path: str) -> bool:
return os.access(path, os.R_OK)
def function_logger(prefix):
"""
Log function parameters and return
Source: https://stackoverflow.com/questions/25936746/
create-a-function-decorator-that-logs-arguments
"""
def decorate(f):
def wrapper(*args, **kwargs):
print(prefix, f.__name__, "args", args, "kwargs", kwargs)
cr = f(*args, **kwargs)
print(prefix, f.__name__, "result", cr)
return cr
return wrapper
return decorate
def get_audio_segment(path: str) -> Optional[AudioSegment]:
try:
if path.endswith('.mp3'):

View File

@ -9,7 +9,7 @@ import threading
from datetime import datetime, timedelta
from time import sleep
from typing import List, Optional
from typing import Callable, List, Optional
from PyQt5.QtCore import pyqtSignal, QDate, QEvent, Qt, QSize, QTime, QTimer
from PyQt5.QtGui import QColor, QFont, QPalette, QResizeEvent
@ -139,14 +139,11 @@ class Window(QMainWindow, Ui_MainWindow):
self.even_tick: bool = True
self.playing: bool = False
self.music: music.Music = music.Music()
self.current_track: Optional[TrackData] = None
self.current_plr: Optional[PlaylistRows] = None
self.current_track_playlist_tab: Optional[PlaylistTab] = None
self.current_track_end_time = None
self.next_plr: Optional[PlaylistRows] = None
self.next_track: Optional[TrackData] = None
self.next_track_playlist_tab: Optional[PlaylistTab] = None
self.previous_track: Optional[TrackData] = None
self.previous_track_playlist_tab: Optional[PlaylistTab] = None
self.previous_plr: Optional[PlaylistRows] = None
self.previous_track_position: Optional[int] = None
self.selected_plrs = None
@ -564,9 +561,9 @@ class Window(QMainWindow, Ui_MainWindow):
self.playing = False
# Reset current track
if self.current_track:
self.previous_track = self.current_track
self.current_track = None
if self.current_plr:
self.previous_plr = self.current_plr
self.current_plr = None
# Tell playlist_tab track has finished and
# reset current playlist_tab
@ -595,9 +592,6 @@ class Window(QMainWindow, Ui_MainWindow):
self.label_track_length.setText("0:00")
self.label_fade_length.setText("0:00")
# Reset end time
self.current_track_end_time = None
# Update headers
self.update_headers()
@ -629,6 +623,7 @@ class Window(QMainWindow, Ui_MainWindow):
# Get list of track rows for this playlist
plrs = PlaylistRows.get_rows_with_tracks(session, playlist_id)
import ipdb; ipdb.set_trace()
with open(path, "w") as f:
# Required directive on first line
f.write("#EXTM3U\n")
@ -754,6 +749,7 @@ class Window(QMainWindow, Ui_MainWindow):
self.visible_playlist_tab().insert_track(session, track)
self.visible_playlist_tab().save_playlist(session)
@helpers.function_logger("insert_header")
def insert_header(self) -> None:
"""Show dialog box to enter header text and add to playlist"""
@ -1007,8 +1003,8 @@ class Window(QMainWindow, Ui_MainWindow):
self.stop_playing(fade=True)
# Move next track to current track.
self.current_track = self.next_track
self.next_track = None
self.current_plr = self.next_plr
self.next_plr = None
# Ensure playlist tabs are the correct colour
# If current track on different playlist_tab to last, reset
@ -1029,10 +1025,11 @@ class Window(QMainWindow, Ui_MainWindow):
# Play (new) current track
start_at = datetime.now()
self.music.play(self.current_track.path, position)
session.add(self.current_plr.track.path)
self.music.play(self.current_plr.track.path, position)
# Tell database to record it as played
Playdates(session, self.current_track.id)
Playdates(session, self.current_plr.track.id)
# Tell playlist track is now playing
self.current_track_playlist_tab.play_started(session)
@ -1048,16 +1045,16 @@ class Window(QMainWindow, Ui_MainWindow):
# Update clocks
self.label_track_length.setText(
helpers.ms_to_mmss(self.current_track.duration)
helpers.ms_to_mmss(self.current_plr.track.duration)
)
fade_at = self.current_track.fade_at
silence_at = self.current_track.silence_at
fade_at = self.current_plr.track.fade_at
silence_at = self.current_plr.track.silence_at
self.label_fade_length.setText(
helpers.ms_to_mmss(silence_at - fade_at))
self.label_start_time.setText(
start_at.strftime(Config.TRACK_TIME_FORMAT))
self.current_track_end_time = start_at + timedelta(
milliseconds=self.current_track.duration)
milliseconds=self.current_plr.track.duration)
self.label_end_time.setText(
self.current_track_end_time.strftime(Config.TRACK_TIME_FORMAT))
@ -1196,7 +1193,6 @@ class Window(QMainWindow, Ui_MainWindow):
def show_current(self) -> None:
"""Scroll to show current track"""
log.debug("KAE: musicmuster.show_current()")
if self.current_track_playlist_tab != self.visible_playlist_tab():
self.tabPlaylist.setCurrentWidget(self.current_track_playlist_tab)
self.tabPlaylist.currentWidget().scroll_current_to_top()
@ -1204,7 +1200,6 @@ class Window(QMainWindow, Ui_MainWindow):
def show_next(self) -> None:
"""Scroll to show next track"""
log.debug("KAE: musicmuster.show_next()")
if self.next_track_playlist_tab != self.visible_playlist_tab():
self.tabPlaylist.setCurrentWidget(self.next_track_playlist_tab)
self.tabPlaylist.currentWidget().scroll_next_to_top()
@ -1368,10 +1363,10 @@ class Window(QMainWindow, Ui_MainWindow):
# If track is playing, update track clocks time and colours
if self.music.player and self.music.player.is_playing():
playtime = self.music.get_playtime()
time_to_fade = (self.current_track.fade_at - playtime)
time_to_fade = (self.current_plr.track.fade_at - playtime)
time_to_silence = (
self.current_track.silence_at - playtime)
time_to_end = (self.current_track.duration - playtime)
self.current_plr.track.silence_at - playtime)
time_to_end = (self.current_plr.track.duration - playtime)
# Elapsed time
self.label_elapsed_timer.setText(helpers.ms_to_mmss(playtime))

43
poetry.lock generated
View File

@ -245,26 +245,28 @@ python-versions = ">=3.5, <4"
[[package]]
name = "mypy"
version = "0.931"
version = "0.991"
description = "Optional static typing for Python"
category = "dev"
category = "main"
optional = false
python-versions = ">=3.6"
python-versions = ">=3.7"
[package.dependencies]
mypy-extensions = ">=0.4.3"
tomli = ">=1.1.0"
tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""}
typing-extensions = ">=3.10"
[package.extras]
dmypy = ["psutil (>=4.0)"]
install-types = ["pip"]
python2 = ["typed-ast (>=1.4.0,<2)"]
reports = ["lxml"]
[[package]]
name = "mypy-extensions"
version = "0.4.3"
description = "Experimental type system extensions for programs checked with the mypy typechecker."
category = "dev"
category = "main"
optional = false
python-versions = "*"
@ -618,7 +620,7 @@ sqlcipher = ["sqlcipher3-binary"]
name = "sqlalchemy-stubs"
version = "0.4"
description = "SQLAlchemy stubs and mypy plugin"
category = "dev"
category = "main"
optional = false
python-versions = "*"
@ -692,7 +694,7 @@ python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*"
name = "tomli"
version = "2.0.1"
description = "A lil' TOML parser"
category = "dev"
category = "main"
optional = false
python-versions = ">=3.7"
@ -719,7 +721,7 @@ python-versions = "*"
name = "typing-extensions"
version = "4.1.1"
description = "Backported and Experimental Type Hints for Python 3.6+"
category = "dev"
category = "main"
optional = false
python-versions = ">=3.6"
@ -734,7 +736,7 @@ python-versions = "*"
[metadata]
lock-version = "1.1"
python-versions = "^3.9"
content-hash = "8a7dd5f873d901ffbe422d010464bcc8bb2acfa79329a95e4f18f213e120b5a7"
content-hash = "fff052a6a4dc1e7ba869c22e3ac07c6bdadb49e721fab8ac3464e674debb5e8d"
[metadata.files]
alembic = [
@ -901,28 +903,7 @@ mutagen = [
{file = "mutagen-1.45.1-py3-none-any.whl", hash = "sha256:9c9f243fcec7f410f138cb12c21c84c64fde4195481a30c9bfb05b5f003adfed"},
{file = "mutagen-1.45.1.tar.gz", hash = "sha256:6397602efb3c2d7baebd2166ed85731ae1c1d475abca22090b7141ff5034b3e1"},
]
mypy = [
{file = "mypy-0.931-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:3c5b42d0815e15518b1f0990cff7a705805961613e701db60387e6fb663fe78a"},
{file = "mypy-0.931-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:c89702cac5b302f0c5d33b172d2b55b5df2bede3344a2fbed99ff96bddb2cf00"},
{file = "mypy-0.931-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:300717a07ad09525401a508ef5d105e6b56646f7942eb92715a1c8d610149714"},
{file = "mypy-0.931-cp310-cp310-win_amd64.whl", hash = "sha256:7b3f6f557ba4afc7f2ce6d3215d5db279bcf120b3cfd0add20a5d4f4abdae5bc"},
{file = "mypy-0.931-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:1bf752559797c897cdd2c65f7b60c2b6969ffe458417b8d947b8340cc9cec08d"},
{file = "mypy-0.931-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:4365c60266b95a3f216a3047f1d8e3f895da6c7402e9e1ddfab96393122cc58d"},
{file = "mypy-0.931-cp36-cp36m-win_amd64.whl", hash = "sha256:1b65714dc296a7991000b6ee59a35b3f550e0073411ac9d3202f6516621ba66c"},
{file = "mypy-0.931-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:e839191b8da5b4e5d805f940537efcaa13ea5dd98418f06dc585d2891d228cf0"},
{file = "mypy-0.931-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:50c7346a46dc76a4ed88f3277d4959de8a2bd0a0fa47fa87a4cde36fe247ac05"},
{file = "mypy-0.931-cp37-cp37m-win_amd64.whl", hash = "sha256:d8f1ff62f7a879c9fe5917b3f9eb93a79b78aad47b533911b853a757223f72e7"},
{file = "mypy-0.931-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:f9fe20d0872b26c4bba1c1be02c5340de1019530302cf2dcc85c7f9fc3252ae0"},
{file = "mypy-0.931-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:1b06268df7eb53a8feea99cbfff77a6e2b205e70bf31743e786678ef87ee8069"},
{file = "mypy-0.931-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:8c11003aaeaf7cc2d0f1bc101c1cc9454ec4cc9cb825aef3cafff8a5fdf4c799"},
{file = "mypy-0.931-cp38-cp38-win_amd64.whl", hash = "sha256:d9d2b84b2007cea426e327d2483238f040c49405a6bf4074f605f0156c91a47a"},
{file = "mypy-0.931-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:ff3bf387c14c805ab1388185dd22d6b210824e164d4bb324b195ff34e322d166"},
{file = "mypy-0.931-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:5b56154f8c09427bae082b32275a21f500b24d93c88d69a5e82f3978018a0266"},
{file = "mypy-0.931-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:8ca7f8c4b1584d63c9a0f827c37ba7a47226c19a23a753d52e5b5eddb201afcd"},
{file = "mypy-0.931-cp39-cp39-win_amd64.whl", hash = "sha256:74f7eccbfd436abe9c352ad9fb65872cc0f1f0a868e9d9c44db0893440f0c697"},
{file = "mypy-0.931-py3-none-any.whl", hash = "sha256:1171f2e0859cfff2d366da2c7092b06130f232c636a3f7301e3feb8b41f6377d"},
{file = "mypy-0.931.tar.gz", hash = "sha256:0038b21890867793581e4cb0d810829f5fd4441aa75796b53033af3aa30430ce"},
]
mypy = []
mypy-extensions = [
{file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"},
{file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"},

View File

@ -24,12 +24,12 @@ python-Levenshtein = "^0.12.2"
pyfzf = "^0.3.1"
pydymenu = "^0.5.2"
stackprinter = "^0.2.10"
sqlalchemy-stubs = "^0.4"
[tool.poetry.dev-dependencies]
ipdb = "^0.13.9"
sqlalchemy-stubs = "^0.4"
PyQt5-stubs = "^5.15.2"
mypy = "^0.931"
pytest = "^7.0.1"
pytest-qt = "^4.0.2"
pydub-stubs = "^0.25.1"