コード例 #1
0
 def create_event(self, description=_("Estimated date"),
                  type=None, date=None, source=None,
                  note_text="", modifier=None):
     event = Event()
     event.set_description(description)
     note = Note()
     note.handle = create_id()
     note.type.set(NoteType.EVENT)
     note.set(note_text)
     self.db.add_note(note, self.trans)
     event.add_note(note.handle)
     if type:
         event.set_type(EventType(type))
     if date:
         if modifier:
             date.set_modifier(modifier)
         date.set_quality(Date.QUAL_ESTIMATED)
         date.set_yr_mon_day(date.get_year(), 0, 0)
         event.set_date_object(date)
     if source:
         citation = Citation()
         citation.set_reference_handle(source.get_handle())
         self.db.add_citation(citation, self.trans)
         event.add_citation(citation.get_handle())
         self.db.commit_source(source, self.trans)
     self.db.add_event(event, self.trans)
     return event
コード例 #2
0
    def instance_from_struct(cls, struct):
        """
        Given a struct with metadata, create a Gramps object.

        self is class when called as a classmethod.
        """
        from gramps.gen.lib import (Person, Family, Event, Source, Place,
                                    Citation, Repository, Media, Note, Tag,
                                    Date)
        if isinstance(struct, dict):
            if "_class" in struct.keys():
                if struct["_class"] == "Person":
                    return Person.create(Person.from_struct(struct))
                elif struct["_class"] == "Family":
                    return Family.create(Family.from_struct(struct))
                elif struct["_class"] == "Event":
                    return Event.create(Event.from_struct(struct))
                elif struct["_class"] == "Source":
                    return Source.create(Source.from_struct(struct))
                elif struct["_class"] == "Place":
                    return Place.create(Place.from_struct(struct))
                elif struct["_class"] == "Citation":
                    return Citation.create(Citation.from_struct(struct))
                elif struct["_class"] == "Repository":
                    return Repository.create(Repository.from_struct(struct))
                elif struct["_class"] == "Media":
                    return Media.create(Media.from_struct(struct))
                elif struct["_class"] == "Note":
                    return Note.create(Note.from_struct(struct))
                elif struct["_class"] == "Tag":
                    return Tag.create(Tag.from_struct(struct))
                elif struct["_class"] == "Date":
                    return Date().unserialize(
                        Date.from_struct(struct, full=True))
        raise AttributeError("invalid struct: %s" % struct)
コード例 #3
0
    def __init__(self, dbstate, uistate, clicked):
        self.clicked_func = clicked
        self.filter_id = widgets.BasicEntry()
        self.filter_text = widgets.BasicEntry()
        self.note = Note()
        self.note.set_type((NoteType.CUSTOM, ''))
        self.ntype = Gtk.ComboBox(has_entry=True)
        if dbstate.is_open():
            self.custom_types = dbstate.db.get_note_types()
        else:
            self.custom_types = []

        self.event_menu = widgets.MonitoredDataType(
            self.ntype,
            self.note.set_type,
            self.note.get_type,
            False,  # read-only?
            self.custom_types)

        self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))

        self.tag = Gtk.ComboBox()
        self.generic = Gtk.ComboBox()

        SidebarFilter.__init__(self, dbstate, uistate, "Note")
コード例 #4
0
ファイル: notes.py プロジェクト: zackJKnight/gramps-webapi
 def object_extend(self,
                   obj: Note,
                   args: Dict,
                   locale: GrampsLocale = glocale) -> Note:
     """Extend note attributes as needed."""
     if "formats" in args:
         formats_allowed = [
             fmt.lower() for fmt in args["formats"]
             if fmt.lower() in set(self.FORMATS_SUPPORTED)
         ]
         if args.get("format_options"):
             try:
                 format_options = json.loads(args["format_options"])
             except json.JSONDecodeError:
                 abort(400)
         else:
             format_options = None
         obj.formatted = {
             fmt: self.get_formatted_note(note=obj,
                                          fmt=fmt,
                                          options=format_options)
             for fmt in formats_allowed
         }
     if "extend" in args:
         obj.extended = get_extended_attributes(self.db_handle, obj, args)
     return obj
コード例 #5
0
 def create_event(self, description=_("Estimated date"),
                  type=None, date=None, source=None,
                  note_text="", modifier=None):
     event = Event()
     event.set_description(description)
     note = Note()
     note.handle = create_id()
     note.type.set(NoteType.EVENT)
     note.set(note_text)
     self.db.add_note(note, self.trans)
     event.add_note(note.handle)
     if type:
         event.set_type(EventType(type))
     if date:
         if modifier:
             date.set_modifier(modifier)
         date.set_quality(Date.QUAL_ESTIMATED)
         date.set_yr_mon_day(date.get_year(), 0, 0)
         event.set_date_object(date)
     if source:
         citation = Citation()
         citation.set_reference_handle(source.get_handle())
         self.db.add_citation(citation, self.trans)
         event.add_citation(citation.get_handle())
         self.db.commit_source(source, self.trans)
     self.db.add_event(event, self.trans)
     return event
コード例 #6
0
    def addNewNote(self, notecontent):
        with DbTxn(_("Add New Note"), self.db) as ntrans:
            new_note = Note(notecontent)
            new_note.set_type(NoteType.RESEARCH)
            note_handle = self.db.add_note(new_note, ntrans)
#            self.db.commit_note(new_note, ntrans)
            return note_handle
コード例 #7
0
ファイル: struct.py プロジェクト: belissent/gramps
    def instance_from_struct(cls, struct):
        """
        Given a struct with metadata, create a Gramps object.

        self is class when called as a classmethod.
        """
        from  gramps.gen.lib import (Person, Family, Event, Source, Place, Citation,
                                     Repository, Media, Note, Tag, Date)
        if isinstance(struct, dict):
            if "_class" in struct.keys():
                if struct["_class"] == "Person":
                    return Person.create(Person.from_struct(struct))
                elif struct["_class"] == "Family":
                    return Family.create(Family.from_struct(struct))
                elif struct["_class"] == "Event":
                    return Event.create(Event.from_struct(struct))
                elif struct["_class"] == "Source":
                    return Source.create(Source.from_struct(struct))
                elif struct["_class"] == "Place":
                    return Place.create(Place.from_struct(struct))
                elif struct["_class"] == "Citation":
                    return Citation.create(Citation.from_struct(struct))
                elif struct["_class"] == "Repository":
                    return Repository.create(Repository.from_struct(struct))
                elif struct["_class"] == "Media":
                    return Media.create(Media.from_struct(struct))
                elif struct["_class"] == "Note":
                    return Note.create(Note.from_struct(struct))
                elif struct["_class"] == "Tag":
                    return Tag.create(Tag.from_struct(struct))
                elif struct["_class"] == "Date":
                    return Date().unserialize(Date.from_struct(struct, full=True))
        raise AttributeError("invalid struct: %s" % struct)
コード例 #8
0
 def addNoteToName(self, notecontent, aPerson, aName):
     with DbTxn(_("Add Note To Object"), self.db) as trans:
         new_note = Note(notecontent)
         new_note.set_type(NoteType.RESEARCH)
         note_handle = self.db.add_note(new_note, trans)
         aName.add_note(note_handle)
         self.db.commit_note(aName, trans)
コード例 #9
0
ファイル: diff.py プロジェクト: cicl06/gramps
def from_struct(struct):
    """
    Given a struct with metadata, create a Gramps object.
    """
    from gramps.gen.lib import (Person, Family, Event, Source, Place, Citation,
                                Repository, MediaObject, Note, Tag)
    if isinstance(struct, dict):
        if "_class" in struct.keys():
            if struct["_class"] == "Person":
                return Person.create(Person.from_struct(struct))
            elif struct["_class"] == "Family":
                return Family.create(Family.from_struct(struct))
            elif struct["_class"] == "Event":
                return Event.create(Event.from_struct(struct))
            elif struct["_class"] == "Source":
                return Source.create(Source.from_struct(struct))
            elif struct["_class"] == "Place":
                return Place.create(Place.from_struct(struct))
            elif struct["_class"] == "Citation":
                return Citation.create(Citation.from_struct(struct))
            elif struct["_class"] == "Repository":
                return Repository.create(Repository.from_struct(struct))
            elif struct["_class"] == "MediaObject":
                return MediaObject.create(MediaObject.from_struct(struct))
            elif struct["_class"] == "Note":
                return Note.create(Note.from_struct(struct))
            elif struct["_class"] == "Tag":
                return Tag.create(Tag.from_struct(struct))
    raise AttributeError("invalid struct: %s" % struct)
コード例 #10
0
ファイル: diff.py プロジェクト: cicl06/gramps
def from_struct(struct):
    """
    Given a struct with metadata, create a Gramps object.
    """
    from  gramps.gen.lib import (Person, Family, Event, Source, Place, Citation,
                                 Repository, MediaObject, Note, Tag)
    if isinstance(struct, dict):
        if "_class" in struct.keys():
            if struct["_class"] == "Person":
                return Person.create(Person.from_struct(struct))
            elif struct["_class"] == "Family":
                return Family.create(Family.from_struct(struct))
            elif struct["_class"] == "Event":
                return Event.create(Event.from_struct(struct))
            elif struct["_class"] == "Source":
                return Source.create(Source.from_struct(struct))
            elif struct["_class"] == "Place":
                return Place.create(Place.from_struct(struct))
            elif struct["_class"] == "Citation":
                return Citation.create(Citation.from_struct(struct))
            elif struct["_class"] == "Repository":
                return Repository.create(Repository.from_struct(struct))
            elif struct["_class"] == "MediaObject":
                return MediaObject.create(MediaObject.from_struct(struct))
            elif struct["_class"] == "Note":
                return Note.create(Note.from_struct(struct))
            elif struct["_class"] == "Tag":
                return Tag.create(Tag.from_struct(struct))
    raise AttributeError("invalid struct: %s" % struct)
コード例 #11
0
 def addNoteToPerson(self, type, notecontent, aPerson):
     with DbTxn(_("Add Note To Object"), self.db) as trans:
         new_note = Note(notecontent)
         new_note.set_type(type)
         note_handle = self.db.add_note(new_note, trans)
         aPerson.add_note(note_handle)
         self.db.commit_person(aPerson, trans)
         return   
コード例 #12
0
ファイル: html.py プロジェクト: gramps-project/gramps-webapi
def get_note_html(note: Note, link_format: Optional[str] = None) -> str:
    """Return a note text as sanitized HTML."""
    html_note_text = styledtext_to_html(
        styledtext=note.get_styledtext(),
        space_format=note.get_format(),
        contains_html=(note.get_type() == NoteType.HTML_CODE),
        link_format=link_format,
    )
    return sanitize(html_note_text)
コード例 #13
0
ファイル: importgeneweb.py プロジェクト: ewongbb/gramps
 def read_family_comment(self,line,fields):
     if not self.current_family:
         LOG.warning("Unknown family of child in line %d!" % self.lineno)
         return None
     n = Note()
     n.set(line)
     self.db.add_note(n,self.trans)
     self.current_family.add_note(n.handle)
     self.db.commit_family(self.current_family,self.trans)
     return None
コード例 #14
0
ファイル: editnote.py プロジェクト: shubhtr/gramps
    def empty_object(self):
        """Return an empty Note object for comparison for changes.

        It is used by the base class L{EditPrimary}.

        """
        empty_note = Note();
        if self.extratype:
            empty_note.set_type(self.extratype[0])
        return empty_note
