diff --git a/README.md b/README.md index 7fe2ce0..57184cc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# pyfunkwhale +# Playtypus -(working name) \ No newline at end of file +Playtpus is a desktop Funkwhale client. diff --git a/playtypus/__init__.py b/playtypus/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyfunkwhale.py b/playtypus/__main__.py similarity index 100% rename from pyfunkwhale.py rename to playtypus/__main__.py diff --git a/mainwindow.py b/playtypus/mainwindow.py similarity index 68% rename from mainwindow.py rename to playtypus/mainwindow.py index 614f0c5..51e7f32 100644 --- a/mainwindow.py +++ b/playtypus/mainwindow.py @@ -1,72 +1,10 @@ # -*- coding: utf-8 -*- -import requests from funksnake import Funkwhale -from PyQt5 import QtCore, QtGui, QtWidgets, QtNetwork +from PyQt5 import QtCore, QtWidgets, QtNetwork -from ui_mainwindow import UiMainWindow -from settingsdialog import SettingsDialog - - -class ThreadWorker(QtCore.QObject): - """ - The :class:`~threads.ThreadWorker` class provides a base class for thread workers. - - In Qt5, all work is done in workers, rather than actual QThread classes, and this case class provides - some utility signals and slots to make it easier to use threads and thread workers. - """ - quit = QtCore.pyqtSignal() - error = QtCore.pyqtSignal(str, str) - - def start(self): - """ - The start method is how the worker runs. Basically, put your code here. - """ - raise NotImplementedError('Your class needs to override this method and run self.quit.emit() when complete') - - -class AlbumArtWorker(ThreadWorker): - album_item = None - artwork_url = None - - def start(self): - if not self.album_item: - self.error.emit('No album QListWidgetItem set', 'The album_item attribute was not set') - self.quit.emit() - return - if not self.artwork_url: - self.error.emit('No artwork URL set', 'The artwork_url attribute was not set') - self.quit.emit() - return - response = requests.get(self.artwork_url) - if response.status_code == 200: - pixmap = QtGui.QPixmap() - pixmap.loadFromData(response.content) - self.album_item.setIcon(QtGui.QIcon(pixmap)) - else: - print(response.text) - self.quit.emit() - - -class AlbumWorker(ThreadWorker): - """ - A thread worker to fetch the album art - """ - window = None - - def start(self): - if not self.window: - self.error.emit('No window set', 'The window attribute was not set') - self.quit.emit() - return - self.window.albumListWidget.clear() - for album in self.window.funkwhale.albums.list()['results']: - album_item = QtWidgets.QListWidgetItem(album['title']) - self.window.albumListWidget.addItem(album_item) - artwork_worker = AlbumArtWorker() - artwork_worker.album_item = album_item - artwork_worker.artwork_url = album['cover']['urls']['medium_square_crop'] - self.window.run_thread(artwork_worker, 'album-{}'.format(album['title'])) - self.quit.emit() +from playtypus.ui_mainwindow import UiMainWindow +from playtypus.settingsdialog import SettingsDialog +from playtypus.threads import AlbumWorker class MainWindow(QtWidgets.QMainWindow, UiMainWindow): diff --git a/settingsdialog.py b/playtypus/settingsdialog.py similarity index 100% rename from settingsdialog.py rename to playtypus/settingsdialog.py diff --git a/playtypus/threads.py b/playtypus/threads.py new file mode 100644 index 0000000..b3dd0ac --- /dev/null +++ b/playtypus/threads.py @@ -0,0 +1,67 @@ +""" +The :mod:`threads` module contains functions to make working with QThreads easier +""" +import requests +from PyQt5 import QtCore, QtGui, QtWidgets + + +class ThreadWorker(QtCore.QObject): + """ + The :class:`~threads.ThreadWorker` class provides a base class for thread workers. + + In Qt5, all work is done in workers, rather than actual QThread classes, and this case class provides + some utility signals and slots to make it easier to use threads and thread workers. + """ + quit = QtCore.pyqtSignal() + error = QtCore.pyqtSignal(str, str) + + def start(self): + """ + The start method is how the worker runs. Basically, put your code here. + """ + raise NotImplementedError('Your class needs to override this method and run self.quit.emit() when complete') + + +class AlbumArtWorker(ThreadWorker): + album_item = None + artwork_url = None + + def start(self): + if not self.album_item: + self.error.emit('No album QListWidgetItem set', 'The album_item attribute was not set') + self.quit.emit() + return + if not self.artwork_url: + self.error.emit('No artwork URL set', 'The artwork_url attribute was not set') + self.quit.emit() + return + response = requests.get(self.artwork_url) + if response.status_code == 200: + pixmap = QtGui.QPixmap() + pixmap.loadFromData(response.content) + self.album_item.setIcon(QtGui.QIcon(pixmap)) + else: + print(response.text) + self.quit.emit() + + +class AlbumWorker(ThreadWorker): + """ + A thread worker to fetch the album art + """ + window = None + + def start(self): + if not self.window: + self.error.emit('No window set', 'The window attribute was not set') + self.quit.emit() + return + self.window.albumListWidget.clear() + for album in self.window.funkwhale.albums.list()['results']: + album_item = QtWidgets.QListWidgetItem(album['title']) + self.window.albumListWidget.addItem(album_item) + artwork_worker = AlbumArtWorker() + artwork_worker.album_item = album_item + artwork_worker.artwork_url = album['cover']['urls']['medium_square_crop'] + self.window.run_thread(artwork_worker, 'album-{}'.format(album['title'])) + self.quit.emit() diff --git a/ui_mainwindow.py b/playtypus/ui_mainwindow.py similarity index 100% rename from ui_mainwindow.py rename to playtypus/ui_mainwindow.py diff --git a/ui_settingsdialog.py b/playtypus/ui_settingsdialog.py similarity index 100% rename from ui_settingsdialog.py rename to playtypus/ui_settingsdialog.py diff --git a/threads.py b/threads.py deleted file mode 100644 index c62f0ea..0000000 --- a/threads.py +++ /dev/null @@ -1,6 +0,0 @@ -""" -The :mod:`threads` module contains functions to make working with QThreads easier -""" -from PyQt5 import QtCore - -