Exemple #1
0
    def build_header(self):
        """
        Build up the header of the html file over the defaults of Html()
        """
        # add additional meta tags and stylesheet links to head section
        # create additional meta tags
        _meta1 = 'name="generator" content="%s %s %s"' % (
            const.PROGRAM_NAME, const.VERSION, const.URL_HOMEPAGE)
        meta = Html('meta', attr=_meta1)

        #set styles of the report as inline css
        self.build_style_declaration()

        # GRAMPS favicon en css
        fname1 = '/'.join([self._backend.datadir(), 'favicon.ico'])
        fname2 = '/'.join([self._backend.datadir(), _TEXTDOCSCREEN])
        fname3 = '/'.join([self._backend.datadir(), _HTMLSCREEN])

        # links for GRAMPS favicon and stylesheets
        links = Html(
            'link', rel='shortcut icon', href=fname1,
            type='image/x-icon') + (Html('link',
                                         rel='stylesheet',
                                         href=fname2,
                                         type='text/css',
                                         media='screen',
                                         indent=False), )
        if self.css_filename:
            links += (Html('link',
                           rel='stylesheet',
                           href=fname3,
                           type='text/css',
                           media='screen',
                           indent=False), )
        self._backend.html_header += (meta, links)
Exemple #2
0
 def start_cell(self, style_name, span=1):
     """
     Overwrite base method
     """
     self._empty = 1
     if span > 1:
         self.htmllist += (Html('td', colspan=str(span),
                                class_=style_name), )
         self._col += span
     else:
         self.htmllist += (Html(
             'td',
             colspan=str(span),
             width=str(self._tbl.get_column_width(self._col)) + '%',
             class_=style_name), )
     self._col += 1
Exemple #3
0
    def add_media_object(self,
                         name,
                         pos,
                         w_cm,
                         h_cm,
                         alt='',
                         style_name=None,
                         crop=None):
        """
        Overwrite base method
        """
        self._empty = 0
        size = int(max(w_cm, h_cm) * float(150.0 / 2.54))
        refname = "is%s" % os.path.basename(name)

        imdir = self._backend.datadirfull()

        try:
            ImgManip.resize_to_jpeg(name,
                                    imdir + os.sep + refname,
                                    size,
                                    size,
                                    crop=crop)
        except:
            LOG.warn(
                _("Could not create jpeg version of image %(name)s") %
                {'name': name})
            return

        if len(alt):
            alt = '<br />'.join(alt)

        if pos not in ["right", "left"]:
            if len(alt):
                self.htmllist[-1] += Html('div') + (Html(
                    'img', src=imdir + os.sep + refname, border='0',
                    alt=alt), Html('p', class_="DDR-Caption") + alt)
            else:
                self.htmllist[-1] += Html('img',
                                          src=imdir + os.sep + refname,
                                          border='0',
                                          alt=alt)
        else:
            if len(alt):
                self.htmllist[-1] += Html(
                    'div', style_="float: %s; padding: 5px; margin: 0;" % pos
                ) + (Html(
                    'img', src=imdir + os.sep + refname, border='0',
                    alt=alt), Html('p', class_="DDR-Caption") + alt)
            else:
                self.htmllist[-1] += Html('img',
                                          src=imdir + os.sep + refname,
                                          border='0',
                                          alt=alt,
                                          align=pos)
Exemple #4
0
 def start_table(self, name, style):
     """
     Overwrite base method
     """
     styles = self.get_style_sheet()
     self._tbl = styles.get_table_style(style)
     self.htmllist += [
         Html('table',
              width=str(self._tbl.get_width()) + '%',
              cellspacing='0')
     ]
Exemple #5
0
    def open(self, filename):
        """
        Overwrite base method
        """
        self._backend = HtmlBackend(filename)
        self._backend.open()
        self.htmllist += [self._backend.html_body]
        #start a gramps report
        self.htmllist += [Html('div', id="grampstextdoc")]

        self.build_header()
Exemple #6
0
 def start_paragraph(self, style_name, leader=None):
     """
     Overwrite base method
     """
     style_sheet = self.get_style_sheet()
     style = style_sheet.get_paragraph_style(style_name)
     level = style.get_header_level()
     if level == 0:
         #a normal paragraph
         self.htmllist += (Html('p', class_=style_name, inline=True), )
     elif level == 1:
         if self.__title_written == -1 and \
                 style_name.upper().find('TITLE') != -1:
             self.__title_written = 0
             self.htmllist += (Html('div', id="header"), )
             self.htmllist += (Html('h1',
                                    class_=style_name,
                                    id='SiteTitle',
                                    inline=True), )
         else:
             self.htmllist += (Html('h1', class_=style_name, inline=True), )
     elif 2 <= level <= 5:
         tag = 'h' + str(level + 1)
         self.htmllist += (Html(tag, class_=style_name, inline=True), )
     else:
         # a low level header
         self.htmllist += (Html('div',
                                id='grampsheading',
                                class_=style_name), )
     if leader is not None:
         self.write_text(leader + ' ')
