コード例 #1
0
ファイル: lineage.py プロジェクト: arpalmares/portableApps
def run_mother(database, document, person):
    """ Function writing the mother lineage quick report
    """
    sa = SimpleAccess(database)
    sd = SimpleDoc(document)

    # display the results

    # feature request 2356: avoid genitive form
    sd.title(_("Mother lineage for %s") % sa.name(person))
    sd.paragraph("")
    sd.paragraph(
        _(""
          "This report shows the mother lineage, also called matronymic lineage "
          "mtDNA lineage."
          " People in this lineage all share the same Mitochondrial DNA (mtDNA)."
          ))
    sd.paragraph("")

    stab = SimpleTable(sa)
    stab.columns(_("Name Mother"), _("Birth"), _("Death Date"), _("Remark"))
    make_details(gen.lib.Person.FEMALE, person, sa, sd, database, stab)
    stab.write(sd)
    sd.paragraph("")

    if person.gender == gen.lib.Person.MALE:
        return

    sd.header2((_("Direct line female descendants")))
    sd.paragraph("")

    make_details_child(gen.lib.Person.FEMALE, person, sa, sd, database)
コード例 #2
0
    def __init__(self, database, document, person):
        self.database = database
        self.person   = person
        self.sdb = SimpleAccess(database)
        self.sdoc = SimpleDoc(document)
        self.rel_class = Relationship.get_relationship_calculator()

        self.msg_list = []
コード例 #3
0
ファイル: siblings.py プロジェクト: arpalmares/portableApps
def run(database, document, person):
    """
    Loops through the families that the person is a child in, and display
    the information about the other children.
    """
    # setup the simple access functions
    sdb = SimpleAccess(database)
    sdoc = SimpleDoc(document)
    stab = SimpleTable(sdb)
    rel_class = Relationship.get_relationship_calculator()

    # display the title
    # feature request 2356: avoid genitive form
    sdoc.title(_("Siblings of %s") % sdb.name(person))
    sdoc.paragraph("")
    stab.columns(_("Sibling"), _("Gender"), _("Birth Date"), _("Type"))
    # grab our current id (self):
    gid = sdb.gid(person)
    # loop through each family in which the person is a child
    document.has_data = False
    for family in sdb.child_in(person):
        # loop through each child in the family
        for child in sdb.children(family):
            # only display if this child is not the active person
            if sdb.gid(child) != gid:
                rel_str = rel_class.get_sibling_relationship_string(
                    rel_class.get_sibling_type(database, person, child),
                    person.get_gender(), child.get_gender())
            else:
                rel_str = _('self')
            # pass row the child object to make link:
            stab.row(child, sdb.gender(child), sdb.birth_or_fallback(child),
                     rel_str)
            document.has_data = True
    stab.write(sdoc)
コード例 #4
0
ファイル: editlink.py プロジェクト: arpalmares/portableApps
    def __init__(self, dbstate, uistate, track, url, callback):
        self.url = url
        self.dbstate = dbstate
        self.simple_access = SimpleAccess(self.dbstate.db)
        self.callback = callback

        ManagedWindow.ManagedWindow.__init__(self, uistate, track, url)

        self._local_init()
        self._connect_signals()
        self.show()
コード例 #5
0
ファイル: AgeOnDate.py プロジェクト: arpalmares/portableApps
def run(database, document, date):
    """
    Display people probably alive and their ages on a particular date.
    """
    # setup the simple access functions
    sdb = SimpleAccess(database)
    sdoc = SimpleDoc(document)
    stab = SimpleTable(sdb)
    if not date.get_valid():
        sdoc.paragraph("Date is not a valid date.")
        return
    # display the title
    if date.get_day_valid():
        sdoc.title(
            _("People and their ages the %s") %
            DateHandler.displayer.display(date))
    else:
        sdoc.title(
            _("People and their ages on %s") %
            DateHandler.displayer.display(date))
    stab.columns(_("Person"), _("Age"),
                 _("Status"))  # Actual Date makes column unicode
    alive_matches = 0
    dead_matches = 0
    for person in sdb.all_people():
        alive, birth, death, explain, relative = \
            probably_alive(person, database, date, return_range=True)
        # Doesn't show people probably alive but no way of figuring an age:
        if alive:
            if birth:
                diff_span = (date - birth)
                stab.row(person, str(diff_span), _("Alive: %s") % explain)
                stab.row_sort_val(1, int(diff_span))
            else:
                stab.row(person, "", _("Alive: %s") % explain)
                stab.row_sort_val(1, 0)
            alive_matches += 1
        else:
            if birth:
                diff_span = (date - birth)
                stab.row(person, str(diff_span), _("Deceased: %s") % explain)
                stab.row_sort_val(1, int(diff_span))
            else:
                stab.row(person, "", _("Deceased: %s") % explain)
                stab.row_sort_val(1, 1)
            dead_matches += 1

    document.has_data = (alive_matches + dead_matches) > 0
    sdoc.paragraph(
        _("\nLiving matches: %d, Deceased matches: %d\n") %
        (alive_matches, dead_matches))
    stab.write(sdoc)
    sdoc.paragraph("")
コード例 #6
0
 def make_tooltip_from_link(self, link_tag):
     """
     Return a string useful for a tooltip given a LinkTag object.
     """
     from Simple import SimpleAccess
     win_obj = find_parent_with_attr(self, attr="dbstate")
     display = link_tag.data
     if win_obj:
         simple_access = SimpleAccess(win_obj.dbstate.db)
         url = link_tag.data
         if url.startswith("gramps://"):
             obj_class, prop, value = url[9:].split("/")
             display = simple_access.display(obj_class, prop, value) or url
     return display
