2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2003-09-10 19:08:02 +05:30
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2003-12-02 09:57:23 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
|
|
|
Provides the interface to allow a person to add a media object to the database.
|
|
|
|
"""
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# internationalization
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
2003-08-17 07:44:33 +05:30
|
|
|
from gettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-21 06:48:07 +05:30
|
|
|
from QuestionDialog import ErrorDialog
|
2002-10-20 19:55:16 +05:30
|
|
|
import gtk.glade
|
2003-12-02 09:57:23 +05:30
|
|
|
import gnome
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import const
|
|
|
|
import Utils
|
|
|
|
import RelImage
|
|
|
|
import RelLib
|
2004-04-04 10:09:52 +05:30
|
|
|
import GrampsMime
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# AddMediaObject
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class AddMediaObject:
|
|
|
|
"""
|
|
|
|
Displays the Add Media Dialog window, allowing the user to select
|
|
|
|
a media object from the file system, while providing a description.
|
|
|
|
"""
|
|
|
|
|
2003-09-10 19:08:02 +05:30
|
|
|
def __init__(self,db,update=None):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
|
|
|
Creates and displays the dialog box
|
|
|
|
|
|
|
|
db - the database in which the new object is to be stored
|
|
|
|
update - a function to call to update the display
|
|
|
|
"""
|
|
|
|
self.db = db
|
2003-08-17 07:44:33 +05:30
|
|
|
self.glade = gtk.glade.XML(const.imageselFile,"imageSelect","gramps")
|
2002-10-20 19:55:16 +05:30
|
|
|
self.window = self.glade.get_widget("imageSelect")
|
|
|
|
self.description = self.glade.get_widget("photoDescription")
|
|
|
|
self.image = self.glade.get_widget("image")
|
|
|
|
self.file_text = self.glade.get_widget("fname")
|
2005-02-16 11:11:33 +05:30
|
|
|
self.internal = self.glade.get_widget('internal')
|
|
|
|
self.internal.connect('toggled',self.internal_toggled)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.update = update
|
|
|
|
self.temp_name = ""
|
2003-09-10 19:08:02 +05:30
|
|
|
self.object = None
|
2003-08-13 09:58:07 +05:30
|
|
|
|
|
|
|
Utils.set_titles(self.window,self.glade.get_widget('title'),
|
|
|
|
_('Select a media object'))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
self.glade.signal_autoconnect({
|
2004-07-10 10:19:53 +05:30
|
|
|
"on_fname_update_preview" : self.on_name_changed,
|
|
|
|
"on_help_imagesel_clicked" : self.on_help_imagesel_clicked,
|
2002-10-20 19:55:16 +05:30
|
|
|
})
|
|
|
|
|
|
|
|
self.window.show()
|
|
|
|
|
2005-02-16 11:11:33 +05:30
|
|
|
def internal_toggled(self, obj):
|
|
|
|
self.file_text.set_sensitive(not obj.get_active())
|
|
|
|
|
2004-07-10 10:19:53 +05:30
|
|
|
def on_help_imagesel_clicked(self,obj):
|
2003-12-02 09:57:23 +05:30
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
|
|
|
gnome.help_display('gramps-manual','gramps-edit-quick')
|
2004-07-10 10:19:53 +05:30
|
|
|
self.val = self.window.run()
|
2003-12-02 09:57:23 +05:30
|
|
|
|
2003-09-10 19:08:02 +05:30
|
|
|
def on_savephoto_clicked(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
|
|
|
Callback function called with the save button is pressed.
|
|
|
|
A new media object is created, and added to the database.
|
|
|
|
"""
|
2005-02-16 11:11:33 +05:30
|
|
|
|
2003-12-17 10:53:16 +05:30
|
|
|
description = unicode(self.description.get_text())
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-02-16 11:11:33 +05:30
|
|
|
if self.internal.get_active():
|
|
|
|
import NoteEdit
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-02-16 11:11:33 +05:30
|
|
|
mobj = RelLib.MediaObject()
|
|
|
|
mobj.set_description(description)
|
|
|
|
mobj.set_mime_type(None)
|
|
|
|
else:
|
|
|
|
filename = self.file_text.get_filename()
|
|
|
|
|
|
|
|
if os.path.exists(filename) == 0:
|
|
|
|
msgstr = _("Cannot import %s")
|
|
|
|
msgstr2 = _("The filename supplied could not be found.")
|
|
|
|
ErrorDialog(msgstr % filename, msgstr2)
|
|
|
|
return
|
|
|
|
|
|
|
|
mtype = GrampsMime.get_type(filename)
|
|
|
|
if description == "":
|
|
|
|
description = os.path.basename(filename)
|
|
|
|
|
|
|
|
mobj = RelLib.MediaObject()
|
|
|
|
mobj.set_description(description)
|
|
|
|
mobj.set_mime_type(mtype)
|
|
|
|
name = filename
|
|
|
|
mobj.set_path(name)
|
2004-07-10 10:19:53 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
trans = self.db.transaction_begin()
|
2004-07-10 10:19:53 +05:30
|
|
|
self.db.add_object(mobj,trans)
|
2003-09-10 19:08:02 +05:30
|
|
|
self.object = mobj
|
2004-03-30 10:20:24 +05:30
|
|
|
self.db.commit_media_object(mobj,trans)
|
2004-08-13 10:04:07 +05:30
|
|
|
self.db.transaction_commit(trans,_("Add Media Object"))
|
2004-07-10 10:19:53 +05:30
|
|
|
if self.update:
|
2004-08-31 09:21:05 +05:30
|
|
|
self.update(mobj.get_handle())
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def on_name_changed(self,*obj):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
|
|
|
Called anytime the filename text window changes. Checks to
|
|
|
|
see if the file exists. If it does, the imgae is loaded into
|
|
|
|
the preview window.
|
|
|
|
"""
|
2004-07-10 10:19:53 +05:30
|
|
|
filename = unicode(self.file_text.get_filename())
|
2002-10-20 19:55:16 +05:30
|
|
|
basename = os.path.basename(filename)
|
|
|
|
(root,ext) = os.path.splitext(basename)
|
2003-12-17 10:53:16 +05:30
|
|
|
old_title = unicode(self.description.get_text())
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
if old_title == '' or old_title == self.temp_name:
|
|
|
|
self.description.set_text(root)
|
|
|
|
self.temp_name = root
|
|
|
|
|
|
|
|
if os.path.isfile(filename):
|
2004-05-14 04:15:51 +05:30
|
|
|
mtype = GrampsMime.get_type(filename)
|
2004-04-04 10:09:52 +05:30
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
if mtype[0:5] == "image":
|
2002-10-20 19:55:16 +05:30
|
|
|
image = RelImage.scale_image(filename,const.thumbScale)
|
|
|
|
else:
|
2004-07-10 10:19:53 +05:30
|
|
|
image = gtk.gdk.pixbuf_new_from_file(Utils.find_icon(mtype))
|
2003-02-08 22:58:41 +05:30
|
|
|
self.image.set_from_pixbuf(image)
|
2003-09-10 19:08:02 +05:30
|
|
|
|
|
|
|
def run(self):
|
2003-12-02 09:57:23 +05:30
|
|
|
while 1:
|
|
|
|
val = self.window.run()
|
|
|
|
|
|
|
|
if val == gtk.RESPONSE_OK:
|
|
|
|
self.on_savephoto_clicked()
|
|
|
|
self.window.destroy()
|
|
|
|
return self.object
|
|
|
|
elif val == gtk.RESPONSE_HELP:
|
2004-10-08 09:29:55 +05:30
|
|
|
self.on_help_imagesel_clicked(None)
|
2003-12-02 09:57:23 +05:30
|
|
|
else:
|
|
|
|
self.window.destroy()
|
|
|
|
return None
|
2004-05-14 04:15:51 +05:30
|
|
|
return None
|