Пример #1
0
    def write_report(self):
        """ Generate the contents of the report """
        self.doc.start_paragraph('SBT-Title')
        self.doc.write_text(self.title_string)
        self.doc.end_paragraph()

        self.doc.start_paragraph('SBT-Subtitle')
        self.doc.write_text(self.subtitle_string)
        self.doc.end_paragraph()

        if self.media_id:
            the_object = self.database.get_media_from_gid(self.media_id)
            filename = media_path_full(self.database, the_object.get_path())
            if os.path.exists(filename):
                if self.image_size:
                    image_size = self.image_size
                else:
                    image_size = min(0.8 * self.doc.get_usable_width(),
                                     0.7 * self.doc.get_usable_height())
                self.doc.add_media(filename, 'center', image_size, image_size)
            else:
                self._user.warn(_('Could not add photo to page'),
                                _('File %s does not exist') % filename)

        self.doc.start_paragraph('SBT-Footer')
        self.doc.write_text(self.footer_string)
        self.doc.end_paragraph()
Пример #2
0
 def get_image_path_from_handle(self, identifier):
     """
     Given an image handle, return the full path/filename.
     """
     from gprime.utils.file import media_path_full
     media = self.database.get_media_from_handle(identifier)
     if media:
         return media_path_full(self.database, media.get_path())
     return ""
Пример #3
0
    def summarize_media(self):
        """
        Write a summary of all the media in the database.
        """
        total_media = 0
        size_in_bytes = 0
        notfound = []

        self.doc.start_paragraph("SR-Heading")
        self.doc.write_text(self._("Media Objects"))
        self.doc.end_paragraph()

        total_media = len(self.__db.get_media_handles())
        mbytes = "0"
        for media_id in self.__db.get_media_handles():
            media = self.__db.get_media_from_handle(media_id)
            try:
                size_in_bytes += posixpath.getsize(
                    media_path_full(self.__db, media.get_path()))
                length = len(str(size_in_bytes))
                if size_in_bytes <= 999999:
                    mbytes = self._("less than 1")
                else:
                    mbytes = str(size_in_bytes)[:(length - 6)]
            except:
                notfound.append(media.get_path())

        self.doc.start_paragraph("SR-Normal")
        self.doc.write_text(
            self._("Number of unique media objects: %d") % total_media)
        self.doc.end_paragraph()

        self.doc.start_paragraph("SR-Normal")
        self.doc.write_text(
            self._("Total size of media objects: %s MB") % mbytes)
        self.doc.end_paragraph()

        if len(notfound) > 0:
            self.doc.start_paragraph("SR-Heading")
            self.doc.write_text(self._("Missing Media Objects"))
            self.doc.end_paragraph()

            for media_path in notfound:
                self.doc.start_paragraph("SR-Normal")
                self.doc.write_text(media_path)
                self.doc.end_paragraph()
Пример #4
0
    def write_people(self):
        """ write the people """

        self.doc.add_comment('')

        # If we're going to attempt to include images, then use the HTML style
        # of .gv file.
        use_html_output = False
        if self._incimages:
            use_html_output = True

        # loop through all the people we need to output
        for handle in sorted(self._people): # enable a diff
            person = self._db.get_person_from_handle(handle)
            name = self._name_display.display(person)
            p_id = person.get_gid()

            # figure out what colour to use
            gender = person.get_gender()
            colour = self._colorunknown
            if gender == Person.MALE:
                colour = self._colormales
            elif gender == Person.FEMALE:
                colour = self._colorfemales

            # see if we have surname colours that match this person
            surname = person.get_primary_name().get_surname()
            surname = surname.encode('iso-8859-1', 'xmlcharrefreplace')
            if surname in self._surnamecolors:
                colour = self._surnamecolors[surname]

            # see if we have a birth/death or fallback dates we can use
            if self._incdates or self._incplaces:
                bth_event = get_birth_or_fallback(self._db, person)
                dth_event = get_death_or_fallback(self._db, person)
            else:
                bth_event = None
                dth_event = None

            # output the birth or fallback event
            birth_str = None
            if bth_event and self._incdates:
                date = bth_event.get_date_object()
                if self._just_years and date.get_year_valid():
                    birth_str = '%i' % date.get_year()
                else:
                    birth_str = self._get_date(date)

            # get birth place (one of:  city, state, or country) we can use
            birthplace = None
            if bth_event and self._incplaces:
                birthplace = self.get_event_place(bth_event)

            # see if we have a deceased date we can use
            death_str = None
            if dth_event and self._incdates:
                date = dth_event.get_date_object()
                if self._just_years and date.get_year_valid():
                    death_str = '%i' % date.get_year()
                else:
                    death_str = self._get_date(date)

            # get death place (one of:  city, state, or country) we can use
            deathplace = None
            if dth_event and self._incplaces:
                deathplace = self.get_event_place(dth_event)

            # see if we have an image to use for this person
            image_path = None
            if self._incimages:
                media_list = person.get_media_list()
                if len(media_list) > 0:
                    media_handle = media_list[0].get_reference_handle()
                    media = self._db.get_media_from_handle(media_handle)
                    media_mime_type = media.get_mime_type()
                    if media_mime_type[0:5] == "image":
                        image_path = get_thumbnail_path(
                            media_path_full(self._db, media.get_path()),
                            rectangle=media_list[0].get_rectangle())

            # put the label together and output this person
            label = ""
            line_delimiter = '\\n'
            if use_html_output:
                line_delimiter = '<BR/>'

            # if we have an image, then start an HTML table;
            # remember to close the table afterwards!
            if image_path:
                label = ('<TABLE BORDER="0" CELLSPACING="2" CELLPADDING="0" '
                         'CELLBORDER="0"><TR><TD><IMG SRC="%s"/></TD>' %
                         image_path)
                if self._imageonside == 0:
                    label += '</TR><TR>'
                label += '<TD>'

            # at the very least, the label must have the person's name
            label += name
            if self.includeid == 1: # same line
                label += " (%s)" % p_id
            elif self.includeid == 2: # own line
                label += "%s(%s)" % (line_delimiter, p_id)

            if birth_str or death_str:
                label += '%s(' % line_delimiter
                if birth_str:
                    label += '%s' % birth_str
                label += ' - '
                if death_str:
                    label += '%s' % death_str
                label += ')'
            if birthplace or deathplace:
                if birthplace == deathplace:
                    deathplace = None    # no need to print the same name twice
                label += '%s' % line_delimiter
                if birthplace:
                    label += '%s' % birthplace
                if birthplace and deathplace:
                    label += ' / '
                if deathplace:
                    label += '%s' % deathplace

            # see if we have a table that needs to be terminated
            if image_path:
                label += '</TD></TR></TABLE>'

            shape = "box"
            style = "solid"
            border = colour
            fill = colour

            # do not use colour if this is B&W outline
            if self._colorize == 'outline':
                border = ""
                fill = ""

            if gender == person.FEMALE and self._useroundedcorners:
                style = "rounded"
            elif gender == person.UNKNOWN:
                shape = "hexagon"

            # if we're filling the entire node:
            if self._colorize == 'filled':
                style += ",filled"
                border = ""

            # we're done -- add the node
            self.doc.add_node(p_id,
                              label=label,
                              shape=shape,
                              color=border,
                              style=style,
                              fillcolor=fill,
                              htmloutput=use_html_output)