コード例 #15
0
ファイル: editnote.py プロジェクト: fobrice/gramps
    def empty_object(self):
        """Return an empty Note object for comparison for changes.

        It is used by the base class L{EditPrimary}.

        """
        empty_note = Note();
        if self.extratype:
            empty_note.set_type(self.extratype[0])
        return empty_note
コード例 #16
0
 def read_family_comment(self, line, fields):
     if not self.current_family:
         LOG.warning("Unknown family of child in line %d!" % self.lineno)
         return None
     n = Note()
     n.set(line)
     self.db.add_note(n, self.trans)
     self.current_family.add_note(n.handle)
     self.db.commit_family(self.current_family, self.trans)
     return None
コード例 #17
0
ファイル: todogramplet.py プロジェクト: oluul/gramps
 def new_clicked(self, obj):
     """
     Create a new To Do note.
     """
     from gramps.gui.editors import EditNote
     note = Note()
     note.set_type(NoteType.TODO)
     try:
         EditNote(self.gui.dbstate, self.gui.uistate, [], note)
     except AttributeError:
         pass
コード例 #18
0
 def create_note(self, place, data, trans):
     new_note = Note()
     tag = StyledTextTag(StyledTextTagType.FONTFACE, 'Monospace',
                         [(0, len(data))])
     text = StyledText(data, [tag])
     new_note.set_styledtext(text)
     note_type = NoteType()
     note_type.set((NoteType.CUSTOM, _("Place titles")))
     new_note.set_type(note_type)
     handle = self.db.add_note(new_note, trans)
     place.add_note(handle)
コード例 #19
0
ファイル: todogramplet.py プロジェクト: SNoiraud/gramps
 def new_clicked(self, obj):
     """
     Create a new To Do note.
     """
     from gramps.gui.editors import EditNote
     note = Note()
     note.set_type(NoteType.TODO)
     try:
         EditNote(self.gui.dbstate, self.gui.uistate, [], note)
     except AttributeError:
         pass
コード例 #20
0
 def add_note(self, gid, text, trans):
     new_note = self.db.get_note_from_gramps_id(gid)
     if new_note:
         new_note.set(text)
         self.db.commit_note(new_note, trans)
         msg = _("Add Test Note")
     else:
         new_note = Note(text)
         new_note.set_gramps_id(gid)
         self.db.add_note(new_note, trans)
         msg = _("Add Test Note")
     trans.set_description(msg)
コード例 #21
0
ファイル: objectentries.py プロジェクト: goetzk/gramps
 def call_editor(self, obj=None):
     if obj is None:
         note = Note()
         note.set_type(self.get_notetype())
         func = self.obj_added
     else:
         note = obj
         func = self.after_edit
     try:
         EditNote(self.dbstate, self.uistate, self.track, note, func)
     except WindowActiveError:
         pass
コード例 #22
0
 def add_note(self, gid, text, trans):
     new_note = self.db.get_note_from_gramps_id(gid)
     if new_note:
         new_note.set(text)
         self.db.commit_note(new_note, trans)
         msg = _("Add Test Note")
     else:
         new_note = Note(text)
         new_note.set_gramps_id(gid)
         self.db.add_note(new_note, trans)
         msg = _("Add Test Note")
     trans.set_description(msg)
コード例 #23
0
 def addNote(ntext, ntype):
     nidno = db.find_next_note_gramps_id()
     note = Note(ntext)
     note.set_gramps_id(nidno)
     note.set_type(ntype)
     if reftag != None:
         note.add_tag(reftag.get_handle())
     note.set_change_time(chgtime)
     with DbTxn(_("Add Note"), db) as trans:
         nhandle = db.add_note(note, trans)
         LOG.debug('Note added: ' + ntext + ' ' + nhandle)
     return note
コード例 #24
0
ファイル: objectentries.py プロジェクト: SNoiraud/gramps
 def call_editor(self, obj=None):
     if obj is None:
         note = Note()
         note.set_type(self.get_notetype())
         func = self.obj_added
     else:
         note = obj
         func = self.after_edit
     try:
         EditNote(self.dbstate, self.uistate, self.track,
                      note, func)
     except WindowActiveError:
         pass
コード例 #25
0
 def __apply(self, obj):
     with DbTxn(_("Processing events"), self.dbstate.db) as self.trans:
         selected_handles = self.uistate.viewmanager.active_page.selected_handles(
         )
         num_events = len(selected_handles)
         for handle in selected_handles:
             event = self.dbstate.db.get_event_from_handle(handle)
             text = self.note.get_text()
             note = Note()
             note.set(text)
             notehandle = self.dbstate.db.add_note(note, self.trans)
             event.add_note(notehandle)
             self.dbstate.db.commit_event(event, self.trans)
コード例 #26
0
    def read_pevent_line(self, event, fields):

        name = fields[2] + fields[1]

        try:
            self.person = self.ikeys[name]
        # check key on {ikey}
        except:
            self.person = "(TO_CHECK: %s)" % fields[1:]
            #GrampsImportError()

        lastname = fields[1]
        firstname = fields[2]
        self.current_person = self.get_or_create_person(firstname, lastname)

        #name = Name()
        #name.set_type(NameType(NameType.BIRTH))
        #name.set_first_name(firstname)
        #surname_obj = name.get_primary_surname()
        #surname_obj.set_surname(surname)
        #self.current_person.set_primary_name(name)

        if pevents_map.get(event[0:5]) == None:
            return  #need to fix custom event types not in the map

        self.current_event = None
        # get events for the current person
        for evr in self.current_person.get_event_ref_list():
            ev = self.db.get_event_from_handle(evr.get_reference_handle())
            if ev.get_type() == pevents_map.get(event[0:5]):
                self.current_event = ev  # found. Need to also check EventRef role
            if not self.current_event:  # No event found create a new one
                self.current_event = self.new_gwplus_pevent(event)
        while True:
            line = self.get_next_line()
            if line and line[0:5] in pevents_map:
                self.current_mode = "person_event"
                self.current_event = self.new_gwplus_pevent(line)
            elif line and line[0:4] == "note":
                n = Note()
                n.set(line[5:])
                self.db.add_note(n, self.trans)
                if self.current_event:
                    self.current_event.add_note(n.handle)
                    self.db.commit_event(self.current_event, self.trans)
                else:
                    print('note', n.handle)
            else:
                self.current_mode = None
                #self.db.commit_person(self.current_person,self.trans)
                break
コード例 #27
0
ファイル: importgeneweb.py プロジェクト: ewongbb/gramps
    def read_pevent_line(self, event, fields):

        name = fields[2] + fields[1]

        try:
            self.person = self.ikeys[name]
        # check key on {ikey}
        except:
            self.person = "(TO_CHECK: %s)" % fields[1:]
            #GrampsImportError()

        lastname = fields[1]
        firstname = fields[2]
        self.current_person = self.get_or_create_person(firstname, lastname)

        #name = Name()
        #name.set_type(NameType(NameType.BIRTH))
        #name.set_first_name(firstname)
        #surname_obj = name.get_primary_surname()
        #surname_obj.set_surname(surname)
        #self.current_person.set_primary_name(name)

        if pevents_map.get(event[0:5]) == None:
            return #need to fix custom event types not in the map

        self.current_event = None
        # get events for the current person
        for evr in self.current_person.get_event_ref_list():
            ev = self.db.get_event_from_handle(evr.get_reference_handle())
            if ev.get_type() == pevents_map.get(event[0:5]):
                self.current_event = ev # found. Need to also check EventRef role
            if not self.current_event: # No event found create a new one
                self.current_event = self.new_gwplus_pevent(event)
        while True:
            line = self.get_next_line()
            if line and line[0:5] in pevents_map:
                self.current_mode = "person_event"
                self.current_event = self.new_gwplus_pevent(line)
            elif line and line[0:4] == "note":
                n = Note()
                n.set(line[5:])
                self.db.add_note(n, self.trans)
                if self.current_event:
                    self.current_event.add_note(n.handle)
                    self.db.commit_event(self.current_event, self.trans)
                else:
                    print('note', n.handle)
            else:
                self.current_mode = None
                #self.db.commit_person(self.current_person,self.trans)
                break
コード例 #28
0
 def main(self):  # return false finishes
     if self._dirty:
         return
     self.active_person_edit.hide()
     self.active_family_edit.hide()
     self.active_family_label.hide()
     self.note_buffer.set_text(StyledText())
     active_person = self.get_active_object("Person")
     self._dirty_person = active_person
     self._dirty_family = None
     if active_person:
         self.active_person_edit.show()
         self.active_family_edit.hide()
         self.active_family_label.hide()
         # Fill in current person edits:
         name = name_displayer.display(active_person)
         self.active_person_widget.set_text("<i>%s</i> " % name)
         self.active_person_widget.set_use_markup(True)
         # Note:
         self.note = None
         note_list = active_person.get_referenced_note_handles()
         for (classname, note_handle) in note_list:
             note_obj = self.dbstate.db.get_note_from_handle(note_handle)
             if note_obj.get_type() == _("Person Note"):
                 self.note = note_obj
                 break
         if self.note is None:
             self.note = Note()
         self.texteditor.set_text(self.note.get_styledtext())
         self.flow_changed(self.note.get_format())
         # Family button:
         family_list = active_person.get_family_handle_list()
         if len(family_list) > 0:
             self._dirty_family = self.dbstate.db.get_family_from_handle(
                 family_list[0])
             self.active_family_edit.show()
             self.active_family_label.show()
         else:
             family_list = active_person.get_parent_family_handle_list()
             if len(family_list) > 0:
                 self._dirty_family = self.dbstate.db.get_family_from_handle(
                     family_list[0])
                 self.active_family_edit.show()
                 self.active_family_label.show()
     else:
         self.clear_data_entry(None)
         self.active_person_edit.hide()
         self.active_family_edit.hide()
         self.active_family_label.hide()
     self._dirty = False
コード例 #29
0
ファイル: _notesidebarfilter.py プロジェクト: SNoiraud/gramps
    def __init__(self, dbstate, uistate, clicked):
        self.clicked_func = clicked
        self.filter_id = widgets.BasicEntry()
        self.filter_text = widgets.BasicEntry()
        self.note = Note()
        self.note.set_type((NoteType.CUSTOM,''))
        self.ntype = Gtk.ComboBox(has_entry=True)
        if dbstate.is_open():
            self.custom_types = dbstate.db.get_note_types()
        else:
            self.custom_types = []

        self.event_menu = widgets.MonitoredDataType(
            self.ntype,
            self.note.set_type,
            self.note.get_type,
            False, # read-only?
            self.custom_types)

        self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))

        self.tag = Gtk.ComboBox()
        self.generic = Gtk.ComboBox()

        SidebarFilter.__init__(self, dbstate, uistate, "Note")
