diff --git a/gramps/src/AutoComp.py b/gramps/src/AutoComp.py index fcb8cc6cd..b4af82602 100644 --- a/gramps/src/AutoComp.py +++ b/gramps/src/AutoComp.py @@ -28,19 +28,16 @@ import gtk cnv = string.lower -class AutoComp: - """ - Allows allow completion of the GtkEntry widget with the entries - in the passed string list. - """ +class AutoCompBase: + def __init__(self,widget,plist,source=None): - self.entry = widget if source: self.nlist = source.nlist else: self.nlist = map((lambda n: (cnv(n),n)),plist) self.nlist.sort() - self.entry.connect("insert-text",self.insert_text) + self.nl = "xzsdkdjecsc" + self.l = 0 def insert_text(self,entry,new_text,new_text_len,i_dont_care): """ @@ -76,6 +73,94 @@ class AutoComp: """ entry.select_region(0, 0) + +class AutoCombo(AutoCompBase): + """ + Allows allow completion of the GtkEntry widget with the entries + in the passed string list. + """ + def __init__(self,widget,plist,source=None): + AutoCompBase.__init__(self,widget,plist,source) + self.entry = widget + widget.entry.connect("insert-text",self.insert_text) + widget.children()[1].connect("button-press-event",self.build_list) + widget.children()[1].connect("button-release-event",self.setval) + self.vals = [""] + self.inb = 0 + + def setval(self,widget,event): + self.inb = 0 + text = self.entry.entry.get_text() + if self.nl == string.lower(text): + self.entry.entry.set_position(self.l) + self.entry.entry.select_region(self.l, -1) + + def build_list(self,widget,event): + self.inb = 1 + if self.vals[0] == "": + self.entry.set_popdown_strings([self.entry.entry.get_text()]) + else: + self.entry.set_popdown_strings(self.vals) + + def timer_callback(self,entry): + """ + The workhors +e routine of file completion. This routine grabs the + current text of the entry box, and grubs through the list item + looking for any case insensitive matches. This routine relies on + public knowledge of the GtkEntry data structure, not on any private + data. + """ + # Clear any timer + timer = entry.get_data("timer"); + if (timer): + gtk.timeout_remove(timer) + + if self.inb == 1: + return + + # Get the user's text + typed = entry.get_text() + if (not typed): + return + typed_lc = string.lower(typed) + + if typed_lc == self.nl: + return + + self.l = len(typed_lc) + + self.vals = [] + + # Walk the GtkList in the entry box + for nl,n in self.nlist: + # If typed text is a substring of the label text, then fill in + # the entry field with the full text (and correcting + # capitalization), and then select all the characters that + # don't match. With the user's next keystroke these will be + # replaced if they are incorrect. + if nl[0:self.l] == typed_lc: + self.vals.append(n) + + if len(self.vals) > 0: + n = self.vals[0] + self.nl = string.lower(n) + entry.set_text(n) + entry.set_position(self.l) + entry.select_region(self.l, -1) + else: + self.vals = [""] + +class AutoEntry(AutoCompBase): + """ + Allows allow completion of the GtkEntry widget with the entries + in the passed string list. + """ + def __init__(self,widget,plist,source=None): + AutoCompBase.__init__(self,widget,plist,source) + self.entry = widget + self.entry.connect("insert-text",self.insert_text) + def timer_callback(self,entry): """ The workhorse routine of file completion. This routine grabs the @@ -84,7 +169,6 @@ class AutoComp: public knowledge of the GtkEntry data structure, not on any private data. """ - # Clear any timer timer = entry.get_data("timer"); if (timer): @@ -96,23 +180,22 @@ class AutoComp: return typed_lc = string.lower(typed) + if typed_lc == self.nl: + return + + self.l = len(typed_lc) + # Walk the GtkList in the entry box for nl,n in self.nlist: - if (not nl): - continue - - # If equal, no need to add any text - if (typed_lc == nl): - return - # If typed text is a substring of the label text, then fill in # the entry field with the full text (and correcting # capitalization), and then select all the characters that - # don't match. With the user's enxt keystroke these will be + # don't match. With the user's next keystroke these will be # replaced if they are incorrect. - if (string.find(nl,typed_lc) == 0): + if nl[0:self.l] == typed_lc: + self.nl = nl entry.set_text(n) - entry.set_position(len(typed)) - entry.select_region(len(typed), -1) + entry.set_position(self.l) + entry.select_region(self.l, -1) return diff --git a/gramps/src/EditPerson.glade b/gramps/src/EditPerson.glade index 2435efb6d..cb969e4a0 100644 --- a/gramps/src/EditPerson.glade +++ b/gramps/src/EditPerson.glade @@ -342,13 +342,14 @@ - GtkEntry - birthPlace - True - True - True - 0 - + GtkCombo + bpcombo + False + True + False + True + False + 2 3 @@ -363,6 +364,17 @@ True False + + + GtkEntry + GtkCombo:entry + birthPlace + True + True + True + 0 + + @@ -557,13 +569,14 @@ - GtkEntry - deathPlace - True - True - True - 0 - + GtkCombo + dbcombo + False + True + False + True + False + 2 3 @@ -578,6 +591,17 @@ True False + + + GtkEntry + GtkCombo:entry + deathPlace + True + True + True + 0 + + @@ -790,54 +814,6 @@ - - GtkEntry - suffix - True - True - True - 0 - - - 1 - 2 - 2 - 3 - 5 - 5 - True - False - False - False - True - False - - - - - GtkEntry - title - True - True - True - 0 - - - 1 - 2 - 3 - 4 - 5 - 5 - True - False - False - False - True - False - - - GtkLabel label22 @@ -864,6 +840,30 @@ + + GtkEntry + nickname + True + True + True + 0 + + + 1 + 3 + 4 + 5 + 3 + 3 + True + False + False + False + True + False + + + GtkEntry givenName @@ -878,8 +878,8 @@ 3 0 1 - 5 - 5 + 3 + 3 True False False @@ -889,9 +889,45 @@ + + GtkCombo + sncombo + False + True + False + True + False + + + 1 + 3 + 1 + 2 + 3 + 3 + True + False + False + False + True + False + + + + GtkEntry + GtkCombo:entry + surname + True + True + True + 0 + + + + GtkEntry - nickname + suffix True True True @@ -899,11 +935,11 @@ 1 - 3 - 4 - 5 - 5 - 5 + 2 + 2 + 3 + 3 + 3 True False False @@ -931,8 +967,8 @@ 3 2 3 - 5 - 0 + 3 + 3 False False False @@ -942,6 +978,30 @@ + + GtkEntry + title + True + True + True + 0 + + + 1 + 2 + 3 + 4 + 3 + 3 + True + False + False + False + True + False + + + GtkButton button106 @@ -960,8 +1020,8 @@ 3 3 4 - 5 - 0 + 3 + 3 False False False @@ -970,30 +1030,6 @@ False - - - GtkEntry - surname - True - True - True - 0 - - - 1 - 3 - 1 - 2 - 5 - 5 - True - False - False - False - True - False - - @@ -1197,8 +1233,8 @@ 3 0 1 - 2 - 0 + 3 + 3 True False False diff --git a/gramps/src/EditPerson.py b/gramps/src/EditPerson.py index 1c02ef9fe..786dbb899 100644 --- a/gramps/src/EditPerson.py +++ b/gramps/src/EditPerson.py @@ -181,6 +181,9 @@ class EditPerson: self.title = self.get_widget("title") self.bdate = self.get_widget("birthDate") self.bplace = self.get_widget("birthPlace") + self.bpcombo = self.get_widget("bpcombo") + self.dpcombo = self.get_widget("bpcombo") + self.sncombo = self.get_widget("sncombo") self.ddate = self.get_widget("deathDate") self.dplace = self.get_widget("deathPlace") self.is_male = self.get_widget("genderMale") @@ -216,10 +219,10 @@ class EditPerson: self.window.editable_enters(self.ddate); self.window.editable_enters(self.dplace); - self.autoplace = AutoComp.AutoComp(self.bplace,self.pmap.keys()) - AutoComp.AutoComp(self.dplace,self.pmap.keys(),self.autoplace) - if Config.autocomp: - self.comp = AutoComp.AutoComp(self.surname_field,const.surnames) + self.autoplace = AutoComp.AutoCombo(self.bpcombo,self.pmap.keys()) + + AutoComp.AutoCombo(self.dpcombo,self.pmap.keys(),self.autoplace) + self.comp = AutoComp.AutoCombo(self.sncombo,const.surnames) self.gid.set_text(person.getId()) self.gid.set_editable(Config.id_edit) @@ -318,7 +321,7 @@ class EditPerson: stat = 0 combo.entry.set_text("") - AutoComp.AutoComp(place,None,self.autoplace) + AutoComp.AutoEntry(place,None,self.autoplace) if ord and ord.getPlace(): place.set_text(ord.getPlace().get_title()) return stat diff --git a/gramps/src/EventEdit.py b/gramps/src/EventEdit.py index cf01ed0b0..d98a3724f 100644 --- a/gramps/src/EventEdit.py +++ b/gramps/src/EventEdit.py @@ -100,7 +100,7 @@ class EventEditor: self.window.editable_enters(self.cause_field); self.window.editable_enters(self.descr_field); - AutoComp.AutoComp(self.place_field,self.pmap.keys()) + AutoComp.AutoEntry(self.place_field,self.pmap.keys()) if event != None: self.name_field.set_text(event.getName()) diff --git a/gramps/src/Find.py b/gramps/src/Find.py index 2a6f21ce1..3ef23990a 100644 --- a/gramps/src/Find.py +++ b/gramps/src/Find.py @@ -58,7 +58,7 @@ class Find: self.nlist.append(n.getPrimaryName().getName()) if Config.autocomp: - self.comp = AutoComp.AutoComp(self.entry,self.nlist) + self.comp = AutoComp.AutoEntry(self.entry,self.nlist) self.next = self.xml.get_widget("next") self.top.editable_enters(self.entry) diff --git a/gramps/src/SelectChild.py b/gramps/src/SelectChild.py index 60a739c8a..3d8128026 100644 --- a/gramps/src/SelectChild.py +++ b/gramps/src/SelectChild.py @@ -243,7 +243,7 @@ class NewChild: self.surname = self.xml.get_widget("surname") self.given = self.xml.get_widget("childGiven") if Config.autocomp: - self.comp = AutoComp.AutoComp(self.surname,const.surnames) + self.comp = AutoComp.AutoEntry(self.surname,const.surnames) self.surname.set_text(self.update_surname(2)) diff --git a/gramps/src/plugins/ReadGedcom.py b/gramps/src/plugins/ReadGedcom.py index 27f74f304..f63585000 100644 --- a/gramps/src/plugins/ReadGedcom.py +++ b/gramps/src/plugins/ReadGedcom.py @@ -289,18 +289,26 @@ class GedcomParser: def parse_source(self,name,level): self.source = self.db.findSource(name,self.smap) - + + note = "" while 1: matches = self.get_next() if int(matches[0]) < level: + if note: + self.source.setNote(note) + if not self.source.getTitle(): + self.source.setTitle("No title - ID %s" % self.source.getId()) self.backup() return - elif matches[1] == "DATA" or matches[1] == "TEXT": - self.ignore_sub_junk(2) elif matches[1] == "TITL": title = matches[2] + self.parse_continue_data(level+1) title = string.replace(title,'\n',' ') self.source.setTitle(title) + elif matches[1] == "TAXT" or matches[1] == "PERI": # EasyTree Sierra On-Line + if self.source.getTitle() == "": + title = matches[2] + self.parse_continue_data(level+1) + title = string.replace(title,'\n',' ') + self.source.setTitle(title) elif matches[1] == "AUTH": self.source.setAuthor(matches[2] + self.parse_continue_data(level+1)) elif matches[1] == "PUBL": @@ -309,8 +317,10 @@ class GedcomParser: self.ignore_sub_junk(2) elif matches[1] == "NOTE": if matches[2] and matches[2][0] != "@": - note = matches[2] + self.parse_continue_data(level+1) - self.source.setNote(note) + if note: + note = "%s\n%s%s" % (note,matches[2],self.parse_continue_data(level+1)) + else: + note = matches[2] + self.parse_continue_data(level+1) self.ignore_sub_junk(2) else: if self.nmap.has_key(matches[2]): @@ -319,6 +329,20 @@ class GedcomParser: noteobj = Note() self.nmap[matches[2]] = noteobj self.source.setNoteObj(noteobj) + elif matches[1] == "TEXT": + d = self.parse_continue_data(level+1) + if note: + note = "%s\n%s %s%s" % (note,matches[1],matches[2],d) + else: + note = "%s %s%s" % (matches[1],matches[2],d) + title = matches[2] + d + title = string.replace(title,'\n',' ') + self.source.setTitle(title) + else: + if note: + note = "%s\n%s %s" % (note,matches[1],matches[2]) + else: + note = "%s %s" % (matches[1],matches[2]) def parse_record(self): while 1: @@ -360,9 +384,9 @@ class GedcomParser: self.nmap[matches[1]] = noteobj text = matches[2][4:] if text == "": - noteobj.set(self.parse_continue_data(1)) + noteobj.set(self.parse_note_continue(1)) else: - noteobj.set(text + self.parse_continue_data(1)) + noteobj.set(text + self.parse_note_continue(1)) self.parse_note_data(1) elif matches[2] == "OBJE": self.ignore_sub_junk(1) @@ -1538,6 +1562,27 @@ class GedcomParser: self.backup() return data + def parse_note_continue(self,level): + data = "" + while 1: + matches = self.get_next() + + if int(matches[0]) < level: + self.backup() + return data + elif matches[1] == "NOTE": + data = "%s\n%s%s" % (data,matches[2],self.parse_continue_data(level+1)) + elif matches[1] == "CONC": + if self.broken_conc: + data = "%s %s" % (data,matches[2]) + else: + data = "%s%s" % (data,matches[2]) + elif matches[1] == "CONT": + data = "%s\n%s" % (data,matches[2]) + else: + self.backup() + return data + def parse_date(self,level): date = DateStruct() while 1: