* src/DisplayModels.py: use a dictionary to handle reverse

indices instead of list.index function. Drastically reduces
time are larger lists.
* src/GrampsDbBase.py: use cursors to build sorted key lists
* src/PeopleModel.py: fetch sort names out of database first
instead of continuously fetching from database during sort
* src/PeopleView.py: remove unnecessary apply_filter
* src/PlaceView.py: remove commented-out code
* src/ReadXML.py: add gtk event handling to allow screen to
update
* src/gramps.glade: use gramps.png for loading message window
* src/gramps_main.py: remove delete_abandoned_photos calls

* src/PeopleModel.py: Fixed rebuild_display
* src/ReadXML.py: Fixed calendar handling


svn: r3819
This commit is contained in:
Don Allingham 2004-12-19 22:55:41 +00:00
parent 6dea6f401e
commit 295e9a530f
11 changed files with 168 additions and 120 deletions

View File

@ -1,3 +1,21 @@
2004-12-19 Don Allingham <dallingham@users.sourceforge.net>
* src/DisplayModels.py: use a dictionary to handle reverse
indices instead of list.index function. Drastically reduces
time are larger lists.
* src/GrampsDbBase.py: use cursors to build sorted key lists
* src/PeopleModel.py: fetch sort names out of database first
instead of continuously fetching from database during sort
* src/PeopleView.py: remove unnecessary apply_filter
* src/PlaceView.py: remove commented-out code
* src/ReadXML.py: add gtk event handling to allow screen to
update
* src/gramps.glade: use gramps.png for loading message window
* src/gramps_main.py: remove delete_abandoned_photos calls
2004-12-16 Don Allingham <dallingham@users.sourceforge.net>
* src/PeopleModel.py: Fixed rebuild_display
* src/ReadXML.py: Fixed calendar handling
2004-12-16 Julio Sanchez <julio.sanchez@gmail.com>
* src/po/es.po: forward port of the Spanish translations in STABLE,
plus many new translations

5
TODO
View File

@ -10,10 +10,6 @@
see http://sourceforge.net/mailarchive/forum.php?thread_id=3066997&forum_id=1993
and http://sourceforge.net/mailarchive/forum.php?thread_id=3134931&forum_id=1993
for the details.
* Make Date parsing locale dependent, like relationship calculator
* Add Confession as a standard event
* Now that the completeness flag exists, create filters that are using it
(both individual and family).
* Add autofill feature for City, Church parish, County, State and Country?
* Move LDS temple info out of const.py and into an XML file
* Enhanced web page generator
@ -23,5 +19,4 @@
3 entries per page.
* Add slideshow generation ability to web page generator
* Enhance privacy handling
* Better name handling, especially of non-European style names
* And a whole lot more....

View File

@ -51,25 +51,37 @@ class BaseModel(gtk.GenericTreeModel):
def rebuild_data(self):
if self.db.is_open():
self.datalist = self.sort_keys()
i = 0
self.indexlist = {}
for key in self.datalist:
self.indexlist[key] = i
i += 1
else:
self.datalist = []
self.indexlist = []
def on_row_inserted(self,obj,path,node):
self.rebuild_data()
def add_row_by_handle(self,handle):
self.datalist = self.sort_keys()
index = self.datalist.index(handle)
i = 0
self.indexlist = {}
for key in self.datalist:
self.indexlist[key] = i
i += 1
index = self.indexlist[handle]
node = self.get_iter(index)
self.row_inserted(index,node)
def delete_row_by_handle(self,handle):
index = self.datalist.index(handle)
index = self.indexlist[handle]
del self.datalist[index]
del self.indexlist[handle]
self.row_deleted(index)
def update_row_by_handle(self,handle):
index = self.datalist.index(handle)
index = self.indexlist[handle]
node = self.get_iter(index)
self.row_changed(index,node)
@ -83,7 +95,7 @@ class BaseModel(gtk.GenericTreeModel):
def on_get_path(self, node):
'''returns the tree path (a tuple of indices at the various
levels) for a particular node.'''
return self.datalist.index(node[0])
return self.indexlist[node[0]]
def on_get_column_type(self,index):
return gobject.TYPE_STRING
@ -103,7 +115,7 @@ class BaseModel(gtk.GenericTreeModel):
def on_iter_next(self, node):
'''returns the next node at this level of the tree'''
try:
return self.datalist[self.datalist.index(node)+1]
return self.datalist[self.indexlist[node]+1]
except IndexError:
return None

View File

