|
1
|
|
|
from PyQt5.QtGui import QIcon |
|
2
|
|
|
from PyQt5.QtWidgets import (QDialog, QHBoxLayout, QLabel, QLineEdit, QTabWidget, QTableWidget, |
|
3
|
|
|
QTableWidgetItem, QTextEdit, QVBoxLayout, QWidget) |
|
4
|
|
|
|
|
5
|
|
|
from mosaic import metadata, utilities |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
class GeneralInformation(QWidget): |
|
9
|
|
|
"""MediaInformation houses all of the widgets and layouts in order to show general metadata.""" |
|
10
|
|
|
|
|
11
|
|
|
def __init__(self, file=None, parent=None): |
|
12
|
|
|
"""Initialize the widgets and layouts needed to create a dialog.""" |
|
13
|
|
|
super(GeneralInformation, self).__init__(parent) |
|
14
|
|
|
|
|
15
|
|
|
if file is not None: |
|
16
|
|
|
(album, artist, title, track_number, date, genre, description, sample_rate, |
|
17
|
|
|
bitrate, bitrate_mode, bits_per_sample, *__) = metadata.metadata(file) |
|
18
|
|
|
|
|
19
|
|
|
artist_label = QLabel('Artist', self) |
|
20
|
|
|
artist_label.setStyleSheet('font-weight: bold') |
|
21
|
|
|
artist_line = QLineEdit() |
|
22
|
|
|
artist_line.setText(artist) |
|
23
|
|
|
artist_line.setReadOnly(True) |
|
24
|
|
|
artist_box = QVBoxLayout() |
|
25
|
|
|
artist_box.addWidget(artist_label) |
|
26
|
|
|
artist_box.addWidget(artist_line) |
|
27
|
|
|
|
|
28
|
|
|
album_label = QLabel('Album', self) |
|
29
|
|
|
album_label.setStyleSheet('font-weight: bold') |
|
30
|
|
|
album_line = QLineEdit() |
|
31
|
|
|
album_line.setText(album) |
|
32
|
|
|
album_line.setReadOnly(True) |
|
33
|
|
|
album_box = QVBoxLayout() |
|
34
|
|
|
album_box.addWidget(album_label) |
|
35
|
|
|
album_box.addWidget(album_line) |
|
36
|
|
|
|
|
37
|
|
|
album_date_label = QLabel('Album Date', self) |
|
38
|
|
|
album_date_label.setStyleSheet('font-weight: bold') |
|
39
|
|
|
album_date_line = QLineEdit() |
|
40
|
|
|
album_date_line.setText(date) |
|
41
|
|
|
album_date_line.setReadOnly(True) |
|
42
|
|
|
album_date_line.setFixedWidth(70) |
|
43
|
|
|
date_box = QVBoxLayout() |
|
44
|
|
|
date_box.addWidget(album_date_label) |
|
45
|
|
|
date_box.addWidget(album_date_line) |
|
46
|
|
|
|
|
47
|
|
|
track_label = QLabel('Track Title', self) |
|
48
|
|
|
track_label.setStyleSheet('font-weight: bold') |
|
49
|
|
|
track_line = QLineEdit() |
|
50
|
|
|
track_line.setText(title) |
|
51
|
|
|
track_line.setReadOnly(True) |
|
52
|
|
|
track_box = QVBoxLayout() |
|
53
|
|
|
track_box.addWidget(track_label) |
|
54
|
|
|
track_box.addWidget(track_line) |
|
55
|
|
|
|
|
56
|
|
|
track_number_label = QLabel('Track Number', self) |
|
57
|
|
|
track_number_label.setStyleSheet('font-weight: bold') |
|
58
|
|
|
track_number_line = QLineEdit() |
|
59
|
|
|
track_number_line.setText(track_number) |
|
60
|
|
|
track_number_line.setReadOnly(True) |
|
61
|
|
|
track_number_line.setFixedWidth(90) |
|
62
|
|
|
number_box = QVBoxLayout() |
|
63
|
|
|
number_box.addWidget(track_number_label) |
|
64
|
|
|
number_box.addWidget(track_number_line) |
|
65
|
|
|
|
|
66
|
|
|
genre_label = QLabel('Genre', self) |
|
67
|
|
|
genre_label.setStyleSheet('font-weight: bold') |
|
68
|
|
|
genre_line = QLineEdit() |
|
69
|
|
|
genre_line.setText(genre) |
|
70
|
|
|
genre_line.setReadOnly(True) |
|
71
|
|
|
genre_line.setFixedWidth(100) |
|
72
|
|
|
genre_box = QVBoxLayout() |
|
73
|
|
|
genre_box.addWidget(genre_label) |
|
74
|
|
|
genre_box.addWidget(genre_line) |
|
75
|
|
|
|
|
76
|
|
|
bitrate_label = QLabel('Bitrate', self) |
|
77
|
|
|
bitrate_label.setStyleSheet('font-weight: bold') |
|
78
|
|
|
bitrate_line = QLineEdit() |
|
79
|
|
|
bitrate_line.setText(bitrate) |
|
80
|
|
|
bitrate_line.setReadOnly(True) |
|
81
|
|
|
bitrate_line.setFixedWidth(70) |
|
82
|
|
|
bitrate_box = QVBoxLayout() |
|
83
|
|
|
bitrate_box.addWidget(bitrate_label) |
|
84
|
|
|
bitrate_box.addWidget(bitrate_line) |
|
85
|
|
|
|
|
86
|
|
|
bitrate_mode_label = QLabel('Bitrate Mode', self) |
|
87
|
|
|
bitrate_mode_label.setStyleSheet('font-weight: bold') |
|
88
|
|
|
bitrate_mode_line = QLineEdit() |
|
89
|
|
|
bitrate_mode_line.setText(bitrate_mode) |
|
90
|
|
|
bitrate_mode_line.setReadOnly(True) |
|
91
|
|
|
bitrate_mode_box = QVBoxLayout() |
|
92
|
|
|
bitrate_mode_box.addWidget(bitrate_mode_label) |
|
93
|
|
|
bitrate_mode_box.addWidget(bitrate_mode_line) |
|
94
|
|
|
|
|
95
|
|
|
sample_rate_label = QLabel('Sample Rate', self) |
|
96
|
|
|
sample_rate_label.setStyleSheet('font-weight: bold') |
|
97
|
|
|
sample_rate_line = QLineEdit() |
|
98
|
|
|
sample_rate_line.setText(sample_rate) |
|
99
|
|
|
sample_rate_line.setReadOnly(True) |
|
100
|
|
|
sample_rate_box = QVBoxLayout() |
|
101
|
|
|
sample_rate_box.addWidget(sample_rate_label) |
|
102
|
|
|
sample_rate_box.addWidget(sample_rate_line) |
|
103
|
|
|
|
|
104
|
|
|
bits_per_sample_label = QLabel('Bits Per Sample', self) |
|
105
|
|
|
bits_per_sample_label.setStyleSheet('font-weight: bold') |
|
106
|
|
|
bits_per_sample_line = QLineEdit() |
|
107
|
|
|
bits_per_sample_line.setText(bits_per_sample) |
|
108
|
|
|
bits_per_sample_line.setReadOnly(True) |
|
109
|
|
|
bits_per_sample_box = QVBoxLayout() |
|
110
|
|
|
bits_per_sample_box.addWidget(bits_per_sample_label) |
|
111
|
|
|
bits_per_sample_box.addWidget(bits_per_sample_line) |
|
112
|
|
|
|
|
113
|
|
|
audio_description_label = QLabel('Description', self) |
|
114
|
|
|
audio_description_label.setStyleSheet('font-weight: bold') |
|
115
|
|
|
audio_description_line = QTextEdit() |
|
116
|
|
|
audio_description_line.setText(description) |
|
117
|
|
|
audio_description_line.setReadOnly(True) |
|
118
|
|
|
audio_description_box = QVBoxLayout() |
|
119
|
|
|
audio_description_box.addWidget(audio_description_label) |
|
120
|
|
|
audio_description_box.addWidget(audio_description_line) |
|
121
|
|
|
|
|
122
|
|
|
artist_info = QHBoxLayout() |
|
123
|
|
|
artist_info.addLayout(artist_box) |
|
124
|
|
|
artist_info.addLayout(album_box) |
|
125
|
|
|
artist_info.addLayout(date_box) |
|
126
|
|
|
|
|
127
|
|
|
song_info = QHBoxLayout() |
|
128
|
|
|
song_info.addLayout(track_box) |
|
129
|
|
|
song_info.addLayout(number_box) |
|
130
|
|
|
song_info.addLayout(genre_box) |
|
131
|
|
|
|
|
132
|
|
|
audio_info = QHBoxLayout() |
|
133
|
|
|
audio_info.addLayout(bitrate_box) |
|
134
|
|
|
audio_info.addLayout(bitrate_mode_box) |
|
135
|
|
|
audio_info.addLayout(sample_rate_box) |
|
136
|
|
|
audio_info.addLayout(bits_per_sample_box) |
|
137
|
|
|
|
|
138
|
|
|
song_description = QHBoxLayout() |
|
139
|
|
|
song_description.addLayout(audio_description_box) |
|
140
|
|
|
|
|
141
|
|
|
media_information_layout = QVBoxLayout() |
|
142
|
|
|
media_information_layout.addLayout(artist_info) |
|
143
|
|
|
media_information_layout.addLayout(song_info) |
|
144
|
|
|
media_information_layout.addLayout(audio_info) |
|
145
|
|
|
media_information_layout.addLayout(song_description) |
|
146
|
|
|
media_information_layout.addStretch(1) |
|
147
|
|
|
|
|
148
|
|
|
self.setLayout(media_information_layout) |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
class FullInformation(QWidget): |
|
152
|
|
|
"""Abstract class that provides a table with two columns. |
|
153
|
|
|
|
|
154
|
|
|
One column for the current audio file's metadata tags and one column for the |
|
155
|
|
|
values of the tags. |
|
156
|
|
|
""" |
|
157
|
|
|
|
|
158
|
|
|
def __init__(self, file=None, parent=None): |
|
159
|
|
|
"""Provide data on every tag embedded within the audio file.""" |
|
160
|
|
|
super(FullInformation, self).__init__(parent) |
|
161
|
|
|
|
|
162
|
|
|
table_layout = QHBoxLayout() |
|
163
|
|
|
table = QTableWidget() |
|
164
|
|
|
table.setColumnCount(2) |
|
165
|
|
|
table.setColumnWidth(0, 270) |
|
166
|
|
|
table.setColumnWidth(1, 270) |
|
167
|
|
|
table.verticalHeader().hide() |
|
168
|
|
|
table.horizontalHeader().hide() |
|
169
|
|
|
|
|
170
|
|
|
if file is not None: |
|
171
|
|
|
file = metadata.extract_metadata(file) |
|
172
|
|
|
table.setRowCount(len(file)) |
|
173
|
|
|
for i, (tag, data) in enumerate(sorted(file.items())): |
|
174
|
|
|
table.setItem(i, 0, QTableWidgetItem(tag)) |
|
175
|
|
|
table.setItem(i, 1, QTableWidgetItem(data)) |
|
176
|
|
|
|
|
177
|
|
|
table_layout.addWidget(table) |
|
178
|
|
|
|
|
179
|
|
|
self.setLayout(table_layout) |
|
180
|
|
|
|
|
181
|
|
|
|
|
182
|
|
|
class InformationDialog(QDialog): |
|
183
|
|
|
"""InformationDialog displays a dialog containing tabs for metadata.""" |
|
184
|
|
|
|
|
185
|
|
|
def __init__(self, file=None, parent=None): |
|
186
|
|
|
"""Initialize QTabWidget with tabs for each metadata page.""" |
|
187
|
|
|
super(InformationDialog, self).__init__(parent) |
|
188
|
|
|
self.setWindowTitle('Media Information') |
|
189
|
|
|
|
|
190
|
|
|
info_icon = utilities.resource_filename('mosaic.images', 'md_info.png') |
|
191
|
|
|
self.setWindowIcon(QIcon(info_icon)) |
|
192
|
|
|
self.setFixedSize(600, 600) |
|
193
|
|
|
|
|
194
|
|
|
media_information = GeneralInformation(file) |
|
195
|
|
|
metadata_information = FullInformation(file) |
|
196
|
|
|
|
|
197
|
|
|
page = QTabWidget() |
|
198
|
|
|
page.addTab(media_information, 'General') |
|
199
|
|
|
page.addTab(metadata_information, 'Metadata') |
|
200
|
|
|
|
|
201
|
|
|
dialog_layout = QHBoxLayout() |
|
202
|
|
|
dialog_layout.addWidget(page) |
|
203
|
|
|
|
|
204
|
|
|
self.setLayout(dialog_layout) |
|
205
|
|
|
|