コード例 #7
0
def run(database, document, person):
    """
    Loops through the person events and the family events of any family
    in which the person is a parent (to catch Marriage events), displaying 
    the basic details of the event
    """

    sdb = SimpleAccess(database)
    sdoc = SimpleDoc(document)
    stab = SimpleTable(sdb)

    # get the personal events
    event_list = sdb.events(person)

    # get the events of each family in which the person is
    # a parent
    for family in sdb.parent_in(person):
        event_list += sdb.events(family)

    # Sort the events by their date
    event_list.sort(by_date)

    # display the results

    # feature request 2356: avoid genitive form
    sdoc.title(_("Sorted events of %s") % sdb.name(person))
    sdoc.paragraph("")

    stab.columns(_("Event Type"), _("Event Date"), _("Event Place"))
    document.has_data = False
    for event in event_list:
        stab.row(event, sdb.event_date_obj(event), sdb.event_place(event))
        document.has_data = True
    stab.write(sdoc)
コード例 #8
0
ファイル: References.py プロジェクト: arpalmares/portableApps
def run(database, document, object, item, trans):
    """
    Display back-references for this object.
    """

    # setup the simple access functions
    sdb = SimpleAccess(database)
    sdoc = SimpleDoc(document)
    stab = SimpleTable(sdb)

    # display the title
    sdoc.title(_("References for this %s") % trans)
    sdoc.paragraph("\n")
    stab.columns(_("Type"), _("Reference"))
    for (objclass, handle) in database.find_backlink_handles(object.handle):
        ref = get_ref(database, objclass, handle)
        stab.row(_(objclass), ref)  # translation are explicit (above)

    if stab.get_row_count() > 0:
        document.has_data = True
        stab.write(sdoc)
    else:
        document.has_data = False
        sdoc.paragraph(_("No references for this %s") % trans)
        sdoc.paragraph("")
    sdoc.paragraph("")
コード例 #9
0
def run(database, document, obj):
    """
    Display link references for this note.
    """

    # setup the simple access functions
    sdb = SimpleAccess(database)
    sdoc = SimpleDoc(document)
    stab = SimpleTable(sdb)

    # display the title
    sdoc.title(_("Link References for this note"))
    sdoc.paragraph("\n")
    stab.columns(_("Type"), _("Reference"), _("Link check"))

    tags = obj.text.get_tags()

    for styledtext_tag in tags:
        if int(styledtext_tag.name) == StyledTextTagType.LINK:
            if styledtext_tag.value.startswith("gramps://"):
                object_class, prop, value = styledtext_tag.value[9:].split(
                    "/", 2)
                tagtype = _(object_class)
                ref_obj = sdb.get_link(object_class, prop, value)
                if ref_obj:
                    tagvalue = ref_obj
                    tagcheck = _("Ok")
                else:
                    tagvalue = styledtext_tag.value
                    tagcheck = _("Failed: missing object")
            else:
                tagtype = _("Internet")
                tagvalue = styledtext_tag.value
                tagcheck = ""
            stab.row(tagtype, tagvalue, tagcheck)

    if stab.get_row_count() > 0:
        stab.write(sdoc)
        document.has_data = True
    else:
        sdoc.paragraph(_("No link references for this note"))
        sdoc.paragraph("")
        document.has_data = False
    sdoc.paragraph("")
コード例 #10
0
def run(database, document, person):
    """
    Loops through the families that the person is a child in, and displays
    the information about the other children.
    """
    # setup the simple access functions
    sdb = SimpleAccess(database)
    sdoc = SimpleDoc(document)
    stab = SimpleTable(sdb)
    if isinstance(person, gen.lib.Person):
        surname = sdb.surname(person)
        rsurname = person.get_primary_name().get_group_name()
    else:
        surname = person
        rsurname = person
    # display the title
    sdoc.title(_("People sharing the surname '%s'") % surname)
    sdoc.paragraph("")
    stab.columns(_("Person"), _("Birth Date"), _("Name type"))
    filter = GenericFilterFactory('Person')()
    if rsurname != '':
        rule = SameSurname([rsurname])
    else:
        rule = IncompleteSurname([])
    filter.add_rule(rule)
    people = filter.apply(database, database.iter_person_handles())

    matches = 0
    for person_handle in people:
        person = database.get_person_from_handle(person_handle)
        stab.row(person, sdb.birth_or_fallback(person),
                 str(person.get_primary_name().get_type()))
        matches += 1

    document.has_data = matches > 0
    sdoc.paragraph(
        ngettext(
            "There is %d person with a matching name, or alternate name.\n",
            "There are %d people with a matching name, or alternate name.\n",
            matches) % matches)
    stab.write(sdoc)
コード例 #11
0
ファイル: Reporef.py プロジェクト: arpalmares/portableApps
def run(database, document, repo):
    """
    Display back-references (sources) for this repository.
    """

    # setup the simple access functions

    sdb = SimpleAccess(database)
    sdoc = SimpleDoc(document)
    stab = SimpleTable(sdb)

    # First we find repository and add its text

    sdoc.title('%s\n' % repo.get_name())

    # Go over all the sources that refer to this repository

    repo_handle = repo.handle
    source_list = [
        item[1]
        for item in database.find_backlink_handles(repo_handle, ['Source'])
    ]

    stab.columns(_("Source"), _("Type of media"), _("Call number"))
    document.has_data = False
    for source_handle in source_list:
        src = database.get_source_from_handle(source_handle)

        # Get the list of references from this source to our repo
        # (can be more than one, technically)

        for reporef in src.get_reporef_list():
            if reporef.ref == repo_handle:

                # Determine the text for this source

                media = str(reporef.get_media_type())
                call = reporef.get_call_number()

                stab.row(src.get_title(), media, call)
                document.has_data = True
    stab.write(sdoc)
