gramps/gramps2/src/RelImage.py

88 lines
2.9 KiB
Python
Raw Normal View History

2002-10-20 19:55:16 +05:30
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2003 Donald N. Allingham
2002-10-20 19:55:16 +05:30
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#-------------------------------------------------------------------------
#
# Standard python modules
#
#-------------------------------------------------------------------------
import os
import string
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
import gtk
from QuestionDialog import ErrorDialog, WarningDialog
2002-10-20 19:55:16 +05:30
#-------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
import const
2003-08-17 07:44:33 +05:30
from gettext import gettext as _
2002-10-20 19:55:16 +05:30
#-------------------------------------------------------------------------
#
# import_media_object
#
#-------------------------------------------------------------------------
def import_media_object(filename,path,base):
import shutil
if not os.path.exists(filename):
2003-02-24 10:21:57 +05:30
ErrorDialog(_("Could not import %s") % filename,
_("The file has been moved or deleted"))
2002-10-20 19:55:16 +05:30
return ""
return filename
2002-10-20 19:55:16 +05:30
#-------------------------------------------------------------------------
#
# scale_image
#
#-------------------------------------------------------------------------
def scale_image(path,size):
try:
image1 = gtk.gdk.pixbuf_new_from_file(path)
except:
2003-02-27 05:59:37 +05:30
WarningDialog(_("Cannot display %s") % path,
_('GRAMPS is not able to display the image file. '
'This may be caused by a corrupt file.'))
2002-10-20 19:55:16 +05:30
return gtk.gdk.pixbuf_new_from_file(const.icon)
width = image1.get_width()
height = image1.get_height()
scale = size / float(max(width,height))
try:
return image1.scale_simple(int(scale*width), int(scale*height),
gtk.gdk.INTERP_BILINEAR)
2002-10-20 19:55:16 +05:30
except:
2003-02-27 05:59:37 +05:30
WarningDialog(_("Cannot display %s") % path,
_('GRAMPS is not able to display the image file. '
'This may be caused by a corrupt file.'))
2002-10-20 19:55:16 +05:30
return gtk.gdk.pixbuf_new_from_file(const.icon)