Getting closer, got an album view... ish

This commit is contained in:
Salt 2020-03-07 19:29:00 -06:00
parent 58f7cacec9
commit cf9722516f

View File

@ -13,7 +13,7 @@ from pathlib import Path
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import (
QAction, qApp, QApplication, QMainWindow, QWidget,
QPushButton,
QFrame, QLabel, QPushButton,
QGroupBox, QGridLayout, QHBoxLayout, QVBoxLayout
)
import argparse
@ -143,6 +143,17 @@ class Library:
except (KeyboardInterrupt, EOFError):
logging.debug('Interrupt received, exiting')
class AlbumWidget(QFrame):
def __init__(self, album, albumcontent):
super().__init__()
self.album = albumcontent
self.title = album
self.initUI()
def initUI(self):
self.label = QLabel(self.title, self)
pass
class BadWitchGUI(QMainWindow):
# A Qt5 GUI
def __init__(self, badwitch, library):
@ -153,16 +164,30 @@ class BadWitchGUI(QMainWindow):
# Set central widget to something blank
# We don't care because we can access it later via method
self.setCentralWidget(QWidget())
# Init actions
# Initialize our UI
self.initActions()
# Init UI
self.initUI()
# Populate it
self.populateAlbums()
# Statusbar
self.statusBar().showMessage('Ready')
def initActions(self):
self.saveAct = QAction(QIcon.fromTheme('document-save'), '&Save', self)
saveAct = self.saveAct
saveAct.setShortcut('Ctrl+S')
saveAct.setStatusTip('Save outstanding library changes')
saveAct.triggered.connect(self.saveLib)
self.exitAct = QAction(QIcon.fromTheme('application-exit'), '&Exit', self)
self.exitAct.setShortcut('Ctrl+Q')
self.exitAct.setStatusTip('Exit Bad Witch')
self.exitAct.triggered.connect(qApp.quit)
exitAct = self.exitAct
exitAct.setShortcut('Ctrl+Q')
exitAct.setStatusTip('Exit Bad Witch')
exitAct.triggered.connect(qApp.quit)
self.refreshAct = QAction(QIcon.fromTheme('view-refresh'), 'Reload Library', self)
refreshAct = self.refreshAct
refreshAct.setShortcut('Ctrl+R')
refreshAct.setStatusTip('Reload albums from library')
refreshAct.triggered.connect(self.populateAlbums)
def initUI(self):
# Main window shenanigans
@ -172,8 +197,11 @@ class BadWitchGUI(QMainWindow):
# Menubar
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(self.saveAct)
fileMenu.addSeparator()
fileMenu.addAction(self.exitAct)
viewMenu = menubar.addMenu('&View')
viewMenu.addAction(self.refreshAct)
# Container box
self.containerBox = QGridLayout()
@ -183,20 +211,35 @@ class BadWitchGUI(QMainWindow):
# Song browser box
self.libraryGroup = QGroupBox()
self.libraryBox = QVBoxLayout()
libraryBox = self.libraryBox
libraryBox.addWidget(self.libraryGroup)
containerBox.addLayout(libraryBox, 0, 0)
self.libraryGroup.setLayout(self.libraryBox)
containerBox.addWidget(self.libraryGroup, 0, 0)
# Queue box
self.queueGroup = QGroupBox()
self.queueBox = QVBoxLayout()
queueBox = self.queueBox
testButton2 = QPushButton("queue")
queueBox.addWidget(self.queueGroup)
containerBox.addLayout(queueBox, 0, 1, 0, 2)
self.queueGroup.setLayout(self.queueBox)
containerBox.addWidget(self.queueGroup, 0, 1, 0, 2)
# Show
self.show()
def populateAlbums(self):
statusBar = self.statusBar()
# Remove all albums
statusBar.showMessage('Reloading library')
for widget in self.libraryGroup.findChildren(AlbumWidget):
widget.deleteLater()
self.lib.load()
for album, albumcontent in self.lib.albums.items():
albumWidget = AlbumWidget(album, albumcontent)
self.libraryBox.addWidget(albumWidget)
statusBar.showMessage('Library reloaded')
def saveLib(self):
statusBar = self.statusBar()
statusBar.showMessage('Saving library')
self.lib.save()
statusBar.showMessage('Library saved')
class BadWitch:
# Our program
def __init__(self):