コード例 #12
0
def run(database, document, attribute, value=None):
    sdb = SimpleAccess(database)
    sdoc = SimpleDoc(document)
    stab = SimpleTable(sdb)
    sdoc.title(_("People who have the '%s' Attribute") % attribute)
    sdoc.paragraph("")
    stab.columns(_("Person"), str(attribute))
    matches = 0
    for person_handle in database.iter_person_handles():
        person = database.get_person_from_handle(person_handle)
        matched = False
        for attr in person.attribute_list:
            if str(attr.type) == attribute:
                stab.row(person, str(attr.get_value()))
                matched = True
        if matched:
            matches += 1
    document.has_data = matches > 0
    sdoc.paragraph(
        _("There are %d people with a matching attribute name.\n") % matches)
    stab.write(sdoc)
コード例 #13
0
def run(database, document, filter_name, *args, **kwargs):
    """
    Loops through the families that the person is a child in, and display
    the information about the other children.
    """
    # setup the simple access functions
    sdb = SimpleAccess(database)
    sdoc = SimpleDoc(document)
    stab = SimpleTable(sdb)
    if (filter_name == 'all'):
        sdoc.title(_("Summary counts of current selection"))
        sdoc.paragraph("")
        sdoc.paragraph(
            _("Right-click row (or press ENTER) to see selected items."))
        sdoc.paragraph("")
        stab.columns(_("Object"), _("Count/Total"))
        stab.row([_("People"), "Filter", "Person"],
                 "%d/%d" % (len(database.get_person_handles()),
                            len(database.basedb.get_person_handles())))
        stab.row([_("Families"), "Filter", "Family"],
                 "%d/%d" % (len(database.get_family_handles()),
                            len(database.basedb.get_family_handles())))
        stab.row([_("Events"), "Filter", "Event"],
                 "%d/%d" % (len(database.get_event_handles()),
                            len(database.basedb.get_event_handles())))
        stab.row([_("Places"), "Filter", "Place"],
                 "%d/%d" % (len(database.get_place_handles()),
                            len(database.basedb.get_place_handles())))
        stab.row([_("Sources"), "Filter", "Source"],
                 "%d/%d" % (len(database.get_source_handles()),
                            len(database.basedb.get_source_handles())))
        stab.row([_("Repositories"), "Filter", "Repository"],
                 "%d/%d" % (len(database.get_repository_handles()),
                            len(database.basedb.get_repository_handles())))
        stab.row([_("Media"), "Filter", "MediaObject"],
                 "%d/%d" % (len(database.get_media_object_handles()),
                            len(database.basedb.get_media_object_handles())))
        stab.row([_("Notes"), "Filter", "Note"],
                 "%d/%d" % (len(database.get_note_handles()),
                            len(database.basedb.get_note_handles())))
        sdoc.paragraph("")
        stab.write(sdoc)
        return

    # display the title
    if filter_name in fname_map:
        sdoc.title(_("Filtering on %s") %
                   fname_map[filter_name])  # listed above
    else:
        sdoc.title(_("Filtering on %s") % _(filter_name))
    sdoc.paragraph("")
    matches = 0

    if (filter_name == 'Inverse Person'):
        sdb.dbase = database.db
        stab.columns(_("Person"), _("Gramps ID"), _("Birth Date"))
        proxy_handles = set(database.iter_person_handles())

        for person in database.db.iter_people():
            if person.handle not in proxy_handles:
                stab.row(person, person.gramps_id,
                         sdb.birth_or_fallback(person))
                matches += 1

    elif (filter_name == 'Inverse Family'):
        sdb.dbase = database.db
        stab.columns(_("Family"), _("Gramps ID"))
        proxy_handles = set(database.iter_family_handles())

        for family in database.db.iter_families():
            if family.handle not in proxy_handles:
                stab.row(family, family.gramps_id)
                matches += 1

    elif (filter_name == 'Inverse Event'):
        sdb.dbase = database.db
        stab.columns(_("Event"), _("Gramps ID"))
        proxy_handles = set(database.iter_event_handles())

        for event in database.db.iter_events():
            if event.handle not in proxy_handles:
                stab.row(event, event.gramps_id)
                matches += 1

    elif (filter_name == 'Inverse Place'):
        sdb.dbase = database.db
        stab.columns(_("Place"), _("Gramps ID"))
        proxy_handles = set(database.iter_place_handles())

        for place in database.db.iter_places():
            if place.handle not in proxy_handles:
                stab.row(place, place.gramps_id)
                matches += 1

    elif (filter_name == 'Inverse Source'):
        sdb.dbase = database.db
        stab.columns(_("Source"), _("Gramps ID"))
        proxy_handles = set(database.iter_source_handles())

        for source in database.db.iter_sources():
            if source.handle not in proxy_handles:
                stab.row(source, source.gramps_id)
                matches += 1

    elif (filter_name == 'Inverse Repository'):
        sdb.dbase = database.db
        stab.columns(_("Repository"), _("Gramps ID"))
        proxy_handles = set(database.iter_repository_handles())

        for repository in database.db.iter_repositories():
            if repository.handle not in proxy_handles:
                stab.row(repository, repository.gramps_id)
                matches += 1

    elif (filter_name == 'Inverse MediaObject'):
        sdb.dbase = database.db
        stab.columns(_("Media"), _("Gramps ID"))
        proxy_handles = set(database.iter_media_object_handles())

        for media in database.db.iter_media_objects():
            if media.handle not in proxy_handles:
                stab.row(media, media.gramps_id)
                matches += 1

    elif (filter_name == 'Inverse Note'):
        sdb.dbase = database.db
        stab.columns(_("Note"), _("Gramps ID"))
        proxy_handles = set(database.iter_note_handles())

        for note in database.db.iter_notes():
            if note.handle not in proxy_handles:
                stab.row(note, note.gramps_id)
                matches += 1

    elif (filter_name in ['all people', 'Person']):
        stab.columns(_("Person"), _("Gramps ID"), _("Birth Date"))
        for person in database.iter_people():
            stab.row(person, person.gramps_id, sdb.birth_or_fallback(person))
            matches += 1

    elif (filter_name in ['all families', 'Family']):
        stab.columns(_("Family"), _("Gramps ID"))
        for family in database.iter_families():
            stab.row(family, family.gramps_id)
            matches += 1

    elif (filter_name in ['all events', 'Event']):
        stab.columns(_("Event"), _("Gramps ID"))
        for obj in database.iter_events():
            stab.row(obj, obj.gramps_id)
            matches += 1

    elif (filter_name in ['all places', 'Place']):
        stab.columns(_("Place"), _("Gramps ID"))
        for obj in database.iter_places():
            stab.row(obj, obj.gramps_id)
            matches += 1

    elif (filter_name in ['all sources', 'Source']):
        stab.columns(_("Source"), _("Gramps ID"))
        for obj in database.iter_sources():
            stab.row(obj, obj.gramps_id)
            matches += 1

    elif (filter_name in ['all repositories', 'Repository']):
        stab.columns(_("Repository"), _("Gramps ID"))
        for obj in database.iter_repositories():
            stab.row(obj, obj.gramps_id)
            matches += 1

    elif (filter_name in ['all media', 'MediaObject']):
        stab.columns(_("Media"), _("Gramps ID"))
        for obj in database.iter_media_objects():
            stab.row(obj, obj.gramps_id)
            matches += 1

    elif (filter_name in ['all notes', 'Note']):
        stab.columns(_("Note"), _("Gramps ID"))
        for obj in database.iter_notes():
            stab.row(obj, obj.gramps_id)
            matches += 1

    elif (filter_name == 'males'):
        stab.columns(_("Person"), _("Birth Date"), _("Name type"))
        for person in database.iter_people():
            if person.gender == Person.MALE:
                stab.row(person, sdb.birth_or_fallback(person),
                         str(person.get_primary_name().get_type()))
                matches += 1

    elif (filter_name == 'females'):
        stab.columns(_("Person"), _("Birth Date"), _("Name type"))
        for person in database.iter_people():
            if person.gender == Person.FEMALE:
                stab.row(person, sdb.birth_or_fallback(person),
                         str(person.get_primary_name().get_type()))
                matches += 1

    elif (filter_name == 'people with unknown gender'):
        stab.columns(_("Person"), _("Birth Date"), _("Name type"))
        for person in database.iter_people():
            if person.gender not in [Person.FEMALE, Person.MALE]:
                stab.row(person, sdb.birth_or_fallback(person),
                         str(person.get_primary_name().get_type()))
                matches += 1

    elif (filter_name == 'people with incomplete names'):
        stab.columns(_("Person"), _("Birth Date"), _("Name type"))
        for person in database.iter_people():
            for name in [person.get_primary_name()
                         ] + person.get_alternate_names():
                if name.get_group_name() == "" or name.get_first_name() == "":
                    stab.row(person, sdb.birth_or_fallback(person),
                             str(person.get_primary_name().get_type()))
                    matches += 1

    elif (filter_name == 'people with missing birth dates'):
        stab.columns(_("Person"), _("Type"))
        for person in database.iter_people():
            birth_ref = person.get_birth_ref()
            if birth_ref:
                birth = database.get_event_from_handle(birth_ref.ref)
                if not DateHandler.get_date(birth):
                    stab.row(person, _("birth event but no date"))
                    matches += 1
            else:
                stab.row(person, _("missing birth event"))
                matches += 1

    elif (filter_name == 'disconnected people'):
        stab.columns(_("Person"), _("Birth Date"), _("Name type"))
        for person in database.iter_people():
            if ((not person.get_main_parents_family_handle())
                    and (not len(person.get_family_handle_list()))):
                stab.row(person, sdb.birth_or_fallback(person),
                         str(person.get_primary_name().get_type()))
                matches += 1

    elif (filter_name == 'unique surnames'):
        namelist = defaultdict(int)
        for person in database.iter_people():
            names = [person.get_primary_name()] + person.get_alternate_names()
            surnames = list(set([name.get_group_name() for name in names]))
            for surname in surnames:
                namelist[surname] += 1
        stab.columns(_("Surname"), _("Count"))
        for name in sorted(namelist):
            stab.row(name, namelist[name])
            matches += 1
        stab.set_callback(
            "leftdouble", lambda name: run_quick_report_by_name_direct(
                "samesurnames", database, document, name))

    elif (filter_name == 'people with media'):
        stab.columns(_("Person"), _("Media count"))
        for person in database.iter_people():
            length = len(person.get_media_list())
            if length > 0:
                stab.row(person, length)
                matches += 1

    elif (filter_name == 'media references'):
        stab.columns(_("Person"), _("Reference"))
        for person in database.iter_people():
            medialist = person.get_media_list()
            for item in medialist:
                stab.row(person, _("media"))
                matches += 1

    elif (filter_name == 'unique media'):
        stab.columns(_("Unique Media"))
        for photo in database.iter_media_objects():
            fullname = media_path_full(database, photo.get_path())
            stab.row(fullname)
            matches += 1

    elif (filter_name == 'missing media'):
        stab.columns(_("Missing Media"))
        for photo in database.iter_media_objects():
            fullname = media_path_full(database, photo.get_path())
            try:
                posixpath.getsize(fullname)
            except:
                stab.row(fullname)
                matches += 1

    elif (filter_name == 'media by size'):
        stab.columns(_("Media"), _("Size in bytes"))
        for photo in database.iter_media_objects():
            fullname = media_path_full(database, photo.get_path())
            try:
                bytes = posixpath.getsize(fullname)
                stab.row(fullname, bytes)
                matches += 1
            except:
                pass

    elif (filter_name == 'list of people'):
        stab.columns(_("Person"), _("Birth Date"), _("Name type"))
        handles = kwargs["handles"]
        for person_handle in handles:
            person = database.get_person_from_handle(person_handle)
            stab.row(person, sdb.birth_or_fallback(person),
                     str(person.get_primary_name().get_type()))
            matches += 1

    else:
        raise AttributeError, ("invalid filter name: '%s'" % filter_name)
    sdoc.paragraph(
        ngettext("Filter matched %d record.", "Filter matched %d records.",
                 matches) % matches)
    sdoc.paragraph("")
    document.has_data = matches > 0
    if matches > 0:
        stab.write(sdoc)
