28
26
# You should have received a copy of the GNU General Public License
29
27
# along with this program. If not, see <http://www.gnu.org/licenses/>.
31
## --------------------------------------------------------- Licence ----
33
## ---- Important Assumptions -------------------------------------------
35
# * The user running the program has a /home/<USER>/.gnome2 directory;
36
# * It contains backgrounds.xml, for listing the user's backgrounds;
37
# * Only PNG, JPEG, GIF, and SVG formats are used for backgrounds.
39
## ------------------------------------------- Important Assumptions ----
41
## ===================================================== INFORMATION ====
29
## ========================================================= LICENCE ====
48
from xml.dom import minidom
88
78
# Set up GUIcombine arrays
91
if (os.path.dirname(os.path.abspath(__file__)) == '/usr/bin'):
93
b.add_from_file("/usr/share/crebs/glade/create-background-slideshow.glade")
94
b.add_from_file("/usr/share/crebs/glade/add-images.glade")
95
b.add_from_file("/usr/share/crebs/glade/clear-images.glade")
97
# Use local (uninstalled) files
98
b.add_from_file("glade/create-background-slideshow.glade")
99
b.add_from_file("glade/add-images.glade")
100
b.add_from_file("glade/clear-images.glade")
81
prefix = os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + '/..')
82
b.add_from_file(prefix + "/share/crebs/glade/create-background-slideshow.glade")
83
b.add_from_file(prefix + "/share/crebs/glade/add-images.glade")
84
b.add_from_file(prefix + "/share/crebs/glade/clear-images.glade")
102
86
# Link to GUI actions
103
87
b.connect_signals({
328
327
print "Adding an image to the slideshow..."
329
pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
330
aspect_ratio = float(pixbuf.get_width()) / float(pixbuf.get_height())
332
if (aspect_ratio >= 1):
334
y = int(target_size / aspect_ratio)
337
x = int(target_size * aspect_ratio)
339
image.set_from_pixbuf(pixbuf.scale_simple(x,y,gtk.gdk.INTERP_BILINEAR))
341
print " {1}x{2} ({0})".format(aspect_ratio, pixbuf.get_width(), pixbuf.get_height())
343
if (spec_dur < 1) or (spec_trn < 0):
344
self.lstImages.append([filename, image.get_pixbuf(), True, self.DurDefault.get_value(), self.cmbDurScaleDefault.get_active(), True, self.TrnDefault.get_value()])
346
if spec_dur % 3600 == 0:
348
dur_scaled = spec_dur / 3600
351
if spec_dur % 60 == 0:
353
dur_scaled = spec_dur / 60
357
dur_scaled = spec_dur
360
if (dur_scaled == self.DurDefault.get_value()) and (scale == self.cmbDurScaleDefault.get_active()):
365
if (spec_trn == self.TrnDefault.get_value()):
370
self.lstImages.append([filename, image.get_pixbuf(), use_def_dur, dur_scaled, scale, use_def_trn, spec_trn])
372
print " Slideshow now has " + str(len(self.lstImages)) + " image(s)."
329
pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
331
print " Can't add", filename, "(not a valid image or can't generate thumbnail)"
334
aspect_ratio = float(pixbuf.get_width()) / float(pixbuf.get_height())
336
if (aspect_ratio >= 1):
338
y = int(target_size / aspect_ratio)
341
x = int(target_size * aspect_ratio)
343
image.set_from_pixbuf(pixbuf.scale_simple(x,y,gtk.gdk.INTERP_BILINEAR))
345
print " {1}x{2} ({0})".format(aspect_ratio, pixbuf.get_width(), pixbuf.get_height())
347
if (spec_dur < 1) or (spec_trn < 0):
348
self.lstImages.append([filename, image.get_pixbuf(), True, self.DurDefault.get_value(), self.cmbDurScaleDefault.get_active(), True, self.TrnDefault.get_value()])
350
if spec_dur % 3600 == 0:
352
dur_scaled = spec_dur / 3600
355
if spec_dur % 60 == 0:
357
dur_scaled = spec_dur / 60
361
dur_scaled = spec_dur
364
if (dur_scaled == self.DurDefault.get_value()) and (scale == self.cmbDurScaleDefault.get_active()):
369
if (spec_trn == self.TrnDefault.get_value()):
374
self.lstImages.append([filename, image.get_pixbuf(), use_def_dur, dur_scaled, scale, use_def_trn, spec_trn])
376
print " Slideshow now has " + str(len(self.lstImages)) + " image(s)."
376
380
def import_slideshow(self, filename):
377
381
"""Imports a pre-existing slideshow, including images and timings."""
378
382
print "Importing slideshow " + filename + " ..."
380
slides = minidom.parse(filename)
384
slides = libxml2.parseFile(filename)
382
386
print " Failed. Could not open and parse slideshow file."
385
imagelist = slides.getElementsByTagName('file')
386
st_list = slides.getElementsByTagName('static')
387
tr_list = slides.getElementsByTagName('transition')
389
for i in range(len(imagelist)):
390
filename = imagelist[i].firstChild.data
393
for child in st_list[i].childNodes:
394
if child.nodeName == 'duration':
395
duration = float(child.firstChild.data)
398
for child in tr_list[i].childNodes:
399
if child.nodeName == 'duration':
400
transition = float(child.firstChild.data)
402
added = self.add_image(filename, duration, transition)
389
root = slides.getRootElement()
390
if root.name != 'background':
397
b_children = root.children
398
for b_child in b_children:
399
if b_child.name == 'static':
400
st_children = b_child.children
401
for st_child in st_children:
402
if st_child.name == 'file':
403
imagelist.append(str(st_child.children))
404
elif st_child.name == 'duration':
405
st_list.append(float(str(st_child.children)))
406
elif b_child.name == 'transition':
407
tr_children = b_child.children
408
for tr_child in tr_children:
409
if tr_child.name == 'duration':
410
tr_list.append(float(str(tr_child.children)))
412
for i in range(len(imagelist)):
413
filename = imagelist[i]
414
duration = st_list[i]
415
transition = tr_list[i]
417
added = self.add_image(filename, duration, transition)
428
449
self.check_if_clearable()
452
def add_by_drop(self, widget, context, x, y, selection, target_type, timestamp):
453
"""Add an image by dropping it onto the window."""
454
print "Files dropped onto main window."
455
if target_type == 80:
456
print "Processing dropped files..."
458
path_list = selection.data.strip('\r\n\x00').split()
459
for path in path_list:
460
if path.startswith('file://'):
462
elif path.stratswith('file:'):
464
# Fix characters escaped by Nautilus, e.g. %20 -> space
465
path = urllib.url2pathname(path)
466
filenames.append(path)
468
self.add_images(widget, filenames)
469
print " Dropped file(s) processed."
431
472
def copy_image(self, widget):
432
473
"""Copies the selected image."""