forked from Wobbl/Wobuzz
Added a button that adds a playlist.
This commit is contained in:
parent
1007ac045f
commit
31e72c25d3
6 changed files with 57 additions and 9 deletions
|
@ -15,7 +15,7 @@ class Library:
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
self.app = app
|
self.app = app
|
||||||
|
|
||||||
self.main_library_dock = LibraryDock()
|
self.main_library_dock = LibraryDock(self)
|
||||||
self.library_docks = [self.main_library_dock]
|
self.library_docks = [self.main_library_dock]
|
||||||
|
|
||||||
self.temporary_playlist = Playlist(self.app, "Temporary Playlist")
|
self.temporary_playlist = Playlist(self.app, "Temporary Playlist")
|
||||||
|
@ -49,7 +49,7 @@ class Library:
|
||||||
|
|
||||||
def load_playlist_views(self):
|
def load_playlist_views(self):
|
||||||
for library_dock in self.library_docks:
|
for library_dock in self.library_docks:
|
||||||
playlist_tabs: QTabWidget = library_dock.library.playlist_tabs
|
playlist_tabs: QTabWidget = library_dock.library_widget.playlist_tabs
|
||||||
|
|
||||||
playlist_tabs.playlists = {}
|
playlist_tabs.playlists = {}
|
||||||
|
|
||||||
|
@ -61,3 +61,13 @@ class Library:
|
||||||
for playlist in self.playlists:
|
for playlist in self.playlists:
|
||||||
playlist.save()
|
playlist.save()
|
||||||
|
|
||||||
|
def new_playlist(self):
|
||||||
|
playlist = Playlist(self.app, self.app.utils.unique_name("New Playlist"))
|
||||||
|
self.playlists.append(playlist)
|
||||||
|
|
||||||
|
for library_dock in self.library_docks:
|
||||||
|
playlist_tabs: QTabWidget = library_dock.library_widget.playlist_tabs
|
||||||
|
|
||||||
|
playlist_view = PlaylistView(playlist)
|
||||||
|
playlist_tabs.addTab(playlist_view, playlist.title)
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,8 @@ class Playlist:
|
||||||
|
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
if self.current_track is None: # set current track to the first track if there is no currently playing track
|
# set current track to the first track if there is no currently playing track
|
||||||
|
if self.current_track is None and self.has_tracks():
|
||||||
self.current_track = self.tracks[0]
|
self.current_track = self.tracks[0]
|
||||||
|
|
||||||
def load_from_m3u(self, path):
|
def load_from_m3u(self, path):
|
||||||
|
@ -52,7 +53,8 @@ class Playlist:
|
||||||
|
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
if self.current_track is None: # set current track to the first track if there is no currently playing track
|
# set current track to the first track if there is no currently playing track
|
||||||
|
if self.current_track is None and self.has_tracks():
|
||||||
self.current_track = self.tracks[0]
|
self.current_track = self.tracks[0]
|
||||||
|
|
||||||
def load_from_wbz(self, path):
|
def load_from_wbz(self, path):
|
||||||
|
|
|
@ -1,15 +1,28 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
from PyQt6.QtWidgets import QToolBox, QLabel, QFrame, QTabWidget
|
from PyQt6.QtCore import Qt
|
||||||
|
from PyQt6.QtGui import QIcon
|
||||||
|
from PyQt6.QtWidgets import QToolBox, QLabel, QTabWidget, QToolButton
|
||||||
|
|
||||||
|
|
||||||
class Library(QToolBox):
|
class Library(QToolBox):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, library, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
|
self.library = library
|
||||||
|
|
||||||
self.playlist_tabs = QTabWidget()
|
self.playlist_tabs = QTabWidget()
|
||||||
|
self.playlist_tabs.setMovable(True)
|
||||||
|
|
||||||
self.addItem(self.playlist_tabs, "Playlists")
|
self.addItem(self.playlist_tabs, "Playlists")
|
||||||
|
|
||||||
|
self.create_playlist = QToolButton(self)
|
||||||
|
|
||||||
|
plus_icon = QIcon.fromTheme(QIcon.ThemeIcon.ListAdd)
|
||||||
|
self.create_playlist.setIcon(plus_icon)
|
||||||
|
|
||||||
|
self.playlist_tabs.setCornerWidget(self.create_playlist)
|
||||||
|
|
||||||
label = QLabel()
|
label = QLabel()
|
||||||
self.addItem(label, "Genres")
|
self.addItem(label, "Genres")
|
||||||
label = QLabel()
|
label = QLabel()
|
||||||
|
@ -19,3 +32,5 @@ class Library(QToolBox):
|
||||||
label = QLabel()
|
label = QLabel()
|
||||||
self.addItem(label, "Tracks")
|
self.addItem(label, "Tracks")
|
||||||
|
|
||||||
|
self.create_playlist.pressed.connect(self.library.new_playlist)
|
||||||
|
|
||||||
|
|
|
@ -6,15 +6,17 @@ from .library import Library
|
||||||
|
|
||||||
|
|
||||||
class LibraryDock(QDockWidget):
|
class LibraryDock(QDockWidget):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, library, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
|
self.library = library
|
||||||
|
|
||||||
self.setAllowedAreas(
|
self.setAllowedAreas(
|
||||||
Qt.DockWidgetArea.LeftDockWidgetArea |
|
Qt.DockWidgetArea.LeftDockWidgetArea |
|
||||||
Qt.DockWidgetArea.RightDockWidgetArea |
|
Qt.DockWidgetArea.RightDockWidgetArea |
|
||||||
Qt.DockWidgetArea.BottomDockWidgetArea
|
Qt.DockWidgetArea.BottomDockWidgetArea
|
||||||
)
|
)
|
||||||
|
|
||||||
self.library = Library(self)
|
self.library_widget = Library(library, self)
|
||||||
self.setWidget(self.library)
|
self.setWidget(self.library_widget)
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ class TrackControl(QToolBar):
|
||||||
|
|
||||||
self.app = app
|
self.app = app
|
||||||
|
|
||||||
|
self.setWindowTitle("Track Control")
|
||||||
|
|
||||||
self.play_icon = QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackStart)
|
self.play_icon = QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackStart)
|
||||||
self.pause_icon = QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackPause)
|
self.pause_icon = QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackPause)
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ class Utils:
|
||||||
|
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
self.app = app
|
self.app = app
|
||||||
|
self.unique_names = {}
|
||||||
|
|
||||||
def format_time(self, ms):
|
def format_time(self, ms):
|
||||||
seconds = int(ms / 1000) % 60
|
seconds = int(ms / 1000) % 60
|
||||||
|
@ -29,3 +30,19 @@ class Utils:
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
def unique_name(self, name: str) -> str:
|
||||||
|
"""
|
||||||
|
Makes a name unique by adding a number to it if the name already exists.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if name in self.unique_names:
|
||||||
|
num_duplicates = self.unique_names[name]
|
||||||
|
self.unique_names[name] += 1
|
||||||
|
|
||||||
|
name = f"{name} {str(num_duplicates).zfill(2)}"
|
||||||
|
|
||||||
|
else:
|
||||||
|
self.unique_names[name] = 1
|
||||||
|
|
||||||
|
return name
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue