Update the GUI a bit more, make things look nicer

This commit is contained in:
Raoul Snyman 2021-06-17 14:16:23 -07:00
parent 7304fa15cb
commit 2c04c298e3
4 changed files with 84 additions and 93 deletions

View File

@ -1,10 +1,18 @@
from PyQt5 import QtWidgets import qtawesome as qta
from PyQt5 import QtGui, QtWidgets
from playtypus.mainwindow import MainWindow from playtypus.mainwindow import MainWindow
def main(): def main():
"""Main""" """Main"""
app = QtWidgets.QApplication([]) app = QtWidgets.QApplication([])
# Set up icon colours
palette = app.palette()
qta.set_defaults(color=palette.color(QtGui.QPalette.Active,
QtGui.QPalette.WindowText),
color_disabled=palette.color(QtGui.QPalette.Disabled,
QtGui.QPalette.WindowText))
# Create the main window and run the app
main_window = MainWindow() main_window = MainWindow()
main_window.show() main_window.show()
return app.exec() return app.exec()

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from funksnake import Funkwhale from funksnake import Funkwhale
from PyQt5 import QtCore, QtWidgets, QtNetwork from PyQt5 import QtCore, QtWidgets
from playtypus.ui_mainwindow import UiMainWindow from playtypus.ui_mainwindow import UiMainWindow
from playtypus.settingsdialog import SettingsDialog from playtypus.settingsdialog import SettingsDialog
@ -12,17 +12,19 @@ class MainWindow(QtWidgets.QMainWindow, UiMainWindow):
super().__init__(parent) super().__init__(parent)
self.setup_ui() self.setup_ui()
self.settingsAction.triggered.connect(self.on_settings_action_triggered) self.settingsAction.triggered.connect(self.on_settings_action_triggered)
self.settings = QtCore.QSettings('info.snyman.pyfunkwhale', 'PyFunkwhale') self.settings = QtCore.QSettings('info.snyman.playtypus', 'Playtypus')
self.network_manager = QtNetwork.QNetworkAccessManager()
self.settings_dialog = SettingsDialog(self) self.settings_dialog = SettingsDialog(self)
self.funkwhale = None self.funkwhale = None
self.threads = {} self.threads = {}
# Check for Funkwhale settings, and load all the things
if self.settings.contains('funkwhale/server_url'): if self.settings.contains('funkwhale/server_url'):
self.setup_funkwhale(self.settings.value('funkwhale/server_url'), self.setup_funkwhale(self.settings.value('funkwhale/server_url'),
self.settings.value('funkwhale/username', None), self.settings.value('funkwhale/username', None),
self.settings.value('funkwhale/password', None)) self.settings.value('funkwhale/password', None))
self.load_albums()
# self.load_artists() @property
def is_funkwhale_active(self):
return self.funkwhale and self.funkwhale.token
def run_thread(self, worker, thread_name): def run_thread(self, worker, thread_name):
""" """
@ -98,16 +100,19 @@ class MainWindow(QtWidgets.QMainWindow, UiMainWindow):
self.funkwhale = Funkwhale(server_url) self.funkwhale = Funkwhale(server_url)
if username and password: if username and password:
self.funkwhale.login(username, password) self.funkwhale.login(username, password)
if self.is_funkwhale_active:
self.load_albums()
# self.load_artists()
def load_albums(self): def load_albums(self):
if not self.funkwhale or not self.funkwhale.token: if not self.is_funkwhale_active:
return return
worker = AlbumWorker() worker = AlbumWorker()
worker.window = self worker.window = self
self.run_thread(worker, 'get-albums') self.run_thread(worker, 'get-albums')
def load_artists(self): def load_artists(self):
if not self.funkwhale or not self.funkwhale.token: if not self.is_funkwhale_active:
return return
self.artistListWidget.clear() self.artistListWidget.clear()
for artist in self.funkwhale.artists.list()['results']: for artist in self.funkwhale.artists.list()['results']:
@ -117,7 +122,8 @@ class MainWindow(QtWidgets.QMainWindow, UiMainWindow):
self.settings_dialog.server_url = self.settings.value('funkwhale/server_url', '') self.settings_dialog.server_url = self.settings.value('funkwhale/server_url', '')
self.settings_dialog.username = self.settings.value('funkwhale/username', '') self.settings_dialog.username = self.settings.value('funkwhale/username', '')
self.settings_dialog.password = self.settings.value('funkwhale/password', '') self.settings_dialog.password = self.settings.value('funkwhale/password', '')
if self.settings_dialog.exec() == QtWidgets.QDialog.Accepted: if self.settings_dialog.exec() == QtWidgets.QDialog.Accepted \
and self.settings.value('funkwhale/server_url', '') != self.settings_dialog.server_url:
self.settings.setValue('funkwhale/server_url', self.settings_dialog.server_url) self.settings.setValue('funkwhale/server_url', self.settings_dialog.server_url)
self.settings.setValue('funkwhale/username', self.settings_dialog.username) self.settings.setValue('funkwhale/username', self.settings_dialog.username)
self.settings.setValue('funkwhale/password', self.settings_dialog.password) self.settings.setValue('funkwhale/password', self.settings_dialog.password)

