22import glob
33import wx
44
5+
56class EditDialog (wx .Dialog ):
6-
77 def __init__ (self , mp3 ):
88 title = 'Editing "{title}"' .format (title = mp3 .tag .title )
99 super ().__init__ (parent = None , title = title )
10-
10+
1111 self .mp3 = mp3
12-
12+
1313 self .main_sizer = wx .BoxSizer (wx .VERTICAL )
14-
14+
1515 self .artist = wx .TextCtrl (self , value = self .mp3 .tag .artist )
16- self .add_widgets (' Artist' , self .artist )
17-
16+ self .add_widgets (" Artist" , self .artist )
17+
1818 self .album = wx .TextCtrl (self , value = self .mp3 .tag .album )
19- self .add_widgets (' Album' , self .album )
20-
19+ self .add_widgets (" Album" , self .album )
20+
2121 self .title = wx .TextCtrl (self , value = self .mp3 .tag .title )
22- self .add_widgets (' Title' , self .title )
23-
22+ self .add_widgets (" Title" , self .title )
23+
2424 btn_sizer = wx .BoxSizer ()
25- save_btn = wx .Button (self , label = ' Save' )
25+ save_btn = wx .Button (self , label = " Save" )
2626 save_btn .Bind (wx .EVT_BUTTON , self .on_save )
27-
27+
2828 btn_sizer .Add (save_btn , 0 , wx .ALL , 5 )
2929 btn_sizer .Add (wx .Button (self , id = wx .ID_CANCEL ), 0 , wx .ALL , 5 )
3030 self .main_sizer .Add (btn_sizer , 0 , wx .CENTER )
31-
31+
3232 self .SetSizer (self .main_sizer )
33-
33+
3434 def add_widgets (self , label_text , text_ctrl ):
3535 row_sizer = wx .BoxSizer (wx .HORIZONTAL )
36- label = wx .StaticText (self , label = label_text ,
37- size = (50 , - 1 ))
36+ label = wx .StaticText (self , label = label_text , size = (50 , - 1 ))
3837 row_sizer .Add (label , 0 , wx .ALL , 5 )
39- row_sizer .Add (text_ctrl , 1 , wx .ALL | wx .EXPAND , 5 )
38+ row_sizer .Add (text_ctrl , 1 , wx .ALL | wx .EXPAND , 5 )
4039 self .main_sizer .Add (row_sizer , 0 , wx .EXPAND )
41-
40+
4241 def on_save (self , event ):
4342 self .mp3 .tag .artist = self .artist .GetValue ()
4443 self .mp3 .tag .album = self .album .GetValue ()
4544 self .mp3 .tag .title = self .title .GetValue ()
4645 self .mp3 .tag .save ()
4746 self .Close ()
48-
47+
4948
5049class Mp3Panel (wx .Panel ):
51-
5250 def __init__ (self , parent ):
5351 super ().__init__ (parent )
5452 main_sizer = wx .BoxSizer (wx .VERTICAL )
5553 self .row_obj_dict = {}
5654 self .current_folder_path = None
57-
58- self .list_ctrl = wx .ListCtrl (self , size = (- 1 ,100 ),
59- style = wx .LC_REPORT
60- | wx .BORDER_SUNKEN
61- )
62- self .list_ctrl .InsertColumn (0 , 'Artist' , width = 140 )
63- self .list_ctrl .InsertColumn (1 , 'Album' , width = 140 )
64- self .list_ctrl .InsertColumn (2 , 'Title' , width = 200 )
65- self .list_ctrl .InsertColumn (3 , 'Year' , width = 200 )
66- main_sizer .Add (self .list_ctrl , 0 , wx .ALL | wx .EXPAND , 5 )
67-
68- edit_button = wx .Button (self , label = 'Edit' )
55+
56+ self .list_ctrl = wx .ListCtrl (
57+ self , size = (- 1 , 100 ), style = wx .LC_REPORT | wx .BORDER_SUNKEN
58+ )
59+ self .list_ctrl .InsertColumn (0 , "Artist" , width = 140 )
60+ self .list_ctrl .InsertColumn (1 , "Album" , width = 140 )
61+ self .list_ctrl .InsertColumn (2 , "Title" , width = 200 )
62+ self .list_ctrl .InsertColumn (3 , "Year" , width = 200 )
63+ main_sizer .Add (self .list_ctrl , 0 , wx .ALL | wx .EXPAND , 5 )
64+
65+ edit_button = wx .Button (self , label = "Edit" )
6966 edit_button .Bind (wx .EVT_BUTTON , self .on_edit )
70- main_sizer .Add (edit_button , 0 , wx .ALL | wx .CENTER , 5 )
71-
67+ main_sizer .Add (edit_button , 0 , wx .ALL | wx .CENTER , 5 )
68+
7269 self .SetSizer (main_sizer )
73-
70+
7471 def on_edit (self , event ):
7572 selection = self .list_ctrl .GetFocusedItem ()
7673 if selection >= 0 :
@@ -79,58 +76,54 @@ def on_edit(self, event):
7976 dlg .ShowModal ()
8077 self .update_mp3_listing (self .current_folder_path )
8178 dlg .Destroy ()
82-
79+
8380 def update_mp3_listing (self , folder_path ):
8481 self .current_folder_path = folder_path
8582 self .list_ctrl .ClearAll ()
86-
87- self .list_ctrl .InsertColumn (0 , ' Artist' , width = 140 )
88- self .list_ctrl .InsertColumn (1 , ' Album' , width = 140 )
89- self .list_ctrl .InsertColumn (2 , ' Title' , width = 200 )
90- self .list_ctrl .InsertColumn (3 , ' Year' , width = 200 )
91-
92- mp3s = glob .glob (folder_path + ' /*.mp3' )
83+
84+ self .list_ctrl .InsertColumn (0 , " Artist" , width = 140 )
85+ self .list_ctrl .InsertColumn (1 , " Album" , width = 140 )
86+ self .list_ctrl .InsertColumn (2 , " Title" , width = 200 )
87+ self .list_ctrl .InsertColumn (3 , " Year" , width = 200 )
88+
89+ mp3s = glob .glob (folder_path + " /*.mp3" )
9390 mp3_objects = []
9491 index = 0
9592 for mp3 in mp3s :
9693 mp3_object = eyed3 .load (mp3 )
97- self .list_ctrl .InsertItem (
98- index , mp3_object .tag .artist )
94+ self .list_ctrl .InsertItem (index , mp3_object .tag .artist )
9995 self .list_ctrl .SetItem (index , 1 , mp3_object .tag .album )
10096 self .list_ctrl .SetItem (index , 2 , mp3_object .tag .title )
10197 mp3_objects .append (mp3_object )
10298 self .row_obj_dict [index ] = mp3_object
10399 index += 1
104-
105-
100+
101+
106102class Mp3Frame (wx .Frame ):
107-
108103 def __init__ (self ):
109- super ().__init__ (parent = None , title = ' Mp3 Tag Editor' )
104+ super ().__init__ (parent = None , title = " Mp3 Tag Editor" )
110105 self .panel = Mp3Panel (self )
111106 self .create_menu ()
112107 self .Show ()
113-
108+
114109 def create_menu (self ):
115110 menu_bar = wx .MenuBar ()
116111 file_menu = wx .Menu ()
117112 open_folder_menu_item = file_menu .Append (
118- wx .NewId (), ' Open Folder' , ' Open a folder with MP3s'
113+ wx .NewId (), " Open Folder" , " Open a folder with MP3s"
119114 )
120- menu_bar .Append (file_menu , '&File' )
121- self .Bind (wx .EVT_MENU , self .on_open_folder ,
122- open_folder_menu_item )
115+ menu_bar .Append (file_menu , "&File" )
116+ self .Bind (wx .EVT_MENU , self .on_open_folder , open_folder_menu_item )
123117 self .SetMenuBar (menu_bar )
124-
118+
125119 def on_open_folder (self , event ):
126- dlg = wx .DirDialog (self , "Choose a directory:" ,
127- style = wx .DD_DEFAULT_STYLE ,
128- )
120+ dlg = wx .DirDialog (self , "Choose a directory:" , style = wx .DD_DEFAULT_STYLE )
129121 if dlg .ShowModal () == wx .ID_OK :
130122 self .panel .update_mp3_listing (dlg .GetPath ())
131123 dlg .Destroy ()
132-
133- if __name__ == '__main__' :
124+
125+
126+ if __name__ == "__main__" :
134127 app = wx .App (False )
135128 frame = Mp3Frame ()
136129 app .MainLoop ()
0 commit comments