Пример #1
0
    def link_stylesheets(self, names):
        s = self.categories['styles']
        sheets = [unicode(s.child(i).data(0, NAME_ROLE).toString()) for i in xrange(s.childCount())]
        if not sheets:
            return error_dialog(self, _('No stylesheets'), _(
                'This book currently has no stylesheets. You must first create a stylesheet'
                ' before linking it.'), show=True)
        d = QDialog(self)
        d.l = l = QVBoxLayout(d)
        d.setLayout(l)
        d.setWindowTitle(_('Choose stylesheets'))
        d.la = la = QLabel(_('Choose the stylesheets to link. Drag and drop to re-arrange'))

        la.setWordWrap(True)
        l.addWidget(la)
        d.s = s = QListWidget(d)
        l.addWidget(s)
        s.setDragEnabled(True)
        s.setDropIndicatorShown(True)
        s.setDragDropMode(self.InternalMove)
        s.setAutoScroll(True)
        s.setDefaultDropAction(Qt.MoveAction)
        for name in sheets:
            i = QListWidgetItem(name, s)
            flags = Qt.ItemIsEnabled | Qt.ItemIsUserCheckable | Qt.ItemIsDragEnabled | Qt.ItemIsSelectable
            i.setFlags(flags)
            i.setCheckState(Qt.Checked)
        d.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        bb.accepted.connect(d.accept), bb.rejected.connect(d.reject)
        l.addWidget(bb)
        if d.exec_() == d.Accepted:
            sheets = [unicode(s.item(i).text()) for i in xrange(s.count()) if s.item(i).checkState() == Qt.Checked]
            if sheets:
                self.link_stylesheets_requested.emit(names, sheets)
Пример #2
0
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
Пример #3
0
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
Пример #4
0
 def view_server_logs(self):
     from calibre.library.server import log_access_file, log_error_file
     d = QDialog(self)
     d.resize(QSize(800, 600))
     layout = QVBoxLayout()
     d.setLayout(layout)
     layout.addWidget(QLabel(_('Error log:')))
     el = QPlainTextEdit(d)
     layout.addWidget(el)
     try:
         el.setPlainText(
             open(log_error_file, 'rb').read().decode('utf8', 'replace'))
     except IOError:
         el.setPlainText('No error log found')
     layout.addWidget(QLabel(_('Access log:')))
     al = QPlainTextEdit(d)
     layout.addWidget(al)
     try:
         al.setPlainText(
             open(log_access_file, 'rb').read().decode('utf8', 'replace'))
     except IOError:
         al.setPlainText('No access log found')
     bx = QDialogButtonBox(QDialogButtonBox.Ok)
     layout.addWidget(bx)
     bx.accepted.connect(d.accept)
     d.show()
Пример #5
0
    def polish(self, action, name):
        self.commit_all_editors_to_container()
        with BusyCursor():
            self.add_savepoint(name)
            try:
                report = tweak_polish(current_container(), {action: True})
            except:
                self.rewind_savepoint()
                raise
            self.apply_container_update_to_gui()
            from calibre.ebooks.markdown import markdown

            report = markdown("# %s\n\n" % self.current_metadata.title + "\n\n".join(report), output_format="html4")
        d = QDialog(self.gui)
        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)
        d.l.addWidget(d.bb)
        d.bb.rejected.connect(d.reject)
        d.bb.accepted.connect(d.accept)
        d.resize(600, 400)
        d.exec_()
Пример #6
0
 def polish(self, action, name):
     self.commit_all_editors_to_container()
     with BusyCursor():
         self.add_savepoint(name)
         try:
             report = tweak_polish(current_container(), {action: True})
         except:
             self.rewind_savepoint()
             raise
         self.apply_container_update_to_gui()
         from calibre.ebooks.markdown import markdown
         report = markdown('# %s\n\n' % self.current_metadata.title +
                           '\n\n'.join(report),
                           output_format='html4')
     d = QDialog(self.gui)
     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)
     d.l.addWidget(d.bb)
     d.bb.rejected.connect(d.reject)
     d.bb.accepted.connect(d.accept)
     d.resize(600, 400)
     d.exec_()
Пример #7
0
 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)