Пример #5
0
    def export(self):
        #        missmedia_action = 0
        #--------------------------------------------------------------
        # def remove_clicked():
        #     # File is lost => remove all references and the object itself
        #     for p_id in self.db.iter_family_handles():
        #         p = self.db.get_family_from_handle(p_id)
        #         nl = p.get_media_list()
        #         for o in nl:
        #             if o.get_reference_handle() == m_id:
        #                 nl.remove(o)
        #         p.set_media_list(nl)
        #         self.db.commit_family(p,None)
        #     for key in self.db.iter_person_handles():
        #         p = self.db.get_person_from_handle(key)
        #         nl = p.get_media_list()
        #         for o in nl:
        #             if o.get_reference_handle() == m_id:
        #                 nl.remove(o)
        #         p.set_media_list(nl)
        #         self.db.commit_person(p,None)
        #     for key in self.db.get_source_handles():
        #         p = self.db.get_source_from_handle(key)
        #         nl = p.get_media_list()
        #         for o in nl:
        #             if o.get_reference_handle() == m_id:
        #                 nl.remove(o)
        #         p.set_media_list(nl)
        #         self.db.commit_source(p,None)
        #     for key in self.db.get_place_handles():
        #         p = self.db.get_place_from_handle(key)
        #         nl = p.get_media_list()
        #         for o in nl:
        #             if o.get_reference_handle() == m_id:
        #                 nl.remove(o)
        #         p.set_media_list(nl)
        #         self.db.commit_place(p,None)
        #     for key in self.db.get_event_handles():
        #         p = self.db.get_event_from_handle(key)
        #         nl = p.get_media_list()
        #         for o in nl:
        #             if o.get_reference_handle() == m_id:
        #                 nl.remove(o)
        #         p.set_media_list(nl)
        #         self.db.commit_event(p,None)
        #     self.db.remove_media(m_id,None)

        # def leave_clicked():
        #     # File is lost => do nothing, leave as is
        #     pass

        # def select_clicked():
        #     # File is lost => select a file to replace the lost one
        #     def fs_close_window(obj):
        #         pass

        #     def fs_ok_clicked(obj):
        #         name = fs_top.get_filename()
        #         if os.path.isfile(name):
        #             archive.add(name)

        #     fs_top = gtk.FileChooserDialog("%s - GRAMPS" % _("Select file"),
        #                 buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
        #                          gtk.STOCK_OK, Gtk.ResponseType.OK)
        #                 )
        #     response = fs_top.run()
        #     if response == Gtk.ResponseType.OK:
        #         fs_ok_clicked(fs_top)
        #     elif response == gtk.RESPONSE_CANCEL:
        #         fs_close_window(fs_top)

        #     fs_top.destroy()
        #---------------------------------------------------------------

        try:
            archive = tarfile.open(self.filename, 'w:gz')
        except EnvironmentError as msg:
            log.warning(str(msg))
            self.user.notify_error(
                _('Failure writing %s') % self.filename, str(msg))
            return 0

        # Write media files first, since the database may be modified
        # during the process (i.e. when removing object)
        for m_id in self.db.get_media_handles(sort_handles=True):
            mobject = self.db.get_media_from_handle(m_id)
            filename = media_path_full(self.db, mobject.get_path())
            archname = str(mobject.get_path())
            if os.path.isfile(filename) and os.access(filename, os.R_OK):
                archive.add(filename, archname)

        # Write XML now
        g = BytesIO()
        gfile = XmlWriter(self.db, self.user, 2)
        gfile.write_handle(g)
        tarinfo = tarfile.TarInfo('data.gramps')
        tarinfo.size = len(g.getvalue())
        tarinfo.mtime = time.time()
        if not win():
            tarinfo.uid = os.getuid()
            tarinfo.gid = os.getgid()
        g.seek(0)
        archive.addfile(tarinfo, g)
        archive.close()
        g.close()

        return True
