1
1
import wx
2
2
import glob
3
- # import eyed3
3
+ import eyed3
4
+
5
+
6
+ class EditDialog (wx .Dialog ):
7
+ def __init__ (self , mp3 ):
4
8
5
9
6
10
class Mp3Panel (wx .Panel ):
@@ -17,25 +21,73 @@ def __init__(self, parent):
17
21
self .list_ctrl .InsertColumn (2 , 'Альбом' , width = 140 )
18
22
main_sizer .Add (self .list_ctrl , 0 , wx .ALL | wx .EXPAND , 5 )
19
23
20
- edit_button = wx .Button (self , label = 'Edit ' )
24
+ edit_button = wx .Button (self , label = 'Редактировать ' )
21
25
edit_button .Bind (wx .EVT_BUTTON , self .on_edit )
22
26
main_sizer .Add (edit_button , 0 , wx .ALL | wx .CENTER , 5 )
23
27
self .SetSizer (main_sizer )
24
28
25
29
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 ()
27
37
28
38
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
30
55
31
56
32
57
class Mp3Frame (wx .Frame ):
33
58
def __init__ (self ):
34
- super ().__init__ (parent = None , title = 'Mp3 тег редактор ' )
59
+ super ().__init__ (parent = None , title = 'Редактор тегов песен. ' )
35
60
self .panel = Mp3Panel (self )
61
+ self .create_menu ()
62
+
36
63
# Показать фрейм
37
64
self .Show ()
38
65
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
+
39
91
40
92
if __name__ == '__main__' :
41
93
# Инициализация приложения
0 commit comments