Пример #8
0
    def add_builtin_recipe(self):
        from calibre.web.feeds.recipes.collection import \
            get_builtin_recipe_collection, get_builtin_recipe_by_id
        from PyQt4.Qt import QDialog, QVBoxLayout, QListWidgetItem, \
                QListWidget, QDialogButtonBox, QSize

        d = QDialog(self)
        d.l = QVBoxLayout()
        d.setLayout(d.l)
        d.list = QListWidget(d)
        d.list.doubleClicked.connect(lambda x: d.accept())
        d.l.addWidget(d.list)
        d.bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel,
                Qt.Horizontal, d)
        d.bb.accepted.connect(d.accept)
        d.bb.rejected.connect(d.reject)
        d.l.addWidget(d.bb)
        d.setWindowTitle(_('Choose builtin recipe'))
        items = []
        for r in get_builtin_recipe_collection():
            id_ = r.get('id', '')
            title = r.get('title', '')
            lang = r.get('language', '')
            if id_ and title:
                items.append((title + ' [%s]'%lang, id_))

        items.sort(key=lambda x:sort_key(x[0]))
        for title, id_ in items:
            item = QListWidgetItem(title)
            item.setData(Qt.UserRole, id_)
            d.list.addItem(item)

        d.resize(QSize(450, 400))
        ret = d.exec_()
        d.list.doubleClicked.disconnect()
        if ret != d.Accepted:
            return

        items = list(d.list.selectedItems())
        if not items:
            return
        item = items[-1]
        id_ = unicode(item.data(Qt.UserRole).toString())
        title = unicode(item.data(Qt.DisplayRole).toString()).rpartition(' [')[0]
        profile = get_builtin_recipe_by_id(id_, download_recipe=True)
        if profile is None:
            raise Exception('Something weird happened')

        if self._model.has_title(title):
            if question_dialog(self, _('Replace recipe?'),
                _('A custom recipe named %s already exists. Do you want to '
                    'replace it?')%title):
                self._model.replace_by_title(title, profile)
            else:
                return
        else:
            self.model.add(title, profile)

        self.clear()
Пример #9
0
    def password_dialog(self, msg=None):
        if not msg:
            msg = _("Please enter your Trezor password")

        d = QDialog()
        d.setModal(1)
        d.setLayout(make_password_dialog(d, None, msg, False))
        return run_password_dialog(d, None, None)
Пример #10
0
    def password_dialog(self, msg=None):
        if not msg:
            msg = _("Please enter your Trezor password")

        d = QDialog()
        d.setModal(1)
        d.setLayout( make_password_dialog(d, None, msg, False) )
        return run_password_dialog(d, None, None)
Пример #11
0
    def password_dialog(self, msg=None):
        if not msg:
            msg = _("Disconnect your BTChip, read the unique second factor PIN, reconnect it and enter the unique second factor PIN")

        d = QDialog()
        d.setModal(1)
        d.setLayout( make_password_dialog(d, None, msg, False) )
        return run_password_dialog(d, None, None)
Пример #12
0
def test():
    app = QApplication([])
    app
    d = QDialog()
    d.setLayout(QVBoxLayout())
    d.layout().addWidget(FontFamilyChooser(d))
    d.layout().addWidget(QFontComboBox(d))
    d.exec_()
Пример #13
0
def test():
    app = QApplication([])
    app
    d = QDialog()
    d.setLayout(QVBoxLayout())
    d.layout().addWidget(FontFamilyChooser(d))
    d.layout().addWidget(QFontComboBox(d))
    d.exec_()
Пример #14
0
    def confirm_quit(self):
        if self.doing_terminal_save:
            return False
        if self.save_manager.has_tasks:
            if not question_dialog(
                    self.gui,
                    _('Are you sure?'),
                    _('The current book is being saved in the background, quitting will abort'
                      ' the save process, are you sure?'),
                    default_yes=False):
                return False

        if self.gui.action_save.isEnabled():
            d = QDialog(self.gui)
            d.l = QGridLayout(d)
            d.setLayout(d.l)
            d.setWindowTitle(_('Unsaved changes'))
            d.i = QLabel('')
            d.i.setPixmap(
                QPixmap(I('save.png')).scaledToHeight(64,
                                                      Qt.SmoothTransformation))
            d.i.setMaximumSize(QSize(d.i.pixmap().width(), 64))
            d.i.setScaledContents(True)
            d.l.addWidget(d.i, 0, 0)
            d.m = QLabel(
                _('There are unsaved changes, if you quit without saving, you will lose them.'
                  ))
            d.m.setWordWrap(True)
            d.l.addWidget(d.m, 0, 1)
            d.bb = QDialogButtonBox(QDialogButtonBox.Cancel)
            d.bb.rejected.connect(d.reject)
            d.bb.accepted.connect(d.accept)
            d.l.addWidget(d.bb, 1, 0, 1, 2)
            d.do_save = None

            def endit(x):
                d.do_save = x
                d.accept()

            b = d.bb.addButton(_('&Save and Quit'),
                               QDialogButtonBox.ActionRole)
            b.setIcon(QIcon(I('save.png')))
            b.clicked.connect(lambda *args: endit(True))
            b = d.bb.addButton(_('&Quit without saving'),
                               QDialogButtonBox.ActionRole)
            b.clicked.connect(lambda *args: endit(False))
            d.resize(d.sizeHint())
            if d.exec_() != d.Accepted or d.do_save is None:
                return False
            if d.do_save:
                self.gui.action_save.trigger()
                self.gui.blocking_job.set_msg(_('Saving, please wait...'))
                self.gui.blocking_job.start()
                self.doing_terminal_save = True
                QTimer.singleShot(50, self.check_terminal_save)
                return False

        return True
