1
|
|
|
import os |
2
|
|
|
|
3
|
|
|
from appdirs import AppDirs |
4
|
|
|
from PyQt5.QtWidgets import QFileSystemModel, QTreeView |
5
|
|
|
import toml |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class MediaLibraryModel(QFileSystemModel): |
9
|
|
|
"""Creates a model of the media library to be shown in a view.""" |
10
|
|
|
|
11
|
|
|
def __init__(self, parent=None): |
12
|
|
|
"""Read the path of the media library from settings.toml. |
13
|
|
|
|
14
|
|
|
This path is set as the root path of the file system model. |
15
|
|
|
""" |
16
|
|
|
super(MediaLibraryModel, self).__init__(parent) |
17
|
|
|
|
18
|
|
|
self.setNameFilters(['*.mp3', '*.flac']) |
19
|
|
|
self.config_directory = AppDirs('mosaic', 'Mandeep').user_config_dir |
20
|
|
|
self.user_config_file = os.path.join(self.config_directory, 'settings.toml') |
21
|
|
|
|
22
|
|
|
with open(self.user_config_file) as conffile: |
23
|
|
|
config = toml.load(conffile) |
24
|
|
|
self.library = config['media_library']['media_library_path'] |
25
|
|
|
|
26
|
|
|
if os.path.isdir(self.library): |
27
|
|
|
self.setRootPath(self.library) |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
class MediaLibraryView(QTreeView): |
31
|
|
|
"""Creates a view of the media library from a model.""" |
32
|
|
|
|
33
|
|
|
def __init__(self, parent=None): |
34
|
|
|
"""Set MediaLibraryModel as the model of the view. |
35
|
|
|
|
36
|
|
|
Sets the root index as the path of the media library. Removes |
37
|
|
|
the 2nd, 3rd, and 4th columns which display size, type, and date modified. |
38
|
|
|
""" |
39
|
|
|
super(MediaLibraryView, self).__init__(parent) |
40
|
|
|
|
41
|
|
|
self.model = MediaLibraryModel() |
42
|
|
|
self.setModel(self.model) |
43
|
|
|
|
44
|
|
|
if os.path.isdir(self.model.library): |
45
|
|
|
self.setRootIndex(self.model.index(self.model.library)) |
46
|
|
|
|
47
|
|
|
for column in range(1, 4): |
48
|
|
|
self.hideColumn(column) |
49
|
|
|
|