@ -676,10 +676,18 @@ class GrampsDbBase:
the database. If sort_handles is True, the list is sorted by surnames
"""
if self.person_map:
handle_list = self.person_map.keys()
if sort_handles:
handle_list.sort(self._sortbyname)
return handle_list
slist = []
cursor = self.get_person_cursor()
data = cursor.first()
while data:
slist.append((data[1][3].sname,data[0]))
data = cursor.next()
cursor.close()
slist.sort()
return map(lambda x: x[1], slist)
else:
return self.person_map.keys()
return []
def get_place_handles(self,sort_handles=True):
@ -689,10 +697,19 @@ class GrampsDbBase:
Place title.
"""
if self.place_map:
handle_list = self.place_map.keys()
if sort_handles:
handle_list.sort(self._sortbyplace)
return handle_list
slist = []
cursor = self.get_place_cursor()
data = cursor.first()
while data:
slist.append((data[1][2],data[0]))
data = cursor.next()
cursor.close()
slist.sort()
val = map(lambda x: x[1], slist)
return val
else:
return self.place_map.keys()
return []
def get_source_handles(self,sort_handles=True):

View File

@ -86,7 +86,9 @@ class PeopleModel(gtk.GenericTreeModel):
return
if data_filter:
keys = self.data_filter.apply(self.db,self.db.get_person_handles(sort_handles=False))
handle_list = self.db.get_person_handles(sort_handles=False)
keys = data_filter.apply(self.db,handle_list)
del handle_list
else:
keys = self.db.get_person_handles(sort_handles=False)
@ -107,9 +109,14 @@ class PeopleModel(gtk.GenericTreeModel):
temp_top_path2iter = self.sname_sub.keys()
temp_top_path2iter.sort(locale.strcoll)
for name in temp_top_path2iter:
slist = []
for handle in self.sname_sub[name]:
n = self.db.person_map.get(handle)[_NAME_COL].get_sort_name()
slist.append((n,handle))
slist.sort(self.byname)
entries = map(lambda x: x[1], slist)
val = 0
entries = self.sname_sub[name]
entries.sort(self.byname)
for person_handle in entries:
tpl = (name,val)
temp_iter2path[person_handle] = tpl
@ -120,18 +127,8 @@ class PeopleModel(gtk.GenericTreeModel):
self.iter2path = temp_iter2path
self.path2iter = temp_path2iter
self.db.set_people_view_maps(self.get_maps())
def get_maps(self):
return (self.top_path2iter,
self.iter2path,
self.path2iter,
self.sname_sub)
def byname(self,f,s):
n1 = self.db.person_map.get(str(f))[_NAME_COL].get_sort_name()
n2 = self.db.person_map.get(str(s))[_NAME_COL].get_sort_name()
return locale.strcoll(n1,n2)
return locale.strcoll(f[0],s[0])
def on_get_flags(self):
'''returns the GtkTreeModelFlags for this particular type of model'''

View File

@ -72,7 +72,7 @@ class PeopleView:
all.set_name(_("Entire Database"))
all.add_rule(GenericFilter.Everyone([]))
self.DataFilter = all
self.DataFilter = None
self.pscroll = self.parent.gtop.get_widget("pscroll")
self.person_tree = self.parent.gtop.get_widget("person_tree")
self.person_tree.set_rules_hint(gtk.TRUE)
@ -87,9 +87,6 @@ class PeopleView:
self.person_tree.connect('button-press-event',
self.on_plist_button_press)
def get_maps(self):
return self.person_model.get_maps()
def build_columns(self):
for column in self.columns:
self.person_tree.remove_column(column)
@ -147,9 +144,6 @@ class PeopleView:
self.build_columns()
self.person_model = PeopleModel.PeopleModel(db,self.DataFilter)
self.sort_model = self.person_model
#self.sort_model = self.person_model.filter_new()
#self.sort_model.set_visible_column(PeopleModel.COLUMN_VIEW)
self.apply_filter()
self.person_tree.set_model(self.sort_model)
def remove_from_person_list(self,person):

View File

@ -70,7 +70,6 @@ class PlaceView:
self.parent = parent
self.glade = glade
self.list = glade.get_widget("place_list")
#self.list.set_property('fixed-height-mode',True)
self.list.connect('button-press-event',self.button_press)
self.list.connect('key-press-event',self.key_press)
self.selection = self.list.get_selection()

View File