Пример #15
0
    def password_dialog(self, msg=None):
        if not msg:
            msg = _(
                "Disconnect your BTChip, read the unique second factor PIN, reconnect it and enter the unique second factor PIN"
            )

        d = QDialog()
        d.setModal(1)
        d.setLayout(make_password_dialog(d, None, msg, False))
        return run_password_dialog(d, None, None)
Пример #16
0
    def confirm_quit(self):
        if self.doing_terminal_save:
            return False
        if self.save_manager.has_tasks:
            if not question_dialog(
                self.gui,
                _("Are you sure?"),
                _(
                    "The current book is being saved in the background, quitting will abort"
                    " the save process, are you sure?"
                ),
                default_yes=False,
            ):
                return False

        if self.gui.action_save.isEnabled():
            d = QDialog(self.gui)
            d.l = QGridLayout(d)
            d.setLayout(d.l)
            d.setWindowTitle(_("Unsaved changes"))
            d.i = QLabel("")
            d.i.setPixmap(QPixmap(I("save.png")).scaledToHeight(64, Qt.SmoothTransformation))
            d.i.setMaximumSize(QSize(d.i.pixmap().width(), 64))
            d.i.setScaledContents(True)
            d.l.addWidget(d.i, 0, 0)
            d.m = QLabel(_("There are unsaved changes, if you quit without saving, you will lose them."))
            d.m.setWordWrap(True)
            d.l.addWidget(d.m, 0, 1)
            d.bb = QDialogButtonBox(QDialogButtonBox.Cancel)
            d.bb.rejected.connect(d.reject)
            d.bb.accepted.connect(d.accept)
            d.l.addWidget(d.bb, 1, 0, 1, 2)
            d.do_save = None

            def endit(x):
                d.do_save = x
                d.accept()

            b = d.bb.addButton(_("&Save and Quit"), QDialogButtonBox.ActionRole)
            b.setIcon(QIcon(I("save.png")))
            b.clicked.connect(lambda *args: endit(True))
            b = d.bb.addButton(_("&Quit without saving"), QDialogButtonBox.ActionRole)
            b.clicked.connect(lambda *args: endit(False))
            d.resize(d.sizeHint())
            if d.exec_() != d.Accepted or d.do_save is None:
                return False
            if d.do_save:
                self.gui.action_save.trigger()
                self.gui.blocking_job.set_msg(_("Saving, please wait..."))
                self.gui.blocking_job.start()
                self.doing_terminal_save = True
                QTimer.singleShot(50, self.check_terminal_save)
                return False

        return True
Пример #17
0
def trezor_passphrase_dialog(msg):
    from chainkey_gui.qt.password_dialog import make_password_dialog, run_password_dialog
    d = QDialog()
    d.setModal(1)
    d.setLayout(make_password_dialog(d, None, msg, False))
    confirmed, p, passphrase = run_password_dialog(d, None, None)
    if not confirmed:
        return None
    if passphrase is None:
        passphrase = ''  # Even blank string is valid Trezor passphrase
    passphrase = unicodedata.normalize('NFKD', unicode(passphrase))
    return passphrase
Пример #18
0
def trezor_passphrase_dialog(msg):
    from chainkey_gui.qt.password_dialog import make_password_dialog, run_password_dialog
    d = QDialog()
    d.setModal(1)
    d.setLayout(make_password_dialog(d, None, msg, False))
    confirmed, p, passphrase = run_password_dialog(d, None, None)
    if not confirmed:
        return None
    if passphrase is None:
        passphrase = '' # Even blank string is valid Trezor passphrase
    passphrase = unicodedata.normalize('NFKD', unicode(passphrase))
    return passphrase