コード例 #30
0
ファイル: JSONImport.py プロジェクト: sam-m888/addons-source
def importData(db, filename, user):
    """Function called by Gramps to import data on persons in CSV format."""
    db.disable_signals()
    try:
        with DbTxn(_("JSON import"), db, batch=True) as trans:
            with OpenFileOrStdin(filename, encoding="utf-8") as fp:
                line = fp.readline()
                while line:
                    data = json.loads(line)
                    if data["_class"] == "Person":
                        obj = Person.create(Person.from_struct(data))
                        db.add_person(obj, trans)
                    elif data["_class"] == "Family":
                        obj = Family.create(Family.from_struct(data))
                        db.add_family(obj, trans)
                    elif data["_class"] == "Event":
                        obj = Event.create(Event.from_struct(data))
                        db.add_event(obj, trans)
                    elif data["_class"] == "Media":
                        obj = Media.create(Media.from_struct(data))
                        db.add_media(obj, trans)
                    elif data["_class"] == "Repository":
                        obj = Repository.create(Repository.from_struct(data))
                        db.add_repository(obj, trans)
                    elif data["_class"] == "Tag":
                        obj = Tag.create(Tag.from_struct(data))
                        db.add_tag(obj, trans)
                    elif data["_class"] == "Source":
                        obj = Source.create(Source.from_struct(data))
                        db.add_source(obj, trans)
                    elif data["_class"] == "Citation":
                        obj = Citation.create(Citation.from_struct(data))
                        db.add_citation(obj, trans)
                    elif data["_class"] == "Note":
                        obj = Note.create(Note.from_struct(data))
                        db.add_note(obj, trans)
                    elif data["_class"] == "Place":
                        obj = Place.create(Place.from_struct(data))
                        db.add_place(obj, trans)
                    else:
                        LOG.warn("ignored: " + data)
                    line = fp.readline()
    except EnvironmentError as err:
        user.notify_error(_("%s could not be opened\n") % filename, str(err))

    db.enable_signals()
    db.request_rebuild()
コード例 #31
0
 def addnote(self, place, notetext, trans, trace):
     "Find a note starting with self.tag (Types:) or create a new and add it to the place"
     for notehandle in place.get_note_list():
         note = self.db.get_note_from_handle(notehandle)
         old_notetext = note.get()
         if old_notetext.startswith(self.tag):
             if trace: print("found old note")
             note.set(notetext)
             self.db.commit_note(note, trans)
             return note
     if trace: print("create a new note")
     note = Note()
     note.set(notetext)
     note_handle = self.db.add_note(note, trans)
     place.add_note(note_handle)
     self.db.commit_note(note, trans)
     return note
コード例 #32
0
ファイル: notetab.py プロジェクト: tester0077/gramps
    def add_button_clicked(self, obj):
        """
        Create a new Note instance and call the EditNote editor with the new
        note.

        Called when the Add button is clicked.
        If the window already exists (WindowActiveError), we ignore it.
        This prevents the dialog from coming up twice on the same object.
        """
        note = Note()
        if self.notetype :
            note.set_type(self.notetype)
        try:
            from .. import EditNote
            EditNote(self.dbstate, self.uistate, self.track,
                            note, self.add_callback,
                            self.callertitle, extratype = [self.notetype])
        except WindowActiveError:
            pass
コード例 #33
0
ファイル: todo.py プロジェクト: SNoiraud/gramps
 def new_clicked(self, obj):
     """
     Create a new To Do note.
     """
     nav_type = self.uistate.viewmanager.active_page.navigation_type()
     active_handle = self.get_active(nav_type)
     if active_handle:
         from gramps.gui.editors import EditNote
         note = Note()
         note.set_type(NoteType.TODO)
         try:
             EditNote(self.gui.dbstate, self.gui.uistate, [], note, self.created)
         except WindowActiveError:
             pass
     else:
         WarningDialog(_("No active object"),
             _("First select the object to which you want to attach a note")
                 + _(":") + _(nav_type),
             parent=self.uistate.window)
コード例 #34
0
 def new_clicked(self, obj):
     """
     Create a new To Do note.
     """
     nav_type = self.uistate.viewmanager.active_page.navigation_type()
     active_handle = self.get_active(nav_type)
     if active_handle:
         from gramps.gui.editors import EditNote
         note = Note()
         note.set_type(NoteType.TODO)
         try:
             EditNote(self.gui.dbstate, self.gui.uistate, [], note,
                      self.created)
         except WindowActiveError:
             pass
     else:
         WarningDialog(
             _("No active object"),
             _("First select the object to which you want to attach a note")
             + _(":") + _(nav_type),
             parent=self.uistate.window)
コード例 #35
0
 def post(self, path):
     if "/" in path:
         handle, action = path.split("/")
     else:
         handle, action = path, "view"
     if handle == "add":
         note = Note()
         note.handle = handle = create_id()
     else:
         note = self.database.get_note_from_handle(handle)
     form = NoteForm(self.database, _, instance=note)
     form.save(handler=self)
     self.redirect("/note/%(handle)s" % {"handle": handle})
コード例 #36
0
ファイル: importgeneweb.py プロジェクト: ewongbb/gramps
    def _read_notes_lines(self, note_tag):
        note_txt = ""
        while True:
            line = self.get_next_line()
            if line is None:
                break

            fields = line.split(" ")
            if fields[0] == "end" and fields[1] == note_tag:
                break
            elif fields[0] == "beg":
                continue
            else:
                if note_txt:
                    note_txt = note_txt + "\n" + line
                else:
                    note_txt = note_txt + line
        if note_txt:
            n = Note()
            n.set(note_txt)
            self.db.add_note(n,self.trans)
            return n.handle
        return None
コード例 #37
0
    def _read_notes_lines(self, note_tag):
        note_txt = ""
        while True:
            line = self.get_next_line()
            if line is None:
                break

            fields = line.split(" ")
            if fields[0] == "end" and fields[1] == note_tag:
                break
            elif fields[0] == "beg":
                continue
            else:
                if note_txt:
                    note_txt = note_txt + "\n" + line
                else:
                    note_txt = note_txt + line
        if note_txt:
            n = Note()
            n.set(note_txt)
            self.db.add_note(n, self.trans)
            return n.handle
        return None
コード例 #38
0
    def add_button_clicked(self, obj):
        """
        Create a new Note instance and call the EditNote editor with the new
        note.

        Called when the Add button is clicked.
        If the window already exists (WindowActiveError), we ignore it.
        This prevents the dialog from coming up twice on the same object.
        """
        note = Note()
        if self.notetype:
            note.set_type(self.notetype)
        try:
            from .. import EditNote
            EditNote(self.dbstate,
                     self.uistate,
                     self.track,
                     note,
                     self.add_callback,
                     self.callertitle,
                     extratype=[self.notetype])
        except WindowActiveError:
            pass
コード例 #39
0
    def find_or_make_source(self):
        """ Find or create a source.
        returns handle to source."""
        for hndl in self.dbstate.db.get_source_handles():
            if self.dbstate.db.get_raw_source_data(hndl)[2] == 'GeoNames':
                return hndl
        # No source found, lets add one with associated repo and note
        repo = Repository()
        repo.set_name("www.geonames.org")
        rtype = RepositoryType(RepositoryType.WEBSITE)
        repo.set_type(rtype)
        url = Url()
        url.set_path('http://www.geonames.org/')
        url.set_description(_('GeoNames web site'))
        url.set_type(UrlType(UrlType.WEB_HOME))
        repo.add_url(url)
        url = Url()
        url.set_path('*****@*****.**')
        url.set_description(_('GeoNames author'))
        url.set_type(UrlType(UrlType.EMAIL))
        repo.add_url(url)

        note_txt = StyledText(
            _('GeoNames was founded by Marc Wick. You can reach him at '))
        note_txt += StyledText('*****@*****.**' + '\n')
        note_txt += StyledText(
            _('GeoNames is a project of Unxos GmbH, Weingartenstrasse 8,'
              ' 8708 Männedorf, Switzerland.\nThis work is licensed under a '))
        note_txt += linkst(
            _('Creative Commons Attribution 3.0 License'),
            'https://creativecommons.org/licenses/by/3.0/legalcode')

        new_note = Note()
        new_note.set_styledtext(note_txt)
        new_note.set_type(NoteType.REPO)
        src = Source()
        src.title = 'GeoNames'
        src.author = 'Marc Wick'
        repo_ref = RepoRef()
        mtype = SourceMediaType(SourceMediaType.ELECTRONIC)
        repo_ref.set_media_type(mtype)
        with DbTxn(
                _("Add Souce/Repo/Note (%s)") % "GeoNames",
                self.dbstate.db) as trans:

            self.dbstate.db.add_note(new_note, trans)
            repo.add_note(new_note.get_handle())
            self.dbstate.db.add_repository(repo, trans)
            repo_ref.set_reference_handle(repo.handle)
            src.add_repo_reference(repo_ref)
            self.dbstate.db.add_source(src, trans)
        return src.handle
コード例 #40
0
ファイル: NoteGramplet.py プロジェクト: vantu5z/addons-source
 def main(self): # return false finishes
     if self._dirty:
         return
     self.active_person_edit.hide()
     self.active_family_edit.hide()
     self.active_family_label.hide()
     self.note_buffer.set_text(StyledText())
     active_person = self.get_active_object("Person")
     self._dirty_person = active_person
     self._dirty_family = None
     if active_person:
         self.active_person_edit.show()
         self.active_family_edit.hide()
         self.active_family_label.hide()
         # Fill in current person edits:
         name = name_displayer.display(active_person)
         self.active_person_widget.set_text("<i>%s</i> " % name)
         self.active_person_widget.set_use_markup(True)
         # Note:
         self.note = None
         note_list = active_person.get_referenced_note_handles()
         for (classname, note_handle) in note_list:
             note_obj = self.dbstate.db.get_note_from_handle(note_handle)
             if note_obj.get_type() == _("Person Note"):
                 self.note = note_obj
                 break
         if self.note is None:
             self.note = Note()
         self.texteditor.set_text(self.note.get_styledtext())
         self.flow_changed(self.note.get_format())
         # Family button:
         family_list = active_person.get_family_handle_list()
         if len(family_list) > 0:
             self._dirty_family = self.dbstate.db.get_family_from_handle(family_list[0])
             self.active_family_edit.show()
             self.active_family_label.show()
         else:
             family_list = active_person.get_parent_family_handle_list()
             if len(family_list) > 0:
                 self._dirty_family = self.dbstate.db.get_family_from_handle(family_list[0])
                 self.active_family_edit.show()
                 self.active_family_label.show()
     else:
         self.clear_data_entry(None)
         self.active_person_edit.hide()
         self.active_family_edit.hide()
         self.active_family_label.hide()
     self._dirty = False
コード例 #41
0
 def create_note(self, place, data, trans):
     new_note = Note()
     tag = StyledTextTag(StyledTextTagType.FONTFACE, 'Monospace',
                         [(0, len(data))])
     text = StyledText(data, [tag])
     new_note.set_styledtext(text)
     note_type = NoteType()
     note_type.set((NoteType.CUSTOM, _("Place titles")))
     new_note.set_type(note_type)
     handle = self.db.add_note(new_note, trans)
     place.add_note(handle)
コード例 #42
0
 def get(self, path=""):
     """
     HANDLE
     HANDLE/edit|delete
     /add
     b2cfa6ca1e174b1f63d/remove/eventref/1
     """
     page = int(self.get_argument("page", 1))
     search = self.get_argument("search", "")
     if "/" in path:
         handle, action = path.split("/", 1)
     else:
         handle, action = path, "view"
     if handle:
         if handle == "add":
             note = Note()
             action = "edit"
         else:
             note = self.database.get_note_from_handle(handle)
         if note:
             self.render(
                 "note.html",
                 **self.get_template_dict(tview=_("note detail"),
                                          action=action,
                                          page=page,
                                          search=search,
                                          form=NoteForm(self.database,
                                                        _,
                                                        instance=note),
                                          logform=None))
             return
         else:
             self.clear()
             self.set_status(404)
             self.finish("<html><body>No such note</body></html>")
             return
     self.render(
         "page_view.html",
         **self.get_template_dict(
             tview=_("note view"),
             page=page,
             search=search,
             form=NoteForm(self.database, _, table="Note"),
         ))
