Typing and other cleanups
This commit is contained in:
parent
73bb4b3a7f
commit
5d50ebf3aa
@ -5,21 +5,17 @@ import smtplib
|
||||
import ssl
|
||||
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 datetime import datetime
|
||||
from email.message import EmailMessage
|
||||
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 tinytag import TinyTag # type: ignore
|
||||
from typing import Optional
|
||||
# from typing import Dict, Optional, Union
|
||||
from typing import Dict, Union
|
||||
from typing import Any, Dict, Optional, Union
|
||||
|
||||
|
||||
def ask_yes_no(title: str, question: str) -> bool:
|
||||
@ -82,7 +78,7 @@ def get_audio_segment(path: str) -> Optional[AudioSegment]:
|
||||
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.
|
||||
"""
|
||||
|
||||
@ -212,7 +212,7 @@ class Playlists(Base):
|
||||
def __init__(self, session: scoped_session, name: str):
|
||||
self.name = name
|
||||
session.add(self)
|
||||
session.commit()
|
||||
session.flush()
|
||||
|
||||
def close(self, session: scoped_session) -> None:
|
||||
"""Mark playlist as unloaded"""
|
||||
@ -233,10 +233,15 @@ class Playlists(Base):
|
||||
session: scoped_session,
|
||||
template: "Playlists",
|
||||
playlist_name: str) \
|
||||
-> "Playlists":
|
||||
-> Optional["Playlists"]:
|
||||
"""Create a new playlist from template"""
|
||||
|
||||
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)
|
||||
|
||||
return playlist
|
||||
@ -334,6 +339,9 @@ class Playlists(Base):
|
||||
"""Save passed playlist as new template"""
|
||||
|
||||
template = Playlists(session, template_name)
|
||||
if not template or not template.id:
|
||||
return
|
||||
|
||||
template.is_template = True
|
||||
session.commit()
|
||||
|
||||
|
||||
@ -1360,7 +1360,7 @@ class PlaylistTab(QTableWidget):
|
||||
return playlistrow_id
|
||||
|
||||
def _get_playlistrow_object(self, session: scoped_session,
|
||||
row: int) -> int:
|
||||
row: int) -> PlaylistRows:
|
||||
"""Return the playlistrow object associated with this row"""
|
||||
|
||||
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] = []
|
||||
tags_not_name: List[str] = []
|
||||
multiple_similar: List[str] = []
|
||||
# multiple_similar: List[str] = []
|
||||
no_match: List[str] = []
|
||||
possibles: List[str] = []
|
||||
# possibles: List[str] = []
|
||||
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
|
||||
|
||||
|
||||
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')
|
||||
|
||||
@ -45,5 +45,6 @@ mypy_path = "/home/kae/.cache/pypoetry/virtualenvs/musicmuster-oWgGw1IG-py3.9:/h
|
||||
plugins = "sqlalchemy.ext.mypy.plugin"
|
||||
|
||||
[tool.vulture]
|
||||
exclude = ["migrations"]
|
||||
exclude = ["migrations", "app/ui", "archive"]
|
||||
paths = ["app"]
|
||||
make_whitelist = true
|
||||
|
||||
16
test.py
16
test.py
@ -2,28 +2,28 @@
|
||||
|
||||
from PyQt5 import QtGui, QtWidgets
|
||||
|
||||
class TabBar(QtWidgets.QTabWidget):
|
||||
class TabBar(QtWidgets.QTabBar):
|
||||
def paintEvent(self, event):
|
||||
painter = QtGui.QStylePainter(self)
|
||||
option = QtGui.QStyleOptionTab()
|
||||
painter = QtWidgets.QStylePainter(self)
|
||||
option = QtWidgets.QStyleOptionTab()
|
||||
for index in range(self.count()):
|
||||
self.initStyleOption(option, index)
|
||||
bgcolor = QtGui.QColor(self.tabText(index))
|
||||
option.palette.setColor(QtGui.QPalette.Window, bgcolor)
|
||||
painter.drawControl(QtGui.QStyle.CE_TabBarTabShape, option)
|
||||
painter.drawControl(QtGui.QStyle.CE_TabBarTabLabel, option)
|
||||
painter.drawControl(QtWidgets.QStyle.CE_TabBarTabShape, option)
|
||||
painter.drawControl(QtWidgets.QStyle.CE_TabBarTabLabel, option)
|
||||
|
||||
class Window(QtWidgets.QTabWidget):
|
||||
def __init__(self):
|
||||
QtGui.QTabWidget.__init__(self)
|
||||
QtWidgets.QTabWidget.__init__(self)
|
||||
self.setTabBar(TabBar(self))
|
||||
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__':
|
||||
|
||||
import sys
|
||||
app = QtGui.QApplication(sys.argv)
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
window = Window()
|
||||
window.resize(420, 200)
|
||||
window.show()
|
||||
|
||||
@ -5,7 +5,6 @@ from app.models import (
|
||||
Notes,
|
||||
Playdates,
|
||||
Playlists,
|
||||
PlaylistTracks,
|
||||
Tracks,
|
||||
)
|
||||
|
||||
@ -205,11 +204,11 @@ def test_playlist_notes(session):
|
||||
# We need two notes
|
||||
note1_text = "note1 text"
|
||||
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_row = 19
|
||||
note2 = Notes(session, playlist.id, note2_row, note2_text)
|
||||
_ = Notes(session, playlist.id, note2_row, note2_text)
|
||||
|
||||
notes = playlist.notes
|
||||
assert note1_text in [n.note for n in notes]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user