예제 #1
0
    def save(self, *obj):
        self.ok_button.set_sensitive(False)
        if self.object_is_empty():
            ErrorDialog(
                _("Cannot save event"),
                _("No data exists for this event. Please "
                  "enter data or cancel the edit."))
            self.ok_button.set_sensitive(True)
            return

        (uses_dupe_id, id) = self._uses_duplicate_id()
        if uses_dupe_id:
            prim_object = self.get_from_gramps_id(id)
            name = prim_object.get_description()
            msg1 = _("Cannot save event. ID already exists.")
            msg2 = _("You have attempted to use the existing Gramps ID with "
                     "value %(id)s. This value is already used by '"
                     "%(prim_object)s'. Please enter a different ID or leave "
                     "blank to get the next available ID value.") % {
                         'id': id,
                         'prim_object': name
                     }
            ErrorDialog(msg1, msg2)
            self.ok_button.set_sensitive(True)
            return

        t = self.obj.get_type()
        if t.is_custom() and str(t) == '':
            ErrorDialog(_("Cannot save event"),
                        _("The event type cannot be empty"))
            self.ok_button.set_sensitive(True)
            return

        if not self.obj.handle:
            with DbTxn(
                    _("Add Event (%s)") % self.obj.get_gramps_id(),
                    self.db) as trans:
                self.db.add_event(self.obj, trans)
        else:
            orig = self.get_from_handle(self.obj.handle)
            if cmp(self.obj.serialize(), orig.serialize()):
                with DbTxn(
                        _("Edit Event (%s)") % self.obj.get_gramps_id(),
                        self.db) as trans:
                    if not self.obj.get_gramps_id():
                        self.obj.set_gramps_id(
                            self.db.find_next_event_gramps_id())
                    self.commit_event(self.obj, trans)

        if self.callback:
            self.callback(self.obj)
        self.close()
예제 #2
0
    def on_ok_clicked(self, obj):
        with DbTxn(_("Capitalization changes"), self.db,
                   batch=True) as self.trans:
            self.db.disable_signals()
            changelist = set(
                self.model.get_value(node, 1) for node in self.iter_list
                if self.model.get_value(node, 0))

            #with self.db.get_person_cursor(update=True, commit=True) as cursor:
            #  for handle, data in cursor:
            for handle in self.db.get_person_handles(False):
                person = self.db.get_person_from_handle(handle)
                #person = Person(data)
                change = False
                for name in [person.get_primary_name()
                             ] + person.get_alternate_names():
                    sname = find_surname_name(handle, name.serialize())
                    if sname in changelist:
                        change = True
                        for surn in name.get_surname_list():
                            sname = self.name_cap(surn.get_surname())
                            surn.set_surname(sname)
                if change:
                    #cursor.update(handle, person.serialize())
                    self.db.commit_person(person, transaction=self.trans)

        self.db.enable_signals()
        self.db.request_rebuild()
        # FIXME: this probably needs to be removed, and bookmarks
        # should always be rebuilt on a commit_person via signals
        # self.parent.bookmarks.redraw()
        self.close()
        self.cb()
예제 #3
0
    def execute(self):
        """
        Merges to places into a single place.
        """
        new_handle = self.phoenix.get_handle()
        old_handle = self.titanic.get_handle()

        self.phoenix.merge(self.titanic)

        with DbTxn(_("Merge Places"), self.database) as trans:
            self.database.commit_place(self.phoenix, trans)
            for (class_name,
                 handle) in self.database.find_backlink_handles(old_handle):
                if class_name == Person.__name__:
                    person = self.database.get_person_from_handle(handle)
                    assert (person.has_handle_reference('Place', old_handle))
                    person.replace_handle_reference('Place', old_handle,
                                                    new_handle)
                    self.database.commit_person(person, trans)
                elif class_name == Family.__name__:
                    family = self.database.get_family_from_handle(handle)
                    assert (family.has_handle_reference('Place', old_handle))
                    family.replace_handle_reference('Place', old_handle,
                                                    new_handle)
                    self.database.commit_family(family, trans)
                elif class_name == Event.__name__:
                    event = self.database.get_event_from_handle(handle)
                    assert (event.has_handle_reference('Place', old_handle))
                    event.replace_handle_reference('Place', old_handle,
                                                   new_handle)
                    self.database.commit_event(event, trans)
                else:
                    raise MergeError("Encounter an object of type %s that has "
                                     "a place reference." % class_name)
            self.database.remove_place(old_handle, trans)
