Esempio n. 1
0
 def remove(self, obj):
     """
     Remove a person from the database.
     """
     handles = self.selected_handles()
     if len(handles) == 1:
         person = self._lookup_person(handles[0])
         msg1 = self._message1_format(person)
         msg2 = self._message2_format(person)
         msg2 = "%s %s" % (msg2, data_recover_msg)
         # This gets person to delete self.active_person:
         QuestionDialog(msg1,
                        msg2,
                        _('_Delete Person'),
                        self.delete_person_response,
                        parent=self.uistate.window)
     else:
         # Ask to delete; option to cancel, delete rest
         # This gets person to delete from parameter
         MultiSelectDialog(self._message1_format,
                           self._message2_format,
                           handles,
                           self._lookup_person,
                           yes_func=self.delete_person_response,
                           parent=self.uistate.window)
Esempio n. 2
0
    def __init__(self, dbstate, user, options_class, name, callback=None):
        uistate = user.uistate

        tool.Tool.__init__(self, dbstate, options_class, name)
        if uistate:
            # Running with gui -> Show message
            QuestionDialog(
                _("Start date test?"),
                _("This test will create many persons and events in the current database. Do you really want to run this test?"
                  ), _("Run test"), self.run_tool)
        else:
            self.run_tool()
Esempio n. 3
0
    def remove(self, obj):
        """
        Remove a person from the database.
        """
        for sel in self.selected_handles():
            person = self.dbstate.db.get_person_from_handle(sel)
            self.active_person = person
            name = name_displayer.display(person) 

            msg = _('Deleting the person will remove the person '
                             'from the database.')
            msg = "%s %s" % (msg, data_recover_msg)
            QuestionDialog(_('Delete %s?') % name, 
                                          msg, 
                                          _('_Delete Person'), 
                                          self.delete_person_response)
Esempio n. 4
0
 def delete_filter(self, obj):
     gfilter = self.getfilter(self.current_category,  self.current_filtername)
     name = gfilter.get_name()
     using_filters = self.check_recursive_filters(self.current_category, name)
     if using_filters:
         QuestionDialog( _('Delete Filter?'),
                         _('This filter is currently being used '
                           'as the base for other filters. Deleting '
                           'this filter will result in removing all '
                           'other filters that depend on it:\n' +
                           ", ".join(f.get_name() for f in using_filters)),
                         _('Delete Filter'),
                         self._do_delete_selected_filter,
                         parent=self.dialog)
     else:
         self._do_delete_selected_filter()
Esempio n. 5
0
 def remove(self, obj):
     """
     Method called when deleting a family from a family view.
     """
     from gramps.gui.dialog import QuestionDialog, MultiSelectDialog
     from gramps.gen.utils.string import data_recover_msg
     handles = self.selected_handles()
     if len(handles) == 1:
         family = self.dbstate.db.get_family_from_handle(handles[0])
         msg1 = self._message1_format(family)
         msg2 = self._message2_format(family)
         msg2 = "%s %s" % (msg2, data_recover_msg)
         QuestionDialog(msg1, msg2, _('_Delete Family'),
                        lambda: self.delete_family_response(family))
     else:
         MultiSelectDialog(self._message1_format,
                           self._message2_format,
                           handles,
                           self.dbstate.db.get_family_from_handle,
                           yes_func=self.delete_family_response)
