def double_click(self, obj): # bring up events on this day year, month, day = self.gui.calendar.get_date() date = Date() date.set_yr_mon_day(year, month + 1, day) run_quick_report_by_name(self.gui.dbstate, self.gui.uistate, 'onthisday', date)
def format_datetime(datestring): """ Convert an exif timestamp into a string for display, using the standard Gramps date format. """ try: timestamp = datetime.strptime(datestring, '%Y:%m:%d %H:%M:%S') except ValueError: return _('Invalid format') date_part = Date() date_part.set_yr_mon_day(timestamp.year, timestamp.month, timestamp.day) date_str = displayer.display(date_part) time_str = _('%(hr)02d:%(min)02d:%(sec)02d') % {'hr': timestamp.hour, 'min': timestamp.minute, 'sec': timestamp.second} return _('%(date)s %(time)s') % {'date': date_str, 'time': time_str}
def makedate(year, month=0, day=0, about=False): d = GrampsDate() d.set_yr_mon_day(year, month, day) if about: d.set_modifier(GrampsDate.MOD_ABOUT) return DateProxy(d)
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) supdate = None 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: if source.get_title() == source_text: #print("birth event removed from:", # person.gramps_id) 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.remove_citation(citation_handle, self.trans) pupdate = 1 supdate = source # found the source. 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: if source.get_title() == source_text: #print("death event removed from:", # person.gramps_id) person.set_death_ref(None) person.remove_handle_references('Event',[death_ref.ref]) # remove note note_list = death.get_referenced_note_handles() death.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.remove_citation(citation_handle, self.trans) pupdate = 1 supdate = source # found the source. break if pupdate == 1: self.db.commit_person(person, self.trans) if supdate: self.db.remove_source(supdate.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.set_current_frame(_("Select"))
def _convert_date(self, date_in): """Convert the change date to the preferred date format and return a string""" change_date = Date() change_date.set_yr_mon_day(*time.localtime(date_in)[0:3]) return gramps.gen.datehandler.displayer.display(change_date)
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"))