2006-02-03 01:13:42 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-02-04 03:33:53 +05:30
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2006-02-03 01:13:42 +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
|
|
|
|
#
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2006-02-07 05:14:09 +05:30
|
|
|
import os
|
2006-02-03 01:13:42 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gobject
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import const
|
|
|
|
import Utils
|
|
|
|
import RelLib
|
2006-03-03 05:53:04 +05:30
|
|
|
import Mime
|
2006-02-03 01:13:42 +05:30
|
|
|
import ImgManip
|
2006-03-04 12:04:48 +05:30
|
|
|
from _EditPrimary import EditPrimary
|
2006-02-03 01:13:42 +05:30
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
from GrampsWidgets import *
|
2006-02-03 01:13:42 +05:30
|
|
|
from QuestionDialog import ErrorDialog
|
|
|
|
from DisplayTabs import *
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# EditMedia
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-03-04 12:04:48 +05:30
|
|
|
class EditMedia(EditPrimary):
|
2006-02-03 01:13:42 +05:30
|
|
|
|
|
|
|
def __init__(self,state,uistate,track,obj):
|
|
|
|
|
2006-03-04 12:04:48 +05:30
|
|
|
EditPrimary.__init__(self, state, uistate, track, obj,
|
|
|
|
state.db.get_object_from_handle)
|
2006-03-01 10:38:11 +05:30
|
|
|
|
2006-04-01 01:16:41 +05:30
|
|
|
def empty_object(self):
|
|
|
|
return RelLib.MediaObject()
|
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
def _local_init(self):
|
|
|
|
assert(self.obj)
|
|
|
|
self.glade = gtk.glade.XML(const.gladeFile,
|
|
|
|
"change_global","gramps")
|
2006-04-24 03:48:01 +05:30
|
|
|
self.set_window(self.glade.get_widget('change_global'),
|
|
|
|
self.glade.get_widget('title'),
|
|
|
|
_('Media Properties Editor'))
|
2006-03-01 10:38:11 +05:30
|
|
|
|
|
|
|
def _connect_signals(self):
|
|
|
|
self.define_cancel_button(self.glade.get_widget('button91'))
|
|
|
|
self.define_ok_button(self.glade.get_widget('ok'),self.save)
|
|
|
|
self.define_help_button(self.glade.get_widget('button102'),'adv-media')
|
|
|
|
|
|
|
|
def _setup_fields(self):
|
|
|
|
self.date_field = MonitoredDate(
|
|
|
|
self.glade.get_widget('date'),
|
|
|
|
self.glade.get_widget("date_edit"),
|
|
|
|
self.obj.get_date_object(),
|
|
|
|
self.window,
|
|
|
|
self.db.readonly)
|
|
|
|
|
|
|
|
self.descr_window = MonitoredEntry(
|
|
|
|
self.glade.get_widget("description"),
|
|
|
|
self.obj.set_description,
|
|
|
|
self.obj.get_description,
|
|
|
|
self.db.readonly)
|
2006-02-03 01:13:42 +05:30
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
self.gid = MonitoredEntry(
|
|
|
|
self.glade.get_widget("gid"),
|
|
|
|
self.obj.set_gramps_id,
|
|
|
|
self.obj.get_gramps_id,
|
|
|
|
self.db.readonly)
|
2006-02-03 01:13:42 +05:30
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
pixmap = self.glade.get_widget("pixmap")
|
2006-02-03 01:13:42 +05:30
|
|
|
|
|
|
|
mtype = self.obj.get_mime_type()
|
|
|
|
if mtype:
|
|
|
|
pb = ImgManip.get_thumbnail_image(self.obj.get_path(),mtype)
|
2006-03-01 10:38:11 +05:30
|
|
|
pixmap.set_from_pixbuf(pb)
|
2006-03-03 05:53:04 +05:30
|
|
|
descr = Mime.get_description(mtype)
|
2006-02-03 01:13:42 +05:30
|
|
|
if descr:
|
2006-03-01 10:38:11 +05:30
|
|
|
self.glade.get_widget("type").set_text(descr)
|
2006-02-03 01:13:42 +05:30
|
|
|
else:
|
2006-03-03 05:53:04 +05:30
|
|
|
pb = Mime.find_mime_type_pixbuf('text/plain')
|
2006-03-01 10:38:11 +05:30
|
|
|
pixmap.set_from_pixbuf(pb)
|
|
|
|
self.glade.get_widget("type").set_text(_('Note'))
|
2006-02-03 01:13:42 +05:30
|
|
|
|
2006-02-09 02:43:05 +05:30
|
|
|
self.setup_filepath()
|
2006-02-03 01:13:42 +05:30
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
def _create_tabbed_pages(self):
|
|
|
|
notebook = gtk.Notebook()
|
2006-02-03 01:13:42 +05:30
|
|
|
|
2006-02-09 02:43:05 +05:30
|
|
|
if self.obj.get_mime_type():
|
2006-03-01 10:38:11 +05:30
|
|
|
self.src_list = self._add_tab(
|
|
|
|
notebook,
|
|
|
|
SourceEmbedList(self.dbstate,self.uistate,
|
|
|
|
self.track,self.obj.source_list))
|
|
|
|
|
|
|
|
self.attr_list = self._add_tab(
|
|
|
|
notebook,
|
|
|
|
AttrEmbedList(self.dbstate, self.uistate, self.track,
|
|
|
|
self.obj.get_attribute_list()))
|
|
|
|
|
|
|
|
self.note_tab = self._add_tab(
|
|
|
|
notebook,
|
|
|
|
NoteTab(self.dbstate, self.uistate, self.track,
|
|
|
|
self.obj.get_note_object()))
|
2006-02-09 02:43:05 +05:30
|
|
|
else:
|
2006-03-01 10:38:11 +05:30
|
|
|
self.note_tab = self._add_tab(
|
|
|
|
notebook,
|
|
|
|
NoteTab(self.dbstate, self.uistate, self.track,
|
|
|
|
self.obj.get_note_object()))
|
|
|
|
|
|
|
|
self.src_list = self._add_tab(
|
|
|
|
notebook,
|
|
|
|
SourceEmbedList(self.dbstate,self.uistate,
|
|
|
|
self.track,self.obj.source_list))
|
|
|
|
|
|
|
|
self.attr_list = self._add_tab(
|
|
|
|
notebook,
|
|
|
|
AttrEmbedList(self.dbstate, self.uistate, self.track,
|
|
|
|
self.obj.get_attribute_list()))
|
2006-02-03 01:13:42 +05:30
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
self.backref_list = self._add_tab(
|
|
|
|
notebook,
|
|
|
|
MediaBackRefList(self.dbstate,self.uistate,self.track,
|
2006-04-22 02:04:26 +05:30
|
|
|
self.db.find_backlink_handles(self.obj.handle)))
|
2006-02-25 03:30:20 +05:30
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
notebook.show_all()
|
|
|
|
self.glade.get_widget('vbox').pack_start(notebook,True)
|
2006-02-25 03:30:20 +05:30
|
|
|
|
2006-02-03 01:13:42 +05:30
|
|
|
def build_menu_names(self,person):
|
|
|
|
win_menu_label = _("Media Properties")
|
|
|
|
return (_('Edit Media Object'),win_menu_label)
|
|
|
|
|
2006-02-07 05:14:09 +05:30
|
|
|
def select_file(self,obj):
|
2006-03-01 10:38:11 +05:30
|
|
|
f = gtk.FileChooserDialog(
|
|
|
|
_('Select Media Object'),
|
|
|
|
action=gtk.FILE_CHOOSER_ACTION_OPEN,
|
|
|
|
buttons=(gtk.STOCK_CANCEL,
|
|
|
|
gtk.RESPONSE_CANCEL,
|
|
|
|
gtk.STOCK_OPEN,
|
|
|
|
gtk.RESPONSE_OK))
|
2006-02-07 05:14:09 +05:30
|
|
|
|
|
|
|
text = self.file_path.get_text()
|
|
|
|
path = os.path.dirname(text)
|
|
|
|
|
|
|
|
f.set_filename(path)
|
|
|
|
|
|
|
|
status = f.run()
|
|
|
|
if status == gtk.RESPONSE_OK:
|
|
|
|
self.file_path.set_text(f.get_filename())
|
|
|
|
f.destroy()
|
|
|
|
|
2006-02-09 02:43:05 +05:30
|
|
|
def setup_filepath(self):
|
2006-03-01 10:38:11 +05:30
|
|
|
self.select = self.glade.get_widget('file_select')
|
|
|
|
self.file_path = self.glade.get_widget("path")
|
2006-02-09 02:43:05 +05:30
|
|
|
|
|
|
|
if self.obj.get_mime_type():
|
|
|
|
fname = self.obj.get_path()
|
|
|
|
self.file_path.set_text(fname)
|
|
|
|
self.select.connect('clicked', self.select_file)
|
|
|
|
else:
|
2006-03-01 10:38:11 +05:30
|
|
|
self.glade.get_widget('path_label').hide()
|
2006-02-09 02:43:05 +05:30
|
|
|
self.file_path.hide()
|
|
|
|
self.select.hide()
|
2006-02-03 01:13:42 +05:30
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
def save(self, *obj):
|
|
|
|
path = self.glade.get_widget('path').get_text()
|
2006-02-05 04:59:44 +05:30
|
|
|
|
2006-02-03 01:13:42 +05:30
|
|
|
if path != self.obj.get_path():
|
2006-03-03 05:53:04 +05:30
|
|
|
mime = Mime.get_type(path)
|
2006-02-03 01:13:42 +05:30
|
|
|
self.obj.set_mime_type(mime)
|
|
|
|
self.obj.set_path(path)
|
|
|
|
|
|
|
|
trans = self.db.transaction_begin()
|
|
|
|
self.db.commit_media_object(self.obj,trans)
|
|
|
|
self.db.transaction_commit(trans,_("Edit Media Object"))
|
2006-03-01 10:38:11 +05:30
|
|
|
self.close_window()
|
2006-02-03 01:13:42 +05:30
|
|
|
|
|
|
|
class DeleteMediaQuery:
|
|
|
|
|
|
|
|
def __init__(self,media_handle,db,the_lists):
|
|
|
|
self.db = db
|
|
|
|
self.media_handle = media_handle
|
|
|
|
self.the_lists = the_lists
|
|
|
|
|
|
|
|
def query_response(self):
|
|
|
|
trans = self.db.transaction_begin()
|
|
|
|
self.db.disable_signals()
|
|
|
|
|
|
|
|
(person_list,family_list,event_list,
|
|
|
|
place_list,source_list) = self.the_lists
|
|
|
|
|
|
|
|
for handle in person_list:
|
|
|
|
person = self.db.get_person_from_handle(handle)
|
|
|
|
new_list = [ photo for photo in person.get_media_list() \
|
|
|
|
if photo.get_reference_handle() != self.media_handle ]
|
|
|
|
person.set_media_list(new_list)
|
|
|
|
self.db.commit_person(person,trans)
|
|
|
|
|
|
|
|
for handle in family_list:
|
|
|
|
family = self.db.get_family_from_handle(handle)
|
|
|
|
new_list = [ photo for photo in family.get_media_list() \
|
|
|
|
if photo.get_reference_handle() != self.media_handle ]
|
|
|
|
family.set_media_list(new_list)
|
|
|
|
self.db.commit_family(family,trans)
|
|
|
|
|
|
|
|
for handle in event_list:
|
|
|
|
event = self.db.get_event_from_handle(handle)
|
|
|
|
new_list = [ photo for photo in event.get_media_list() \
|
|
|
|
if photo.get_reference_handle() != self.media_handle ]
|
|
|
|
event.set_media_list(new_list)
|
|
|
|
self.db.commit_event(event,trans)
|
|
|
|
|
|
|
|
for handle in place_list:
|
|
|
|
place = self.db.get_place_from_handle(handle)
|
|
|
|
new_list = [ photo for photo in place.get_media_list() \
|
|
|
|
if photo.get_reference_handle() != self.media_handle ]
|
|
|
|
place.set_media_list(new_list)
|
|
|
|
self.db.commit_place(place,trans)
|
|
|
|
|
|
|
|
for handle in source_list:
|
|
|
|
source = self.db.get_source_from_handle(handle)
|
|
|
|
new_list = [ photo for photo in source.get_media_list() \
|
|
|
|
if photo.get_reference_handle() != self.media_handle ]
|
|
|
|
source.set_media_list(new_list)
|
|
|
|
self.db.commit_source(source,trans)
|
|
|
|
|
|
|
|
self.db.enable_signals()
|
|
|
|
self.db.remove_object(self.media_handle,trans)
|
|
|
|
self.db.transaction_commit(trans,_("Remove Media Object"))
|
|
|
|
|