From cf9722516fc49607e44cc5688e7b2fffe6be3e50 Mon Sep 17 00:00:00 2001 From: Salt Date: Sat, 7 Mar 2020 19:29:00 -0600 Subject: [PATCH] Getting closer, got an album view... ish --- badwitch.py | 69 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 13 deletions(-) diff --git a/badwitch.py b/badwitch.py index 77280c1..3ac4e81 100755 --- a/badwitch.py +++ b/badwitch.py @@ -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):