コード例 #14
0
def run(database, document, main_event):
    """
    Displays events on a specific date of an event (or date)
    
    Takes an Event or Date object
    """
    if isinstance(main_event, gen.lib.Date):
        main_date = main_event
    else:
        main_date = main_event.get_date_object()

    cal = main_date.get_calendar()

    # setup the simple access functions
    sdb = SimpleAccess(database)
    sdoc = SimpleDoc(document)
    stab = SimpleTable(sdb)
    stab.set_link_col(3)
    yeartab = SimpleTable(sdb)
    yeartab.set_link_col(3)
    histab = SimpleTable(sdb)
    histab.set_link_col(3)

    # display the title
    sdoc.title(_("Events of %(date)s") % {"date": sdb.date_string(main_date)})
    sdoc.paragraph("")
    stab.columns(_("Date"), _("Type"), _("Place"), _("Reference"))
    yeartab.columns(_("Date"), _("Type"), _("Place"), _("Reference"))
    histab.columns(_("Date"), _("Type"), _("Place"), _("Reference"))

    for event in database.iter_events():
        date = event.get_date_object()
        date.convert_calendar(cal)
        if date.get_year() == 0:
            continue
        if (date.get_year() == main_date.get_year()
                and date.get_month() == main_date.get_month()
                and date.get_day() == main_date.get_day()):
            for (objclass,
                 handle) in database.find_backlink_handles(event.handle):
                ref = get_ref(database, objclass, handle)
                stab.row(date, sdb.event_type(event), sdb.event_place(event),
                         ref)
        elif (date.get_month() == main_date.get_month()
              and date.get_day() == main_date.get_day()
              and date.get_month() != 0):
            for (objclass,
                 handle) in database.find_backlink_handles(event.handle):
                ref = get_ref(database, objclass, handle)
                histab.row(date, sdb.event_type(event), sdb.event_place(event),
                           ref)
        elif (date.get_year() == main_date.get_year()):
            for (objclass,
                 handle) in database.find_backlink_handles(event.handle):
                ref = get_ref(database, objclass, handle)
                yeartab.row(date, sdb.event_type(event),
                            sdb.event_place(event), ref)

    document.has_data = False
    if stab.get_row_count() > 0:
        document.has_data = True
        sdoc.paragraph(_("Events on this exact date"))
        stab.write(sdoc)
    else:
        sdoc.paragraph(_("No events on this exact date"))
        sdoc.paragraph("")
    sdoc.paragraph("")

    if histab.get_row_count() > 0:
        document.has_data = True
        sdoc.paragraph(_("Other events on this month/day in history"))
        histab.write(sdoc)
    else:
        sdoc.paragraph(_("No other events on this month/day in history"))
        sdoc.paragraph("")
    sdoc.paragraph("")

    if yeartab.get_row_count() > 0:
        document.has_data = True
        sdoc.paragraph(
            _("Other events in %(year)d") % {"year": main_date.get_year()})
        yeartab.write(sdoc)
    else:
        sdoc.paragraph(
            _("No other events in %(year)d") % {"year": main_date.get_year()})
        sdoc.paragraph("")
    sdoc.paragraph("")