View File

@ -49,6 +49,7 @@ class AlbumWorker(ThreadWorker):
""" """
A thread worker to fetch the album art A thread worker to fetch the album art
""" """
ALBUM_TEMPLATE = "{title}\n{artist}\n{year}"
window = None window = None
def start(self): def start(self):
@ -58,10 +59,16 @@ class AlbumWorker(ThreadWorker):
return return
self.window.albumListWidget.clear() self.window.albumListWidget.clear()
for album in self.window.funkwhale.albums.list()['results']: for album in self.window.funkwhale.albums.list()['results']:
album_item = QtWidgets.QListWidgetItem(album['title']) details = {
'title': album['title'],
'year': album['release_date'][:4] if album.get('release_date') else '',
'artist': album['artist']['name']
}
album_item = QtWidgets.QListWidgetItem(self.ALBUM_TEMPLATE.format(**details))
self.window.albumListWidget.addItem(album_item) self.window.albumListWidget.addItem(album_item)
artwork_worker = AlbumArtWorker() artwork_worker = AlbumArtWorker()
artwork_worker.album_item = album_item artwork_worker.album_item = album_item
artwork_worker.artwork_url = album['cover']['urls']['medium_square_crop'] artwork_worker.artwork_url = album['cover']['urls']['medium_square_crop']
self.window.run_thread(artwork_worker, 'album-{}'.format(album['title'])) self.window.run_thread(artwork_worker, 'album-{}'.format(album['title']))
self.window.update_album_total(self.window.albumListWidget.count())
self.quit.emit() self.quit.emit()

View File