Пример #19
0
 def password_dialog(self, msg=None):
     if not msg:
         msg = _("Do not enter your device PIN here !\r\n\r\n" \
                 "Your BTChip wants to talk to you and tell you a unique second factor code.\r\n" \
                 "For this to work, please open a text editor (on a different computer / device if you believe this computer is compromised) and put your cursor into it, unplug your BTChip and plug it back in.\r\n" \
                 "It should show itself to your computer as a keyboard and output the second factor along with a summary of the transaction it is signing into the text-editor.\r\n\r\n" \
                 "Check that summary and then enter the second factor code here.\r\n" \
                 "Before clicking OK, re-plug the device once more (unplug it and plug it again if you read the second factor code on the same computer)")
     d = QDialog()
     d.setModal(1)
     d.setLayout(make_password_dialog(d, None, msg, False))
     return run_password_dialog(d, None, None)
Пример #20
0
 def password_dialog(self, msg=None):
     if not msg:
         msg = _("Do not enter your device PIN here !\r\n\r\n" \
                 "Your BTChip wants to talk to you and tell you a unique second factor code.\r\n" \
                 "For this to work, please open a text editor (on a different computer / device if you believe this computer is compromised) and put your cursor into it, unplug your BTChip and plug it back in.\r\n" \
                 "It should show itself to your computer as a keyboard and output the second factor along with a summary of the transaction it is signing into the text-editor.\r\n\r\n" \
                 "Check that summary and then enter the second factor code here.\r\n" \
                 "Before clicking OK, re-plug the device once more (unplug it and plug it again if you read the second factor code on the same computer)")
     d = QDialog()
     d.setModal(1)
     d.setLayout( make_password_dialog(d, None, msg, False) )
     return run_password_dialog(d, None, None)
Пример #21
0
    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
Пример #22
0
 def passphrase_dialog(self):
     from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog
     d = QDialog()
     d.setModal(1)
     d.setLayout(make_password_dialog(d, None, self.message, False))
     confirmed, p, passphrase = run_password_dialog(d, None, None)
     if not confirmed:
         QMessageBox.critical(None, _('Error'), _("Password request canceled"), _('OK'))
         self.passphrase = None
     else:
         if passphrase is None:
             passphrase = '' # Even blank string is valid Trezor passphrase
         self.passphrase = unicodedata.normalize('NFKD', unicode(passphrase))
     self.done.set()
Пример #23
0
    def pin_dialog(self, msg):
        d = QDialog(None)
        d.setModal(1)
        d.setWindowTitle(_("Enter PIN"))
        matrix = PinMatrixWidget()

        vbox = QVBoxLayout()
        vbox.addWidget(QLabel(msg))
        vbox.addWidget(matrix)
        vbox.addLayout(ok_cancel_buttons(d))
        d.setLayout(vbox)

        if not d.exec_(): return
        return str(matrix.get_value())
Пример #24
0
    def pin_dialog(self, msg):
        d = QDialog(None)
        d.setModal(1)
        d.setWindowTitle(_("Enter PIN"))
        matrix = PinMatrixWidget()

        vbox = QVBoxLayout()
        vbox.addWidget(QLabel(msg))
        vbox.addWidget(matrix)
        vbox.addLayout(ok_cancel_buttons(d))
        d.setLayout(vbox)

        if not d.exec_(): return
        return str(matrix.get_value())
Пример #25
0
 def passphrase_dialog(self):
     from electrum_oracoin_gui.qt.password_dialog import make_password_dialog, run_password_dialog
     d = QDialog()
     d.setModal(1)
     d.setLayout(make_password_dialog(d, None, self.message, False))
     confirmed, p, passphrase = run_password_dialog(d, None, None)
     if not confirmed:
         QMessageBox.critical(None, _('Error'), _("Password request canceled"), _('OK'))
         self.passphrase = None
     else:
         if passphrase is None:
             passphrase = '' # Even blank string is valid Trezor passphrase
         self.passphrase = unicodedata.normalize('NFKD', unicode(passphrase))
     self.done.set()