コード例 #15
0
ファイル: editlink.py プロジェクト: arpalmares/portableApps
class EditLink(ManagedWindow.ManagedWindow):
    def __init__(self, dbstate, uistate, track, url, callback):
        self.url = url
        self.dbstate = dbstate
        self.simple_access = SimpleAccess(self.dbstate.db)
        self.callback = callback

        ManagedWindow.ManagedWindow.__init__(self, uistate, track, url)

        self._local_init()
        self._connect_signals()
        self.show()

    def _local_init(self):
        self.top = Glade()
        self.set_window(self.top.toplevel, self.top.get_object("title"),
                        _('Link Editor'))
        self.table = self.top.get_object('table27')
        self.uri_list = gtk.combo_box_new_text()
        for text in [
                _("Internet Address"),  # 0 this order range above
                _("Event"),  # 1 
                _("Family"),  # 2 
                _("Media"),  # 3
                _("Note"),  # 4
                _("Person"),  # 5
                _("Place"),  # 6
                _("Repository"),  # 7
                _("Source"),  # 8
        ]:
            self.uri_list.append_text(text)
        self.table.attach(self.uri_list, 1, 2, 0, 1)
        self.pick_item = self.top.get_object('button1')
        #self.edit_item = self.top.get_object('button2')
        self.selected = self.top.get_object('label1')
        self.url_link = self.top.get_object('entry1')
        self.uri_list.connect("changed", self._on_type_changed)
        self.pick_item.connect("clicked", self._on_pick_one)
        #self.edit_item.connect("clicked", self._on_edit_one)
        if self.url.startswith("gramps://"):
            object_class, prop, value = self.url[9:].split("/", 2)
            if object_class == "Event":
                self.uri_list.set_active(EVENT)
            elif object_class == "Family":
                self.uri_list.set_active(FAMILY)
            elif object_class == "Media":
                self.uri_list.set_active(MEDIA)
            elif object_class == "Note":
                self.uri_list.set_active(NOTE)
            elif object_class == "Person":
                self.uri_list.set_active(PERSON)
            elif object_class == "Place":
                self.uri_list.set_active(PLACE)
            elif object_class == "Repository":
                self.uri_list.set_active(REPOSITORY)
            elif object_class == "Source":
                self.uri_list.set_active(SOURCE)
            # set texts:
            self.selected.set_text(self.display_link(object_class, prop,
                                                     value))
            self.url_link.set_text("gramps://%s/%s/%s" %
                                   (object_class, prop, value))
        else:
            self.uri_list.set_active(WEB)
            self.url_link.set_text(self.url)
        self.url_link.connect("changed", self.update_ui)

    def update_ui(self, widget):
        url = self.url_link.get_text()
        # text needs to have 3 or more chars://and at least one char
        match = re.match("\w{3,}://\w+", url)
        if match:
            self.ok_button.set_sensitive(True)
        else:
            self.ok_button.set_sensitive(False)

    def display_link(self, obj_class, prop, value):
        return self.simple_access.display(obj_class, prop, value)

    def _on_edit_one(self, widget):
        # Not used due to modal dialog in StyledTextEditor
        from gui.editors import EditObject
        uri = self.url_link.get_text()
        if uri.startswith("gramps://"):
            obj_class, prop, value = uri[9:].split("/", 2)
            EditObject(self.dbstate, self.uistate, self.track, obj_class, prop,
                       value)

    def _on_pick_one(self, widget):
        from gui.selectors import SelectorFactory
        object_class = OBJECT_MAP[self.uri_list.get_active()]
        Select = SelectorFactory(object_class)
        uri = self.url_link.get_text()
        default = None
        if uri.startswith("gramps://"):
            obj_class, prop, value = uri[9:].split("/", 2)
            if object_class == obj_class:
                if prop == "handle":
                    default = value
                elif (prop == "gramps_id"
                      and object_class in self.dbstate.db.get_table_names()):
                    person = self.dbstate.db.get_table_metadata(
                        object_class)["gramps_id_func"](value)
                    if person:
                        default = person.handle
        d = Select(self.dbstate, self.uistate, self.track, default=default)

        result = d.run()
        if result:
            prop = "handle"
            value = result.handle
            self.selected.set_text(self.display_link(object_class, prop,
                                                     value))
            self.url_link.set_text("gramps://%s/%s/%s" %
                                   (object_class, prop, value))

    def _on_type_changed(self, widget):
        self.selected.set_text("")
        if self.uri_list.get_active() == WEB:
            self.url_link.set_sensitive(True)
            self.pick_item.set_sensitive(False)
        else:
            self.url_link.set_sensitive(False)
            self.pick_item.set_sensitive(True)

    def get_uri(self):
        if self.uri_list.get_active() == WEB:
            return self.url_link.get_text()
        else:
            return self.url_link.get_text()

    def _connect_signals(self):
        self.define_cancel_button(self.top.get_object('button125'))
        self.ok_button = self.top.get_object('button124')
        self.define_ok_button(self.ok_button, self.save)
        self.define_help_button(self.top.get_object('button130'))
        self.update_ui(self.url_link)

    def build_menu_names(self, obj):
        etitle = _('Link Editor')
        return (etitle, etitle)

    def define_ok_button(self, button, function):
        button.connect('clicked', function)

    def save(self, widget):
        self.callback(self.get_uri())
        self.close()

    def define_cancel_button(self, button):
        button.connect('clicked', self.close)

    def define_help_button(self, button, webpage='', section=''):
        button.connect('clicked',
                       lambda x: GrampsDisplay.help(webpage, section))
