Fixed EventCmp handling of files, sort on place fields

svn: r527
This commit is contained in:
Don Allingham 2001-10-30 20:37:56 +00:00
parent 1737362432
commit 1d1879b6cd
5 changed files with 544 additions and 53 deletions

1
NEWS
View File

@ -40,6 +40,7 @@ Version 0.6.0pre
a dotted line). a dotted line).
* Reordering GRAMPS' ids attempts to preserve the integer originally * Reordering GRAMPS' ids attempts to preserve the integer originally
assigned to the object. assigned to the object.
* The person view can be sorted by GRAMPS id.
Version 0.5.1 Version 0.5.1
* Bug fixes * Bug fixes

View File

@ -909,16 +909,73 @@
</widget> </widget>
<widget> <widget>
<class>GtkLabel</class> <class>GtkHBox</class>
<child_name>CList:title</child_name> <child_name>CList:title</child_name>
<name>glabel5</name> <name>hbox38</name>
<label>ID</label> <homogeneous>True</homogeneous>
<justify>GTK_JUSTIFY_CENTER</justify> <spacing>0</spacing>
<wrap>False</wrap>
<xalign>0.5</xalign> <widget>
<yalign>0.5</yalign> <class>GtkHBox</class>
<xpad>0</xpad> <child_name>CList:title</child_name>
<ypad>0</ypad> <name>hbox39</name>
<homogeneous>True</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
<widget>
<class>GtkHBox</class>
<name>hbox40</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label275</name>
<label>ID</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkArrow</class>
<name>idSort</name>
<width>10</width>
<height>10</height>
<visible>False</visible>
<arrow_type>GTK_ARROW_DOWN</arrow_type>
<shadow_type>GTK_SHADOW_OUT</shadow_type>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>5</padding>
<expand>False</expand>
<fill>True</fill>
</child>
</widget>
</widget>
</widget>
</widget> </widget>
<widget> <widget>
@ -2406,17 +2463,363 @@
<handler>on_place_list_button_press_event</handler> <handler>on_place_list_button_press_event</handler>
<last_modification_time>Fri, 17 Aug 2001 23:00:19 GMT</last_modification_time> <last_modification_time>Fri, 17 Aug 2001 23:00:19 GMT</last_modification_time>
</signal> </signal>
<columns>6</columns> <signal>
<column_widths>236,47,102,88,77,80</column_widths> <name>click_column</name>
<handler>on_place_list_click_column</handler>
<last_modification_time>Tue, 30 Oct 2001 18:18:53 GMT</last_modification_time>
</signal>
<columns>12</columns>
<column_widths>222,47,102,88,77,80,5,5,5,5,5,5</column_widths>
<selection_mode>GTK_SELECTION_EXTENDED</selection_mode> <selection_mode>GTK_SELECTION_EXTENDED</selection_mode>
<show_titles>True</show_titles> <show_titles>True</show_titles>
<shadow_type>GTK_SHADOW_IN</shadow_type> <shadow_type>GTK_SHADOW_IN</shadow_type>
<widget>
<class>GtkHBox</class>
<child_name>CList:title</child_name>
<name>hbox41</name>
<homogeneous>True</homogeneous>
<spacing>0</spacing>
<widget>
<class>GtkHBox</class>
<name>hbox42</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>place_title</name>
<label>Place Name</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkArrow</class>
<name>place_arrow</name>
<width>10</width>
<height>10</height>
<arrow_type>GTK_ARROW_DOWN</arrow_type>
<shadow_type>GTK_SHADOW_OUT</shadow_type>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>5</padding>
<expand>False</expand>
<fill>True</fill>
</child>
</widget>
</widget>
</widget>
<widget>
<class>GtkHBox</class>
<child_name>CList:title</child_name>
<name>hbox43</name>
<homogeneous>True</homogeneous>
<spacing>0</spacing>
<widget>
<class>GtkHBox</class>
<name>hbox44</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label283</name>
<label>ID</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkArrow</class>
<name>place_id_arrow</name>
<width>10</width>
<height>10</height>
<visible>False</visible>
<arrow_type>GTK_ARROW_DOWN</arrow_type>
<shadow_type>GTK_SHADOW_OUT</shadow_type>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>5</padding>
<expand>False</expand>
<fill>True</fill>
</child>
</widget>
</widget>
</widget>
<widget>
<class>GtkHBox</class>
<child_name>CList:title</child_name>
<name>hbox45</name>
<homogeneous>True</homogeneous>
<spacing>0</spacing>
<widget>
<class>GtkHBox</class>
<name>hbox46</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label284</name>
<label>City</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkArrow</class>
<name>city_arrow</name>
<width>10</width>
<height>10</height>
<visible>False</visible>
<arrow_type>GTK_ARROW_DOWN</arrow_type>
<shadow_type>GTK_SHADOW_OUT</shadow_type>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>5</padding>
<expand>False</expand>
<fill>True</fill>
</child>
</widget>
</widget>
</widget>
<widget>
<class>GtkHBox</class>
<child_name>CList:title</child_name>
<name>hbox47</name>
<homogeneous>True</homogeneous>
<spacing>0</spacing>
<widget>
<class>GtkHBox</class>
<name>hbox48</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label285</name>
<label>County</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkArrow</class>
<name>county_arrow</name>
<width>10</width>
<height>10</height>
<visible>False</visible>
<arrow_type>GTK_ARROW_DOWN</arrow_type>
<shadow_type>GTK_SHADOW_OUT</shadow_type>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>5</padding>
<expand>False</expand>
<fill>True</fill>
</child>
</widget>
</widget>
</widget>
<widget>
<class>GtkHBox</class>
<child_name>CList:title</child_name>
<name>hbox49</name>
<homogeneous>True</homogeneous>
<spacing>0</spacing>
<widget>
<class>GtkHBox</class>
<name>hbox50</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label286</name>
<label>State</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkArrow</class>
<name>state_arrow</name>
<width>10</width>
<height>10</height>
<visible>False</visible>
<arrow_type>GTK_ARROW_DOWN</arrow_type>
<shadow_type>GTK_SHADOW_OUT</shadow_type>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>5</padding>
<expand>False</expand>
<fill>True</fill>
</child>
</widget>
</widget>
</widget>
<widget>
<class>GtkHBox</class>
<child_name>CList:title</child_name>
<name>hbox51</name>
<homogeneous>True</homogeneous>
<spacing>0</spacing>
<widget>
<class>GtkHBox</class>
<name>hbox52</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label287</name>
<label>Country</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkArrow</class>
<name>country_arrow</name>
<width>10</width>
<height>10</height>
<visible>False</visible>
<arrow_type>GTK_ARROW_DOWN</arrow_type>
<shadow_type>GTK_SHADOW_OUT</shadow_type>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>5</padding>
<expand>False</expand>
<fill>True</fill>
</child>
</widget>
</widget>
</widget>
<widget> <widget>
<class>GtkLabel</class> <class>GtkLabel</class>
<child_name>CList:title</child_name> <child_name>CList:title</child_name>
<name>label232</name> <name>label276</name>
<label>Place Name</label> <label></label>
<justify>GTK_JUSTIFY_CENTER</justify> <justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap> <wrap>False</wrap>
<xalign>0.5</xalign> <xalign>0.5</xalign>
@ -2428,8 +2831,8 @@
<widget> <widget>
<class>GtkLabel</class> <class>GtkLabel</class>
<child_name>CList:title</child_name> <child_name>CList:title</child_name>
<name>label233a</name> <name>label277</name>
<label>ID</label> <label></label>
<justify>GTK_JUSTIFY_CENTER</justify> <justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap> <wrap>False</wrap>
<xalign>0.5</xalign> <xalign>0.5</xalign>
@ -2441,8 +2844,8 @@
<widget> <widget>
<class>GtkLabel</class> <class>GtkLabel</class>
<child_name>CList:title</child_name> <child_name>CList:title</child_name>
<name>label233b</name> <name>label278</name>
<label>City</label> <label></label>
<justify>GTK_JUSTIFY_CENTER</justify> <justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap> <wrap>False</wrap>
<xalign>0.5</xalign> <xalign>0.5</xalign>
@ -2454,8 +2857,8 @@
<widget> <widget>
<class>GtkLabel</class> <class>GtkLabel</class>
<child_name>CList:title</child_name> <child_name>CList:title</child_name>
<name>label233c</name> <name>label279</name>
<label>County</label> <label></label>
<justify>GTK_JUSTIFY_CENTER</justify> <justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap> <wrap>False</wrap>
<xalign>0.5</xalign> <xalign>0.5</xalign>
@ -2467,8 +2870,8 @@
<widget> <widget>
<class>GtkLabel</class> <class>GtkLabel</class>
<child_name>CList:title</child_name> <child_name>CList:title</child_name>
<name>label233d</name> <name>label280</name>
<label>State</label> <label></label>
<justify>GTK_JUSTIFY_CENTER</justify> <justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap> <wrap>False</wrap>
<xalign>0.5</xalign> <xalign>0.5</xalign>
@ -2480,8 +2883,8 @@
<widget> <widget>
<class>GtkLabel</class> <class>GtkLabel</class>
<child_name>CList:title</child_name> <child_name>CList:title</child_name>
<name>label233e</name> <name>label281</name>
<label>Country</label> <label></label>
<justify>GTK_JUSTIFY_CENTER</justify> <justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap> <wrap>False</wrap>
<xalign>0.5</xalign> <xalign>0.5</xalign>

