annotate cover2musc/cover2music.py @ 36:eb36f97db4de

bing4desktop-0.240209-0_README
author prymula <prymula76@outlook.com>
date Fri, 09 Feb 2024 23:23:59 +0100
parents dcd610585610
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
prymula <prymula76@outlook.com>
parents:
diff changeset
1 #!/usr/bin/env python3
prymula <prymula76@outlook.com>
parents:
diff changeset
2 #
prymula <prymula76@outlook.com>
parents:
diff changeset
3 # cover2music - appka do przypisywania obrazków płyt plikom ogg, oga, opus oraz mp3
prymula <prymula76@outlook.com>
parents:
diff changeset
4 # program: Przemysław R. Pietraszczyk
prymula <prymula76@outlook.com>
parents:
diff changeset
5 # rozpoczęto: 26-04-2021
prymula <prymula76@outlook.com>
parents:
diff changeset
6 # licencja: GPL
prymula <prymula76@outlook.com>
parents:
diff changeset
7 # napisano w edytorze: Atom
prymula <prymula76@outlook.com>
parents:
diff changeset
8
prymula <prymula76@outlook.com>
parents:
diff changeset
9 import gi, os
prymula <prymula76@outlook.com>
parents:
diff changeset
10 gi.require_version('Gtk', '3.0')
prymula <prymula76@outlook.com>
parents:
diff changeset
11 from gi.repository import Gtk, GdkPixbuf, GLib
prymula <prymula76@outlook.com>
parents:
diff changeset
12
prymula <prymula76@outlook.com>
parents:
diff changeset
13 import base64
prymula <prymula76@outlook.com>
parents:
diff changeset
14 from mutagen.mp3 import MP3
prymula <prymula76@outlook.com>
parents:
diff changeset
15 from mutagen.id3 import ID3, APIC, error
prymula <prymula76@outlook.com>
parents:
diff changeset
16 from mutagen.oggvorbis import OggVorbis
prymula <prymula76@outlook.com>
parents:
diff changeset
17 from mutagen.oggflac import OggFLAC
prymula <prymula76@outlook.com>
parents:
diff changeset
18 from mutagen.oggopus import OggOpus
prymula <prymula76@outlook.com>
parents:
diff changeset
19 from mutagen.flac import Picture
prymula <prymula76@outlook.com>
parents:
diff changeset
20 import mutagen
prymula <prymula76@outlook.com>
parents:
diff changeset
21
prymula <prymula76@outlook.com>
parents:
diff changeset
22 file_snd_selected=[]
prymula <prymula76@outlook.com>
parents:
diff changeset
23 file_img_selected=""
prymula <prymula76@outlook.com>
parents:
diff changeset
24
prymula <prymula76@outlook.com>
parents:
diff changeset
25 #snd_selected=[]
prymula <prymula76@outlook.com>
parents:
diff changeset
26 #COVER ="cover2music.png"
prymula <prymula76@outlook.com>
parents:
diff changeset
27 COVER ="/usr/share/pixmaps/cover2music.png"
prymula <prymula76@outlook.com>
parents:
diff changeset
28 snd_extension="ogg"
prymula <prymula76@outlook.com>
parents:
diff changeset
29 img_extension="png" # dla przykladu
prymula <prymula76@outlook.com>
parents:
diff changeset
30
prymula <prymula76@outlook.com>
parents:
diff changeset
31
prymula <prymula76@outlook.com>
parents:
diff changeset
32 UI_INFO = """
prymula <prymula76@outlook.com>
parents:
diff changeset
33 <ui>
prymula <prymula76@outlook.com>
parents:
diff changeset
34 <menubar name='MenuBar'>
prymula <prymula76@outlook.com>
parents:
diff changeset
35 <menu action='FileMenu'>
prymula <prymula76@outlook.com>
parents:
diff changeset
36 <menu action='FileLoad'>
prymula <prymula76@outlook.com>
parents:
diff changeset
37 <menuitem action='LoadImg' />
prymula <prymula76@outlook.com>
parents:
diff changeset
38 <menuitem action='LoadOgg' />
prymula <prymula76@outlook.com>
parents:
diff changeset
39 </menu>
prymula <prymula76@outlook.com>
parents:
diff changeset
40 <menu action='FileDelete'>
prymula <prymula76@outlook.com>
parents:
diff changeset
41 <menuitem action='RemoveCover' />
prymula <prymula76@outlook.com>
parents:
diff changeset
42 </menu>
prymula <prymula76@outlook.com>
parents:
diff changeset
43 <separator />
prymula <prymula76@outlook.com>
parents:
diff changeset
44 <menuitem action='FileQuit' />
prymula <prymula76@outlook.com>
parents:
diff changeset
45 </menu>
prymula <prymula76@outlook.com>
parents:
diff changeset
46
prymula <prymula76@outlook.com>
parents:
diff changeset
47 <menu action='ChoicesMenu'>
prymula <prymula76@outlook.com>
parents:
diff changeset
48 <menuitem action='ChoiceTree'/>
prymula <prymula76@outlook.com>
parents:
diff changeset
49 </menu>
prymula <prymula76@outlook.com>
parents:
diff changeset
50
prymula <prymula76@outlook.com>
parents:
diff changeset
51 <menu action='InfoMenu'>
prymula <prymula76@outlook.com>
parents:
diff changeset
52 <menuitem action='Help'/>
prymula <prymula76@outlook.com>
parents:
diff changeset
53 <menuitem action='About'/>
prymula <prymula76@outlook.com>
parents:
diff changeset
54 </menu>
prymula <prymula76@outlook.com>
parents:
diff changeset
55 </menubar>
prymula <prymula76@outlook.com>
parents:
diff changeset
56
prymula <prymula76@outlook.com>
parents:
diff changeset
57 </ui>
prymula <prymula76@outlook.com>
parents:
diff changeset
58 """
prymula <prymula76@outlook.com>
parents:
diff changeset
59
prymula <prymula76@outlook.com>
parents:
diff changeset
60
prymula <prymula76@outlook.com>
parents:
diff changeset
61 class FileChooserIMG(Gtk.Window):
prymula <prymula76@outlook.com>
parents:
diff changeset
62 def __init__(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
63 Gtk.Window.__init__(self, title="Wybór plików graficznych")
prymula <prymula76@outlook.com>
parents:
diff changeset
64 global file_img_selected
prymula <prymula76@outlook.com>
parents:
diff changeset
65
prymula <prymula76@outlook.com>
parents:
diff changeset
66 dialog = Gtk.FileChooserDialog(title="Please choose a file", parent=self, action=Gtk.FileChooserAction.OPEN)
prymula <prymula76@outlook.com>
parents:
diff changeset
67 dialog.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
68 Gtk.STOCK_CANCEL,
prymula <prymula76@outlook.com>
parents:
diff changeset
69 Gtk.ResponseType.CANCEL,
prymula <prymula76@outlook.com>
parents:
diff changeset
70 Gtk.STOCK_OPEN,
prymula <prymula76@outlook.com>
parents:
diff changeset
71 Gtk.ResponseType.OK,
prymula <prymula76@outlook.com>
parents:
diff changeset
72 )
prymula <prymula76@outlook.com>
parents:
diff changeset
73
prymula <prymula76@outlook.com>
parents:
diff changeset
74 self.add_filters(dialog)
prymula <prymula76@outlook.com>
parents:
diff changeset
75
prymula <prymula76@outlook.com>
parents:
diff changeset
76 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
77 if response == Gtk.ResponseType.OK:
prymula <prymula76@outlook.com>
parents:
diff changeset
78 print("Open clicked")
prymula <prymula76@outlook.com>
parents:
diff changeset
79 print("File selected: " + dialog.get_filename())
prymula <prymula76@outlook.com>
parents:
diff changeset
80 file_img_selected=dialog.get_filename()
prymula <prymula76@outlook.com>
parents:
diff changeset
81 elif response == Gtk.ResponseType.CANCEL:
prymula <prymula76@outlook.com>
parents:
diff changeset
82 print("Cancel clicked")
prymula <prymula76@outlook.com>
parents:
diff changeset
83
prymula <prymula76@outlook.com>
parents:
diff changeset
84 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
85
prymula <prymula76@outlook.com>
parents:
diff changeset
86 def add_filters(self, dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
87 filter_jpeg = Gtk.FileFilter()
prymula <prymula76@outlook.com>
parents:
diff changeset
88 filter_jpeg.set_name("Pliki JPEG")
prymula <prymula76@outlook.com>
parents:
diff changeset
89 filter_jpeg.add_mime_type("image/jpeg")
prymula <prymula76@outlook.com>
parents:
diff changeset
90 dialog.add_filter(filter_jpeg)
prymula <prymula76@outlook.com>
parents:
diff changeset
91
prymula <prymula76@outlook.com>
parents:
diff changeset
92 filter_png = Gtk.FileFilter()
prymula <prymula76@outlook.com>
parents:
diff changeset
93 filter_png.set_name("Pliki PNG")
prymula <prymula76@outlook.com>
parents:
diff changeset
94 filter_png.add_mime_type("image/png")
prymula <prymula76@outlook.com>
parents:
diff changeset
95 dialog.add_filter(filter_png)
prymula <prymula76@outlook.com>
parents:
diff changeset
96
prymula <prymula76@outlook.com>
parents:
diff changeset
97 class FileChooserOgg(Gtk.Window):
prymula <prymula76@outlook.com>
parents:
diff changeset
98 def __init__(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
99 Gtk.Window.__init__(self, title="Wybór plików dzwiękowych")
prymula <prymula76@outlook.com>
parents:
diff changeset
100 global file_snd_selected
prymula <prymula76@outlook.com>
parents:
diff changeset
101 dialog = Gtk.FileChooserDialog(title="Please choose a file", parent=self, action=Gtk.FileChooserAction.OPEN)
prymula <prymula76@outlook.com>
parents:
diff changeset
102 dialog.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
103 Gtk.STOCK_CANCEL,
prymula <prymula76@outlook.com>
parents:
diff changeset
104 Gtk.ResponseType.CANCEL,
prymula <prymula76@outlook.com>
parents:
diff changeset
105 Gtk.STOCK_OPEN,
prymula <prymula76@outlook.com>
parents:
diff changeset
106 Gtk.ResponseType.OK,
prymula <prymula76@outlook.com>
parents:
diff changeset
107 )
prymula <prymula76@outlook.com>
parents:
diff changeset
108
prymula <prymula76@outlook.com>
parents:
diff changeset
109 self.add_filters(dialog)
prymula <prymula76@outlook.com>
parents:
diff changeset
110 dialog.set_select_multiple(True)
prymula <prymula76@outlook.com>
parents:
diff changeset
111 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
112 if response == Gtk.ResponseType.OK:
prymula <prymula76@outlook.com>
parents:
diff changeset
113 print("Open clicked")
prymula <prymula76@outlook.com>
parents:
diff changeset
114 file_snd_selected=dialog.get_filenames()
prymula <prymula76@outlook.com>
parents:
diff changeset
115
prymula <prymula76@outlook.com>
parents:
diff changeset
116 elif response == Gtk.ResponseType.CANCEL:
prymula <prymula76@outlook.com>
parents:
diff changeset
117 print("Cancel clicked")
prymula <prymula76@outlook.com>
parents:
diff changeset
118
prymula <prymula76@outlook.com>
parents:
diff changeset
119 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
120
prymula <prymula76@outlook.com>
parents:
diff changeset
121 def add_filters(self, dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
122
prymula <prymula76@outlook.com>
parents:
diff changeset
123 filter_ogg = Gtk.FileFilter()
prymula <prymula76@outlook.com>
parents:
diff changeset
124 filter_ogg.set_name("Pliki OGG")
prymula <prymula76@outlook.com>
parents:
diff changeset
125 filter_ogg.add_mime_type("audio/ogg")
prymula <prymula76@outlook.com>
parents:
diff changeset
126 dialog.add_filter(filter_ogg)
prymula <prymula76@outlook.com>
parents:
diff changeset
127
prymula <prymula76@outlook.com>
parents:
diff changeset
128 filter_mp3 = Gtk.FileFilter()
prymula <prymula76@outlook.com>
parents:
diff changeset
129 filter_mp3.set_name("Pliki MP3")
prymula <prymula76@outlook.com>
parents:
diff changeset
130 filter_mp3.add_mime_type("audio/mp3")
prymula <prymula76@outlook.com>
parents:
diff changeset
131 dialog.add_filter(filter_mp3)
prymula <prymula76@outlook.com>
parents:
diff changeset
132
prymula <prymula76@outlook.com>
parents:
diff changeset
133
prymula <prymula76@outlook.com>
parents:
diff changeset
134 class DialogDeleteProgress(Gtk.Dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
135 def __init__(self,parent):
prymula <prymula76@outlook.com>
parents:
diff changeset
136
prymula <prymula76@outlook.com>
parents:
diff changeset
137 Gtk.Dialog.__init__(self, title="Postęp", transient_for=parent, flags=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
138 self.current_snd=0
prymula <prymula76@outlook.com>
parents:
diff changeset
139 self.props.border_width = 20
prymula <prymula76@outlook.com>
parents:
diff changeset
140 #self.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
141 # Gtk.STOCK_OK, Gtk.ResponseType.OK
prymula <prymula76@outlook.com>
parents:
diff changeset
142 #)
prymula <prymula76@outlook.com>
parents:
diff changeset
143 self.progressbar = Gtk.ProgressBar()
prymula <prymula76@outlook.com>
parents:
diff changeset
144 self.set_default_size(150, 100)
prymula <prymula76@outlook.com>
parents:
diff changeset
145 box = self.get_content_area()
prymula <prymula76@outlook.com>
parents:
diff changeset
146
prymula <prymula76@outlook.com>
parents:
diff changeset
147 label = Gtk.Label(label="Usuwam okladki z plików\n")
prymula <prymula76@outlook.com>
parents:
diff changeset
148
prymula <prymula76@outlook.com>
parents:
diff changeset
149 box.add(label)
prymula <prymula76@outlook.com>
parents:
diff changeset
150 box.add(self.progressbar)
prymula <prymula76@outlook.com>
parents:
diff changeset
151 self.divider_next=1/len(file_snd_selected)
prymula <prymula76@outlook.com>
parents:
diff changeset
152 self.timeout_id = GLib.timeout_add(300, self.on_timeout, len(file_snd_selected))
prymula <prymula76@outlook.com>
parents:
diff changeset
153 self.activity_mode = False
prymula <prymula76@outlook.com>
parents:
diff changeset
154 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
155
prymula <prymula76@outlook.com>
parents:
diff changeset
156 def on_timeout(self, user_data):
prymula <prymula76@outlook.com>
parents:
diff changeset
157
prymula <prymula76@outlook.com>
parents:
diff changeset
158 #jesli przepytano wszyskie pliki wówczas koniec
prymula <prymula76@outlook.com>
parents:
diff changeset
159 if self.current_snd == user_data:
prymula <prymula76@outlook.com>
parents:
diff changeset
160 self.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
161 Gtk.STOCK_OK, Gtk.ResponseType.OK
prymula <prymula76@outlook.com>
parents:
diff changeset
162 )
prymula <prymula76@outlook.com>
parents:
diff changeset
163 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
164 return False
prymula <prymula76@outlook.com>
parents:
diff changeset
165
prymula <prymula76@outlook.com>
parents:
diff changeset
166 if self.activity_mode:
prymula <prymula76@outlook.com>
parents:
diff changeset
167 self.progressbar.pulse()
prymula <prymula76@outlook.com>
parents:
diff changeset
168 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
169 new_value = self.progressbar.get_fraction() + self.divider_next
prymula <prymula76@outlook.com>
parents:
diff changeset
170
prymula <prymula76@outlook.com>
parents:
diff changeset
171 #if new_value > 1:
prymula <prymula76@outlook.com>
parents:
diff changeset
172 # new_value = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
173
prymula <prymula76@outlook.com>
parents:
diff changeset
174 self.progressbar.set_fraction(new_value)
prymula <prymula76@outlook.com>
parents:
diff changeset
175 snd=file_snd_selected[self.current_snd]
prymula <prymula76@outlook.com>
parents:
diff changeset
176 self.current_snd = self.current_snd +1
prymula <prymula76@outlook.com>
parents:
diff changeset
177 print ("file selected: ",snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
178 extension = os.path.splitext(snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
179 snd_extension=extension[1].replace(".", "")
prymula <prymula76@outlook.com>
parents:
diff changeset
180 print ("Rozszerzenie pliku dzwiekowego: ", snd_extension)
prymula <prymula76@outlook.com>
parents:
diff changeset
181
prymula <prymula76@outlook.com>
parents:
diff changeset
182 type=self.check_file_type(snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
183 if type == "mp3":
prymula <prymula76@outlook.com>
parents:
diff changeset
184 self.remove_cover_mp3_generic(snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
185 elif type == "ogg":
prymula <prymula76@outlook.com>
parents:
diff changeset
186 self.remove_cover_ogg_generic(snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
187 elif type == "oga":
prymula <prymula76@outlook.com>
parents:
diff changeset
188 self.remove_cover_oga_generic(snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
189 elif type == "opus":
prymula <prymula76@outlook.com>
parents:
diff changeset
190 self.remove_cover_opus_generic(snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
191
prymula <prymula76@outlook.com>
parents:
diff changeset
192 # As this is a timeout function, return True so that it
prymula <prymula76@outlook.com>
parents:
diff changeset
193 # continues to get called
prymula <prymula76@outlook.com>
parents:
diff changeset
194 return True
prymula <prymula76@outlook.com>
parents:
diff changeset
195
prymula <prymula76@outlook.com>
parents:
diff changeset
196
prymula <prymula76@outlook.com>
parents:
diff changeset
197 def check_file_type(self,snd):
prymula <prymula76@outlook.com>
parents:
diff changeset
198
prymula <prymula76@outlook.com>
parents:
diff changeset
199 magic_numbers = {'ID3v2': bytes([0x49, 0x44, 0x33]),
prymula <prymula76@outlook.com>
parents:
diff changeset
200 'ID3v1': bytes([0xFF, 0xF2]),
prymula <prymula76@outlook.com>
parents:
diff changeset
201 'ID3': bytes([0xFF, 0xF3]),
prymula <prymula76@outlook.com>
parents:
diff changeset
202 'withoutID': bytes([0xFF, 0xFB]),
prymula <prymula76@outlook.com>
parents:
diff changeset
203 'ogg': bytes([0x4F, 0x67, 0x67, 0x53])}
prymula <prymula76@outlook.com>
parents:
diff changeset
204 max_read_size = max(len(m) for m in magic_numbers.values())
prymula <prymula76@outlook.com>
parents:
diff changeset
205
prymula <prymula76@outlook.com>
parents:
diff changeset
206 with open(snd, 'rb') as fd:
prymula <prymula76@outlook.com>
parents:
diff changeset
207 file_head = fd.read()
prymula <prymula76@outlook.com>
parents:
diff changeset
208 #print(file_head)
prymula <prymula76@outlook.com>
parents:
diff changeset
209
prymula <prymula76@outlook.com>
parents:
diff changeset
210 if file_head.startswith(magic_numbers['ID3v2']):
prymula <prymula76@outlook.com>
parents:
diff changeset
211 print ("Plik MP3- z ID3v2")
prymula <prymula76@outlook.com>
parents:
diff changeset
212 return "mp3"
prymula <prymula76@outlook.com>
parents:
diff changeset
213 elif file_head.startswith(magic_numbers['ID3v1']):
prymula <prymula76@outlook.com>
parents:
diff changeset
214 print ("Plik MP3- z ID3v1")
prymula <prymula76@outlook.com>
parents:
diff changeset
215 return "mp3"
prymula <prymula76@outlook.com>
parents:
diff changeset
216 elif file_head.startswith(magic_numbers['ID3']):
prymula <prymula76@outlook.com>
parents:
diff changeset
217 print ("Plik MP3- z ID3")
prymula <prymula76@outlook.com>
parents:
diff changeset
218 return "mp3"
prymula <prymula76@outlook.com>
parents:
diff changeset
219 elif file_head.startswith(magic_numbers['withoutID']):
prymula <prymula76@outlook.com>
parents:
diff changeset
220 print ("Plik MP3 bez ID3")
prymula <prymula76@outlook.com>
parents:
diff changeset
221 return "mp3"
prymula <prymula76@outlook.com>
parents:
diff changeset
222 elif file_head.startswith(magic_numbers['ogg']):
prymula <prymula76@outlook.com>
parents:
diff changeset
223 print("Kontener OGG")
prymula <prymula76@outlook.com>
parents:
diff changeset
224 ogg_head=mutagen.File(snd).pprint()[0:20]
prymula <prymula76@outlook.com>
parents:
diff changeset
225
prymula <prymula76@outlook.com>
parents:
diff changeset
226 if 'opus' in ogg_head.lower():
prymula <prymula76@outlook.com>
parents:
diff changeset
227 return "opus"
prymula <prymula76@outlook.com>
parents:
diff changeset
228 elif 'flac' in ogg_head.lower():
prymula <prymula76@outlook.com>
parents:
diff changeset
229 return "oga"
prymula <prymula76@outlook.com>
parents:
diff changeset
230 elif 'vorbis'in ogg_head.lower():
prymula <prymula76@outlook.com>
parents:
diff changeset
231 return "ogg"
prymula <prymula76@outlook.com>
parents:
diff changeset
232
prymula <prymula76@outlook.com>
parents:
diff changeset
233
prymula <prymula76@outlook.com>
parents:
diff changeset
234
prymula <prymula76@outlook.com>
parents:
diff changeset
235
prymula <prymula76@outlook.com>
parents:
diff changeset
236 def remove_cover_mp3_generic(self,snd):
prymula <prymula76@outlook.com>
parents:
diff changeset
237
prymula <prymula76@outlook.com>
parents:
diff changeset
238 file = ID3(snd) # Load the file
prymula <prymula76@outlook.com>
parents:
diff changeset
239 file.delall("APIC") # Delete every APIC tag (Cover art)
prymula <prymula76@outlook.com>
parents:
diff changeset
240 file.save() # Save the file
prymula <prymula76@outlook.com>
parents:
diff changeset
241
prymula <prymula76@outlook.com>
parents:
diff changeset
242 def remove_cover_ogg_generic(self,snd):
prymula <prymula76@outlook.com>
parents:
diff changeset
243
prymula <prymula76@outlook.com>
parents:
diff changeset
244 file = OggVorbis(snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
245 try:
prymula <prymula76@outlook.com>
parents:
diff changeset
246 artist=file["artist"]
prymula <prymula76@outlook.com>
parents:
diff changeset
247 except KeyError:
prymula <prymula76@outlook.com>
parents:
diff changeset
248 artist=""
prymula <prymula76@outlook.com>
parents:
diff changeset
249 try:
prymula <prymula76@outlook.com>
parents:
diff changeset
250 title=file["title"]
prymula <prymula76@outlook.com>
parents:
diff changeset
251 except KeyError:
prymula <prymula76@outlook.com>
parents:
diff changeset
252 title=""
prymula <prymula76@outlook.com>
parents:
diff changeset
253 try:
prymula <prymula76@outlook.com>
parents:
diff changeset
254 year=file["year_of_relase"]
prymula <prymula76@outlook.com>
parents:
diff changeset
255 except KeyError:
prymula <prymula76@outlook.com>
parents:
diff changeset
256 year=""
prymula <prymula76@outlook.com>
parents:
diff changeset
257 try:
prymula <prymula76@outlook.com>
parents:
diff changeset
258 album=file["album"]
prymula <prymula76@outlook.com>
parents:
diff changeset
259 except KeyError:
prymula <prymula76@outlook.com>
parents:
diff changeset
260 album=""
prymula <prymula76@outlook.com>
parents:
diff changeset
261 try:
prymula <prymula76@outlook.com>
parents:
diff changeset
262 genre=file["genre"]
prymula <prymula76@outlook.com>
parents:
diff changeset
263 except KeyError:
prymula <prymula76@outlook.com>
parents:
diff changeset
264 genre=""
prymula <prymula76@outlook.com>
parents:
diff changeset
265
prymula <prymula76@outlook.com>
parents:
diff changeset
266 file.delete()
prymula <prymula76@outlook.com>
parents:
diff changeset
267 file["year_of_relase"]=year
prymula <prymula76@outlook.com>
parents:
diff changeset
268 file["artist"]=artist
prymula <prymula76@outlook.com>
parents:
diff changeset
269 file["title"]=title
prymula <prymula76@outlook.com>
parents:
diff changeset
270 file["album"]=album
prymula <prymula76@outlook.com>
parents:
diff changeset
271 file["genre"]=genre
prymula <prymula76@outlook.com>
parents:
diff changeset
272 file.save()
prymula <prymula76@outlook.com>
parents:
diff changeset
273
prymula <prymula76@outlook.com>
parents:
diff changeset
274 def remove_cover_oga_generic(self,snd):
prymula <prymula76@outlook.com>
parents:
diff changeset
275
prymula <prymula76@outlook.com>
parents:
diff changeset
276 file = OggFLAC(snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
277 try:
prymula <prymula76@outlook.com>
parents:
diff changeset
278 artist=file["artist"]
prymula <prymula76@outlook.com>
parents:
diff changeset
279 except KeyError:
prymula <prymula76@outlook.com>
parents:
diff changeset
280 artist=""
prymula <prymula76@outlook.com>
parents:
diff changeset
281 try:
prymula <prymula76@outlook.com>
parents:
diff changeset
282 title=file["title"]
prymula <prymula76@outlook.com>
parents:
diff changeset
283 except KeyError:
prymula <prymula76@outlook.com>
parents:
diff changeset
284 title=""
prymula <prymula76@outlook.com>
parents:
diff changeset
285 try:
prymula <prymula76@outlook.com>
parents:
diff changeset
286 year=file["year_of_relase"]
prymula <prymula76@outlook.com>
parents:
diff changeset
287 except KeyError:
prymula <prymula76@outlook.com>
parents:
diff changeset
288 year=""
prymula <prymula76@outlook.com>
parents:
diff changeset
289 try:
prymula <prymula76@outlook.com>
parents:
diff changeset
290 album=file["album"]
prymula <prymula76@outlook.com>
parents:
diff changeset
291 except KeyError:
prymula <prymula76@outlook.com>
parents:
diff changeset
292 album=""
prymula <prymula76@outlook.com>
parents:
diff changeset
293 try:
prymula <prymula76@outlook.com>
parents:
diff changeset
294 genre=file["genre"]
prymula <prymula76@outlook.com>
parents:
diff changeset
295 except KeyError:
prymula <prymula76@outlook.com>
parents:
diff changeset
296 genre=""
prymula <prymula76@outlook.com>
parents:
diff changeset
297
prymula <prymula76@outlook.com>
parents:
diff changeset
298 file.delete()
prymula <prymula76@outlook.com>
parents:
diff changeset
299 file["year_of_relase"]=year
prymula <prymula76@outlook.com>
parents:
diff changeset
300 file["artist"]=artist
prymula <prymula76@outlook.com>
parents:
diff changeset
301 file["title"]=title
prymula <prymula76@outlook.com>
parents:
diff changeset
302 file["album"]=album
prymula <prymula76@outlook.com>
parents:
diff changeset
303 file["genre"]=genre
prymula <prymula76@outlook.com>
parents:
diff changeset
304 file.save()
prymula <prymula76@outlook.com>
parents:
diff changeset
305
prymula <prymula76@outlook.com>
parents:
diff changeset
306 def remove_cover_opus_generic(self,snd):
prymula <prymula76@outlook.com>
parents:
diff changeset
307
prymula <prymula76@outlook.com>
parents:
diff changeset
308 file = OggOpus(snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
309 #year=file["YEAR_OF_RELEASE"]
prymula <prymula76@outlook.com>
parents:
diff changeset
310 try:
prymula <prymula76@outlook.com>
parents:
diff changeset
311 artist=file["artist"]
prymula <prymula76@outlook.com>
parents:
diff changeset
312 except KeyError:
prymula <prymula76@outlook.com>
parents:
diff changeset
313 artist=""
prymula <prymula76@outlook.com>
parents:
diff changeset
314 try:
prymula <prymula76@outlook.com>
parents:
diff changeset
315 title=file["title"]
prymula <prymula76@outlook.com>
parents:
diff changeset
316 except KeyError:
prymula <prymula76@outlook.com>
parents:
diff changeset
317 title=""
prymula <prymula76@outlook.com>
parents:
diff changeset
318 try:
prymula <prymula76@outlook.com>
parents:
diff changeset
319 year=file["year_of_relase"]
prymula <prymula76@outlook.com>
parents:
diff changeset
320 except KeyError:
prymula <prymula76@outlook.com>
parents:
diff changeset
321 year=""
prymula <prymula76@outlook.com>
parents:
diff changeset
322 try:
prymula <prymula76@outlook.com>
parents:
diff changeset
323 album=file["album"]
prymula <prymula76@outlook.com>
parents:
diff changeset
324 except KeyError:
prymula <prymula76@outlook.com>
parents:
diff changeset
325 album=""
prymula <prymula76@outlook.com>
parents:
diff changeset
326 try:
prymula <prymula76@outlook.com>
parents:
diff changeset
327 genre=file["genre"]
prymula <prymula76@outlook.com>
parents:
diff changeset
328 except KeyError:
prymula <prymula76@outlook.com>
parents:
diff changeset
329 genre=""
prymula <prymula76@outlook.com>
parents:
diff changeset
330
prymula <prymula76@outlook.com>
parents:
diff changeset
331 file.delete()
prymula <prymula76@outlook.com>
parents:
diff changeset
332 file["year_of_relase"]=year
prymula <prymula76@outlook.com>
parents:
diff changeset
333 file["artist"]=artist
prymula <prymula76@outlook.com>
parents:
diff changeset
334 file["title"]=title
prymula <prymula76@outlook.com>
parents:
diff changeset
335 file["album"]=album
prymula <prymula76@outlook.com>
parents:
diff changeset
336 file["genre"]=genre
prymula <prymula76@outlook.com>
parents:
diff changeset
337 file.save()
prymula <prymula76@outlook.com>
parents:
diff changeset
338
prymula <prymula76@outlook.com>
parents:
diff changeset
339
prymula <prymula76@outlook.com>
parents:
diff changeset
340 class DialogAddCoverProgress(Gtk.Dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
341 def __init__(self,parent):
prymula <prymula76@outlook.com>
parents:
diff changeset
342
prymula <prymula76@outlook.com>
parents:
diff changeset
343 Gtk.Dialog.__init__(self, title="Postęp", transient_for=parent, flags=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
344 self.current_snd=0
prymula <prymula76@outlook.com>
parents:
diff changeset
345 self.props.border_width = 20
prymula <prymula76@outlook.com>
parents:
diff changeset
346 #self.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
347 # Gtk.STOCK_OK, Gtk.ResponseType.OK
prymula <prymula76@outlook.com>
parents:
diff changeset
348 #)
prymula <prymula76@outlook.com>
parents:
diff changeset
349 self.progressbar = Gtk.ProgressBar()
prymula <prymula76@outlook.com>
parents:
diff changeset
350 self.set_default_size(150, 100)
prymula <prymula76@outlook.com>
parents:
diff changeset
351 box = self.get_content_area()
prymula <prymula76@outlook.com>
parents:
diff changeset
352
prymula <prymula76@outlook.com>
parents:
diff changeset
353 label = Gtk.Label(label="Dodaję okladkę do plików\n")
prymula <prymula76@outlook.com>
parents:
diff changeset
354
prymula <prymula76@outlook.com>
parents:
diff changeset
355 box.add(label)
prymula <prymula76@outlook.com>
parents:
diff changeset
356 box.add(self.progressbar)
prymula <prymula76@outlook.com>
parents:
diff changeset
357
prymula <prymula76@outlook.com>
parents:
diff changeset
358 self.divider_next=1/len(file_snd_selected)
prymula <prymula76@outlook.com>
parents:
diff changeset
359 self.timeout_id = GLib.timeout_add(300, self.on_timeout, len(file_snd_selected))
prymula <prymula76@outlook.com>
parents:
diff changeset
360 self.activity_mode = False
prymula <prymula76@outlook.com>
parents:
diff changeset
361 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
362
prymula <prymula76@outlook.com>
parents:
diff changeset
363 def on_timeout(self, user_data):
prymula <prymula76@outlook.com>
parents:
diff changeset
364 global img_extension
prymula <prymula76@outlook.com>
parents:
diff changeset
365 #jesli przepytano wszyskie pliki wówczas koniec
prymula <prymula76@outlook.com>
parents:
diff changeset
366 if self.current_snd == user_data:
prymula <prymula76@outlook.com>
parents:
diff changeset
367 self.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
368 Gtk.STOCK_OK, Gtk.ResponseType.OK
prymula <prymula76@outlook.com>
parents:
diff changeset
369 )
prymula <prymula76@outlook.com>
parents:
diff changeset
370 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
371 return False
prymula <prymula76@outlook.com>
parents:
diff changeset
372
prymula <prymula76@outlook.com>
parents:
diff changeset
373 if self.activity_mode:
prymula <prymula76@outlook.com>
parents:
diff changeset
374 self.progressbar.pulse()
prymula <prymula76@outlook.com>
parents:
diff changeset
375 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
376 new_value = self.progressbar.get_fraction() + self.divider_next
prymula <prymula76@outlook.com>
parents:
diff changeset
377
prymula <prymula76@outlook.com>
parents:
diff changeset
378 #if new_value > 1:
prymula <prymula76@outlook.com>
parents:
diff changeset
379 # new_value = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
380
prymula <prymula76@outlook.com>
parents:
diff changeset
381 self.progressbar.set_fraction(new_value)
prymula <prymula76@outlook.com>
parents:
diff changeset
382 snd=file_snd_selected[self.current_snd]
prymula <prymula76@outlook.com>
parents:
diff changeset
383 self.current_snd = self.current_snd +1
prymula <prymula76@outlook.com>
parents:
diff changeset
384 print ("file selected: ",snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
385 extension = os.path.splitext(snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
386 snd_extension=extension[1].replace(".", "")
prymula <prymula76@outlook.com>
parents:
diff changeset
387 print ("Rozszerzenie pliku dzwiekowego: ", snd_extension)
prymula <prymula76@outlook.com>
parents:
diff changeset
388
prymula <prymula76@outlook.com>
parents:
diff changeset
389
prymula <prymula76@outlook.com>
parents:
diff changeset
390 #print ("file selected: ",snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
391 #extension = os.path.splitext(snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
392 #snd_extension=extension[1].replace(".", "")
prymula <prymula76@outlook.com>
parents:
diff changeset
393 #print ("Rozszerzenie pliku dzwiekowego: ", snd_extension)
prymula <prymula76@outlook.com>
parents:
diff changeset
394
prymula <prymula76@outlook.com>
parents:
diff changeset
395 if snd_extension.lower() == "ogg":
prymula <prymula76@outlook.com>
parents:
diff changeset
396
prymula <prymula76@outlook.com>
parents:
diff changeset
397 file_ = OggVorbis(snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
398 print("IMAGE FILE: ",file_img_selected)
prymula <prymula76@outlook.com>
parents:
diff changeset
399 with open(file_img_selected, "rb") as h:
prymula <prymula76@outlook.com>
parents:
diff changeset
400 data = h.read()
prymula <prymula76@outlook.com>
parents:
diff changeset
401
prymula <prymula76@outlook.com>
parents:
diff changeset
402 img_extension=img_extension.lower()
prymula <prymula76@outlook.com>
parents:
diff changeset
403 picture = Picture()
prymula <prymula76@outlook.com>
parents:
diff changeset
404 picture.data = data
prymula <prymula76@outlook.com>
parents:
diff changeset
405 picture.type = 17
prymula <prymula76@outlook.com>
parents:
diff changeset
406 picture.desc = u"Picture set by cover2music"
prymula <prymula76@outlook.com>
parents:
diff changeset
407 picture.mime = u"image/"+img_extension
prymula <prymula76@outlook.com>
parents:
diff changeset
408 picture.width = 100
prymula <prymula76@outlook.com>
parents:
diff changeset
409 picture.height = 100
prymula <prymula76@outlook.com>
parents:
diff changeset
410 picture.depth = 24
prymula <prymula76@outlook.com>
parents:
diff changeset
411
prymula <prymula76@outlook.com>
parents:
diff changeset
412 picture_data = picture.write()
prymula <prymula76@outlook.com>
parents:
diff changeset
413 encoded_data = base64.b64encode(picture_data)
prymula <prymula76@outlook.com>
parents:
diff changeset
414 vcomment_value = encoded_data.decode("ascii")
prymula <prymula76@outlook.com>
parents:
diff changeset
415
prymula <prymula76@outlook.com>
parents:
diff changeset
416 file_["metadata_block_picture"] = [vcomment_value]
prymula <prymula76@outlook.com>
parents:
diff changeset
417 file_.save()
prymula <prymula76@outlook.com>
parents:
diff changeset
418
prymula <prymula76@outlook.com>
parents:
diff changeset
419 elif snd_extension.lower() == "oga":
prymula <prymula76@outlook.com>
parents:
diff changeset
420
prymula <prymula76@outlook.com>
parents:
diff changeset
421 #for snd in file_snd_selected:
prymula <prymula76@outlook.com>
parents:
diff changeset
422 file_ = OggFLAC(snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
423 print("IMAGE FILE: ",file_img_selected)
prymula <prymula76@outlook.com>
parents:
diff changeset
424 with open(file_img_selected, "rb") as h:
prymula <prymula76@outlook.com>
parents:
diff changeset
425 data = h.read()
prymula <prymula76@outlook.com>
parents:
diff changeset
426
prymula <prymula76@outlook.com>
parents:
diff changeset
427 img_extension=img_extension.lower()
prymula <prymula76@outlook.com>
parents:
diff changeset
428 picture = Picture()
prymula <prymula76@outlook.com>
parents:
diff changeset
429 picture.data = data
prymula <prymula76@outlook.com>
parents:
diff changeset
430 picture.type = 17 # 0x7f
prymula <prymula76@outlook.com>
parents:
diff changeset
431 picture.desc = u"Picture set by cover2music"
prymula <prymula76@outlook.com>
parents:
diff changeset
432 picture.mime = u"image/"+img_extension
prymula <prymula76@outlook.com>
parents:
diff changeset
433 picture.width = 100
prymula <prymula76@outlook.com>
parents:
diff changeset
434 picture.height = 100
prymula <prymula76@outlook.com>
parents:
diff changeset
435 picture.depth = 24
prymula <prymula76@outlook.com>
parents:
diff changeset
436
prymula <prymula76@outlook.com>
parents:
diff changeset
437 picture_data = picture.write()
prymula <prymula76@outlook.com>
parents:
diff changeset
438 encoded_data = base64.b64encode(picture_data)
prymula <prymula76@outlook.com>
parents:
diff changeset
439 vcomment_value = encoded_data.decode("ascii")
prymula <prymula76@outlook.com>
parents:
diff changeset
440
prymula <prymula76@outlook.com>
parents:
diff changeset
441 file_["metadata_block_picture"] = [vcomment_value]
prymula <prymula76@outlook.com>
parents:
diff changeset
442 file_.save()
prymula <prymula76@outlook.com>
parents:
diff changeset
443
prymula <prymula76@outlook.com>
parents:
diff changeset
444
prymula <prymula76@outlook.com>
parents:
diff changeset
445 elif snd_extension.lower() == "opus":
prymula <prymula76@outlook.com>
parents:
diff changeset
446
prymula <prymula76@outlook.com>
parents:
diff changeset
447 #for snd in file_snd_selected:
prymula <prymula76@outlook.com>
parents:
diff changeset
448 file_ = OggOpus(snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
449 print("IMAGE FILE: ",file_img_selected)
prymula <prymula76@outlook.com>
parents:
diff changeset
450 with open(file_img_selected, "rb") as h:
prymula <prymula76@outlook.com>
parents:
diff changeset
451 data = h.read()
prymula <prymula76@outlook.com>
parents:
diff changeset
452
prymula <prymula76@outlook.com>
parents:
diff changeset
453 img_extension=img_extension.lower()
prymula <prymula76@outlook.com>
parents:
diff changeset
454 picture = Picture()
prymula <prymula76@outlook.com>
parents:
diff changeset
455 picture.data = data
prymula <prymula76@outlook.com>
parents:
diff changeset
456 picture.type = 17 # 0x7f
prymula <prymula76@outlook.com>
parents:
diff changeset
457 picture.desc = u"Picture set by cover2music"
prymula <prymula76@outlook.com>
parents:
diff changeset
458 picture.mime = u"image/"+img_extension
prymula <prymula76@outlook.com>
parents:
diff changeset
459 #picture.width = 100
prymula <prymula76@outlook.com>
parents:
diff changeset
460 #picture.height = 100
prymula <prymula76@outlook.com>
parents:
diff changeset
461 #picture.depth = 24
prymula <prymula76@outlook.com>
parents:
diff changeset
462
prymula <prymula76@outlook.com>
parents:
diff changeset
463 picture_data = picture.write()
prymula <prymula76@outlook.com>
parents:
diff changeset
464 encoded_data = base64.b64encode(picture_data)
prymula <prymula76@outlook.com>
parents:
diff changeset
465 vcomment_value = encoded_data.decode("ascii")
prymula <prymula76@outlook.com>
parents:
diff changeset
466
prymula <prymula76@outlook.com>
parents:
diff changeset
467 file_["metadata_block_picture"] = [vcomment_value]
prymula <prymula76@outlook.com>
parents:
diff changeset
468 file_.save()
prymula <prymula76@outlook.com>
parents:
diff changeset
469
prymula <prymula76@outlook.com>
parents:
diff changeset
470 elif snd_extension.lower() == "mp3":
prymula <prymula76@outlook.com>
parents:
diff changeset
471 #for snd in file_snd_selected:
prymula <prymula76@outlook.com>
parents:
diff changeset
472 print ("Dodaje do mp3: ",snd)
prymula <prymula76@outlook.com>
parents:
diff changeset
473 print ("file_img_selected: ", file_img_selected)
prymula <prymula76@outlook.com>
parents:
diff changeset
474 file = MP3(snd, ID3=ID3)
prymula <prymula76@outlook.com>
parents:
diff changeset
475
prymula <prymula76@outlook.com>
parents:
diff changeset
476 try:
prymula <prymula76@outlook.com>
parents:
diff changeset
477 file.add_tags()
prymula <prymula76@outlook.com>
parents:
diff changeset
478 except error:
prymula <prymula76@outlook.com>
parents:
diff changeset
479 pass
prymula <prymula76@outlook.com>
parents:
diff changeset
480
prymula <prymula76@outlook.com>
parents:
diff changeset
481 file.tags.add(APIC(mime="image/"+img_extension,type=3,desc=u'Cove by cover2music',data=open(file_img_selected,'rb').read()))
prymula <prymula76@outlook.com>
parents:
diff changeset
482 file.save() # save the current changes
prymula <prymula76@outlook.com>
parents:
diff changeset
483
prymula <prymula76@outlook.com>
parents:
diff changeset
484 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
485 print ("źle")
prymula <prymula76@outlook.com>
parents:
diff changeset
486
prymula <prymula76@outlook.com>
parents:
diff changeset
487 # As this is a timeout function, return True so that it
prymula <prymula76@outlook.com>
parents:
diff changeset
488 # continues to get called
prymula <prymula76@outlook.com>
parents:
diff changeset
489 return True
prymula <prymula76@outlook.com>
parents:
diff changeset
490
prymula <prymula76@outlook.com>
parents:
diff changeset
491
prymula <prymula76@outlook.com>
parents:
diff changeset
492
prymula <prymula76@outlook.com>
parents:
diff changeset
493 class DialogHelp(Gtk.Dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
494 def __init__(self, parent):
prymula <prymula76@outlook.com>
parents:
diff changeset
495 Gtk.Dialog.__init__(self, title="Pomoc", transient_for=parent, flags=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
496 self.props.border_width = 20
prymula <prymula76@outlook.com>
parents:
diff changeset
497 self.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
498 Gtk.STOCK_OK, Gtk.ResponseType.OK
prymula <prymula76@outlook.com>
parents:
diff changeset
499 )
prymula <prymula76@outlook.com>
parents:
diff changeset
500
prymula <prymula76@outlook.com>
parents:
diff changeset
501 self.set_default_size(150, 100)
prymula <prymula76@outlook.com>
parents:
diff changeset
502 txt="-jednak samo załadownie obrazka do pliku nie gwarantuje, że zmieni się ikona w menedżerze plików.\n W tym względzie są przyjazne menedżery takie jak PCManFM, jak i nieprzyjazne jak Nemo.\n Jednak w graficznym odtwarzaczu, załadowany obrazek powinien pojawić się zawsze\n\n"
prymula <prymula76@outlook.com>
parents:
diff changeset
503 label1 = Gtk.Label(label="Aplikacja jest w stanie dodać okładkę do prawie wszystkich plików MP3, oraz do plików OGG (Vorbis),\n OGA (OGG FLAC) oraz OPUS. Możliwe jest również usuwanie okładek z pozostawieniem pozostałych tagów.\n Pliki można zmieniać pojedynczo jak i grupowo. Okładki odczytywane są w formatach JPEG oraz PNG.\n Należy zadbać wcześniej aby obrazy okładek nie były zbyt duże, optymalna wielkość to 384x384 px.\n\n")
prymula <prymula76@outlook.com>
parents:
diff changeset
504 label2 = Gtk.Label(label=" Uwagi:\n-format JPEG w plikach OPUS nie jest wspierany \n-mieszana kolekcja plików zakodowanych rożnymi kodekami w kontenerach OGG jest co prawda możliwa,\n jednak skrypt może zachowywać się niestabilnie\n"+txt)
prymula <prymula76@outlook.com>
parents:
diff changeset
505 box = self.get_content_area()
prymula <prymula76@outlook.com>
parents:
diff changeset
506 box.add(label1)
prymula <prymula76@outlook.com>
parents:
diff changeset
507 box.add(label2)
prymula <prymula76@outlook.com>
parents:
diff changeset
508 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
509
prymula <prymula76@outlook.com>
parents:
diff changeset
510 class DialogAbout(Gtk.Dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
511 def __init__(self, parent):
prymula <prymula76@outlook.com>
parents:
diff changeset
512 Gtk.Dialog.__init__(self, title="O Programie", transient_for=parent, flags=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
513 self.props.border_width = 20
prymula <prymula76@outlook.com>
parents:
diff changeset
514 self.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
515 Gtk.STOCK_OK, Gtk.ResponseType.OK
prymula <prymula76@outlook.com>
parents:
diff changeset
516 )
prymula <prymula76@outlook.com>
parents:
diff changeset
517
prymula <prymula76@outlook.com>
parents:
diff changeset
518 self.set_default_size(150, 100)
prymula <prymula76@outlook.com>
parents:
diff changeset
519
prymula <prymula76@outlook.com>
parents:
diff changeset
520 label = Gtk.Label(label="\tAplikacja napisana na podstawie:\n\nhttps://python-gtk-3-tutorial.readthedocs.io/\n\n\t\t\tWersja: 0.1-3\n\n\t\tPrzemysław R. Pietraszczyk\n\n\t\t\tKwiecień/Maj 2021\n\t\t\tLicencja: GPL\n\n")
prymula <prymula76@outlook.com>
parents:
diff changeset
521 #label3 = Gtk.Label(label="-jednak samo załadownie obrazka do pliku nie gwarantuje, że zmieni się ikona w menedżerze plików.\n W tym względzie są przyjazne menedżery takie jak PCManFM, jak i nie przyjazne jak Nemo.\n Jednak w graficznym odtwarzaczu, załadowany obrazek powinien pojawić się zawsze.\n\n")
prymula <prymula76@outlook.com>
parents:
diff changeset
522
prymula <prymula76@outlook.com>
parents:
diff changeset
523 box = self.get_content_area()
prymula <prymula76@outlook.com>
parents:
diff changeset
524 box.add(label)
prymula <prymula76@outlook.com>
parents:
diff changeset
525
prymula <prymula76@outlook.com>
parents:
diff changeset
526 button = Gtk.LinkButton("http://www.prp.xlx.pl", label="Strona Domowa")
prymula <prymula76@outlook.com>
parents:
diff changeset
527 box.add(button)
prymula <prymula76@outlook.com>
parents:
diff changeset
528
prymula <prymula76@outlook.com>
parents:
diff changeset
529 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
530
prymula <prymula76@outlook.com>
parents:
diff changeset
531 class DialogNoSelectIMG(Gtk.Dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
532 def __init__(self, parent):
prymula <prymula76@outlook.com>
parents:
diff changeset
533 Gtk.Dialog.__init__(self, title="Błąd", transient_for=parent, flags=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
534 self.props.border_width = 20
prymula <prymula76@outlook.com>
parents:
diff changeset
535 self.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
536 Gtk.STOCK_OK, Gtk.ResponseType.OK
prymula <prymula76@outlook.com>
parents:
diff changeset
537 )
prymula <prymula76@outlook.com>
parents:
diff changeset
538
prymula <prymula76@outlook.com>
parents:
diff changeset
539 self.set_default_size(150, 100)
prymula <prymula76@outlook.com>
parents:
diff changeset
540
prymula <prymula76@outlook.com>
parents:
diff changeset
541 label = Gtk.Label(label="Nie wybrano żadnego pliku z muzyką!\n")
prymula <prymula76@outlook.com>
parents:
diff changeset
542
prymula <prymula76@outlook.com>
parents:
diff changeset
543 box = self.get_content_area()
prymula <prymula76@outlook.com>
parents:
diff changeset
544 box.add(label)
prymula <prymula76@outlook.com>
parents:
diff changeset
545
prymula <prymula76@outlook.com>
parents:
diff changeset
546 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
547
prymula <prymula76@outlook.com>
parents:
diff changeset
548 def get_resource_path(rel_path):
prymula <prymula76@outlook.com>
parents:
diff changeset
549 dir_of_py_file = os.path.dirname(__file__)
prymula <prymula76@outlook.com>
parents:
diff changeset
550 rel_path_to_resource = os.path.join(dir_of_py_file, rel_path)
prymula <prymula76@outlook.com>
parents:
diff changeset
551 abs_path_to_resource = os.path.abspath(rel_path_to_resource)
prymula <prymula76@outlook.com>
parents:
diff changeset
552 return abs_path_to_resource
prymula <prymula76@outlook.com>
parents:
diff changeset
553
prymula <prymula76@outlook.com>
parents:
diff changeset
554
prymula <prymula76@outlook.com>
parents:
diff changeset
555 grid = Gtk.Grid()
prymula <prymula76@outlook.com>
parents:
diff changeset
556
prymula <prymula76@outlook.com>
parents:
diff changeset
557
prymula <prymula76@outlook.com>
parents:
diff changeset
558 class MyWindow(Gtk.Window):
prymula <prymula76@outlook.com>
parents:
diff changeset
559
prymula <prymula76@outlook.com>
parents:
diff changeset
560 def __init__(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
561 super().__init__()
prymula <prymula76@outlook.com>
parents:
diff changeset
562
prymula <prymula76@outlook.com>
parents:
diff changeset
563 self.init_ui()
prymula <prymula76@outlook.com>
parents:
diff changeset
564
prymula <prymula76@outlook.com>
parents:
diff changeset
565
prymula <prymula76@outlook.com>
parents:
diff changeset
566 def init_ui(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
567 global grid, file_img_selected, snd_extension
prymula <prymula76@outlook.com>
parents:
diff changeset
568 self.image_new=None
prymula <prymula76@outlook.com>
parents:
diff changeset
569 #grid = Gtk.Grid()
prymula <prymula76@outlook.com>
parents:
diff changeset
570 self.props.border_width = 20
prymula <prymula76@outlook.com>
parents:
diff changeset
571 #self.img_extension="png" # dla przykladu
prymula <prymula76@outlook.com>
parents:
diff changeset
572 #snd_extension="ogg"
prymula <prymula76@outlook.com>
parents:
diff changeset
573
prymula <prymula76@outlook.com>
parents:
diff changeset
574 self.add(grid)
prymula <prymula76@outlook.com>
parents:
diff changeset
575
prymula <prymula76@outlook.com>
parents:
diff changeset
576 grid.set_row_spacing(10)
prymula <prymula76@outlook.com>
parents:
diff changeset
577 grid.set_column_spacing(10)
prymula <prymula76@outlook.com>
parents:
diff changeset
578 grid.set_column_homogeneous(True) # rozszerza kontrolke z utworami na resztę okna
prymula <prymula76@outlook.com>
parents:
diff changeset
579
prymula <prymula76@outlook.com>
parents:
diff changeset
580 action_group = Gtk.ActionGroup(name="my_actions")
prymula <prymula76@outlook.com>
parents:
diff changeset
581
prymula <prymula76@outlook.com>
parents:
diff changeset
582 self.add_file_menu_actions(action_group)
prymula <prymula76@outlook.com>
parents:
diff changeset
583 self.add_info_menu_actions(action_group)
prymula <prymula76@outlook.com>
parents:
diff changeset
584 self.add_choices_menu_actions(action_group)
prymula <prymula76@outlook.com>
parents:
diff changeset
585
prymula <prymula76@outlook.com>
parents:
diff changeset
586 uimanager = self.create_ui_manager()
prymula <prymula76@outlook.com>
parents:
diff changeset
587 uimanager.insert_action_group(action_group)
prymula <prymula76@outlook.com>
parents:
diff changeset
588
prymula <prymula76@outlook.com>
parents:
diff changeset
589 menubar = uimanager.get_widget("/MenuBar")
prymula <prymula76@outlook.com>
parents:
diff changeset
590
prymula <prymula76@outlook.com>
parents:
diff changeset
591 box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
prymula <prymula76@outlook.com>
parents:
diff changeset
592 box.pack_start(menubar, False, False, 0)
prymula <prymula76@outlook.com>
parents:
diff changeset
593
prymula <prymula76@outlook.com>
parents:
diff changeset
594 grid.attach(box, 0, 0, 2, 1)
prymula <prymula76@outlook.com>
parents:
diff changeset
595 file_img_selected=get_resource_path(COVER)
prymula <prymula76@outlook.com>
parents:
diff changeset
596 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
prymula <prymula76@outlook.com>
parents:
diff changeset
597 filename=file_img_selected,
prymula <prymula76@outlook.com>
parents:
diff changeset
598 width=100,
prymula <prymula76@outlook.com>
parents:
diff changeset
599 height=100,
prymula <prymula76@outlook.com>
parents:
diff changeset
600 preserve_aspect_ratio=True)
prymula <prymula76@outlook.com>
parents:
diff changeset
601
prymula <prymula76@outlook.com>
parents:
diff changeset
602 self.image = Gtk.Image.new_from_pixbuf(pixbuf)
prymula <prymula76@outlook.com>
parents:
diff changeset
603 grid.attach(self.image,0,1,1,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
604
prymula <prymula76@outlook.com>
parents:
diff changeset
605 quitBtn = Gtk.Button(label="Wykonaj !")
prymula <prymula76@outlook.com>
parents:
diff changeset
606 quitBtn.set_size_request(60, 30)
prymula <prymula76@outlook.com>
parents:
diff changeset
607
prymula <prymula76@outlook.com>
parents:
diff changeset
608 quitBtn.connect("clicked", self.on_button_clicked)
prymula <prymula76@outlook.com>
parents:
diff changeset
609
prymula <prymula76@outlook.com>
parents:
diff changeset
610 grid.attach(quitBtn, 0, 2, 1, 1) # lewo, top wielkosc, wysokosc
prymula <prymula76@outlook.com>
parents:
diff changeset
611
prymula <prymula76@outlook.com>
parents:
diff changeset
612 self.liststore = Gtk.ListStore(str, str)
prymula <prymula76@outlook.com>
parents:
diff changeset
613 self.treeview = Gtk.TreeView(model=self.liststore)
prymula <prymula76@outlook.com>
parents:
diff changeset
614
prymula <prymula76@outlook.com>
parents:
diff changeset
615 self.renderer_text = Gtk.CellRendererText()
prymula <prymula76@outlook.com>
parents:
diff changeset
616 self.column_text = Gtk.TreeViewColumn("Wybrane Utwory", self.renderer_text, text=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
617 self.treeview.append_column(self.column_text)
prymula <prymula76@outlook.com>
parents:
diff changeset
618
prymula <prymula76@outlook.com>
parents:
diff changeset
619 self.scrolled_window = Gtk.ScrolledWindow ()
prymula <prymula76@outlook.com>
parents:
diff changeset
620 self.scrolled_window.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
prymula <prymula76@outlook.com>
parents:
diff changeset
621
prymula <prymula76@outlook.com>
parents:
diff changeset
622 self.scrolled_window.add (self.treeview)
prymula <prymula76@outlook.com>
parents:
diff changeset
623 grid.attach_next_to(self.scrolled_window, self.image ,Gtk.PositionType.RIGHT,6,2)
prymula <prymula76@outlook.com>
parents:
diff changeset
624
prymula <prymula76@outlook.com>
parents:
diff changeset
625 self.set_border_width(10)
prymula <prymula76@outlook.com>
parents:
diff changeset
626 self.set_title("Cover2Music")
prymula <prymula76@outlook.com>
parents:
diff changeset
627 self.set_default_size(650, 180)
prymula <prymula76@outlook.com>
parents:
diff changeset
628 self.connect("destroy", Gtk.main_quit)
prymula <prymula76@outlook.com>
parents:
diff changeset
629
prymula <prymula76@outlook.com>
parents:
diff changeset
630 self.set_icon_from_file(get_resource_path(COVER))
prymula <prymula76@outlook.com>
parents:
diff changeset
631
prymula <prymula76@outlook.com>
parents:
diff changeset
632 def on_button_clicked(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
633 global file_img_selected, snd_extension
prymula <prymula76@outlook.com>
parents:
diff changeset
634
prymula <prymula76@outlook.com>
parents:
diff changeset
635 if len(file_snd_selected)<1:
prymula <prymula76@outlook.com>
parents:
diff changeset
636 print("nie zaznaczyleś żadnego pliku z muzyką !")
prymula <prymula76@outlook.com>
parents:
diff changeset
637 dialog = DialogNoSelectIMG(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
638 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
639 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
640 return
prymula <prymula76@outlook.com>
parents:
diff changeset
641
prymula <prymula76@outlook.com>
parents:
diff changeset
642
prymula <prymula76@outlook.com>
parents:
diff changeset
643 progress =DialogAddCoverProgress(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
644 response = progress.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
645 progress.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
646
prymula <prymula76@outlook.com>
parents:
diff changeset
647
prymula <prymula76@outlook.com>
parents:
diff changeset
648 def add_info_menu_actions(self, action_group):
prymula <prymula76@outlook.com>
parents:
diff changeset
649 action_info_menu = Gtk.Action(name="InfoMenu", label="Info")
prymula <prymula76@outlook.com>
parents:
diff changeset
650 action_group.add_action(action_info_menu)
prymula <prymula76@outlook.com>
parents:
diff changeset
651
prymula <prymula76@outlook.com>
parents:
diff changeset
652 action_new = Gtk.Action(
prymula <prymula76@outlook.com>
parents:
diff changeset
653 name="Help",
prymula <prymula76@outlook.com>
parents:
diff changeset
654 label="Pomoc",
prymula <prymula76@outlook.com>
parents:
diff changeset
655 tooltip="Create a new file",
prymula <prymula76@outlook.com>
parents:
diff changeset
656 )
prymula <prymula76@outlook.com>
parents:
diff changeset
657 action_new.connect("activate", self.on_menu_help)
prymula <prymula76@outlook.com>
parents:
diff changeset
658 action_group.add_action_with_accel(action_new, None)
prymula <prymula76@outlook.com>
parents:
diff changeset
659
prymula <prymula76@outlook.com>
parents:
diff changeset
660 action_new = Gtk.Action(
prymula <prymula76@outlook.com>
parents:
diff changeset
661 name="About",
prymula <prymula76@outlook.com>
parents:
diff changeset
662 label="O Programie",
prymula <prymula76@outlook.com>
parents:
diff changeset
663 tooltip="Create a new file",
prymula <prymula76@outlook.com>
parents:
diff changeset
664 )
prymula <prymula76@outlook.com>
parents:
diff changeset
665 action_new.connect("activate", self.on_menu_about)
prymula <prymula76@outlook.com>
parents:
diff changeset
666 action_group.add_action_with_accel(action_new, None)
prymula <prymula76@outlook.com>
parents:
diff changeset
667
prymula <prymula76@outlook.com>
parents:
diff changeset
668 def add_file_menu_actions(self, action_group):
prymula <prymula76@outlook.com>
parents:
diff changeset
669 action_filemenu = Gtk.Action(name="FileMenu", label="Plik")
prymula <prymula76@outlook.com>
parents:
diff changeset
670 action_group.add_action(action_filemenu)
prymula <prymula76@outlook.com>
parents:
diff changeset
671
prymula <prymula76@outlook.com>
parents:
diff changeset
672 action_fileloadmenu = Gtk.Action(name="FileLoad", stock_id=Gtk.STOCK_NEW)
prymula <prymula76@outlook.com>
parents:
diff changeset
673 action_group.add_action(action_fileloadmenu)
prymula <prymula76@outlook.com>
parents:
diff changeset
674
prymula <prymula76@outlook.com>
parents:
diff changeset
675 action_new = Gtk.Action(
prymula <prymula76@outlook.com>
parents:
diff changeset
676 name="LoadImg",
prymula <prymula76@outlook.com>
parents:
diff changeset
677 label="Załaduj okladkę",
prymula <prymula76@outlook.com>
parents:
diff changeset
678 tooltip="Wybór okladki",
prymula <prymula76@outlook.com>
parents:
diff changeset
679 )
prymula <prymula76@outlook.com>
parents:
diff changeset
680 action_new.connect("activate", self.on_menu_file_load_img_generic)
prymula <prymula76@outlook.com>
parents:
diff changeset
681 action_group.add_action_with_accel(action_new, None)
prymula <prymula76@outlook.com>
parents:
diff changeset
682
prymula <prymula76@outlook.com>
parents:
diff changeset
683
prymula <prymula76@outlook.com>
parents:
diff changeset
684 action_new = Gtk.Action(
prymula <prymula76@outlook.com>
parents:
diff changeset
685 name="LoadOgg",
prymula <prymula76@outlook.com>
parents:
diff changeset
686 label="Załaduj muzykę",
prymula <prymula76@outlook.com>
parents:
diff changeset
687 tooltip="Wybór muzyki",
prymula <prymula76@outlook.com>
parents:
diff changeset
688 )
prymula <prymula76@outlook.com>
parents:
diff changeset
689 action_new.connect("activate", self.on_menu_file_load_ogg_generic)
prymula <prymula76@outlook.com>
parents:
diff changeset
690 action_group.add_action_with_accel(action_new, None)
prymula <prymula76@outlook.com>
parents:
diff changeset
691
prymula <prymula76@outlook.com>
parents:
diff changeset
692 action_fileloadmenu = Gtk.Action(name="FileDelete", label="Usuń", stock_id=None)
prymula <prymula76@outlook.com>
parents:
diff changeset
693 action_group.add_action(action_fileloadmenu)
prymula <prymula76@outlook.com>
parents:
diff changeset
694
prymula <prymula76@outlook.com>
parents:
diff changeset
695 action_new = Gtk.Action(
prymula <prymula76@outlook.com>
parents:
diff changeset
696 name="RemoveCover",
prymula <prymula76@outlook.com>
parents:
diff changeset
697 label="Usuwa okladkę",
prymula <prymula76@outlook.com>
parents:
diff changeset
698 tooltip="Usuwa okladkę z pliku",
prymula <prymula76@outlook.com>
parents:
diff changeset
699 )
prymula <prymula76@outlook.com>
parents:
diff changeset
700 action_new.connect("activate", self.on_menu_file_erase_cover_all)
prymula <prymula76@outlook.com>
parents:
diff changeset
701 action_group.add_action_with_accel(action_new, None)
prymula <prymula76@outlook.com>
parents:
diff changeset
702
prymula <prymula76@outlook.com>
parents:
diff changeset
703
prymula <prymula76@outlook.com>
parents:
diff changeset
704 action_filequit = Gtk.Action(name="FileQuit", stock_id=Gtk.STOCK_QUIT)
prymula <prymula76@outlook.com>
parents:
diff changeset
705 action_filequit.connect("activate", self.on_menu_file_quit)
prymula <prymula76@outlook.com>
parents:
diff changeset
706 action_group.add_action(action_filequit)
prymula <prymula76@outlook.com>
parents:
diff changeset
707
prymula <prymula76@outlook.com>
parents:
diff changeset
708 def add_choices_menu_actions(self, action_group):
prymula <prymula76@outlook.com>
parents:
diff changeset
709 action_group.add_action(Gtk.Action(name="ChoicesMenu", label="Opcje"))
prymula <prymula76@outlook.com>
parents:
diff changeset
710
prymula <prymula76@outlook.com>
parents:
diff changeset
711 three = Gtk.ToggleAction(name="ChoiceTree", label="Pozwolenie")
prymula <prymula76@outlook.com>
parents:
diff changeset
712 three.connect("toggled", self.on_menu_choices_toggled)
prymula <prymula76@outlook.com>
parents:
diff changeset
713 action_group.add_action(three)
prymula <prymula76@outlook.com>
parents:
diff changeset
714
prymula <prymula76@outlook.com>
parents:
diff changeset
715 # tworzy menu bar
prymula <prymula76@outlook.com>
parents:
diff changeset
716 def create_ui_manager(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
717 uimanager = Gtk.UIManager()
prymula <prymula76@outlook.com>
parents:
diff changeset
718
prymula <prymula76@outlook.com>
parents:
diff changeset
719 # Throws exception if something went wrong
prymula <prymula76@outlook.com>
parents:
diff changeset
720 uimanager.add_ui_from_string(UI_INFO)
prymula <prymula76@outlook.com>
parents:
diff changeset
721
prymula <prymula76@outlook.com>
parents:
diff changeset
722 # Add the accelerator group to the toplevel window
prymula <prymula76@outlook.com>
parents:
diff changeset
723 accelgroup = uimanager.get_accel_group()
prymula <prymula76@outlook.com>
parents:
diff changeset
724 self.add_accel_group(accelgroup)
prymula <prymula76@outlook.com>
parents:
diff changeset
725 return uimanager
prymula <prymula76@outlook.com>
parents:
diff changeset
726
prymula <prymula76@outlook.com>
parents:
diff changeset
727 def on_menu_help(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
728 dialog = DialogHelp(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
729 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
730
prymula <prymula76@outlook.com>
parents:
diff changeset
731 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
732
prymula <prymula76@outlook.com>
parents:
diff changeset
733 def on_menu_about(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
734 dialog = DialogAbout(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
735 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
736
prymula <prymula76@outlook.com>
parents:
diff changeset
737 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
738
prymula <prymula76@outlook.com>
parents:
diff changeset
739
prymula <prymula76@outlook.com>
parents:
diff changeset
740 def on_menu_file_load_img_generic(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
741 global grid, file_img_selected, img_extension
prymula <prymula76@outlook.com>
parents:
diff changeset
742
prymula <prymula76@outlook.com>
parents:
diff changeset
743 print("A File|New menu item was selected.")
prymula <prymula76@outlook.com>
parents:
diff changeset
744 file=FileChooserIMG()
prymula <prymula76@outlook.com>
parents:
diff changeset
745 print ("file:"+str(file_img_selected))
prymula <prymula76@outlook.com>
parents:
diff changeset
746 pixbuf_new = GdkPixbuf.Pixbuf.new_from_file_at_scale(
prymula <prymula76@outlook.com>
parents:
diff changeset
747 filename=file_img_selected,
prymula <prymula76@outlook.com>
parents:
diff changeset
748 width=100,
prymula <prymula76@outlook.com>
parents:
diff changeset
749 height=100,
prymula <prymula76@outlook.com>
parents:
diff changeset
750 preserve_aspect_ratio=True)
prymula <prymula76@outlook.com>
parents:
diff changeset
751
prymula <prymula76@outlook.com>
parents:
diff changeset
752 if self.image != None:
prymula <prymula76@outlook.com>
parents:
diff changeset
753 grid.remove(self.image)
prymula <prymula76@outlook.com>
parents:
diff changeset
754 self.image=None
prymula <prymula76@outlook.com>
parents:
diff changeset
755 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
756 grid.remove(self.image_new)
prymula <prymula76@outlook.com>
parents:
diff changeset
757
prymula <prymula76@outlook.com>
parents:
diff changeset
758
prymula <prymula76@outlook.com>
parents:
diff changeset
759 # TODO - pozbyć się self.image_new na rzecz self.image
prymula <prymula76@outlook.com>
parents:
diff changeset
760 self.image_new = Gtk.Image.new_from_pixbuf(pixbuf_new)
prymula <prymula76@outlook.com>
parents:
diff changeset
761 grid.attach_next_to(self.image_new, self.scrolled_window,Gtk.PositionType.LEFT,1,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
762
prymula <prymula76@outlook.com>
parents:
diff changeset
763 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
764
prymula <prymula76@outlook.com>
parents:
diff changeset
765 extension = os.path.splitext(file_img_selected)
prymula <prymula76@outlook.com>
parents:
diff changeset
766 #self.img_extension=extension[1].replace(".", "") # tupla (0) wskazuje na nazwe pliku !
prymula <prymula76@outlook.com>
parents:
diff changeset
767 img_extension=extension[1].replace(".", "") # tupla (0) wskazuje na nazwe pliku !
prymula <prymula76@outlook.com>
parents:
diff changeset
768
prymula <prymula76@outlook.com>
parents:
diff changeset
769
prymula <prymula76@outlook.com>
parents:
diff changeset
770 def on_menu_file_load_ogg_generic(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
771 global file_snd_selected
prymula <prymula76@outlook.com>
parents:
diff changeset
772 file=FileChooserOgg()
prymula <prymula76@outlook.com>
parents:
diff changeset
773 #grid.remove(self.treeview)
prymula <prymula76@outlook.com>
parents:
diff changeset
774 self.scrolled_window.remove(self.treeview)
prymula <prymula76@outlook.com>
parents:
diff changeset
775 grid.remove(self.scrolled_window)
prymula <prymula76@outlook.com>
parents:
diff changeset
776 self.liststore = Gtk.ListStore(str, str)
prymula <prymula76@outlook.com>
parents:
diff changeset
777 self.treeview.remove_column(self.column_text)
prymula <prymula76@outlook.com>
parents:
diff changeset
778
prymula <prymula76@outlook.com>
parents:
diff changeset
779 print ("file selected: ",file_snd_selected)
prymula <prymula76@outlook.com>
parents:
diff changeset
780
prymula <prymula76@outlook.com>
parents:
diff changeset
781 for o in file_snd_selected:
prymula <prymula76@outlook.com>
parents:
diff changeset
782 self.liststore.append([o,""])
prymula <prymula76@outlook.com>
parents:
diff changeset
783
prymula <prymula76@outlook.com>
parents:
diff changeset
784 self.scrolled_window = Gtk.ScrolledWindow ()
prymula <prymula76@outlook.com>
parents:
diff changeset
785 self.scrolled_window.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
prymula <prymula76@outlook.com>
parents:
diff changeset
786
prymula <prymula76@outlook.com>
parents:
diff changeset
787 self.treeview = Gtk.TreeView(model=self.liststore)
prymula <prymula76@outlook.com>
parents:
diff changeset
788 self.renderer_text = Gtk.CellRendererText()
prymula <prymula76@outlook.com>
parents:
diff changeset
789 self.column_text = Gtk.TreeViewColumn("Wybrane Utwory", self.renderer_text, text=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
790 self.treeview.append_column(self.column_text)
prymula <prymula76@outlook.com>
parents:
diff changeset
791
prymula <prymula76@outlook.com>
parents:
diff changeset
792 if self.image != None:
prymula <prymula76@outlook.com>
parents:
diff changeset
793 self.scrolled_window.add (self.treeview)
prymula <prymula76@outlook.com>
parents:
diff changeset
794 grid.attach_next_to(self.scrolled_window, self.image ,Gtk.PositionType.RIGHT,6,2)
prymula <prymula76@outlook.com>
parents:
diff changeset
795 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
796 self.scrolled_window.add (self.treeview)
prymula <prymula76@outlook.com>
parents:
diff changeset
797 grid.attach_next_to(self.scrolled_window, self.image_new ,Gtk.PositionType.RIGHT,6,2)
prymula <prymula76@outlook.com>
parents:
diff changeset
798
prymula <prymula76@outlook.com>
parents:
diff changeset
799 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
800 """
prymula <prymula76@outlook.com>
parents:
diff changeset
801 def close_progress(self, gparmstring):
prymula <prymula76@outlook.com>
parents:
diff changeset
802 self.progress.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
803 """
prymula <prymula76@outlook.com>
parents:
diff changeset
804 def on_menu_file_erase_cover_all(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
805
prymula <prymula76@outlook.com>
parents:
diff changeset
806 if len(file_snd_selected)<1:
prymula <prymula76@outlook.com>
parents:
diff changeset
807 dialog = DialogNoSelectIMG(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
808 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
809 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
810 return
prymula <prymula76@outlook.com>
parents:
diff changeset
811
prymula <prymula76@outlook.com>
parents:
diff changeset
812 self.progress =DialogDeleteProgress(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
813 response = self.progress.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
814 self.progress.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
815
prymula <prymula76@outlook.com>
parents:
diff changeset
816
prymula <prymula76@outlook.com>
parents:
diff changeset
817 def on_menu_file_quit(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
818 Gtk.main_quit()
prymula <prymula76@outlook.com>
parents:
diff changeset
819
prymula <prymula76@outlook.com>
parents:
diff changeset
820 def on_menu_choices_toggled(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
821 if widget.get_active():
prymula <prymula76@outlook.com>
parents:
diff changeset
822 print(widget.get_name() + " activated")
prymula <prymula76@outlook.com>
parents:
diff changeset
823 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
824 print(widget.get_name() + " deactivated")
prymula <prymula76@outlook.com>
parents:
diff changeset
825
prymula <prymula76@outlook.com>
parents:
diff changeset
826 def on_button_press_event(self, widget, event):
prymula <prymula76@outlook.com>
parents:
diff changeset
827 # Check if right mouse button was preseed
prymula <prymula76@outlook.com>
parents:
diff changeset
828 if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 3:
prymula <prymula76@outlook.com>
parents:
diff changeset
829 self.popup.popup(None, None, None, None, event.button, event.time)
prymula <prymula76@outlook.com>
parents:
diff changeset
830 return True # event has been handled
prymula <prymula76@outlook.com>
parents:
diff changeset
831
prymula <prymula76@outlook.com>
parents:
diff changeset
832
prymula <prymula76@outlook.com>
parents:
diff changeset
833 win = MyWindow()
prymula <prymula76@outlook.com>
parents:
diff changeset
834 win.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
835 Gtk.main()