コード例 #16
0
def run_fam(database, document, family):
    """
    Loops through the family events and the events of all parents, displaying 
    the basic details of the event
    """

    sdb = SimpleAccess(database)
    sdoc = SimpleDoc(document)
    stab = SimpleTable(sdb)

    # get the family events
    event_list = [(_('Family'), x) for x in sdb.events(family)]

    # get the events of father and mother
    #fathername = sdb.first_name(sdb.father(family))
    event_list += [(sdb.father(family), x)
                   for x in sdb.events(sdb.father(family))]
    #mothername = sdb.first_name(sdb.mother(family))
    event_list += [(sdb.mother(family), x)
                   for x in sdb.events(sdb.mother(family))]

    # children events
    event_list_children = []
    for child in sdb.children(family):
        #name = sdb.first_name(child)
        event_list_children += [(child, x) for x in sdb.events(child)]

    # Sort the events by their date
    event_list.sort(fam_sort)
    event_list_children.sort(fam_sort)

    # display the results

    sdoc.title(
        _("Sorted events of family\n %(father)s - %(mother)s") % {
            'father': sdb.name(sdb.father(family)),
            'mother': sdb.name(sdb.mother(family))
        })
    sdoc.paragraph("")

    document.has_data = False
    stab.columns(_("Family Member"), _("Event Type"), _("Event Date"),
                 _("Event Place"))

    for (person, event) in event_list:
        stab.row(person, sdb.event_type(event), sdb.event_date_obj(event),
                 sdb.event_place(event))
        document.has_data = True
    stab.write(sdoc)

    stab = SimpleTable(sdb)
    sdoc.header1(_("Personal events of the children"))
    stab.columns(_("Family Member"), _("Event Type"), _("Event Date"),
                 _("Event Place"))
    for (person, event) in event_list_children:
        stab.row(person, sdb.event_type(event), sdb.event_date_obj(event),
                 sdb.event_place(event))
        document.has_data = True
    stab.write(sdoc)
