def new_child_added(self, person): ref = ChildRef() ref.ref = person.get_handle() self.family.add_child_ref(ref) self.rebuild() GLib.idle_add(self.tree.scroll_to_cell, len(self.family.get_child_ref_list()) - 1) self.call_edit_childref(ref)
def read_children_lines(self): father_surname = "Dummy" if not self.current_husband_handle: LOG.warning("Unknown father for child in line %d!" % self.lineno) return None husb = self.db.get_person_from_handle(self.current_husband_handle) father_surname = husb.get_primary_name().get_surname() if not self.current_family: LOG.warning("Unknown family of child in line %d!" % self.lineno) return None while 1: line = self.get_next_line() if line is None: break if line == "": continue fields = line.split(" ") if fields[0] == "-": LOG.debug("Child:") child = None if fields[1] == "h": (idx, child) = self.parse_person(fields, 2, Person.MALE, father_surname) elif fields[1] == "f": (idx, child) = self.parse_person(fields, 2, Person.FEMALE, father_surname) else: (idx, child) = self.parse_person(fields, 1, Person.UNKNOWN, father_surname) if child: childref = ChildRef() childref.set_reference_handle(child.get_handle()) self.current_family.add_child_ref(childref) self.db.commit_family(self.current_family, self.trans) child.add_parent_family_handle( self.current_family.get_handle()) if self.current_child_birthplace_handle: birth = None birth_ref = child.get_birth_ref() if birth_ref: birth = self.db.get_event_from_handle( birth_ref.ref) if not birth: birth = self.create_event(EventType.BIRTH) birth_ref = EventRef() birth_ref.set_reference_handle(birth.get_handle()) child.set_birth_ref(birth_ref) birth.set_place_handle( self.current_child_birthplace_handle) self.db.commit_event(birth, self.trans) if self.current_child_source_handle: child.add_citation(self.current_child_source_handle) self.db.commit_person(child, self.trans) else: break self.current_mode = None return None
def read_children_lines(self): father_surname = "Dummy" if not self.current_husband_handle: LOG.warning("Unknown father for child in line %d!" % self.lineno) return None husb = self.db.get_person_from_handle(self.current_husband_handle) father_surname = husb.get_primary_name().get_surname() if not self.current_family: LOG.warning("Unknown family of child in line %d!" % self.lineno) return None while 1: line = self.get_next_line() if line is None: break if line == "": continue fields = line.split(" ") if fields[0] == "-": LOG.debug("Child:") child = None if fields[1] == "h": (idx,child) = self.parse_person(fields,2,Person.MALE,father_surname) elif fields[1] == "f": (idx,child) = self.parse_person(fields,2,Person.FEMALE,father_surname) else: (idx,child) = self.parse_person(fields,1,Person.UNKNOWN,father_surname) if child: childref = ChildRef() childref.set_reference_handle(child.get_handle()) self.current_family.add_child_ref( childref) self.db.commit_family(self.current_family,self.trans) child.add_parent_family_handle( self.current_family.get_handle()) if self.current_child_birthplace_handle: birth = None birth_ref = child.get_birth_ref() if birth_ref: birth = self.db.get_event_from_handle(birth_ref.ref) if not birth: birth = self.create_event(EventType.BIRTH) birth_ref = EventRef() birth_ref.set_reference_handle(birth.get_handle()) child.set_birth_ref(birth_ref) birth.set_place_handle(self.current_child_birthplace_handle) self.db.commit_event(birth,self.trans) if self.current_child_source_handle: child.add_citation(self.current_child_source_handle) self.db.commit_person(child,self.trans) else: break self.current_mode = None return None
def callback_add_child(self, person, family_handle): ref = ChildRef() ref.ref = person.get_handle() family = self.dbstate.db.get_family_from_handle(family_handle) family.add_child_ref(ref) with DbTxn(_("Add Child to Family"), self.dbstate.db) as trans: #add parentref to child person.add_parent_family_handle(family_handle) #default relationship is used self.dbstate.db.commit_person(person, trans) #add child to family self.dbstate.db.commit_family(family, trans)
def add_parent_family(self, obj, event, handle): if button_activated(event, _LEFT_BUTTON): family = Family() person = self.dbstate.db.get_person_from_handle(self.get_handle()) ref = ChildRef() ref.ref = person.handle family.add_child_ref(ref) try: EditFamily(self.dbstate, self.uistate, [], family) except WindowActiveError: pass
def add_parents(self, *obj): family = Family() person = self.dbstate.db.get_person_from_handle(self.handle) if not person: return ref = ChildRef() ref.ref = person.handle family.add_child_ref(ref) try: EditFamily(self.dbstate, self.uistate, [], family) except WindowActiveError: pass
def share_button_clicked(self, obj=None): # it only makes sense to skip those who are already in the family skip_list = [self.family.get_father_handle(), self.family.get_mother_handle()] skip_list.extend(x.ref for x in self.family.get_child_ref_list()) sel = SelectPerson(self.dbstate, self.uistate, self.track, _("Select Child"), skip=skip_list) person = sel.run() if person: ref = ChildRef() ref.ref = person.get_handle() self.family.add_child_ref(ref) self.rebuild() GLib.idle_add(self.tree.scroll_to_cell, len(self.family.get_child_ref_list()) - 1) self.call_edit_childref(ref)
def _parse_family(self, line_number, row, col): "Parse the content of a family line" family_ref = rd(line_number, row, col, "family") if family_ref is None: LOG.warn("no family reference found for family on line %d" % line_number) return # required child = rd(line_number, row, col, "child") source = rd(line_number, row, col, "source") note = rd(line_number, row, col, "note") gender = rd(line_number, row, col, "gender") child = self.lookup("person", child) family = self.lookup("family", family_ref) if family is None: LOG.warn("no matching family reference found for family " "on line %d" % line_number) return if child is None: LOG.warn("no matching child reference found for family " "on line %d" % line_number) return # is this child already in this family? If so, don't add LOG.debug("children: %s", [ref.ref for ref in family.get_child_ref_list()]) LOG.debug("looking for: %s", child.get_handle()) if child.get_handle() not in [ ref.ref for ref in family.get_child_ref_list() ]: # add child to family LOG.debug(" adding child [%s] to family [%s]", child.get_gramps_id(), family.get_gramps_id()) childref = ChildRef() childref.set_reference_handle(child.get_handle()) family.add_child_ref(childref) self.db.commit_family(family, self.trans) child.add_parent_family_handle(family.get_handle()) if gender: # replace gender = gender.lower() if gender == gender_map[Person.MALE].lower(): gender = Person.MALE elif gender == gender_map[Person.FEMALE].lower(): gender = Person.FEMALE else: gender = Person.UNKNOWN child.set_gender(gender) if source: # add, if new dummy_new, source = self.get_or_create_source(source) self.find_and_set_citation(child, source) # put note on child if note: # append notes, if previous notes previous_notes_list = child.get_note_list() updated_note = False for note_handle in previous_notes_list: previous_note = self.db.get_note_from_handle(note_handle) if previous_note.type == NoteType.PERSON: previous_text = previous_note.get() if note not in previous_text: note = previous_text + "\n" + note previous_note.set(note) self.db.commit_note(previous_note, self.trans) updated_note = True break if not updated_note: # add new note here new_note = Note() new_note.handle = create_id() new_note.type.set(NoteType.PERSON) new_note.set(note) if self.default_tag: new_note.add_tag(self.default_tag.handle) self.db.add_note(new_note, self.trans) child.add_note(new_note.handle) self.db.commit_person(child, self.trans)
def _parse_family(self, line_number, row, col): "Parse the content of a family line" family_ref = rd(line_number, row, col, "family") if family_ref is None: LOG.warn("no family reference found for family on line %d" % line_number) return # required child = rd(line_number, row, col, "child") source = rd(line_number, row, col, "source") note = rd(line_number, row, col, "note") gender = rd(line_number, row, col, "gender") child = self.lookup("person", child) family = self.lookup("family", family_ref) if family is None: LOG.warn("no matching family reference found for family " "on line %d" % line_number) return if child is None: LOG.warn("no matching child reference found for family " "on line %d" % line_number) return # is this child already in this family? If so, don't add LOG.debug("children: %s", [ref.ref for ref in family.get_child_ref_list()]) LOG.debug("looking for: %s", child.get_handle()) if child.get_handle() not in [ref.ref for ref in family.get_child_ref_list()]: # add child to family LOG.debug(" adding child [%s] to family [%s]", child.get_gramps_id(), family.get_gramps_id()) childref = ChildRef() childref.set_reference_handle(child.get_handle()) family.add_child_ref( childref) self.db.commit_family(family, self.trans) child.add_parent_family_handle(family.get_handle()) if gender: # replace gender = gender.lower() if gender == gender_map[Person.MALE].lower(): gender = Person.MALE elif gender == gender_map[Person.FEMALE].lower(): gender = Person.FEMALE else: gender = Person.UNKNOWN child.set_gender(gender) if source: # add, if new dummy_new, source = self.get_or_create_source(source) self.find_and_set_citation(child, source) # put note on child if note: # append notes, if previous notes previous_notes_list = child.get_note_list() updated_note = False for note_handle in previous_notes_list: previous_note = self.db.get_note_from_handle(note_handle) if previous_note.type == NoteType.PERSON: previous_text = previous_note.get() if note not in previous_text: note = previous_text + "\n" + note previous_note.set(note) self.db.commit_note(previous_note, self.trans) updated_note = True break if not updated_note: # add new note here new_note = Note() new_note.handle = create_id() new_note.type.set(NoteType.PERSON) new_note.set(note) if self.default_tag: new_note.add_tag(self.default_tag.handle) self.db.add_note(new_note, self.trans) child.add_note(new_note.handle) self.db.commit_person(child, self.trans)