fix for bug #0002240; Events show up as blank lines when removing unused objects; merged from gramps30
svn: r10829
This commit is contained in:
parent
036e0ec65c
commit
90df86f127
@ -3,6 +3,7 @@
|
|||||||
#
|
#
|
||||||
# Copyright (C) 2000-2007 Donald N. Allingham
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
||||||
# Copyright (C) 2008 Brian G. Matherly
|
# Copyright (C) 2008 Brian G. Matherly
|
||||||
|
# Copyright (C) 2008 Stephane Charette
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -56,6 +57,7 @@ from gen.lib import StyledText
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import Errors
|
import Errors
|
||||||
import ManagedWindow
|
import ManagedWindow
|
||||||
|
from DateHandler import displayer as _dd
|
||||||
from BasicUtils import UpdateCallback
|
from BasicUtils import UpdateCallback
|
||||||
from PluginUtils import Tool, PluginManager
|
from PluginUtils import Tool, PluginManager
|
||||||
|
|
||||||
@ -88,31 +90,37 @@ class RemoveUnused(Tool.Tool,ManagedWindow.ManagedWindow,UpdateCallback):
|
|||||||
self.tables = {
|
self.tables = {
|
||||||
'events' : {'get_func': self.db.get_event_from_handle,
|
'events' : {'get_func': self.db.get_event_from_handle,
|
||||||
'remove' : self.db.remove_event,
|
'remove' : self.db.remove_event,
|
||||||
|
'get_text': self.get_event_text,
|
||||||
'editor' : 'EditEvent',
|
'editor' : 'EditEvent',
|
||||||
'stock' : 'gramps-event',
|
'stock' : 'gramps-event',
|
||||||
'name_ix' : 4},
|
'name_ix' : 4},
|
||||||
'sources' : {'get_func': self.db.get_source_from_handle,
|
'sources' : {'get_func': self.db.get_source_from_handle,
|
||||||
'remove' : self.db.remove_source,
|
'remove' : self.db.remove_source,
|
||||||
|
'get_text': None,
|
||||||
'editor' : 'EditSource',
|
'editor' : 'EditSource',
|
||||||
'stock' : 'gramps-source',
|
'stock' : 'gramps-source',
|
||||||
'name_ix' : 2},
|
'name_ix' : 2},
|
||||||
'places' : {'get_func': self.db.get_place_from_handle,
|
'places' : {'get_func': self.db.get_place_from_handle,
|
||||||
'remove' : self.db.remove_place,
|
'remove' : self.db.remove_place,
|
||||||
|
'get_text': None,
|
||||||
'editor' : 'EditPlace',
|
'editor' : 'EditPlace',
|
||||||
'stock' : 'gramps-place',
|
'stock' : 'gramps-place',
|
||||||
'name_ix' : 2},
|
'name_ix' : 2},
|
||||||
'media' : {'get_func': self.db.get_object_from_handle,
|
'media' : {'get_func': self.db.get_object_from_handle,
|
||||||
'remove' : self.db.remove_object,
|
'remove' : self.db.remove_object,
|
||||||
|
'get_text': None,
|
||||||
'editor' : 'EditMedia',
|
'editor' : 'EditMedia',
|
||||||
'stock' : 'gramps-media',
|
'stock' : 'gramps-media',
|
||||||
'name_ix' : 4},
|
'name_ix' : 4},
|
||||||
'repos' : {'get_func': self.db.get_repository_from_handle,
|
'repos' : {'get_func': self.db.get_repository_from_handle,
|
||||||
'remove' : self.db.remove_repository,
|
'remove' : self.db.remove_repository,
|
||||||
|
'get_text': None,
|
||||||
'editor' : 'EditRepository',
|
'editor' : 'EditRepository',
|
||||||
'stock' : 'gramps-repository',
|
'stock' : 'gramps-repository',
|
||||||
'name_ix' : 3},
|
'name_ix' : 3},
|
||||||
'notes' : {'get_func': self.db.get_note_from_handle,
|
'notes' : {'get_func': self.db.get_note_from_handle,
|
||||||
'remove' : self.db.remove_note,
|
'remove' : self.db.remove_note,
|
||||||
|
'get_text': self.get_note_text,
|
||||||
'editor' : 'EditNote',
|
'editor' : 'EditNote',
|
||||||
'stock' : 'gramps-notes',
|
'stock' : 'gramps-notes',
|
||||||
'name_ix' : 2},
|
'name_ix' : 2},
|
||||||
@ -281,7 +289,7 @@ class RemoveUnused(Tool.Tool,ManagedWindow.ManagedWindow,UpdateCallback):
|
|||||||
|
|
||||||
hlist = [x for x in self.db.find_backlink_handles(handle)]
|
hlist = [x for x in self.db.find_backlink_handles(handle)]
|
||||||
if len(hlist) == 0:
|
if len(hlist) == 0:
|
||||||
self.add_results((the_type, handle,data))
|
self.add_results((the_type, handle, data))
|
||||||
item = cursor.next()
|
item = cursor.next()
|
||||||
self.update()
|
self.update()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
@ -360,24 +368,75 @@ class RemoveUnused(Tool.Tool,ManagedWindow.ManagedWindow,UpdateCallback):
|
|||||||
the_stock = self.tables[the_type]['stock']
|
the_stock = self.tables[the_type]['stock']
|
||||||
cell.set_property('stock-id', the_stock)
|
cell.set_property('stock-id', the_stock)
|
||||||
|
|
||||||
def add_results(self,results):
|
def add_results(self, results):
|
||||||
(the_type, handle,data) = results
|
(the_type, handle, data) = results
|
||||||
|
|
||||||
gramps_id = data[1]
|
gramps_id = data[1]
|
||||||
name_ix = self.tables[the_type]['name_ix']
|
|
||||||
|
|
||||||
if the_type == 'notes':
|
# if we have a function that will return to us some type
|
||||||
note = unicode(data[name_ix][StyledText.POS_TEXT])
|
# of text summary, then we should use it; otherwise we'll
|
||||||
note = " ".join(note.split())
|
# use the generic field index provided in the tables above
|
||||||
if len(note) > 80:
|
if self.tables[the_type]['get_text']:
|
||||||
name = note[:80] + "..."
|
text = self.tables[the_type]['get_text'](the_type, handle, data)
|
||||||
else:
|
|
||||||
name = note
|
|
||||||
else:
|
else:
|
||||||
name = data[name_ix]
|
# grab the text field index we know about, and hope
|
||||||
|
# it represents something useful to the user
|
||||||
self.real_model.append(row=[False,gramps_id, name,the_type, handle])
|
name_ix = self.tables[the_type]['name_ix']
|
||||||
|
text = data[name_ix]
|
||||||
|
|
||||||
|
# insert a new row into the table
|
||||||
|
self.real_model.append(row=[False, gramps_id, text, the_type, handle])
|
||||||
|
|
||||||
|
def get_event_text(self, the_type, handle, data):
|
||||||
|
"""
|
||||||
|
Come up with a short line of text that we can use as
|
||||||
|
a summary to represent this event.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# get the event:
|
||||||
|
event = self.tables[the_type]['get_func'](handle)
|
||||||
|
|
||||||
|
# first check to see if the event has a descriptive name
|
||||||
|
text = event.get_description() # (this is rarely set for events)
|
||||||
|
|
||||||
|
# if we don't have a description...
|
||||||
|
if text == '':
|
||||||
|
# ... then we merge together several fields
|
||||||
|
|
||||||
|
# get the event type (marriage, birth, death, etc.)
|
||||||
|
text = str(event.get_type())
|
||||||
|
|
||||||
|
# see if there is a date
|
||||||
|
date = _dd.display(event.get_date_object())
|
||||||
|
if date != '':
|
||||||
|
text += '; %s' % date
|
||||||
|
|
||||||
|
# see if there is a place
|
||||||
|
place_handle = event.get_place_handle()
|
||||||
|
if place_handle:
|
||||||
|
place = self.db.get_place_from_handle(place_handle)
|
||||||
|
text += '; %s' % place.get_title()
|
||||||
|
|
||||||
|
return text
|
||||||
|
|
||||||
|
def get_note_text(self, the_type, handle, data):
|
||||||
|
"""
|
||||||
|
We need just the first few words of a note as a summary.
|
||||||
|
"""
|
||||||
|
# get the note object
|
||||||
|
note = self.tables[the_type]['get_func'](handle)
|
||||||
|
|
||||||
|
# get the note text; this ignores (discards) formatting
|
||||||
|
text = note.get()
|
||||||
|
|
||||||
|
# convert whitespace to a single space
|
||||||
|
text = " ".join(text.split())
|
||||||
|
|
||||||
|
# if the note is too long, truncate it
|
||||||
|
if len(text) > 80:
|
||||||
|
text = text[:80] + "..."
|
||||||
|
|
||||||
|
return text
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user