def render_bookmark_as_text(b, lines): lines.append(b['title']) date = QDateTime.fromString(b['timestamp'], Qt.DateFormat.ISODate).toLocalTime().toString(Qt.DateFormat.SystemLocaleShortDate) lines.append(date) lines.append('') lines.append('───') lines.append('')
def paste(self): md = QApplication.instance().clipboard().mimeData() if md.hasFormat(self.MIME_TYPE): self.date_time_pasted.emit( QDateTime.fromString( md.data(self.MIME_TYPE).data().decode('ascii'), Qt.ISODate)) else: QLineEdit.paste(self)
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()
def render_highlight_as_text(hl, lines): lines.append(hl['highlighted_text']) date = QDateTime.fromString(hl['timestamp'], Qt.DateFormat.ISODate).toLocalTime().toString(Qt.DateFormat.SystemLocaleShortDate) lines.append(date) notes = hl.get('notes') if notes: lines.append('') lines.append(notes) lines.append('') lines.append('───') lines.append('')
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('')
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('')
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 = '{0} of {1}'.format( fmt_sidx(sidx, use_roman=use_roman_numbers), series) annot = r['annotation'] atype = annotation_title(annot['type'], singular=True) book_format = r['format'] annot_text = '' a = prepare_string_for_xml 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': p(annot['highlighted_text']) 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'))) annot_text += '\n'.join(paras) date = QDateTime.fromString(annot['timestamp'], Qt.ISODate).toLocalTime().toString( Qt.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> </div> <div> </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> <h2 style="text-align: left">{atype}</h2> {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'])), ov=a(_('Open in viewer')), sic=a(_('Show in calibre')), ovtt=a( _('Open the book at this annotation in the calibre viewer')), sictt=(_('Show this book in the main calibre book list')), ) self.text_browser.setHtml(text)