* src/GrampsDbBase.py: remove thumbnailing routines, add

id creation. Removes gtk and Utils dependencies, making the
database routines independent of gtk and gnome.
* src/ImgManip.py: add thumbnailing routines.
* various: thumbnailing changes and pychecker fixes


svn: r3888
This commit is contained in:
Don Allingham 2005-01-09 02:18:49 +00:00
parent 65b6bb34af
commit 8ad3ba7456
23 changed files with 86 additions and 149 deletions

View File

@ -1,3 +1,10 @@
2005-01-08 Don Allingham <dallingham@users.sourceforge.net>
* src/GrampsDbBase.py: remove thumbnailing routines, add
id creation. Removes gtk and Utils dependencies, making the
database routines independent of gtk and gnome.
* src/ImgManip.py: add thumbnailing routines.
* various: thumbnailing changes and pychecker fixes
2005-01-08 Alex Roitman <shura@alex.neuro.umn.edu>
* src/Report.py (CommandLineReport.parse_option_str):
Fix PluginMgr lists.

View File

@ -51,7 +51,6 @@ import Date
import RelLib
import Sources
import DateEdit
import NameDisplay
#-------------------------------------------------------------------------
#
@ -83,11 +82,6 @@ class AddressEditor:
self.addr = addr
self.callback = callback
self.child_windows = {}
name = NameDisplay.displayer.display(person)
if name == ", ":
text = _("Address Editor")
else:
text = _("Address Editor for %s") % name
# Get the important widgets from the glade description
self.top = gtk.glade.XML(const.dialogFile, "addr_edit","gramps")

View File

@ -529,7 +529,6 @@ class ArgHandler:
print "Report name not given. Please use name=reportname"
os._exit(1)
found = False
for item in PluginMgr.cl_list:
if name == item[0]:
category = item[1]
@ -541,11 +540,10 @@ class ArgHandler:
else:
Report.cl_report(self.parent.db,name,category,
report_class,options_class,options_str_dict)
found = True
return
print "Unknown report name. Available names are:"
for item in Plugins._cl:
for item in PluginMgr.cl_list:
print " %s" % item[0]
else:
print "Unknown action: %s." % action

View File

@ -76,9 +76,9 @@ def get_date_formats():
except:
return DateDisplay.DateDisplay.formats
def set_format(val):
def set_format(value):
try:
_lang_to_display[_lang].set_format(val)
_lang_to_display[_lang].set_format(value)
except:
pass

View File

