def __init__(self, log, parent=None): QDialog.__init__(self, parent) self.log = log self.l = l = QVBoxLayout() self.setLayout(l) self.tb = QTextBrowser(self) l.addWidget(self.tb) self.bb = QDialogButtonBox(QDialogButtonBox.Close) l.addWidget(self.bb) self.copy_button = self.bb.addButton(_('Copy to clipboard'), self.bb.ActionRole) self.copy_button.clicked.connect(self.copy_to_clipboard) self.copy_button.setIcon(QIcon(I('edit-copy.png'))) self.bb.rejected.connect(self.reject) self.bb.accepted.connect(self.accept) self.setWindowTitle(_('Download log')) self.setWindowIcon(QIcon(I('debug.png'))) self.resize(QSize(800, 400)) self.keep_updating = True self.last_html = None self.finished.connect(self.stop) QTimer.singleShot(100, self.update_log) self.show()
def __init__(self, parent=None): QSplitter.__init__(self, parent) self.setChildrenCollapsible(False) self.items = i = QListWidget(self) i.setContextMenuPolicy(Qt.CustomContextMenu) i.customContextMenuRequested.connect(self.context_menu) self.items.setSpacing(3) self.items.itemDoubleClicked.connect(self.current_item_activated) self.items.currentItemChanged.connect(self.current_item_changed) self.items.setSelectionMode(self.items.NoSelection) self.delegate = Delegate(self.items) self.items.setItemDelegate(self.delegate) self.addWidget(i) self.help = h = QTextBrowser(self) h.anchorClicked.connect(self.link_clicked) h.setOpenLinks(False) self.addWidget(h) self.setStretchFactor(0, 100) self.setStretchFactor(1, 50) self.clear_at_startup() state = tprefs.get('check-book-splitter-state', None) if state is not None: self.restoreState(state)
def show_report(changed, title, report, parent, show_current_diff): report = format_report(title, report) d = QDialog(parent) d.setWindowTitle(_('Action report')) d.l = QVBoxLayout() d.setLayout(d.l) d.e = QTextBrowser(d) d.l.addWidget(d.e) d.e.setHtml(report) d.bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Close) d.show_changes = False if changed: b = d.b = d.bb.addButton(_('See what &changed'), d.bb.AcceptRole) b.setIcon(QIcon(I('diff.png'))), b.setAutoDefault(False) connect_lambda(b.clicked, d, lambda d: setattr(d, 'show_changes', True)) b = d.bb.addButton(_('&Copy to clipboard'), d.bb.ActionRole) b.setIcon(QIcon(I('edit-copy.png'))), b.setAutoDefault(False) def copy_report(): text = re.sub(r'</.+?>', '\n', report) text = re.sub(r'<.+?>', '', text) cp = QApplication.instance().clipboard() cp.setText(text) b.clicked.connect(copy_report) d.bb.button(d.bb.Close).setDefault(True) d.l.addWidget(d.bb) d.bb.rejected.connect(d.reject) d.bb.accepted.connect(d.accept) d.resize(600, 400) d.exec_() b.clicked.disconnect() if d.show_changes: show_current_diff(allow_revert=True)
def __init__(self, parent): QWidget.__init__(self, parent) self._text_edit = CodeTextEdit(self) self._output_pane = QTextBrowser(self) self._output_pane.document().setDefaultFont(QFont('Courier', pointSize=7)) self._output_pane.setWordWrapMode(QTextOption.NoWrap) self._output_pane_container = QWidget(self) self._output_pane_layout = QGridLayout(self._output_pane_container) self._output_pane_layout.setContentsMargins(0, 16, 0, 0) self._output_pane_layout.addWidget(QLabel(self.tr('Script Output')), 0, 0) self._output_pane_layout.addWidget(self._output_pane) self._splitter = QSplitter(Qt.Vertical, self) self._splitter.addWidget(self._text_edit) self._splitter.addWidget(self._output_pane_container) self._splitter.setStretchFactor(0, 3) self._splitter.setStretchFactor(1, 1) self._layout = QGridLayout(self) self._layout.setContentsMargins(0, 0, 0, 0) self._layout.addWidget(self._splitter, 0, 0) self._text_edit.editComplete.connect(self.editComplete)
def __init__(self, title, html, parent=None): ''' :param title: Caption for window title :param html: HTML string log/report ''' QDialog.__init__(self, parent) self.l = l = QVBoxLayout() self.setLayout(l) self.tb = QTextBrowser(self) QApplication.setOverrideCursor(Qt.WaitCursor) # Rather than formatting the text in <pre> blocks like the calibre # ViewLog does, instead just format it inside divs to keep style formatting html = html.replace( '\t', ' ') #.replace('\n', '<br/>') html = html.replace('> ', '> ') self.tb.setHtml('<div>{0}</div>'.format(html)) QApplication.restoreOverrideCursor() l.addWidget(self.tb) self.bb = QDialogButtonBox(QDialogButtonBox.Ok) self.bb.accepted.connect(self.accept) self.bb.rejected.connect(self.reject) self.copy_button = self.bb.addButton(_('Copy to clipboard'), self.bb.ActionRole) self.copy_button.setIcon(QIcon(I('edit-copy.png'))) self.copy_button.clicked.connect(self.copy_to_clipboard) l.addWidget(self.bb) self.setModal(False) self.resize(QSize(700, 500)) self.setWindowTitle(title) self.setWindowIcon(QIcon(I('dialog_information.png'))) self.show()
def __init__(self, metadata, parent=None): QDialog.__init__(self, parent=parent) self.setWindowFlags(Qt.Window) buttonBox = QDialogButtonBox(QDialogButtonBox.Close) origbrowser = QTextBrowser() origbrowser.setText('') origbrowser.setReadOnly(True) browser = QTextBrowser() browser.setText('') browser.setReadOnly(True) gpbox2 = QGroupBox('Metadata: Original') lay2 = QHBoxLayout() gpbox2.setLayout(lay2) lay2.addWidget(origbrowser) gpbox4 = QGroupBox('Metadata: After scrambling') lay4 = QHBoxLayout() gpbox4.setLayout(lay4) lay4.addWidget(browser) splitter = QSplitter(Qt.Horizontal) splitter.addWidget(gpbox2) splitter.addWidget(gpbox4) splitter.setMinimumHeight(500) splitter.setMinimumWidth(1000) lay = QVBoxLayout() self.setLayout(lay) lay.addWidget(splitter) lay.addWidget(buttonBox) # create connect signals/slots buttonBox.rejected.connect(self.reject) metaorig = metadata.get('orig', '') metaorig = re.sub(r'\n\s*', r'\n ', metaorig) origbrowser.setText(metaorig) browser.setText(metadata.get('scramb', '')) self.setWindowTitle('%s: Metadata' % CAPTION) if not 'scramb' in metadata: gpbox4.setVisible(False)
def setup_ui(self): self.l = l = QVBoxLayout(self) self.splitter = s = QSplitter(self) s.setChildrenCollapsible(False) l.addWidget(s), l.addWidget(self.bb) self.bb.setStandardButtons(self.bb.Yes | self.bb.No) self.left = w = QWidget(self) s.addWidget(w) w.l = l = QVBoxLayout(w) l.setContentsMargins(0, 0, 0, 0) self.la = la = QLabel(self.msg) la.setWordWrap(True) l.addWidget(la) self.confirm = c = QCheckBox(_('Show this confirmation again'), self) c.setChecked(True) c.stateChanged.connect(self.toggle) l.addWidget(c) self.right = r = QTextBrowser(self) series = '' mi, fm = self.mi, field_metadata if mi.series: series = _('{num} of {series}').format( num=mi.format_series_index(), series='<i>%s</i>' % mi.series) r.setHtml(''' <h3 style="text-align:center">{mb}</h3> <p><b>{title}</b> - <i>{authors}</i><br></p> <table> <tr><td>{fm[timestamp][name]}:</td><td>{date}</td></tr> <tr><td>{fm[pubdate][name]}:</td><td>{published}</td></tr> <tr><td>{fm[formats][name]}:</td><td>{formats}</td></tr> <tr><td>{fm[series][name]}:</td><td>{series}</td></tr> </table> '''.format(mb=_('Target book'), title=mi.title, authors=authors_to_string(mi.authors), date=format_date(mi.timestamp, tweaks['gui_timestamp_display_format']), fm=fm, published=(format_date(mi.pubdate, tweaks['gui_pubdate_display_format']) if mi.pubdate else ''), formats=', '.join(mi.formats or ()), series=series)) s.addWidget(r)
def __init__(self, derrors, parent=None): QDialog.__init__(self, parent=parent) self.setWindowFlags(Qt.Window) self.derrors = derrors buttonBox = QDialogButtonBox(QDialogButtonBox.Close) browser = QTextBrowser() browser.setText('') browser.setFontFamily("Courier") browser.setFontWeight(QFont.Bold) browser.setLineWrapMode(QTextBrowser.NoWrap) browser.setReadOnly(True) self.ctc_button = QPushButton('Copy to clipboard') self.ctc_button.setMaximumWidth(100) gpbox2 = QGroupBox() lay2 = QHBoxLayout() gpbox2.setLayout(lay2) lay2.addWidget(browser) gpbox2.setMinimumHeight(500) gpbox2.setMinimumWidth(1000) lay = QVBoxLayout() self.setLayout(lay) lay.addWidget(gpbox2) lay.addWidget(self.ctc_button) lay.addWidget(buttonBox) buttonBox.rejected.connect(self.reject) self.ctc_button.clicked.connect(self.copy_to_clipboard) self.setWindowTitle('%s: Calibre error checks' % CAPTION) if 'scramb' in self.derrors: msg = 'Original vs. After scrambling' else: msg = 'Original - ebook not yet scrambled' gpbox2.setTitle(msg) self.report = self.summarise_errors() browser.setText(self.report)
def setup_ui(self): self.l = l = QVBoxLayout(self) if self.html_view: self.tb = w = QTextBrowser(self) else: self.log = w = QPlainTextEdit(self) w.setReadOnly(True), w.setLineWrapMode(w.NoWrap) l.addWidget(w) l.addWidget(self.bb) self.bb.clear(), self.bb.setStandardButtons(self.bb.Close) self.next_pos = 0 self.update() self.timer = QTimer(self) self.timer.timeout.connect(self.update) self.timer.start(1000) if not self.html_view: v = self.log.verticalScrollBar() v.setValue(v.maximum())
def show_report(changed, title, report, parent, show_current_diff): report = format_report(title, report) d = QDialog(parent) d.l = QVBoxLayout() d.setLayout(d.l) d.e = QTextBrowser(d) d.l.addWidget(d.e) d.e.setHtml(report) d.bb = QDialogButtonBox(QDialogButtonBox.Close) if changed: b = d.b = d.bb.addButton(_('See what &changed'), d.bb.AcceptRole) b.setIcon(QIcon(I('diff.png'))), b.setAutoDefault(False) b.clicked.connect(partial(show_current_diff, allow_revert=True)) d.bb.button(d.bb.Close).setDefault(True) d.l.addWidget(d.bb) d.bb.rejected.connect(d.reject) d.bb.accepted.connect(d.accept) d.resize(600, 400) d.exec_()
def __init__(self, title, html, parent=None): SizePersistedDialog.__init__(self, parent, 'epubsplit:view sample') self.l = l = QVBoxLayout() self.setLayout(l) self.tb = QTextBrowser(self) self.tb.setHtml(html) l.addWidget(self.tb) self.bb = QDialogButtonBox(QDialogButtonBox.Ok) self.bb.accepted.connect(self.accept) self.bb.rejected.connect(self.reject) l.addWidget(self.bb) self.setModal(False) self.setWindowTitle(title) self.setWindowIcon(get_icon('format-justify-fill.png')) # Cause our dialog size to be restored from prefs or created on first usage self.resize_dialog() self.show()
def setup_ui(self): self.l = l = QVBoxLayout(self) if self.html_view: self.tb = w = QTextBrowser(self) else: self.log = w = QPlainTextEdit(self) w.setReadOnly(True), w.setLineWrapMode(QPlainTextEdit.LineWrapMode.NoWrap) l.addWidget(w) l.addWidget(self.bb) self.bb.clear(), self.bb.setStandardButtons(QDialogButtonBox.StandardButton.Close) self.copy_button = b = self.bb.addButton(_('&Copy to clipboard'), QDialogButtonBox.ButtonRole.ActionRole) b.setIcon(QIcon(I('edit-copy.png'))) b.clicked.connect(self.copy_to_clipboard) self.next_pos = 0 self.update() self.timer = QTimer(self) self.timer.timeout.connect(self.update) self.timer.start(1000) if not self.html_view: v = self.log.verticalScrollBar() v.setValue(v.maximum())
def __init__(self, title, html, parent=None): QDialog.__init__(self, parent) self.l = l = QVBoxLayout() self.setLayout(l) self.tb = QTextBrowser(self) self.tb.setHtml('<pre style="font-family: monospace">%s</pre>' % html) l.addWidget(self.tb) self.bb = QDialogButtonBox(QDialogButtonBox.Ok) self.bb.accepted.connect(self.accept) self.bb.rejected.connect(self.reject) self.copy_button = self.bb.addButton(_('Copy to clipboard'), self.bb.ActionRole) self.copy_button.setIcon(QIcon(I('edit-copy.png'))) self.copy_button.clicked.connect(self.copy_to_clipboard) l.addWidget(self.bb) self.setModal(False) self.resize(QSize(700, 500)) self.setWindowTitle(title) self.setWindowIcon(QIcon(I('debug.png'))) self.show()
def __init__(self, parent=None): QWidget.__init__(self, parent) self.setFocusPolicy(Qt.NoFocus) self.l = l = QVBoxLayout(self) l.setContentsMargins(0, 0, 0, 0) self.search_input = si = SearchInput(self, 'highlights-search') si.do_search.connect(self.search_requested) l.addWidget(si) la = QLabel(_('Double click to jump to an entry')) la.setWordWrap(True) l.addWidget(la) self.highlights = h = Highlights(self) l.addWidget(h) h.jump_to_highlight.connect(self.jump_to_highlight) h.current_highlight_changed.connect(self.current_highlight_changed) self.load = h.load self.refresh = h.refresh self.h = h = QHBoxLayout() l.addLayout(h) def button(icon, text, tt, target): b = QPushButton(QIcon(I(icon)), text, self) b.setToolTip(tt) b.setFocusPolicy(Qt.NoFocus) b.clicked.connect(target) return b self.add_button = button('plus.png', _('Add'), _('Create a new highlight'), self.add_highlight) self.edit_button = button('edit_input.png', _('Edit'), _('Edit the selected highlight'), self.edit_highlight) self.remove_button = button('trash.png', _('Remove'), _('Remove the selected highlight'), self.remove_highlight) h.addWidget(self.add_button), h.addWidget(self.edit_button), h.addWidget(self.remove_button) self.notes_display = nd = QTextBrowser(self) l.addWidget(nd) nd.setVisible(False)
def setup_ui(self): self.pb = pb = QProgressBar(self) pb.setTextVisible(True) pb.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) pb.setRange(0, 0) self.w = w = QWidget(self) self.w.l = l = QVBoxLayout(w) l.addStretch(), l.addWidget(pb) self.w.la = la = QLabel(_('Checking external links, please wait...')) la.setStyleSheet('QLabel { font-size: 20px; font-weight: bold }') l.addWidget(la, 0, Qt.AlignCenter), l.addStretch() self.l = l = QVBoxLayout(self) self.results = QTextBrowser(self) self.results.setOpenLinks(False) self.results.anchorClicked.connect(self.anchor_clicked) self.stack = s = QStackedWidget(self) s.addWidget(w), s.addWidget(self.results) l.addWidget(s) l.addWidget(self.bb) self.bb.setStandardButtons(self.bb.Close) self.rb = b = self.bb.addButton(_('&Refresh'), self.bb.ActionRole) b.setIcon(QIcon(I('view-refresh.png'))) b.clicked.connect(self.refresh)
def __init__(self, gui, existing_names, editing=None): QDialog.__init__(self, gui) self.gui = gui self.existing_names = existing_names if editing: self.setWindowTitle(_('Edit virtual library')) else: self.setWindowTitle(_('Create virtual library')) self.setWindowIcon(QIcon(I('lt.png'))) gl = QGridLayout() self.setLayout(gl) self.la1 = la1 = QLabel(_('Virtual library &name:')) gl.addWidget(la1, 0, 0) self.vl_name = QComboBox() self.vl_name.setEditable(True) self.vl_name.lineEdit().setMaxLength(MAX_VIRTUAL_LIBRARY_NAME_LENGTH) la1.setBuddy(self.vl_name) gl.addWidget(self.vl_name, 0, 1) self.editing = editing self.saved_searches_label = sl = QTextBrowser(self) sl.viewport().setAutoFillBackground(False) gl.addWidget(sl, 2, 0, 1, 2) self.la2 = la2 = QLabel(_('&Search expression:')) gl.addWidget(la2, 1, 0) self.vl_text = QLineEdit() self.vl_text.textChanged.connect(self.search_text_changed) la2.setBuddy(self.vl_text) gl.addWidget(self.vl_text, 1, 1) self.vl_text.setText(_build_full_search_string(self.gui)) self.sl = sl = QLabel( '<p>' + _('Create a virtual library based on: ') + ('<a href="author.{0}">{0}</a>, ' '<a href="tag.{1}">{1}</a>, ' '<a href="publisher.{2}">{2}</a>, ' '<a href="series.{3}">{3}</a>, ' '<a href="search.{4}">{4}</a>.').format(_('Authors'), _( 'Tags'), _('Publishers'), _('Series'), _('Saved searches'))) sl.setWordWrap(True) sl.setTextInteractionFlags(Qt.LinksAccessibleByMouse) sl.linkActivated.connect(self.link_activated) gl.addWidget(sl, 3, 0, 1, 2) gl.setRowStretch(3, 10) self.hl = hl = QLabel( _(''' <h2>Virtual libraries</h2> <p>Using <i>virtual libraries</i> you can restrict calibre to only show you books that match a search. When a virtual library is in effect, calibre behaves as though the library contains only the matched books. The Tag browser display only the tags/authors/series/etc. that belong to the matched books and any searches you do will only search within the books in the virtual library. This is a good way to partition your large library into smaller and easier to work with subsets.</p> <p>For example you can use a Virtual library to only show you books with the Tag <i>"Unread"</i> or only books by <i>"My favorite author"</i> or only books in a particular series.</p> <p>More information and examples are available in the <a href="%s">User Manual</a>.</p> ''') % localize_user_manual_link( 'https://manual.calibre-ebook.com/virtual_libraries.html')) hl.setWordWrap(True) hl.setOpenExternalLinks(True) hl.setFrameStyle(hl.StyledPanel) gl.addWidget(hl, 0, 3, 4, 1) bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) gl.addWidget(bb, 4, 0, 1, 0) if editing: db = self.gui.current_db virt_libs = db.prefs.get('virtual_libraries', {}) for dex, vl in enumerate(sorted(virt_libs.keys(), key=sort_key)): self.vl_name.addItem(vl, virt_libs.get(vl, '')) if vl == editing: self.vl_name.setCurrentIndex(dex) self.original_index = dex self.original_search = virt_libs.get(editing, '') self.vl_text.setText(self.original_search) self.new_name = editing self.vl_name.currentIndexChanged[int].connect( self.name_index_changed) self.vl_name.lineEdit().textEdited.connect(self.name_text_edited) self.resize(self.sizeHint() + QSize(150, 25))
def __init__(self, pathtoebook, book_id=None, from_calibre=False, dsettings={}, calibre_libpaths=[], parent=None): QDialog.__init__(self, parent=parent) self.gui = parent self.pathtoebook = pathtoebook self.book_id = book_id self.from_calibre = from_calibre self.calibre_libpaths = calibre_libpaths self.dsettings = MR_SETTINGS.copy() self.dsettings.update(dsettings) self.ebook = None self.eborig = None self.cleanup_dirs = [] self.cleanup_files = [] self.log = [] self.rename_file_map = {} self.meta, self.errors = {}, {} self.is_scrambled = False self.dummyimg = None self.dummysvg = '' self.setWindowTitle(CAPTION) self.setWindowIcon(get_icons('images/plugin_icon.png')) # create widgets self.buttonBox = QDialogButtonBox(QDialogButtonBox.Save | QDialogButtonBox.Cancel) self.buttonBox.button( QDialogButtonBox.Save).setText('Save scrambled ebook && Exit') self.browser = QTextBrowser() self.browser.setText('') self.browser.setLineWrapMode(QTextBrowser.NoWrap) self.browser.setMinimumWidth(600) self.browser.setMinimumHeight(150) self.browser.setReadOnly(True) self.savefile = QLineEdit() self.savefile.setReadOnly(True) self.sourcefile = QLineEdit() self.sourcefile.setMinimumWidth(100) self.sourcefile.setReadOnly(True) self.browsesource = QPushButton('...') self.browsesource.setMaximumWidth(30) about_button = QPushButton('About', self) self.runButton = QPushButton('Scramble now') previewButton = QPushButton('Preview content') if Webview is None: previewButton.setEnabled(False) previewButton.setToolTip( 'Preview not currently available for this book') configButton = QPushButton('Change rules *') configButton.setToolTip( 'Only available in standalone version, not calibre plugin') metadataButton = QPushButton('View metadata *') metadataButton.setToolTip( 'Only available in standalone version, not calibre plugin') errorsButton = QPushButton('View errors *') errorsButton.setToolTip( 'Only available in standalone version, not calibre plugin') # layout widgets gpsource = QGroupBox('Source ebook:') laysource = QGridLayout() gpsource.setLayout(laysource) laysource.addWidget(self.sourcefile, 0, 0) laysource.addWidget(self.browsesource, 0, 1) gptarget = QGroupBox('Scrambled ebook:') laytarget = QGridLayout() gptarget.setLayout(laytarget) laytarget.addWidget(self.savefile, 0, 0) gpaction = QGroupBox('Actions:') layaction = QVBoxLayout() gpaction.setLayout(layaction) layaction.addWidget(self.runButton) layaction.addStretch() layaction.addWidget(previewButton) layaction.addStretch() gpextras = QGroupBox('Extras:') layaction2 = QVBoxLayout() gpextras.setLayout(layaction2) layaction2.addWidget(configButton) layaction2.addWidget(metadataButton) layaction2.addWidget(errorsButton) layaction3 = QVBoxLayout() layaction3.addWidget(about_button) layaction3.addStretch() layaction3.addWidget(gpextras) grid = QGridLayout() grid.addWidget(self.browser, 0, 0) grid.addLayout(layaction3, 0, 1) grid.addWidget(gpsource, 2, 0) grid.addWidget(gptarget, 3, 0) grid.addWidget(gpaction, 2, 1, 2, 1) grid.addWidget(self.buttonBox, 5, 0, 1, 2) self.setLayout(grid) # create connect signals/slots about_button.clicked.connect(self.about_button_clicked) self.runButton.clicked.connect(self.create_scramble_book) previewButton.clicked.connect(self.preview_ebook) configButton.clicked.connect(self.change_rules) metadataButton.clicked.connect(self.view_metadata) errorsButton.clicked.connect(self.view_errors) self.browsesource.clicked.connect(self.choose_source_ebook) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) if self.from_calibre: gpextras.setVisible( False) # Extras not available in calibre plugin self.browsesource.setVisible( False) # ebook file selection done by calibre self.initialise_new_file(self.pathtoebook)