diff options
author | Eddy Pedroni <eddy@0xf7.com> | 2021-12-19 19:41:55 +0100 |
---|---|---|
committer | Eddy Pedroni <eddy@0xf7.com> | 2021-12-19 19:41:55 +0100 |
commit | 931ddc7ec9a4c719d6aa08b0a1ac613a95d88b84 (patch) | |
tree | 31f50de465d011a5fc508ea982d28c2b6a8d2b25 /playlist.py | |
parent | c6b5fa928719a05782de40a86fcb90feca92fce3 (diff) |
Added architecture diagram, refactored playlist to match
Diffstat (limited to 'playlist.py')
-rw-r--r-- | playlist.py | 59 |
1 files changed, 18 insertions, 41 deletions
diff --git a/playlist.py b/playlist.py index 12fd9ed..b175a08 100644 --- a/playlist.py +++ b/playlist.py @@ -1,10 +1,6 @@ -from PyQt5.QtGui import * -from PyQt5.QtWidgets import * -from PyQt5.QtCore import * - import logging -import vlc +""" class PlaylistModel(QAbstractListModel): def __init__(self, medialist, *args, **kwargs): super(PlaylistModel, self).__init__(*args, **kwargs) @@ -16,42 +12,23 @@ class PlaylistModel(QAbstractListModel): def rowCount(self, index): return self.medialist.count() +""" class Playlist: - def __init__(self, window): - self.medialist = vlc.MediaList() - self.model = PlaylistModel(self.medialist) - self.window = window - - window.player.set_media_list(self.medialist) - window.songListView.setModel(self.model) - window.songListView.selectionModel().selectionChanged.connect(self.playlistSelectionChanged) - window.addSongButton.pressed.connect(self.addSong) - - def addSong(self): - path, _ = QFileDialog.getOpenFileName(self.window, "Open file", "", "mp3 Audio (*.mp3);FLAC audio (*.flac);All files (*.*)") - if path: - media = vlc.Media(path) - self.medialist.add_media(media) - self.model.layoutChanged.emit() - logging.debug(f"Added song: {path}") - - def playlistSelectionChanged(self, ix): - i = ix.indexes()[0].row() - self.setCurrent(i) - #path = self.playlist.current.filePath - #self.player.set_media(path) - """ - self.abListModel.abList = self.internalState[path] - self.abListView.selectionModel().clearSelection() - self.abListModel.layoutChanged.emit() - self.aSlider.setValue(0) - self.bSlider.setValue(0) - """ + def __init__(self, setSongCallback): + self.songList = list() + self.currentSong = None + self.callback = setSongCallback + + def addSong(self, path): + self.songList.append(path) + logging.debug(f"Added song: {path}") + if self.currentSong is None: + self.setCurrentSong(0) + + def setCurrentSong(self, index): + if index < len(self.songList): + self.currentSong = index + self.callback(self.songList[index]) + logging.debug(f"Selected song: {self.currentSong}") - def setCurrent(self, index): - media = self.medialist.item_at_index(index) - if not media: - raise Exception(f"Invalid playlist index {index}") - self.medialist.set_media(media) - logging.debug(f"Selected song: {self.medialist.media().get_mrl()}") |