예제 #4
0
    def ok_clicked(self, obj):

        if self.source.handle:
            with DbTxn(_("Modify Repository"), self.db) as trans:
                self.db.commit_repository(self.source, trans)
        else:
            if self.check_for_duplicate_id('Repository'):
                return
            with DbTxn(_("Add Repository"), self.db) as trans:
                self.db.add_repository(self.source, trans)
            self.source_ref.ref = self.source.handle

        if self.update:
            self.update((self.source_ref, self.source))

        self.close()
예제 #5
0
    def execute(self):
        """
        Merges to citations into a single citation.
        """
        new_handle = self.phoenix.get_handle()
        old_handle = self.titanic.get_handle()

        self.phoenix.merge(self.titanic)

        with DbTxn(_("Merge Citation"), self.database) as trans:
            self.database.commit_citation(self.phoenix, trans)
            for (class_name, handle) in self.database.find_backlink_handles(
                    old_handle):
                if class_name == Person.__name__:
                    person = self.database.get_person_from_handle(handle)
                    assert(person.has_citation_reference(old_handle))
                    person.replace_citation_references(old_handle, new_handle)
                    self.database.commit_person(person, trans)
                elif class_name == Family.__name__:
                    family = self.database.get_family_from_handle(handle)
                    assert(family.has_citation_reference(old_handle))
                    family.replace_citation_references(old_handle, new_handle)
                    self.database.commit_family(family, trans)
                elif class_name == Event.__name__:
                    event = self.database.get_event_from_handle(handle)
                    assert(event.has_citation_reference(old_handle))
                    event.replace_citation_references(old_handle, new_handle)
                    self.database.commit_event(event, trans)
                elif class_name == Place.__name__:
                    place = self.database.get_place_from_handle(handle)
                    assert(place.has_citation_reference(old_handle))
                    place.replace_citation_references(old_handle, new_handle)
                    self.database.commit_place(place, trans)
                elif class_name == MediaObject.__name__:
                    obj = self.database.get_object_from_handle(handle)
                    assert(obj.has_citation_reference(old_handle))
                    obj.replace_citation_references(old_handle, new_handle)
                    self.database.commit_media_object(obj, trans)
                elif class_name == Repository.__name__:
                    repository = self.database.get_repository_from_handle(handle)
                    assert(repository.has_citation_reference(old_handle))
                    repository.replace_citation_references(old_handle, 
                                                           new_handle)
                    self.database.commit_repository(repository, trans)
                elif class_name == Citation.__name__:
                    citation = self.database.get_citation_from_handle(handle)
                    assert(citation.has_citation_reference(old_handle))
                    citation.replace_citation_references(old_handle, 
                                                           new_handle)
                    self.database.commit_citation(citation, trans)
                elif class_name == Source.__name__:
                    source = self.database.get_source_from_handle(handle)
                    assert(source.has_citation_reference(old_handle))
                    source.replace_citation_references(old_handle, 
                                                           new_handle)
                    self.database.commit_source(source, trans)
                else:
                    raise MergeError("Encounter an object of type %s that has "
                            "a citation reference." % class_name)
            self.database.remove_citation(old_handle, trans)
예제 #6
0
    def ok_clicked(self, obj):

        if self.source.handle:
            with DbTxn(_("Modify Event"), self.db) as trans:
                self.commit_event(self.source, trans)
        else:
            if self.check_for_duplicate_id('Event'):
                return
            with DbTxn(_("Add Event"), self.db) as trans:
                self.add_event(self.source, trans)
            self.source_ref.ref = self.source.handle

        if self.update:
            self.update(self.source_ref, self.source)

        self.close()
예제 #7
0
    def ok_clicked(self, obj):
        name = name_displayer.display(self.person)
        msg = _("Reorder Relationships: %s") % name
        with DbTxn(msg, self.dbstate.db) as trans:
            self.dbstate.db.commit_person(self.person, trans)

        self.close()