Esempio n. 6
0
 def remove(self, *obj):
     """
     Method called when deleting event(s) from the event view.
     """
     handles = self.selected_handles()
     if len(handles) == 1:
         event = self.dbstate.db.get_event_from_handle(handles[0])
         msg1 = self._message1_format(event)
         msg2 = self._message2_format(event)
         msg2 = "%s %s" % (msg2, data_recover_msg)
         QuestionDialog(msg1,
                        msg2,
                        _('_Delete Event'),
                        lambda: self.delete_event_response(event),
                        parent=self.uistate.window)
     else:
         MultiSelectDialog(self._message1_format,
                           self._message2_format,
                           handles,
                           self.dbstate.db.get_event_from_handle,
                           yes_func=self.delete_event_response,
                           parent=self.uistate.window)
    def run(self):
        BUTTONS = ((_("Select All"), self.select_all),
                   (_("Select None"), self.select_none),
                   (_("Toggle Selection"), self.toggle_select),
                   (_("Add Selected Events"), self.apply_selection),
                   )

        if hasattr(self, "table") and self.table:
            self.reselect = False
            if self.options.handler.options_dict['remove']:
                QuestionDialog(_("Remove Events, Notes, and Source and Reselect Data"),
                               _("Are you sure you want to remove previous events, notes, and source and reselect data?"),
                               _("Remove and Run Select Again"),
                               self.set_reselect,
                               self.window)
            else:
                QuestionDialog(_("Reselect Data"),
                               _("Are you sure you want to reselect data?"),
                               _("Run Select Again"),
                               self.set_reselect,
                               self.window)
            if not self.reselect:
                return

        current_date = Date()
        current_date.set_yr_mon_day(*time.localtime(time.time())[0:3])
        self.action = {}
        widget = self.add_results_frame(_("Select"))
        document = TextBufDoc(make_basic_stylesheet(), None)
        document.dbstate = self.dbstate
        document.uistate = self.uistate
        document.open("", container=widget)
        self.sdb = SimpleAccess(self.db)
        sdoc = SimpleDoc(document)
        stab = QuickTable(self.sdb)
        self.table = stab
        stab.columns(_("Select"), _("Person"), _("Action"),
                     _("Birth Date"), _("Death Date"),
                     _("Evidence"), _("Relative"))
        self.results_write(_("Processing...\n"))
        self.filter_option =  self.options.menu.get_option_by_name('filter')
        self.filter = self.filter_option.get_filter() # the actual filter
        people = self.filter.apply(self.db,
                                   self.db.iter_person_handles())
        num_people = self.db.get_number_of_people()
        source_text = self.options.handler.options_dict['source_text']
        source = None
        add_birth = self.options.handler.options_dict['add_birth']
        add_death = self.options.handler.options_dict['add_death']
        remove_old = self.options.handler.options_dict['remove']

        self.MAX_SIB_AGE_DIFF = self.options.handler.options_dict['MAX_SIB_AGE_DIFF']
        self.MAX_AGE_PROB_ALIVE = self.options.handler.options_dict['MAX_AGE_PROB_ALIVE']
        self.AVG_GENERATION_GAP = self.options.handler.options_dict['AVG_GENERATION_GAP']
        if remove_old:
            with DbTxn("", self.db, batch=True) as self.trans:
                self.db.disable_signals()
                self.results_write(_("Removing old estimations... "))
                self.progress.set_pass((_("Removing '%s'...") % source_text),
                                       num_people)
                for person_handle in people:
                    self.progress.step()
                    pupdate = 0
                    person = self.db.get_person_from_handle(person_handle)
                    birth_ref = person.get_birth_ref()
                    if birth_ref:
                        birth = self.db.get_event_from_handle(birth_ref.ref)
                        for citation_handle in birth.get_citation_list():
                            citation = self.db.get_citation_from_handle(citation_handle)
                            source_handle = citation.get_reference_handle()
                            #print "birth handle:", source_handle
                            source = self.db.get_source_from_handle(source_handle)
                            if source:
                                #print "birth source:", source, source.get_title()
                                if source.get_title() == source_text:
                                    person.set_birth_ref(None)
                                    person.remove_handle_references('Event',[birth_ref.ref])
                                    # remove note
                                    note_list = birth.get_referenced_note_handles()
                                    birth.remove_handle_references('Note',
                                      [note_handle for (obj_type, note_handle) in note_list])
                                    for (obj_type, note_handle) in note_list:
                                        self.db.remove_note(note_handle, self.trans)
                                    self.db.remove_event(birth_ref.ref, self.trans)
                                    self.db.commit_source(source, self.trans)
                                    pupdate = 1
                                    break
                    death_ref = person.get_death_ref()
                    if death_ref:
                        death = self.db.get_event_from_handle(death_ref.ref)
                        for citation_handle in death.get_citation_list():
                            citation = self.db.get_citation_from_handle(citation_handle)
                            source_handle = citation.get_reference_handle()
                            #print "death handle:", source_handle
                            source = self.db.get_source_from_handle(source_handle)
                            if source:
                                #print "death source:", source, source.get_title()
                                if source.get_title() == source_text:
                                    person.set_death_ref(None)
                                    person.remove_handle_references('Event',[death_ref.ref])
                                    # remove note
                                    note_list = death.get_referenced_note_handles()
                                    birth.remove_handle_references('Note',
                                      [note_handle for (obj_type, note_handle) in note_list])
                                    for (obj_type, note_handle) in note_list:
                                        self.db.remove_note(note_handle, self.trans)
                                    self.db.remove_event(death_ref.ref, self.trans)
                                    self.db.commit_source(source, self.trans)
                                    pupdate = 1
                                    break
                    if pupdate == 1:
                        self.db.commit_person(person, self.trans)
                if source:
                    self.db.remove_source(source.handle, self.trans)
                self.results_write(_("done!\n"))
                self.db.enable_signals()
                self.db.request_rebuild()
        if add_birth or add_death:
            self.results_write(_("Selecting... \n\n"))
            self.progress.set_pass(_('Selecting...'),
                                   num_people)
            row = 0
            for person_handle in people:
                self.progress.step()
                person = self.db.get_person_from_handle(person_handle)
                birth_ref = person.get_birth_ref()
                death_ref = person.get_death_ref()
                add_birth_event, add_death_event = False, False
                if not birth_ref or not death_ref:
                    date1, date2, explain, other = self.calc_estimates(person)
                    if birth_ref:
                        ev = self.db.get_event_from_handle(birth_ref.ref)
                        date1 = ev.get_date_object()
                    elif not birth_ref and add_birth and date1:
                        if date1.match( current_date, "<"):
                            add_birth_event = True
                            date1.make_vague()
                        else:
                            date1 = Date()
                    else:
                        date1 = Date()
                    if death_ref:
                        ev = self.db.get_event_from_handle(death_ref.ref)
                        date2 = ev.get_date_object()
                    elif not death_ref and add_death and date2:
                        if date2.match( current_date, "<"):
                            add_death_event = True
                            date2.make_vague()
                        else:
                            date2 = Date()
                    else:
                        date2 = Date()
                    # Describe
                    if add_birth_event and add_death_event:
                        action = _("Add birth and death events")
                    elif add_birth_event:
                        action = _("Add birth event")
                    elif add_death_event:
                        action = _("Add death event")
                    else:
                        continue
                    #stab.columns(_("Select"), _("Person"), _("Action"),
                    # _("Birth Date"), _("Death Date"), _("Evidence"), _("Relative"))
                    if add_birth == 1 and not birth_ref: # no date
                        date1 = Date()
                    if add_death == 1 and not death_ref: # no date
                        date2 = Date()
                    if person == other:
                        other = None
                    stab.row("checkbox",
                             person,
                             action,
                             date1,
                             date2,
                             explain or "",
                             other or "")
                    if add_birth_event:
                        stab.set_cell_markup(3, row, "<b>%s</b>" % date_displayer.display(date1))
                    if add_death_event:
                        stab.set_cell_markup(4, row, "<b>%s</b>" % date_displayer.display(date2))
                    self.action[person.handle] = (add_birth_event, add_death_event)
                    row += 1
            if row > 0:
                self.results_write("  ")
                for text, function in BUTTONS:
                    self.make_button(text, function, widget)
                self.results_write("\n")
                stab.write(sdoc)
                self.results_write("  ")
                for text, function in BUTTONS:
                    self.make_button(text, function, widget)
                self.results_write("\n")
            else:
                self.results_write(_("No events to be added."))
                self.results_write("\n")
        self.results_write("\n")
        self.progress.close()
        self.set_current_frame(_("Select"))