@ -1142,6 +1142,8 @@ class GrampsParser:
def stop_family(self,*tag):
self.db.commit_family(self.family,self.trans,self.change)
self.family = None
while gtk.events_pending():
gtk.main_iteration()
def stop_event(self,*tag):
self.event.name = self.event_type
@ -1186,6 +1188,8 @@ class GrampsParser:
self.event.set_place_handle(self.placeobj.get_handle())
self.db.commit_place(self.placeobj,self.trans,self.change)
self.placeobj = None
while gtk.events_pending():
gtk.main_iteration()
def stop_date(self,tag):
if tag:
@ -1203,6 +1207,8 @@ class GrampsParser:
def stop_person(self,*tag):
self.db.commit_person(self.person,self.trans,self.change)
self.person = None
while gtk.events_pending():
gtk.main_iteration()
def stop_description(self,tag):
self.event.set_description(tag)

View File

@ -31735,36 +31735,16 @@ Family name Given name
<widget class="GtkTable" id="table47">
<property name="border_width">12</property>
<property name="visible">True</property>
<property name="n_rows">2</property>
<property name="n_rows">3</property>
<property name="n_columns">2</property>
<property name="homogeneous">False</property>
<property name="row_spacing">0</property>
<property name="column_spacing">0</property>
<child>
<widget class="GtkImage" id="image2223">
<property name="visible">True</property>
<property name="stock">gtk-dialog-info</property>
<property name="icon_size">6</property>
<property name="xalign">0.5</property>
<property name="yalign">0</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">0</property>
<property name="bottom_attach">2</property>
<property name="x_options">fill</property>
<property name="y_options">fill</property>
</packing>
</child>
<property name="row_spacing">6</property>
<property name="column_spacing">6</property>
<child>
<widget class="GtkLabel" id="label401">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;span size=&quot;larger&quot; weight=&quot;bold&quot;&gt;Loading Database&lt;/span&gt;</property>
<property name="label" translatable="yes">&lt;span size=&quot;larger&quot; weight=&quot;bold&quot;&gt;Loading database&lt;/span&gt;</property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
@ -31808,6 +31788,49 @@ Family name Given name
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="message">
<property name="visible">True</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_CENTER</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkImage" id="image2223">
<property name="visible">True</property>
<property name="pixbuf">gramps.png</property>
<property name="xalign">0.5</property>
<property name="yalign">0</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">0</property>
<property name="bottom_attach">3</property>
<property name="x_options">fill</property>
<property name="y_options">fill</property>
</packing>
</child>
</widget>
</child>
</widget>

View File