예제 #8
0
    def cb_remove_clicked(self, button, top):
        """
        Remove the selected tag.
        """
        store, iter_ = self.namemodel.get_selected()
        if iter_ is None:
            return
        tag_handle = store.get_value(iter_, 1)
        tag_name = store.get_value(iter_, 2)

        yes_no = QuestionDialog2(
            _("Remove tag '%s'?") % tag_name,
            _("The tag definition will be removed.  "
              "The tag will be also removed from all objects in the database."
              ), _("Yes"), _("No"))
        prompt = yes_no.run()
        if prompt:

            fnc = {
                'Person':
                (self.db.get_person_from_handle, self.db.commit_person),
                'Family':
                (self.db.get_family_from_handle, self.db.commit_family),
                'Event': (self.db.get_event_from_handle, self.db.commit_event),
                'Place': (self.db.get_place_from_handle, self.db.commit_place),
                'Source':
                (self.db.get_source_from_handle, self.db.commit_source),
                'Repository': (self.db.get_repository_from_handle,
                               self.db.commit_repository),
                'MediaObject':
                (self.db.get_object_from_handle, self.db.commit_media_object),
                'Note': (self.db.get_note_from_handle, self.db.commit_note)
            }

            links = [
                link for link in self.db.find_backlink_handles(tag_handle)
            ]
            # Make the dialog modal so that the user can't start another
            # database transaction while the one removing tags is still running.
            pmon = progressdlg.ProgressMonitor(
                progressdlg.GtkProgressDialog,
                ("", self.parent_window, gtk.DIALOG_MODAL),
                popup_time=2)
            status = progressdlg.LongOpStatus(msg=_("Removing Tags"),
                                              total_steps=len(links),
                                              interval=len(links) // 20)
            pmon.add_op(status)

            msg = _('Delete Tag (%s)') % tag_name
            with DbTxn(msg, self.db) as trans:
                for classname, handle in links:
                    status.heartbeat()
                    obj = fnc[classname][0](handle)  # get from handle
                    obj.remove_tag(tag_handle)
                    fnc[classname][1](obj, trans)  # commit

                self.db.remove_tag(tag_handle, trans)
                self.__change_tag_priority(trans)
            self.namemodel.remove(iter_)
            status.end()
예제 #9
0
 def execute(self, family_merger=True, trans=None):
     """
     Merges two persons into a single person.
     """
     if trans is None:
         with DbTxn(_('Merge Person'), self.database) as trans:
             self.__execute(family_merger, trans)
     else:
         self.__execute(family_merger, trans)
예제 #10
0
    def applyTagClicked(self, button):
        progress = None
        rows = self.treeSelection.count_selected_rows()
        tag_name = unicode(self.tagcombo.get_active_text())

        # start the db transaction
        with DbTxn("Tag not related", self.db) as transaction:

            tag = self.db.get_tag_from_name(tag_name)
            if not tag:
                # create the tag if it doesn't already exist
                tag = Tag()
                tag.set_name(tag_name)
                tag.set_priority(self.db.get_number_of_tags())
                tag_handle = self.db.add_tag(tag, transaction)
            else:
                tag_handle = tag.get_handle()

            # if more than 1 person is selected, use a progress indicator
            if rows > 1:
                progress = ProgressMeter(self.title, _('Starting'))
                #TRANS: no singular form needed, as rows is always > 1
                progress.set_pass(
                    ngettext("Setting tag for %d person",
                             "Setting tag for %d people", rows) % rows, rows)

            # iterate through all of the selected rows
            (model, paths) = self.treeSelection.get_selected_rows()

            for path in paths:
                if progress:
                    progress.step()

                # for the current row, get the GID and the person from the database
                iter = self.model.get_iter(path)
                personGid = self.model.get_value(iter, 1)
                person = self.db.get_person_from_gramps_id(personGid)

                # add the tag to the person
                person.add_tag(tag_handle)

                # save this change
                self.db.commit_person(person, transaction)

        # refresh the tags column
        self.treeView.set_model(None)
        for path in paths:
            iter = self.model.get_iter(path)
            personGid = self.model.get_value(iter, 1)
            person = self.db.get_person_from_gramps_id(personGid)
            self.model.set_value(iter, 3, self.get_tag_list(person))
        self.treeView.set_model(self.model)
        self.treeView.expand_all()

        if progress:
            progress.close()
예제 #11
0
    def query_response(self):
        with DbTxn(_("Delete Repository (%s)") % self.obj.get_name(),
                   self.db) as trans:

            repos_handle_list = [self.obj.get_handle()]

            for handle in self.sources:
                source = self.db.get_source_from_handle(handle)
                source.remove_repo_references(repos_handle_list)
                self.db.commit_source(source, trans)

            self.db.remove_repository(self.obj.get_handle(), trans)
예제 #12
0
 def run_tool(self):
     """
     This method runs the batch op, taking care of database signals
     and transactions before and after the running.
     Should not be overridden without good reasons.
     """
     self.db.disable_signals()
     with DbTxn(self.title, self.db, batch=True) as self.trans:
         success = self._run()
     self.db.enable_signals()
     self.db.request_rebuild()
     return success
예제 #13
0
    def query_response(self):
        with DbTxn(_("Delete Note (%s)") % self.note.get_gramps_id(),
                   self.db) as trans:
            self.db.disable_signals()
        
            (person_list, family_list, event_list, place_list, source_list,
             citation_list, media_list, repo_list) = self.the_lists

            note_handle = self.note.get_handle()

            for handle in person_list:
                person = self.db.get_person_from_handle(handle)
                person.remove_note(note_handle)
                self.db.commit_person(person, trans)

            for handle in family_list:
                family = self.db.get_family_from_handle(handle)
                family.remove_note(note_handle)
                self.db.commit_family(family, trans)

            for handle in event_list:
                event = self.db.get_event_from_handle(handle)
                event.remove_note(note_handle)
                self.db.commit_event(event, trans)

            for handle in place_list:
                place = self.db.get_place_from_handle(handle)
                place.remove_note(note_handle)
                self.db.commit_place(place, trans)

            for handle in source_list:
                source = self.db.get_source_from_handle(handle)
                source.remove_note(note_handle)
                self.db.commit_source(source, trans)

            for handle in citation_list:
                citation = self.db.get_citation_from_handle(handle)
                citation.remove_note(note_handle)
                self.db.commit_citation(citation, trans)

            for handle in media_list:
                media = self.db.get_object_from_handle(handle)
                media.remove_note(note_handle)
                self.db.commit_media_object(media, trans)

            for handle in repo_list:
                repo = self.db.get_repository_from_handle(handle)
                repo.remove_note(note_handle)
                self.db.commit_repository(repo, trans)

            self.db.enable_signals()
            self.db.remove_note(note_handle, trans)
예제 #14
0
    def _save(self):
        """
        Save the changes made to the tag.
        """
        self.tag.set_name(unicode(self.entry.get_text()))
        self.tag.set_color(self.color.get_color().to_string())

        if not self.tag.get_name():
            ErrorDialog(_("Cannot save tag"),
                        _("The tag name cannot be empty"))
            return

        if not self.tag.get_handle():
            msg = _("Add Tag (%s)") % self.tag.get_name()
            with DbTxn(msg, self.db) as trans:
                self.db.add_tag(self.tag, trans)
        else:
            orig = self.db.get_tag_from_handle(self.tag.get_handle())
            if cmp(self.tag.serialize(), orig.serialize()):
                msg = _("Edit Tag (%s)") % self.tag.get_name()
                with DbTxn(msg, self.db) as trans:
                    self.db.commit_tag(self.tag, trans)
예제 #15
0
    def save(self, *obj):

        #first save primary object
        if self.source.handle:
            with DbTxn(
                    _("Edit Media Object (%s)") %
                    self.source.get_description(), self.db) as trans:
                self.db.commit_media_object(self.source, trans)
        else:
            if self.check_for_duplicate_id('Media'):
                return
            with DbTxn(
                    _("Add Media Object (%s)") % self.source.get_description(),
                    self.db) as trans:
                self.db.add_object(self.source, trans)

        #save reference object in memory
        coord = (
            self.top.get_object("corner1_x").get_value_as_int(),
            self.top.get_object("corner1_y").get_value_as_int(),
            self.top.get_object("corner2_x").get_value_as_int(),
            self.top.get_object("corner2_y").get_value_as_int(),
        )

        #do not set unset or invalid coord

        if coord is not None and coord in ((None, ) * 4, (0, 0, 100, 100),
                                           (coord[0], coord[1]) * 2):
            coord = None

        self.source_ref.set_rectangle(coord)

        #call callback if given
        if self.update:
            self.update(self.source_ref, self.source)
            self.update = None
        self.close()
예제 #16
0
    def save(self, *obj):
        """
        Save the data.
        """
        self.ok_button.set_sensitive(False)
        if not self.obj.get_reference_handle():
            ErrorDialog(
                _("No source selected"),
                _("A source is anything (personal testimony, "
                  "video recording, photograph, newspaper column, "
                  "gravestone...) from which information can be "
                  "derived. To create a citation, first select the "
                  "required source, and then record the location of "
                  "the information referenced within the source in the "
                  "'Volume/Page' field."))
            self.ok_button.set_sensitive(True)
            return

        (uses_dupe_id, gramps_id) = self._uses_duplicate_id()
        if uses_dupe_id:
            prim_object = self.get_from_gramps_id(gramps_id)
            name = prim_object.get_page()
            msg1 = _("Cannot save citation. ID already exists.")
            msg2 = _("You have attempted to use the existing Gramps ID with "
                     "value %(id)s. This value is already used by '"
                     "%(prim_object)s'. Please enter a different ID or leave "
                     "blank to get the next available ID value.") % {
                         'id': gramps_id,
                         'prim_object': name
                     }
            ErrorDialog(msg1, msg2)
            self.ok_button.set_sensitive(True)
            return

        with DbTxn('', self.db) as trans:
            if not self.obj.get_handle():
                self.db.add_citation(self.obj, trans)
                msg = _("Add Citation (%s)") % self.obj.get_page()
            else:
                if not self.obj.get_gramps_id():
                    self.obj.set_gramps_id(
                        self.db.find_next_citation_gramps_id())
                self.db.commit_citation(self.obj, trans)
                msg = _("Edit Citation (%s)") % self.obj.get_page()
            trans.set_description(msg)

        if self.callback:
            self.callback(self.obj.get_handle())
        self.close()
예제 #17
0
    def execute(self):
        """
        Merges two events into a single event.
        """
        new_handle = self.phoenix.get_handle()
        old_handle = self.titanic.get_handle()

        self.phoenix.merge(self.titanic)

        with DbTxn(_("Merge Event Objects"), self.database) as trans:
            self.database.commit_event(self.phoenix, trans)
            for (class_name,
                 handle) in self.database.find_backlink_handles(old_handle):
                if class_name == Person.__name__:
                    person = self.database.get_person_from_handle(handle)
                    assert (person.has_handle_reference("Event", old_handle))
                    bri = person.birth_ref_index
                    dri = person.death_ref_index
                    person.replace_handle_reference("Event", old_handle,
                                                    new_handle)
                    if person.birth_ref_index != bri and \
                            person.birth_ref_index == -1:
                        for index, ref in enumerate(
                                person.get_event_ref_list()):
                            event = self.database.get_event_from_handle(
                                ref.ref)
                            if event.type.is_birth() and ref.role.is_primary():
                                person.birth_ref_index = index
                                break
                    if person.death_ref_index != dri and \
                            person.death_ref_index == -1:
                        for index, ref in enumerate(
                                person.get_event_ref_list()):
                            event = self.database.get_event_from_handle(
                                ref.ref)
                            if event.type.is_death() and ref.role.is_primary():
                                person.death_ref_index = index
                                break
                    self.database.commit_person(person, trans)
                elif class_name == Family.__name__:
                    family = self.database.get_family_from_handle(handle)
                    assert (family.has_handle_reference("Event", old_handle))
                    family.replace_handle_reference("Event", old_handle,
                                                    new_handle)
                    self.database.commit_family(family, trans)
                else:
                    raise MergeError("Encounter an object of type %s that has "
                                     "an event reference." % class_name)
            self.database.remove_event(old_handle, trans)
예제 #18
0
    def query_response(self):
        with DbTxn(
                _("Delete Citation (%s)") % self.citation.get_page(),
                self.db) as trans:
            self.db.disable_signals()

            (person_list, family_list, event_list, place_list, source_list,
             media_list, repo_list) = self.the_lists

            ctn_handle_list = [self.citation.get_handle()]

            for handle in person_list:
                person = self.db.get_person_from_handle(handle)
                person.remove_citation_references(ctn_handle_list)
                self.db.commit_person(person, trans)

            for handle in family_list:
                family = self.db.get_family_from_handle(handle)
                family.remove_citation_references(ctn_handle_list)
                self.db.commit_family(family, trans)

            for handle in event_list:
                event = self.db.get_event_from_handle(handle)
                event.remove_citation_references(ctn_handle_list)
                self.db.commit_event(event, trans)

            for handle in place_list:
                place = self.db.get_place_from_handle(handle)
                place.remove_citation_references(ctn_handle_list)
                self.db.commit_place(place, trans)

            for handle in source_list:
                source = self.db.get_source_from_handle(handle)
                source.remove_citation_references(ctn_handle_list)
                self.db.commit_source(source, trans)

            for handle in media_list:
                media = self.db.get_object_from_handle(handle)
                media.remove_citation_references(ctn_handle_list)
                self.db.commit_media_object(media, trans)

            for handle in repo_list:
                repo = self.db.get_repository_from_handle(handle)
                repo.remove_citation_references(ctn_handle_list)
                self.db.commit_repository(repo, trans)

            self.db.enable_signals()
            self.db.remove_citation(self.citation.get_handle(), trans)
예제 #19
0
    def execute(self):
        """
        Merges two families into a single family.
        """
        new_handle = self.phoenix.get_handle()
        old_handle = self.titanic.get_handle()

        with DbTxn(_('Merge Family'), self.database) as trans:

            phoenix_father = self.database.get_person_from_handle(self.phoenix_fh)
            titanic_father = self.database.get_person_from_handle(self.titanic_fh)
            self.merge_person(phoenix_father, titanic_father, 'father', trans)

            phoenix_mother = self.database.get_person_from_handle(self.phoenix_mh)
            titanic_mother = self.database.get_person_from_handle(self.titanic_mh)
            self.phoenix = self.database.get_family_from_handle(new_handle)
            self.titanic = self.database.get_family_from_handle(old_handle)
            self.merge_person(phoenix_mother, titanic_mother, 'mother', trans)

            phoenix_father = self.database.get_person_from_handle(self.phoenix_fh)
            phoenix_mother = self.database.get_person_from_handle(self.phoenix_mh)
            self.phoenix = self.database.get_family_from_handle(new_handle)
            self.titanic = self.database.get_family_from_handle(old_handle)
            self.phoenix.merge(self.titanic)
            self.database.commit_family(self.phoenix, trans)
            for childref in self.titanic.get_child_ref_list():
                child = self.database.get_person_from_handle(
                        childref.get_reference_handle())
                if new_handle in child.parent_family_list:
                    child.remove_handle_references('Family', [old_handle])
                else:
                    child.replace_handle_reference('Family', old_handle,
                                                   new_handle)
                self.database.commit_person(child, trans)
            if phoenix_father:
                phoenix_father.remove_family_handle(old_handle)
                self.database.commit_person(phoenix_father, trans)
            if phoenix_mother:
                phoenix_mother.remove_family_handle(old_handle)
                self.database.commit_person(phoenix_mother, trans)
            # replace the family in lds ordinances
            for (dummy, person_handle) in self.database.find_backlink_handles(
                    old_handle, ['Person']):
                person = self.database.get_person_from_handle(person_handle)
                person.replace_handle_reference('Family', old_handle,new_handle)
                self.database.commit_person(person, trans)
            self.database.remove_family(old_handle, trans)
예제 #20
0
 def parse(self, filehandle):
     """
     Prepare the database and parse the input file.
     
     :param filehandle: open file handle positioned at start of the file
     """
     tym = time.time()
     self.person = None
     self.database.disable_signals()
     with DbTxn(_("vCard import"), self.database, batch=True) as self.trans:
         self._parse_vCard_file(filehandle)
     self.database.enable_signals()
     self.database.request_rebuild()
     tym = time.time() - tym
     msg = ngettext('Import Complete: %d second',
                    'Import Complete: %d seconds', tym) % tym
     LOG.debug(msg)
예제 #21
0
    def run(self):
        """
        Run the dialog and return the result.
        """
        self._populate_model()
        while True:
            response = self.top.run()
            if response == gtk.RESPONSE_HELP:
                GrampsDisplay.help(webpage=WIKI_HELP_PAGE,
                                   section=WIKI_HELP_SEC)
            else:
                break

        # Save changed priority values
        if self.__priorities_changed():
            with DbTxn(_('Change Tag Priority'), self.db) as trans:
                self.__change_tag_priority(trans)

        self.top.destroy()
예제 #22
0
 def run(self):
     """
     Perform the actual extraction of information.
     """
     menu = self.options.menu
     self.filter = menu.get_option_by_name('filter').get_filter()
     sort_func_num = menu.get_option_by_name('sort_by').get_value()
     self.sort_desc = menu.get_option_by_name('sort_desc').get_value()
     self.fam_events = menu.get_option_by_name('family_events').get_value()
     sort_functions = _get_sort_functions(Sort.Sort(self.db))
     self.sort_name = sort_functions[sort_func_num][0]
     self.sort_func = sort_functions[sort_func_num][1]
     self.sort = Sort.Sort(self.db)
     with DbTxn(_("Sort event changes"), self.db, batch=True) as trans:
         self.db.disable_signals()
         family_handles = self.sort_person_events(trans)
         if len(family_handles) > 0:
             self.sort_family_events(family_handles, trans)
     self.db.enable_signals()
     self.db.request_rebuild()
예제 #23
0
    def query_response(self):
        with DbTxn(
                _("Delete Event (%s)") % self.event.get_gramps_id(),
                self.db) as trans:
            self.db.disable_signals()

            ev_handle_list = [self.event.get_handle()]

            for handle in self.person_list:
                person = self.db.get_person_from_handle(handle)
                person.remove_handle_references('Event', ev_handle_list)
                self.db.commit_person(person, trans)

            for handle in self.family_list:
                family = self.db.get_family_from_handle(handle)
                family.remove_handle_references('Event', ev_handle_list)
                self.db.commit_family(family, trans)

            self.db.enable_signals()
            self.db.remove_event(self.event.get_handle(), trans)
예제 #24
0
    def save(self, *obj):
        self.ok_button.set_sensitive(False)
        if self.object_is_empty():
            ErrorDialog(
                _("Cannot save source"),
                _("No data exists for this source. Please "
                  "enter data or cancel the edit."))
            self.ok_button.set_sensitive(True)
            return

        (uses_dupe_id, id) = self._uses_duplicate_id()
        if uses_dupe_id:
            prim_object = self.get_from_gramps_id(id)
            name = prim_object.get_title()
            msg1 = _("Cannot save source. ID already exists.")
            msg2 = _("You have attempted to use the existing Gramps ID with "
                     "value %(id)s. This value is already used by '"
                     "%(prim_object)s'. Please enter a different ID or leave "
                     "blank to get the next available ID value.") % {
                         'id': id,
                         'prim_object': name
                     }
            ErrorDialog(msg1, msg2)
            self.ok_button.set_sensitive(True)
            return

        with DbTxn('', self.db) as trans:
            if not self.obj.get_handle():
                self.db.add_source(self.obj, trans)
                msg = _("Add Source (%s)") % self.obj.get_title()
            else:
                if not self.obj.get_gramps_id():
                    self.obj.set_gramps_id(
                        self.db.find_next_source_gramps_id())
                self.db.commit_source(self.obj, trans)
                msg = _("Edit Source (%s)") % self.obj.get_title()
            trans.set_description(msg)

        self.close()
        if self.callback:
            self.callback(self.obj)
예제 #25
0
    def run(self):
        """
        Perform the actual extraction of information.
        """
        with DbTxn(_("Event name changes"), self.db, batch=True) as trans:
            self.db.disable_signals()
            self.change = False
            counter = 0
        
            for person in self.db.iter_people():
                for event_ref in person.get_event_ref_list():
                    if event_ref.get_role() == gen.lib.EventRoleType.PRIMARY:
                        event_handle = event_ref.ref
                        event = self.db.get_event_from_handle(event_handle)
                        if event.get_description() == "":
                            person_event_name(event, person)
                            self.db.commit_event(event, trans)
                            self.change = True
                            counter += 1

            for family in self.db.iter_families():
                for event_ref in family.get_event_ref_list():
                    if event_ref.get_role() == gen.lib.EventRoleType.FAMILY:
                        event_handle = event_ref.ref
                        event = self.db.get_event_from_handle(event_handle)
                        if event.get_description() == "":
                            family_event_name(event, family, self.db)
                            self.db.commit_event(event, trans)
                            self.change = True
                            counter += 1

        self.db.enable_signals()
        self.db.request_rebuild()

        if self.change == True:
            OkDialog(_('Modifications made'), 
                    ngettext("%s event description has been added", 
                    "%s event descriptions have been added", counter) % counter)
        else:
            OkDialog(_('No modifications made'), 
                    _("No event description has been added."))
예제 #26
0
    def delete_person_response(self):
        """
        Deletes the person from the database.
        """
        # set the busy cursor, so the user knows that we are working
        self.uistate.set_busy_cursor(True)

        # create the transaction
        with DbTxn('', self.dbstate.db) as trans:
        
            # create name to save
            person = self.active_person
            active_name = _("Delete Person (%s)") % name_displayer.display(person)

            # delete the person from the database
            # Above will emit person-delete, which removes the person via 
            # callback to the model, so row delete is signaled
            self.dbstate.db.delete_person_from_database(person, trans)
            trans.set_description(active_name)

        self.uistate.set_busy_cursor(False)
예제 #27
0
    def execute(self):
        """
        Merges to sources into a single source.
        """
        new_handle = self.phoenix.get_handle()
        old_handle = self.titanic.get_handle()

        self.phoenix.merge(self.titanic)

        with DbTxn(_("Merge Source"), self.database) as trans:
            self.database.commit_source(self.phoenix, trans)
            for (class_name,
                 handle) in self.database.find_backlink_handles(old_handle):
                if class_name == Citation.__name__:
                    citation = self.database.get_citation_from_handle(handle)
                    assert (citation.get_reference_handle() == old_handle)
                    citation.set_reference_handle(new_handle)
                    self.database.commit_citation(citation, trans)
                else:
                    raise MergeError("Encounter an object of type %s that has "
                                     "a source reference." % class_name)
            self.database.remove_source(old_handle, trans)
예제 #28
0
    def execute(self):
        """
        Merges two repositories into a single repository.
        """
        new_handle = self.phoenix.get_handle()
        old_handle = self.titanic.get_handle()

        self.phoenix.merge(self.titanic)

        with DbTxn(_("Merge Repositories"), self.database) as trans:
            self.database.commit_repository(self.phoenix, trans)
            for (class_name, handle) in self.database.find_backlink_handles(
                    old_handle):
                if class_name == Source.__name__:
                    source = self.database.get_source_from_handle(handle)
                    assert source.has_handle_reference('Repository', old_handle)
                    source.replace_repo_references(old_handle, new_handle)
                    self.database.commit_source(source, trans)
                else:
                    raise MergeError("Encounter an object of type %s that has "
                        "a repository reference." % class_name)
            self.database.remove_repository(old_handle, trans)
예제 #29
0
 def save(self, *obj):
     """Save the data."""
     self.ok_button.set_sensitive(False)
     
     self.update_note()
     
     if self.object_is_empty():
         ErrorDialog(_("Cannot save note"), 
                     _("No data exists for this note. Please "
                       "enter data or cancel the edit."))
         self.ok_button.set_sensitive(True)
         return
     
     (uses_dupe_id, id) = self._uses_duplicate_id()
     if uses_dupe_id:
         msg1 = _("Cannot save note. ID already exists.")
         msg2 = _("You have attempted to use the existing Gramps ID with "
                      "value %(id)s. This value is already used. Please "
                      "enter a different ID or leave "
                      "blank to get the next available ID value.") % {
                      'id' : id }
         ErrorDialog(msg1, msg2)
         self.ok_button.set_sensitive(True)
         return
     
     with DbTxn('', self.db) as trans:
         if not self.obj.get_handle():
             self.db.add_note(self.obj, trans)
             msg = _("Add Note")
         else:
             if not self.obj.get_gramps_id():
                 self.obj.set_gramps_id(self.db.find_next_note_gramps_id())
             self.db.commit_note(self.obj, trans)
             msg = _("Edit Note")
         trans.set_description(msg)
         
     if self.callback:
         self.callback(self.obj.get_handle())
     self.close()
예제 #30
0
    def drag_data_received(self, widget, context, x, y, sel_data, info, time):
        """
        Handle the standard gtk interface for drag_data_received.

        If the selection data is define, extract the value from sel_data.data, 
        and decide if this is a move or a reorder.
        The only data we accept on mediaview is dropping a file, so URI_LIST. 
        We assume this is what we obtain
        """
        if not sel_data:
            return
        #modern file managers provide URI_LIST. For Windows split sel_data.data
        if constfunc.win():
            files = sel_data.data.split('\n')
        else:
            files = sel_data.get_uris()
        for file in files:
            clean_string = Utils.fix_encoding(
                file.replace('\0', ' ').replace("\r", " ").strip())
            protocol, site, mfile, j, k, l = urlparse.urlparse(clean_string)
            if protocol == "file":
                name = unicode(
                    urllib.url2pathname(
                        mfile.encode(sys.getfilesystemencoding())))
                mime = gen.mime.get_type(name)
                if not gen.mime.is_valid_type(mime):
                    return
                photo = gen.lib.MediaObject()
                base_dir = unicode(Utils.media_path(self.dbstate.db))
                if os.path.exists(base_dir):
                    name = Utils.relative_path(name, base_dir)
                photo.set_path(name)
                photo.set_mime_type(mime)
                basename = os.path.basename(name)
                (root, ext) = os.path.splitext(basename)
                photo.set_description(root)
                with DbTxn(_("Drag Media Object"), self.dbstate.db) as trans:
                    self.dbstate.db.add_object(photo, trans)
        widget.emit_stop_by_name('drag_data_received')