Implemented displaying of tracks in a QTreeWidget.

This commit is contained in:
The Wobbler 2024-12-28 20:41:18 +01:00
parent 10c36b37a1
commit af2b7b6c8d
11 changed files with 90 additions and 19 deletions

View file

@ -3,6 +3,7 @@
import sys
import argparse
from main import Wobuzz
from player.playlist import Playlist
description = "A music player made by The Wobbler."
@ -17,12 +18,13 @@ arguments = parser.parse_args()
app = Wobuzz()
if arguments.playlist:
print(arguments.playlist)
app.player.current_playlist.load_from_m3u(arguments.playlist)
app.library.temporary_playlist.load_from_m3u(arguments.playlist)
if arguments.track:
print(arguments.track)
app.player.current_playlist.load_from_paths(arguments.track)
app.library.temporary_playlist.load_from_paths(arguments.track)
app.player.current_playlist = app.library.temporary_playlist
app.library.create_playlist_views()
sys.exit(app.qt_app.exec())

View file

@ -1,5 +1,7 @@
#!/usr/bin/python3
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QDockWidget
from ui.main_window import MainWindow
@ -9,6 +11,13 @@ class GUI:
self.window = MainWindow()
self.window.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, self.app.library.main_library_dock)
self.app.library.main_library_dock.setFeatures(
QDockWidget.DockWidgetFeature.DockWidgetMovable |
QDockWidget.DockWidgetFeature.DockWidgetFloatable
)
if self.app.settings.window_maximized:
self.window.showMaximized()

42
wobuzz/library/library.py Normal file
View file

@ -0,0 +1,42 @@
#!/usr/bin/python3
from PyQt6.QtWidgets import QTabWidget, QTreeWidgetItem
from player.playlist import Playlist
from ui.library_dock import LibraryDock
from ui.playlist import PlaylistView
class Library:
"""
Class that manages and syncs the library and library gui dock widgets.
"""
def __init__(self, app):
self.app = app
self.main_library_dock = LibraryDock()
self.library_docks = [self.main_library_dock]
self.temporary_playlist = Playlist(self.app, "Temporary Playlist")
self.playlists = [self.temporary_playlist]
def create_playlist_views(self):
for library_dock in self.library_docks:
playlist_tabs: QTabWidget = library_dock.library.playlist_tabs
playlist_tabs.playlists = {}
for playlist in self.playlists:
playlist_view = self.create_playlist_view(playlist)
playlist_tabs.playlists[playlist.title] = playlist_view
playlist_tabs.addTab(playlist_view, playlist.title)
def create_playlist_view(self, playlist: Playlist):
view = PlaylistView()
for track in playlist.tracks:
track_item = QTreeWidgetItem(view)
track_item.setText(1, track.title)
return view

View file

@ -6,6 +6,7 @@ from wobbl_tools.data_file import load_dataclass_json
from settings import Settings
from utils import Utils
from player.player import Player
from library.library import Library
from gui import GUI
from gui_communication.gui_communication import GUICommunication
@ -20,6 +21,7 @@ class Wobuzz:
self.settings.set_attribute_change_event(self.on_settings_change)
self.player = Player(self)
self.library = Library(self)
self.gui = GUI(self)
self.gui_communication = GUICommunication(self)

View file

@ -19,7 +19,7 @@ class Player:
self.track_progress = TrackProgress(self.app)
self.current_playlist = Playlist(self.app)
self.current_playlist = Playlist(self.app, "None")
self.playing = False
self.paused = False

View file

@ -5,8 +5,9 @@ from .track import Track
class Playlist:
def __init__(self, app):
def __init__(self, app, title: str):
self.app = app
self.title = title # playlist title
self.tracks: list[Track] = []
self.current_track_index = 0
self.current_track: Track | None = None
@ -22,7 +23,8 @@ class Playlist:
i += 1
self.current_track = self.tracks[0] # current track is the first track in the playlist
if self.current_track is None: # set current track to the first track if there is no currently playing track
self.current_track = self.tracks[0]
def load_from_m3u(self, path):
file = open(path, "r")
@ -43,6 +45,7 @@ class Playlist:
i += 1
if self.current_track is None: # set current track to the first track if there is no currently playing track
self.current_track = self.tracks[0]
def load_from_wbz(self, path):

View file

@ -16,6 +16,8 @@ class Track:
self.property_string = property_string
self.cached = cache
# get filename (will be replaced by proper name getter in future)
self.title = path.split("/")[-1].split(".")[0]
self.audio = None
self.sound = None
self.duration = 0

View file

@ -7,8 +7,9 @@ class Library(QToolBox):
def __init__(self, parent=None):
super().__init__(parent)
playlist_tabs = QTabWidget()
self.addItem(playlist_tabs, "Playlists")
self.playlist_tabs = QTabWidget()
self.addItem(self.playlist_tabs, "Playlists")
label = QLabel()
self.addItem(label, "Genres")
label = QLabel()

View file

@ -15,11 +15,6 @@ class LibraryDock(QDockWidget):
Qt.DockWidgetArea.BottomDockWidgetArea
)
self.setFeatures(
QDockWidget.DockWidgetFeature.DockWidgetMovable |
QDockWidget.DockWidgetFeature.DockWidgetFloatable
)
self.library = Library(self)
self.setWidget(self.library)

View file

@ -3,7 +3,6 @@
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QMainWindow, QMenu
from .track_control import TrackControl
from .library_dock import LibraryDock
from .settings.settings import Settings
@ -30,6 +29,3 @@ class MainWindow(QMainWindow):
self.settings.hide()
self.addDockWidget(Qt.DockWidgetArea.LeftDockWidgetArea, self.settings)
self.library_dock = LibraryDock()
self.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, self.library_dock)

19
wobuzz/ui/playlist.py Normal file
View file

@ -0,0 +1,19 @@
#!/usr/bin/python3
from PyQt6.QtWidgets import QTreeWidget
class PlaylistView(QTreeWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setColumnCount(4)
headers = [
"#",
"Title",
"Artist",
"Album"
]
self.setHeaderLabels(headers)