2001-05-13 07:26:57 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000 Donald N. Allingham
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2001-06-17 19:14:35 +05:30
|
|
|
import gtk
|
2001-08-31 09:10:23 +05:30
|
|
|
import gnome.mime
|
2001-10-12 04:26:48 +05:30
|
|
|
from gnome.ui import *
|
2001-08-31 09:10:23 +05:30
|
|
|
import string
|
|
|
|
import os
|
|
|
|
import const
|
2001-10-17 05:39:42 +05:30
|
|
|
import RelImage
|
2001-09-01 08:54:35 +05:30
|
|
|
import intl
|
|
|
|
|
|
|
|
_ = intl.gettext
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
_modifiedFlag = 0
|
|
|
|
|
2001-08-31 09:10:23 +05:30
|
|
|
LISTOBJ = "s"
|
2001-09-03 08:48:54 +05:30
|
|
|
OBJECT = "o"
|
2001-08-31 09:10:23 +05:30
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Sets the modified flag, which is used to determine if the database
|
|
|
|
# needs to be saved. Anytime a routine modifies data, it should call
|
|
|
|
# this routine.
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def modified():
|
|
|
|
global _modifiedFlag
|
|
|
|
_modifiedFlag = 1
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Clears the modified flag. Should be called after data is saved.
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def clearModified():
|
|
|
|
global _modifiedFlag
|
|
|
|
_modifiedFlag = 0
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Returns the modified flag
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def wasModified():
|
|
|
|
return _modifiedFlag
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Short hand function to return either the person's name, or an empty
|
|
|
|
# string if the person is None
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def phonebook_name(person):
|
|
|
|
if person:
|
|
|
|
return person.getPrimaryName().getName()
|
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Short hand function to return either the person's name, or an empty
|
|
|
|
# string if the person is None
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def phonebook_from_name(name,alt):
|
|
|
|
if alt:
|
2001-06-17 19:14:35 +05:30
|
|
|
return "%s *" % name.getName()
|
2001-05-13 07:26:57 +05:30
|
|
|
else:
|
|
|
|
return name.getName()
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Short hand function to return either the person's name, or an empty
|
|
|
|
# string if the person is None
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def normal_name(person):
|
|
|
|
if person:
|
|
|
|
return person.getPrimaryName().getRegularName()
|
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def destroy_passed_object(obj):
|
|
|
|
obj.destroy()
|
|
|
|
while gtk.events_pending():
|
|
|
|
gtk.mainiteration()
|
|
|
|
|
2001-06-07 19:19:00 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Get around python's interpretation of commas/periods in floating
|
|
|
|
# point numbers
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if string.find("%.3f" % 1.2, ",") == -1:
|
|
|
|
_use_comma = 0
|
|
|
|
else:
|
|
|
|
_use_comma = 1
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2001-10-19 05:41:06 +05:30
|
|
|
if _use_comma:
|
|
|
|
def txt2fl(st):
|
2001-06-07 19:19:00 +05:30
|
|
|
return string.atof(string.replace(st,'.',','))
|
2001-10-19 05:41:06 +05:30
|
|
|
else:
|
|
|
|
def txt2fl(st):
|
2001-06-07 19:19:00 +05:30
|
|
|
return string.atof(string.replace(st,',','.'))
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2001-10-19 05:41:06 +05:30
|
|
|
if _use_comma:
|
|
|
|
def fl2txt(fmt,val):
|
|
|
|
return string.replace(fmt % val, ',', '.')
|
|
|
|
else:
|
|
|
|
def fl2txt(fmt,val):
|
|
|
|
return fmt % val
|
2001-08-31 09:10:23 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def get_detail_flags(obj):
|
|
|
|
import Config
|
|
|
|
|
|
|
|
detail = ""
|
|
|
|
if Config.show_detail:
|
|
|
|
if obj.getNote() != "":
|
|
|
|
detail = "N"
|
2001-10-06 23:55:31 +05:30
|
|
|
if len(obj.getSourceRefList()) > 0:
|
2001-08-31 09:10:23 +05:30
|
|
|
detail = detail + "S"
|
|
|
|
if obj.getPrivacy():
|
|
|
|
detail = detail + "P"
|
|
|
|
return detail
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def get_detail_text(obj):
|
|
|
|
if obj.getNote() != "":
|
|
|
|
details = "%s" % _("Note")
|
|
|
|
else:
|
|
|
|
details = ""
|
2001-10-06 23:55:31 +05:30
|
|
|
if len(obj.getSourceRefList()) > 0:
|
2001-08-31 09:10:23 +05:30
|
|
|
if details == "":
|
|
|
|
details = _("Source")
|
|
|
|
else:
|
|
|
|
details = "%s, %s" % (details,_("Source"))
|
|
|
|
if obj.getPrivacy() == 1:
|
|
|
|
if details == "":
|
|
|
|
details = _("Private")
|
|
|
|
else:
|
|
|
|
details = "%s, %s" % (details,_("Private"))
|
|
|
|
return details
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def build_confidence_menu(menu):
|
|
|
|
myMenu = gtk.GtkMenu()
|
|
|
|
index = 0
|
|
|
|
for name in const.confidence:
|
|
|
|
item = gtk.GtkMenuItem(name)
|
|
|
|
item.set_data("a",index)
|
|
|
|
item.show()
|
|
|
|
myMenu.append(item)
|
|
|
|
index = index + 1
|
|
|
|
menu.set_menu(myMenu)
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def redraw_list(dlist,clist,func):
|
|
|
|
clist.freeze()
|
|
|
|
clist.clear()
|
|
|
|
|
|
|
|
index = 0
|
|
|
|
for object in dlist:
|
|
|
|
clist.append(func(object))
|
|
|
|
clist.set_row_data(index,object)
|
|
|
|
index = index + 1
|
|
|
|
|
2001-10-07 03:01:38 +05:30
|
|
|
if len(clist.selection) == 0:
|
|
|
|
current_row = 0
|
|
|
|
else:
|
|
|
|
current_row = clist.selection[0]
|
|
|
|
|
|
|
|
clist.select_row(current_row,0)
|
|
|
|
clist.moveto(current_row,0)
|
2001-08-31 09:10:23 +05:30
|
|
|
clist.thaw()
|
|
|
|
return index
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def delete_selected(obj,list):
|
2001-10-07 03:01:38 +05:30
|
|
|
if len(obj.selection) == 0:
|
2001-08-31 09:10:23 +05:30
|
|
|
return 0
|
2001-10-07 03:01:38 +05:30
|
|
|
del list[obj.selection[0]]
|
2001-08-31 09:10:23 +05:30
|
|
|
return 1
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def add_menuitem(menu,msg,obj,func):
|
|
|
|
item = gtk.GtkMenuItem(msg)
|
2001-09-03 08:48:54 +05:30
|
|
|
item.set_data(OBJECT,obj)
|
2001-08-31 09:10:23 +05:30
|
|
|
item.connect("activate",func)
|
|
|
|
item.show()
|
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def view_photo(photo):
|
2001-10-12 04:26:48 +05:30
|
|
|
type = photo.getMimeType()
|
|
|
|
prog = ""
|
|
|
|
open = ""
|
|
|
|
edit = ""
|
|
|
|
for key in gnome.mime.get_keys(type):
|
|
|
|
if key == 'view':
|
|
|
|
prog = string.split(gnome.mime.get_value(type,key))
|
|
|
|
if key == 'open':
|
|
|
|
open = string.split(gnome.mime.get_value(type,key))
|
|
|
|
if key == 'edit':
|
|
|
|
edit = string.split(gnome.mime.get_value(type,key))
|
|
|
|
if prog == "" and open == "" and edit == "":
|
|
|
|
GnomeWarningDialog("Sorry, I cannot find a viewer for %s type" % type)
|
|
|
|
return
|
|
|
|
|
|
|
|
if prog == "" and open == "":
|
|
|
|
prog = edit
|
|
|
|
else:
|
|
|
|
prog = open
|
|
|
|
|
2001-08-31 09:10:23 +05:30
|
|
|
args = []
|
|
|
|
for val in prog:
|
|
|
|
if val == "%f":
|
|
|
|
args.append(photo.getPath())
|
|
|
|
else:
|
|
|
|
args.append(val)
|
|
|
|
|
|
|
|
if os.fork() == 0:
|
|
|
|
os.execvp(args[0],args)
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def attach_places(values,combo,place):
|
|
|
|
l = gtk.GtkLabel("")
|
|
|
|
l.show()
|
|
|
|
l.set_alignment(0,0.5)
|
|
|
|
c = gtk.GtkListItem()
|
|
|
|
c.add(l)
|
|
|
|
c.set_data(LISTOBJ,None)
|
|
|
|
c.show()
|
|
|
|
sel_child = c
|
|
|
|
list = [c]
|
|
|
|
mymap = {}
|
2001-09-09 04:57:16 +05:30
|
|
|
placenamemap = {}
|
2001-08-31 09:10:23 +05:30
|
|
|
for src in values:
|
2001-09-09 04:57:16 +05:30
|
|
|
placenamemap["%s [%s]" % (src.get_title(),src.getId())] = src
|
|
|
|
placenames = placenamemap.keys()
|
|
|
|
placenames.sort()
|
|
|
|
for key in placenames:
|
|
|
|
src = placenamemap[key]
|
|
|
|
l = gtk.GtkLabel(key)
|
2001-08-31 09:10:23 +05:30
|
|
|
l.show()
|
|
|
|
l.set_alignment(0,0.5)
|
|
|
|
c = gtk.GtkListItem()
|
|
|
|
c.add(l)
|
|
|
|
c.set_data(LISTOBJ,src)
|
|
|
|
c.show()
|
|
|
|
list.append(c)
|
|
|
|
if src == place:
|
|
|
|
sel_child = c
|
|
|
|
mymap[src] = c
|
|
|
|
|
|
|
|
combo.list.append_items(list)
|
|
|
|
combo.list.select_child(sel_child)
|
|
|
|
|
|
|
|
for v in mymap.keys():
|
|
|
|
combo.set_item_string(mymap[v],v.get_title())
|
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def get_place_from_list(obj):
|
|
|
|
select = obj.list.get_selection()
|
|
|
|
if len(select) == 0:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return select[0].get_data(LISTOBJ)
|
2001-10-12 04:26:48 +05:30
|
|
|
|
|
|
|
def find_icon(mtype):
|
|
|
|
icon = None
|
|
|
|
nicon = None
|
|
|
|
for k in gnome.mime.get_keys(mtype):
|
|
|
|
if k == "icon-filename":
|
|
|
|
icon = gnome.mime.get_value(mtype,k)
|
|
|
|
elif k == "icon_filename":
|
|
|
|
nicon = gnome.mime.get_value(mtype,k)
|
|
|
|
if nicon:
|
|
|
|
p = "%s/%s" % (gnome.util.pixmap_file("nautilus"),nicon)
|
|
|
|
if os.path.isfile(p):
|
|
|
|
return p
|
|
|
|
p = "%s.png" % p
|
|
|
|
if os.path.isfile(p):
|
|
|
|
return p
|
|
|
|
if icon:
|
|
|
|
return icon
|
|
|
|
return ""
|
|
|
|
|
|
|
|
def get_mime_type(file):
|
|
|
|
if os.path.isfile(file) or os.path.isdir(file):
|
|
|
|
mtype = gnome.mime.type_of_file(file)
|
|
|
|
if len(string.split(mtype,"/")) != 2:
|
|
|
|
mtype = gnome.mime.type(file)
|
|
|
|
else:
|
|
|
|
mtype = gnome.mime.type(file)
|
|
|
|
return mtype
|
|
|
|
|
|
|
|
def get_mime_description(type):
|
|
|
|
for key in gnome.mime.get_keys(type):
|
|
|
|
if key == "description":
|
|
|
|
return gnome.mime.get_value(type,key)
|
|
|
|
return type
|
2001-10-14 07:55:58 +05:30
|
|
|
|
|
|
|
|
2001-10-16 20:34:25 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Short hand function to return either the person's birthday, or an empty
|
|
|
|
# string if the person is None
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def birthday(person):
|
|
|
|
if person:
|
|
|
|
return person.getBirth().getQuoteDate()
|
|
|
|
else:
|
|
|
|
return ""
|
2001-10-17 05:39:42 +05:30
|
|
|
|
|
|
|
def thumb_path(dir,mobj):
|
|
|
|
type = mobj.getMimeType()
|
|
|
|
if type[0:5] == "image":
|
|
|
|
thumb = "%s/.thumb/%s.jpg" % (dir,mobj.getId())
|
|
|
|
RelImage.check_thumb(mobj.getPath(),thumb,const.thumbScale)
|
|
|
|
return thumb
|
|
|
|
else:
|
|
|
|
return find_icon(type)
|