Skip to content

Commit bc6d4d3

Browse files
author
Dmitry Ershov
committed
Created a function choose songs
1 parent 061ff96 commit bc6d4d3

File tree

4 files changed

+115
-20
lines changed

4 files changed

+115
-20
lines changed

.idea/workspace.xml

+47-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pipfile

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ verify_ssl = true
88
[packages]
99
wxpython = "*"
1010
eyed3 = "*"
11+
python-magic-bin = "*"
1112

1213
[requires]
1314
python_version = "3.7"

Pipfile.lock

+10-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main.py

+57-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import wx
22
import glob
3-
# import eyed3
3+
import eyed3
4+
5+
6+
class EditDialog(wx.Dialog):
7+
def __init__(self, mp3):
48

59

610
class Mp3Panel(wx.Panel):
@@ -17,25 +21,73 @@ def __init__(self, parent):
1721
self.list_ctrl.InsertColumn(2, 'Альбом', width=140)
1822
main_sizer.Add(self.list_ctrl, 0, wx.ALL | wx.EXPAND, 5)
1923

20-
edit_button = wx.Button(self, label='Edit')
24+
edit_button = wx.Button(self, label='Редактировать')
2125
edit_button.Bind(wx.EVT_BUTTON, self.on_edit)
2226
main_sizer.Add(edit_button, 0, wx.ALL | wx.CENTER, 5)
2327
self.SetSizer(main_sizer)
2428

2529
def on_edit(self, event):
26-
print('Редактируется')
30+
selection = self.list_ctrl.GetFocusedItem()
31+
if selection >= 0:
32+
mp3 = self.row_obj_dict[selection]
33+
dialog = EditDialog(mp3)
34+
dialog.ShowModal()
35+
self.update_mp3_listing(self.current_folder_path)
36+
dialog.Destroy()
2737

2838
def update_mp3_listing(self, folder_path):
29-
print(folder_path)
39+
self.current_folder_path = folder_path
40+
self.list_ctrl.ClearAll()
41+
42+
self.list_ctrl.InsertColumn(0, 'Название', width=200)
43+
self.list_ctrl.InsertColumn(1, 'Артист', width=140)
44+
self.list_ctrl.InsertColumn(2, 'Альбом', width=140)
45+
46+
mp3s = glob.glob(f'{folder_path}/*.mp3)')
47+
mp3_objects = []
48+
for index, mp3 in enumerate(mp3s):
49+
mp3_object = eyed3.load(mp3)
50+
self.list_ctrl.InsertItem(index, mp3_object.tag.title)
51+
self.list_ctrl.SetItem(index, 1, mp3_object.tag.artist)
52+
self.list_ctrl.SetItem(index, 2, mp3_object.tag.album)
53+
mp3_objects.append(mp3_object)
54+
self.row_obj_dict[index] = mp3_object
3055

3156

3257
class Mp3Frame(wx.Frame):
3358
def __init__(self):
34-
super().__init__(parent=None, title='Mp3 тег редактор')
59+
super().__init__(parent=None, title='Редактор тегов песен.')
3560
self.panel = Mp3Panel(self)
61+
self.create_menu()
62+
3663
# Показать фрейм
3764
self.Show()
3865

66+
def create_menu(self):
67+
menu_bar = wx.MenuBar()
68+
file_menu = wx.Menu()
69+
open_folder_menu_item = file_menu.Append(
70+
wx.ID_ANY, 'Выбрать директорию',
71+
'Открыть папку с треками'
72+
)
73+
menu_bar.Append(file_menu, '&File')
74+
75+
self.Bind(
76+
event=wx.EVT_MENU,
77+
handler=self.on_open_folder,
78+
source=open_folder_menu_item
79+
)
80+
self.SetMenuBar(menu_bar)
81+
82+
def on_open_folder(self, event):
83+
title = 'Выберите директорию'
84+
dialog = wx.DirDialog(self, title, style=wx.DD_DEFAULT_STYLE)
85+
86+
if dialog.ShowModal() == wx.ID_OK:
87+
self.panel.update_mp3_listing(dialog.GetPath())
88+
89+
dialog.Destroy()
90+
3991

4092
if __name__ == '__main__':
4193
# Инициализация приложения

0 commit comments

Comments
 (0)