コード例 #43
0
    def find_or_make_source(self):
        """ Find or create a source.
        returns handle to source."""
        for hndl in self.dbstate.db.get_source_handles():
            if self.dbstate.db.get_raw_source_data(hndl)[2] == 'GeoNames':
                return hndl
        # No source found, lets add one with associated repo and note
        repo = Repository()
        repo.set_name("www.geonames.org")
        rtype = RepositoryType(RepositoryType.WEBSITE)
        repo.set_type(rtype)
        url = Url()
        url.set_path('http://www.geonames.org/')
        url.set_description(_('GeoNames web site'))
        url.set_type(UrlType(UrlType.WEB_HOME))
        repo.add_url(url)
        url = Url()
        url.set_path('*****@*****.**')
        url.set_description(_('GeoNames author'))
        url.set_type(UrlType(UrlType.EMAIL))
        repo.add_url(url)

        note_txt = StyledText(_(
            'GeoNames was founded by Marc Wick. You can reach him at '))
        note_txt += StyledText('*****@*****.**' + '\n')
        note_txt += StyledText(_(
            'GeoNames is a project of Unxos GmbH, Weingartenstrasse 8,'
            ' 8708 Männedorf, Switzerland.\nThis work is licensed under a '))
        note_txt += linkst(
            _('Creative Commons Attribution 3.0 License'),
            'https://creativecommons.org/licenses/by/3.0/legalcode')

        new_note = Note()
        new_note.set_styledtext(note_txt)
        new_note.set_type(NoteType.REPO)
        src = Source()
        src.title = 'GeoNames'
        src.author = 'Marc Wick'
        repo_ref = RepoRef()
        mtype = SourceMediaType(SourceMediaType.ELECTRONIC)
        repo_ref.set_media_type(mtype)
        with DbTxn(_("Add Souce/Repo/Note (%s)") % "GeoNames",
                   self.dbstate.db) as trans:

            self.dbstate.db.add_note(new_note, trans)
            repo.add_note(new_note.get_handle())
            self.dbstate.db.add_repository(repo, trans)
            repo_ref.set_reference_handle(repo.handle)
            src.add_repo_reference(repo_ref)
            self.dbstate.db.add_source(src, trans)
        return src.handle
コード例 #44
0
class NoteGramplet(Gramplet):
    """
    Gramplet that gives simplified interface to a Person's primary note.
    """
    def init(self):
        rows = Gtk.VBox()
        self._dirty = False
        self._dirty_person = None

        # Active person: Name
        row = Gtk.HBox()
        label = Gtk.Label()
        label.set_text("<b>%s</b>: " % _("Active person"))
        label.set_use_markup(True)
        label.set_alignment(0.0, 0.5)
        row.pack_start(label, False, False, 0)

        apw = Gtk.Label()
        self.active_person_widget = apw
        apw.set_alignment(0.0, 0.5)
        apw.set_use_markup(True)
        row.pack_start(apw, False, False, 0)

        # Add edit for person and family
        icon = Gtk.STOCK_EDIT
        size = Gtk.IconSize.MENU
        button = Gtk.Button()
        image = Gtk.Image()
        image.set_from_stock(icon, size)
        button.add(image)
        button.set_relief(Gtk.ReliefStyle.NONE)
        button.connect("clicked", self.edit_person)
        self.active_person_edit = button
        row.pack_start(button, False, False, 0)

        label = Gtk.Label()
        label.set_text(" %s: " % _("Family"))
        self.active_family_label = label
        row.pack_start(label, False, False, 0)

        button = Gtk.Button()
        image = Gtk.Image()
        image.set_from_stock(icon, size)
        button.add(image)
        button.set_relief(Gtk.ReliefStyle.NONE)
        button.connect("clicked", self.edit_family)
        self.active_family_edit = button
        row.pack_start(button, False, False, 0)

        rows.pack_start(row, False, False, 0)

        row = self.build_interface()
        self.note_buffer = self.texteditor.textbuffer
        self.note_buffer.connect("changed", self.mark_dirty)
        rows.pack_start(row, True, True, 0)

        # Save and Abandon
        row = Gtk.HBox()
        button = Gtk.Button(_("Save"))
        button.connect("clicked", self.save_data_edit)
        row.pack_start(button, True, True, 0)
        button = Gtk.Button(_("Abandon"))
        button.connect("clicked", self.abandon_data_edit)
        row.pack_start(button, True, True, 0)
        rows.pack_start(row, False, False, 0)

        self.gui.get_container_widget().remove(self.gui.textview)
        self.gui.get_container_widget().add_with_viewport(rows)
        rows.show_all()
        self.clear_data_entry(None)

    def flow_changed(self, active):
        """
        Changes the wrap/font of text flow.
        """
        if active:
            # Set the text style to monospace
            self.texteditor.set_wrap_mode(Gtk.WrapMode.NONE)
            self.texteditor.modify_font(Pango.FontDescription("monospace"))
        else:
            # Set the text style to normal
            self.texteditor.set_wrap_mode(Gtk.WrapMode.WORD)
            self.texteditor.modify_font(Pango.FontDescription("normal"))

    def build_interface(self):
        """
        Based on src/Editors/_EditNote.py
        """
        vbox = Gtk.VBox()
        self.texteditor = StyledTextEditor()
        # create a formatting toolbar
        vbox.pack_start(self.texteditor.get_toolbar(), False, False, 0)
        vbox.pack_start(self.texteditor, True, True, 0)
        self.flow_changed(False)
        return vbox

    def main(self):  # return false finishes
        if self._dirty:
            return
        self.active_person_edit.hide()
        self.active_family_edit.hide()
        self.active_family_label.hide()
        self.note_buffer.set_text(StyledText())
        active_person = self.get_active_object("Person")
        self._dirty_person = active_person
        self._dirty_family = None
        if active_person:
            self.active_person_edit.show()
            self.active_family_edit.hide()
            self.active_family_label.hide()
            # Fill in current person edits:
            name = name_displayer.display(active_person)
            self.active_person_widget.set_text("<i>%s</i> " % name)
            self.active_person_widget.set_use_markup(True)
            # Note:
            self.note = None
            note_list = active_person.get_referenced_note_handles()
            for (classname, note_handle) in note_list:
                note_obj = self.dbstate.db.get_note_from_handle(note_handle)
                if note_obj.get_type() == _("Person Note"):
                    self.note = note_obj
                    break
            if self.note is None:
                self.note = Note()
            self.texteditor.set_text(self.note.get_styledtext())
            self.flow_changed(self.note.get_format())
            # Family button:
            family_list = active_person.get_family_handle_list()
            if len(family_list) > 0:
                self._dirty_family = self.dbstate.db.get_family_from_handle(
                    family_list[0])
                self.active_family_edit.show()
                self.active_family_label.show()
            else:
                family_list = active_person.get_parent_family_handle_list()
                if len(family_list) > 0:
                    self._dirty_family = self.dbstate.db.get_family_from_handle(
                        family_list[0])
                    self.active_family_edit.show()
                    self.active_family_label.show()
        else:
            self.clear_data_entry(None)
            self.active_person_edit.hide()
            self.active_family_edit.hide()
            self.active_family_label.hide()
        self._dirty = False

    def clear_data_entry(self, obj):
        self.note_buffer.set_text(StyledText())
        self.flow_changed(False)

    def db_changed(self):
        """
        If person or family changes, the relatives of active person might have
        changed
        """
        self._dirty = False
        self._dirty_person = None
        self.clear_data_entry(None)
        self.texteditor.set_editable(not self.dbstate.db.readonly)
        self.update()

    def active_changed(self, handle):
        self.update()

    def mark_dirty(self, obj):
        self._dirty = True

    def abandon_data_edit(self, obj):
        self._dirty = False
        self.update()

    def edit_callback(self, person):
        self._dirty = False
        self.update()

    def edit_person(self, obj):
        from gramps.gui.editors import EditPerson
        try:
            EditPerson(self.gui.dbstate,
                       self.gui.uistate, [],
                       self._dirty_person,
                       callback=self.edit_callback)
        except WindowActiveError:
            pass

    def edit_family(self, obj):
        from gramps.gui.editors import EditFamily
        try:
            EditFamily(self.gui.dbstate, self.gui.uistate, [],
                       self._dirty_family)
        except WindowActiveError:
            pass

    def save_data_edit(self, obj):
        if self._dirty:
            person = self._dirty_person
            text = self.texteditor.get_text()
            self.note.set_styledtext(text)
            with DbTxn(_("Save Note"), self.dbstate.db) as trans:
                if not self.note.get_handle():
                    self.note.set_type(_("Person Note"))
                    self.dbstate.db.add_note(self.note, trans)
                    person.add_note(self.note.get_handle())
                    self.dbstate.db.commit_person(person, trans)
                else:
                    if not self.note.get_gramps_id():
                        self.note.set_gramps_id(
                            self.dbstate.db.find_next_note_gramps_id())
                    self.dbstate.db.commit_note(self.note, trans)
        self._dirty = False