View File

@ -109,12 +109,23 @@ mdetails = None
preview = None preview = None
database = None database = None
nameArrow = None nameArrow = None
idArrow = None
deathArrow = None deathArrow = None
dateArrow = None dateArrow = None
place_arrow = None
place_id_arrow= None
city_arrow = None
county_arrow = None
state_arrow = None
country_arrow = None
canvas = None canvas = None
merge_button = None merge_button = None
sort_column = 5 sort_column = 5
sort_direct = SORT_ASCENDING sort_direct = SORT_ASCENDING
p_sort_column = 0
p_sort_direct = SORT_ASCENDING
DataFilter = Filter.Filter("") DataFilter = Filter.Filter("")
c_birth_order = 0 c_birth_order = 0
c_name = 1 c_name = 1
@ -939,11 +950,13 @@ def on_person_list_select_row(obj,row,b,c):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def on_person_list_click_column(obj,column): def on_person_list_click_column(obj,column):
if column == 0: if column == 0:
change_sort(5,gtop.get_widget("nameSort")) change_sort(5,nameArrow)
elif column == 1:
change_sort(1,idArrow)
elif column == 3: elif column == 3:
change_sort(6,gtop.get_widget("dateSort")) change_sort(6,dateArrow)
elif column == 4: elif column == 4:
change_sort(7,gtop.get_widget("deathSort")) change_sort(7,deathArrow)
else: else:
return return
@ -952,6 +965,41 @@ def on_person_list_click_column(obj,column):
row = person_list.find_row_from_data(id2col[active_person]) row = person_list.find_row_from_data(id2col[active_person])
person_list.moveto(row) person_list.moveto(row)
def on_place_list_click_column(obj,column):
global p_sort_direct, p_sort_column
obj.freeze()
if len(obj.selection):
sel = obj.get_row_data(obj.selection[0])
else:
sel = None
place_arrows = [ place_arrow, place_id_arrow, city_arrow,
county_arrow, state_arrow, country_arrow ]
for a in place_arrows:
a.hide()
arrow = place_arrows[column]
if p_sort_column == column:
if p_sort_direct == SORT_DESCENDING:
p_sort_direct = SORT_ASCENDING
arrow.set(GTK.ARROW_DOWN,2)
else:
p_sort_direct = SORT_DESCENDING
arrow.set(GTK.ARROW_UP,2)
else:
p_sort_direct = SORT_ASCENDING
arrow.set(GTK.ARROW_DOWN,2)
p_sort_column = column
place_list.set_sort_type(p_sort_direct)
place_list.set_sort_column(p_sort_column + 6)
arrow.show()
place_list.sort()
if sel:
place_list.moveto(place_list.find_row_from_data(sel))
obj.thaw()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #
@ -961,9 +1009,9 @@ def change_sort(column,arrow):
global sort_direct global sort_direct
global sort_column global sort_column
nameArrow.hide() for a in [ nameArrow, deathArrow, dateArrow, idArrow ]:
deathArrow.hide() if arrow != a:
dateArrow.hide() a.hide()
arrow.show() arrow.show()
if sort_column == column: if sort_column == column:
@ -975,6 +1023,7 @@ def change_sort(column,arrow):
arrow.set(GTK.ARROW_UP,2) arrow.set(GTK.ARROW_UP,2)
else: else:
sort_direct = SORT_ASCENDING sort_direct = SORT_ASCENDING
arrow.set(GTK.ARROW_DOWN,2)
sort_column = column sort_column = column
person_list.set_sort_type(sort_direct) person_list.set_sort_type(sort_direct)
person_list.set_sort_column(sort_column) person_list.set_sort_column(sort_column)
@ -1347,21 +1396,21 @@ def on_media_activate(obj):
def on_notebook1_switch_page(obj,junk,page): def on_notebook1_switch_page(obj,junk,page):
if page == 0: if page == 0:
goto_active_person() goto_active_person()
merge_button.show() merge_button.set_sensitive(1)
elif page == 1: elif page == 1:
merge_button.hide() merge_button.set_sensitive(0)
load_family() load_family()
elif page == 2: elif page == 2:
merge_button.hide() merge_button.set_sensitive(0)
load_canvas() load_canvas()
elif page == 3: elif page == 3:
merge_button.hide() merge_button.set_sensitive(0)
load_sources() load_sources()
elif page == 4: elif page == 4:
merge_button.show() merge_button.set_sensitive(1)
load_places() load_places()
elif page == 5: elif page == 5:
merge_button.hide() merge_button.set_sensitive(0)
load_media() load_media()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -1381,10 +1430,7 @@ def load_places():
index = 0 index = 0
places = database.getPlaceMap().values() places = database.getPlaceMap().values()
nlist = map(lambda x: (string.upper(x.get_title()),x),places) u = string.upper
nlist.sort()
places = map(lambda(key,x): x, nlist)
for src in places: for src in places:
title = src.get_title() title = src.get_title()
id = src.getId() id = src.getId()
@ -1393,7 +1439,8 @@ def load_places():
county = mloc.get_county() county = mloc.get_county()
state = mloc.get_state() state = mloc.get_state()
country = mloc.get_country() country = mloc.get_country()
place_list.append([title,id,city,county,state,country]) place_list.append([title,id,city,county,state,country,
u(title), u(id), u(city), u(county), u(state), u(country)])
place_list.set_row_data(index,src) place_list.set_row_data(index,src)
index = index + 1 index = index + 1
@ -2601,8 +2648,10 @@ def main(arg):
global statusbar,notebook global statusbar,notebook
global person_list, source_list, place_list, canvas, media_list global person_list, source_list, place_list, canvas, media_list
global topWindow, preview, merge_button global topWindow, preview, merge_button
global nameArrow, dateArrow, deathArrow global nameArrow, dateArrow, deathArrow, idArrow
global cNameArrow, cDateArrow global cNameArrow, cDateArrow
global place_arrow, place_id_arrow, city_arrow, county_arrow
global state_arrow, country_arrow
global mid, mtype, mdesc, mpath, mdetails global mid, mtype, mdesc, mpath, mdetails
rc_parse(const.gtkrcFile) rc_parse(const.gtkrcFile)
@ -2635,9 +2684,16 @@ def main(arg):
filter_list = gtop.get_widget("filter_list") filter_list = gtop.get_widget("filter_list")
notebook = gtop.get_widget(NOTEBOOK) notebook = gtop.get_widget(NOTEBOOK)
nameArrow = gtop.get_widget("nameSort") nameArrow = gtop.get_widget("nameSort")
idArrow = gtop.get_widget("idSort")
dateArrow = gtop.get_widget("dateSort") dateArrow = gtop.get_widget("dateSort")
deathArrow = gtop.get_widget("deathSort") deathArrow = gtop.get_widget("deathSort")
merge_button= gtop.get_widget("merge") merge_button= gtop.get_widget("merge")
place_arrow = gtop.get_widget("place_arrow")
place_id_arrow= gtop.get_widget("place_id_arrow")
city_arrow = gtop.get_widget("city_arrow")
county_arrow = gtop.get_widget("county_arrow")
state_arrow = gtop.get_widget("state_arrow")
country_arrow = gtop.get_widget("country_arrow")
t = [ ('STRING', 0, 0), t = [ ('STRING', 0, 0),
('text/plain',0,0), ('text/plain',0,0),
@ -2653,6 +2709,15 @@ def main(arg):
person_list.set_sort_column(sort_column) person_list.set_sort_column(sort_column)
person_list.set_sort_type(sort_direct) person_list.set_sort_type(sort_direct)
place_list.set_column_visibility(6,0)
place_list.set_column_visibility(7,0)
place_list.set_column_visibility(8,0)
place_list.set_column_visibility(9,0)
place_list.set_column_visibility(10,0)
place_list.set_column_visibility(11,0)
place_list.set_sort_column(p_sort_column +6 )
place_list.set_sort_type(p_sort_direct)
fw = gtop.get_widget('filter') fw = gtop.get_widget('filter')
filter_list.set_menu(Filter.build_filter_menu(on_filter_name_changed,fw)) filter_list.set_menu(Filter.build_filter_menu(on_filter_name_changed,fw))
@ -2717,6 +2782,7 @@ def main(arg):
"on_person_list_click_column" : on_person_list_click_column, "on_person_list_click_column" : on_person_list_click_column,
"on_person_list_select_row" : on_person_list_select_row, "on_person_list_select_row" : on_person_list_select_row,
"on_place_list_button_press_event" : on_place_list_button_press_event, "on_place_list_button_press_event" : on_place_list_button_press_event,
"on_place_list_click_column" : on_place_list_click_column,
"on_main_key_release_event" : on_main_key_release_event, "on_main_key_release_event" : on_main_key_release_event,
"on_add_media_clicked" : create_add_dialog, "on_add_media_clicked" : create_add_dialog,
"on_media_activate" : on_media_activate, "on_media_activate" : on_media_activate,

View File

@ -265,11 +265,14 @@ class ComplexFilterFile:
def __init__(self,name): def __init__(self,name):
self.filters = {} self.filters = {}
self.fname = name self.fname = name
f = open(self.fname) try:
parser = make_parser() f = open(self.fname)
parser.setContentHandler(ComplexFilterParser(self)) parser = make_parser()
parser.parse(f) parser.setContentHandler(ComplexFilterParser(self))
f.close() parser.parse(f)
f.close()
except IOError:
pass
def get_filter_names(self): def get_filter_names(self):
return self.filters.keys() return self.filters.keys()

View File

@ -18,7 +18,10 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
"Database Processing/Reorder gramps IDs" """
Change id IDs of all the elements in the database to conform to the
scheme specified in the database's prefix ids
"""
import re import re
import utils import utils
@ -28,13 +31,9 @@ _ = intl.gettext
_findint = re.compile('^[^\d]*(\d+)[^\d]*') _findint = re.compile('^[^\d]*(\d+)[^\d]*')
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def runTool(database,active_person,callback): def runTool(database,active_person,callback):
"""Changed person, family, object, source, and place ids"""
make_new_ids(database.getPersonMap(),database.iprefix) make_new_ids(database.getPersonMap(),database.iprefix)
make_new_ids(database.getFamilyMap(),database.fprefix) make_new_ids(database.getFamilyMap(),database.fprefix)
make_new_ids(database.getObjectMap(),database.oprefix) make_new_ids(database.getObjectMap(),database.oprefix)
@ -45,11 +44,24 @@ def runTool(database,active_person,callback):
def make_new_ids(data_map,prefix): def make_new_ids(data_map,prefix):
"""Try to extract the old integer out of the id, and reuse it
if possible. Otherwise, blindly renumber those that can't."""
dups = [] dups = []
newids = [] newids = []
# search all ids in the map
for id in data_map.keys(): for id in data_map.keys():
# attempt to extract integer, if we can't, treat it as a
# duplicate
match = _findint.match(id) match = _findint.match(id)
if match: if match:
# get the integer, build the new id. Make sure it
# hasn't already been chosen. If it has, put this
# in the duplicate id list
index = match.groups()[0] index = match.groups()[0]
newid = prefix % int(index) newid = prefix % int(index)
if newid == id: if newid == id:
@ -62,6 +74,12 @@ def make_new_ids(data_map,prefix):
data.setId(newid) data.setId(newid)
data_map[newid] = data data_map[newid] = data
del data_map[id] del data_map[id]
else:
dups.append(id)
# go through the duplicates, looking for the first availble
# id that matches the new scheme.
index = 0 index = 0
for id in dups: for id in dups:
while 1: while 1: