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()
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 __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()
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.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 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
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_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
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