2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2004-02-06 12:14:22 +05:30
|
|
|
# Copyright (C) 2000-2004 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-10-20 08:17:03 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
|
|
|
import string
|
2002-11-03 02:49:58 +05:30
|
|
|
import urlparse
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
2003-12-02 09:57:23 +05:30
|
|
|
import gnome
|
2002-10-20 19:55:16 +05:30
|
|
|
import gnome.ui
|
|
|
|
import gnome.canvas
|
|
|
|
import gtk.glade
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import const
|
|
|
|
import Utils
|
|
|
|
import GrampsCfg
|
|
|
|
import Plugins
|
2003-01-10 10:51:32 +05:30
|
|
|
import RelLib
|
2002-10-20 19:55:16 +05:30
|
|
|
import RelImage
|
2002-10-25 10:22:51 +05:30
|
|
|
import ListModel
|
2003-12-12 11:06:38 +05:30
|
|
|
import SelectObject
|
2002-10-28 19:06:39 +05:30
|
|
|
import grampslib
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-10-21 06:48:07 +05:30
|
|
|
from QuestionDialog import ErrorDialog
|
2003-08-17 07:44:33 +05:30
|
|
|
from gettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
_IMAGEX = 140
|
|
|
|
_IMAGEY = 150
|
2002-11-08 09:12:25 +05:30
|
|
|
_PAD = 5
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-08-13 09:58:07 +05:30
|
|
|
_last_path = ""
|
2002-12-17 10:42:28 +05:30
|
|
|
_iconlist_refs = []
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# ImageSelect class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class ImageSelect:
|
|
|
|
|
2003-09-15 09:46:12 +05:30
|
|
|
def __init__(self, path, db, parent, parent_window=None):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Creates an edit window. Associates a person with the window."""
|
|
|
|
self.path = path;
|
|
|
|
self.db = db
|
|
|
|
self.dataobj = None
|
2002-11-08 09:12:25 +05:30
|
|
|
self.parent = parent
|
2003-09-15 09:46:12 +05:30
|
|
|
self.parent_window = parent_window
|
2002-11-08 09:12:25 +05:30
|
|
|
self.canvas_list = {}
|
2003-01-06 10:44:49 +05:30
|
|
|
self.p_map = {}
|
2003-04-09 08:59:08 +05:30
|
|
|
self.canvas = None
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def add_thumbnail(self, photo):
|
|
|
|
"should be overrridden"
|
|
|
|
pass
|
|
|
|
|
|
|
|
def load_images(self):
|
|
|
|
"should be overrridden"
|
|
|
|
pass
|
|
|
|
|
|
|
|
def create_add_dialog(self):
|
|
|
|
"""Create the gnome dialog for selecting a new photo and entering
|
|
|
|
its description."""
|
|
|
|
|
|
|
|
if self.path == '':
|
|
|
|
return
|
|
|
|
|
2003-08-17 07:44:33 +05:30
|
|
|
self.glade = gtk.glade.XML(const.imageselFile,"imageSelect","gramps")
|
2003-12-02 09:57:23 +05:30
|
|
|
self.window = self.glade.get_widget("imageSelect")
|
2003-03-06 11:42:51 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.fname = self.glade.get_widget("fname")
|
|
|
|
self.image = self.glade.get_widget("image")
|
|
|
|
self.description = self.glade.get_widget("photoDescription")
|
|
|
|
self.external = self.glade.get_widget("private")
|
2003-08-13 09:58:07 +05:30
|
|
|
self.photosel = self.glade.get_widget("photosel")
|
2002-10-20 19:55:16 +05:30
|
|
|
self.temp_name = ""
|
|
|
|
|
2003-12-02 09:57:23 +05:30
|
|
|
Utils.set_titles(self.window,self.glade.get_widget('title'),
|
2003-03-06 11:42:51 +05:30
|
|
|
_('Select a media object'))
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.glade.signal_autoconnect({
|
|
|
|
"on_name_changed" : self.on_name_changed,
|
2003-12-02 09:57:23 +05:30
|
|
|
"on_help_imagesel_clicked" : self.on_help_imagesel_clicked,
|
2002-10-20 19:55:16 +05:30
|
|
|
})
|
|
|
|
|
2003-08-13 09:58:07 +05:30
|
|
|
if os.path.isdir(_last_path):
|
|
|
|
self.photosel.set_default_path(_last_path)
|
|
|
|
self.photosel.set_filename(_last_path)
|
|
|
|
self.photosel.gtk_entry().set_position(len(_last_path))
|
2003-09-15 09:46:12 +05:30
|
|
|
|
|
|
|
if self.parent_window:
|
2003-12-02 09:57:23 +05:30
|
|
|
self.window.set_transient_for(self.parent_window)
|
|
|
|
self.window.show()
|
|
|
|
self.val = self.window.run()
|
|
|
|
if self.val == gtk.RESPONSE_OK:
|
2003-09-15 09:46:12 +05:30
|
|
|
self.on_savephoto_clicked()
|
2003-12-02 09:57:23 +05:30
|
|
|
self.window.destroy()
|
|
|
|
|
|
|
|
def on_help_imagesel_clicked(self,obj):
|
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
|
|
|
gnome.help_display('gramps-manual','gramps-edit-quick')
|
|
|
|
self.val = self.window.run()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def on_name_changed(self, obj):
|
|
|
|
"""The filename has changed. Verify it and load the picture."""
|
2003-12-17 10:53:16 +05:30
|
|
|
filename = unicode(self.fname.get_text())
|
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):
|
|
|
|
type = Utils.get_mime_type(filename)
|
|
|
|
if type[0:5] == "image":
|
|
|
|
image = RelImage.scale_image(filename,const.thumbScale)
|
|
|
|
self.image.set_from_pixbuf(image)
|
|
|
|
else:
|
|
|
|
i = gtk.gdk.pixbuf_new_from_file(Utils.find_icon(type))
|
2003-02-04 00:54:27 +05:30
|
|
|
self.image.set_from_pixbuf(i)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-09-15 09:46:12 +05:30
|
|
|
def on_savephoto_clicked(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Save the photo in the dataobj object. (Required function)"""
|
2003-08-13 09:58:07 +05:30
|
|
|
global _last_path
|
|
|
|
|
|
|
|
filename = self.photosel.get_full_path(0)
|
|
|
|
_last_path = os.path.dirname(filename)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-12-17 10:53:16 +05:30
|
|
|
description = unicode(self.description.get_text())
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
if os.path.exists(filename) == 0:
|
2003-02-24 10:21:57 +05:30
|
|
|
msgstr = _("Cannot import %s")
|
|
|
|
msgstr2 = _("The filename supplied could not be found.")
|
2003-05-08 22:42:10 +05:30
|
|
|
ErrorDialog(msgstr % filename, msgstr2)
|
2002-10-20 19:55:16 +05:30
|
|
|
return
|
|
|
|
|
|
|
|
already_imported = None
|
|
|
|
for o in self.db.getObjectMap().values():
|
|
|
|
if o.getPath() == filename:
|
|
|
|
already_imported = o
|
|
|
|
break
|
|
|
|
|
|
|
|
if (already_imported):
|
2003-01-10 10:51:32 +05:30
|
|
|
oref = RelLib.ObjectRef()
|
2002-10-20 19:55:16 +05:30
|
|
|
oref.setReference(already_imported)
|
|
|
|
self.dataobj.addPhoto(oref)
|
|
|
|
self.add_thumbnail(oref)
|
|
|
|
else:
|
|
|
|
type = Utils.get_mime_type(filename)
|
2003-01-10 10:51:32 +05:30
|
|
|
mobj = RelLib.Photo()
|
2002-10-20 19:55:16 +05:30
|
|
|
if description == "":
|
|
|
|
description = os.path.basename(filename)
|
|
|
|
mobj.setDescription(description)
|
|
|
|
mobj.setMimeType(type)
|
2003-02-09 00:46:12 +05:30
|
|
|
self.savephoto(mobj)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
if type[0:5] == "image":
|
|
|
|
if self.external.get_active() == 0:
|
|
|
|
name = RelImage.import_media_object(filename,self.path,
|
|
|
|
mobj.getId())
|
|
|
|
mobj.setLocal(1)
|
|
|
|
else:
|
|
|
|
name = filename
|
|
|
|
else:
|
|
|
|
if self.external.get_active() == 1:
|
|
|
|
name = filename
|
|
|
|
else:
|
|
|
|
name = RelImage.import_media_object(filename,self.path,
|
|
|
|
mobj.getId())
|
|
|
|
mobj.setLocal(1)
|
|
|
|
mobj.setPath(name)
|
|
|
|
|
|
|
|
self.parent.lists_changed = 1
|
|
|
|
self.load_images()
|
|
|
|
|
|
|
|
def savephoto(self, photo):
|
|
|
|
"""Save the photo in the dataobj object - must be overridden"""
|
|
|
|
pass
|
|
|
|
|
2002-11-08 09:12:25 +05:30
|
|
|
_drag_targets = [
|
|
|
|
('STRING', 0, 0),
|
|
|
|
('text/plain',0,0),
|
|
|
|
('text/uri-list',0,2),
|
|
|
|
('application/x-rootwin-drop',0,1)]
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Gallery class - This class handles all the logic underlying a
|
|
|
|
# picture gallery. This class does not load or contain the widget
|
|
|
|
# data structure to actually display the gallery.
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class Gallery(ImageSelect):
|
2003-09-15 09:46:12 +05:30
|
|
|
def __init__(self, dataobj, path, icon_list, db, parent, parent_window=None):
|
|
|
|
ImageSelect.__init__(self, path, db, parent, parent_window)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
if path:
|
2002-11-08 09:12:25 +05:30
|
|
|
icon_list.drag_dest_set(gtk.DEST_DEFAULT_ALL, _drag_targets,
|
2002-10-20 19:55:16 +05:30
|
|
|
gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)
|
2002-11-08 09:12:25 +05:30
|
|
|
icon_list.connect('event',self.item_event)
|
2002-10-20 19:55:16 +05:30
|
|
|
icon_list.connect("drag_data_received",
|
|
|
|
self.on_photolist_drag_data_received)
|
|
|
|
icon_list.connect("drag_data_get",
|
|
|
|
self.on_photolist_drag_data_get)
|
2003-05-17 08:50:50 +05:30
|
|
|
icon_list.connect("drag_begin", self.on_drag_begin)
|
2002-11-08 09:12:25 +05:30
|
|
|
|
2002-12-17 10:42:28 +05:30
|
|
|
_iconlist_refs.append(icon_list)
|
2003-07-06 09:22:38 +05:30
|
|
|
self.in_event = 0
|
2004-02-07 02:27:01 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
# Remember arguments
|
|
|
|
self.path = path;
|
|
|
|
self.dataobj = dataobj;
|
|
|
|
self.iconlist = icon_list;
|
2002-11-28 11:22:02 +05:30
|
|
|
self.root = self.iconlist.root()
|
2004-02-07 06:14:22 +05:30
|
|
|
self.old_photo_list = self.dataobj.getPhotoList()[:]
|
2004-02-07 02:27:01 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
# Local object variables
|
|
|
|
self.y = 0
|
2002-11-08 09:12:25 +05:30
|
|
|
self.remember_x = -1
|
|
|
|
self.remember_y = -1
|
|
|
|
self.button = None
|
|
|
|
self.drag_item = None
|
|
|
|
self.sel = None
|
|
|
|
self.photo = None
|
|
|
|
|
2004-02-07 02:27:01 +05:30
|
|
|
def close(self,ok=0):
|
2002-12-11 10:48:47 +05:30
|
|
|
self.iconlist.hide()
|
2003-01-06 10:44:49 +05:30
|
|
|
for a in self.canvas_list.values():
|
2002-12-17 10:42:28 +05:30
|
|
|
a[0].destroy()
|
|
|
|
a[1].destroy()
|
|
|
|
a[2].destroy()
|
2002-12-11 10:48:47 +05:30
|
|
|
self.p_map = None
|
2002-12-17 10:42:28 +05:30
|
|
|
self.canvas_list = None
|
2004-02-07 06:14:22 +05:30
|
|
|
# restore old photo list, in case we removed some and then
|
|
|
|
# hit cancel button or closed the window
|
|
|
|
if not ok:
|
|
|
|
if self.old_photo_list is not None:
|
|
|
|
self.dataobj.setPhotoList(self.old_photo_list)
|
2004-02-07 02:27:01 +05:30
|
|
|
|
2002-11-27 11:26:23 +05:30
|
|
|
|
2002-11-08 09:12:25 +05:30
|
|
|
def on_canvas1_event(self,obj,event):
|
2003-01-06 10:44:49 +05:30
|
|
|
"""
|
|
|
|
Handle resize events over the canvas, redrawing if the size changes
|
|
|
|
"""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-05-17 08:50:50 +05:30
|
|
|
def on_drag_begin(self,obj,context):
|
2003-06-07 19:41:52 +05:30
|
|
|
if const.dnd_images:
|
2003-05-17 08:50:50 +05:30
|
|
|
mtype = self.sel_obj.getReference().getMimeType()
|
|
|
|
name = Utils.thumb_path(self.db.getSavePath(),self.sel_obj.getReference())
|
|
|
|
pix = gtk.gdk.pixbuf_new_from_file(name)
|
|
|
|
context.set_icon_pixbuf(pix,0,0)
|
|
|
|
|
2002-11-03 02:49:58 +05:30
|
|
|
def item_event(self, widget, event=None):
|
|
|
|
|
2003-07-06 09:22:38 +05:30
|
|
|
if self.in_event:
|
|
|
|
return
|
|
|
|
self.in_event = 1
|
2002-11-08 09:12:25 +05:30
|
|
|
if self.button and event.type == gtk.gdk.MOTION_NOTIFY :
|
2004-02-06 12:14:22 +05:30
|
|
|
if widget.drag_check_threshold(int(self.remember_x),int(self.remember_y),
|
2004-02-04 10:12:06 +05:30
|
|
|
int(event.x),int(event.y)):
|
2002-11-25 10:00:36 +05:30
|
|
|
self.drag_item = widget.get_item_at(self.remember_x,
|
|
|
|
self.remember_y)
|
2003-05-17 08:50:50 +05:30
|
|
|
icon_index = self.get_index(widget,event.x,event.y)-1
|
|
|
|
self.sel_obj = self.dataobj.getPhotoList()[icon_index]
|
2002-11-08 09:12:25 +05:30
|
|
|
if self.drag_item:
|
2003-01-10 10:51:32 +05:30
|
|
|
widget.drag_begin(_drag_targets,
|
|
|
|
gtk.gdk.ACTION_COPY|gtk.gdk.ACTION_MOVE,
|
|
|
|
self.button, event)
|
2003-05-17 08:50:50 +05:30
|
|
|
|
2003-07-06 09:22:38 +05:30
|
|
|
self.in_event = 0
|
2002-11-08 09:12:25 +05:30
|
|
|
return gtk.TRUE
|
2002-11-25 10:00:36 +05:30
|
|
|
|
|
|
|
style = self.iconlist.get_style()
|
2002-11-08 09:12:25 +05:30
|
|
|
|
2002-11-03 02:49:58 +05:30
|
|
|
if event.type == gtk.gdk.BUTTON_PRESS:
|
|
|
|
if event.button == 1:
|
|
|
|
# Remember starting position.
|
2002-11-08 09:12:25 +05:30
|
|
|
|
|
|
|
item = widget.get_item_at(event.x,event.y)
|
|
|
|
if item:
|
2002-12-11 10:48:47 +05:30
|
|
|
(i,t,b,self.photo,oid) = self.p_map[item]
|
2002-11-08 09:12:25 +05:30
|
|
|
t.set(fill_color_gdk=style.fg[gtk.STATE_SELECTED])
|
|
|
|
b.set(fill_color_gdk=style.bg[gtk.STATE_SELECTED])
|
|
|
|
if self.sel:
|
2002-12-11 10:48:47 +05:30
|
|
|
(i,t,b,photo,oid) = self.p_map[self.sel]
|
2002-11-08 09:12:25 +05:30
|
|
|
t.set(fill_color_gdk=style.fg[gtk.STATE_NORMAL])
|
|
|
|
b.set(fill_color_gdk=style.bg[gtk.STATE_NORMAL])
|
|
|
|
|
|
|
|
self.sel = item
|
|
|
|
|
2002-11-03 02:49:58 +05:30
|
|
|
self.remember_x = event.x
|
|
|
|
self.remember_y = event.y
|
2002-11-08 09:12:25 +05:30
|
|
|
self.button = event.button
|
2003-07-06 09:22:38 +05:30
|
|
|
self.in_event = 0
|
2002-11-03 02:49:58 +05:30
|
|
|
return gtk.TRUE
|
|
|
|
|
|
|
|
elif event.button == 3:
|
2002-11-08 09:12:25 +05:30
|
|
|
item = widget.get_item_at(event.x,event.y)
|
|
|
|
if item:
|
2002-12-11 10:48:47 +05:30
|
|
|
(i,t,b,self.photo,oid) = self.p_map[item]
|
2003-10-20 08:17:03 +05:30
|
|
|
self.show_popup(self.photo,event)
|
2003-07-06 09:22:38 +05:30
|
|
|
self.in_event = 0
|
2002-11-03 02:49:58 +05:30
|
|
|
return gtk.TRUE
|
2002-11-08 09:12:25 +05:30
|
|
|
elif event.type == gtk.gdk.BUTTON_RELEASE:
|
|
|
|
self.button = 0
|
2002-11-03 02:49:58 +05:30
|
|
|
elif event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
|
2002-11-25 10:00:36 +05:30
|
|
|
item = widget.get_item_at(event.x,event.y)
|
|
|
|
if item:
|
2002-12-11 10:48:47 +05:30
|
|
|
(i,t,b,self.photo,oid) = self.p_map[item]
|
2004-02-06 12:14:22 +05:30
|
|
|
LocalMediaProperties(self.photo,self.path,self,self.parent_window)
|
2003-07-06 09:22:38 +05:30
|
|
|
self.in_event = 0
|
2002-11-03 02:49:58 +05:30
|
|
|
return gtk.TRUE
|
|
|
|
elif event.type == gtk.gdk.MOTION_NOTIFY:
|
|
|
|
if event.state & gtk.gdk.BUTTON1_MASK:
|
|
|
|
# Get the new position and move by the difference
|
|
|
|
new_x = event.x
|
|
|
|
new_y = event.y
|
|
|
|
|
|
|
|
self.remember_x = new_x
|
|
|
|
self.remember_y = new_y
|
|
|
|
|
2003-07-06 09:22:38 +05:30
|
|
|
self.in_event = 0
|
2002-11-03 02:49:58 +05:30
|
|
|
return gtk.TRUE
|
|
|
|
|
2002-11-08 09:12:25 +05:30
|
|
|
if event.type == gtk.gdk.EXPOSE:
|
|
|
|
self.load_images()
|
2002-11-03 02:49:58 +05:30
|
|
|
|
2003-07-06 09:22:38 +05:30
|
|
|
self.in_event = 0
|
2002-11-03 02:49:58 +05:30
|
|
|
return gtk.FALSE
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def savephoto(self, photo):
|
|
|
|
"""Save the photo in the dataobj object. (Required function)"""
|
|
|
|
self.db.addObject(photo)
|
2003-01-10 10:51:32 +05:30
|
|
|
oref = RelLib.ObjectRef()
|
2002-10-20 19:55:16 +05:30
|
|
|
oref.setReference(photo)
|
|
|
|
self.dataobj.addPhoto(oref)
|
|
|
|
|
|
|
|
def add_thumbnail(self, photo):
|
|
|
|
"""Scale the image and add it to the IconList."""
|
|
|
|
object = photo.getReference()
|
2002-11-08 09:12:25 +05:30
|
|
|
oid = object.getId()
|
2003-05-27 09:13:36 +05:30
|
|
|
|
2002-11-08 09:12:25 +05:30
|
|
|
if self.canvas_list.has_key(oid):
|
2002-11-25 10:00:36 +05:30
|
|
|
(grp,item,text,x,y) = self.canvas_list[oid]
|
2002-11-08 09:12:25 +05:30
|
|
|
if x != self.cx or y != self.cy:
|
|
|
|
grp.move(self.cx-x,self.cy-y)
|
|
|
|
else:
|
2003-02-05 19:23:00 +05:30
|
|
|
import gobject
|
|
|
|
|
2002-11-08 09:12:25 +05:30
|
|
|
name = Utils.thumb_path(self.db.getSavePath(),object)
|
2003-02-09 00:46:12 +05:30
|
|
|
|
2002-11-08 09:12:25 +05:30
|
|
|
description = object.getDescription()
|
|
|
|
if len(description) > 20:
|
|
|
|
description = "%s..." % description[0:20]
|
|
|
|
|
2003-02-05 19:23:00 +05:30
|
|
|
try:
|
|
|
|
image = gtk.gdk.pixbuf_new_from_file(name)
|
|
|
|
except gobject.GError,msg:
|
|
|
|
ErrorDialog(str(msg))
|
|
|
|
image = gtk.gdk.pixbuf_new_from_file(const.icon)
|
|
|
|
except:
|
|
|
|
ErrorDialog(_("Thumbnail %s could not be found") % name)
|
|
|
|
image = gtk.gdk.pixbuf_new_from_file(const.icon)
|
|
|
|
|
2002-11-08 09:12:25 +05:30
|
|
|
x = image.get_width()
|
|
|
|
y = image.get_height()
|
|
|
|
|
|
|
|
grp = self.root.add(gnome.canvas.CanvasGroup,x=self.cx,y=self.cy)
|
|
|
|
|
|
|
|
xloc = (_IMAGEX-x)/2
|
|
|
|
yloc = (_IMAGEY-y)/2
|
|
|
|
|
2002-11-25 10:00:36 +05:30
|
|
|
style = self.iconlist.get_style()
|
|
|
|
|
|
|
|
box = grp.add(gnome.canvas.CanvasRect,x1=0,x2=_IMAGEX,y1=_IMAGEY-20,
|
|
|
|
y2=_IMAGEY, fill_color_gdk=style.bg[gtk.STATE_NORMAL])
|
2002-11-08 09:12:25 +05:30
|
|
|
item = grp.add(gnome.canvas.CanvasPixbuf,
|
2002-11-25 10:00:36 +05:30
|
|
|
pixbuf=image,x=xloc, y=yloc)
|
|
|
|
text = grp.add(gnome.canvas.CanvasText, x=_IMAGEX/2,
|
2002-11-08 09:12:25 +05:30
|
|
|
anchor=gtk.ANCHOR_CENTER,
|
2002-11-25 10:00:36 +05:30
|
|
|
justification=gtk.JUSTIFY_CENTER,
|
|
|
|
y=_IMAGEY-10, text=description)
|
2002-11-08 09:12:25 +05:30
|
|
|
|
2004-01-06 10:32:06 +05:30
|
|
|
# make sure that the text string doesn't exceed the size of the box
|
|
|
|
|
2004-01-06 10:04:19 +05:30
|
|
|
bnds = text.get_bounds()
|
|
|
|
while bnds[0] <0:
|
|
|
|
description = description[0:-4] + "..."
|
|
|
|
text.set(text=description)
|
|
|
|
bnds = text.get_bounds()
|
|
|
|
|
2002-11-25 10:00:36 +05:30
|
|
|
for i in [ item, text, box, grp ] :
|
2002-11-28 11:22:02 +05:30
|
|
|
self.p_map[i] = (item,text,box,photo,oid)
|
2002-11-25 10:00:36 +05:30
|
|
|
i.show()
|
2002-11-08 09:12:25 +05:30
|
|
|
|
2002-11-25 10:00:36 +05:30
|
|
|
self.canvas_list[oid] = (grp,item,text,self.cx,self.cy)
|
2002-11-08 09:12:25 +05:30
|
|
|
|
2003-05-27 09:13:36 +05:30
|
|
|
self.cx += _PAD + _IMAGEX
|
|
|
|
|
2002-11-08 09:12:25 +05:30
|
|
|
if self.cx + _PAD + _IMAGEX > self.x:
|
|
|
|
self.cx = _PAD
|
2003-05-27 09:13:36 +05:30
|
|
|
self.cy += _PAD + _IMAGEY
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def load_images(self):
|
|
|
|
"""clears the currentImages list to free up any cached
|
|
|
|
Imlibs. Then add each photo in the place's list of photos to the
|
|
|
|
photolist window."""
|
|
|
|
|
|
|
|
self.pos = 0
|
2002-11-08 09:12:25 +05:30
|
|
|
self.cx = _PAD
|
|
|
|
self.cy = _PAD
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-11-03 02:49:58 +05:30
|
|
|
(self.x,self.y) = self.iconlist.get_size()
|
|
|
|
|
2002-11-08 09:12:25 +05:30
|
|
|
self.max = (self.x)/(_IMAGEX+_PAD)
|
2002-11-03 02:49:58 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
for photo in self.dataobj.getPhotoList():
|
|
|
|
self.add_thumbnail(photo)
|
|
|
|
|
|
|
|
if self.cy > self.y:
|
|
|
|
self.iconlist.set_scroll_region(0,0,self.x,self.cy)
|
|
|
|
else:
|
|
|
|
self.iconlist.set_scroll_region(0,0,self.x,self.y)
|
2003-11-13 00:15:07 +05:30
|
|
|
|
|
|
|
if self.dataobj.getPhotoList():
|
|
|
|
Utils.bold_label(self.parent.gallery_label)
|
|
|
|
else:
|
|
|
|
Utils.unbold_label(self.parent.gallery_label)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-11-03 02:49:58 +05:30
|
|
|
def get_index(self,obj,x,y):
|
2002-11-08 09:12:25 +05:30
|
|
|
x_offset = x/(_IMAGEX+_PAD)
|
|
|
|
y_offset = y/(_IMAGEY+_PAD)
|
|
|
|
index = (y_offset*(1+self.max))+x_offset
|
2002-11-03 02:49:58 +05:30
|
|
|
return min(index,len(self.dataobj.getPhotoList()))
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def on_photolist_drag_data_received(self,w, context, x, y, data, info, time):
|
|
|
|
if data and data.format == 8:
|
2002-11-03 02:49:58 +05:30
|
|
|
icon_index = self.get_index(w,x,y)
|
2002-10-20 19:55:16 +05:30
|
|
|
d = string.strip(string.replace(data.data,'\0',' '))
|
|
|
|
protocol,site,file, j,k,l = urlparse.urlparse(d)
|
|
|
|
if protocol == "file":
|
|
|
|
name = file
|
|
|
|
mime = Utils.get_mime_type(name)
|
2003-01-10 10:51:32 +05:30
|
|
|
photo = RelLib.Photo()
|
2002-10-20 19:55:16 +05:30
|
|
|
photo.setPath(name)
|
|
|
|
photo.setMimeType(mime)
|
|
|
|
basename = os.path.basename(name)
|
|
|
|
(root,ext) = os.path.splitext(basename)
|
|
|
|
photo.setDescription(root)
|
|
|
|
self.savephoto(photo)
|
|
|
|
if GrampsCfg.mediaref == 0:
|
|
|
|
name = RelImage.import_media_object(name,self.path,photo.getId())
|
|
|
|
photo.setPath(name)
|
|
|
|
photo.setLocal(1)
|
|
|
|
self.parent.lists_changed = 1
|
|
|
|
if GrampsCfg.globalprop:
|
|
|
|
Utils.modified()
|
|
|
|
GlobalMediaProperties(self.db,photo,None)
|
|
|
|
elif protocol != "":
|
|
|
|
import urllib
|
|
|
|
u = urllib.URLopener()
|
|
|
|
try:
|
|
|
|
tfile,headers = u.retrieve(d)
|
|
|
|
except IOError, msg:
|
|
|
|
t = _("Could not import %s") % d
|
2003-02-24 10:21:57 +05:30
|
|
|
ErrorDialog(t,str(msg))
|
2002-10-20 19:55:16 +05:30
|
|
|
return
|
|
|
|
mime = Utils.get_mime_type(tfile)
|
2003-01-10 10:51:32 +05:30
|
|
|
photo = RelLib.Photo()
|
2002-10-20 19:55:16 +05:30
|
|
|
photo.setMimeType(mime)
|
|
|
|
photo.setDescription(d)
|
|
|
|
photo.setLocal(1)
|
|
|
|
photo.setPath(tfile)
|
|
|
|
self.db.addObject(photo)
|
2003-01-10 10:51:32 +05:30
|
|
|
oref = RelLib.ObjectRef()
|
2002-10-20 19:55:16 +05:30
|
|
|
oref.setReference(photo)
|
|
|
|
self.dataobj.addPhoto(oref)
|
|
|
|
try:
|
|
|
|
id = photo.getId()
|
|
|
|
name = RelImage.import_media_object(tfile,self.path,id)
|
|
|
|
photo.setLocal(1)
|
|
|
|
photo.setPath(name)
|
|
|
|
except:
|
|
|
|
photo.setPath(tfile)
|
|
|
|
return
|
|
|
|
self.add_thumbnail(oref)
|
|
|
|
self.parent.lists_changed = 1
|
|
|
|
if GrampsCfg.globalprop:
|
|
|
|
Utils.modified()
|
|
|
|
GlobalMediaProperties(self.db,photo,None)
|
|
|
|
else:
|
|
|
|
if self.db.getObjectMap().has_key(data.data):
|
2002-11-03 02:49:58 +05:30
|
|
|
icon_index = self.get_index(w,x,y)
|
2002-10-20 19:55:16 +05:30
|
|
|
index = 0
|
|
|
|
for p in self.dataobj.getPhotoList():
|
|
|
|
if data.data == p.getReference().getId():
|
|
|
|
if index == icon_index or icon_index == -1:
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
nl = self.dataobj.getPhotoList()
|
|
|
|
item = nl[index]
|
|
|
|
if icon_index == 0:
|
|
|
|
del nl[index]
|
|
|
|
nl = [item] + nl
|
|
|
|
else:
|
|
|
|
del nl[index]
|
|
|
|
nl = nl[0:icon_index] + [item] + nl[icon_index:]
|
|
|
|
self.dataobj.setPhotoList(nl)
|
|
|
|
Utils.modified()
|
|
|
|
self.parent.lists_changed = 1
|
|
|
|
self.load_images()
|
|
|
|
return
|
|
|
|
index = index + 1
|
2003-01-10 10:51:32 +05:30
|
|
|
oref = RelLib.ObjectRef()
|
2002-10-20 19:55:16 +05:30
|
|
|
oref.setReference(self.db.findObjectNoMap(data.data))
|
|
|
|
self.dataobj.addPhoto(oref)
|
|
|
|
self.add_thumbnail(oref)
|
|
|
|
self.parent.lists_changed = 1
|
|
|
|
if GrampsCfg.globalprop:
|
2004-02-06 12:14:22 +05:30
|
|
|
LocalMediaProperties(oref,self.path,self,self.parent_window)
|
2002-10-20 19:55:16 +05:30
|
|
|
Utils.modified()
|
|
|
|
|
|
|
|
def on_photolist_drag_data_get(self,w, context, selection_data, info, time):
|
|
|
|
if info == 1:
|
|
|
|
return
|
2002-11-28 11:22:02 +05:30
|
|
|
id = self.p_map[self.drag_item]
|
|
|
|
selection_data.set(selection_data.target, 8, id[4])
|
2002-11-08 09:12:25 +05:30
|
|
|
self.drag_item = None
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def on_add_photo_clicked(self, obj):
|
|
|
|
"""User wants to add a new photo. Create a dialog to find out
|
|
|
|
which photo they want."""
|
|
|
|
self.create_add_dialog()
|
|
|
|
|
2003-12-12 11:06:38 +05:30
|
|
|
def on_select_photo_clicked(self,obj):
|
|
|
|
"""User wants to add a new object that is already in a database.
|
|
|
|
Create a dialog to find out which object they want."""
|
|
|
|
|
|
|
|
s_o = SelectObject.SelectObject(self.db,_("Select an Object"))
|
|
|
|
object = s_o.run()
|
|
|
|
if not object:
|
|
|
|
return
|
|
|
|
oref = RelLib.ObjectRef()
|
|
|
|
oref.setReference(object)
|
|
|
|
self.dataobj.addPhoto(oref)
|
|
|
|
self.add_thumbnail(oref)
|
|
|
|
|
|
|
|
self.parent.lists_changed = 1
|
|
|
|
self.load_images()
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def on_delete_photo_clicked(self, obj):
|
|
|
|
"""User wants to delete a new photo. Remove it from the displayed
|
|
|
|
thumbnails, and remove it from the dataobj photo list."""
|
|
|
|
|
2002-11-10 00:14:58 +05:30
|
|
|
if self.sel:
|
2002-12-11 10:48:47 +05:30
|
|
|
(i,t,b,photo,oid) = self.p_map[self.sel]
|
2002-11-10 00:14:58 +05:30
|
|
|
val = self.canvas_list[photo.getReference().getId()]
|
|
|
|
val[0].hide()
|
|
|
|
val[1].hide()
|
|
|
|
val[2].hide()
|
|
|
|
|
|
|
|
l = self.dataobj.getPhotoList()
|
|
|
|
l.remove(photo)
|
|
|
|
self.dataobj.setPhotoList(l)
|
|
|
|
self.parent.lists_changed = 1
|
|
|
|
self.load_images()
|
2003-03-03 10:02:53 +05:30
|
|
|
|
|
|
|
def on_edit_photo_clicked(self, obj):
|
|
|
|
"""User wants to delete a new photo. Remove it from the displayed
|
|
|
|
thumbnails, and remove it from the dataobj photo list."""
|
|
|
|
|
|
|
|
if self.sel:
|
|
|
|
(i,t,b,photo,oid) = self.p_map[self.sel]
|
2004-02-06 12:14:22 +05:30
|
|
|
LocalMediaProperties(photo,self.path,self,self.parent_window)
|
2002-11-10 00:14:58 +05:30
|
|
|
|
2003-10-20 08:17:03 +05:30
|
|
|
def show_popup(self, photo, event):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Look for right-clicks on a picture and create a popup
|
|
|
|
menu of the available actions."""
|
2002-11-03 02:49:58 +05:30
|
|
|
|
|
|
|
menu = gtk.Menu()
|
2003-02-09 00:46:12 +05:30
|
|
|
menu.set_title(_("Media Object"))
|
2002-11-03 02:49:58 +05:30
|
|
|
object = photo.getReference()
|
|
|
|
mtype = object.getMimeType()
|
|
|
|
progname = grampslib.default_application_name(mtype)
|
|
|
|
|
|
|
|
Utils.add_menuitem(menu,_("Open in %s") % progname,
|
|
|
|
photo,self.popup_view_photo)
|
|
|
|
if mtype[0:5] == "image":
|
|
|
|
Utils.add_menuitem(menu,_("Edit with the GIMP"),
|
|
|
|
photo,self.popup_edit_photo)
|
|
|
|
Utils.add_menuitem(menu,_("Edit Object Properties"),photo,
|
|
|
|
self.popup_change_description)
|
|
|
|
if object.getLocal() == 0:
|
|
|
|
Utils.add_menuitem(menu,_("Convert to local copy"),photo,
|
|
|
|
self.popup_convert_to_private)
|
2003-10-20 08:17:03 +05:30
|
|
|
menu.popup(None,None,None,event.button,event.time)
|
2002-11-03 02:49:58 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def popup_view_photo(self, obj):
|
|
|
|
"""Open this picture in a picture viewer"""
|
2002-11-03 02:49:58 +05:30
|
|
|
photo = obj.get_data('o')
|
2002-10-20 19:55:16 +05:30
|
|
|
Utils.view_photo(photo.getReference())
|
|
|
|
|
|
|
|
def popup_edit_photo(self, obj):
|
|
|
|
"""Open this picture in a picture editor"""
|
2002-11-08 09:40:31 +05:30
|
|
|
photo = obj.get_data('o')
|
2002-10-20 19:55:16 +05:30
|
|
|
if os.fork() == 0:
|
|
|
|
os.execvp(const.editor,[const.editor,
|
|
|
|
photo.getReference().getPath()])
|
|
|
|
|
|
|
|
def popup_convert_to_private(self, obj):
|
|
|
|
"""Copy this picture into gramps private database instead of
|
|
|
|
leaving it as an external data object."""
|
2002-11-08 09:40:31 +05:30
|
|
|
photo = obj.get_data('o')
|
2002-10-20 19:55:16 +05:30
|
|
|
object = photo.getReference()
|
|
|
|
name = RelImage.import_media_object(object.getPath(),self.path,
|
|
|
|
object.getId())
|
|
|
|
object.setPath(name)
|
|
|
|
object.setLocal(1)
|
|
|
|
|
|
|
|
def popup_change_description(self, obj):
|
|
|
|
"""Bring up a window allowing the user to edit the description
|
|
|
|
of a picture."""
|
2002-11-08 09:40:31 +05:30
|
|
|
photo = obj.get_data('o')
|
|
|
|
LocalMediaProperties(photo,self.path,self)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# LocalMediaProperties
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class LocalMediaProperties:
|
|
|
|
|
2004-02-06 12:14:22 +05:30
|
|
|
def __init__(self,photo,path,parent,parent_window=None):
|
2002-10-20 19:55:16 +05:30
|
|
|
self.photo = photo
|
|
|
|
self.object = photo.getReference()
|
|
|
|
self.alist = photo.getAttributeList()[:]
|
|
|
|
self.lists_changed = 0
|
|
|
|
self.parent = parent
|
2002-11-25 10:00:36 +05:30
|
|
|
self.db = parent.db
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
fname = self.object.getPath()
|
2003-08-17 07:44:33 +05:30
|
|
|
self.change_dialog = gtk.glade.XML(const.imageselFile,"change_description","gramps")
|
2003-03-06 11:42:51 +05:30
|
|
|
|
|
|
|
title = _('Change local media object properties')
|
|
|
|
Utils.set_titles(self.change_dialog.get_widget('change_description'),
|
|
|
|
self.change_dialog.get_widget('title'), title)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
descr_window = self.change_dialog.get_widget("description")
|
2002-11-25 10:00:36 +05:30
|
|
|
self.pixmap = self.change_dialog.get_widget("pixmap")
|
2002-10-20 19:55:16 +05:30
|
|
|
self.attr_type = self.change_dialog.get_widget("attr_type")
|
|
|
|
self.attr_value = self.change_dialog.get_widget("attr_value")
|
|
|
|
self.attr_details = self.change_dialog.get_widget("attr_details")
|
2002-10-25 10:22:51 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.attr_list = self.change_dialog.get_widget("attr_list")
|
2002-12-11 10:48:47 +05:30
|
|
|
titles = [(_('Attribute'),0,150),(_('Value'),0,100)]
|
2002-10-25 10:22:51 +05:30
|
|
|
|
2003-12-16 06:07:47 +05:30
|
|
|
self.attr_label = self.change_dialog.get_widget("attr_local")
|
|
|
|
self.notes_label = self.change_dialog.get_widget("notes_local")
|
|
|
|
self.flowed = self.change_dialog.get_widget("flowed")
|
|
|
|
self.preform = self.change_dialog.get_widget("preform")
|
|
|
|
|
2002-11-25 10:00:36 +05:30
|
|
|
self.atree = ListModel.ListModel(self.attr_list,titles,
|
|
|
|
self.on_attr_list_select_row,
|
|
|
|
self.on_update_attr_clicked)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
descr_window.set_text(self.object.getDescription())
|
|
|
|
mtype = self.object.getMimeType()
|
|
|
|
|
2002-11-25 10:00:36 +05:30
|
|
|
thumb = Utils.thumb_path(path,self.object)
|
|
|
|
if os.path.isfile(thumb):
|
|
|
|
self.pix = gtk.gdk.pixbuf_new_from_file(thumb)
|
|
|
|
self.pixmap.set_from_pixbuf(self.pix)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
self.change_dialog.get_widget("private").set_active(photo.getPrivacy())
|
|
|
|
self.change_dialog.get_widget("gid").set_text(self.object.getId())
|
|
|
|
|
|
|
|
if self.object.getLocal():
|
|
|
|
self.change_dialog.get_widget("path").set_text("<local>")
|
|
|
|
else:
|
|
|
|
self.change_dialog.get_widget("path").set_text(fname)
|
|
|
|
|
|
|
|
mt = Utils.get_mime_description(mtype)
|
|
|
|
self.change_dialog.get_widget("type").set_text(mt)
|
2003-12-16 06:07:47 +05:30
|
|
|
self.notes = self.change_dialog.get_widget("notes")
|
|
|
|
if self.photo.getNote():
|
|
|
|
self.notes.get_buffer().set_text(self.photo.getNote())
|
|
|
|
Utils.bold_label(self.notes_label)
|
|
|
|
if self.photo.getNoteFormat() == 1:
|
|
|
|
self.preform.set_active(1)
|
|
|
|
else:
|
|
|
|
self.flowed.set_active(1)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.change_dialog.signal_autoconnect({
|
|
|
|
"on_add_attr_clicked": self.on_add_attr_clicked,
|
2003-12-16 06:07:47 +05:30
|
|
|
"on_notebook_switch_page": self.on_notebook_switch_page,
|
2003-03-03 10:02:53 +05:30
|
|
|
"on_update_attr_clicked": self.on_update_attr_clicked,
|
2002-10-20 19:55:16 +05:30
|
|
|
"on_delete_attr_clicked" : self.on_delete_attr_clicked,
|
2003-12-16 06:07:47 +05:30
|
|
|
"on_help_clicked" : self.on_help_clicked,
|
2002-10-20 19:55:16 +05:30
|
|
|
})
|
|
|
|
self.redraw_attr_list()
|
2004-02-06 12:14:22 +05:30
|
|
|
self.window = self.change_dialog.get_widget('change_description')
|
|
|
|
if parent_window:
|
|
|
|
self.window.set_transient_for(parent_window)
|
|
|
|
self.val = self.window.run()
|
|
|
|
if self.val == gtk.RESPONSE_OK:
|
|
|
|
self.on_ok_clicked()
|
|
|
|
self.window.destroy()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def redraw_attr_list(self):
|
2002-11-25 10:00:36 +05:30
|
|
|
self.atree.clear()
|
2003-06-11 08:24:57 +05:30
|
|
|
self.amap = {}
|
2002-11-25 10:00:36 +05:30
|
|
|
for attr in self.alist:
|
|
|
|
d = [attr.getType(),attr.getValue()]
|
2003-06-11 08:24:57 +05:30
|
|
|
iter = self.atree.add(d,attr)
|
|
|
|
self.amap[str(attr)] = iter
|
2003-12-16 06:07:47 +05:30
|
|
|
if self.alist:
|
|
|
|
Utils.bold_label(self.attr_label)
|
|
|
|
else:
|
|
|
|
Utils.unbold_label(self.attr_label)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-12-16 06:07:47 +05:30
|
|
|
def on_notebook_switch_page(self,obj,junk,page):
|
|
|
|
t = self.notes.get_buffer()
|
2003-12-17 21:36:36 +05:30
|
|
|
text = unicode(t.get_text(t.get_start_iter(),t.get_end_iter(),gtk.FALSE))
|
2003-12-16 06:07:47 +05:30
|
|
|
if text:
|
|
|
|
Utils.bold_label(self.notes_label)
|
|
|
|
else:
|
|
|
|
Utils.unbold_label(self.notes_label)
|
|
|
|
|
2004-02-06 12:14:22 +05:30
|
|
|
def on_apply_clicked(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
priv = self.change_dialog.get_widget("private").get_active()
|
2002-10-27 09:13:12 +05:30
|
|
|
|
2003-12-16 06:07:47 +05:30
|
|
|
t = self.notes.get_buffer()
|
2003-12-17 21:36:36 +05:30
|
|
|
text = unicode(t.get_text(t.get_start_iter(),t.get_end_iter(),gtk.FALSE))
|
2002-10-20 19:55:16 +05:30
|
|
|
note = self.photo.getNote()
|
2003-12-16 06:07:47 +05:30
|
|
|
format = self.preform.get_active()
|
2002-10-20 19:55:16 +05:30
|
|
|
if text != note or priv != self.photo.getPrivacy():
|
|
|
|
self.photo.setNote(text)
|
|
|
|
self.photo.setPrivacy(priv)
|
|
|
|
self.parent.lists_changed = 1
|
|
|
|
Utils.modified()
|
2003-12-16 06:07:47 +05:30
|
|
|
if format != self.photo.getNoteFormat():
|
|
|
|
self.photo.setNoteFormat(format)
|
|
|
|
Utils.modified()
|
2002-10-20 19:55:16 +05:30
|
|
|
if self.lists_changed:
|
|
|
|
self.photo.setAttributeList(self.alist)
|
|
|
|
self.parent.lists_changed = 1
|
|
|
|
Utils.modified()
|
|
|
|
|
2003-12-16 06:07:47 +05:30
|
|
|
def on_help_clicked(self, obj):
|
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
|
|
|
gnome.help_display('gramps-manual','gramps-edit-complete')
|
2004-02-06 12:14:22 +05:30
|
|
|
self.val = self.window.run()
|
2003-12-16 06:07:47 +05:30
|
|
|
|
2004-02-06 12:14:22 +05:30
|
|
|
def on_ok_clicked(self):
|
|
|
|
self.on_apply_clicked()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-11-25 10:00:36 +05:30
|
|
|
def on_attr_list_select_row(self,obj):
|
|
|
|
store,iter = self.atree.get_selected()
|
2002-10-25 10:22:51 +05:30
|
|
|
if iter:
|
2002-11-25 10:00:36 +05:30
|
|
|
attr = self.atree.get_object(iter)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-10-25 10:22:51 +05:30
|
|
|
self.attr_type.set_label(attr.getType())
|
|
|
|
self.attr_value.set_text(attr.getValue())
|
|
|
|
else:
|
|
|
|
self.attr_type.set_label('')
|
|
|
|
self.attr_value.set_text('')
|
2003-06-11 08:24:57 +05:30
|
|
|
|
|
|
|
def attr_callback(self,attr):
|
|
|
|
self.redraw_attr_list()
|
|
|
|
self.atree.select_iter(self.amap[str(attr)])
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def on_update_attr_clicked(self,obj):
|
|
|
|
import AttrEdit
|
2002-10-25 10:22:51 +05:30
|
|
|
|
2002-11-25 10:00:36 +05:30
|
|
|
store,iter = self.atree.get_selected()
|
2002-10-25 10:22:51 +05:30
|
|
|
if iter:
|
2002-11-25 10:00:36 +05:30
|
|
|
attr = self.atree.get_object(iter)
|
2002-10-20 19:55:16 +05:30
|
|
|
AttrEdit.AttributeEditor(self,attr,"Media Object",
|
2003-06-11 08:24:57 +05:30
|
|
|
Plugins.get_image_attributes(),
|
|
|
|
self.attr_callback)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def on_delete_attr_clicked(self,obj):
|
|
|
|
if Utils.delete_selected(obj,self.alist):
|
|
|
|
self.lists_changed = 1
|
|
|
|
self.redraw_attr_list()
|
|
|
|
|
|
|
|
def on_add_attr_clicked(self,obj):
|
|
|
|
import AttrEdit
|
|
|
|
AttrEdit.AttributeEditor(self,None,"Media Object",
|
2003-06-11 08:24:57 +05:30
|
|
|
Plugins.get_image_attributes(),
|
|
|
|
self.attr_callback)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GlobalMediaProperties
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class GlobalMediaProperties:
|
|
|
|
|
|
|
|
def __init__(self,db,object,update):
|
|
|
|
self.object = object
|
|
|
|
self.alist = self.object.getAttributeList()[:]
|
|
|
|
self.lists_changed = 0
|
|
|
|
self.db = db
|
|
|
|
self.update = update
|
|
|
|
self.refs = 0
|
2003-04-11 07:44:51 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.path = self.db.getSavePath()
|
2003-08-17 07:44:33 +05:30
|
|
|
self.change_dialog = gtk.glade.XML(const.imageselFile,"change_global","gramps")
|
2003-03-06 11:42:51 +05:30
|
|
|
|
2003-04-10 01:19:11 +05:30
|
|
|
title = _('Change global media object properties')
|
2003-03-06 11:42:51 +05:30
|
|
|
|
|
|
|
Utils.set_titles(self.change_dialog.get_widget('change_global'),
|
|
|
|
self.change_dialog.get_widget('title'),title)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.descr_window = self.change_dialog.get_widget("description")
|
|
|
|
self.notes = self.change_dialog.get_widget("notes")
|
2002-11-25 10:00:36 +05:30
|
|
|
self.pixmap = self.change_dialog.get_widget("pixmap")
|
2002-10-20 19:55:16 +05:30
|
|
|
self.attr_type = self.change_dialog.get_widget("attr_type")
|
|
|
|
self.attr_value = self.change_dialog.get_widget("attr_value")
|
|
|
|
self.attr_details = self.change_dialog.get_widget("attr_details")
|
2002-10-25 10:22:51 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.attr_list = self.change_dialog.get_widget("attr_list")
|
2002-11-25 10:00:36 +05:30
|
|
|
|
2003-11-14 00:20:01 +05:30
|
|
|
self.attr_label = self.change_dialog.get_widget("attrGlobal")
|
|
|
|
self.notes_label = self.change_dialog.get_widget("notesGlobal")
|
|
|
|
self.refs_label = self.change_dialog.get_widget("refsGlobal")
|
2003-12-16 06:07:47 +05:30
|
|
|
self.flowed = self.change_dialog.get_widget("global_flowed")
|
|
|
|
self.preform = self.change_dialog.get_widget("global_preform")
|
2003-11-14 00:20:01 +05:30
|
|
|
|
2002-12-11 10:48:47 +05:30
|
|
|
titles = [(_('Attribute'),0,150),(_('Value'),1,100)]
|
2002-11-25 10:00:36 +05:30
|
|
|
|
|
|
|
self.atree = ListModel.ListModel(self.attr_list,titles,
|
|
|
|
self.on_attr_list_select_row,
|
|
|
|
self.on_update_attr_clicked)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
self.descr_window.set_text(self.object.getDescription())
|
|
|
|
mtype = self.object.getMimeType()
|
|
|
|
pb = gtk.gdk.pixbuf_new_from_file(Utils.thumb_path(self.path,self.object))
|
2002-11-25 10:00:36 +05:30
|
|
|
self.pixmap.set_from_pixbuf(pb)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
self.change_dialog.get_widget("gid").set_text(self.object.getId())
|
|
|
|
self.makelocal = self.change_dialog.get_widget("makelocal")
|
|
|
|
|
|
|
|
self.update_info()
|
|
|
|
|
|
|
|
self.change_dialog.get_widget("type").set_text(Utils.get_mime_description(mtype))
|
2003-11-14 00:20:01 +05:30
|
|
|
if self.object.getNote():
|
2003-12-16 06:07:47 +05:30
|
|
|
self.notes.get_buffer().set_text(self.object.getNote())
|
2003-11-14 00:20:01 +05:30
|
|
|
Utils.bold_label(self.notes_label)
|
2003-12-16 06:07:47 +05:30
|
|
|
if self.object.getNoteFormat() == 1:
|
|
|
|
self.preform.set_active(1)
|
|
|
|
else:
|
|
|
|
self.flowed.set_active(1)
|
2003-11-14 00:20:01 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.change_dialog.signal_autoconnect({
|
|
|
|
"on_cancel_clicked" : Utils.destroy_passed_object,
|
|
|
|
"on_up_clicked" : self.on_up_clicked,
|
|
|
|
"on_down_clicked" : self.on_down_clicked,
|
|
|
|
"on_ok_clicked" : self.on_ok_clicked,
|
|
|
|
"on_apply_clicked" : self.on_apply_clicked,
|
|
|
|
"on_add_attr_clicked" : self.on_add_attr_clicked,
|
|
|
|
"on_notebook_switch_page": self.on_notebook_switch_page,
|
|
|
|
"on_make_local_clicked" : self.on_make_local_clicked,
|
|
|
|
"on_delete_attr_clicked" : self.on_delete_attr_clicked,
|
|
|
|
"on_update_attr_clicked" : self.on_update_attr_clicked,
|
2003-12-02 09:57:23 +05:30
|
|
|
"on_help_clicked" : self.on_help_clicked,
|
2002-10-20 19:55:16 +05:30
|
|
|
})
|
|
|
|
self.redraw_attr_list()
|
2003-11-14 00:20:01 +05:30
|
|
|
self.display_refs()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def on_up_clicked(self,obj):
|
2002-11-25 10:00:36 +05:30
|
|
|
store,iter = self.atree.get_selected()
|
2002-10-25 10:22:51 +05:30
|
|
|
if iter:
|
2002-11-25 10:00:36 +05:30
|
|
|
row = self.atree.get_row(iter)
|
|
|
|
if row != 0:
|
|
|
|
self.atree.select_row(row-1)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def on_down_clicked(self,obj):
|
2002-11-25 10:00:36 +05:30
|
|
|
model,iter = self.atree.get_selected()
|
|
|
|
if not iter:
|
|
|
|
return
|
|
|
|
row = self.atree.get_row(iter)
|
|
|
|
self.atree.select_row(row+1)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def update_info(self):
|
|
|
|
fname = self.object.getPath()
|
|
|
|
if self.object.getLocal():
|
|
|
|
self.change_dialog.get_widget("path").set_text("<local>")
|
|
|
|
self.makelocal.set_sensitive(0)
|
|
|
|
else:
|
|
|
|
self.change_dialog.get_widget("path").set_text(fname)
|
|
|
|
self.makelocal.set_sensitive(1)
|
|
|
|
|
|
|
|
def on_make_local_clicked(self, obj):
|
|
|
|
name = RelImage.import_media_object(self.object.getPath(),
|
|
|
|
self.path,
|
|
|
|
self.object.getId())
|
|
|
|
self.object.setPath(name)
|
|
|
|
self.object.setLocal(1)
|
|
|
|
self.update_info()
|
|
|
|
if self.update != None:
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
def redraw_attr_list(self):
|
2002-11-25 10:00:36 +05:30
|
|
|
self.atree.clear()
|
2003-06-11 08:24:57 +05:30
|
|
|
self.amap = {}
|
2002-11-25 10:00:36 +05:30
|
|
|
for attr in self.alist:
|
|
|
|
d = [attr.getType(),attr.getValue()]
|
2003-06-11 08:24:57 +05:30
|
|
|
iter = self.atree.add(d,attr)
|
|
|
|
self.amap[str(attr)] = iter
|
2003-11-14 00:20:01 +05:30
|
|
|
if self.alist:
|
|
|
|
Utils.bold_label(self.attr_label)
|
|
|
|
else:
|
|
|
|
Utils.unbold_label(self.attr_label)
|
|
|
|
|
2003-05-17 08:50:50 +05:30
|
|
|
def button_press(self,obj):
|
2002-10-25 10:22:51 +05:30
|
|
|
store,iter = self.refmodel.selection.get_selected()
|
|
|
|
if not iter:
|
2002-10-20 19:55:16 +05:30
|
|
|
return
|
2002-10-25 10:22:51 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def display_refs(self):
|
|
|
|
if self.refs == 1:
|
|
|
|
return
|
|
|
|
self.refs = 1
|
2002-10-25 10:22:51 +05:30
|
|
|
|
2002-11-25 10:00:36 +05:30
|
|
|
titles = [(_('Type'),0,150),(_('ID'),1,75),(_('Value'),2,100)]
|
2002-10-25 10:22:51 +05:30
|
|
|
self.refmodel = ListModel.ListModel(self.change_dialog.get_widget("refinfo"),
|
2002-11-25 10:00:36 +05:30
|
|
|
titles,event_func=self.button_press)
|
2003-11-14 00:20:01 +05:30
|
|
|
any = 0
|
2002-10-20 19:55:16 +05:30
|
|
|
for key in self.db.getPersonKeys():
|
|
|
|
p = self.db.getPerson(key)
|
|
|
|
for o in p.getPhotoList():
|
|
|
|
if o.getReference() == self.object:
|
2002-10-25 10:22:51 +05:30
|
|
|
self.refmodel.add([_("Person"),p.getId(),GrampsCfg.nameof(p)])
|
2003-11-14 00:20:01 +05:30
|
|
|
any = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
for p in self.db.getFamilyMap().values():
|
|
|
|
for o in p.getPhotoList():
|
|
|
|
if o.getReference() == self.object:
|
2002-10-25 10:22:51 +05:30
|
|
|
self.refmodel.add([_("Family"),p.getId(),Utils.family_name(p)])
|
2003-11-14 00:20:01 +05:30
|
|
|
any = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
for key in self.db.getSourceKeys():
|
|
|
|
p = self.db.getSource(key)
|
|
|
|
for o in p.getPhotoList():
|
|
|
|
if o.getReference() == self.object:
|
2002-10-25 10:22:51 +05:30
|
|
|
self.refmodel.add([_("Source"),p.getId(),p.getTitle()])
|
2003-11-14 00:20:01 +05:30
|
|
|
any = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
for key in self.db.getPlaceKeys():
|
|
|
|
p = self.db.getPlace(key)
|
|
|
|
for o in p.getPhotoList():
|
|
|
|
if o.getReference() == self.object:
|
2002-10-25 10:22:51 +05:30
|
|
|
self.refmodel.add([_("Place"),p.getId(),p.get_title()])
|
2003-11-14 00:20:01 +05:30
|
|
|
any = 1
|
|
|
|
if any:
|
|
|
|
Utils.bold_label(self.refs_label)
|
|
|
|
else:
|
|
|
|
Utils.unbold_label(self.refs_label)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def on_notebook_switch_page(self,obj,junk,page):
|
|
|
|
if page == 3:
|
|
|
|
self.display_refs()
|
2003-11-14 00:20:01 +05:30
|
|
|
t = self.notes.get_buffer()
|
2003-12-17 21:36:36 +05:30
|
|
|
text = unicode(t.get_text(t.get_start_iter(),t.get_end_iter(),gtk.FALSE))
|
2003-11-14 00:20:01 +05:30
|
|
|
if text:
|
|
|
|
Utils.bold_label(self.notes_label)
|
|
|
|
else:
|
|
|
|
Utils.unbold_label(self.notes_label)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def on_apply_clicked(self, obj):
|
2002-10-27 09:13:12 +05:30
|
|
|
t = self.notes.get_buffer()
|
2003-12-17 21:36:36 +05:30
|
|
|
text = unicode(t.get_text(t.get_start_iter(),t.get_end_iter(),gtk.FALSE))
|
2003-12-17 10:53:16 +05:30
|
|
|
desc = unicode(self.descr_window.get_text())
|
2002-10-20 19:55:16 +05:30
|
|
|
note = self.object.getNote()
|
2003-12-16 06:07:47 +05:30
|
|
|
format = self.preform.get_active()
|
2002-10-20 19:55:16 +05:30
|
|
|
if text != note or desc != self.object.getDescription():
|
|
|
|
self.object.setNote(text)
|
|
|
|
self.object.setDescription(desc)
|
|
|
|
Utils.modified()
|
2003-12-16 06:07:47 +05:30
|
|
|
if format != self.object.getNoteFormat():
|
|
|
|
self.object.setNoteFormat(format)
|
|
|
|
Utils.modified()
|
2002-10-20 19:55:16 +05:30
|
|
|
if self.lists_changed:
|
|
|
|
self.object.setAttributeList(self.alist)
|
|
|
|
Utils.modified()
|
|
|
|
if self.update != None:
|
|
|
|
self.update()
|
|
|
|
|
2003-12-02 09:57:23 +05:30
|
|
|
def on_help_clicked(self, obj):
|
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
|
|
|
gnome.help_display('gramps-manual','gramps-edit-complete')
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def on_ok_clicked(self, obj):
|
|
|
|
self.on_apply_clicked(obj)
|
|
|
|
Utils.destroy_passed_object(obj)
|
2003-12-02 09:57:23 +05:30
|
|
|
|
2003-03-03 10:02:53 +05:30
|
|
|
def on_attr_list_select_row(self,obj):
|
2002-11-25 10:00:36 +05:30
|
|
|
store,iter = self.atree.get_selected()
|
2002-10-25 10:22:51 +05:30
|
|
|
if iter:
|
2002-11-25 10:00:36 +05:30
|
|
|
attr = self.atree.get_object(iter)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-10-25 10:22:51 +05:30
|
|
|
self.attr_type.set_label(attr.getType())
|
|
|
|
self.attr_value.set_text(attr.getValue())
|
|
|
|
else:
|
|
|
|
self.attr_type.set_label('')
|
|
|
|
self.attr_value.set_text('')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-06-11 08:24:57 +05:30
|
|
|
def attr_callback(self,attr):
|
|
|
|
self.redraw_attr_list()
|
|
|
|
self.atree.select_iter(self.amap[str(attr)])
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def on_update_attr_clicked(self,obj):
|
|
|
|
import AttrEdit
|
2002-10-25 10:22:51 +05:30
|
|
|
|
2002-11-25 10:00:36 +05:30
|
|
|
store,iter = self.atree.get_selected()
|
2002-10-25 10:22:51 +05:30
|
|
|
if iter:
|
2002-11-25 10:00:36 +05:30
|
|
|
attr = self.atree.get_object(iter)
|
2002-10-20 19:55:16 +05:30
|
|
|
AttrEdit.AttributeEditor(self,attr,"Media Object",
|
2003-06-11 08:24:57 +05:30
|
|
|
Plugins.get_image_attributes(),
|
|
|
|
self.attr_callback)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def on_delete_attr_clicked(self,obj):
|
|
|
|
if Utils.delete_selected(obj,self.alist):
|
|
|
|
self.lists_changed = 1
|
|
|
|
self.redraw_attr_list()
|
|
|
|
|
|
|
|
def on_add_attr_clicked(self,obj):
|
|
|
|
import AttrEdit
|
|
|
|
AttrEdit.AttributeEditor(self,None,"Media Object",
|
2003-06-11 08:24:57 +05:30
|
|
|
Plugins.get_image_attributes(),
|
|
|
|
self.attr_callback)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
class DeleteMediaQuery:
|
|
|
|
|
|
|
|
def __init__(self,media,db,update):
|
|
|
|
self.db = db
|
|
|
|
self.media = media
|
|
|
|
self.update = update
|
|
|
|
|
|
|
|
def query_response(self):
|
|
|
|
del self.db.getObjectMap()[self.media.getId()]
|
|
|
|
Utils.modified()
|
|
|
|
|
|
|
|
for key in self.db.getPersonKeys():
|
|
|
|
p = self.db.getPerson(key)
|
|
|
|
nl = []
|
|
|
|
change = 0
|
|
|
|
for photo in p.getPhotoList():
|
|
|
|
if photo.getReference() != self.media:
|
|
|
|
nl.append(photo)
|
|
|
|
else:
|
|
|
|
change = 1
|
|
|
|
if change:
|
|
|
|
p.setPhotoList(nl)
|
|
|
|
|
|
|
|
for p in self.db.getFamilyMap().values():
|
|
|
|
nl = []
|
|
|
|
change = 0
|
|
|
|
for photo in p.getPhotoList():
|
|
|
|
if photo.getReference() != self.media:
|
|
|
|
nl.append(photo)
|
|
|
|
else:
|
|
|
|
change = 1
|
|
|
|
if change:
|
|
|
|
p.setPhotoList(nl)
|
|
|
|
|
|
|
|
for key in self.db.getSourceKeys():
|
|
|
|
p = self.db.getSource(key)
|
|
|
|
nl = []
|
|
|
|
change = 0
|
|
|
|
for photo in p.getPhotoList():
|
|
|
|
if photo.getReference() != self.media:
|
|
|
|
nl.append(photo)
|
|
|
|
else:
|
|
|
|
change = 1
|
|
|
|
if change:
|
|
|
|
p.setPhotoList(nl)
|
|
|
|
|
|
|
|
for key in self.db.getPlaceKeys():
|
|
|
|
p = self.db.getPlace(key)
|
|
|
|
nl = []
|
|
|
|
change = 0
|
|
|
|
for photo in p.getPhotoList():
|
|
|
|
if photo.getReference() != self.media:
|
|
|
|
nl.append(photo)
|
|
|
|
else:
|
|
|
|
change = 1
|
|
|
|
if change:
|
|
|
|
p.setPhotoList(nl)
|
|
|
|
|
|
|
|
if self.update:
|
|
|
|
self.update(0)
|