Пример #26
0
    def link_stylesheets(self, names):
        s = self.categories['styles']
        sheets = [
            unicode(s.child(i).data(0, NAME_ROLE).toString())
            for i in xrange(s.childCount())
        ]
        if not sheets:
            return error_dialog(
                self,
                _('No stylesheets'),
                _('This book currently has no stylesheets. You must first create a stylesheet'
                  ' before linking it.'),
                show=True)
        d = QDialog(self)
        d.l = l = QVBoxLayout(d)
        d.setLayout(l)
        d.setWindowTitle(_('Choose stylesheets'))
        d.la = la = QLabel(
            _('Choose the stylesheets to link. Drag and drop to re-arrange'))

        la.setWordWrap(True)
        l.addWidget(la)
        d.s = s = QListWidget(d)
        l.addWidget(s)
        s.setDragEnabled(True)
        s.setDropIndicatorShown(True)
        s.setDragDropMode(self.InternalMove)
        s.setAutoScroll(True)
        s.setDefaultDropAction(Qt.MoveAction)
        for name in sheets:
            i = QListWidgetItem(name, s)
            flags = Qt.ItemIsEnabled | Qt.ItemIsUserCheckable | Qt.ItemIsDragEnabled | Qt.ItemIsSelectable
            i.setFlags(flags)
            i.setCheckState(Qt.Checked)
        d.r = r = QCheckBox(_('Remove existing links to stylesheets'))
        r.setChecked(tprefs['remove_existing_links_when_linking_sheets'])
        l.addWidget(r)
        d.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok
                                     | QDialogButtonBox.Cancel)
        bb.accepted.connect(d.accept), bb.rejected.connect(d.reject)
        l.addWidget(bb)
        if d.exec_() == d.Accepted:
            tprefs['remove_existing_links_when_linking_sheets'] = r.isChecked()
            sheets = [
                unicode(s.item(il).text()) for il in xrange(s.count())
                if s.item(il).checkState() == Qt.Checked
            ]
            if sheets:
                self.link_stylesheets_requested.emit(names, sheets,
                                                     r.isChecked())
Пример #27
0
 def pin_dialog(self):
     d = QDialog(None)
     d.setModal(1)
     d.setWindowTitle(_("Enter PIN"))
     d.setWindowFlags(d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
     matrix = PinMatrixWidget()
     vbox = QVBoxLayout()
     vbox.addWidget(QLabel(self.message))
     vbox.addWidget(matrix)
     vbox.addLayout(Buttons(CancelButton(d), OkButton(d)))
     d.setLayout(vbox)
     if not d.exec_():
         self.response = None
     self.response = str(matrix.get_value())
     self.done.set()
Пример #28
0
 def pin_dialog(self):
     d = QDialog(None)
     d.setModal(1)
     d.setWindowTitle(_("Enter PIN"))
     d.setWindowFlags(d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
     matrix = PinMatrixWidget()
     vbox = QVBoxLayout()
     vbox.addWidget(QLabel(self.message))
     vbox.addWidget(matrix)
     vbox.addLayout(Buttons(CancelButton(d), OkButton(d)))
     d.setLayout(vbox)
     if not d.exec_():
         self.response = None
     self.response = str(matrix.get_value())
     self.done.set()
Пример #29
0
    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)
Пример #30
0
    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
Пример #31
0
 def passphrase_dialog(self):
     if type(self.win) is ElectrumWindow:
         passphrase = self.win.password_dialog(_("Please enter your KeepKey passphrase"))
         self.passphrase = unicodedata.normalize('NFKD', unicode(passphrase)) if passphrase else ''
     else:
         assert type(self.win) is InstallWizard
         from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog
         d = QDialog()
         d.setModal(1)
         d.setLayout(make_password_dialog(d, None, self.message, False))
         confirmed, p, passphrase = run_password_dialog(d, None, None)
         if not confirmed:
             QMessageBox.critical(None, _('Error'), _("Password request canceled"), _('OK'))
             self.passphrase = None
         else:
             self.passphrase = unicodedata.normalize('NFKD', unicode(passphrase)) if passphrase else ''
     self.done.set()
Пример #32
0
 def passphrase_dialog(self):
     if type(self.win) is ElectrumWindow:
         passphrase = self.win.password_dialog(_("Please enter your Trezor passphrase"))
         self.passphrase = unicodedata.normalize('NFKD', unicode(passphrase)) if passphrase else ''
     else:
         assert type(self.win) is InstallWizard
         from electrum_ltc_gui.qt.password_dialog import make_password_dialog, run_password_dialog
         d = QDialog()
         d.setModal(1)
         d.setLayout(make_password_dialog(d, None, self.message, False))
         confirmed, p, passphrase = run_password_dialog(d, None, None)
         if not confirmed:
             QMessageBox.critical(None, _('Error'), _("Password request canceled"), _('OK'))
             self.passphrase = None
         else:
             self.passphrase = unicodedata.normalize('NFKD', unicode(passphrase)) if passphrase else ''
     self.done.set()
Пример #33
0
 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
Пример #34
0
 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
Пример #35
0
 def show_debug_info(self):
     info = self.device.device_debug_info()
     d = QDialog(self)
     d.l = l = QVBoxLayout()
     d.setLayout(l)
     d.v = v = QPlainTextEdit()
     d.setWindowTitle(self.device.get_gui_name())
     v.setPlainText(info)
     v.setMinimumWidth(400)
     v.setMinimumHeight(350)
     l.addWidget(v)
     bb = d.bb = QDialogButtonBox(QDialogButtonBox.Close)
     bb.accepted.connect(d.accept)
     bb.rejected.connect(d.reject)
     l.addWidget(bb)
     bb.addButton(_("Copy to clipboard"), bb.ActionRole)
     bb.clicked.connect(lambda: QApplication.clipboard().setText(v.toPlainText()))
     d.exec_()
Пример #36
0
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_()
Пример #37
0
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_()
Пример #38
0
 def show_debug_info(self):
     info = self.device.device_debug_info()
     d = QDialog(self)
     d.l = l = QVBoxLayout()
     d.setLayout(l)
     d.v = v = QPlainTextEdit()
     d.setWindowTitle(self.device.get_gui_name())
     v.setPlainText(info)
     v.setMinimumWidth(400)
     v.setMinimumHeight(350)
     l.addWidget(v)
     bb = d.bb = QDialogButtonBox(QDialogButtonBox.Close)
     bb.accepted.connect(d.accept)
     bb.rejected.connect(d.reject)
     l.addWidget(bb)
     bb.addButton(_('Copy to clipboard'), bb.ActionRole)
     bb.clicked.connect(
         lambda: QApplication.clipboard().setText(v.toPlainText()))
     d.exec_()
Пример #39
0
def customize_remove_unused_css(name, parent, ans):
    d = QDialog(parent)
    d.l = l = QVBoxLayout()
    d.setLayout(d.l)
    d.setWindowTitle(_('Remove unused CSS'))
    d.la = la = QLabel(_(
        'This will remove all CSS rules that do not match any actual content. You'
        ' can also have it automatically remove any class attributes from the HTML'
        ' that do not match any CSS rules, by using the check box below:'))
    la.setWordWrap(True), l.addWidget(la)
    d.c = c = QCheckBox(_('Remove unused &class attributes'))
    c.setChecked(tprefs['remove_unused_classes'])
    l.addWidget(c)
    d.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
    d.l.addWidget(d.bb)
    d.bb.rejected.connect(d.reject)
    d.bb.accepted.connect(d.accept)
    if d.exec_() != d.Accepted:
        raise Abort()
    ans['remove_unused_classes'] = tprefs['remove_unused_classes'] = c.isChecked()
Пример #40
0
def customize_remove_unused_css(name, parent, ans):
    d = QDialog(parent)
    d.l = l = QVBoxLayout()
    d.setLayout(d.l)
    d.setWindowTitle(_('Remove unused CSS'))
    d.la = la = QLabel(
        _('This will remove all CSS rules that do not match any actual content. You'
          ' can also have it automatically remove any class attributes from the HTML'
          ' that do not match any CSS rules, by using the check box below:'))
    la.setWordWrap(True), l.addWidget(la)
    d.c = c = QCheckBox(_('Remove unused &class attributes'))
    c.setChecked(tprefs['remove_unused_classes'])
    l.addWidget(c)
    d.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
    d.l.addWidget(d.bb)
    d.bb.rejected.connect(d.reject)
    d.bb.accepted.connect(d.accept)
    if d.exec_() != d.Accepted:
        raise Abort()
    ans['remove_unused_classes'] = tprefs[
        'remove_unused_classes'] = c.isChecked()
Пример #41
0
 def polish(self, action, name):
     if not self.check_dirtied():
         return
     self.add_savepoint(name)
     try:
         report = tweak_polish(current_container(), {action:True})
     except:
         self.rewind_savepoint()
         raise
     self.apply_container_update_to_gui()
     from calibre.ebooks.markdown import markdown
     report = markdown('# %s\n\n'%self.current_metadata.title + '\n\n'.join(report), output_format='html4')
     d = QDialog(self.gui)
     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)
     d.l.addWidget(d.bb)
     d.bb.rejected.connect(d.reject)
     d.bb.accepted.connect(d.accept)
     d.resize(600, 400)
     d.exec_()