コード例 #17
0
class AllRelReport():
    """
    Obtains all relationships, displays the relations, and in details, the 
    relation path
    """
    def __init__(self, database, document, person):
        self.database = database
        self.person   = person
        self.sdb = SimpleAccess(database)
        self.sdoc = SimpleDoc(document)
        self.rel_class = Relationship.get_relationship_calculator()

        self.msg_list = []

    def run(self):
        #get home_person
        self.home_person = self.database.get_default_person()
        if not self.home_person :
            self.sdoc.paragraph(_("Home person not set."))
            return

        self.print_title()

        p2 = self.sdb.name(self.home_person)
        p1 = self.sdb.name(self.person)
        if self.person.handle == self.home_person.handle :
            self.sdoc.paragraph(_FMT_VOID % (
                _("%(person)s and %(active_person)s are the same person.")) % {
                'person' : p1, 'active_person' : p2 }) 
            return

        #check if not a family too:
        is_spouse = self.rel_class.is_spouse(self.database, self.home_person, 
                                             self.person)
        if is_spouse:
            rel_string = is_spouse
            rstr = _("%(person)s is the %(relationship)s of %(active_person)s."
                         ) % {'person' : p1, 'relationship' : rel_string,
                              'active_person' : p2 }
            self.sdoc.paragraph(_FMT_VOID % (rstr))
            self.sdoc.paragraph("")

        #obtain all relationships, assume home person has largest tree
        common, self.msg_list = self.rel_class.get_relationship_distance_new(
                    self.database, self.person, self.home_person,
                    all_families=True, 
                    all_dist=True, 
                    only_birth=False)
        #all relations
        if (not common or common[0][0]== -1 ) and not is_spouse:
            rstr = _("%(person)s and %(active_person)s are not "
                     "directly related.") % {'person' : p2, 
                                             'active_person' : p1 }
            self.sdoc.paragraph(_FMT_VOID % (rstr))
            self.sdoc.paragraph("")

        #collapse common so parents of same fam in common are one line
        commonnew = self.rel_class.collapse_relations(common)
        self.print_details_header(commonnew, self.home_person, self.person,
                                  skip_list_text=None)
        self.print_details_path(commonnew, self.home_person, self.person)
        self.print_details_path(commonnew, self.home_person, self.person,
                                first=False) 
        
        if not common or common[0][0]== -1 :
            self.remarks(self.msg_list)
            self.msg_list = []
            #check inlaw relation next
        else:
            #stop
            return
        
        #we check the inlaw relationships if not partners.
        if is_spouse:
            return
        handles_done = [(self.person.handle, self.home_person.handle)]
        inlaws_pers = [self.person] + self.get_inlaws(self.person)
        inlaws_home = [self.home_person] + self.get_inlaws(self.home_person)
        #remove overlap:
        inlaws_home = [x for x in inlaws_home if x not in inlaws_pers]
        inlawwritten = False
        skiplist = []
        commonnew = []
        for inlawpers in inlaws_pers:
            for inlawhome in inlaws_home:
                if (inlawpers, inlawhome) in handles_done :
                    continue
                else:
                    handles_done.append((inlawpers, inlawhome))
                common, msg = \
                    self.rel_class.get_relationship_distance_new(
                            self.database, inlawpers, inlawhome,
                            all_families=True, 
                            all_dist=True, 
                            only_birth=False)
                if msg:
                    self.msg_list += msg
                if common and not common[0][0] == -1:
                    if not inlawwritten:
                        rstr = _("%(person)s and %(active_person)s have "
                                 "following in-law relations:"
                                ) % {'person' : p2, 
                                     'active_person' : p1 }
                        self.sdoc.paragraph(_FMT_VOID % (rstr))
                        self.sdoc.paragraph("")
                        inlawwritten = True
                else: 
                    continue
                inlawb = not inlawpers.handle == self.person.handle
                inlawa = not inlawhome.handle == self.home_person.handle
                commonnew.append((inlawa, inlawb, inlawhome, inlawpers,
                                  self.rel_class.collapse_relations(common)))
        skip=[]
        skip_text = []
        count = 1
        for inlawa, inlawb, inlawhome, inlawpers, commonrel in commonnew:
            count = self.print_details_header(commonrel, 
                                inlawhome, inlawpers,
                                inlawa = inlawa, inlawb = inlawb,
                                count=count, 
                                skip_list=skip, skip_list_text = skip_text)
        count = 1
        for inlawa, inlawb, inlawhome, inlawpers, commonrel in commonnew:
            self.print_details_path(commonrel, inlawhome, inlawpers,
                                        inlawa = inlawa, inlawb = inlawb,
                                        count = count, skip_list = skip)
            count = self.print_details_path(commonrel, inlawhome, inlawpers,
                                        inlawa = inlawa, inlawb = inlawb,
                                        count = count, skip_list = skip,
                                        first = False)
        self.remarks(self.msg_list, True)

    def get_inlaws(self, person):
        inlaws = []
        family_handles = person.get_family_handle_list()
        for handle in family_handles:
            fam = self.database.get_family_from_handle(handle)
            if fam.father_handle and \
                    not fam.father_handle == person.handle:
                inlaws.append(self.database.get_person_from_handle(
                                                        fam.father_handle))
            elif fam.mother_handle and \
                    not fam.mother_handle == person.handle:
                inlaws.append(self.database.get_person_from_handle(
                                                        fam.mother_handle))
        return inlaws


    def print_title(self):
        """ print the title
        """
        p2 = self.sdb.name(self.home_person)
        p1 = self.sdb.name(self.person)
        self.sdoc.title(_("Relationships of %(person)s to %(active_person)s") % {
            'person' : p1 ,'active_person' : p2 })
        self.sdoc.paragraph("")

    def print_details_header(self, relations, pers1, pers2, 
                             inlawa=False, inlawb=False, count=1, 
                             skip_list=[], skip_list_text = []):
        if not relations or relations[0][0] == -1:
            return count

        sdoc = self.sdoc
        rel_class = self.rel_class
        for relation in relations: 
            birth = self.rel_class.only_birth(relation[2])\
                        and self.rel_class.only_birth(relation[4])
            distorig = len(relation[4])
            distother = len(relation[2])
            if distorig == distother == 1 and not inlawa \
                    and not inlawb:
                rel_str = self.rel_class.get_sibling_relationship_string(
                            self.rel_class.get_sibling_type(
                                self.database, pers1, pers2), 
                            self.home_person.get_gender(),
                            self.person.get_gender())
            else:
                rel_str = self.rel_class.get_single_relationship_string(
                                    distorig, distother, 
                                    self.home_person.get_gender(), 
                                    self.person.get_gender(),
                                    relation[4], relation[2], 
                                    only_birth = birth,
                                    in_law_a = inlawa, in_law_b = inlawb)
            if not skip_list_text is None:
                if rel_str in skip_list_text:
                    skip_list.append(count)
                else:
                    skip_list_text.append(rel_str)
                    sdoc.paragraph(_FMT % (count-len(skip_list), rel_str))
            else:
                sdoc.paragraph(_FMT % (count, rel_str))
            count += 1
        return count
        
    def print_details_path(self, relations, pers1, pers2, 
                            inlawa=False, inlawb=False,
                            count = 1, skip_list = [], first=True):
        if not relations or relations[0][0] == -1:
            return count

        sdoc = self.sdoc
        rel_class = self.rel_class
        p2 = self.sdb.name(self.home_person)
        p1 = self.sdb.name(self.person)
        pers = p2
        inlaw = inlawa
        if first:
            pers = p1
            inlaw = inlawb
        
        if count == 1:
            sdoc.paragraph("")
            sdoc.header1(_("Detailed path from %(person)s to common ancestor"
                          ) % {'person':pers})
            sdoc.paragraph("")
            sdoc.header2(_FMT_DET1 % ('   ', _('Name Common ancestor')))
            sdoc.header2(_FMT_DET2 % (' ', _('Parent'), _('Birth'), _('Family')))
            sdoc.paragraph("")
        for relation in relations:
            if count in skip_list:
                count += 1
                continue
            counter = str(count - len([x for x in range(count) if x+1 in skip_list])) 
            name = _('Unknown')
            if relation[1]:
                name = self.sdb.name(self.database.get_person_from_handle(
                                                            relation[1][0]))
                for handle in relation[1][1:]:
                    name += ' ' + _('and') + ' ' + self.sdb.name(
                                self.database.get_person_from_handle(handle))
            sdoc.paragraph(_FMT_DET1 % (counter, name))
            if inlaw:
                sdoc.paragraph(_FMT_DET2 % (' ', _('Partner'), ' ', ' '))
            if first:
                ind1 = 2
                ind2 = 3
            else:
                ind1 = 4
                ind2 = 5
            for rel,fam in zip(relation[ind1],relation[ind2]) :
                par_str = _('Unknown') #when sibling, parent is unknown
                if rel == rel_class.REL_MOTHER \
                        or rel == rel_class.REL_MOTHER_NOTBIRTH:
                    par_str = _('Mother')
                if rel == rel_class.REL_FATHER \
                        or rel == rel_class.REL_FATHER_NOTBIRTH:
                    par_str = _('Father')
                if (rel == rel_class.REL_FAM_BIRTH 
                        or rel == rel_class.REL_FAM_NONBIRTH 
                        or rel == rel_class.REL_FAM_BIRTH_MOTH_ONLY
                        or rel == rel_class.REL_FAM_BIRTH_FATH_ONLY):
                    par_str = _('Parents')
                birth_str = _('Yes')
                if (rel == rel_class.REL_MOTHER_NOTBIRTH 
                        or rel == rel_class.REL_FATHER_NOTBIRTH 
                        or rel == rel_class.REL_FAM_NONBIRTH):
                    birth_str = _('No')
                elif (rel == rel_class.REL_FAM_BIRTH_FATH_ONLY 
                        or rel == rel_class.REL_FAM_BIRTH_MOTH_ONLY):
                    birth_str = _('Partial')
                famstr = ''
                if isinstance(fam, list):
                    famstr = str(fam[0]+1)
                    for val in fam[1:] :
                        famstr += ', ' + str(val+1)
                else:
                    famstr = str(fam+1)
                sdoc.paragraph(_FMT_DET2 % (' ', par_str, birth_str, famstr))
                counter=''
                name = ''
            count += 1
        return count
        
    def remarks(self, msg_list, inlaw=False):
        if msg_list :
            sdoc = self.sdoc
            sdoc.paragraph("")
            if inlaw:
                sdoc.header1(_("Remarks with inlaw family"))
            else:
                sdoc.header1(_("Remarks"))
            sdoc.paragraph("")
            sdoc.paragraph(_("The following problems were encountered:"))
            
            map(sdoc.paragraph, msg_list)
            sdoc.paragraph("")
            sdoc.paragraph("")