Ejemplo n.º 1
0
 def paste(self):
     md = QApplication.instance().clipboard().mimeData()
     if md.hasFormat(self.MIME_TYPE):
         self.setDateTime(
             QDateTime.fromString(
                 md.data(self.MIME_TYPE).data().decode('ascii'),
                 Qt.DateFormat.ISODate))
     else:
         self.lineEdit().paste()
Ejemplo n.º 2
0
def render_bookmark_as_text(b, lines, as_markdown=False, link_prefix=None):
    lines.append(b['title'])
    date = QDateTime.fromString(b['timestamp'], Qt.DateFormat.ISODate).toLocalTime().toString(Qt.DateFormat.SystemLocaleShortDate)
    if as_markdown and link_prefix and b['pos_type'] == 'epubcfi':
        link = (link_prefix + quote(b['pos'])).replace(')', '%29')
        date = f'[{date}]({link})'
    lines.append(date)
    lines.append('')
    if as_markdown:
        lines.append('-' * 20)
    else:
        lines.append('───')
    lines.append('')
Ejemplo n.º 3
0
def render_highlight_as_text(hl, lines, as_markdown=False, link_prefix=None):
    lines.append(hl['highlighted_text'])
    date = QDateTime.fromString(hl['timestamp'], Qt.DateFormat.ISODate).toLocalTime().toString(Qt.DateFormat.SystemLocaleShortDate)
    if as_markdown and link_prefix:
        cfi = hl['start_cfi']
        spine_index = (1 + hl['spine_index']) * 2
        link = (link_prefix + quote(f'epubcfi(/{spine_index}{cfi})')).replace(')', '%29')
        date = f'[{date}]({link})'
    lines.append(date)
    notes = hl.get('notes')
    if notes:
        lines.append('')
        lines.append(notes)
    lines.append('')
    if as_markdown:
        lines.append('-' * 20)
    else:
        lines.append('───')
    lines.append('')
Ejemplo n.º 4
0
    def show_result(self, result_or_none):
        self.current_result = r = result_or_none
        if r is None:
            self.set_controls_visibility(False)
            return
        self.set_controls_visibility(True)
        db = current_db()
        book_id = r['book_id']
        title, authors = db.field_for('title', book_id), db.field_for(
            'authors', book_id)
        authors = authors_to_string(authors)
        series, sidx = db.field_for('series', book_id), db.field_for(
            'series_index', book_id)
        series_text = ''
        if series:
            use_roman_numbers = config['use_roman_numerals_for_series_number']
            series_text = f'{fmt_sidx(sidx, use_roman=use_roman_numbers)} of {series}'
        annot = r['annotation']
        atype = annotation_title(annot['type'], singular=True)
        book_format = r['format']
        annot_text = ''
        a = prepare_string_for_xml
        highlight_css = ''

        paras = []

        def p(text, tag='p'):
            paras.append('<{0}>{1}</{0}>'.format(tag, a(text)))

        if annot['type'] == 'bookmark':
            p(annot['title'])
        elif annot['type'] == 'highlight':
            for line in annot['highlighted_text'].splitlines():
                p(line)
            notes = annot.get('notes')
            if notes:
                paras.append(
                    '<h4>{} (<a title="{}" href="calibre://edit_result">{}</a>)</h4>'
                    .format(_('Notes'), _('Edit the notes of this highlight'),
                            _('Edit')))
                paras.extend(render_notes(notes))
            else:
                paras.append(
                    '<p><a title="{}" href="calibre://edit_result">{}</a></p>'.
                    format(_('Add notes to this highlight'), _('Add notes')))
            if 'style' in annot:
                highlight_css = css_for_highlight_style(annot['style'])

        annot_text += '\n'.join(paras)
        date = QDateTime.fromString(
            annot['timestamp'], Qt.DateFormat.ISODate).toLocalTime().toString(
                Qt.DateFormat.SystemLocaleShortDate)

        text = '''
        <style>a {{ text-decoration: none }}</style>
        <h2 style="text-align: center">{title} [{book_format}]</h2>
        <div style="text-align: center">{authors}</div>
        <div style="text-align: center">{series}</div>
        <div>&nbsp;</div>
        <div>&nbsp;</div>

        <div>{dt}: {date}</div>
        <div>{ut}: {user}</div>
        <div>
            <a href="calibre://open_result" title="{ovtt}" style="margin-right: 20px">{ov}</a>
            <span>\xa0\xa0\xa0</span>
            <a title="{sictt}" href="calibre://show_in_library">{sic}</a>
        </div>
        <h3 style="text-align: left; {highlight_css}">{atype}</h3>
        {text}
        '''.format(
            title=a(title),
            authors=a(authors),
            series=a(series_text),
            book_format=a(book_format),
            atype=a(atype),
            text=annot_text,
            dt=_('Date'),
            date=a(date),
            ut=a(_('User')),
            user=a(friendly_username(r['user_type'], r['user'])),
            highlight_css=highlight_css,
            ov=a(_('Open in viewer')),
            sic=a(_('Show in calibre')),
            ovtt=a(
                _('Open the book at this annotation in the calibre E-book viewer'
                  )),
            sictt=(_('Show this book in the main calibre book list')),
        )
        self.text_browser.setHtml(text)