Пример #42
0
 def view_server_logs(self):
     from calibre.library.server import log_access_file, log_error_file
     d = QDialog(self)
     d.resize(QSize(800, 600))
     layout = QVBoxLayout()
     d.setLayout(layout)
     layout.addWidget(QLabel(_('Error log:')))
     el = QPlainTextEdit(d)
     layout.addWidget(el)
     try:
         el.setPlainText(open(log_error_file, 'rb').read().decode('utf8', 'replace'))
     except IOError:
         el.setPlainText('No error log found')
     layout.addWidget(QLabel(_('Access log:')))
     al = QPlainTextEdit(d)
     layout.addWidget(al)
     try:
         al.setPlainText(open(log_access_file, 'rb').read().decode('utf8', 'replace'))
     except IOError:
         al.setPlainText('No access log found')
     bx = QDialogButtonBox(QDialogButtonBox.Ok)
     layout.addWidget(bx)
     bx.accepted.connect(d.accept)
     d.show()
Пример #43
0
    def textChanged(self):
        return self.lineEdit().textChanged

    def clear(self):
        self.lineEdit().clear()
        EnComboBox.clear(self)

    def eventFilter(self, obj, e):
        try:
            c = self.lineEdit().mcompleter
        except AttributeError:
            return False
        etype = e.type()
        if self.eat_focus_out and self is obj and etype == e.FocusOut:
            if c.isVisible():
                return True
        return EnComboBox.eventFilter(self, obj, e)

if __name__ == '__main__':
    from PyQt4.Qt import QDialog, QVBoxLayout
    app = QApplication([])
    d = QDialog()
    d.setLayout(QVBoxLayout())
    le = EditWithComplete(d)
    d.layout().addWidget(le)
    items = ['one', 'otwo', 'othree', 'ooone', 'ootwo',
        'oothree', 'a1', 'a2',u'Edgas', u'Èdgar', u'Édgaq', u'Edgar', u'Édgar']
    le.update_items_cache(items)
    le.show_initial_value('')
    d.exec_()
Пример #44
0
        dev = self.parent().device_manager.connected_device
        dev.highlight_ignored_folders = True
        self.parent().configure_connected_device()
        dev.highlight_ignored_folders = False


if __name__ == "__main__":
    from calibre.gui2 import Application
    from calibre.devices.mtp.driver import MTP_DEVICE
    from calibre.devices.scanner import DeviceScanner

    s = DeviceScanner()
    s.scan()
    app = Application([])
    dev = MTP_DEVICE(None)
    dev.startup()
    cd = dev.detect_managed_devices(s.devices)
    dev.open(cd, "test")
    cw = dev.config_widget()
    d = QDialog()
    d.l = QVBoxLayout()
    d.setLayout(d.l)
    d.l.addWidget(cw)
    bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
    d.l.addWidget(bb)
    bb.accepted.connect(d.accept)
    bb.rejected.connect(d.reject)
    if d.exec_() == d.Accepted:
        cw.commit()
    dev.shutdown()
Пример #45
0
from __future__ import (unicode_literals, division, absolute_import,
                        print_function)

__license__ = 'GPL v3'
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
__docformat__ = 'restructuredtext en'

from calibre.gui2 import Application
from PyQt4.Qt import (QDialog, QGridLayout, QListWidget, QDialogButtonBox,
                      QPushButton, QTimer, QIcon)

app = Application([], force_calibre_style=True)

d = QDialog()
d.l = l = QGridLayout()
d.setLayout(l)
lw = QListWidget()
lw.addItem('Some text guy')
l.addWidget(lw, 0, 0, 2, 1)
bb = QDialogButtonBox()
bb.setStandardButtons(bb.Close)
bb.accepted.connect(d.accept)
bb.rejected.connect(d.reject)
b = bb.addButton('Action', bb.ActionRole)
b.setIcon(QIcon(I('wizard.png')))
l.addWidget(bb, 2, 0, 1, 2)
bb.button(bb.Close).setDefault(True)

b = QPushButton('Normal')
l.addWidget(b, 0, 1, 1, 1)
Пример #46
0
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
Пример #47
0
    def clear(self):
        self.lineEdit().clear()
        EnComboBox.clear(self)

    def eventFilter(self, obj, e):
        try:
            c = self.lineEdit().mcompleter
        except AttributeError:
            return False
        etype = e.type()
        if self.eat_focus_out and self is obj and etype == e.FocusOut:
            if c.isVisible():
                return True
        return EnComboBox.eventFilter(self, obj, e)


if __name__ == '__main__':
    from PyQt4.Qt import QDialog, QVBoxLayout
    app = QApplication([])
    d = QDialog()
    d.setLayout(QVBoxLayout())
    le = EditWithComplete(d)
    d.layout().addWidget(le)
    items = [
        'one', 'otwo', 'othree', 'ooone', 'ootwo', 'oothree', 'a1', 'a2',
        u'Edgas', u'Èdgar', u'Édgaq', u'Edgar', u'Édgar'
    ]
    le.update_items_cache(items)
    le.show_initial_value('')
    d.exec_()