コード例 #45
0
ファイル: NoteGramplet.py プロジェクト: vantu5z/addons-source
class NoteGramplet(Gramplet):
    """
    Gramplet that gives simplified interface to a Person's primary note.
    """
    def init(self):
        rows = Gtk.VBox()
        self._dirty = False
        self._dirty_person = None

        # Active person: Name
        row = Gtk.HBox()
        label = Gtk.Label()
        label.set_text("<b>%s</b>: " % _("Active person"))
        label.set_use_markup(True)
        label.set_alignment(0.0, 0.5)
        row.pack_start(label, False, False, 0)

        apw = Gtk.Label()
        self.active_person_widget = apw
        apw.set_alignment(0.0, 0.5)
        apw.set_use_markup(True)
        row.pack_start(apw, False, False, 0)

        # Add edit for person and family
        icon = Gtk.STOCK_EDIT
        size = Gtk.IconSize.MENU
        button = Gtk.Button()
        image = Gtk.Image()
        image.set_from_stock(icon, size)
        button.add(image)
        button.set_relief(Gtk.ReliefStyle.NONE)
        button.connect("clicked", self.edit_person)
        self.active_person_edit = button
        row.pack_start(button, False, False, 0)

        label = Gtk.Label()
        label.set_text(" %s: " % _("Family"))
        self.active_family_label = label
        row.pack_start(label, False, False, 0)

        button = Gtk.Button()
        image = Gtk.Image()
        image.set_from_stock(icon, size)
        button.add(image)
        button.set_relief(Gtk.ReliefStyle.NONE)
        button.connect("clicked", self.edit_family)
        self.active_family_edit = button
        row.pack_start(button, False, False, 0)

        rows.pack_start(row, False, False, 0)

        row = self.build_interface()
        self.note_buffer = self.texteditor.textbuffer
        self.note_buffer.connect("changed", self.mark_dirty)
        rows.pack_start(row, True, True, 0)

        # Save and Abandon
        row = Gtk.HBox()
        button = Gtk.Button(_("Save"))
        button.connect("clicked", self.save_data_edit)
        row.pack_start(button, True, True, 0)
        button = Gtk.Button(_("Abandon"))
        button.connect("clicked", self.abandon_data_edit)
        row.pack_start(button, True, True, 0)
        rows.pack_start(row, False, False, 0)

        self.gui.get_container_widget().remove(self.gui.textview)
        self.gui.get_container_widget().add_with_viewport(rows)
        rows.show_all()
        self.clear_data_entry(None)

    def flow_changed(self, active):
        """
        Changes the wrap/font of text flow.
        """
        if active:
            # Set the text style to monospace
            self.texteditor.set_wrap_mode(Gtk.WrapMode.NONE)
            self.texteditor.modify_font(Pango.FontDescription("monospace"))
        else:
            # Set the text style to normal
            self.texteditor.set_wrap_mode(Gtk.WrapMode.WORD)
            self.texteditor.modify_font(Pango.FontDescription("normal"))

    def build_interface(self):
        """
        Based on src/Editors/_EditNote.py
        """
        vbox = Gtk.VBox()
        self.texteditor = StyledTextEditor()
        # create a formatting toolbar
        vbox.pack_start(self.texteditor.get_toolbar(),
                        False, False, 0)
        vbox.pack_start(self.texteditor, True, True, 0)
        self.flow_changed(False)
        return vbox

    def main(self): # return false finishes
        if self._dirty:
            return
        self.active_person_edit.hide()
        self.active_family_edit.hide()
        self.active_family_label.hide()
        self.note_buffer.set_text(StyledText())
        active_person = self.get_active_object("Person")
        self._dirty_person = active_person
        self._dirty_family = None
        if active_person:
            self.active_person_edit.show()
            self.active_family_edit.hide()
            self.active_family_label.hide()
            # Fill in current person edits:
            name = name_displayer.display(active_person)
            self.active_person_widget.set_text("<i>%s</i> " % name)
            self.active_person_widget.set_use_markup(True)
            # Note:
            self.note = None
            note_list = active_person.get_referenced_note_handles()
            for (classname, note_handle) in note_list:
                note_obj = self.dbstate.db.get_note_from_handle(note_handle)
                if note_obj.get_type() == _("Person Note"):
                    self.note = note_obj
                    break
            if self.note is None:
                self.note = Note()
            self.texteditor.set_text(self.note.get_styledtext())
            self.flow_changed(self.note.get_format())
            # Family button:
            family_list = active_person.get_family_handle_list()
            if len(family_list) > 0:
                self._dirty_family = self.dbstate.db.get_family_from_handle(family_list[0])
                self.active_family_edit.show()
                self.active_family_label.show()
            else:
                family_list = active_person.get_parent_family_handle_list()
                if len(family_list) > 0:
                    self._dirty_family = self.dbstate.db.get_family_from_handle(family_list[0])
                    self.active_family_edit.show()
                    self.active_family_label.show()
        else:
            self.clear_data_entry(None)
            self.active_person_edit.hide()
            self.active_family_edit.hide()
            self.active_family_label.hide()
        self._dirty = False

    def clear_data_entry(self, obj):
        self.note_buffer.set_text(StyledText())
        self.flow_changed(False)

    def db_changed(self):
        """
        If person or family changes, the relatives of active person might have
        changed
        """
        self.connect(self.dbstate.db, 'person-update', self.update)
        self.connect(self.dbstate.db, 'note-update', self.update)
        self._dirty = False
        self._dirty_person = None
        self.clear_data_entry(None)
        self.texteditor.set_editable(not self.dbstate.db.readonly)
        self.update()

    def active_changed(self, handle):
        self.update()

    def mark_dirty(self, obj):
        self._dirty = True

    def abandon_data_edit(self, obj):
        self._dirty = False
        self.update()

    def edit_callback(self, person):
        self._dirty = False
        self.update()

    def edit_person(self, obj):
        from gramps.gui.editors import EditPerson
        try:
            EditPerson(self.gui.dbstate,
                       self.gui.uistate, [],
                       self._dirty_person,
                       callback=self.edit_callback)
        except WindowActiveError:
            pass

    def edit_family(self, obj):
        from gramps.gui.editors import EditFamily
        try:
            EditFamily(self.gui.dbstate,
                       self.gui.uistate, [],
                       self._dirty_family)
        except WindowActiveError:
            pass

    def save_data_edit(self, obj):
        if self._dirty:
            person = self._dirty_person
            text = self.texteditor.get_text()
            self.note.set_styledtext(text)
            with DbTxn(_("Save Note"), self.dbstate.db) as trans:
                if not self.note.get_handle():
                    self.note.set_type(_("Person Note"))
                    self.dbstate.db.add_note(self.note, trans)
                    person.add_note(self.note.get_handle())
                    self.dbstate.db.commit_person(person, trans)
                else:
                    if not self.note.get_gramps_id():
                        self.note.set_gramps_id(self.dbstate.db.find_next_note_gramps_id())
                    self.dbstate.db.commit_note(self.note, trans)
        self._dirty = False
コード例 #46
0
ファイル: importcsv.py プロジェクト: tecknicaltom/gramps
 def _parse_marriage(self, line_number, row, col):
     "Parse the content of a Marriage,Husband,Wife line."
     marriage_ref   = rd(line_number, row, col, "marriage")
     husband  = rd(line_number, row, col, "husband")
     wife     = rd(line_number, row, col, "wife")
     marriagedate = rd(line_number, row, col, "date")
     marriageplace = rd(line_number, row, col, "place")
     marriageplace_id = rd(line_number, row, col, "place_id")
     marriagesource = rd(line_number, row, col, "source")
     note = rd(line_number, row, col, "note")
     wife = self.lookup("person", wife)
     husband = self.lookup("person", husband)
     if husband is None and wife is None:
         # might have children, so go ahead and add
         LOG.warn("no parents on line %d; adding family anyway" %
                  line_number)
     family = self.get_or_create_family(marriage_ref, husband, wife)
     # adjust gender, if not already provided
     if husband:
         # this is just a guess, if unknown
         if husband.get_gender() == Person.UNKNOWN:
             husband.set_gender(Person.MALE)
             self.db.commit_person(husband, self.trans)
     if wife:
         # this is just a guess, if unknown
         if wife.get_gender() == Person.UNKNOWN:
             wife.set_gender(Person.FEMALE)
             self.db.commit_person(wife, self.trans)
     if marriage_ref:
         self.storeup("family", marriage_ref.lower(), family)
     if marriagesource:
         # add, if new
         new, marriagesource = self.get_or_create_source(marriagesource)
     if marriageplace and marriageplace_id:
         raise Error("Error in marriage: can't have a place and place_id")
     if marriageplace:
         # add, if new
         new, marriageplace = self.get_or_create_place(marriageplace)
     elif marriageplace_id:
         # better exist already, locally or in database:
         marriageplace = self.lookup("place", marriageplace_id)
     if marriagedate:
         marriagedate = _dp.parse(marriagedate)
     if marriagedate or marriageplace or marriagesource or note:
         # add, if new; replace, if different
         new, marriage = self.get_or_create_event(family,
                 EventType.MARRIAGE, marriagedate,
                 marriageplace, marriagesource)
         if new:
             mar_ref = EventRef()
             mar_ref.set_reference_handle(marriage.get_handle())
             family.add_event_ref(mar_ref)
             self.db.commit_family(family, self.trans)
         # only add note to event:
         # append notes, if previous notes
         if note:
             previous_notes_list = marriage.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.EVENT:
                     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.EVENT)
                 new_note.set(note)
                 if self.default_tag:
                     new_note.add_tag(self.default_tag.handle)
                 self.db.add_note(new_note, self.trans)
                 marriage.add_note(new_note.handle)
             self.db.commit_event(marriage, self.trans)
コード例 #47
0
ファイル: importcsv.py プロジェクト: tecknicaltom/gramps
 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)
コード例 #48
0
ファイル: importcsv.py プロジェクト: tecknicaltom/gramps
 def _parse_person(self, line_number, row, col):
     "Parse the content of a Person line."
     surname   = rd(line_number, row, col, "surname")
     firstname = rd(line_number, row, col, "firstname", "")
     callname  = rd(line_number, row, col, "callname")
     title     = rd(line_number, row, col, "title")
     prefix    = rd(line_number, row, col, "prefix")
     suffix    = rd(line_number, row, col, "suffix")
     gender    = rd(line_number, row, col, "gender")
     source    = rd(line_number, row, col, "source")
     note      = rd(line_number, row, col, "note")
     birthplace  = rd(line_number, row, col, "birthplace")
     birthplace_id  = rd(line_number, row, col, "birthplace_id")
     birthdate   = rd(line_number, row, col, "birthdate")
     birthsource = rd(line_number, row, col, "birthsource")
     baptismplace  = rd(line_number, row, col, "baptismplace")
     baptismplace_id  = rd(line_number, row, col, "baptismplace_id")
     baptismdate   = rd(line_number, row, col, "baptismdate")
     baptismsource = rd(line_number, row, col, "baptismsource")
     burialplace  = rd(line_number, row, col, "burialplace")
     burialplace_id  = rd(line_number, row, col, "burialplace_id")
     burialdate   = rd(line_number, row, col, "burialdate")
     burialsource = rd(line_number, row, col, "burialsource")
     deathplace  = rd(line_number, row, col, "deathplace")
     deathplace_id  = rd(line_number, row, col, "deathplace_id")
     deathdate   = rd(line_number, row, col, "deathdate")
     deathsource = rd(line_number, row, col, "deathsource")
     deathcause  = rd(line_number, row, col, "deathcause")
     grampsid    = rd(line_number, row, col, "grampsid")
     person_ref  = rd(line_number, row, col, "person")
     #########################################################
     # if this person already exists, don't create them
     person = self.lookup("person", person_ref)
     if person is None:
         if surname is None:
             LOG.warn("empty surname for new person on line %d" %
                      line_number)
             surname = ""
         # new person
         person = self.create_person()
         name = Name()
         name.set_type(NameType(NameType.BIRTH))
         name.set_first_name(firstname)
         surname_obj = Surname()
         surname_obj.set_surname(surname)
         name.add_surname(surname_obj)
         person.set_primary_name(name)
     else:
         name = person.get_primary_name()
     #########################################################
     if person_ref is not None:
         self.storeup("person", person_ref, person)
     # replace
     if surname is not None:
         name.get_primary_surname().set_surname(surname)
     if firstname is not None:
         name.set_first_name(firstname)
     if callname is not None:
         name.set_call_name(callname)
     if title is not None:
         name.set_title(title)
     if prefix is not None:
         name.get_primary_surname().set_prefix(prefix)
         name.group_as = '' # HELP? what should I do here?
     if suffix is not None:
         name.set_suffix(suffix)
     if note is not None:
         # append notes, if previous notes
         previous_notes_list = person.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)
             person.add_note(new_note.handle)
     if grampsid is not None:
         person.gramps_id = grampsid
     elif person_ref is not None:
         if person_ref.startswith("[") and person_ref.endswith("]"):
             person.gramps_id = self.db.id2user_format(person_ref[1:-1])
     if (person.get_gender() == Person.UNKNOWN and
             gender is not None):
         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
         person.set_gender(gender)
     #########################################################
     # add if new, replace if different
     # Birth:
     if birthdate is not None:
         birthdate = _dp.parse(birthdate)
     if birthplace and birthplace_id:
         raise Error("Error in person: can't have a birthplace and birthplace_id")
     if birthplace is not None:
         new, birthplace = self.get_or_create_place(birthplace)
     elif birthplace_id:
         # better exist already, locally or in database:
         birthplace = self.lookup("place", birthplace_id)
     if birthsource is not None:
         new, birthsource = self.get_or_create_source(birthsource)
     if birthdate or birthplace or birthsource:
         new, birth = self.get_or_create_event(person,
              EventType.BIRTH, birthdate,
              birthplace, birthsource)
         birth_ref = person.get_birth_ref()
         if birth_ref is None:
             # new
             birth_ref = EventRef()
         birth_ref.set_reference_handle( birth.get_handle())
         person.set_birth_ref( birth_ref)
     # Baptism:
     if baptismdate is not None:
         baptismdate = _dp.parse(baptismdate)
     if baptismplace and baptismplace_id:
         raise Error("Error in person: can't have a baptismplace and baptismplace_id")
     if baptismplace is not None:
         new, baptismplace = self.get_or_create_place(baptismplace)
     elif baptismplace_id:
         # better exist already, locally or in database:
         baptismplace = self.lookup("place", baptismplace_id)
     if baptismsource is not None:
         new, baptismsource = self.get_or_create_source(baptismsource)
     if baptismdate or baptismplace or baptismsource:
         new, baptism = self.get_or_create_event(person,
              EventType.BAPTISM, baptismdate,
              baptismplace, baptismsource)
         baptism_ref = get_primary_event_ref_from_type(self.db, person,
                                                       "Baptism")
         if baptism_ref is None:
             # new
             baptism_ref = EventRef()
         baptism_ref.set_reference_handle( baptism.get_handle())
         person.add_event_ref( baptism_ref)
     # Death:
     if deathdate is not None:
         deathdate = _dp.parse(deathdate)
     if deathplace and deathplace_id:
         raise Error("Error in person: can't have a deathplace and deathplace_id")
     if deathplace is not None:
         new, deathplace = self.get_or_create_place(deathplace)
     elif deathplace_id:
         # better exist already, locally or in database:
         deathplace = self.lookup("place", deathplace_id)
     if deathsource is not None:
         new, deathsource = self.get_or_create_source(deathsource)
     if deathdate or deathplace or deathsource or deathcause:
         new, death = self.get_or_create_event(person,
                 EventType.DEATH, deathdate, deathplace,
                 deathsource)
         if deathcause:
             death.set_description(deathcause)
             self.db.commit_event(death, self.trans)
         death_ref = person.get_death_ref()
         if death_ref is None:
             # new
             death_ref = EventRef()
         death_ref.set_reference_handle(death.get_handle())
         person.set_death_ref(death_ref)
     # Burial:
     if burialdate is not None:
         burialdate = _dp.parse(burialdate)
     if burialplace and burialplace_id:
         raise Error("Error in person: can't have a burialplace and burialplace_id")
     if burialplace is not None:
         new, burialplace = self.get_or_create_place(burialplace)
     elif burialplace_id:
         # better exist already, locally or in database:
         burialplace = self.lookup("place", burialplace_id)
     if burialsource is not None:
         new, burialsource = self.get_or_create_source(burialsource)
     if burialdate or burialplace or burialsource:
         new, burial = self.get_or_create_event(person,
              EventType.BURIAL, burialdate,
              burialplace, burialsource)
         burial_ref = get_primary_event_ref_from_type(self.db, person,
                                                      "Burial")
         if burial_ref is None:
             # new
             burial_ref = EventRef()
         burial_ref.set_reference_handle( burial.get_handle())
         person.add_event_ref( burial_ref)
     if source:
         # add, if new
         new, source = self.get_or_create_source(source)
         self.find_and_set_citation(person, source)
     self.db.commit_person(person, self.trans)
