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
|
2007-01-22 09:26:23 +05:30
|
|
|
import sys
|
2006-02-03 01:13:42 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import const
|
2006-11-26 06:59:58 +05:30
|
|
|
import Config
|
2006-02-03 01:13:42 +05:30
|
|
|
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-05-05 06:09:11 +05:30
|
|
|
from DisplayTabs import SourceEmbedList,AttrEmbedList,NoteTab,MediaBackRefList
|
2006-02-03 01:13:42 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# 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-11-27 02:48:30 +05:30
|
|
|
def get_menu_title(self):
|
|
|
|
if self.obj.get_handle():
|
2006-12-12 10:27:36 +05:30
|
|
|
name = self.obj.get_description()
|
|
|
|
if not name:
|
|
|
|
name = self.obj.get_path()
|
|
|
|
if not name:
|
|
|
|
name = self.obj.get_mime_type()
|
|
|
|
if not name:
|
|
|
|
name = _('Note')
|
|
|
|
dialog_title = _('Media: %s') % name
|
2006-11-27 02:48:30 +05:30
|
|
|
else:
|
|
|
|
dialog_title = _('New Media')
|
|
|
|
return dialog_title
|
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
def _local_init(self):
|
|
|
|
assert(self.obj)
|
2007-09-08 11:24:02 +05:30
|
|
|
self.glade = gtk.glade.XML(const.GLADE_FILE,
|
2006-03-01 10:38:11 +05:30
|
|
|
"change_global","gramps")
|
2006-11-26 06:59:58 +05:30
|
|
|
|
2006-12-12 10:27:36 +05:30
|
|
|
self.set_window(self.glade.get_widget('change_global'),
|
|
|
|
None, self.get_menu_title())
|
2006-11-26 06:59:58 +05:30
|
|
|
width = Config.get(Config.MEDIA_WIDTH)
|
|
|
|
height = Config.get(Config.MEDIA_HEIGHT)
|
|
|
|
self.window.resize(width, height)
|
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(
|
2007-03-24 06:00:14 +05:30
|
|
|
self.glade.get_widget("date_entry"),
|
2006-03-01 10:38:11 +05:30
|
|
|
self.glade.get_widget("date_edit"),
|
|
|
|
self.obj.get_date_object(),
|
2006-05-06 08:44:13 +05:30
|
|
|
self.uistate,
|
|
|
|
self.track,
|
2006-03-01 10:38:11 +05:30
|
|
|
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-08-30 05:15:07 +05:30
|
|
|
self.privacy = PrivacyButton(
|
|
|
|
self.glade.get_widget("private"),
|
|
|
|
self.obj, self.db.readonly)
|
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
pixmap = self.glade.get_widget("pixmap")
|
2006-12-10 09:54:11 +05:30
|
|
|
ebox = self.glade.get_widget('eventbox')
|
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-12-10 09:54:11 +05:30
|
|
|
ebox.connect('button-press-event', self.button_press_event)
|
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,
|
2006-10-09 08:15:26 +05:30
|
|
|
SourceEmbedList(self.dbstate,self.uistate,self.track,self.obj))
|
2006-03-01 10:38:11 +05:30
|
|
|
|
|
|
|
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,
|
2007-05-08 02:11:16 +05:30
|
|
|
self.obj.get_note_list(),
|
|
|
|
notetype=RelLib.NoteType.MEDIA))
|
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,
|
2007-05-08 02:11:16 +05:30
|
|
|
self.obj.get_note_list(),
|
|
|
|
notetype=RelLib.NoteType.MEDIA))
|
2006-03-01 10:38:11 +05:30
|
|
|
|
|
|
|
self.src_list = self._add_tab(
|
|
|
|
notebook,
|
2006-10-09 08:15:26 +05:30
|
|
|
SourceEmbedList(self.dbstate,self.uistate,self.track,self.obj))
|
2006-03-01 10:38:11 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
2007-01-16 12:42:10 +05:30
|
|
|
self._setup_notebook_tabs( notebook)
|
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):
|
2006-11-27 02:48:30 +05:30
|
|
|
return (_('Edit Media Object'), self.get_menu_title())
|
2006-02-03 01:13:42 +05:30
|
|
|
|
2006-12-10 09:54:11 +05:30
|
|
|
def button_press_event(self, obj, event):
|
|
|
|
if event.button==1 and event.type == gtk.gdk._2BUTTON_PRESS:
|
|
|
|
self.view_media(obj)
|
|
|
|
|
|
|
|
def view_media(self, obj):
|
|
|
|
|
|
|
|
ref_obj = self.dbstate.db.get_object_from_handle(self.obj.handle)
|
|
|
|
mime_type = ref_obj.get_mime_type()
|
|
|
|
app = Mime.get_application(mime_type)
|
|
|
|
if app:
|
|
|
|
import Utils
|
|
|
|
Utils.launch(app[0],ref_obj.get_path())
|
|
|
|
|
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:
|
2007-01-22 09:26:23 +05:30
|
|
|
self.file_path.set_text(unicode(f.get_filename(),
|
|
|
|
sys.getfilesystemencoding()))
|
2006-02-07 05:14:09 +05:30
|
|
|
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-07-30 09:31:45 +05:30
|
|
|
mime = Mime.get_type(os.path.abspath(path))
|
2006-02-03 01:13:42 +05:30
|
|
|
self.obj.set_mime_type(mime)
|
2006-08-26 19:48:47 +05:30
|
|
|
|
|
|
|
if self.obj.get_mime_type():
|
|
|
|
self.obj.set_path(path)
|
2006-02-03 01:13:42 +05:30
|
|
|
|
|
|
|
trans = self.db.transaction_begin()
|
|
|
|
self.db.commit_media_object(self.obj,trans)
|
|
|
|
self.db.transaction_commit(trans,_("Edit Media Object"))
|
2006-04-24 04:13:36 +05:30
|
|
|
self.close()
|
2006-02-03 01:13:42 +05:30
|
|
|
|
2006-11-26 06:59:58 +05:30
|
|
|
def _cleanup_on_exit(self):
|
|
|
|
self.backref_list.close()
|
|
|
|
(width, height) = self.window.get_size()
|
|
|
|
Config.set(Config.MEDIA_WIDTH, width)
|
|
|
|
Config.set(Config.MEDIA_HEIGHT, height)
|
|
|
|
Config.sync()
|
|
|
|
|
2006-02-03 01:13:42 +05:30
|
|
|
class DeleteMediaQuery:
|
|
|
|
|
2007-01-23 09:07:13 +05:30
|
|
|
def __init__(self,dbstate,uistate,media_handle,the_lists):
|
|
|
|
self.db = dbstate.db
|
|
|
|
self.uistate = uistate
|
2006-02-03 01:13:42 +05:30
|
|
|
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"))
|