Typing and other cleanups
This commit is contained in:
parent
73bb4b3a7f
commit
5d50ebf3aa
@ -5,21 +5,17 @@ import smtplib
|
|||||||
import ssl
|
import ssl
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from email.message import EmailMessage
|
|
||||||
from mutagen.flac import FLAC # type: ignore
|
|
||||||
from mutagen.mp3 import MP3 # type: ignore
|
|
||||||
from pydub import effects
|
|
||||||
from pydub.utils import mediainfo
|
|
||||||
|
|
||||||
from config import Config
|
from config import Config
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from email.message import EmailMessage
|
||||||
from log import log
|
from log import log
|
||||||
from pydub import AudioSegment
|
from mutagen.flac import FLAC # type: ignore
|
||||||
|
from mutagen.mp3 import MP3 # type: ignore
|
||||||
|
from pydub import AudioSegment, effects
|
||||||
|
from pydub.utils import mediainfo
|
||||||
from PyQt5.QtWidgets import QMessageBox
|
from PyQt5.QtWidgets import QMessageBox
|
||||||
from tinytag import TinyTag # type: ignore
|
from tinytag import TinyTag # type: ignore
|
||||||
from typing import Optional
|
from typing import Any, Dict, Optional, Union
|
||||||
# from typing import Dict, Optional, Union
|
|
||||||
from typing import Dict, Union
|
|
||||||
|
|
||||||
|
|
||||||
def ask_yes_no(title: str, question: str) -> bool:
|
def ask_yes_no(title: str, question: str) -> bool:
|
||||||
@ -82,7 +78,7 @@ def get_audio_segment(path: str) -> Optional[AudioSegment]:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_tags(path: str) -> Dict[str, Union[str, int]]:
|
def get_tags(path: str) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Return a dictionary of title, artist, duration-in-milliseconds and path.
|
Return a dictionary of title, artist, duration-in-milliseconds and path.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -212,7 +212,7 @@ class Playlists(Base):
|
|||||||
def __init__(self, session: scoped_session, name: str):
|
def __init__(self, session: scoped_session, name: str):
|
||||||
self.name = name
|
self.name = name
|
||||||
session.add(self)
|
session.add(self)
|
||||||
session.commit()
|
session.flush()
|
||||||
|
|
||||||
def close(self, session: scoped_session) -> None:
|
def close(self, session: scoped_session) -> None:
|
||||||
"""Mark playlist as unloaded"""
|
"""Mark playlist as unloaded"""
|
||||||
@ -233,10 +233,15 @@ class Playlists(Base):
|
|||||||
session: scoped_session,
|
session: scoped_session,
|
||||||
template: "Playlists",
|
template: "Playlists",
|
||||||
playlist_name: str) \
|
playlist_name: str) \
|
||||||
-> "Playlists":
|
-> Optional["Playlists"]:
|
||||||
"""Create a new playlist from template"""
|
"""Create a new playlist from template"""
|
||||||
|
|
||||||
playlist = cls(session, playlist_name)
|
playlist = cls(session, playlist_name)
|
||||||
|
|
||||||
|
# Sanity / mypy checks
|
||||||
|
if not playlist or not playlist.id or not template.id:
|
||||||
|
return None
|
||||||
|
|
||||||
PlaylistRows.copy_playlist(session, template.id, playlist.id)
|
PlaylistRows.copy_playlist(session, template.id, playlist.id)
|
||||||
|
|
||||||
return playlist
|
return playlist
|
||||||
@ -334,6 +339,9 @@ class Playlists(Base):
|
|||||||
"""Save passed playlist as new template"""
|
"""Save passed playlist as new template"""
|
||||||
|
|
||||||
template = Playlists(session, template_name)
|
template = Playlists(session, template_name)
|
||||||
|
if not template or not template.id:
|
||||||
|
return
|
||||||
|
|
||||||
template.is_template = True
|
template.is_template = True
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|||||||
@ -1360,7 +1360,7 @@ class PlaylistTab(QTableWidget):
|
|||||||
return playlistrow_id
|
return playlistrow_id
|
||||||
|
|
||||||
def _get_playlistrow_object(self, session: scoped_session,
|
def _get_playlistrow_object(self, session: scoped_session,
|
||||||
row: int) -> int:
|
row: int) -> PlaylistRows:
|
||||||
"""Return the playlistrow object associated with this row"""
|
"""Return the playlistrow object associated with this row"""
|
||||||
|
|
||||||
playlistrow_id = (self.item(row, USERDATA).data(self.PLAYLISTROW_ID))
|
playlistrow_id = (self.item(row, USERDATA).data(self.PLAYLISTROW_ID))
|
||||||
|
|||||||
@ -35,9 +35,9 @@ parent_dir = os.path.dirname(source_dir)
|
|||||||
|
|
||||||
name_and_tags: List[str] = []
|
name_and_tags: List[str] = []
|
||||||
tags_not_name: List[str] = []
|
tags_not_name: List[str] = []
|
||||||
multiple_similar: List[str] = []
|
# multiple_similar: List[str] = []
|
||||||
no_match: List[str] = []
|
no_match: List[str] = []
|
||||||
possibles: List[str] = []
|
# possibles: List[str] = []
|
||||||
no_match: int = 0
|
no_match: int = 0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,17 +0,0 @@
|
|||||||
from PyQt5.QtCore import Qt
|
|
||||||
from PyQt5.QtGui import QFontMetrics, QPainter
|
|
||||||
from PyQt5.QtWidgets import QLabel
|
|
||||||
|
|
||||||
|
|
||||||
# class ElideLabel(QLabel):
|
|
||||||
# """
|
|
||||||
# From https://stackoverflow.com/questions/11446478/
|
|
||||||
# pyside-pyqt-truncate-text-in-qlabel-based-on-minimumsize
|
|
||||||
# """
|
|
||||||
#
|
|
||||||
# def paintEvent(self, event):
|
|
||||||
# painter = QPainter(self)
|
|
||||||
# metrics = QFontMetrics(self.font())
|
|
||||||
# elided = metrics.elidedText(self.text(), Qt.ElideRight, self.width())
|
|
||||||
#
|
|
||||||
# painter.drawText(self.rect(), self.alignment(), elided)
|
|
||||||
@ -70,11 +70,4 @@ def do_command(command):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def quick_test():
|
|
||||||
"""Example list of commands."""
|
|
||||||
do_command('Help: Command=Help')
|
|
||||||
do_command('Help: Command="GetInfo"')
|
|
||||||
# do_command('SetPreference: Name=GUI/Theme Value=classic Reload=1')
|
|
||||||
|
|
||||||
|
|
||||||
do_command('Import2: Filename=/home/kae/git/musicmuster/archive/boot.flac')
|
do_command('Import2: Filename=/home/kae/git/musicmuster/archive/boot.flac')
|
||||||
|
|||||||
@ -45,5 +45,6 @@ mypy_path = "/home/kae/.cache/pypoetry/virtualenvs/musicmuster-oWgGw1IG-py3.9:/h
|
|||||||
plugins = "sqlalchemy.ext.mypy.plugin"
|
plugins = "sqlalchemy.ext.mypy.plugin"
|
||||||
|
|
||||||
[tool.vulture]
|
[tool.vulture]
|
||||||
exclude = ["migrations"]
|
exclude = ["migrations", "app/ui", "archive"]
|
||||||
paths = ["app"]
|
paths = ["app"]
|
||||||
|
make_whitelist = true
|
||||||
|
|||||||
16
test.py
16
test.py
@ -2,28 +2,28 @@
|
|||||||
|
|
||||||
from PyQt5 import QtGui, QtWidgets
|
from PyQt5 import QtGui, QtWidgets
|
||||||
|
|
||||||
class TabBar(QtWidgets.QTabWidget):
|
class TabBar(QtWidgets.QTabBar):
|
||||||
def paintEvent(self, event):
|
def paintEvent(self, event):
|
||||||
painter = QtGui.QStylePainter(self)
|
painter = QtWidgets.QStylePainter(self)
|
||||||
option = QtGui.QStyleOptionTab()
|
option = QtWidgets.QStyleOptionTab()
|
||||||
for index in range(self.count()):
|
for index in range(self.count()):
|
||||||
self.initStyleOption(option, index)
|
self.initStyleOption(option, index)
|
||||||
bgcolor = QtGui.QColor(self.tabText(index))
|
bgcolor = QtGui.QColor(self.tabText(index))
|
||||||
option.palette.setColor(QtGui.QPalette.Window, bgcolor)
|
option.palette.setColor(QtGui.QPalette.Window, bgcolor)
|
||||||
painter.drawControl(QtGui.QStyle.CE_TabBarTabShape, option)
|
painter.drawControl(QtWidgets.QStyle.CE_TabBarTabShape, option)
|
||||||
painter.drawControl(QtGui.QStyle.CE_TabBarTabLabel, option)
|
painter.drawControl(QtWidgets.QStyle.CE_TabBarTabLabel, option)
|
||||||
|
|
||||||
class Window(QtWidgets.QTabWidget):
|
class Window(QtWidgets.QTabWidget):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
QtGui.QTabWidget.__init__(self)
|
QtWidgets.QTabWidget.__init__(self)
|
||||||
self.setTabBar(TabBar(self))
|
self.setTabBar(TabBar(self))
|
||||||
for color in 'tomato orange yellow lightgreen skyblue plum'.split():
|
for color in 'tomato orange yellow lightgreen skyblue plum'.split():
|
||||||
self.addTab(QtGui.QWidget(self), color)
|
self.addTab(QtWidgets.QWidget(self), color)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
app = QtGui.QApplication(sys.argv)
|
app = QtWidgets.QApplication(sys.argv)
|
||||||
window = Window()
|
window = Window()
|
||||||
window.resize(420, 200)
|
window.resize(420, 200)
|
||||||
window.show()
|
window.show()
|
||||||
|
|||||||
@ -5,7 +5,6 @@ from app.models import (
|
|||||||
Notes,
|
Notes,
|
||||||
Playdates,
|
Playdates,
|
||||||
Playlists,
|
Playlists,
|
||||||
PlaylistTracks,
|
|
||||||
Tracks,
|
Tracks,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -205,11 +204,11 @@ def test_playlist_notes(session):
|
|||||||
# We need two notes
|
# We need two notes
|
||||||
note1_text = "note1 text"
|
note1_text = "note1 text"
|
||||||
note1_row = 11
|
note1_row = 11
|
||||||
note1 = Notes(session, playlist.id, note1_row, note1_text)
|
_ = Notes(session, playlist.id, note1_row, note1_text)
|
||||||
|
|
||||||
note2_text = "note2 text"
|
note2_text = "note2 text"
|
||||||
note2_row = 19
|
note2_row = 19
|
||||||
note2 = Notes(session, playlist.id, note2_row, note2_text)
|
_ = Notes(session, playlist.id, note2_row, note2_text)
|
||||||
|
|
||||||
notes = playlist.notes
|
notes = playlist.notes
|
||||||
assert note1_text in [n.note for n in notes]
|
assert note1_text in [n.note for n in notes]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user