@ -183,7 +183,7 @@ class ExistingDbPrompter:
# The above native formats did not work, so we need to
# look up the importer for this format
# and create an empty native database to import data in
for (importData,mime_filter,mime_type,native_format) in Plugin.import_list:
for (importData,mime_filter,mime_type,native_format) in PluginMgr.import_list:
if filetype == mime_type or the_file == mime_type:
QuestionDialog.OkDialog(
_("Opening non-native format"),

View File

@ -49,7 +49,6 @@ from gtk.gdk import ACTION_COPY, BUTTON1_MASK, INTERP_BILINEAR, pixbuf_new_from_
import const
import Utils
import GrampsKeys
import GrampsCfg
import GrampsMime
import ImageSelect
import AutoComp

View File

@ -44,7 +44,6 @@ import gnome
#-------------------------------------------------------------------------
import const
import Utils
import GrampsCfg
import Sources
import ImageSelect
import NameDisplay

View File

@ -35,7 +35,6 @@ import gnome
#-------------------------------------------------------------------------
import const
import Utils
import GrampsCfg
import ImageSelect
import ListModel
import RelLib
@ -183,8 +182,8 @@ class EditSource:
model.remove(node)
def edit_cb(self, cell, path, new_text, data):
iter = self.data_model.get_iter(path)
self.data_model.set_value(iter,data,new_text)
node = self.data_model.get_iter(path)
self.data_model.set_value(node,data,new_text)
def on_delete_event(self,obj,b):
self.close_child_windows()

View File

@ -37,7 +37,6 @@ from gtk.gdk import ACTION_COPY, BUTTON1_MASK
import const
import Utils
import GrampsKeys
import GrampsCfg
import AddSpouse
import SelectChild
import DisplayTrace
@ -842,9 +841,9 @@ class FamilyView:
mother_id = self.family.get_mother_handle()
father_id = self.family.get_father_handle()
for id in [father_id, mother_id]:
if id:
p = self.db.find_person_from_handle(id)
for handle in [father_id, mother_id]:
if handle:
p = self.parent.db.find_person_from_handle(handle)
p.remove_family_handle(self.family.get_handle())
self.parent.db.commit_person(p,trans)
@ -1059,7 +1058,7 @@ class FamilyView:
self.family = self.parent.db.get_family_from_handle(flist[0])
else:
self.family = None
n = NameDisplay.display.displayer(person)
n = NameDisplay.displayer.display(person)
self.parent.db.transaction_commit(trans,_("Remove from family (%s)") % n)
def display_marriage(self,family):

View File

@ -30,19 +30,20 @@ from this class.
# libraries
#
#-------------------------------------------------------------------------
from RelLib import *
import cPickle
import time
import random
import locale
import re
from gettext import gettext as _
import os
import md5
import gtk
#-------------------------------------------------------------------------
#
# GRAMPS libraries
#
#-------------------------------------------------------------------------
from RelLib import *
import GrampsKeys
import Utils
#-------------------------------------------------------------------------
#
@ -116,6 +117,7 @@ class GrampsDbBase:
be created.
"""
self.rand = random.Random(time.time())
self.smap_index = 0
self.emap_index = 0
self.pmap_index = 0
@ -162,6 +164,20 @@ class GrampsDbBase:
self.place2title = {}
self.name_groups = {}
def create_id(self):
s = ""
for val in [ int(time.time()*10000) & 0x7fffffff,
self.rand.randint(0,0x7fffffff),
self.rand.randint(0,0x7fffffff)]:
while val != 0:
rem = val % 36
if rem <= 9:
s += chr(48+rem)
else:
s += chr(rem+55)
val = int(val/36)
return s
def get_person_cursor(self):
assert False, "Needs to be overridden in the derived class"
@ -556,7 +572,7 @@ class GrampsDbBase:
if not person.get_gramps_id():
person.set_gramps_id(self.find_next_person_gramps_id())
if not person.get_handle():
person.set_handle(Utils.create_id())
person.set_handle(self.create_id())
self.commit_person(person,transaction)
self.genderStats.count_person (person, self)
return person.get_handle()
@ -569,7 +585,7 @@ class GrampsDbBase:
if family.get_gramps_id() == None:
family.set_gramps_id(self.find_next_family_gramps_id())
if family.get_handle() == None:
family.set_handle(Utils.create_id())
family.set_handle(self.create_id())
self.commit_family(family,transaction)
return family.get_handle()
@ -579,7 +595,7 @@ class GrampsDbBase:
not already been defined.
"""
if source.get_handle() == None:
source.set_handle(Utils.create_id())
source.set_handle(self.create_id())
if source.get_gramps_id() == None:
source.set_gramps_id(self.find_next_source_gramps_id())
self.commit_source(source,transaction)
@ -591,7 +607,7 @@ class GrampsDbBase:
not already been defined.
"""
if event.get_handle() == None:
event.set_handle(Utils.create_id())
event.set_handle(self.create_id())
if event.get_gramps_id() == None:
event.set_gramps_id(self.find_next_event_gramps_id())
self.commit_event(event,transaction)
@ -603,7 +619,7 @@ class GrampsDbBase:
not already been defined.
"""
if place.get_handle() == None:
index = Utils.create_id()
index = self.create_id()
place.set_handle(index)
if place.get_gramps_id() == None:
place.set_gramps_id(self.find_next_place_gramps_id())
@ -617,7 +633,7 @@ class GrampsDbBase:
"""
index = obj.get_handle()
if index == None:
index = Utils.create_id()
index = self.create_id()
obj.set_handle(index)
if obj.get_gramps_id() == None:
obj.set_gramps_id(self.find_next_object_gramps_id())
@ -1220,36 +1236,6 @@ class GrampsDbBase:
else:
return cols
def _build_thumb_path(self,path):
base = os.path.expanduser('~/.gramps/thumb')
m = md5.md5(path)
return os.path.join(base,m.hexdigest()+'.jpg')
def get_thumbnail_image(self,handle):
data = self.media_map.get(handle)
if data:
filename = self._build_thumb_path(data[2])
if not os.path.isfile(filename):
self.set_thumbnail_image(handle,data[2])
return gtk.gdk.pixbuf_new_from_file(filename)
else:
return None
def set_thumbnail_image(self,handle,path):
try:
pixbuf = gtk.gdk.pixbuf_new_from_file(path)
w = pixbuf.get_width()
h = pixbuf.get_height()
scale = 96.0 / (float(max(w,h)))
pw = int(w*scale)
ph = int(h*scale)
pixbuf = pixbuf.scale_simple(pw,ph,gtk.gdk.INTERP_BILINEAR)
pixbuf.save(self._build_thumb_path(path),"jpeg")
except:
print "Could not create thumbnail for",path
class Transaction:
"""
Defines a group of database commits that define a single logical

View File

@ -60,6 +60,7 @@ import Sources
import DateEdit
import DateHandler
import Date
import ImgManip
from QuestionDialog import ErrorDialog
_IMAGEX = 140
@ -270,7 +271,8 @@ class Gallery(ImageSelect):
def on_drag_begin(self,obj,context):
if const.dnd_images:
handle = self.sel_obj.get_reference_handle()
pix = self.db.get_thumbnail_image(handle)
media_obj = self.db.get_object_from_handle(handle)
pix = self.db.get_thumbnail_image(media_obj.get_path())
context.set_icon_pixbuf(pix,0,0)
def item_event(self, widget, event=None):
@ -356,7 +358,6 @@ class Gallery(ImageSelect):
self.db.add_object(photo,None)
oref = RelLib.MediaRef()
oref.set_reference_handle(photo.get_handle())
self.db.set_thumbnail_image(photo.get_handle(),photo.get_path())
self.dataobj.add_media_reference(oref)
def add_thumbnail(self, photo):
@ -375,9 +376,8 @@ class Gallery(ImageSelect):
description = "%s..." % description[0:20]
try:
image = self.db.get_thumbnail_image(oid)
if not image:
image = gtk.gdk.pixbuf_new_from_file(const.icon)
media_obj = self.db.get_object_from_handle(oid)
image = ImgManip.get_thumbnail_image(media_obj.get_path())
except gobject.GError,msg:
ErrorDialog(str(msg))
image = gtk.gdk.pixbuf_new_from_file(const.icon)
@ -471,8 +471,6 @@ class Gallery(ImageSelect):
photo.set_description(root)
self.savephoto(photo)
if GrampsKeys.get_media_reference() == 0:
self.db.set_thumbnail_image(photo.get_handle(),
self.path)
photo.set_path(name)
self.parent.lists_changed = 1
if GrampsKeys.get_media_global():
@ -497,8 +495,6 @@ class Gallery(ImageSelect):
oref.set_reference_handle(photo.get_handle())
self.dataobj.add_media_reference(oref)
try:
handle = photo.get_handle()
self.db.set_thumbnail_image(handle,self.path)
photo.set_path(name)
except:
photo.set_path(tfile)
@ -623,13 +619,6 @@ class Gallery(ImageSelect):
obj = self.db.get_object_from_handle(photo.get_reference_handle())
os.execvp(const.editor,[const.editor, obj.get_path()])
def popup_convert_to_private(self, obj):
"""Copy this picture into gramps private database instead of
leaving it as an external data object."""
photo = obj.get_data('o')
obj = self.db.get_object_from_handle(photo.get_reference_handle())
self.db.set_thumbnail_image(obj.get_handle(),obj.get_path())
def popup_change_description(self, obj):
"""Bring up a window allowing the user to edit the description
of a picture."""
@ -703,7 +692,7 @@ class LocalMediaProperties:
descr_window.set_text(self.obj.get_description())
mtype = self.obj.get_mime_type()
self.pix = self.db.get_thumbnail_image(self.obj.get_handle())
self.pix = ImgManip.get_thumbnail_image(self.obj.get_path())
self.pixmap.set_from_pixbuf(self.pix)
self.change_dialog.get_widget("private").set_active(photo.get_privacy())
@ -970,7 +959,7 @@ class GlobalMediaProperties:
self.descr_window.set_text(self.obj.get_description())
mtype = self.obj.get_mime_type()
pb = self.db.get_thumbnail_image(self.obj.get_handle())
pb = ImgManip.get_thumbnail_image(self.obj.get_path())
self.pixmap.set_from_pixbuf(pb)
self.change_dialog.get_widget("gid").set_text(self.obj.get_gramps_id())

View File

@ -46,6 +46,7 @@ import Utils
import GrampsKeys
import const
import ImageSelect
import ImgManip
import RelImage
import DisplayModels
import GrampsMime
@ -178,7 +179,7 @@ class MediaView:
mtype = mobj.get_mime_type()
path = mobj.get_path()
type_name = Utils.get_mime_description(mtype)
image = self.db.get_thumbnail_image(mobj.get_handle())
image = ImgManip.get_thumbnail_image(path)
if image != None:
self.preview.set_from_pixbuf(image)
else:
@ -258,13 +259,6 @@ class MediaView:
if os.fork() == 0:
os.execvp(const.editor,[const.editor, self.obj.get_path()])
def popup_convert_to_private(self, obj):
path = self.db.get_save_path()
handle = self.obj.get_handle()
self.db.set_thumbnail_image(handle,path)
if name:
self.obj.set_path(name)
def popup_change_description(self, obj):
ImageSelect.GlobalMediaProperties(self.db,self.obj,
self.update_display,
@ -360,7 +354,7 @@ class MediaView:
if (const.dnd_images):
handle = store.get_value(node,5)
obj = self.db.get_object_from_handle(handle)
image = self.db.get_thumbnail_image(obj.get_handle())
image = ImgManip.get_thumbnail_image(obj.get_path())
context.set_icon_pixbuf(image,0,0)
def on_drag_data_get(self, w, context, selection_data, info, time):
@ -389,8 +383,6 @@ class MediaView:
photo.set_description(description)
trans = self.db.transaction_begin()
self.db.add_object(photo,trans)
if GrampsKeys.get_media_reference() == 0:
self.db.set_thumbnail_image(photo.get_handle(),name)
self.db.commit_media_object(photo,trans)
self.db.transaction_commit(trans,_("Add Media Object"))
@ -416,13 +408,6 @@ class MediaView:
self.db.add_object(photo,trans)
oref = RelLib.MediaRef()
oref.set_reference_handle(photo.get_handle())
try:
handle = photo.get_handle()
path = self.db.get_save_path()
self.db.set_thumbnail_image(handle,path)
except:
photo.set_path(tfile)
return
self.db.commit_media_object(photo,trans)
self.db.transaction_commit(trans,_("Add Media Object"))

View File

@ -46,7 +46,7 @@ class NameDisplay:
displayed in upper case.
@type use_upper: bool
"""
self.use_upper = use_upper
self.force_upper = use_upper
def use_upper(self,upper):
"""
@ -57,7 +57,7 @@ class NameDisplay:
displayed in upper case.
@type upper: bool
"""
self.use_upper = upper
self.force_upper = upper
def sorted(self,person):
"""
@ -139,7 +139,7 @@ class NameDisplay:
else:
first = name.first_name
if self.use_upper:
if self.force_upper:
last = name.surname.upper()
else:
last = name.surname
@ -167,7 +167,7 @@ class NameDisplay:
else:
first = name.first_name
if self.use_upper:
if self.force_upper:
last = name.surname.upper()
else:
last = name.surname

View File

@ -163,7 +163,7 @@ class PeopleView:
hc = self.parent.history.count(del_id)
for c in range(hc):
self.parent.history.remove(del_id)
self.parent.hindex = self.parent.hindex - 1
self.parent.hindex -= 1
mhc = self.parent.mhistory.count(del_id)
for c in range(mhc):

View File

@ -184,8 +184,6 @@ class PlaceView:
mlist = []
self.selection.selected_foreach(self.blist,mlist)
trans = self.parent.db.transaction_begin()
for place_handle in mlist:
used = 0
for key in self.parent.db.get_person_handles(sort_handles=False):

View File

@ -36,7 +36,7 @@ importers, exporters, and document generators.
import os
import sys
import string
from re import compile
import re
from gettext import gettext as _
#-------------------------------------------------------------------------
@ -45,7 +45,6 @@ from gettext import gettext as _
#
#-------------------------------------------------------------------------
import const
import GrampsKeys
import Errors
#-------------------------------------------------------------------------
@ -111,7 +110,7 @@ def load_plugins(direct):
# add the directory to the python search path
sys.path.append(direct)
pymod = compile(r"^(.*)\.py$")
pymod = re.compile(r"^(.*)\.py$")
# loop through each file in the directory, looking for files that
# have a .py extention, and attempt to load the file. If it succeeds,
@ -133,8 +132,10 @@ def load_plugins(direct):
except:
failmsg_list.append((filename,sys.exc_info()))
if GrampsKeys.get_pop_plugin_status() and len(expect_list)+len(failmsg_list):
PluginStatus()
if len(expect_list)+len(failmsg_list):
return False
else:
return True
#-------------------------------------------------------------------------
#
@ -199,13 +200,10 @@ def reload_plugins(obj=None,junk1=None,junk2=None,junk3=None):
except:
failmsg_list.append((filename,sys.exc_info()))
if GrampsKeys.get_pop_plugin_status():
global status_up
if len(failmsg_list):
PluginStatus()
elif status_up:
status_up.close(None)
status_up = None
global status_up
if not len(failmsg_list):
status_up.close(None)
status_up = None
#-------------------------------------------------------------------------
#

View File

@ -50,6 +50,7 @@ import Errors
import RelLib
import Date
import DateParser
import DisplayTrace
from ansel_utf8 import ansel_to_utf8
import latin_utf8
import Utils
@ -1935,14 +1936,6 @@ class GedcomParser:
def invert_year(self,subdate):
return (subdate[0],subdate[1],-subdate[2],subdate[3])
def parse(self,text):
"""
Parses the text, returning a Date object.
"""
new_date = Date.Date()
self.set_date(new_date,text)
return new_date
def extract_temple(matches):
try:
if const.lds_temple_to_abrev.has_key(matches[2]):

View File

@ -265,12 +265,7 @@ class SelectChild:
ddate = ""
rdata = [name,person.get_gramps_id(),gender,bdate,ddate]
new_node = self.refmodel.add(rdata)
names = dinfo[0].split(',')
if len(names):
ln = names[0].upper()
if self.default_name and ln == self.default_name and not node:
node = new_node
node = self.refmodel.add(rdata)
self.refmodel.connect_model()

View File

@ -57,6 +57,7 @@ import gtk.gdk
import const
import Utils
import ListModel
import ImgManip
#-------------------------------------------------------------------------
#
@ -106,8 +107,6 @@ class SelectObject:
self.object_model.connect_model()
def on_select_row(self,obj):
fexists = 1
store,node = self.object_model.get_selected()
if not node:
return
@ -117,19 +116,17 @@ class SelectObject:
the_type = Utils.get_mime_description(obj.get_mime_type())
path = obj.get_path()
image = self.db.get_thumbnail_image(obj.get_handle())
image = ImgManip.get_thumbnail_image(obj.get_path())
if image:
self.preview.set_from_pixbuf(image)
else:
icon_image = gtk.gdk.pixbuf_new_from_file(Utils.find_icon(the_type))
self.preview.set_from_pixbuf(icon_image)
if not pexists:
fexists = 0
self.object_handle.set_text(obj.get_gramps_id())
self.object_type.set_text(the_type)
self.object_desc.set_text(obj.get_description())
if len(path) == 0 or fexists == 0:
if len(path) == 0:
self.object_path.set_text(_("The file no longer exists"))
elif path[0] == "/":
self.object_path.set_text(path)

View File

@ -88,7 +88,7 @@ class StyleListDisplay:
self.redraw()
if parent_window:
self.window.set_transient_for(parent_window)
response = self.window.run()
self.window.run()
self.window.destroy()
def redraw(self):

View File

@ -69,10 +69,9 @@ def history_broken():
# force_unicode
#
#-------------------------------------------------------------------------
_t = type(u'')
def force_unicode(n):
if type(n) != _t:
if type(n) != unicode:
return (unicode(n).lower(),unicode(n))
else:
return (n.lower(),n)

View File

@ -832,12 +832,14 @@ class Gramps:
self.report_menu.set_sensitive(0)
self.tools_menu.set_sensitive(0)
PluginMgr.load_plugins(const.docgenDir)
PluginMgr.load_plugins(os.path.expanduser("~/.gramps/docgen"))
PluginMgr.load_plugins(const.pluginsDir)
PluginMgr.load_plugins(os.path.expanduser("~/.gramps/plugins"))
error = PluginMgr.load_plugins(const.docgenDir)
error |= PluginMgr.load_plugins(os.path.expanduser("~/.gramps/docgen"))
error |= PluginMgr.load_plugins(const.pluginsDir)
error |= PluginMgr.load_plugins(os.path.expanduser("~/.gramps/plugins"))
if GrampsKeys.get_pop_plugin_status() and error:
Plugins.PluginStatus()
Plugins.build_report_menu(self.report_menu,self.menu_report)
Plugins.build_tools_menu(self.tools_menu,self.menu_tools)
@ -1191,7 +1193,6 @@ class Gramps:
if os.path.isfile(name):
obj = self.db.get_object_from_handle(ObjectId)
obj.set_path(name)
self.db.set_thumbnail_image(ObjectId,name)
choose.destroy()
#-------------------------------------------------------------------------

View File

@ -47,6 +47,7 @@ import Utils
import AddMedia
import const
import ReportOptions
import ImgManip
#------------------------------------------------------------------------
#
@ -248,7 +249,7 @@ class SimpleBookTitleOptions(ReportOptions.ReportOptions):
return
self.options_dict['imgid'] = the_object.get_gramps_id()
self.obj_title.set_text(the_object.get_description())
icon_image = database.get_thumbnail_image(the_object.get_handle())
icon_image = ImgManip.get_thumbnail_image(the_object.get_path())
self.preview.set_from_pixbuf(icon_image)
self.remove_obj_button.set_sensitive(gtk.TRUE)
self.size.set_sensitive(gtk.TRUE)