headers
This commit is contained in:
parent
f5db5cf89d
commit
cb40fd0a57
@ -32,6 +32,7 @@ from components.LyricsWindow import LyricsWindow
|
||||
from components.AddToPlaylistWindow import AddToPlaylistWindow
|
||||
from components.MetadataWindow import MetadataWindow
|
||||
|
||||
from components.ResizableHeaderView import ResizableHeaderView
|
||||
from main import Worker
|
||||
from utils.batch_delete_filepaths_from_database import (
|
||||
batch_delete_filepaths_from_database,
|
||||
@ -93,6 +94,9 @@ class MusicTable(QTableView):
|
||||
"TDRC",
|
||||
None,
|
||||
]
|
||||
# Header stuff...
|
||||
header = ResizableHeaderView(Qt.Horizontal, self)
|
||||
self.setHorizontalHeader(header)
|
||||
# hide the id column
|
||||
self.hideColumn(0)
|
||||
# db names of headers
|
||||
@ -113,8 +117,9 @@ class MusicTable(QTableView):
|
||||
self.setup_keyboard_shortcuts()
|
||||
|
||||
def resizeEvent(self, e: typing.Optional[QResizeEvent]) -> None:
|
||||
assert e is not None
|
||||
return super().resizeEvent(e)
|
||||
if e is None:
|
||||
raise Exception
|
||||
super().resizeEvent(e)
|
||||
|
||||
def contextMenuEvent(self, a0):
|
||||
"""Right-click context menu for rows in Music Table"""
|
||||
|
||||
55
components/ResizableHeaderView.py
Normal file
55
components/ResizableHeaderView.py
Normal file
@ -0,0 +1,55 @@
|
||||
from PyQt5.QtWidgets import QHeaderView
|
||||
from PyQt5.QtCore import Qt
|
||||
import configparser
|
||||
|
||||
|
||||
class ResizableHeaderView(QHeaderView):
|
||||
def __init__(self, orientation, parent=None):
|
||||
super().__init__(orientation, parent)
|
||||
self.config = configparser.ConfigParser()
|
||||
self.config.read("config.ini")
|
||||
# FIXME: last column needs to not leave the screen when other columns become big...
|
||||
# howwww
|
||||
table_view_column_widths = str(self.config["table"]["column_widths"]).split(",")
|
||||
for i in range(parent.model.columnCount() - 1):
|
||||
self.setColumnWidth(i, int(table_view_column_widths[i]))
|
||||
self.setSectionsMovable(True)
|
||||
self.setSectionResizeMode(QHeaderView.Interactive)
|
||||
self.setStretchLastSection(True)
|
||||
self.min_section_size = 50
|
||||
self.default_column_proportions = [1, 1, 1, 1, 1, 1, 1, 1]
|
||||
|
||||
def set_default_column_proportions(self, proportions):
|
||||
self.default_column_proportions = proportions
|
||||
|
||||
def resizeEvent(self, e):
|
||||
super().resizeEvent(e)
|
||||
self.adjust_section_sizes()
|
||||
|
||||
def sectionResized(self, logicalIndex, oldSize, newSize):
|
||||
super().sectionResized(logicalIndex, oldSize, newSize)
|
||||
self.adjust_section_sizes()
|
||||
|
||||
def adjust_section_sizes(self):
|
||||
total_width = self.width()
|
||||
column_count = self.count()
|
||||
if not self.default_column_proportions:
|
||||
self.default_column_proportions = [1] * column_count
|
||||
|
||||
# Calculate the total proportion
|
||||
total_proportion = sum(self.default_column_proportions)
|
||||
|
||||
# Calculate sizes based on proportions
|
||||
sizes = [
|
||||
max(self.min_section_size, int(total_width * prop / total_proportion))
|
||||
for prop in self.default_column_proportions
|
||||
]
|
||||
|
||||
# Adjust sizes to fit exactly
|
||||
extra = total_width - sum(sizes)
|
||||
for i in range(abs(extra)):
|
||||
sizes[i % column_count] += 1 if extra > 0 else -1
|
||||
|
||||
# Apply sizes
|
||||
for i in range(column_count):
|
||||
self.resizeSection(i, sizes[i])
|
||||
@ -9,3 +9,4 @@ from .AddToPlaylistWindow import AddToPlaylistWindow
|
||||
from .CreatePlaylistWindow import CreatePlaylistWindow
|
||||
from .PlaylistsPane import PlaylistsPane
|
||||
from .ExportPlaylistWindow import ExportPlaylistWindow
|
||||
from .ResizableHeaderView import ResizableHeaderView
|
||||
|
||||
12
main.py
12
main.py
@ -46,6 +46,7 @@ from components import (
|
||||
AudioVisualizer,
|
||||
CreatePlaylistWindow,
|
||||
ExportPlaylistWindow,
|
||||
ResizableHeaderView,
|
||||
)
|
||||
|
||||
# Create ui.py file from Qt Designer
|
||||
@ -237,7 +238,6 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
)
|
||||
# FIXME: this should delete the album art for the current song - not all selected songs
|
||||
# move functionality to remove album for selected songs to the batch metadata editor
|
||||
|
||||
# self.albumGraphicsView.albumArtDeleted.connect(
|
||||
# self.delete_album_art_for_selected_songs
|
||||
# )
|
||||
@ -246,15 +246,6 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self
|
||||
) # for drag & drop functionality
|
||||
self.tableView.handleProgressSignal.connect(self.handle_progress)
|
||||
# set column widths
|
||||
# FIXME: last column needs to not leave the screen when other columns become big...
|
||||
# howwww
|
||||
table_view_column_widths = str(self.config["table"]["column_widths"]).split(",")
|
||||
for i in range(self.tableView.model.columnCount() - 1):
|
||||
self.tableView.setColumnWidth(i, int(table_view_column_widths[i]))
|
||||
# dont extend last column past table view border
|
||||
self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||
self.tableView.horizontalHeader().setStretchLastSection(True)
|
||||
|
||||
def reload_config(self) -> None:
|
||||
"""does what it says"""
|
||||
@ -276,6 +267,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
# Save the config
|
||||
with open("config.ini", "w") as configfile:
|
||||
self.config.write(configfile)
|
||||
if a0 is not None:
|
||||
super().closeEvent(a0)
|
||||
|
||||
def show_status_bar_message(self, message: str, timeout: int | None = None) -> None:
|
||||
|
||||
4
ui.py
4
ui.py
@ -2,7 +2,7 @@
|
||||
|
||||
# Form implementation generated from reading ui file 'ui.ui'
|
||||
#
|
||||
# Created by: PyQt5 UI code generator 5.15.10
|
||||
# Created by: PyQt5 UI code generator 5.15.9
|
||||
#
|
||||
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
|
||||
# run again. Do not edit this file unless you know what you are doing.
|
||||
@ -160,7 +160,7 @@ class Ui_MainWindow(object):
|
||||
self.verticalLayout_3.setStretch(2, 1)
|
||||
MainWindow.setCentralWidget(self.centralwidget)
|
||||
self.menubar = QtWidgets.QMenuBar(MainWindow)
|
||||
self.menubar.setGeometry(QtCore.QRect(0, 0, 1152, 41))
|
||||
self.menubar.setGeometry(QtCore.QRect(0, 0, 1152, 21))
|
||||
self.menubar.setObjectName("menubar")
|
||||
self.menuFile = QtWidgets.QMenu(self.menubar)
|
||||
self.menuFile.setObjectName("menuFile")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user