Fast sorting

svn: r297
This commit is contained in:
Don Allingham 2001-08-06 03:00:01 +00:00
parent 1feb641e12
commit ebfb8fbe0f
7 changed files with 938 additions and 827 deletions

View File

@ -387,6 +387,14 @@ class GrampsParser(handler.ContentHandler):
def start_created(self,attrs): def start_created(self,attrs):
self.entries = int(attrs["people"]) + int(attrs["families"]) self.entries = int(attrs["people"]) + int(attrs["families"])
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def start_pos(self,attrs):
self.person.position = (int(u2l(attrs["x"])), int(u2l(attrs["y"])))
#--------------------------------------------------------------------- #---------------------------------------------------------------------
# #
# #
@ -818,6 +826,7 @@ class GrampsParser(handler.ContentHandler):
"person" : (start_person, None), "person" : (start_person, None),
"img" : (start_photo, None), "img" : (start_photo, None),
"place" : (None, stop_place), "place" : (None, stop_place),
"pos" : (start_pos, None),
"postal" : (None, stop_postal), "postal" : (None, stop_postal),
"researcher" : (None, stop_research), "researcher" : (None, stop_research),
"resname" : (None, stop_resname ), "resname" : (None, stop_resname ),

View File

@ -454,6 +454,7 @@ class Person:
self.urls = [] self.urls = []
self.note = None self.note = None
self.paf_uid = "" self.paf_uid = ""
self.position = None
def setPrimaryName(self,name) : def setPrimaryName(self,name) :
self.PrimaryName = name self.PrimaryName = name
@ -627,7 +628,13 @@ class Person:
if self.note == None: if self.note == None:
self.note = Note() self.note = Note()
return self.note return self.note
def setPosition(self,pos):
self.position = pos
def getPosition(self):
return self.position
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #

View File

@ -293,7 +293,7 @@ def exportData(database, filename, callback):
write_line(g,"nick",person.getNickName(),3) write_line(g,"nick",person.getNickName(),3)
pos = person.getPosition() pos = person.getPosition()
if pos != None: if pos != None:
g.write(' <pos>%d %d</pos>\n'% pos) g.write(' <pos x="%d" y="%d"/>\n'% pos)
dump_my_event(g,"Birth",person.getBirth(),3) dump_my_event(g,"Birth",person.getBirth(),3)
dump_my_event(g,"Death",person.getDeath(),3) dump_my_event(g,"Death",person.getDeath(),3)
for event in person.getEventList(): for event in person.getEventList():

View File

@ -706,8 +706,8 @@
<handler>on_person_list_click_column</handler> <handler>on_person_list_click_column</handler>
<last_modification_time>Thu, 07 Dec 2000 14:37:54 GMT</last_modification_time> <last_modification_time>Thu, 07 Dec 2000 14:37:54 GMT</last_modification_time>
</signal> </signal>
<columns>5</columns> <columns>8</columns>
<column_widths>250,60,70,150,100</column_widths> <column_widths>250,60,70,150,100,1,1,1</column_widths>
<selection_mode>GTK_SELECTION_SINGLE</selection_mode> <selection_mode>GTK_SELECTION_SINGLE</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>
@ -907,6 +907,46 @@
</widget> </widget>
</widget> </widget>
</widget> </widget>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>sort1</name>
<label></label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
</widget>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>sort2</name>
<label></label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
</widget>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>sort3</name>
<label></label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
</widget>
</widget> </widget>
</widget> </widget>

View File