コード例 #49
0
ファイル: importcsv.py プロジェクト: dmccubbing/gramps
 def _parse_person(self, line_number, row, col):
     "Parse the content of a Person line."
     surname = rd(line_number, row, col, "surname")
     firstname = rd(line_number, row, col, "firstname", "")
     callname = rd(line_number, row, col, "callname")
     title = rd(line_number, row, col, "title")
     prefix = rd(line_number, row, col, "prefix")
     suffix = rd(line_number, row, col, "suffix")
     gender = rd(line_number, row, col, "gender")
     source = rd(line_number, row, col, "source")
     note = rd(line_number, row, col, "note")
     birthplace = rd(line_number, row, col, "birthplace")
     birthplace_id = rd(line_number, row, col, "birthplace_id")
     birthdate = rd(line_number, row, col, "birthdate")
     birthsource = rd(line_number, row, col, "birthsource")
     baptismplace = rd(line_number, row, col, "baptismplace")
     baptismplace_id = rd(line_number, row, col, "baptismplace_id")
     baptismdate = rd(line_number, row, col, "baptismdate")
     baptismsource = rd(line_number, row, col, "baptismsource")
     burialplace = rd(line_number, row, col, "burialplace")
     burialplace_id = rd(line_number, row, col, "burialplace_id")
     burialdate = rd(line_number, row, col, "burialdate")
     burialsource = rd(line_number, row, col, "burialsource")
     deathplace = rd(line_number, row, col, "deathplace")
     deathplace_id = rd(line_number, row, col, "deathplace_id")
     deathdate = rd(line_number, row, col, "deathdate")
     deathsource = rd(line_number, row, col, "deathsource")
     deathcause = rd(line_number, row, col, "deathcause")
     grampsid = rd(line_number, row, col, "grampsid")
     person_ref = rd(line_number, row, col, "person")
     #########################################################
     # if this person already exists, don't create them
     person = self.lookup("person", person_ref)
     if person is None:
         if surname is None:
             LOG.warn("empty surname for new person on line %d" %
                      line_number)
             surname = ""
         # new person
         person = self.create_person()
         name = Name()
         name.set_type(NameType(NameType.BIRTH))
         name.set_first_name(firstname)
         surname_obj = Surname()
         surname_obj.set_surname(surname)
         name.add_surname(surname_obj)
         person.set_primary_name(name)
     else:
         name = person.get_primary_name()
     #########################################################
     if person_ref is not None:
         self.storeup("person", person_ref, person)
     # replace
     if surname is not None:
         name.get_primary_surname().set_surname(surname)
     if firstname is not None:
         name.set_first_name(firstname)
     if callname is not None:
         name.set_call_name(callname)
     if title is not None:
         name.set_title(title)
     if prefix is not None:
         name.get_primary_surname().set_prefix(prefix)
         name.group_as = ''  # HELP? what should I do here?
     if suffix is not None:
         name.set_suffix(suffix)
     if note is not None:
         # append notes, if previous notes
         previous_notes_list = person.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)
             person.add_note(new_note.handle)
     if grampsid is not None:
         person.gramps_id = grampsid
     elif person_ref is not None:
         if person_ref.startswith("[") and person_ref.endswith("]"):
             person.gramps_id = self.db.id2user_format(person_ref[1:-1])
     if (person.get_gender() == Person.UNKNOWN and gender is not None):
         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
         person.set_gender(gender)
     #########################################################
     # add if new, replace if different
     # Birth:
     if birthdate is not None:
         birthdate = _dp.parse(birthdate)
     if birthplace and birthplace_id:
         raise Error(
             "Error in person: can't have a birthplace and birthplace_id")
     if birthplace is not None:
         new, birthplace = self.get_or_create_place(birthplace)
     elif birthplace_id:
         # better exist already, locally or in database:
         birthplace = self.lookup("place", birthplace_id)
     if birthsource is not None:
         new, birthsource = self.get_or_create_source(birthsource)
     if birthdate or birthplace or birthsource:
         new, birth = self.get_or_create_event(person, EventType.BIRTH,
                                               birthdate, birthplace,
                                               birthsource)
         birth_ref = person.get_birth_ref()
         if birth_ref is None:
             # new
             birth_ref = EventRef()
         birth_ref.set_reference_handle(birth.get_handle())
         person.set_birth_ref(birth_ref)
     # Baptism:
     if baptismdate is not None:
         baptismdate = _dp.parse(baptismdate)
     if baptismplace and baptismplace_id:
         raise Error(
             "Error in person: can't have a baptismplace and baptismplace_id"
         )
     if baptismplace is not None:
         new, baptismplace = self.get_or_create_place(baptismplace)
     elif baptismplace_id:
         # better exist already, locally or in database:
         baptismplace = self.lookup("place", baptismplace_id)
     if baptismsource is not None:
         new, baptismsource = self.get_or_create_source(baptismsource)
     if baptismdate or baptismplace or baptismsource:
         new, baptism = self.get_or_create_event(person, EventType.BAPTISM,
                                                 baptismdate, baptismplace,
                                                 baptismsource)
         baptism_ref = get_primary_event_ref_from_type(
             self.db, person, "Baptism")
         if baptism_ref is None:
             # new
             baptism_ref = EventRef()
         baptism_ref.set_reference_handle(baptism.get_handle())
         person.add_event_ref(baptism_ref)
     # Death:
     if deathdate is not None:
         deathdate = _dp.parse(deathdate)
     if deathplace and deathplace_id:
         raise Error(
             "Error in person: can't have a deathplace and deathplace_id")
     if deathplace is not None:
         new, deathplace = self.get_or_create_place(deathplace)
     elif deathplace_id:
         # better exist already, locally or in database:
         deathplace = self.lookup("place", deathplace_id)
     if deathsource is not None:
         new, deathsource = self.get_or_create_source(deathsource)
     if deathdate or deathplace or deathsource or deathcause:
         new, death = self.get_or_create_event(person, EventType.DEATH,
                                               deathdate, deathplace,
                                               deathsource)
         if deathcause:
             death.set_description(deathcause)
             self.db.commit_event(death, self.trans)
         death_ref = person.get_death_ref()
         if death_ref is None:
             # new
             death_ref = EventRef()
         death_ref.set_reference_handle(death.get_handle())
         person.set_death_ref(death_ref)
     # Burial:
     if burialdate is not None:
         burialdate = _dp.parse(burialdate)
     if burialplace and burialplace_id:
         raise Error(
             "Error in person: can't have a burialplace and burialplace_id")
     if burialplace is not None:
         new, burialplace = self.get_or_create_place(burialplace)
     elif burialplace_id:
         # better exist already, locally or in database:
         burialplace = self.lookup("place", burialplace_id)
     if burialsource is not None:
         new, burialsource = self.get_or_create_source(burialsource)
     if burialdate or burialplace or burialsource:
         new, burial = self.get_or_create_event(person, EventType.BURIAL,
                                                burialdate, burialplace,
                                                burialsource)
         burial_ref = get_primary_event_ref_from_type(
             self.db, person, "Burial")
         if burial_ref is None:
             # new
             burial_ref = EventRef()
         burial_ref.set_reference_handle(burial.get_handle())
         person.add_event_ref(burial_ref)
     if source:
         # add, if new
         new, source = self.get_or_create_source(source)
         self.find_and_set_citation(person, source)
     self.db.commit_person(person, self.trans)
