Typing and mypy fixes

This commit is contained in:
Keith Edmunds 2023-10-15 21:04:54 +01:00
parent 3513c32a62
commit 9ac2911a55
6 changed files with 614 additions and 603 deletions

View File

@ -19,6 +19,7 @@ from typing import (
cast,
List,
Optional,
Sequence,
)
from PyQt6.QtCore import (
@ -33,6 +34,7 @@ from PyQt6.QtCore import (
QTimer,
)
from PyQt6.QtGui import (
QCloseEvent,
QColor,
QFont,
QMouseEvent,
@ -119,9 +121,12 @@ class CartButton(QPushButton):
f"path={self.path}, is_playing={self.is_playing}>"
)
def event(self, event: QEvent) -> bool:
def event(self, event: Optional[QEvent]) -> bool:
"""Allow right click even when button is disabled"""
if not event:
return False
if event.type() == QEvent.Type.MouseButtonRelease:
mouse_event = cast(QMouseEvent, event)
if mouse_event.button() == Qt.MouseButton.RightButton:
@ -130,7 +135,7 @@ class CartButton(QPushButton):
return super().event(event)
def resizeEvent(self, event: QResizeEvent) -> None:
def resizeEvent(self, event: Optional[QResizeEvent]) -> None:
"""Resize progess bar when button size changes"""
self.pgb.setGeometry(0, 0, self.width(), 10)
@ -534,9 +539,12 @@ class Window(QMainWindow, Ui_MainWindow):
# Clear the search bar
self.search_playlist_clear()
def closeEvent(self, event: QEvent) -> None:
def closeEvent(self, event: Optional[QCloseEvent]) -> None:
"""Handle attempt to close main window"""
if not event:
return
# Don't allow window to close when a track is playing
if self.playing:
event.ignore()
@ -1038,11 +1046,11 @@ class Window(QMainWindow, Ui_MainWindow):
_ = self.create_playlist_tab(session, playlist)
# Set active tab
record = Settings.get_int_settings(session, "active_tab")
if record and record.f_int >= 0:
if record.f_int and record.f_int >= 0:
self.tabPlaylist.setCurrentIndex(record.f_int)
def move_playlist_rows(
self, session: scoped_session, playlistrows: List[PlaylistRows]
self, session: scoped_session, playlistrows: Sequence[PlaylistRows]
) -> None:
"""
Move passed playlist rows to another playlist
@ -1105,7 +1113,7 @@ class Window(QMainWindow, Ui_MainWindow):
visible_tab.save_playlist(session)
# Disable sort undo
self.sort_undo = None
self.sort_undo = []
# Update destination playlist_tab if visible (if not visible, it
# will be re-populated when it is opened)

View File

@ -164,16 +164,19 @@ class PlaylistTab(QTableWidget):
self.setVerticalScrollMode(QAbstractItemView.ScrollMode.ScrollPerPixel)
self.setRowCount(0)
self.setColumnCount(len(columns))
self.v_header = self.verticalHeader()
self.v_header.setMinimumSectionSize(Config.MINIMUM_ROW_HEIGHT)
self.horizontalHeader().setStretchLastSection(True)
# Header row
self.h_header = self.horizontalHeader()
for idx in [a for a in range(len(columns))]:
item = QTableWidgetItem()
self.setHorizontalHeaderItem(idx, item)
self.horizontalHeader().setMinimumSectionSize(0)
if self.h_header:
self.h_header.setStretchLastSection(True)
self.h_header.setMinimumSectionSize(0)
# Set column headings sorted by idx
self.v_header = self.verticalHeader()
if self.v_header:
self.v_header.setMinimumSectionSize(Config.MINIMUM_ROW_HEIGHT)
self.setHorizontalHeaderLabels(
[
a.heading
@ -215,13 +218,16 @@ class PlaylistTab(QTableWidget):
# ########## Events other than cell editing ##########
def dropEvent(self, event: QDropEvent) -> None:
def dropEvent(self, event: Optional[QDropEvent]) -> None:
"""
Handle drag/drop of rows
https://stackoverflow.com/questions/26227885/drag-and-drop-rows-within-qtablewidget
"""
if not event:
return
if not event.source() == self:
return # We don't accept external drops
@ -267,7 +273,7 @@ class PlaylistTab(QTableWidget):
# Reset drag mode to allow row selection by dragging
self.setDragEnabled(False)
# Disable sort undo
self.sort_undo = None
self.sort_undo = []
with Session() as session:
self.save_playlist(session)
@ -1103,7 +1109,7 @@ class PlaylistTab(QTableWidget):
)
if sort_menu:
sort_menu.setEnabled(self._sortable())
self._add_context_menu("Undo sort", self._sort_undo, self.sort_undo is None)
self._add_context_menu("Undo sort", self._sort_undo, not bool(self.sort_undo))
# Build submenu
@ -2123,9 +2129,7 @@ class PlaylistTab(QTableWidget):
stackprinter.format(),
)
# stackprinter.show(add_summary=True, style="darkbg")
print(
f"playists:_set_row_note_colour() called on track row ({row_number=}"
)
print(f"playists:_set_row_note_colour() called on track row ({row_number=}")
return
# Set colour

View File

@ -1,14 +1,12 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'app/ui/dlg_Cart.ui'
# Form implementation generated from reading ui file 'dlg_Cart.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
# Created by: PyQt6 UI code generator 6.5.3
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_DialogCartEdit(object):
@ -17,43 +15,43 @@ class Ui_DialogCartEdit(object):
DialogCartEdit.resize(564, 148)
self.gridLayout = QtWidgets.QGridLayout(DialogCartEdit)
self.gridLayout.setObjectName("gridLayout")
self.label = QtWidgets.QLabel(DialogCartEdit)
self.label = QtWidgets.QLabel(parent=DialogCartEdit)
self.label.setMaximumSize(QtCore.QSize(56, 16777215))
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.lineEditName = QtWidgets.QLineEdit(DialogCartEdit)
self.lineEditName = QtWidgets.QLineEdit(parent=DialogCartEdit)
self.lineEditName.setInputMask("")
self.lineEditName.setObjectName("lineEditName")
self.gridLayout.addWidget(self.lineEditName, 0, 1, 1, 2)
self.chkEnabled = QtWidgets.QCheckBox(DialogCartEdit)
self.chkEnabled = QtWidgets.QCheckBox(parent=DialogCartEdit)
self.chkEnabled.setObjectName("chkEnabled")
self.gridLayout.addWidget(self.chkEnabled, 0, 3, 1, 1)
self.label_2 = QtWidgets.QLabel(DialogCartEdit)
self.label_2 = QtWidgets.QLabel(parent=DialogCartEdit)
self.label_2.setMaximumSize(QtCore.QSize(56, 16777215))
self.label_2.setObjectName("label_2")
self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
self.lblPath = QtWidgets.QLabel(DialogCartEdit)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
self.lblPath = QtWidgets.QLabel(parent=DialogCartEdit)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lblPath.sizePolicy().hasHeightForWidth())
self.lblPath.setSizePolicy(sizePolicy)
self.lblPath.setMinimumSize(QtCore.QSize(301, 41))
self.lblPath.setText("")
self.lblPath.setTextFormat(QtCore.Qt.PlainText)
self.lblPath.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.lblPath.setTextFormat(QtCore.Qt.TextFormat.PlainText)
self.lblPath.setAlignment(QtCore.Qt.AlignmentFlag.AlignLeading|QtCore.Qt.AlignmentFlag.AlignLeft|QtCore.Qt.AlignmentFlag.AlignTop)
self.lblPath.setWordWrap(True)
self.lblPath.setObjectName("lblPath")
self.gridLayout.addWidget(self.lblPath, 1, 1, 1, 1)
self.btnFile = QtWidgets.QPushButton(DialogCartEdit)
self.btnFile = QtWidgets.QPushButton(parent=DialogCartEdit)
self.btnFile.setMaximumSize(QtCore.QSize(31, 16777215))
self.btnFile.setObjectName("btnFile")
self.gridLayout.addWidget(self.btnFile, 1, 3, 1, 1)
spacerItem = QtWidgets.QSpacerItem(116, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
spacerItem = QtWidgets.QSpacerItem(116, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
self.gridLayout.addItem(spacerItem, 2, 1, 1, 1)
self.buttonBox = QtWidgets.QDialogButtonBox(DialogCartEdit)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox = QtWidgets.QDialogButtonBox(parent=DialogCartEdit)
self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok)
self.buttonBox.setObjectName("buttonBox")
self.gridLayout.addWidget(self.buttonBox, 2, 2, 1, 2)
self.label.setBuddy(self.lineEditName)

View File

@ -1,10 +1,34 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'ui/playlist.ui'
# Form implementation generated from reading ui file 'dlg_SelectPlaylist.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
# Created by: PyQt6 UI code generator 6.5.3
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_dlgSelectPlaylist(object):
def setupUi(self, dlgSelectPlaylist):
dlgSelectPlaylist.setObjectName("dlgSelectPlaylist")
dlgSelectPlaylist.resize(276, 150)
self.verticalLayout = QtWidgets.QVBoxLayout(dlgSelectPlaylist)
self.verticalLayout.setObjectName("verticalLayout")
self.lstPlaylists = QtWidgets.QListWidget(parent=dlgSelectPlaylist)
self.lstPlaylists.setObjectName("lstPlaylists")
self.verticalLayout.addWidget(self.lstPlaylists)
self.buttonBox = QtWidgets.QDialogButtonBox(parent=dlgSelectPlaylist)
self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok)
self.buttonBox.setObjectName("buttonBox")
self.verticalLayout.addWidget(self.buttonBox)
self.retranslateUi(dlgSelectPlaylist)
self.buttonBox.accepted.connect(dlgSelectPlaylist.accept) # type: ignore
self.buttonBox.rejected.connect(dlgSelectPlaylist.reject) # type: ignore
QtCore.QMetaObject.connectSlotsByName(dlgSelectPlaylist)
def retranslateUi(self, dlgSelectPlaylist):
_translate = QtCore.QCoreApplication.translate
dlgSelectPlaylist.setWindowTitle(_translate("dlgSelectPlaylist", "Dialog"))

1102
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,6 @@ mysqlclient = "^2.1.0"
mutagen = "^1.45.1"
alembic = "^1.7.5"
psutil = "^5.9.0"
PyQtWebEngine = "^5.15.5"
pydub = "^0.25.1"
types-psutil = "^5.8.22"
python-slugify = "^6.1.2"