Exemple #7
0
                                 self._filename, msg)
            raise Errors.ReportError(errmsg)
        except:
            raise Errors.ReportError(_("Could not create %s") %
                                     self._filename)
        if not os.path.isdir(self.datadirfull()): 
            try:
                os.mkdir(self.datadirfull())
            except IOError,msg:
                errmsg = "%s\n%s" % (_("Could not create %s") %
                                     self.datadirfull(), msg)
                raise Errors.ReportError(errmsg)
            except:
                raise Errors.ReportError(_("Could not create %s") %
                                         self.datadirfull())
        self.html_page, self.html_header, self.html_body = Html.page(
                        lang=xml_lang(), title=self.title)

    def __write(self, string):
        """ a write to the file
        """
        DocBackend.write(self, string + '\n')

    def write(self, obj):
        """ write to the html page. One can pass a html object, or a string
        """
        self.html_body += obj
        
    def close(self):
        """
        write out the html to the page
        """
Exemple #8
0
 def start_underline(self):
     """
     Starts a section of underlining.
     """
     self.htmllist += [Html('u')]
Exemple #9
0
 def start_link(self, link):
     """
     Starts a section to add a link. Link is a URI.
     """
     self.htmllist += [Html('a', href=link)]
Exemple #10
0
    def write_styled_note(self,
                          styledtext,
                          format,
                          style_name,
                          contains_html=False,
                          links=False):
        """
        Convenience function to write a styledtext to the html doc. 
        styledtext : assumed a StyledText object to write
        format : = 0 : Flowed, = 1 : Preformatted
        style_name : name of the style to use for default presentation
        contains_html: bool, the backend should not check if html is present. 
            If contains_html=True, then the textdoc is free to handle that in 
            some way. Eg, a textdoc could remove all tags, or could make sure
            a link is clickable. HtmlDoc will show the html as pure text, so 
            no escaping will happen.
        links: bool, make URLs clickable if True
        """
        text = str(styledtext)

        self.htmllist += [Html('div', id='grampsstylednote')]
        if contains_html:
            #just dump the note out as it is. Adding markup would be dangerous
            # as it could destroy the html. If html code, one can do the
            self.start_paragraph(style_name)
            self.__write_text(text, markup=True, links=links)
            self.end_paragraph()
        else:
            s_tags = styledtext.get_tags()
            markuptext = self._backend.add_markup_from_styled(text,
                                                              s_tags,
                                                              split='\n')
            self.start_paragraph(style_name)
            inpara = True
            self._empty = 1  # para is empty
            # we explicitly set _empty because start and end para do not seem
            # to do a very good job at setting them
            linenb = 1
            # The code is tricky here, because we don't want to start a new para
            # at the end of the last line if there is no newline there.
            # Instead, we want to just end the current para.
            for line in markuptext.split('\n'):
                [line, sigcount] = process_spaces(line, format)
                if sigcount == 0:
                    if inpara == False:
                        # needed for runs of three or more newlines
                        self.start_paragraph(style_name)
                        inpara = True
                        self._empty = 1  # para is empty
                    self.end_paragraph()
                    inpara = False
                    linenb = 1
                else:
                    if inpara == False:
                        self.start_paragraph(style_name)
                        inpara = True
                        self._empty = 1  # para is empty
                    if linenb > 1:
                        self.htmllist[-1] += Html('br')
                    self.__write_text(line, markup=True, links=links)
                    self._empty = 0  # para is not empty
                    linenb += 1
            if inpara == True:
                self.end_paragraph()
            if sigcount == 0:
                # if the last line was blank, then as well as outputting the previous para,
                # which we have just done,
                # we also output a new blank para
                self.start_paragraph(style_name)
                self._empty = 1  # para is empty
                self.end_paragraph()
        #end div element
        self.__reduce_list()
Exemple #11
0
 def start_superscript(self):
     """
     Overwrite base method
     """
     self.htmllist += [Html('sup')]
Exemple #12
0
 def start_bold(self):
     """
     Overwrite base method
     """
     self.htmllist += [Html('strong')]
Exemple #13
0
 def start_row(self):
     """
     Overwrite base method
     """
     self.htmllist += [Html('tr')]
     self._col = 0
Exemple #14
0
 def write_title(self):
     """
     Add title field to header
     """
     self._backend.html_header += Html('title', self.title, inline=True)