-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
cover-thumbnailer-gui.py
executable file
·655 lines (559 loc) · 26.2 KB
/
cover-thumbnailer-gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#########################################################################
## ##
## ┏━╸┏━┓╻ ╻┏━╸┏━┓ ╺┳╸╻ ╻╻ ╻┏┳┓┏┓ ┏┓╻┏━┓╻╻ ┏━╸┏━┓ ##
## ┃ ┃ ┃┃┏┛┣╸ ┣┳┛ ┃ ┣━┫┃ ┃┃┃┃┣┻┓┃┗┫┣━┫┃┃ ┣╸ ┣┳┛ ##
## ┗━╸┗━┛┗┛ ┗━╸╹┗╸ ╹ ╹ ╹┗━┛╹ ╹┗━┛╹ ╹╹ ╹╹┗━╸┗━╸╹┗╸ ##
## — www.flogisoft.com — ##
## ##
############################################################################
## ##
## Cover thumbnailer GUI ##
## ##
## Copyright (C) 2009 - 2024 Fabien Loison <http://www.flozz.fr/> ##
## ##
## This program is free software: you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation, either version 3 of the License, or ##
## (at your option) any later version. ##
## ##
## This program is distributed in the hope that it will be useful, ##
## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
## GNU General Public License for more details. ##
## ##
## You should have received a copy of the GNU General Public License ##
## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
## ##
############################################################################
## ##
## WEB SITE : https://github.com/flozz/cover-thumbnailer ##
## ##
#########################################################################
"""Configuration GUI for Cover Thumbnailer.
A GUI for easily configuring Cover Thumbnailer.
"""
__version__ = "0.10.2"
__author__ = "Fabien Loison <http://www.flozz.fr/>"
__copyright__ = "Copyright © 2009 - 2024 Fabien LOISON"
__appname__ = "cover-thumbnailer-gui"
import gettext
import os
import re
import shutil
import glob
import hashlib
import subprocess
import gi
gi.require_version("Gtk", "3.0") # noqa
from gi.repository import Gtk as gtk
from gi.repository import Gio
gettext.install(__appname__)
#Base path
if "DEVEL" in os.environ:
BASE_PATH = "./share/" #For devel
else:
BASE_PATH = "/usr/share/cover-thumbnailer/"
class Conf(dict):
""" Import configuration.
Import configuration from the GNOME and cover thumbnailer files
"""
def __init__(self):
""" The constructor
Set the default values
"""
#Initialize the dictionary
dict.__init__(self)
#Music
self['music_enabled'] = True
self['music_keepdefaulticon'] = False
self['music_usegnomefolder'] = True
self['music_cropimg'] = True
self['music_makemosaic'] = False
self['music_paths'] = []
self['music_gnomefolderpath'] = _("<None>")
#Pictures
self['pictures_enabled'] = True
self['pictures_keepdefaulticon'] = False
self['pictures_usegnomefolder'] = True
self['pictures_maxthumbs'] = 3
self['pictures_paths'] = []
self['pictures_gnomefolderpath'] = _("<None>")
#Other
self['other_enabled'] = True
#Ignored
self['ignored_dotted'] = False
self['ignored_paths'] = []
#Never ignored
self['neverignored_paths'] = []
#Global
self.user_homedir = os.environ.get("HOME")
self.user_gnomeconf = os.path.join(
self.user_homedir,
".config/user-dirs.dirs"
)
self.user_conf = os.path.join(
self.user_homedir,
".cover-thumbnailer/cover-thumbnailer.conf"
)
#Read configuration
self.import_gnome_conf()
self.import_user_conf()
def import_gnome_conf(self):
""" Import user folders from GNOME configuration file. """
if os.path.isfile(self.user_gnomeconf):
gnome_conf_file = open(self.user_gnomeconf, 'r')
for line in gnome_conf_file:
if re.match(r'.*?XDG_MUSIC_DIR.*?=.*?"(.*)".*?', line):
match = re.match(r'.*?XDG_MUSIC_DIR.*?=.*?"(.*)".*?', line)
path = match.group(1).replace('$HOME', self.user_homedir)
self['music_gnomefolderpath'] = path
elif re.match(r'.*?XDG_PICTURES_DIR.*?=.*?"(.*)".*?', line):
match = re.match(r'.*?XDG_PICTURES_DIR.*?=.*?"(.*)".*?', line)
path = match.group(1).replace('$HOME', self.user_homedir)
self['pictures_gnomefolderpath'] = path
gnome_conf_file.close()
else:
print("W: [%s:Conf.import_gnome_conf] Can't find `user-dirs.dirs' file." % __file__)
def import_user_conf(self):
""" Import user configuration file. """
if os.path.isfile(self.user_conf):
current_section = "unknown"
user_conf_file = open(self.user_conf, 'r')
for line in user_conf_file:
#Comments
if re.match(r"\s*#.*", line):
continue
#Section
elif re.match(r"\s*\[([a-z]+)\]\s*", line.lower()):
match = re.match(r'\s*\[([a-z]+)\]\s*', line.lower())
current_section = match.group(1)
#Boolean key
elif re.match(r"\s*([a-z]+)\s*=\s*(yes|no|true|false)\s*", line.lower()):
match = re.match(r"\s*([a-z]+)\s*=\s*(yes|no|true|false)\s*", line.lower())
key = match.group(1)
value = match.group(2)
if value in ("yes", "true"):
value = True
else:
value = False
self[current_section + "_" + key] = value
#String key : path
elif re.match(r"\s*(path|PATH|Path)\s*=\s*\"(.+)\"\s*", line):
match = re.match(r"\s*(path|PATH|Path)\s*=\s*\"(.+)\"\s*", line)
key = "paths"
value = match.group(2)
self[current_section + "_" + key].append(value)
#Integer key
elif re.match(r"\s*([a-z]+)\s*=\s*([0-9]+)\s*", line.lower()):
match = re.match(r"\s*([a-z]+)\s*=\s*([0-9]+)\s*", line.lower())
key = match.group(1)
value = match.group(2)
self[current_section + "_" + key] = int(value)
user_conf_file.close()
#Replace "~/" by the user home dir
for path_list in (self['music_paths'], self['pictures_paths'], self['ignored_paths']):
for i in range(0, len(path_list)):
if path_list[i][0] == "~":
path_list[i] = os.path.join(self.user_homedir, path_list[i][2:])
#Import "useGnomeConf" key (for compatibility)
if "miscellaneous_usegnomeconf" in self:
self["music_usegnomefolder"] = self["miscellaneous_usegnomeconf"]
self["pictures_usegnomefolder"] = self["miscellaneous_usegnomeconf"]
def save_user_conf(self):
""" Save configuration file. """
#Check if output folder exists, else create it
conf_dir = os.path.join(self.user_homedir, ".cover-thumbnailer")
if not os.path.isdir(conf_dir):
try:
os.makedirs(conf_dir)
except OSError: #Permission denied
print("E: [%s:Conf.save_user_conf] Can't write configuration directory (permission denied)" % __file__)
return
try:
user_conf_file = open(self.user_conf, 'w')
#Warning
user_conf_file.write('#' + _('Configuration written by Cover Thumbnailer GUI') + "\n")
user_conf_file.write("#" + _('Please edit with caution') + "\n")
#Music
user_conf_file.write("\n[MUSIC]\n")
user_conf_file.write(self._write_bool("music_enabled"))
user_conf_file.write(self._write_bool("music_keepdefaulticon"))
user_conf_file.write(self._write_bool("music_usegnomefolder"))
user_conf_file.write(self._write_bool("music_cropimg"))
user_conf_file.write(self._write_bool("music_makemosaic"))
user_conf_file.write(self._write_list("music_paths"))
#Pictures
user_conf_file.write("\n[PICTURES]\n")
user_conf_file.write(self._write_bool("pictures_enabled"))
user_conf_file.write(self._write_bool("pictures_keepdefaulticon"))
user_conf_file.write(self._write_bool("pictures_usegnomefolder"))
user_conf_file.write(self._write_int("pictures_maxthumbs"))
user_conf_file.write(self._write_list("pictures_paths"))
#Other
user_conf_file.write("\n[OTHER]\n")
user_conf_file.write(self._write_bool("other_enabled"))
#Ignored
user_conf_file.write("\n[IGNORED]\n")
user_conf_file.write(self._write_bool("ignored_dotted"))
user_conf_file.write(self._write_list("ignored_paths"))
#Never ignored
user_conf_file.write("\n[NEVERIGNORED]\n")
user_conf_file.write(self._write_list("neverignored_paths"))
#End
user_conf_file.write("\n\n") #I like blank lines at the end :)
except OSError: #Permission denied
print("E: [%s:Conf.save_user_conf] Can't write configuration (permission denied)" % __file__)
return
except IOError: #Input/Output error
print("E: [%s:Conf.save_user_conf] Can't write configuration (IO error)" % __file__)
return
else:
user_conf_file.close()
def _write_bool(self, key):
""" Return the string to write in config file for boolean key
Argument:
* key -- the name of the CONF key
"""
wkey = key.split("_")[1]
if self[key]:
value = "Yes"
else:
value = "No"
return "\t%s = %s\n" % (wkey, value)
def _write_list(self, key):
""" Return the string to write in config file for list key (path)
Argument:
* key -- the name of the CONF key
"""
result = ""
for value in self[key]:
result += "\tpath = \"%s\"\n" % value
return result
def _write_int(self, key):
""" Return the string to write in config file for integer key
Argument:
* key -- the name of the CONF key
"""
wkey = key.split("_")[1]
value = self[key]
return "\t%s = %i\n" % (wkey, value)
class MainWin(object):
""" The configuration GUI """
def __init__(self):
win = gtk.Builder()
win.set_translation_domain(__appname__)
#FIXME: GtkWarning: Ignoring the separator setting (wtf ?!)
win.add_from_file(os.path.join(BASE_PATH, "cover-thumbnailer-gui.glade"))
self.winAbout = win.get_object("winAbout")
self.winAbout.connect("response", self.on_winAbout_response)
self.winAbout.set_version(__version__)
self.winAbout.set_copyright(__copyright__)
### MUSIC ###
#Music path list
self.trvMusicPathList = win.get_object("trvMusicPathList")
self.lsstMusicPathList = gtk.ListStore(str)
self.trvMusicPathList.set_model(self.lsstMusicPathList)
self.columnMusicPathList = gtk.TreeViewColumn("Path", gtk.CellRendererText(), text=0)
self.trvMusicPathList.append_column(self.columnMusicPathList)
#MusicRemove button
self.btnMusicRemove = win.get_object("btnMusicRemove")
#GNOME music folder checkBox
self.cb_useGnomeMusic = win.get_object("cb_useGnomeMusic")
#Enable checkBox
self.cbMusicEnable = win.get_object("cbMusicEnable")
#KeepIcon checkBox
self.cbMusicKeepFIcon = win.get_object("cbMusicKeepFIcon")
#rbMusicCrop and rbMusicPreserve radiobuttons
self.rbMusicCrop = win.get_object("rbMusicCrop")
self.rbMusicPreserve = win.get_object("rbMusicPreserve")
#rbMusicNoMosaic and rbMusicMosaic radiobuttons
self.rbMusicNoMosaic = win.get_object("rbMusicNoMosaic")
self.rbMusicMosaic = win.get_object("rbMusicMosaic")
### PICTURES ###
#Pictures path list
self.trvPicturesPathList = win.get_object("trvPicturesPathList")
self.lsstPicturesPathList = gtk.ListStore(str)
self.trvPicturesPathList.set_model(self.lsstPicturesPathList)
self.columnPicturesPathList = gtk.TreeViewColumn("Path", gtk.CellRendererText(), text=0)
self.trvPicturesPathList.append_column(self.columnPicturesPathList)
#PicturesRemove button
self.btnPicturesRemove = win.get_object("btnPicturesRemove")
#GNOME picture folder checkBox
self.cb_useGnomePictures = win.get_object("cb_useGnomePictures")
#Enable checkBox
self.cbPicturesEnable = win.get_object("cbPicturesEnable")
#KeepIcon checkBox
self.cbPicturesKeepFIcon = win.get_object("cbPicturesKeepFIcon")
#spinbtn_maxThumbs Spin Button
self.spinbtn_maxThumbs = win.get_object("spinbtn_maxThumbs")
### OTHER ###
#Enable checkBox
self.cbOtherEnable = win.get_object("cbOtherEnable")
### IGNORED ###
#Ignored path list
self.trvIgnoredPathList = win.get_object("trvIgnoredPathList")
self.lsstIgnoredPathList = gtk.ListStore(str)
self.trvIgnoredPathList.set_model(self.lsstIgnoredPathList)
self.columnIgnoredPathList = gtk.TreeViewColumn("Path", gtk.CellRendererText(), text=0)
self.trvIgnoredPathList.append_column(self.columnIgnoredPathList)
#IgnoredRemove button
self.btnIgnoredRemove = win.get_object("btnIgnoredRemove")
#IgnoreHidden checkBox
self.cbIgnoreHidden = win.get_object("cbIgnoreHidden")
### NEVER IGNORED ###
#Never ignored path list
self.trvNeverIgnoredPathList = win.get_object("trvNeverIgnoredPathList")
self.lsstNeverIgnoredPathList = gtk.ListStore(str)
self.trvNeverIgnoredPathList.set_model(self.lsstNeverIgnoredPathList)
self.columnNeverIgnoredPathList = gtk.TreeViewColumn("Path", gtk.CellRendererText(), text=0)
self.trvNeverIgnoredPathList.append_column(self.columnNeverIgnoredPathList)
#NeverIgnoredRemove button
self.btnNeverIgnoredRemove = win.get_object("btnNeverIgnoredRemove")
### MISCELLANEOUS ###
#Enable Cover-Thumbnailer checkBox
self.cbEnableCT = win.get_object("cbEnableCT")
#Thumbnail size spinbtn
self.spinbtn_thumbSize = win.get_object("spinbtn_thumbSize")
### FileChooser Dialog ###
self.fileChooser = win.get_object("filechooserdialog")
self.fileChooserFor = None
### ERROR DIALOG file already in list ###
self.msgdlgErrorPAIL = win.get_object("msgdlgErrorPAIL")
### INFO DIALOG generating thumbnails ###
self.msgdlgGeneratingThumbnails = win.get_object("msgdlgGeneratingThumbnails")
loadInterface(self) #Put config on the gui
win.connect_signals(self)
### WINMAIN ###
def on_winMain_destroy(self, widget):
gtk.main_quit()
def on_btnAbout_clicked(self, widget):
self.winAbout.show()
def on_btnCancel_clicked(self, widget):
gtk.main_quit()
def on_btnOk_clicked(self, widget):
CONF.save_user_conf()
gtk.main_quit()
#~~~ MUSIC ~~~
def on_cbMusicEnable_toggled(self, widget):
CONF['music_enabled'] = self.cbMusicEnable.get_active()
def on_cbMusicKeepFIcon_toggled(self, widget):
CONF['music_keepdefaulticon'] = self.cbMusicKeepFIcon.get_active()
def on_btnMusicAdd_clicked(self, widget):
self.fileChooserFor = 'music'
self.fileChooser.show()
def on_trvMusicPathList_cursor_changed(self, widget):
model, iter_ = widget.get_selection().get_selected()
if iter_ is not None:
self.btnMusicRemove.set_sensitive(True)
def on_btnMusicRemove_clicked(self, widget):
removePathFromList(
self.trvMusicPathList,
self.lsstMusicPathList,
CONF['music_paths']
)
self.btnMusicRemove.set_sensitive(False)
def on_cb_useGnomeMusic_toggled(self, widget):
CONF['music_usegnomefolder'] = self.cb_useGnomeMusic.get_active()
def on_rbMusicCrop_toggled(self, widget):
CONF['music_cropimg'] = self.rbMusicCrop.get_active()
def on_rbMusicNoMosaic_toggled(self, widget):
CONF['music_makemosaic'] = self.rbMusicMosaic.get_active()
#~~~ PICTURES ~~~
def on_cbPicturesEnable_toggled(self, widget):
CONF['pictures_enabled'] = self.cbPicturesEnable.get_active()
def on_cbPicturesKeepFIcon_toggled(self, widget):
CONF['pictures_keepdefaulticon'] = self.cbPicturesKeepFIcon.get_active()
def on_btnPicturesAdd_clicked(self, widget):
self.fileChooserFor = 'pictures'
self.fileChooser.show()
def on_trvPicturesPathList_cursor_changed(self, widget):
model, iter_ = widget.get_selection().get_selected()
if iter_ is not None:
self.btnPicturesRemove.set_sensitive(True)
def on_btnPicturesRemove_clicked(self, widget):
removePathFromList(
self.trvPicturesPathList,
self.lsstPicturesPathList,
CONF['pictures_paths']
)
self.btnPicturesRemove.set_sensitive(False)
def on_spinbtn_maxThumbs_value_changed(self, widget):
CONF['pictures_maxthumbs'] = int(self.spinbtn_maxThumbs.get_value())
def on_cb_useGnomePictures_toggled(self, widget):
CONF['pictures_usegnomefolder'] = self.cb_useGnomePictures.get_active()
#~~~ OTHER ~~~
def on_cbOtherEnable_toggled(self, widget):
CONF['other_enabled'] = self.cbOtherEnable.get_active()
#~~~ IGNORED ~~~
def on_btnIgnoredAdd_clicked(self, widget):
self.fileChooserFor = 'ignored'
self.fileChooser.show()
def on_trvIgnoredPathList_cursor_changed(self, widget):
model, iter_ = widget.get_selection().get_selected()
if iter_ is not None:
self.btnIgnoredRemove.set_sensitive(True)
def on_btnIgnoredRemove_clicked(self, widget):
removePathFromList(self.trvIgnoredPathList, self.lsstIgnoredPathList, CONF['ignored_paths'])
self.btnIgnoredRemove.set_sensitive(False)
def on_cbIgnoreHidden_toggled(self, widget):
CONF['ignored_dotted'] = self.cbIgnoreHidden.get_active()
#~~~ NEVER IGNORED ~~~
def on_btnNeverIgnoredAdd_clicked(self, widget):
self.fileChooserFor = 'neverignored'
self.fileChooser.show()
def on_trvNeverIgnoredPathList_cursor_changed(self, widget):
model, iter_ = widget.get_selection().get_selected()
if iter_ is not None:
self.btnNeverIgnoredRemove.set_sensitive(True)
def on_btnNeverIgnoredRemove_clicked(self, widget):
removePathFromList(self.trvNeverIgnoredPathList, self.lsstNeverIgnoredPathList, CONF['neverignored_paths'])
self.btnNeverIgnoredRemove.set_sensitive(False)
#~~~ MISCELLANEOUS ~~~
def on_btnClearThumbnailCache_clicked(self, widget):
thumbpath = os.path.join(CONF.user_homedir, '.cache/thumbnails')
if os.path.isdir(thumbpath):
shutil.rmtree(thumbpath)
def on_btnGenerateThumbnails_clicked(self, widget):
self.fileChooserFor = 'generatethumbnails'
self.fileChooser.show()
### FILECHOOSER DIALOG ###
def on_btnFileChooserCancel_clicked(self, widget):
self.fileChooser.hide()
def on_btnFileChooserOpen_clicked(self, widget):
self.fileChooser.hide()
path = self.fileChooser.get_filename()
if self.fileChooserFor == 'music':
addPathToList(self.lsstMusicPathList, path, CONF['music_paths'])
elif self.fileChooserFor == 'pictures':
addPathToList(self.lsstPicturesPathList, path, CONF['pictures_paths'])
elif self.fileChooserFor == 'ignored':
addPathToList(self.lsstIgnoredPathList, path, CONF['ignored_paths'])
elif self.fileChooserFor == 'neverignored':
addPathToList(self.lsstNeverIgnoredPathList, path, CONF['neverignored_paths'])
elif self.fileChooserFor == 'generatethumbnails':
self.msgdlgGeneratingThumbnails.show()
gtk.main_iteration_do(True)
CONF.save_user_conf() # Save user conf before generating thumbs
gtk.main_iteration_do(True)
generateThumbnails(path)
self.msgdlgGeneratingThumbnails.hide()
self.fileChooserFor = None
def on_filechooserdialog_delete_event(self, widget, response):
self.fileChooser.hide()
return True #Don't delete
### ABOUT DIALOG ###
def on_winAbout_delete_event(self, widget, event):
self.winAbout.hide()
return True #Don't delete
def on_winAbout_response(self, widget, response):
if response < 0:
self.winAbout.hide()
### ERROR DIALOG file already in list ###
def on_msgdlgErrorPAIL_delete_event(self, widget, event):
self.msgdlgErrorPAIL.hide()
return True #Don't delete
def on_btnErrorPAILClose_clicked(self, widget):
self.msgdlgErrorPAIL.hide()
def list_folders(base_path):
return glob.glob(os.path.join(base_path, "**/"), recursive=True)
def generate_thumbnail_path(path):
gvfs = Gio.Vfs.get_default()
uri = gvfs.get_file_for_path(path).get_uri()
uri = uri.encode("utf-8")
uri_hash = hashlib.md5(uri).hexdigest()
return os.path.join(
CONF.user_homedir,
'.cache/thumbnails/normal',
'%s.png' % uri_hash)
def generateThumbnails(path):
CT_CMD = 'cover-thumbnailer'
if "DEVEL" in os.environ:
CT_CMD = './cover-thumbnailer.py'
for input_folder in list_folders(path):
gtk.main_iteration_do(False)
print('Generating thumbnail for %s' % input_folder)
output_file = generate_thumbnail_path(input_folder)
print(' -> dest: %s' % output_file)
subprocess.run([CT_CMD, input_folder, output_file])
def addPathToList(gtklist, path, conflist):
""" Adds the path in the list
Arguments:
* path -- the path to add
* gtklist -- the gtkListStore where we will add the path
* confilst -- the "Conf" path list
"""
if not path in conflist:
gtklist.append([path])
conflist.append(path)
else:
gui.msgdlgErrorPAIL.show()
def removePathFromList(gtktree, gtklist, conflist):
""" Remove the path from the list
Arguments:
* gtktree -- the gtkTreeView
* gtklist -- the gtkListStore where we will add the path
* confilst -- the "Conf" path list
"""
model, iter_ = gtktree.get_selection().get_selected()
conflist.remove(gtklist.get_value(iter_, 0))
gtklist.remove(iter_)
def loadInterface(gui):
""" Put options on the GUI
Argument:
* gui -- the gui
"""
#Music
gui.cbMusicEnable.set_active(CONF['music_enabled'])
gui.cbMusicKeepFIcon.set_active(CONF['music_keepdefaulticon'])
for path in CONF['music_paths']:
gui.lsstMusicPathList.append([path])
gui.cb_useGnomeMusic.set_label(_("Enable for GNOME's music folder (%s)") %(CONF['music_gnomefolderpath']))
gui.cb_useGnomeMusic.set_active(CONF['music_usegnomefolder'])
if CONF['music_cropimg']:
gui.rbMusicCrop.set_active(True)
else:
gui.rbMusicPreserve.set_active(True)
if CONF['music_makemosaic']:
gui.rbMusicMosaic.set_active(True)
else:
gui.rbMusicNoMosaic.set_active(True)
#Pictures
gui.cbPicturesEnable.set_active(CONF['pictures_enabled'])
gui.cbPicturesKeepFIcon.set_active(CONF['pictures_keepdefaulticon'])
for path in CONF['pictures_paths']:
gui.lsstPicturesPathList.append([path])
gui.cb_useGnomePictures.set_label(_("Enable for GNOME's picture folder (%s)") %(CONF['pictures_gnomefolderpath']))
gui.cb_useGnomePictures.set_active(CONF['pictures_usegnomefolder'])
if CONF['pictures_maxthumbs'] > 4:
gui.spinbtn_maxThumbs.set_value(4)
elif CONF['pictures_maxthumbs'] < 1:
gui.spinbtn_maxThumbs.set_value(1)
else:
gui.spinbtn_maxThumbs.set_value(CONF['pictures_maxthumbs'])
#Other
gui.cbOtherEnable.set_active(CONF['other_enabled'])
#Ignored
gui.cbIgnoreHidden.set_active(CONF['ignored_dotted'])
for path in CONF['ignored_paths']:
gui.lsstIgnoredPathList.append([path])
#Ignored
for path in CONF['neverignored_paths']:
gui.lsstNeverIgnoredPathList.append([path])
#If GNOME folders == user home dir or not defined,
#deactivate the option, it's probably a misconfiguration !
if os.path.isdir(CONF['music_gnomefolderpath']) \
and os.path.samefile(CONF['music_gnomefolderpath'], CONF.user_homedir) \
or CONF['music_gnomefolderpath'] == _("<None>"):
gui.cb_useGnomeMusic.set_active(False)
gui.cb_useGnomeMusic.set_sensitive(False)
if os.path.isdir(CONF['pictures_gnomefolderpath']) \
and os.path.samefile(CONF['pictures_gnomefolderpath'], CONF.user_homedir) \
or CONF['pictures_gnomefolderpath'] == _("<None>"):
gui.cb_useGnomePictures.set_active(False)
gui.cb_useGnomePictures.set_sensitive(False)
if __name__ == "__main__":
CONF = Conf()
gui = MainWin()
gtk.main()