Пример #48
0
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
Пример #49
0
        QDialog.accept(self)
        dev = self.parent().device_manager.connected_device
        dev.highlight_ignored_folders = True
        self.parent().configure_connected_device()
        dev.highlight_ignored_folders = False


if __name__ == '__main__':
    from calibre.gui2 import Application
    from calibre.devices.mtp.driver import MTP_DEVICE
    from calibre.devices.scanner import DeviceScanner
    s = DeviceScanner()
    s.scan()
    app = Application([])
    dev = MTP_DEVICE(None)
    dev.startup()
    cd = dev.detect_managed_devices(s.devices)
    dev.open(cd, 'test')
    cw = dev.config_widget()
    d = QDialog()
    d.l = QVBoxLayout()
    d.setLayout(d.l)
    d.l.addWidget(cw)
    bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
    d.l.addWidget(bb)
    bb.accepted.connect(d.accept)
    bb.rejected.connect(d.reject)
    if d.exec_() == d.Accepted:
        cw.commit()
    dev.shutdown()
Пример #50
0
#!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai
from __future__ import unicode_literals, division, absolute_import, print_function

__license__ = "GPL v3"
__copyright__ = "2012, Kovid Goyal <kovid at kovidgoyal.net>"
__docformat__ = "restructuredtext en"

from calibre.gui2 import Application
from PyQt4.Qt import QDialog, QGridLayout, QListWidget, QDialogButtonBox, QPushButton, QTimer, QIcon

app = Application([], force_calibre_style=True)

d = QDialog()
d.l = l = QGridLayout()
d.setLayout(l)
lw = QListWidget()
lw.addItem("Some text guy")
l.addWidget(lw, 0, 0, 2, 1)
bb = QDialogButtonBox()
bb.setStandardButtons(bb.Close)
bb.accepted.connect(d.accept)
bb.rejected.connect(d.reject)
b = bb.addButton("Action", bb.ActionRole)
b.setIcon(QIcon(I("wizard.png")))
l.addWidget(bb, 2, 0, 1, 2)
bb.button(bb.Close).setDefault(True)

b = QPushButton("Normal")
l.addWidget(b, 0, 1, 1, 1)
Пример #51
0
    def add_builtin_recipe(self):
        from calibre.web.feeds.recipes.collection import \
            get_builtin_recipe_collection, get_builtin_recipe_by_id
        from PyQt4.Qt import QDialog, QVBoxLayout, QListWidgetItem, \
                QListWidget, QDialogButtonBox, QSize

        d = QDialog(self)
        d.l = QVBoxLayout()
        d.setLayout(d.l)
        d.list = QListWidget(d)
        d.list.doubleClicked.connect(lambda x: d.accept())
        d.l.addWidget(d.list)
        d.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
                                Qt.Horizontal, d)
        d.bb.accepted.connect(d.accept)
        d.bb.rejected.connect(d.reject)
        d.l.addWidget(d.bb)
        d.setWindowTitle(_('Choose builtin recipe'))
        items = []
        for r in get_builtin_recipe_collection():
            id_ = r.get('id', '')
            title = r.get('title', '')
            lang = r.get('language', '')
            if id_ and title:
                items.append((title + ' [%s]' % lang, id_))

        items.sort(key=lambda x: sort_key(x[0]))
        for title, id_ in items:
            item = QListWidgetItem(title)
            item.setData(Qt.UserRole, id_)
            d.list.addItem(item)

        d.resize(QSize(450, 400))
        ret = d.exec_()
        d.list.doubleClicked.disconnect()
        if ret != d.Accepted:
            return

        items = list(d.list.selectedItems())
        if not items:
            return
        item = items[-1]
        id_ = unicode(item.data(Qt.UserRole).toString())
        title = unicode(item.data(
            Qt.DisplayRole).toString()).rpartition(' [')[0]
        profile = get_builtin_recipe_by_id(id_, download_recipe=True)
        if profile is None:
            raise Exception('Something weird happened')

        if self._model.has_title(title):
            if question_dialog(
                    self, _('Replace recipe?'),
                    _('A custom recipe named %s already exists. Do you want to '
                      'replace it?') % title):
                self._model.replace_by_title(title, profile)
            else:
                return
        else:
            self.model.add(title, profile)

        self.clear()