Пример #6
0
    def get_person_label(self, person):
        "return person label string"
        # see if we have an image to use for this person
        image_path = None
        if self.use_html_output:
            media_list = person.get_media_list()
            if len(media_list) > 0:
                media_handle = media_list[0].get_reference_handle()
                media = self._db.get_media_from_handle(media_handle)
                media_mime_type = media.get_mime_type()
                if media_mime_type[0:5] == "image":
                    image_path = get_thumbnail_path(
                        media_path_full(self._db, media.get_path()),
                        rectangle=media_list[0].get_rectangle())
                    # test if thumbnail actually exists in thumbs
                    # (import of data means media files might not be present
                    image_path = find_file(image_path)

        label = ""
        line_delimiter = '\\n'

        # If we have an image, then start an HTML table; remember to close
        # the table afterwards!
        #
        # This isn't a free-form HTML format here...just a few keywords that
        # happen to be
        # similar to keywords commonly seen in HTML.  For additional
        # information on what
        # is allowed, see:
        #
        #       http://www.graphviz.org/info/shapes.html#html
        #
        if self.use_html_output and image_path:
            line_delimiter = '<BR/>'
            label += '<TABLE BORDER="0" CELLSPACING="2" CELLPADDING="0" '
            label += 'CELLBORDER="0"><TR><TD></TD><TD>'
            label += '<IMG SRC="%s"/></TD><TD></TD>' % image_path
            if self.imgpos == 0:
                #trick it into not stretching the image
                label += '</TR><TR><TD COLSPAN="3">'
            else:
                label += '<TD>'
        else:
            #no need for html label with this person
            self.use_html_output = False

        # at the very least, the label must have the person's name
        p_name = self._name_display.display(person)
        if self.use_html_output:
            # avoid < and > in the name, as this is html text
            label += p_name.replace('<', '&#60;').replace('>', '&#62;')
        else:
            label += p_name
        p_id = person.get_gid()
        if self.includeid == 1:  # same line
            label += " (%s)" % p_id
        elif self.includeid == 2:  # own line
            label += "%s(%s)" % (line_delimiter, p_id)
        if self.event_choice != 0:
            b_date, d_date, b_place, d_place, b_type, d_type = \
                self.get_event_strings(person)
            if self.event_choice in [1, 2, 3, 4, 5] and (b_date or d_date):
                label += '%s(' % line_delimiter
                if b_date:
                    label += '%s' % b_date
                label += ' - '
                if d_date:
                    label += '%s' % d_date
                label += ')'
            if (self.event_choice in [2, 3, 5, 6] and (b_place or d_place)
                    and not (self.event_choice == 3 and (b_date or d_date))):
                label += '%s(' % line_delimiter
                if b_place:
                    label += '%s' % b_place
                label += ' - '
                if d_place:
                    label += '%s' % d_place
                label += ')'
        if self.event_choice == 7:
            if b_type:
                label += '%s%s' % (line_delimiter, b_type.get_abbreviation())
                if b_date:
                    label += ' %s' % b_date
                if b_place:
                    label += ' %s' % b_place

            if d_type:
                label += '%s%s' % (line_delimiter, d_type.get_abbreviation())
                if d_date:
                    label += ' %s' % d_date
                if d_place:
                    label += ' %s' % d_place

        if self.increlname and self.center_person != person:
            # display relationship info
            if self.advrelinfo:
                (relationship, _ga, _gb) = self.rel_calc.get_one_relationship(
                    self._db,
                    self.center_person,
                    person,
                    extra_info=True,
                    olocale=self._locale)
                if relationship:
                    label += "%s(%s Ga=%d Gb=%d)" % (line_delimiter,
                                                     relationship, _ga, _gb)
            else:
                relationship = self.rel_calc.get_one_relationship(
                    self._db, self.center_person, person, olocale=self._locale)
                if relationship:
                    label += "%s(%s)" % (line_delimiter, relationship)

        if self.occupation > 0:
            event_refs = person.get_primary_event_ref_list()
            events = [
                event for event in [
                    self._db.get_event_from_handle(ref.ref)
                    for ref in event_refs
                ] if event.get_type() == EventType(EventType.OCCUPATION)
            ]
            if len(events) > 0:
                events.sort(key=lambda x: x.get_date_object())
                if self.occupation == 1:
                    occupation = events[-1].get_description()
                    if occupation:
                        label += "%s(%s)" % (line_delimiter, occupation)
                elif self.occupation == 2:
                    for evt in events:
                        date = self.get_date_string(evt)
                        place = self.get_place_string(evt)
                        desc = evt.get_description()
                        if not date and not desc and not place:
                            continue
                        label += '%s(' % line_delimiter
                        if date:
                            label += '%s' % date
                            if desc:
                                label += ' '
                        if desc:
                            label += '%s' % desc
                        if place:
                            if date or desc:
                                label += ', '
                            label += '%s' % place
                        label += ')'

        # see if we have a table that needs to be terminated
        if self.use_html_output:
            label += '</TD></TR></TABLE>'
            return label
        else:
            # non html label is enclosed by "" so escape other "
            return label.replace('"', '\\\"')