@ -104,7 +104,8 @@ family_window = None
queryTop = None queryTop = None
prefsTop = None prefsTop = None
pv = {} pv = {}
sortFunc = sort.fast_name_sort sort_column = 5
sort_direct = SORT_ASCENDING
sbar_active = 1 sbar_active = 1
DataFilter = Filter.create("") DataFilter = Filter.create("")
@ -792,7 +793,7 @@ def load_sources():
if current_row == -1: if current_row == -1:
current_row = 0 current_row = 0
source_list.select_row(current_row,0) source_list.select_row(current_row,0)
source_list.moveto(current_row,0) source_list.moveto(current_row)
source_list.set_data("i",current_row) source_list.set_data("i",current_row)
source_list.thaw() source_list.thaw()
@ -1092,7 +1093,7 @@ def on_save_parents_clicked(obj):
mrel = const.childRelations[mrel] mrel = const.childRelations[mrel]
frel = const.childRelations[frel] frel = const.childRelations[frel]
type = save_frel(type) type = const.save_frel(type)
if select_father or select_mother: if select_father or select_mother:
if select_mother.getGender() == Person.male and \ if select_mother.getGender() == Person.male and \
@ -1371,7 +1372,7 @@ def delete_spouse():
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def on_person_list_select_row(obj,a,b,c): def on_person_list_select_row(obj,a,b,c):
person = obj.get_row_data(a) person,alt = obj.get_row_data(a)
obj.set_data("a",person) obj.set_data("a",person)
change_active_person(person) change_active_person(person)
@ -1386,7 +1387,8 @@ def on_person_list_select_row(obj,a,b,c):
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def on_person_list_click_column(obj,column): def on_person_list_click_column(obj,column):
global sortFunc global sort_column
global sort_direct
nameArrow = gtop.get_widget("nameSort") nameArrow = gtop.get_widget("nameSort")
dateArrow = gtop.get_widget("dateSort") dateArrow = gtop.get_widget("dateSort")
@ -1396,35 +1398,50 @@ def on_person_list_click_column(obj,column):
dateArrow.hide() dateArrow.hide()
deathArrow.hide() deathArrow.hide()
nameArrow.show() nameArrow.show()
if sortFunc != sort.fast_name_sort: if sort_column == 5:
sortFunc = sort.fast_name_sort if sort_direct == SORT_DESCENDING:
nameArrow.set(GTK.ARROW_DOWN,2) sort_direct = SORT_ASCENDING
nameArrow.set(GTK.ARROW_DOWN,2)
else:
sort_direct = SORT_DESCENDING
nameArrow.set(GTK.ARROW_UP,2)
else: else:
sortFunc = sort.reverse_name_sort sort_direct = SORT_DESCENDING
nameArrow.set(GTK.ARROW_UP,2) sort_column = 5
elif column == 3: elif column == 3:
nameArrow.hide() nameArrow.hide()
deathArrow.hide() deathArrow.hide()
dateArrow.show() dateArrow.show()
if sortFunc != sort.fast_birth_sort: if sort_column == 6:
sortFunc = sort.fast_birth_sort if sort_direct == SORT_ASCENDING:
dateArrow.set(GTK.ARROW_DOWN,2) sort_direct = SORT_DESCENDING
dateArrow.set(GTK.ARROW_UP,2)
else:
sort_direct = SORT_ASCENDING
dateArrow.set(GTK.ARROW_DOWN,2)
else: else:
sortFunc = sort.reverse_birth_sort sort_direct = SORT_ASCENDING
dateArrow.set(GTK.ARROW_UP,2) sort_column = 6
elif column == 4: elif column == 4:
nameArrow.hide() nameArrow.hide()
deathArrow.show() deathArrow.show()
dateArrow.hide() dateArrow.hide()
if sortFunc != sort.fast_death_sort: if sort_column == 7:
sortFunc = sort.fast_death_sort if sort_direct == SORT_ASCENDING:
deathArrow.set(GTK.ARROW_DOWN,2) sort_direct = SORT_DESCENDING
deathArrow.set(GTK.ARROW_UP,2)
else:
sort_direct = SORT_ASCENDING
deathArrow.set(GTK.ARROW_DOWN,2)
else: else:
sortFunc = sort.reverse_death_sort sort_direct = SORT_ASCENDING
deathArrow.set(GTK.ARROW_UP,2) sort_column = 7
else: else:
return return
apply_filter() person_list.set_sort_type(sort_direct)
person_list.set_sort_column(sort_column)
person_list.sort()
person_list.moveto()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -1647,10 +1664,7 @@ def on_notebook1_switch_page(obj,junk,page):
if not active_person: if not active_person:
return return
if page == 0: if page == 0:
if id2col.has_key(active_person): goto_active_person()
column = id2col[active_person]
person_list.select_row(column,0)
person_list.moveto(column,0)
elif page == 1: elif page == 1:
load_family() load_family()
elif page == 2: elif page == 2:
@ -2262,8 +2276,6 @@ def apply_filter():
if Config.hide_altnames == 0: if Config.hide_altnames == 0:
names = names + altnames names = names + altnames
names = sortFunc(names)
person_list.freeze() person_list.freeze()
person_list.clear() person_list.clear()
@ -2283,18 +2295,22 @@ def apply_filter():
name = name_tuple[0] name = name_tuple[0]
if datacomp(person): if datacomp(person):
pos = (person,alt)
if not alt: if not alt:
id2col[person] = i id2col[person] = pos
if person.getGender(): if person.getGender():
gender = const.male gender = const.male
else: else:
gender = const.female gender = const.female
bday = person.getBirth().getQuoteDate() bday = person.getBirth().getDateObj()
dday = person.getDeath().getQuoteDate() dday = person.getDeath().getDateObj()
clistadd([gname(name,alt),person.getId(), gender,bday, dday],\ clistadd([gname(name,alt),person.getId(), gender,bday.getQuoteDate(),
person) dday.getQuoteDate(), sort.build_sort_name(name),
sort.build_sort_birth(bday), sort.build_sort_death(dday)], pos)
i = i + 1 i = i + 1
person_list.sort()
person_list.moveto()
person_list.thaw() person_list.thaw()
if i > 0: if i > 0:
@ -2307,13 +2323,15 @@ def apply_filter():
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def goto_active_person(): def goto_active_person():
if id2col.has_key(active_person): if id2col.has_key(active_person):
column = id2col[active_person] pos = id2col[active_person]
person_list.select_row(column,0) column = person_list.find_row_from_data(pos)
person_list.moveto(column,0) if column != -1:
person_list.select_row(column,0)
person_list.moveto(column)
else: else:
person_list.select_row(0,0) person_list.select_row(0,0)
person_list.moveto(0,0) person_list.moveto(0)
person = person_list.get_row_data(0) person,alt = person_list.get_row_data(0)
change_active_person(person) change_active_person(person)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -2453,6 +2471,12 @@ def main(arg):
person_list = gtop.get_widget("person_list") person_list = gtop.get_widget("person_list")
source_list = gtop.get_widget("source_list") source_list = gtop.get_widget("source_list")
filter_list = gtop.get_widget("filter_list") filter_list = gtop.get_widget("filter_list")
person_list.set_column_visibility(5,0)
person_list.set_column_visibility(6,0)
person_list.set_column_visibility(7,0)
person_list.set_sort_column(sort_column)
person_list.set_sort_type(sort_direct)
myMenu = GtkMenu() myMenu = GtkMenu()
for filter in Filter.filterList: for filter in Filter.filterList:

File diff suppressed because it is too large Load Diff

View File

@ -27,50 +27,42 @@ import string
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def build_sort_name(person): def build_sort_name(n):
n = person[0] return "%-25s%-30s%s" % (n.Surname,n.FirstName,n.Suffix)
nm = "%-25s%-30s%s" % (n.Surname,n.FirstName,n.Suffix)
return (string.upper(nm),person)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def build_sort_birth(person): def build_sort_birth(n):
n = person[1].birth.date.start y = n.start.year
y = n.year
if y == -1: if y == -1:
y = 9999 y = 9999
m = n.month m = n.start.month
if m == -1: if m == -1:
m = 99 m = 99
d = n.day d = n.start.day
if d == -1: if d == -1:
d = 99 d = 99
nm = "%04d%2d%2d" % (y,m,d) return "%04d%2d%2d" % (y,m,d)
return (nm,person)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def build_sort_death(person): def build_sort_death(n):
n = person[1].death.date.start y = n.start.year
y = n.year
if y == -1: if y == -1:
y = 9999 y = 9999
m = n.month m = n.start.month
if m == -1: if m == -1:
m = 99 m = 99
d = n.day d = n.start.day
if d == -1: if d == -1:
d = 99 d = 99
nm = "%04d%2d%2d" % (y,m,d) return "%04d%2d%2d" % (y,m,d)
return (nm,person)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #