def __init__(self, log, icon): ''' :param log: The text to show in the dialog :param icon: The window icon ''' QDialog.__init__(self) self.setWindowTitle(_('Prince log')) self.setWindowIcon(icon) self.l = QVBoxLayout() self.setLayout(self.l) monofont = QFont('') monofont.setStyleHint(QFont.TypeWriter) self.box = QPlainTextEdit() self.box.setPlainText(log) self.box.setStyleSheet('* { font-family: monospace }') self.box.setMinimumWidth(500) self.box.setLineWrapMode(QPlainTextEdit.NoWrap) self.box.setReadOnly(True) self.box.setToolTip(_('<qt>Console output from the last Prince run</qt>')) self.l.addWidget(self.box) self.buttons = QDialogButtonBox(QDialogButtonBox.Ok) self.l.addWidget(self.buttons) self.buttons.accepted.connect(self.accept) self.adjustSize()
def __init__(self, parent, recipe_model): ResizableDialog.__init__(self, parent) self._model = self.model = CustomRecipeModel(recipe_model) self.available_profiles.setModel(self._model) self.available_profiles.currentChanged = self.current_changed f = QFont() f.setStyleHint(f.Monospace) self.source_code.setFont(f) self.remove_feed_button.clicked[(bool)].connect(self.added_feeds.remove_selected_items) self.remove_profile_button.clicked[(bool)].connect(self.remove_selected_items) self.add_feed_button.clicked[(bool)].connect(self.add_feed) self.load_button.clicked.connect(self.load) self.opml_button.clicked.connect(self.opml_import) self.builtin_recipe_button.clicked.connect(self.add_builtin_recipe) self.share_button.clicked.connect(self.share) self.show_recipe_files_button.clicked.connect(self.show_recipe_files) self.down_button.clicked.connect(self.down) self.up_button.clicked.connect(self.up) self.add_profile_button.clicked[(bool)].connect(self.add_profile) self.feed_url.returnPressed[()].connect(self.add_feed) self.feed_title.returnPressed[()].connect(self.add_feed) self.toggle_mode_button.clicked[(bool)].connect(self.toggle_mode) self.clear()
def __init__(self, log, icon): ''' :param log: The text to show in the dialog :param icon: The window icon ''' QDialog.__init__(self) self.setWindowTitle(_('Prince log')) self.setWindowIcon(icon) self.l = QVBoxLayout() self.setLayout(self.l) monofont = QFont('') monofont.setStyleHint(QFont.TypeWriter) self.box = QPlainTextEdit() self.box.setPlainText(log) self.box.setStyleSheet('* { font-family: monospace }') self.box.setMinimumWidth(500) self.box.setLineWrapMode(QPlainTextEdit.NoWrap) self.box.setReadOnly(True) self.box.setToolTip( _('<qt>Console output from the last Prince run</qt>')) self.l.addWidget(self.box) self.buttons = QDialogButtonBox(QDialogButtonBox.Ok) self.l.addWidget(self.buttons) self.buttons.accepted.connect(self.accept) self.adjustSize()
def get_monospaced_font(): """ Get a monospaced font. Should work on both windows and linux. """ font = QFont("monospace") font.setStyleHint(QFont.TypeWriter) return font
def __init__(self, byte_length, parent=None): super().__init__(parent) self.length = int(byte_length) case_char = '>' if hex_caps else '<' self.setInputMask(case_char + ' '.join(['HH'] * self.length) + '') font = QFont('Hexedit-monospace') font.setStyleHint(QFont.Monospace) self.setFont(font) self.sizeHint = lambda: QSize( self.fontMetrics().width(self.text() + ' '), self.fontMetrics().height() * 1.2, ) self.minimumSizeHint = self.sizeHint self.sizePolicy().setVerticalPolicy(QSizePolicy.Fixed) self.sizePolicy().setHorizontalPolicy(QSizePolicy.Minimum) self.updateGeometry() self.textChanged.connect( lambda: self.value_changed.emit(self.value()))
def initialize(self, parent): ''' __init__ is called on SizePersistedDialog() ''' #self.connected_device = parent.opts.gui.device_manager.device self.parent = parent self.prefs = parent.prefs self.verbose = parent.verbose self.setupUi(self) self._log_location() # Subscribe to Marvin driver change events #self.connected_device.marvin_device_signals.reader_app_status_changed.connect( # self.marvin_status_changed) self.setWindowTitle("Edit CSS") # Remove the placeholder self.placeholder.setParent(None) self.placeholder.deleteLater() self.placeholder = None # Replace the placeholder self.html_wv = QWebView() self.html_wv.sizeHint = self.wv_sizeHint self.html_wv.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.html_wv.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks) self.html_wv.linkClicked.connect(self.link_clicked) self.splitter.insertWidget(0, self.html_wv) # Add the Accept button self.accept_button = self.bb.addButton('Update', QDialogButtonBox.AcceptRole) self.accept_button.setDefault(True) # ~~~~~~~~ Configure the CSS control ~~~~~~~~ if isosx: FONT = QFont('Monaco', 11) elif iswindows: FONT = QFont('Lucida Console', 9) elif islinux: FONT = QFont('Monospace', 9) FONT.setStyleHint(QFont.TypeWriter) self.css_pte.setFont(FONT) # Tab width width = QFontMetrics(FONT).width(" ") * 4 self.css_pte.setTabStopWidth(width) # Restore/init the stored CSS self.css_pte.setPlainText(self.prefs.get('injected_css', '')) # Populate the HTML content rendered_html = self.inject_css(SAMPLE_HTML) self.html_wv.setHtml(rendered_html) # Restore the splitter split_points = self.prefs.get('css_editor_split_points') if split_points: self.splitter.setSizes(split_points) # Hook the QPlainTextEdit box self.css_pte.textChanged.connect(self.preview_css) # Hook the button events self.bb.clicked.connect(self.dispatch_button_click) self.resize_dialog()
def __init__(self, mi, fmt, opf, oeb, icon): ''' :param mi: The book metadata :param fmt: The source format used for conversion :param opf: The path to the OPF file :param oeb: An OEB object for the unpacked book :param icon: The window icon ''' self.opf = opf self.oeb = oeb self.mi = mi # The unpacked book needs to be parsed before, to read the contents # of the prince-style file, if it exists self.parse() QDialog.__init__(self) self.setAttribute(Qt.WA_DeleteOnClose) self.setWindowTitle(_('Convert to PDF with Prince')) self.setWindowIcon(icon) self.l = QVBoxLayout() self.setLayout(self.l) self.title_label = QLabel(_('<b>Title:</b> %s') % self.mi.title) self.l.addWidget(self.title_label) self.format_label = QLabel(_('<b>Source format:</b> %s') % fmt) self.l.addWidget(self.format_label) self.add_book = QCheckBox(_('&Add PDF to the book record')) self.add_book.setToolTip(_('<qt>Add the converted PDF to the selected book record</qt>')) self.add_book.setChecked(prefs['add_book']) self.add_book.stateChanged.connect(self.set_add_book) self.l.addWidget(self.add_book) self.ll = QHBoxLayout() self.ll.setAlignment(Qt.AlignLeft) self.l.addLayout(self.ll) self.label_css = QLabel(_('&Custom style:')) self.ll.addWidget(self.label_css) self.css_list = QComboBox() self.css_list.setToolTip(_('<qt>Select one style to use. Additional styles can be created in the plugin configuration</qt>')) for key in sorted(prefs['custom_CSS_list'], key=lambda x: x.lower()): self.css_list.addItem(key, key) self.css_list.setCurrentIndex(self.css_list.findText(prefs['default_CSS'])) self.css_list.currentIndexChanged.connect(self.set_css) self.ll.addWidget(self.css_list) self.label_css.setBuddy(self.css_list) self.ll_ = QHBoxLayout() self.l.addLayout(self.ll_) self.label_args = QLabel(_('A&dditional command-line arguments:')) self.ll_.addWidget(self.label_args) self.args = QLineEdit(self) self.args.setText(prefs['custom_args_list'][prefs['default_CSS']]) self.args.setToolTip(_('<qt>Specify additional command-line arguments for the conversion</qt>')) self.ll_.addWidget(self.args) self.label_args.setBuddy(self.args) self.css = QTabWidget() self.l.addWidget(self.css) self.css1 = TextEditWithTooltip(self, expected_geometry=(80,20)) self.css1.setLineWrapMode(TextEditWithTooltip.NoWrap) self.css1.load_text(self.replace_templates(prefs['custom_CSS_list'][prefs['default_CSS']]),'css') self.css1.setToolTip(_('<qt>This stylesheet can be modified<br/>The default can be configured</qt>')) i = self.css.addTab(self.css1, _('C&ustom CSS')) self.css.setTabToolTip(i, _('<qt>Custom CSS stylesheet to be used for this conversion</qt>')) monofont = QFont('') monofont.setStyleHint(QFont.TypeWriter) if (self.prince_css): self.css2 = QPlainTextEdit() self.css2.setStyleSheet('* { font-family: monospace }') self.css2.setLineWrapMode(QPlainTextEdit.NoWrap) self.css2.setPlainText(self.prince_css) self.css2.setReadOnly(True) self.css2.setToolTip(_('<qt>This stylesheet cannot be modified</qt>')) i = self.css.addTab(self.css2, _('&Book CSS')) self.css.setTabToolTip(i, _('<qt>Book-specific CSS stylesheet included in the ebook file</qt>')) self.ll = QHBoxLayout() self.l.addLayout(self.ll) if (prefs['show_CSS']): self.toggle = QPushButton(self.hide_text, self) else: self.toggle = QPushButton(self.show_text, self) self.toggle.setToolTip(_('<qt>Show/hide the additional styles used for the conversion</qt>')) self.toggle.clicked.connect(self.toggle_tabs) self.convert = QPushButton(_('Con&vert'), self) self.convert.setToolTip(_('<qt>Run the conversion with Prince</qt>')) self.convert.setDefault(True) self.buttons = QDialogButtonBox(QDialogButtonBox.Cancel) self.buttons.addButton(self.toggle, QDialogButtonBox.ResetRole) self.buttons.addButton(self.convert, QDialogButtonBox.AcceptRole) self.l.addWidget(self.buttons) self.buttons.accepted.connect(self.prince_convert) self.buttons.rejected.connect(self.reject) if (not prefs['show_CSS']): self.css.hide() self.adjustSize()
def __init__(self, mi, fmt, opf, oeb, icon): ''' :param mi: The book metadata :param fmt: The source format used for conversion :param opf: The path to the OPF file :param oeb: An OEB object for the unpacked book :param icon: The window icon ''' self.opf = opf self.oeb = oeb self.mi = mi # The unpacked book needs to be parsed before, to read the contents # of the prince-style file, if it exists self.parse() QDialog.__init__(self) self.setAttribute(Qt.WA_DeleteOnClose) self.setWindowTitle(_('Convert to PDF with Prince')) self.setWindowIcon(icon) self.l = QVBoxLayout() self.setLayout(self.l) self.title_label = QLabel(_('<b>Title:</b> %s') % self.mi.title) self.l.addWidget(self.title_label) self.format_label = QLabel(_('<b>Source format:</b> %s') % fmt) self.l.addWidget(self.format_label) self.add_book = QCheckBox(_('&Add PDF to the book record')) self.add_book.setToolTip( _('<qt>Add the converted PDF to the selected book record</qt>')) self.add_book.setChecked(prefs['add_book']) self.add_book.stateChanged.connect(self.set_add_book) self.l.addWidget(self.add_book) self.ll = QHBoxLayout() self.ll.setAlignment(Qt.AlignLeft) self.l.addLayout(self.ll) self.label_css = QLabel(_('&Custom style:')) self.ll.addWidget(self.label_css) self.css_list = QComboBox() self.css_list.setToolTip( _('<qt>Select one style to use. Additional styles can be created in the plugin configuration</qt>' )) for key in sorted(prefs['custom_CSS_list'], key=lambda x: x.lower()): self.css_list.addItem(key, key) self.css_list.setCurrentIndex( self.css_list.findText(prefs['default_CSS'])) self.css_list.currentIndexChanged.connect(self.set_css) self.ll.addWidget(self.css_list) self.label_css.setBuddy(self.css_list) self.ll_ = QHBoxLayout() self.l.addLayout(self.ll_) self.label_args = QLabel(_('A&dditional command-line arguments:')) self.ll_.addWidget(self.label_args) self.args = QLineEdit(self) self.args.setText(prefs['custom_args_list'][prefs['default_CSS']]) self.args.setToolTip( _('<qt>Specify additional command-line arguments for the conversion</qt>' )) self.ll_.addWidget(self.args) self.label_args.setBuddy(self.args) self.css = QTabWidget() self.l.addWidget(self.css) self.css1 = TextEditWithTooltip(self, expected_geometry=(80, 20)) self.css1.setLineWrapMode(TextEditWithTooltip.NoWrap) self.css1.load_text( self.replace_templates( prefs['custom_CSS_list'][prefs['default_CSS']]), 'css') self.css1.setToolTip( _('<qt>This stylesheet can be modified<br/>The default can be configured</qt>' )) i = self.css.addTab(self.css1, _('C&ustom CSS')) self.css.setTabToolTip( i, _('<qt>Custom CSS stylesheet to be used for this conversion</qt>')) monofont = QFont('') monofont.setStyleHint(QFont.TypeWriter) if (self.prince_css): self.css2 = QPlainTextEdit() self.css2.setStyleSheet('* { font-family: monospace }') self.css2.setLineWrapMode(QPlainTextEdit.NoWrap) self.css2.setPlainText(self.prince_css) self.css2.setReadOnly(True) self.css2.setToolTip( _('<qt>This stylesheet cannot be modified</qt>')) i = self.css.addTab(self.css2, _('&Book CSS')) self.css.setTabToolTip( i, _('<qt>Book-specific CSS stylesheet included in the ebook file</qt>' )) self.ll = QHBoxLayout() self.l.addLayout(self.ll) if (prefs['show_CSS']): self.toggle = QPushButton(self.hide_text, self) else: self.toggle = QPushButton(self.show_text, self) self.toggle.setToolTip( _('<qt>Show/hide the additional styles used for the conversion</qt>' )) self.toggle.clicked.connect(self.toggle_tabs) self.convert = QPushButton(_('Con&vert'), self) self.convert.setToolTip(_('<qt>Run the conversion with Prince</qt>')) self.convert.setDefault(True) self.buttons = QDialogButtonBox(QDialogButtonBox.Cancel) self.buttons.addButton(self.toggle, QDialogButtonBox.ResetRole) self.buttons.addButton(self.convert, QDialogButtonBox.AcceptRole) self.l.addWidget(self.buttons) self.buttons.accepted.connect(self.prince_convert) self.buttons.rejected.connect(self.reject) if (not prefs['show_CSS']): self.css.hide() self.adjustSize()