@ -77,10 +77,7 @@ import RecentFiles
from QuestionDialog import *
try: # First try python2.3 and later: this is the future
from bsddb import db
except ImportError: # try python2.2
from bsddb3 import db
#-------------------------------------------------------------------------
#
@ -598,7 +595,8 @@ class Gramps:
item = gtk.MenuItem("_%d. %s [%s]" %
(num,person.get_primary_name().get_name(),
person.get_gramps_id()))
item.connect("activate",self.bookmark_callback,person.get_handle())
item.connect("activate",self.bookmark_callback,
person.get_handle())
item.show()
gomenu.append(item)
num = num + 1
@ -629,7 +627,9 @@ class Gramps:
break
person = self.db.get_person_from_handle(pid)
item = gtk.MenuItem("%s. %s [%s]" %
(hotkey,person.get_primary_name().get_name(),person.get_gramps_id()))
(hotkey,
person.get_primary_name().get_name(),
person.get_gramps_id()))
item.connect("activate",self.back_clicked,num)
item.show()
backhistmenu.append(item)
@ -657,7 +657,9 @@ class Gramps:
break
person = self.db.get_person_from_handle(pid)
item = gtk.MenuItem("%s. %s [%s]" %
(hotkey,person.get_primary_name().get_name(),person.get_gramps_id()))
(hotkey,
person.get_primary_name().get_name(),
person.get_gramps_id()))
item.connect("activate",self.fwd_clicked,num)
item.show()
fwdhistmenu.append(item)
@ -901,29 +903,18 @@ class Gramps:
def on_exit_activate(self,obj):
"""Prompt to save on exit if needed"""
self.delete_abandoned_photos()
self.db.close()
gtk.main_quit()
def quit(self):
"""Catch the reponse to the save on exit question"""
self.delete_abandoned_photos()
self.db.close()
gtk.main_quit()
def close_noquit(self):
"""Close database and delete abandoned photos, no quit"""
self.delete_abandoned_photos()
self.db.close()
def delete_abandoned_photos(self):
"""
We only want to delete local objects, not external objects, however, we
can delete any thumbnail images. The thumbnails may or may not exist, depending
on if the image was previewed.
"""
self.db.set_people_view_maps(self.people_view.get_maps())
def on_about_activate(self,obj):
"""Displays the about box. Called from Help menu"""
pixbuf = gtk.gdk.pixbuf_new_from_file(const.logo)
@ -1026,7 +1017,8 @@ class Gramps:
def read_xml(self,filename):
import ReadXML
filename = os.path.normpath(os.path.abspath(os.path.join(filename,const.xmlFile)))
filename = os.path.normpath(
os.path.abspath(os.path.join(filename,const.xmlFile)))
try:
ReadXML.importData(self.db,filename,None)
@ -1602,9 +1594,10 @@ class Gramps:
if self.db.load(filename,self.load_progress) == 0:
self.status_text('')
return 0
self.status_text('')
return self.post_load(name)
val = self.post_load(name)
return val
def setup_bookmarks(self):
self.bookmarks = Bookmarks.Bookmarks(self.db,self.db.get_bookmarks(),

View File

@ -33,13 +33,6 @@ _findint = re.compile('^[^\d]*(\d+)[^\d]*')
def runTool(db,active_person,callback,parent):
"""Changed person, family, object, source, and place ids"""
# FIXME: Remove when plugin is properly implemented
from QuestionDialog import OkDialog
OkDialog(_("Plugin unavailable"),
_("This plugin is not implemented yet. Please check the next version."),
parent.topWindow)
return
try:
ReorderIds(db,callback)
except:
@ -52,33 +45,31 @@ class ReorderIds:
self.db = db
self.reorder(db.get_person_handle_map(),db.iprefix,db.build_person_display)
self.reorder_person()
self.reorder(db.get_family_handle_map(),db.fprefix,None)
self.reorder(db.get_object_map(),db.oprefix,None)
self.reorder(db.get_source_map(),db.sprefix,db.build_source_display)
self.reorder(db.get_place_handle_map(),db.pprefix,db.build_place_display)
Utils.history_broken()
callback(1)
def reorder(self,data_map,prefix,update):
"""Try to extract the old integer out of the id, and reuse it
if possible. Otherwise, blindly renumber those that can't."""
def reorder_person():
dups = []
newids = {}
key_list = []
# search all ids in the map
for x in data_map.keys():
key_list.append(x)
cursor = self.db.get_person_cursor()
data = cursor.first()
while data:
(handle,sdata) = data
for handle in key_list:
gramps_id = sdata[1]
# attempt to extract integer, if we can't, treat it as a
# duplicate
match = _findint.match(handle)
match = _findint.match(gramps_id)
if match:
# get the integer, build the new handle. Make sure it
# hasn't already been chosen. If it has, put this
@ -86,42 +77,45 @@ class ReorderIds:
try:
index = match.groups()[0]
newhandle = prefix % int(index)
if newhandle == handle:
newids[newhandle] = handle
newgramps_id = prefix % int(index)
if newgramps_id == gramps_id:
newids[newgramps_id] = gramps_id
continue
elif data_map.has_key(newhandle):
elif data_map.has_key(newgramps_id):
dups.append(handle)
else:
data = data_map[handle]
data_map[newhandle] = data
newids[newhandle] = handle
data.set_handle(newhandle)
del data_map[handle]
data = data_map[gramps_id]
data_map[newgramps_id] = data
newids[newgramps_id] = gramps_id
data.set_gramps_id(newgramps_id)
del data_map[gramps_id]
if update:
update(newhandle,handle)
update(newgramps_id,gramps_id)
except:
dups.append(handle)
else:
dups.append(handle)
data = cursor.next()
# go through the duplicates, looking for the first availble
# handle that matches the new scheme.
index = 0
for handle in dups:
for gramps_id in dups:
while 1:
newhandle = prefix % index
if not newids.has_key(newhandle):
newgramps_id = prefix % index
if not newids.has_key(newgramps_id):
break
index = index + 1
newids[newhandle] = newhandle
data = data_map[handle]
data.set_handle(newhandle)
data_map[newhandle] = data
newids[newgramps_id] = newgramps_id
data = data_map[gramps_id]
data.set_gramps_id(newgramps_id)
data_map[newgramps_id] = data
if update:
update(newhandle,handle)
del data_map[handle]
update(newgramps_id,gramps_id)
del data_map[gramps_id]
#-------------------------------------------------------------------------
#