def setup_ui(self): self.l = l = QFormLayout(self) self.setLayout(l) la = self.la = QLabel(_( 'You can import an HTML or DOCX file directly as an EPUB and edit it. The EPUB' ' will be generated with minimal changes from the source, unlike doing a full' ' conversion in calibre.')) la.setWordWrap(True) l.addRow(la) self.h1 = h1 = QHBoxLayout() self.src = src = QLineEdit(self) src.setPlaceholderText(_('Choose the file to import')) h1.addWidget(src) self.b1 = b = QToolButton(self) b.setIcon(QIcon(I('document_open.png'))) b.setText(_('Choose file')) h1.addWidget(b) l.addRow(_('Source file'), h1) b.clicked.connect(self.choose_source) b.setFocus(Qt.OtherFocusReason) self.h2 = h1 = QHBoxLayout() self.dest = src = QLineEdit(self) src.setPlaceholderText(_('Choose the location for the newly created EPUB')) h1.addWidget(src) self.b2 = b = QToolButton(self) b.setIcon(QIcon(I('document_open.png'))) b.setText(_('Choose file')) h1.addWidget(b) l.addRow(_('Destination file'), h1) b.clicked.connect(self.choose_destination) l.addRow(self.bb)
def setup_ui(self): self.l = l = QFormLayout(self) self.setLayout(l) self.search_name = n = QLineEdit(self.search.get('name', ''), self) n.setPlaceholderText(_('The name with which to save this search')) l.addRow(_('&Name:'), n) self.find = f = QLineEdit(self.search.get('find', ''), self) f.setPlaceholderText(_('The expression to search for')) l.addRow(_('&Find:'), f) self.replace = r = QLineEdit(self.search.get('replace', ''), self) r.setPlaceholderText(_('The replace expression')) l.addRow(_('&Replace:'), r) self.case_sensitive = c = QCheckBox(_('Case sensitive')) c.setChecked( self.search.get('case_sensitive', SearchWidget.DEFAULT_STATE['case_sensitive'])) l.addRow(c) self.dot_all = d = QCheckBox(_('Dot matches all')) d.setChecked( self.search.get('dot_all', SearchWidget.DEFAULT_STATE['dot_all'])) l.addRow(d) self.mode_box = m = ModeBox(self) self.mode_box.mode = self.search.get('mode', 'regex') l.addRow(_('&Mode:'), m) l.addRow(self.bb)
def __init__(self, parent=None): BasicSettings.__init__(self, parent) self.l = l = QFormLayout(self) self.setLayout(l) fc = FontFamilyChooser(self) self('editor_font_family', widget=fc, getter=attrgetter('font_family'), setter=lambda x, val: setattr(x, 'font_family', val)) fc.family_changed.connect(self.emit_changed) l.addRow(_('Editor font &family:'), fc) fs = self('editor_font_size') fs.setMinimum(8), fs.setSuffix(' pt'), fs.setMaximum(50) l.addRow(_('Editor font &size:'), fs) auto_theme = _('Automatic (%s)') % default_theme() choices = {k:k for k in THEMES} choices['auto'] = auto_theme theme = self.choices_widget('editor_theme', choices, 'auto', 'auto') l.addRow(_('&Color scheme:'), theme) tw = self('editor_tab_stop_width') tw.setMinimum(2), tw.setSuffix(_(' characters')), tw.setMaximum(20) l.addRow(_('Width of &tabs:'), tw) lw = self('editor_line_wrap') lw.setText(_('&Wrap long lines in the editor')) l.addRow(lw)
def setup_ui(self): self.l = l = QFormLayout(self) self.setLayout(l) self.title = t = QLineEdit(self) l.addRow(_('&Title:'), t) t.setFocus(Qt.OtherFocusReason) self.authors = a = QLineEdit(self) l.addRow(_('&Authors:'), a) a.setText(tprefs.get('previous_new_book_authors', '')) self.languages = la = LanguagesEdit(self) l.addRow(_('&Language:'), la) la.lang_codes = (tprefs.get('previous_new_book_lang', canonicalize_lang(get_lang())), ) bb = self.bb l.addRow(bb) bb.clear() bb.addButton(bb.Cancel) b = bb.addButton('&EPUB', bb.AcceptRole) b.clicked.connect(partial(self.set_fmt, 'epub')) b = bb.addButton('&AZW3', bb.AcceptRole) b.clicked.connect(partial(self.set_fmt, 'azw3'))
def __init__(self, width, height, parent=None): QDialog.__init__(self, parent) self.l = l = QFormLayout(self) self.setLayout(l) self.aspect_ratio = width / float(height) l.addRow(QLabel(_('Choose the new width and height'))) self._width = w = QSpinBox(self) w.setMinimum(1) w.setMaximum(10 * width) w.setValue(width) w.setSuffix(' px') l.addRow(_('&Width:'), w) self._height = h = QSpinBox(self) h.setMinimum(1) h.setMaximum(10 * height) h.setValue(height) h.setSuffix(' px') l.addRow(_('&Height:'), h) w.valueChanged.connect(partial(self.keep_ar, 'width')) h.valueChanged.connect(partial(self.keep_ar, 'height')) self.ar = ar = QCheckBox(_('Keep &aspect ratio')) ar.setChecked(True) l.addRow(ar) self.resize(self.sizeHint()) self.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) l.addRow(bb)
def __init__(self, parent=None): BasicSettings.__init__(self, parent) self.l = l = QFormLayout(self) self.setLayout(l) def family_getter(w): return unicode(w.currentFont().family()) def family_setter(w, val): w.setCurrentFont(QFont(val)) families = {'serif':_('Serif text'), 'sans':_('Sans-serif text'), 'mono':_('Monospaced text')} for fam, text in families.iteritems(): w = QFontComboBox(self) self('preview_%s_family' % fam, widget=w, getter=family_getter, setter=family_setter) l.addRow(_('Font family for &%s:') % text, w) w = self.choices_widget('preview_standard_font_family', families, 'serif', 'serif') l.addRow(_('&Style for standard text:'), w) w = self('preview_base_font_size') w.setMinimum(8), w.setMaximum(100), w.setSuffix(' px') l.addRow(_('&Default font size:'), w) w = self('preview_mono_font_size') w.setMinimum(8), w.setMaximum(100), w.setSuffix(' px') l.addRow(_('&Monospace font size:'), w) w = self('preview_minimum_font_size') w.setMinimum(4), w.setMaximum(100), w.setSuffix(' px') l.addRow(_('Mi&nimum font size:'), w)
def get_bulk_rename_settings(parent, number, msg=None, sanitize=sanitize_file_name_unicode, leading_zeros=True): # {{{ d = QDialog(parent) d.l = l = QFormLayout(d) d.setLayout(l) d.prefix = p = QLineEdit(d) p.setText(_('Chapter-')) p.selectAll() d.la = la = QLabel( msg or _('All selected files will be renamed to the form prefix-number')) l.addRow(la) l.addRow(_('&Prefix:'), p) d.num = num = QSpinBox(d) num.setMinimum(0), num.setValue(1), num.setMaximum(1000) l.addRow(_('Starting &number:'), num) d.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bb.accepted.connect(d.accept), bb.rejected.connect(d.reject) l.addRow(bb) if d.exec_() == d.Accepted: prefix = sanitize(unicode(d.prefix.text())) num = d.num.value() fmt = '%d' if leading_zeros: largest = num + number - 1 fmt = '%0{0}d'.format(len(str(largest))) return prefix + fmt, num return None, None
def __init__(self, plugin_action): from calibre_plugins.mendeley_to_calibre.mendeley_oapi import fetch from calibre_plugins.mendeley_to_calibre.mendeley_oapi import mendeley_client self.information_label = None QWidget.__init__(self) self.plugin_action = plugin_action self.layout = QFormLayout() self.label = QLabel() self.label.setOpenExternalLinks(True) oapiConfig = OapiConfig() tokens_store = mendeley_client.MendeleyTokensStore() # tokens_store.loads(plugin_prefs['account']) self.oapi = fetch.calibreMendeleyOapi(oapiConfig, tokens_store) self.oapi.isValid() url = self.oapi.getVerificationUrl() link = '<a href="%s">Press Here</a>' % (url) self.label.setText("""<ol> <li>%s</li> <li>Authenticate and authorize the applicatoin</li> <li>Copy-paste the Verification Token</li> <li>Press 'Ok'</li> </ol> """ % (link)) self.setLayout(self.layout) self.api_key = QLineEdit(self) self.layout.addRow(self.label) self.layout.addRow('Verification Code', self.api_key) self.api_key.textChanged.connect(self.clean_information) self.api_key.setText(plugin_prefs.get('api_key', '')) self.setWindowTitle('Customise Mendeley Plugin Importer') self.layout.setSizeConstraint(QLayout.SetFixedSize)
def __init__(self, parent=None): QDialog.__init__(self, parent=parent) self.l = l = QFormLayout(self) self.setLayout(l) self.setWindowTitle(_('Import OPML file')) self.setWindowIcon(QIcon(I('opml.png'))) self.h = h = QHBoxLayout() self.path = p = QLineEdit(self) p.setMinimumWidth(300) p.setPlaceholderText(_('Path to OPML file')) h.addWidget(p) self.cfb = b = QToolButton(self) b.setIcon(QIcon(I('document_open.png'))) b.setToolTip(_('Browse for OPML file')) b.clicked.connect(self.choose_file) h.addWidget(b) l.addRow(_('&OPML file:'), h) l.labelForField(h).setBuddy(p) b.setFocus(Qt.OtherFocusReason) self._articles_per_feed = a = QSpinBox(self) a.setMinimum(1), a.setMaximum(1000), a.setValue(100) a.setToolTip(_('Maximum number of articles to download per RSS feed')) l.addRow(_('&Maximum articles per feed:'), a) self._oldest_article = o = QSpinBox(self) o.setMinimum(1), o.setMaximum(3650), o.setValue(7) o.setSuffix(_(' days')) o.setToolTip( _('Articles in the RSS feeds older than this will be ignored')) l.addRow(_('&Oldest article:'), o) self.preserve_groups = g = QCheckBox( _('Preserve groups in the OPML file')) g.setToolTip('<p>' + _( 'If enabled, every group of feeds in the OPML file will be converted into a single recipe. Otherwise every feed becomes its own recipe' )) g.setChecked(True) l.addRow(g) self._replace_existing = r = QCheckBox(_('Replace existing recipes')) r.setToolTip('<p>' + _( 'If enabled, any existing recipes with the same titles as entries in the OPML file will be replaced.' ' Otherwise, new entries with modified titles will be created')) r.setChecked(True) l.addRow(r) self.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bb.accepted.connect(self.accept), bb.rejected.connect(self.reject) l.addRow(bb) self.recipes = ()
def setup_ui(self): self.l = l = QVBoxLayout(self) self.setLayout(l) self.tl = tl = QFormLayout() self.semantic_type = QComboBox(self) for key, val in self.all_types.iteritems(): self.semantic_type.addItem(val, key) tl.addRow(_('Type of &semantics:'), self.semantic_type) self.target = t = QLineEdit(self) t.setPlaceholderText(_('The destination (href) for the link')) tl.addRow(_('&Target:'), t) l.addLayout(tl) self.hline = hl = QFrame(self) hl.setFrameStyle(hl.HLine) l.addWidget(hl) self.h = h = QHBoxLayout() l.addLayout(h) names = [n for n, linear in self.container.spine_names] fn, f = create_filterable_names_list(names, filter_text=_('Filter files'), parent=self) self.file_names, self.file_names_filter = fn, f fn.selectionModel().selectionChanged.connect( self.selected_file_changed) self.fnl = fnl = QVBoxLayout() self.la1 = la = QLabel(_('Choose a &file:')) la.setBuddy(fn) fnl.addWidget(la), fnl.addWidget(f), fnl.addWidget(fn) h.addLayout(fnl), h.setStretch(0, 2) fn, f = create_filterable_names_list([], filter_text=_('Filter locations'), parent=self) self.anchor_names, self.anchor_names_filter = fn, f fn.selectionModel().selectionChanged.connect(self.update_target) fn.doubleClicked.connect(self.accept, type=Qt.QueuedConnection) self.anl = fnl = QVBoxLayout() self.la2 = la = QLabel(_('Choose a &location (anchor) in the file:')) la.setBuddy(fn) fnl.addWidget(la), fnl.addWidget(f), fnl.addWidget(fn) h.addLayout(fnl), h.setStretch(1, 1) self.bb.addButton(self.bb.Help) self.bb.helpRequested.connect(self.help_requested) l.addWidget(self.bb) self.semantic_type_changed() self.semantic_type.currentIndexChanged.connect( self.semantic_type_changed) self.target.textChanged.connect(self.target_text_changed)
def __init__(self, parent=None): BasicSettings.__init__(self, parent) self.dictionaries_changed = False self.l = l = QFormLayout(self) self.setLayout(l) fc = FontFamilyChooser(self) self('editor_font_family', widget=fc, getter=attrgetter('font_family'), setter=lambda x, val: setattr(x, 'font_family', val)) fc.family_changed.connect(self.emit_changed) l.addRow(_('Editor font &family:'), fc) fs = self('editor_font_size') fs.setMinimum(8), fs.setSuffix(' pt'), fs.setMaximum(50) l.addRow(_('Editor font &size:'), fs) auto_theme = _('Automatic (%s)') % default_theme() choices = {k:k for k in THEMES} choices['auto'] = auto_theme theme = self.choices_widget('editor_theme', choices, 'auto', 'auto') l.addRow(_('&Color scheme:'), theme) tw = self('editor_tab_stop_width') tw.setMinimum(2), tw.setSuffix(_(' characters')), tw.setMaximum(20) l.addRow(_('Width of &tabs:'), tw) lw = self('editor_line_wrap') lw.setText(_('&Wrap long lines in the editor')) l.addRow(lw) lw = self('replace_entities_as_typed') lw.setText(_('&Replace HTML entities as they are typed')) lw.setToolTip('<p>' + _( 'With this option, every time you type in a complete html entity, such as &hellip;' ' it is automatically replaced by its corresponding character. The replacement' ' happens only when the trailing semi-colon is typed.')) l.addRow(lw) lw = self('editor_show_char_under_cursor') lw.setText(_('Show the name of the current character before the cursor along with the line and column number')) l.addRow(lw) lw = self('pretty_print_on_open') lw.setText(_('Beautify individual files automatically when they are opened')) lw.setToolTip('<p>' + _( 'This will cause the beautify current file action to be performed automatically every' ' time you open a HTML/CSS/etc. file for editing.')) l.addRow(lw) self.dictionaries = d = QPushButton(_('Manage &spelling dictionaries'), self) d.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) d.clicked.connect(self.manage_dictionaries) l.addRow(d)
def setup_ui(self): self.l = l = QFormLayout(self) self.setLayout(l) self.la = la = QLabel(ngettext( 'Change the font %s to:', 'Change the fonts %s to:', self.old_family.count(',')+1) % self.old_family) la.setWordWrap(True) l.addRow(la) self._family = f = QLineEdit(self) l.addRow(_('&New font:'), f) f.textChanged.connect(self.updated_family) self.embed_status = e = QLabel('\xa0') l.addRow(e) l.addRow(self.bb)
def setup_ui(self): self.l = l = QFormLayout(self) self.setLayout(l) self.err_label = QLabel('') self.name_edit = QLineEdit(self) self.name_edit.textChanged.connect(self.verify) self.name_edit.setText(self.candidate) pos = self.candidate.rfind('.') if pos > -1: self.name_edit.setSelection(0, pos) l.addRow(_('File &name:'), self.name_edit) l.addRow(self.err_label) l.addRow(self.bb)
def setup_ui(self): self.l = l = QFormLayout(self) self.setLayout(l) self._name = n = QLineEdit(self) l.addRow(_('&Name of custom theme:'), n) self.base = b = QComboBox(self) b.addItems(sorted(builtin_theme_names())) l.addRow(_('&Builtin theme to base on:'), b) idx = b.findText(tprefs['editor_theme'] or default_theme()) if idx == -1: idx = b.findText(default_theme()) b.setCurrentIndex(idx) l.addRow(self.bb)
def __init__(self, parent=None): BasicSettings.__init__(self, parent) self.l = l = QFormLayout(self) self.setLayout(l) ask = self('choose_tweak_fmt') ask.setText( _('Ask which format to tweak if more than one format is available for the book' )) l.addRow(ask) order = self.order_widget('tweak_fmt_order') order.setToolTip( _('When auto-selecting the format to tweak for a book with' ' multiple formats, this is the preference order.')) l.addRow(_('Preferred format order (drag and drop to change)'), order)
def request_bulk_rename(self): names = { unicode(item.data(0, NAME_ROLE).toString()) for item in self.selectedItems() } bad = names & current_container().names_that_must_not_be_changed if bad: return error_dialog(self, _('Cannot rename'), _('The file(s) %s cannot be renamed.') % ('<b>%s</b>' % ', '.join(bad)), show=True) names = sorted(names, key=self.index_of_name) d = QDialog(self) d.l = l = QFormLayout(d) d.setLayout(l) d.prefix = p = QLineEdit(d) p.setText(_('Chapter-')) p.selectAll() d.la = la = QLabel( _('All selected files will be renamed to the form prefix-number')) l.addRow(la) l.addRow(_('&Prefix:'), p) d.num = num = QSpinBox(d) num.setMinimum(0), num.setValue(1), num.setMaximum(1000) l.addRow(_('Starting &number:'), num) d.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bb.accepted.connect(d.accept), bb.rejected.connect(d.reject) l.addRow(bb) if d.exec_() == d.Accepted: prefix = sanitize_file_name_unicode(unicode(d.prefix.text())) num = d.num.value() largest = num + len(names) - 1 fmt = '%0{0}d'.format(len(str(largest))) def change_name(name, num): parts = name.split('/') base, ext = parts[-1].rpartition('.')[0::2] parts[-1] = prefix + (fmt % num) + '.' + ext return '/'.join(parts) name_map = { n: change_name(n, num + i) for i, n in enumerate(names) } self.bulk_rename_requested.emit(name_map)
def ask_link(self): d = QDialog(self) d.setWindowTitle(_('Create link')) l = QFormLayout() d.setLayout(l) d.url = QLineEdit(d) d.name = QLineEdit(d) d.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) l.addRow(_('Enter &URL:'), d.url) l.addRow(_('Enter name (optional):'), d.name) l.addRow(d.bb) d.bb.accepted.connect(d.accept) d.bb.rejected.connect(d.reject) link, name = None, None if d.exec_() == d.Accepted: link, name = unicode(d.url.text()).strip(), unicode( d.name.text()).strip() return link, name
def setup_ui(self): self.l = l = QVBoxLayout(self) self.setLayout(l) self.h = h = QHBoxLayout() l.addLayout(h) names = [n for n, linear in self.container.spine_names] fn, f = create_filterable_names_list(names, filter_text=_('Filter files'), parent=self) self.file_names, self.file_names_filter = fn, f fn.selectionModel().selectionChanged.connect( self.selected_file_changed) self.fnl = fnl = QVBoxLayout() self.la1 = la = QLabel(_('Choose a &file to link to:')) la.setBuddy(fn) fnl.addWidget(la), fnl.addWidget(f), fnl.addWidget(fn) h.addLayout(fnl), h.setStretch(0, 2) fn, f = create_filterable_names_list([], filter_text=_('Filter locations'), parent=self, model=AnchorsModel) fn.setSpacing(5) self.anchor_names, self.anchor_names_filter = fn, f fn.selectionModel().selectionChanged.connect(self.update_target) fn.doubleClicked.connect(self.accept, type=Qt.QueuedConnection) self.anl = fnl = QVBoxLayout() self.la2 = la = QLabel(_('Choose a &location (anchor) in the file:')) la.setBuddy(fn) fnl.addWidget(la), fnl.addWidget(f), fnl.addWidget(fn) h.addLayout(fnl), h.setStretch(1, 1) self.tl = tl = QFormLayout() self.target = t = QLineEdit(self) t.setPlaceholderText(_('The destination (href) for the link')) tl.addRow(_('&Target:'), t) l.addLayout(tl) self.text_edit = t = QLineEdit(self) la.setBuddy(t) tl.addRow(_('Te&xt:'), t) t.setText(self.initial_text or '') t.setPlaceholderText(_('The (optional) text for the link')) l.addWidget(self.bb)
def __init__(self, plugin_action): from calibre_plugins.mendeley_to_calibre.mendeley_oapi import fetch from calibre_plugins.mendeley_to_calibre.mendeley_oapi import mendeley_client self.information_label = None QWidget.__init__(self) self.plugin_action = plugin_action self.layout = QFormLayout() self.label = QLabel() self.label.setOpenExternalLinks(True) oapiConfig = OapiConfig() tokens_store = mendeley_client.MendeleyTokensStore() # tokens_store.loads(plugin_prefs['account']) self.oapi = fetch.calibreMendeleyOapi(oapiConfig, tokens_store) self.oapi.isValid() url = self.oapi.getVerificationUrl() link = '<a href="%s">Press Here</a>' % (url) self.label.setText("""<ol> <li>%s</li> <li>Authenticate and authorize the applicatoin</li> <li>Copy-paste the Verification Token</li> <li>Press 'Ok'</li> </ol> """ % (link)) self.setLayout(self.layout) self.api_key = QLineEdit(self) self.layout.addRow(self.label) self.layout.addRow('Verification Code',self.api_key) self.api_key.textChanged.connect(self.clean_information) self.api_key.setText(plugin_prefs.get('api_key','')) self.setWindowTitle('Customise Mendeley Plugin Importer') self.layout.setSizeConstraint(QLayout.SetFixedSize)
def ask_link(self): d = QDialog(self) d.setWindowTitle(_('Create link')) l = QFormLayout() d.setLayout(l) d.url = QLineEdit(d) d.name = QLineEdit(d) d.bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) l.addRow(_('Enter &URL:'), d.url) l.addRow(_('Enter name (optional):'), d.name) l.addRow(d.bb) d.bb.accepted.connect(d.accept) d.bb.rejected.connect(d.reject) link, name = None, None if d.exec_() == d.Accepted: link, name = unicode(d.url.text()).strip(), unicode(d.name.text()).strip() return link, name
def __init__(self, parent=None): BasicSettings.__init__(self, parent) self.l = l = QFormLayout(self) self.setLayout(l) um = self('update_metadata_from_calibre') um.setText(_('Update metadata embedded in the book when opening')) um.setToolTip('<p>' + _( 'When the file is opened, update the metadata embedded in the book file to the current metadata' ' in the calibre library.')) l.addRow(um) ask = self('choose_tweak_fmt') ask.setText(_('Ask which format to edit if more than one format is available for the book')) l.addRow(ask) order = self.order_widget('tweak_fmt_order') order.setToolTip(_('When auto-selecting the format to edit for a book with' ' multiple formats, this is the preference order.')) l.addRow(_('Preferred format order (drag and drop to change)'), order)
def __init__(self, parent=None): BasicSettings.__init__(self, parent) self.l = l = QFormLayout(self) self.setLayout(l) nd = self('nestable_dock_widgets') nd.setText( _('Allow dockable windows to be nested inside the dock areas')) nd.setToolTip('<p>' + _( 'By default, you can have only a single row or column of windows in the dock' ' areas (the areas around the central editors). This option allows' ' for more flexible window layout, but is a little more complex to use.' )) l.addRow(nd) l.addRow( QLabel( _('Choose which windows will occupy the corners of the dockable areas' ))) for v, h in product(('top', 'bottom'), ('left', 'right')): choices = { 'vertical': { 'left': _('Left'), 'right': _('Right') }[h], 'horizontal': { 'top': _('Top'), 'bottom': _('Bottom') }[v] } name = 'dock_%s_%s' % (v, h) w = self.choices_widget(name, choices, 'horizontal', 'horizontal') cn = { ('top', 'left'): _('The top-left corner'), ('top', 'right'): _('The top-right corner'), ('bottom', 'left'): _('The bottom-left corner'), ('bottom', 'right'): _('The bottom-right corner') }[(v, h)] l.addRow(cn + ':', w)
def setup_ui(self): from calibre.gui2.convert.look_and_feel_ui import Ui_Form f, w = Ui_Form(), QWidget() f.setupUi(w) self.l = l = QFormLayout(self) self.setLayout(l) l.addRow( QLabel( _('Select what style information you want completely removed:') )) self.h = h = QHBoxLayout() for name, text in { 'fonts': _('&Fonts'), 'margins': _('&Margins'), 'padding': _('&Padding'), 'floats': _('Flo&ats'), 'colors': _('&Colors') }.iteritems(): c = QCheckBox(text) setattr(self, 'opt_' + name, c) h.addWidget(c) c.setToolTip(getattr(f, 'filter_css_' + name).toolTip()) l.addRow(h) self.others = o = QLineEdit(self) l.addRow(_('&Other CSS properties:'), o) o.setToolTip(f.filter_css_others.toolTip()) if self.current_name is not None: self.filter_current = c = QCheckBox( _('Only filter CSS in the current file (%s)') % self.current_name) l.addRow(c) l.addRow(self.bb)
def ask_about_cc_mismatch(gui, db, newdb, missing_cols, incompatible_cols): # {{{ source_metadata = db.field_metadata.custom_field_metadata(include_composites=True) ndbname = os.path.basename(newdb.library_path) d = QDialog(gui) d.setWindowTitle(_('Different custom columns')) l = QFormLayout() tl = QVBoxLayout() d.setLayout(tl) d.s = QScrollArea(d) tl.addWidget(d.s) d.w = QWidget(d) d.s.setWidget(d.w) d.s.setWidgetResizable(True) d.w.setLayout(l) d.setMinimumWidth(600) d.setMinimumHeight(500) d.bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) msg = _('The custom columns in the <i>{0}</i> library are different from the ' 'custom columns in the <i>{1}</i> library. As a result, some metadata might not be copied.').format( os.path.basename(db.library_path), ndbname) d.la = la = QLabel(msg) la.setWordWrap(True) la.setStyleSheet('QLabel { margin-bottom: 1.5ex }') l.addRow(la) if incompatible_cols: la = d.la2 = QLabel(_('The following columns are incompatible - they have the same name' ' but different data types. They will be ignored: ') + ', '.join(sorted(incompatible_cols, key=sort_key))) la.setWordWrap(True) la.setStyleSheet('QLabel { margin-bottom: 1.5ex }') l.addRow(la) missing_widgets = [] if missing_cols: la = d.la3 = QLabel(_('The following columns are missing in the <i>{0}</i> library.' ' You can choose to add them automatically below.').format( ndbname)) la.setWordWrap(True) l.addRow(la) for k in missing_cols: widgets = (k, QCheckBox(_('Add to the %s library') % ndbname)) l.addRow(QLabel(k), widgets[1]) missing_widgets.append(widgets) d.la4 = la = QLabel(_('This warning is only shown once per library, per session')) la.setWordWrap(True) tl.addWidget(la) tl.addWidget(d.bb) d.bb.accepted.connect(d.accept) d.bb.rejected.connect(d.reject) d.resize(d.sizeHint()) if d.exec_() == d.Accepted: for k, cb in missing_widgets: if cb.isChecked(): col_meta = source_metadata[k] newdb.create_custom_column( col_meta['label'], col_meta['name'], col_meta['datatype'], len(col_meta['is_multiple']) > 0, col_meta['is_editable'], col_meta['display']) return True return False
def __init__(self, parent): QDialog.__init__(self, parent) self.setWindowTitle(self.tr("Connect")) # Create inputs self._hostLine = QLineEdit(self) self._hostLine.setText(DEFAULT_HOST) self._portLine = QLineEdit(self) self._portLine.setText(DEFAULT_PORT) self._databaseLine = QLineEdit(self) self._databaseLine.setText(DEFAULT_DATABASE) self._userLine = QLineEdit(self) self._userLine.setText(DEFAULT_USER) self._passwordLine = QLineEdit(self) self._passwordLine.setText(DEFAULT_PASSWORD) validateButton = QPushButton(self.tr("Ok"), self) self.connect(validateButton, SIGNAL("clicked()"), self.validate) # Set a form layout layout = QFormLayout(self) layout.addRow(self.tr("Host : "), self._hostLine) layout.addRow(self.tr("Port : "), self._portLine) layout.addRow(self.tr("Database : "), self._databaseLine) layout.addRow(self.tr("User : "******"Password : "), self._passwordLine) layout.addWidget(validateButton) self.setLayout(layout) self.show()
class ConfigWidget(QDialog): def __init__(self, plugin_action): from calibre_plugins.mendeley_to_calibre.mendeley_oapi import fetch from calibre_plugins.mendeley_to_calibre.mendeley_oapi import mendeley_client self.information_label = None QWidget.__init__(self) self.plugin_action = plugin_action self.layout = QFormLayout() self.label = QLabel() self.label.setOpenExternalLinks(True) oapiConfig = OapiConfig() tokens_store = mendeley_client.MendeleyTokensStore() # tokens_store.loads(plugin_prefs['account']) self.oapi = fetch.calibreMendeleyOapi(oapiConfig, tokens_store) self.oapi.isValid() url = self.oapi.getVerificationUrl() link = '<a href="%s">Press Here</a>' % (url) self.label.setText("""<ol> <li>%s</li> <li>Authenticate and authorize the applicatoin</li> <li>Copy-paste the Verification Token</li> <li>Press 'Ok'</li> </ol> """ % (link)) self.setLayout(self.layout) self.api_key = QLineEdit(self) self.layout.addRow(self.label) self.layout.addRow('Verification Code',self.api_key) self.api_key.textChanged.connect(self.clean_information) self.api_key.setText(plugin_prefs.get('api_key','')) self.setWindowTitle('Customise Mendeley Plugin Importer') self.layout.setSizeConstraint(QLayout.SetFixedSize) def add_ok_cancel_buttons(self): """ This QDialog is shown by Calibre -then it adds the Ok/Cancel buttons- but also by the plugin itself. """ button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.layout.addRow(button_box) button_box.accepted.connect(self.ok_pressed) button_box.rejected.connect(self.reject) def ok_pressed(self): if self.save_settings(): self.accept() else: if self.information_label == None: self.information_label = QLabel() self.layout.addRow(self.information_label) self.information_label.setText('<font color="red">Invalid verification code</font>') def clean_information(self): if self.information_label: self.information_label.setText('') def save_settings(self): ok_api_key = True from calibre_plugins.mendeley_to_calibre.mendeley_oapi import mendeley_client plugin_prefs['verification'] = str(self.api_key.text()) try: self.oapi.setVerificationCode(str(self.api_key.text())) except ValueError: ok_api_key = False if ok_api_key: tokens_store = mendeley_client.MendeleyTokensStore() tokens_store.add_account('test_account',self.oapi.mendeley.get_access_token()) plugin_prefs['account'] = tokens_store.dumps() return ok_api_key
def ask_link(self): d = QDialog(self) d.setWindowTitle(_('Create link')) l = QFormLayout() d.setLayout(l) d.url = QLineEdit(d) d.name = QLineEdit(d) d.treat_as_image = QCheckBox(d) d.setMinimumWidth(600) d.bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) d.br = b = QPushButton(_('&Browse')) b.setIcon(QIcon(I('document_open.png'))) def cf(): files = choose_files(d, 'select link file', _('Choose file'), select_only_single_file=True) if files: path = files[0] d.url.setText(path) if path and os.path.exists(path): with lopen(path, 'rb') as f: q = what(f) is_image = q in {'jpeg', 'png', 'gif'} d.treat_as_image.setChecked(is_image) b.clicked.connect(cf) d.la = la = QLabel(_( 'Enter a URL. If you check the "Treat the URL as an image" box ' 'then the URL will be added as an image reference instead of as ' 'a link. You can also choose to create a link to a file on ' 'your computer. ' 'Note that if you create a link to a file on your computer, it ' 'will stop working if the file is moved.')) la.setWordWrap(True) la.setStyleSheet('QLabel { margin-bottom: 1.5ex }') l.setWidget(0, l.SpanningRole, la) l.addRow(_('Enter &URL:'), d.url) l.addRow(_('Treat the URL as an &image'), d.treat_as_image) l.addRow(_('Enter &name (optional):'), d.name) l.addRow(_('Choose a file on your computer:'), d.br) l.addRow(d.bb) d.bb.accepted.connect(d.accept) d.bb.rejected.connect(d.reject) d.resize(d.sizeHint()) link, name, is_image = None, None, False if d.exec_() == d.Accepted: link, name = unicode(d.url.text()).strip(), unicode(d.name.text()).strip() is_image = d.treat_as_image.isChecked() return link, name, is_image
def ask_link(self): d = QDialog(self) d.setWindowTitle(_('Create link')) l = QFormLayout() d.setLayout(l) d.url = QLineEdit(d) d.name = QLineEdit(d) d.setMinimumWidth(600) d.bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) d.br = b = QPushButton(_('&Browse')) b.setIcon(QIcon(I('document_open.png'))) def cf(): files = choose_files(d, 'select link file', _('Choose file'), select_only_single_file=True) if files: d.url.setText(files[0]) b.clicked.connect(cf) d.la = la = QLabel(_( 'Enter a URL. You can also choose to create a link to a file on ' 'your computer. If the selected file is an image, it will be ' 'inserted as an image. Note that if you create a link to a file on ' 'your computer, it will stop working if the file is moved.')) la.setWordWrap(True) la.setStyleSheet('QLabel { margin-bottom: 1.5ex }') l.setWidget(0, l.SpanningRole, la) l.addRow(_('Enter &URL:'), d.url) l.addRow(_('Enter &name (optional):'), d.name) l.addRow(_('Choose a file on your computer:'), d.br) l.addRow(d.bb) d.bb.accepted.connect(d.accept) d.bb.rejected.connect(d.reject) d.resize(d.sizeHint()) link, name, is_image = None, None, False if d.exec_() == d.Accepted: link, name = unicode(d.url.text()).strip(), unicode(d.name.text()).strip() if link and os.path.exists(link): with lopen(link, 'rb') as f: q = what(f) is_image = q in {'jpeg', 'png', 'gif'} return link, name, is_image
def __init__(self, parent): QDialog.__init__(self, parent) self.setWindowTitle("Import data from database") layout = QFormLayout(self) layout.addRow( QLabel("Database : " + self.parent().controller().databaseName())) layout.addRow(QLabel("Tables : ")) self._tables = self.parent().controller().databaseTables() self._tablesItem = [] for t in self._tables: cb = QCheckBox(t) self._tablesItem.append(cb) layout.addRow(cb) self._subset = QLineEdit(self) layout.addRow("Subset : ", self._subset) # TODO add More option (geom column, ...) validateButton = QPushButton("Ok", self) self.connect(validateButton, SIGNAL("clicked()"), self.validate) layout.addRow(validateButton) self.setLayout(layout) self.show()
class ConfigWidget(QDialog): def __init__(self, plugin_action): from calibre_plugins.mendeley_to_calibre.mendeley_oapi import fetch from calibre_plugins.mendeley_to_calibre.mendeley_oapi import mendeley_client self.information_label = None QWidget.__init__(self) self.plugin_action = plugin_action self.layout = QFormLayout() self.label = QLabel() self.label.setOpenExternalLinks(True) oapiConfig = OapiConfig() tokens_store = mendeley_client.MendeleyTokensStore() # tokens_store.loads(plugin_prefs['account']) self.oapi = fetch.calibreMendeleyOapi(oapiConfig, tokens_store) self.oapi.isValid() url = self.oapi.getVerificationUrl() link = '<a href="%s">Press Here</a>' % (url) self.label.setText("""<ol> <li>%s</li> <li>Authenticate and authorize the applicatoin</li> <li>Copy-paste the Verification Token</li> <li>Press 'Ok'</li> </ol> """ % (link)) self.setLayout(self.layout) self.api_key = QLineEdit(self) self.layout.addRow(self.label) self.layout.addRow('Verification Code', self.api_key) self.api_key.textChanged.connect(self.clean_information) self.api_key.setText(plugin_prefs.get('api_key', '')) self.setWindowTitle('Customise Mendeley Plugin Importer') self.layout.setSizeConstraint(QLayout.SetFixedSize) def add_ok_cancel_buttons(self): """ This QDialog is shown by Calibre -then it adds the Ok/Cancel buttons- but also by the plugin itself. """ button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.layout.addRow(button_box) button_box.accepted.connect(self.ok_pressed) button_box.rejected.connect(self.reject) def ok_pressed(self): if self.save_settings(): self.accept() else: if self.information_label == None: self.information_label = QLabel() self.layout.addRow(self.information_label) self.information_label.setText( '<font color="red">Invalid verification code</font>') def clean_information(self): if self.information_label: self.information_label.setText('') def save_settings(self): ok_api_key = True from calibre_plugins.mendeley_to_calibre.mendeley_oapi import mendeley_client plugin_prefs['verification'] = str(self.api_key.text()) try: self.oapi.setVerificationCode(str(self.api_key.text())) except ValueError: ok_api_key = False if ok_api_key: tokens_store = mendeley_client.MendeleyTokensStore() tokens_store.add_account('test_account', self.oapi.mendeley.get_access_token()) plugin_prefs['account'] = tokens_store.dumps() return ok_api_key