Conditions | 2 |
Total Lines | 138 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | from PyQt5.QtGui import QIcon |
||
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 | |||
205 |