コード例 #50
0
def exportData(database,
               filename,
               error_dialog=None,
               option_box=None,
               callback=None):
    if not callable(callback):
        callback = lambda percent: None  # dummy

    with OpenFileOrStdout(filename, encoding="utf-8") as fp:

        total = (len(database.note_map) + len(database.person_map) +
                 len(database.event_map) + len(database.family_map) +
                 len(database.repository_map) + len(database.place_map) +
                 len(database.media_map) + len(database.citation_map) +
                 len(database.source_map) + len(database.tag_map))
        count = 0.0

        # ---------------------------------
        # Notes
        # ---------------------------------
        for handle in database.note_map.keys():
            serial = database.note_map[handle]
            write_line(fp, Note.create(serial))
            count += 1
            callback(100 * count / total)

        # ---------------------------------
        # Event
        # ---------------------------------
        for handle in database.event_map.keys():
            serial = database.event_map[handle]
            write_line(fp, Event.create(serial))
            count += 1
            callback(100 * count / total)

        # ---------------------------------
        # Person
        # ---------------------------------
        for handle in database.person_map.keys():
            serial = database.person_map[handle]
            write_line(fp, Person.create(serial))
            count += 1
            callback(100 * count / total)

        # ---------------------------------
        # Family
        # ---------------------------------
        for handle in database.family_map.keys():
            serial = database.family_map[handle]
            write_line(fp, Family.create(serial))
            count += 1
            callback(100 * count / total)

        # ---------------------------------
        # Repository
        # ---------------------------------
        for handle in database.repository_map.keys():
            serial = database.repository_map[handle]
            write_line(fp, Repository.create(serial))
            count += 1
            callback(100 * count / total)

        # ---------------------------------
        # Place
        # ---------------------------------
        for handle in database.place_map.keys():
            serial = database.place_map[handle]
            write_line(fp, Place.create(serial))
            count += 1
            callback(100 * count / total)

        # ---------------------------------
        # Source
        # ---------------------------------
        for handle in database.source_map.keys():
            serial = database.source_map[handle]
            write_line(fp, Source.create(serial))
            count += 1
            callback(100 * count / total)

        # ---------------------------------
        # Citation
        # ---------------------------------
        for handle in database.citation_map.keys():
            serial = database.citation_map[handle]
            write_line(fp, Citation.create(serial))
            count += 1
            callback(100 * count / total)

        # ---------------------------------
        # Media
        # ---------------------------------
        for handle in database.media_map.keys():
            serial = database.media_map[handle]
            write_line(fp, MediaObject.create(serial))
            count += 1
            callback(100 * count / total)

        # ---------------------------------
        # Tag
        # ---------------------------------
        for handle in database.tag_map.keys():
            serial = database.tag_map[handle]
            write_line(fp, Tag.create(serial))
            count += 1
            callback(100 * count / total)

    return True
コード例 #51
0
ファイル: _notesidebarfilter.py プロジェクト: SNoiraud/gramps
class NoteSidebarFilter(SidebarFilter):

    def __init__(self, dbstate, uistate, clicked):
        self.clicked_func = clicked
        self.filter_id = widgets.BasicEntry()
        self.filter_text = widgets.BasicEntry()
        self.note = Note()
        self.note.set_type((NoteType.CUSTOM,''))
        self.ntype = Gtk.ComboBox(has_entry=True)
        if dbstate.is_open():
            self.custom_types = dbstate.db.get_note_types()
        else:
            self.custom_types = []

        self.event_menu = widgets.MonitoredDataType(
            self.ntype,
            self.note.set_type,
            self.note.get_type,
            False, # read-only?
            self.custom_types)

        self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))

        self.tag = Gtk.ComboBox()
        self.generic = Gtk.ComboBox()

        SidebarFilter.__init__(self, dbstate, uistate, "Note")

    def create_widget(self):
        cell = Gtk.CellRendererText()
        cell.set_property('width', self._FILTER_WIDTH)
        cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
        self.generic.pack_start(cell, True)
        self.generic.add_attribute(cell, 'text', 0)
        self.on_filters_changed('Note')

        cell = Gtk.CellRendererText()
        cell.set_property('width', self._FILTER_WIDTH)
        cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
        self.tag.pack_start(cell, True)
        self.tag.add_attribute(cell, 'text', 0)

        self.ntype.get_child().set_width_chars(5)

        self.add_text_entry(_('ID'), self.filter_id)
        self.add_text_entry(_('Text'), self.filter_text)
        self.add_entry(_('Type'), self.ntype)
        self.add_entry(_('Tag'), self.tag)
        self.add_filter_entry(_('Custom filter'), self.generic)
        self.add_regex_entry(self.filter_regex)

    def clear(self, obj):
        self.filter_id.set_text('')
        self.filter_text.set_text('')
        self.ntype.get_child().set_text('')
        self.tag.set_active(0)
        self.generic.set_active(0)

    def get_filter(self):
        gid = str(self.filter_id.get_text()).strip()
        text = str(self.filter_text.get_text()).strip()
        ntype = self.note.get_type().xml_str()
        regex = self.filter_regex.get_active()
        tag = self.tag.get_active() > 0
        gen = self.generic.get_active() > 0

        empty = not (gid or text or ntype or regex or tag or gen)
        if empty:
            generic_filter = None
        else:
            generic_filter = GenericNoteFilter()
            if gid:
                rule = RegExpIdOf([gid], use_regex=regex)
                generic_filter.add_rule(rule)

            rule = HasNote([text, ntype], use_regex=regex)
            generic_filter.add_rule(rule)

            # check the Tag
            if tag:
                model = self.tag.get_model()
                node = self.tag.get_active_iter()
                attr = model.get_value(node, 0)
                rule = HasTag([attr])
                generic_filter.add_rule(rule)

            if self.generic.get_active() != 0:
                model = self.generic.get_model()
                node = self.generic.get_active_iter()
                obj = str(model.get_value(node, 0))
                rule = MatchesFilter([obj])
                generic_filter.add_rule(rule)

        return generic_filter

    def on_filters_changed(self, name_space):
        if name_space == 'Note':
            all_filter = GenericNoteFilter()
            all_filter.set_name(_("None"))
            all_filter.add_rule(rules.note.AllNotes([]))
            self.generic.set_model(build_filter_model('Note', [all_filter]))
            self.generic.set_active(0)

    def on_tags_changed(self, tag_list):
        """
        Update the list of tags in the tag filter.
        """
        model = Gtk.ListStore(str)
        model.append(('',))
        for tag_name in tag_list:
            model.append((tag_name,))
        self.tag.set_model(model)
        self.tag.set_active(0)
コード例 #52
0
class NoteSidebarFilter(SidebarFilter):
    def __init__(self, dbstate, uistate, clicked):
        self.clicked_func = clicked
        self.filter_id = widgets.BasicEntry()
        self.filter_text = widgets.BasicEntry()
        self.note = Note()
        self.note.set_type((NoteType.CUSTOM, ''))
        self.ntype = Gtk.ComboBox(has_entry=True)
        if dbstate.is_open():
            self.custom_types = dbstate.db.get_note_types()
        else:
            self.custom_types = []

        self.event_menu = widgets.MonitoredDataType(
            self.ntype,
            self.note.set_type,
            self.note.get_type,
            False,  # read-only?
            self.custom_types)

        self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))

        self.tag = Gtk.ComboBox()
        self.generic = Gtk.ComboBox()

        SidebarFilter.__init__(self, dbstate, uistate, "Note")

    def create_widget(self):
        cell = Gtk.CellRendererText()
        cell.set_property('width', self._FILTER_WIDTH)
        cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
        self.generic.pack_start(cell, True)
        self.generic.add_attribute(cell, 'text', 0)
        self.on_filters_changed('Note')

        cell = Gtk.CellRendererText()
        cell.set_property('width', self._FILTER_WIDTH)
        cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
        self.tag.pack_start(cell, True)
        self.tag.add_attribute(cell, 'text', 0)

        self.ntype.get_child().set_width_chars(5)

        self.add_text_entry(_('ID'), self.filter_id)
        self.add_text_entry(_('Text'), self.filter_text)
        self.add_entry(_('Type'), self.ntype)
        self.add_entry(_('Tag'), self.tag)
        self.add_filter_entry(_('Custom filter'), self.generic)
        self.add_regex_entry(self.filter_regex)

    def clear(self, obj):
        self.filter_id.set_text('')
        self.filter_text.set_text('')
        self.ntype.get_child().set_text('')
        self.tag.set_active(0)
        self.generic.set_active(0)

    def get_filter(self):
        gid = str(self.filter_id.get_text()).strip()
        text = str(self.filter_text.get_text()).strip()
        ntype = self.note.get_type().xml_str()
        regex = self.filter_regex.get_active()
        tag = self.tag.get_active() > 0
        gen = self.generic.get_active() > 0

        empty = not (gid or text or ntype or regex or tag or gen)
        if empty:
            generic_filter = None
        else:
            generic_filter = GenericNoteFilter()
            if gid:
                rule = RegExpIdOf([gid], use_regex=regex)
                generic_filter.add_rule(rule)

            rule = HasNote([text, ntype], use_regex=regex)
            generic_filter.add_rule(rule)

            # check the Tag
            if tag:
                model = self.tag.get_model()
                node = self.tag.get_active_iter()
                attr = model.get_value(node, 0)
                rule = HasTag([attr])
                generic_filter.add_rule(rule)

            if self.generic.get_active() != 0:
                model = self.generic.get_model()
                node = self.generic.get_active_iter()
                obj = str(model.get_value(node, 0))
                rule = MatchesFilter([obj])
                generic_filter.add_rule(rule)

        return generic_filter

    def on_filters_changed(self, name_space):
        if name_space == 'Note':
            all_filter = GenericNoteFilter()
            all_filter.set_name(_("None"))
            all_filter.add_rule(rules.note.AllNotes([]))
            self.generic.set_model(build_filter_model('Note', [all_filter]))
            self.generic.set_active(0)

    def on_tags_changed(self, tag_list):
        """
        Update the list of tags in the tag filter.
        """
        model = Gtk.ListStore(str)
        model.append(('', ))
        for tag_name in tag_list:
            model.append((tag_name, ))
        self.tag.set_model(model)
        self.tag.set_active(0)