Пример #7
0
    def write_person(self, count):
        """ write a person """
        if count != 0:
            self.doc.page_break()
        self.bibli = Bibliography(
            Bibliography.MODE_DATE|Bibliography.MODE_PAGE)

        title1 = self._("Complete Individual Report")
        text2 = self._name_display.display(self.person)
        mark1 = IndexMark(title1, INDEX_TYPE_TOC, 1)
        mark2 = IndexMark(text2, INDEX_TYPE_TOC, 2)
        self.doc.start_paragraph("IDS-Title")
        self.doc.write_text(title1, mark1)
        self.doc.end_paragraph()
        self.doc.start_paragraph("IDS-Title")
        self.doc.write_text(text2, mark2)
        self.doc.end_paragraph()

        self.doc.start_paragraph("IDS-Normal")
        self.doc.end_paragraph()

        name = self.person.get_primary_name()
        text = self.get_name(self.person)
        mark = utils.get_person_mark(self._db, self.person)
        endnotes = self._cite_endnote(self.person)
        endnotes = self._cite_endnote(name, prior=endnotes)

        family_handle = self.person.get_main_parents_family_handle()
        if family_handle:
            family = self._db.get_family_from_handle(family_handle)
            father_inst_id = family.get_father_handle()
            if father_inst_id:
                father_inst = self._db.get_person_from_handle(
                    father_inst_id)
                father = self.get_name(father_inst)
                fmark = utils.get_person_mark(self._db, father_inst)
            else:
                father = ""
                fmark = None
            mother_inst_id = family.get_mother_handle()
            if mother_inst_id:
                mother_inst = self._db.get_person_from_handle(mother_inst_id)
                mother = self.get_name(mother_inst)
                mmark = utils.get_person_mark(self._db, mother_inst)
            else:
                mother = ""
                mmark = None
        else:
            father = ""
            fmark = None
            mother = ""
            mmark = None

        media_list = self.person.get_media_list()
        p_style = 'IDS-PersonTable2'
        self.mime0 = None
        if self.use_images and len(media_list) > 0:
            media0 = media_list[0]
            media_handle = media0.get_reference_handle()
            media = self._db.get_media_from_handle(media_handle)
            self.mime0 = media.get_mime_type()
            if self.mime0 and self.mime0.startswith("image"):
                image_filename = media_path_full(self._db, media.get_path())
                if os.path.exists(image_filename):
                    p_style = 'IDS-PersonTable' # this is tested for, also
                else:
                    self._user.warn(_("Could not add photo to page"),
                                    # translators: for French, else ignore
                                    _("%(str1)s: %(str2)s"
                                     ) % {'str1' : image_filename,
                                          'str2' : _('File does not exist')})

        self.doc.start_table('person', p_style)
        self.doc.start_row()

        # translators: needed for French, ignore otherwise
        ignore = self._("%s:")
        self.doc.start_cell('IDS-NormalCell')
        self.write_paragraph(self._("%s:") % self._("Name"))
        self.write_paragraph(self._("%s:") % self._("Gender"))
        self.write_paragraph(self._("%s:") % self._("Father"))
        self.write_paragraph(self._("%s:") % self._("Mother"))
        self.doc.end_cell()

        self.doc.start_cell('IDS-NormalCell')
        self.write_paragraph(text, endnotes, mark)
        if self.person.get_gender() == Person.MALE:
            self.write_paragraph(self._("Male"))
        elif self.person.get_gender() == Person.FEMALE:
            self.write_paragraph(self._("Female"))
        else:
            self.write_paragraph(self._("Unknown"))
        self.write_paragraph(father, mark=fmark)
        self.write_paragraph(mother, mark=mmark)
        self.doc.end_cell()

        if p_style == 'IDS-PersonTable':
            self.doc.start_cell('IDS-NormalCell')
            self.doc.add_media(image_filename, "right", 4.0, 4.0,
                               crop=media0.get_rectangle())
            endnotes = self._cite_endnote(media0)
            attr_list = media0.get_attribute_list()
            if len(attr_list) == 0 or not self.use_attrs:
                text = _('(image)')
            else:
                for attr in attr_list:
                    attr_type = attr.get_type().type2base()
                    # translators: needed for French, ignore otherwise
                    text = self._("%(str1)s: %(str2)s"
                                 ) % {'str1' : self._(attr_type),
                                      'str2' : attr.get_value()}
                    endnotes = self._cite_endnote(attr, prior=endnotes)
                    self.write_paragraph("(%s)" % text,
                                         endnotes=endnotes,
                                         style='IDS-ImageNote')
                    endnotes = ''
            if endnotes and len(attr_list) == 0:
                self.write_paragraph(text, endnotes=endnotes,
                                     style='IDS-ImageNote')
            self.doc.end_cell()

        self.doc.end_row()
        self.doc.end_table()

        self.doc.start_paragraph("IDS-Normal")
        self.doc.end_paragraph()

        self.write_alt_names()
        self.write_events()
        self.write_alt_parents()
        self.write_families()
        self.write_addresses()
        self.write_associations()
        self.write_attributes()
        self.write_LDS_ordinances()
        self.write_tags()
        self.write_images()
        self.write_note()
        if self.use_srcs:
            if self.use_pagebreak and self.bibli.get_citation_count():
                self.doc.page_break()
            Endnotes.write_endnotes(self.bibli, self._db, self.doc,
                                    printnotes=self.use_src_notes,
                                    elocale=self._locale)
Пример #8
0
def get_image_path_from_media(database, media):
    from gprime.utils.file import media_path_full
    if media:
        return media_path_full(database, media.get_path())
    return ""