@ -20,73 +20,39 @@ class UiMainWindow(object):
self.centralLayout.setContentsMargins(0, 0, 0, 0) self.centralLayout.setContentsMargins(0, 0, 0, 0)
self.centralLayout.setSpacing(0) self.centralLayout.setSpacing(0)
self.centralLayout.setObjectName("centralLayout") self.centralLayout.setObjectName("centralLayout")
self.playbackWidget = QtWidgets.QWidget(self.centralwidget) # Playback toolbar
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) self.playbackToolBar = QtWidgets.QToolBar(self)
sizePolicy.setHorizontalStretch(0) self.playbackToolBar.setMovable(False)
sizePolicy.setVerticalStretch(0) self.playbackToolBar.setIconSize(QtCore.QSize(32, 32))
sizePolicy.setHeightForWidth(self.playbackWidget.sizePolicy().hasHeightForWidth()) self.playbackToolBar.setObjectName("playbackToolBar")
self.playbackWidget.setSizePolicy(sizePolicy) self.toggleAction = self.playbackToolBar.addAction(qta.icon("mdi.chevron-down"), '')
self.playbackWidget.setMinimumSize(QtCore.QSize(0, 36)) self.previousAction = self.playbackToolBar.addAction(qta.icon("mdi.skip-previous"), '')
self.playbackWidget.setObjectName("playbackWidget") self.playAction = self.playbackToolBar.addAction(qta.icon("mdi.play"), '')
self.playbackLayout = QtWidgets.QHBoxLayout(self.playbackWidget) self.nextAction = self.playbackToolBar.addAction(qta.icon("mdi.skip-next"), '')
self.playbackLayout.setContentsMargins(0, 0, 0, 0) self.positionLabel = QtWidgets.QLabel()
self.playbackLayout.setSpacing(0)
self.playbackLayout.setObjectName("playbackLayout")
self.toggleButton = QtWidgets.QToolButton(self.playbackWidget)
self.toggleButton.setIcon(qta.icon("mdi.chevron-down"))
self.toggleButton.setAutoRaise(True)
self.toggleButton.setObjectName("toggleButton")
self.playbackLayout.addWidget(self.toggleButton)
self.previousButton = QtWidgets.QToolButton(self.playbackWidget)
self.previousButton.setIcon(qta.icon("mdi.skip-previous"))
self.previousButton.setAutoRaise(True)
self.previousButton.setObjectName("previousButton")
self.playbackLayout.addWidget(self.previousButton)
self.playButton = QtWidgets.QToolButton(self.playbackWidget)
self.playButton.setIcon(qta.icon("mdi.play"))
self.playButton.setAutoRaise(True)
self.playButton.setObjectName("playButton")
self.playbackLayout.addWidget(self.playButton)
self.nextButton = QtWidgets.QToolButton(self.playbackWidget)
self.nextButton.setIcon(qta.icon("mdi.skip-next"))
self.nextButton.setAutoRaise(True)
self.nextButton.setObjectName("nextButton")
self.playbackLayout.addWidget(self.nextButton)
self.positionLabel = QtWidgets.QLabel(self.playbackWidget)
self.positionLabel.setAlignment(QtCore.Qt.AlignCenter) self.positionLabel.setAlignment(QtCore.Qt.AlignCenter)
self.positionLabel.setObjectName("positionLabel") self.positionLabel.setObjectName("positionLabel")
self.playbackLayout.addWidget(self.positionLabel) self.playbackToolBar.addWidget(self.positionLabel)
self.positionSlider = QtWidgets.QSlider(self.playbackWidget) self.positionSlider = QtWidgets.QSlider()
self.positionSlider.setOrientation(QtCore.Qt.Horizontal) self.positionSlider.setOrientation(QtCore.Qt.Horizontal)
self.positionSlider.setObjectName("positionSlider") self.positionSlider.setObjectName("positionSlider")
self.playbackLayout.addWidget(self.positionSlider) self.playbackToolBar.addWidget(self.positionSlider)
self.shuffleButton = QtWidgets.QToolButton(self.playbackWidget) self.shuffleAction = self.playbackToolBar.addAction(qta.icon("mdi.shuffle"), '')
self.shuffleButton.setIcon(qta.icon("mdi.shuffle")) self.repeatAction = self.playbackToolBar.addAction(qta.icon("mdi.repeat"), '')
self.shuffleButton.setAutoRaise(True) self.muteAction = self.playbackToolBar.addAction(qta.icon("mdi.volume-high"), '')
self.shuffleButton.setObjectName("shuffleButton") self.muteAction.setCheckable(True)
self.playbackLayout.addWidget(self.shuffleButton) self.volumeSlider = QtWidgets.QSlider()
self.repeatButton = QtWidgets.QToolButton(self.playbackWidget)
self.repeatButton.setIcon(qta.icon("mdi.repeat"))
self.repeatButton.setAutoRaise(True)
self.repeatButton.setObjectName("repeatButton")
self.playbackLayout.addWidget(self.repeatButton)
self.muteButton = QtWidgets.QToolButton(self.playbackWidget)
self.muteButton.setIcon(qta.icon("mdi.volume-high"))
self.muteButton.setCheckable(True)
self.muteButton.setAutoRaise(True)
self.muteButton.setObjectName("muteButton")
self.playbackLayout.addWidget(self.muteButton)
self.volumeSlider = QtWidgets.QSlider(self.playbackWidget)
self.volumeSlider.setOrientation(QtCore.Qt.Horizontal) self.volumeSlider.setOrientation(QtCore.Qt.Horizontal)
self.volumeSlider.setObjectName("volumeSlider") self.volumeSlider.setObjectName("volumeSlider")
self.playbackLayout.addWidget(self.volumeSlider) self.playbackToolBar.addWidget(self.volumeSlider)
self.menuButton = QtWidgets.QToolButton(self.playbackWidget) self.mainMenu = QtWidgets.QMenu()
self.menuButton.setIcon(qta.icon("mdi.menu")) self.settingsAction = self.mainMenu.addAction(qta.icon('mdi.application-settings'), '')
self.menuButton.setPopupMode(QtWidgets.QToolButton.DelayedPopup) self.menuAction = self.playbackToolBar.addAction(qta.icon("mdi.menu"), '')
self.menuButton.setAutoRaise(True) self.menuAction.setMenu(self.mainMenu)
self.menuButton.setObjectName("menuButton") menuButton = self.playbackToolBar.widgetForAction(self.menuAction)
self.playbackLayout.addWidget(self.menuButton) self.menuAction.triggered.connect(menuButton.showMenu)
self.centralLayout.addWidget(self.playbackWidget) self.addToolBar(self.playbackToolBar)
# Splitter and main components
self.splitter = QtWidgets.QSplitter(self.centralwidget) self.splitter = QtWidgets.QSplitter(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
@ -97,6 +63,7 @@ class UiMainWindow(object):
self.splitter.setHandleWidth(1) self.splitter.setHandleWidth(1)
self.splitter.setObjectName("splitter") self.splitter.setObjectName("splitter")
self.viewListWidget = QtWidgets.QListWidget(self.splitter) self.viewListWidget = QtWidgets.QListWidget(self.splitter)
self.viewListWidget.setIconSize(QtCore.QSize(40, 40))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Expanding) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
@ -116,19 +83,21 @@ class UiMainWindow(object):
self.albumPageTitleLayout.setSpacing(0) self.albumPageTitleLayout.setSpacing(0)
self.albumPageTitleLayout.setObjectName("albumPageTitleLayout") self.albumPageTitleLayout.setObjectName("albumPageTitleLayout")
self.albumPageIconLabel = QtWidgets.QLabel(self.albumPage) self.albumPageIconLabel = QtWidgets.QLabel(self.albumPage)
self.albumPageIconLabel.setPixmap( self.albumPageIconLabel.setMaximumSize(36, 36)
qta.icon('mdi.album').pixmap(self.albumPageIconLabel.geometry().height())) self.albumPageIconLabel.setPixmap(qta.icon('mdi.album').pixmap(32))
self.albumPageTitleLayout.addWidget(self.albumPageIconLabel) self.albumPageTitleLayout.addWidget(self.albumPageIconLabel)
self.albumPageTitleLabel = QtWidgets.QLabel(self.albumPage) self.albumPageTitleLabel = QtWidgets.QLabel(self.albumPage)
self.albumPageTitleLayout.addWidget(self.albumPageTitleLabel) self.albumPageTitleLayout.addWidget(self.albumPageTitleLabel)
self.albumPageTotalLabel = QtWidgets.QLabel(self.albumPage)
self.albumPageTotalLabel.setAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignRight)
self.albumPageTotalLabel.setIndent(4)
self.albumPageTotalLabel.setText('0')
self.albumPageTitleLayout.addWidget(self.albumPageTotalLabel)
self.albumPageLayout.addLayout(self.albumPageTitleLayout) self.albumPageLayout.addLayout(self.albumPageTitleLayout)
self.albumListWidget = QtWidgets.QListWidget(self.albumPage) self.albumListWidget = QtWidgets.QListWidget(self.albumPage)
self.albumListWidget.setObjectName("albumListWidget") self.albumListWidget.setObjectName("albumListWidget")
self.albumListWidget.setSortingEnabled(True) self.albumListWidget.setSortingEnabled(True)
# self.albumListWidget.setViewMode(QtWidgets.QListView.IconMode)
# self.albumListWidget.setMovement(QtWidgets.QListView.Static)
self.albumListWidget.setIconSize(QtCore.QSize(100, 100)) self.albumListWidget.setIconSize(QtCore.QSize(100, 100))
# self.albumListWidget.setGridSize(QtCore.QSize(128, 128))
self.albumPageLayout.addWidget(self.albumListWidget) self.albumPageLayout.addWidget(self.albumListWidget)
self.stackedWidget.addWidget(self.albumPage) self.stackedWidget.addWidget(self.albumPage)
self.artistPage = QtWidgets.QWidget() self.artistPage = QtWidgets.QWidget()
@ -137,6 +106,17 @@ class UiMainWindow(object):
self.artistPageLayout.setContentsMargins(0, 0, 0, 0) self.artistPageLayout.setContentsMargins(0, 0, 0, 0)
self.artistPageLayout.setSpacing(0) self.artistPageLayout.setSpacing(0)
self.artistPageLayout.setObjectName("artistPageLayout") self.artistPageLayout.setObjectName("artistPageLayout")
self.artistPageTitleLayout = QtWidgets.QHBoxLayout()
self.artistPageTitleLayout.setContentsMargins(0, 0, 0, 0)
self.artistPageTitleLayout.setSpacing(0)
self.artistPageTitleLayout.setObjectName("artistPageTitleLayout")
self.artistPageIconLabel = QtWidgets.QLabel(self.artistPage)
self.artistPageIconLabel.setMaximumSize(36, 36)
self.artistPageIconLabel.setPixmap(qta.icon('mdi.account').pixmap(32))
self.artistPageTitleLayout.addWidget(self.artistPageIconLabel)
self.artistPageTitleLabel = QtWidgets.QLabel(self.artistPage)
self.artistPageTitleLayout.addWidget(self.artistPageTitleLabel)
self.artistPageLayout.addLayout(self.artistPageTitleLayout)
self.artistListWidget = QtWidgets.QListWidget(self.artistPage) self.artistListWidget = QtWidgets.QListWidget(self.artistPage)
self.artistListWidget.setObjectName("artistListWidget") self.artistListWidget.setObjectName("artistListWidget")
self.artistListWidget.setSortingEnabled(True) self.artistListWidget.setSortingEnabled(True)
@ -169,11 +149,6 @@ class UiMainWindow(object):
self.statusbar = QtWidgets.QStatusBar(self) self.statusbar = QtWidgets.QStatusBar(self)
self.statusbar.setObjectName("statusbar") self.statusbar.setObjectName("statusbar")
self.setStatusBar(self.statusbar) self.setStatusBar(self.statusbar)
self.actionPlay = QtWidgets.QAction(self)
self.actionPlay.setObjectName("actionPlay")
self.mainMenu = QtWidgets.QMenu(self)
self.settingsAction = self.mainMenu.addAction(qta.icon('mdi.application-settings'), '')
self.albumsListItem = QtWidgets.QListWidgetItem(qta.icon('mdi.album'), '') self.albumsListItem = QtWidgets.QListWidgetItem(qta.icon('mdi.album'), '')
self.artistsListItem = QtWidgets.QListWidgetItem(qta.icon('mdi.account'), '') self.artistsListItem = QtWidgets.QListWidgetItem(qta.icon('mdi.account'), '')
@ -183,7 +158,6 @@ class UiMainWindow(object):
self.splitter.setStretchFactor(1, 1) self.splitter.setStretchFactor(1, 1)
self.retranslate_ui() self.retranslate_ui()
self.menuButton.clicked.connect(self.on_menu_button_clicked)
self.viewListWidget.currentRowChanged.connect(self.on_view_list_current_row_changed) self.viewListWidget.currentRowChanged.connect(self.on_view_list_current_row_changed)
self.viewListWidget.setCurrentRow(0) self.viewListWidget.setCurrentRow(0)
QtCore.QMetaObject.connectSlotsByName(self) QtCore.QMetaObject.connectSlotsByName(self)
@ -192,21 +166,14 @@ class UiMainWindow(object):
def retranslate_ui(self): def retranslate_ui(self):
_translate = QtCore.QCoreApplication.translate _translate = QtCore.QCoreApplication.translate
self.setWindowTitle(_translate("MainWindow", "PyFunkwhale")) self.setWindowTitle(_translate("MainWindow", "Playtypus"))
self.toggleButton.setText(_translate("MainWindow", "..."))
self.previousButton.setText(_translate("MainWindow", "..."))
self.playButton.setText(_translate("MainWindow", "..."))
self.nextButton.setText(_translate("MainWindow", "..."))
self.positionLabel.setText(_translate("MainWindow", "01:43")) self.positionLabel.setText(_translate("MainWindow", "01:43"))
self.shuffleButton.setText(_translate("MainWindow", "...")) self.playAction.setText(_translate("MainWindow", "&Play"))
self.repeatButton.setText(_translate("MainWindow", "...")) self.playAction.setToolTip(_translate("MainWindow", "Play"))
self.muteButton.setText(_translate("MainWindow", "..."))
self.menuButton.setText(_translate("MainWindow", "..."))
self.actionPlay.setText(_translate("MainWindow", "&Play"))
self.actionPlay.setToolTip(_translate("MainWindow", "Play"))
self.settingsAction.setText(_translate("MainWindow", "&Configure")) self.settingsAction.setText(_translate("MainWindow", "&Configure"))
self.albumsListItem.setText(_translate("MainWindow", "Albums")) self.albumsListItem.setText(_translate("MainWindow", "Albums"))
self.albumPageTitleLabel.setText(_translate("MainWindow", "Albums")) self.albumPageTitleLabel.setText(_translate("MainWindow", "Albums"))
self.artistPageTitleLabel.setText(_translate("MainWindow", "Artists"))
self.artistsListItem.setText(_translate("MainWindow", "Artists")) self.artistsListItem.setText(_translate("MainWindow", "Artists"))
self.tracksListItem.setText(_translate("MainWindow", "Tracks")) self.tracksListItem.setText(_translate("MainWindow", "Tracks"))
@ -217,3 +184,6 @@ class UiMainWindow(object):
def on_view_list_current_row_changed(self, current_row): def on_view_list_current_row_changed(self, current_row):
self.stackedWidget.setCurrentIndex(current_row) self.stackedWidget.setCurrentIndex(current_row)
def update_album_total(self, value):
self.albumPageTotalLabel.setText(str(value))