コード例 #53
0
ファイル: importgeneweb.py プロジェクト: ewongbb/gramps
    def parse_person(self,fields,idx,gender,father_surname):

        if not father_surname:
            if not idx < len(fields):
                LOG.warning("Missing surname of person in line %d!" % self.lineno)
                surname =""
            else:
                surname = self.decode(fields[idx])
            idx += 1
        else:
            surname = father_surname

        if not idx < len(fields):
            LOG.warning("Missing firstname of person in line %d!" % self.lineno)
            firstname = ""
        else:
            firstname = self.decode(fields[idx])
        idx += 1
        if idx < len(fields) and father_surname:
            noSurnameRe = re.compile("^[({\[~><?0-9#].*$")
            if not noSurnameRe.match(fields[idx]):
                surname = self.decode(fields[idx])
                idx += 1

        LOG.debug("Person: %s %s" % (firstname, surname))
        person = self.get_or_create_person(firstname,surname)
        name = Name()
        name.set_type( NameType(NameType.BIRTH))
        name.set_first_name(firstname)
        surname_obj = name.get_primary_surname()
        surname_obj.set_surname(surname)
        person.set_primary_name(name)
        if person.get_gender() == Person.UNKNOWN and gender is not None:
            person.set_gender(gender)
        self.db.commit_person(person,self.trans)
        personDataRe = re.compile("^[kmes0-9<>~#\[({!].*$")
        dateRe = re.compile("^[kmes0-9~<>?]+.*$")

        source = None
        birth_parsed = False
        birth_date = None
        birth_place = None
        birth_source = None

        bapt_date = None
        bapt_place = None
        bapt_source = None

        death_date = None
        death_place = None
        death_source = None
        death_cause = None

        crem_date = None
        bur_date = None
        bur_place = None
        bur_source = None

        public_name = None
        firstname_aliases = []
        nick_names = []
        name_aliases = []
        surname_aliases = []

        while idx < len(fields) and personDataRe.match(fields[idx]):
            field = fields[idx]
            idx += 1
            if field.startswith('('):
                LOG.debug("Public Name: %s" % field)
                public_name = self.decode(field[1:-1])
            elif field.startswith('{'):
                LOG.debug("Firstsname Alias: %s" % field)
                firstname_aliases.append(self.decode(field[1:-1]))
            elif field.startswith('['):
                LOG.debug("Title: %s" % field)
                titleparts = self.decode(field[1:-1]).split(":")
                tname = ttitle = tplace = tstart = tend = tnth = None
                try:
                    tname =  titleparts[0]
                    ttitle = titleparts[1]
                    if titleparts[2]:
                        tplace = self.get_or_create_place(titleparts[2])
                    tstart = self.parse_date(titleparts[3])
                    tend =   self.parse_date(titleparts[4])
                    tnth =   titleparts[5]
                except IndexError:  # not all parts are written all the time
                    pass
                if tnth:    # Append title numer to title
                    ttitle += ", " + tnth
                title = self.create_event(
                           EventType.NOB_TITLE, ttitle, tstart, tplace)
                # TODO: Geneweb has a start date and an end date, and therefore
                # supports stuff like: FROM about 1955 TO between 1998 and 1999
                # gramps only supports one single date or range.
                if tname and tname != "*":
                    n = Note()
                    n.set(tname)
                    self.db.add_note(n,self.trans)
                    title.add_note( n.handle)
                title_ref = EventRef()
                title_ref.set_reference_handle(title.get_handle())
                person.add_event_ref(title_ref)
            elif field == '#nick' and idx < len(fields):
                LOG.debug("Nick Name: %s" % fields[idx])
                nick_names.append(self.decode(fields[idx]))
                idx += 1
            elif field == '#occu' and idx < len(fields):
                LOG.debug("Occupation: %s" % fields[idx])
                occu = self.create_event(
                        EventType.OCCUPATION, self.decode(fields[idx]))
                occu_ref = EventRef()
                occu_ref.set_reference_handle(occu.get_handle())
                person.add_event_ref(occu_ref)
                idx += 1
            elif field == '#alias' and idx < len(fields):
                LOG.debug("Name Alias: %s" % fields[idx])
                name_aliases.append(self.decode(fields[idx]))
                idx += 1
            elif field == '#salias' and idx < len(fields):
                LOG.debug("Surname Alias: %s" % fields[idx])
                surname_aliases.append(self.decode(fields[idx]))
                idx += 1
            elif field == '#image' and idx < len(fields):
                LOG.debug("Image: %s" % fields[idx])
                idx += 1
            elif field == '#src' and idx < len(fields):
                LOG.debug("Source: %s" % fields[idx])
                source = self.get_or_create_source(self.decode(fields[idx]))
                idx += 1
            elif field == '#bs' and idx < len(fields):
                LOG.debug("Birth Source: %s" % fields[idx])
                birth_source = self.get_or_create_source(self.decode(fields[idx]))
                idx += 1
            elif field[0] == '!':
                LOG.debug("Baptize at: %s" % field[1:])
                bapt_date = self.parse_date(self.decode(field[1:]))
            elif field == '#bp' and idx < len(fields):
                LOG.debug("Birth Place: %s" % fields[idx])
                birth_place = self.get_or_create_place(self.decode(fields[idx]))
                idx += 1
            elif field == '#pp' and idx < len(fields):
                LOG.debug("Baptize Place: %s" % fields[idx])
                bapt_place = self.get_or_create_place(self.decode(fields[idx]))
                idx += 1
            elif field == '#ps' and idx < len(fields):
                LOG.debug("Baptize Source: %s" % fields[idx])
                bapt_source = self.get_or_create_source(self.decode(fields[idx]))
                idx += 1
            elif field == '#dp' and idx < len(fields):
                LOG.debug("Death Place: %s" % fields[idx])
                death_place = self.get_or_create_place(self.decode(fields[idx]))
                idx += 1
            elif field == '#ds' and idx < len(fields):
                LOG.debug("Death Source: %s" % fields[idx])
                death_source = self.get_or_create_source(self.decode(fields[idx]))
                idx += 1
            elif field == '#buri' and idx < len(fields):
                if fields[idx][0]!='#': # bug in GeneWeb: empty #buri fields
                    LOG.debug("Burial Date: %s" % fields[idx])
                    bur_date = self.parse_date(self.decode(fields[idx]))
                    idx += 1
            elif field == '#crem' and idx < len(fields):
                LOG.debug("Cremention Date: %s" % fields[idx])
                crem_date = self.parse_date(self.decode(fields[idx]))
                idx += 1
            elif field == '#rp' and idx < len(fields):
                LOG.debug("Burial Place: %s" % fields[idx])
                bur_place = self.get_or_create_place(self.decode(fields[idx]))
                idx += 1
            elif field == '#rs' and idx < len(fields):
                LOG.debug("Burial Source: %s" % fields[idx])
                bur_source = self.get_or_create_source(self.decode(fields[idx]))
                idx += 1
            elif field == '#apubl':
                LOG.debug("This is a public record")
            elif field == '#apriv':
                LOG.debug("This is a private record")
                person.set_privacy(True)
            elif field == '#h':
                LOG.debug("This is a restricted record")
                #TODO: Gramps does currently not feature this level
                person.set_privacy(True)
            elif dateRe.match(field):
                if not birth_parsed:
                    LOG.debug("Birth Date: %s" % field)
                    birth_date = self.parse_date(self.decode(field))
                    birth_parsed = True
                else:
                    LOG.debug("Death Date: %s" % field)
                    death_date = self.parse_date(self.decode(field))
                    if field == "mj":
                        death_cause = "Died joung"
                    elif field.startswith("k"):
                        death_cause = "Killed"
                    elif field.startswith("m"):
                        death_cause = "Murdered"
                    elif field.startswith("e"):
                        death_cause = "Executed"
                    elif field.startswith("d"):
                        death_cause = "Disappeared"
                    #TODO: Set special death types more properly
            else:
                LOG.warning(("parse_person(): Unknown field " +
                          "'%s' for person in line %d!") % (field, self.lineno))

        if public_name:
            name = person.get_primary_name()
            name.set_type(NameType(NameType.BIRTH))
            person.add_alternate_name(name)
            name = Name()
            name.set_type(NameType(NameType.AKA))
            name.set_first_name(public_name)
            surname_obj = name.get_primary_surname()
            surname_obj.set_surname(surname)
            person.set_primary_name(name)

        for aka in nick_names:
            name = Attribute()
            name.set_type(AttributeType(AttributeType.NICKNAME))
            name.set_value(aka)
            person.add_attribute(name)

        for aka in firstname_aliases:
            name = Name()
            name.set_type(NameType(NameType.AKA))
            name.set_first_name(aka)
            surname_obj = name.get_primary_surname()
            surname_obj.set_surname(surname)
            person.add_alternate_name(name)

        for aka in name_aliases:
            name = Name()
            name.set_type(NameType(NameType.AKA))
            name.set_first_name(aka)
            surname_obj = name.get_primary_surname()
            surname_obj.set_surname(surname)
            person.add_alternate_name(name)

        for aka in surname_aliases:
            name = Name()
            name.set_type(NameType(NameType.AKA))
            if public_name:
                name.set_first_name(public_name)
            else:
                name.set_first_name(firstname)
            surname_obj = name.get_primary_surname()
            surname_obj.set_surname(aka)
            person.add_alternate_name(name)

        if source:
            person.add_citation(source.get_handle())

        if birth_date or birth_place or birth_source:
            birth = self.create_event(EventType.BIRTH, None, birth_date, birth_place, birth_source)
            birth_ref = EventRef()
            birth_ref.set_reference_handle( birth.get_handle())
            person.set_birth_ref( birth_ref)

        if bapt_date or bapt_place or bapt_source:
            babt = self.create_event(EventType.BAPTISM, None, bapt_date, bapt_place, bapt_source)
            babt_ref = EventRef()
            babt_ref.set_reference_handle( babt.get_handle())
            person.add_event_ref( babt_ref)

        if death_date or death_place or death_source or death_cause:
            death = self.create_event(EventType.DEATH, None, death_date, death_place, death_source)
            if death_cause:
                death.set_description(death_cause)
                self.db.commit_event(death,self.trans)
            death_ref = EventRef()
            death_ref.set_reference_handle( death.get_handle())
            person.set_death_ref( death_ref)

        if bur_date:
            bur = self.create_event(EventType.BURIAL, None, bur_date, bur_place, bur_source)
            bur_ref = EventRef()
            bur_ref.set_reference_handle( bur.get_handle())
            person.add_event_ref( bur_ref)

        if crem_date:
            crem = self.create_event(EventType.CREMATION, None, crem_date, bur_place, bur_source)
            crem_ref = EventRef()
            crem_ref.set_reference_handle( crem.get_handle())
            person.add_event_ref(crem_ref)

        self.db.commit_person(person,self.trans)

        return (idx,person)
コード例 #54
0
ファイル: JSONExport.py プロジェクト: belissent/addons-source
def exportData(database, filename,
               error_dialog=None, option_box=None, callback=None):
    if not callable(callback):
        callback = lambda percent: None # dummy

    with OpenFileOrStdout(filename, encoding="utf-8") as fp:

        total = (len(database.note_map) +
                 len(database.person_map) +
                 len(database.event_map) +
                 len(database.family_map) +
                 len(database.repository_map) +
                 len(database.place_map) +
                 len(database.media_map) +
                 len(database.citation_map) +
                 len(database.source_map) +
                 len(database.tag_map))
        count = 0.0

        # ---------------------------------
        # Notes
        # ---------------------------------
        for handle in database.note_map.keys():
            serial = database.note_map[handle]
            write_line(fp, Note.create(serial))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Event
        # ---------------------------------
        for handle in database.event_map.keys():
            serial = database.event_map[handle]
            write_line(fp, Event.create(serial))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Person
        # ---------------------------------
        for handle in database.person_map.keys():
            serial = database.person_map[handle]
            write_line(fp, Person.create(serial))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Family
        # ---------------------------------
        for handle in database.family_map.keys():
            serial = database.family_map[handle]
            write_line(fp, Family.create(serial))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Repository
        # ---------------------------------
        for handle in database.repository_map.keys():
            serial = database.repository_map[handle]
            write_line(fp, Repository.create(serial))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Place
        # ---------------------------------
        for handle in database.place_map.keys():
            serial = database.place_map[handle]
            write_line(fp, Place.create(serial))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Source
        # ---------------------------------
        for handle in database.source_map.keys():
            serial = database.source_map[handle]
            write_line(fp, Source.create(serial))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Citation
        # ---------------------------------
        for handle in database.citation_map.keys():
            serial = database.citation_map[handle]
            write_line(fp, Citation.create(serial))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Media
        # ---------------------------------
        for handle in database.media_map.keys():
            serial = database.media_map[handle]
            write_line(fp, Media.create(serial))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Tag
        # ---------------------------------
        for handle in database.tag_map.keys():
            serial = database.tag_map[handle]
            write_line(fp, Tag.create(serial))
            count += 1
            callback(100 * count/total)

    return True