Esempio n. 1
0
 def write_stats(self):
     locs = list(self.stats.keys())
     locs.sort(cmp=lambda x, y: cmp(self.stats[x], self.stats[y]),
             reverse=True)
     for key in locs[500:]:
         self.stats.pop(key)
     gprefs.set('library_usage_stats', self.stats)
    def options(self):
        # Save/return the current options
        # exclude_genre stores literally
        # Section switches store as True/False
        # others store as lists

        opts_dict = {}
        opt_value = unicode(self.library_url.text())
        opts_dict['library_url'] = opt_value
        gprefs.set(self.name + '_' + 'library_url', opt_value)
        opt_value = unicode(self.excluded_tags.text())
        opt_value = unicode([tag.strip() for tag in opt_value.split(',')])
        gprefs.set(self.name + '_' + 'exclusion_tags', opt_value)
        opts_dict['exclusion_tags'] = opt_value

        opts_dict['generate_series'] = True
        opts_dict['generate_recently_added'] = False
        try:
            opts_dict['output_profile'] = [load_defaults('page_setup')['output_profile']]
        except:
            opts_dict['output_profile'] = ['default']
        opts_dict['use_existing_cover'] = False
        opts_dict['thumb_width'] = 1.0

        if self.DEBUG:
            print "opts_dict"
            for opt in sorted(opts_dict.keys(), key=sort_key):
                print " %s: %s" % (opt, repr(opts_dict[opt]))
        return opts_dict
Esempio n. 3
0
    def options(self):

        # Save the currently activated fields
        fields = []
        for x in xrange(self.db_fields.count()):
            item = self.db_fields.item(x)
            if item.isSelected():
                fields.append(unicode(item.text()))
        gprefs.set(self.name+'_db_fields', fields)

        # Dictionary currently activated fields
        if len(self.db_fields.selectedItems()):
            opts_dict = {'fields':[unicode(i.text()) for i in self.db_fields.selectedItems()]}
        else:
            opts_dict = {'fields':['all']}

        # Save/return the current options
        # bib_cit stores as text
        # 'bibfile_enc','bibfile_enctag' stores as int (Indexes)
        for opt in self.OPTION_FIELDS:
            if opt[0] in ['bibfile_enc', 'bibfile_enctag', 'bib_entry']:
                opt_value = getattr(self,opt[0]).currentIndex()
            elif opt[0] in ['impcit', 'addfiles'] :
                opt_value = getattr(self, opt[0]).isChecked()
            else :
                opt_value = unicode(getattr(self, opt[0]).text())
            gprefs.set(self.name + '_' + opt[0], opt_value)

            opts_dict[opt[0]] = opt_value

        return opts_dict
Esempio n. 4
0
 def do_map(self, book_ids, selected):
     from calibre.ebooks.metadata.tag_mapper import map_tags
     from calibre.gui2.tag_mapper import RulesDialog
     from calibre.gui2.device import BusyCursor
     d = RulesDialog(self.gui)
     d.setWindowTitle(ngettext(
         'Map tags for one book in the library',
         'Map tags for {} books in the library', len(book_ids)).format(len(book_ids)))
     d.rules = gprefs.get('library-tag-mapper-ruleset', ())
     txt = ngettext(
         'The changes will be applied to the <b>selected book</b>',
         'The changes will be applied to the <b>{} selected books</b>', len(book_ids)) if selected else ngettext(
         'The changes will be applied to <b>one book in the library</b>',
         'The changes will be applied to <b>{} books in the library</b>', len(book_ids))
     d.edit_widget.msg_label.setText(d.edit_widget.msg_label.text() + '<p>' + txt.format(len(book_ids)))
     if d.exec_() != d.Accepted:
         return
     with BusyCursor():
         rules = d.rules
         gprefs.set('library-tag-mapper-ruleset', rules)
         db = self.gui.current_db.new_api
         tag_map = db.all_field_for('tags', book_ids)
         changed_tag_map = {}
         for book_id, tags in iteritems(tag_map):
             tags = list(tags)
             new_tags = map_tags(tags, rules)
             if tags != new_tags:
                 changed_tag_map[book_id] = new_tags
         if changed_tag_map:
             db.set_field('tags', changed_tag_map)
             self.gui.library_view.model().refresh_ids(tuple(changed_tag_map), current_row=self.gui.library_view.currentIndex().row())
Esempio n. 5
0
 def commit(self):
     widths = []
     for i in range(0, self.opt_columns.columnCount()):
         widths.append(self.opt_columns.columnWidth(i))
     gprefs.set('custcol-prefs-table-geometry', widths)
     rr = ConfigWidgetBase.commit(self)
     return self.apply_custom_column_changes() or rr
Esempio n. 6
0
 def done(self, r):
     saved_layout = (bytearray(self.saveGeometry()), bytearray(self.splitter.saveState()))
     gprefs.set('book_info_dialog_layout', saved_layout)
     ret = QDialog.done(self, r)
     self.view.model().new_bookdisplay_data.disconnect(self.slave)
     self.view = self.link_delegate = self.gui = None
     self.closed.emit(self)
     return ret
Esempio n. 7
0
 def on_shutdown(self):
     gprefs.set('preferences dialog geometry', bytearray(self.saveGeometry()))
     if self.committed:
         self.gui.must_restart_before_config = self.must_restart
         self.gui.tags_view.recount()
         self.gui.create_device_menu()
         self.gui.set_device_menu_items_state(bool(self.gui.device_connected))
         self.gui.bars_manager.apply_settings()
         self.gui.bars_manager.update_bars()
         self.gui.build_context_menus()
Esempio n. 8
0
    def options(self):
        # Save/return the current options
        # exclude_genre stores literally
        # generate_titles, generate_recently_added store as True/False
        # others store as lists

        opts_dict = {}
        # Save values to gprefs
        for opt in self.OPTION_FIELDS:
            c_name, c_def, c_type = opt
            if c_type in ['check_box', 'radio_button']:
                opt_value = getattr(self, c_name).isChecked()
            elif c_type in ['combo_box']:
                opt_value = unicode(getattr(self,c_name).currentText()).strip()
            elif c_type in ['line_edit']:
                opt_value = unicode(getattr(self, c_name).text()).strip()
            elif c_type in ['spin_box']:
                opt_value = unicode(getattr(self, c_name).value())
            gprefs.set(self.name + '_' + c_name, opt_value)

            # Construct opts object
            if c_name == 'exclude_tags':
                # store as list
                opts_dict[c_name] = opt_value.split(',')
            else:
                opts_dict[c_name] = opt_value

        # Generate markers for hybrids
        opts_dict['read_book_marker'] = "%s:%s" % (self.read_source_field_name,
                                                   self.read_pattern.text())
        opts_dict['exclude_book_marker'] = "%s:%s" % (self.exclude_source_field_name,
                                                       self.exclude_pattern.text())

        # Generate specs for merge_comments, header_note_source_field
        checked = ''
        if self.merge_before.isChecked():
            checked = 'before'
        elif self.merge_after.isChecked():
            checked = 'after'
        include_hr = self.include_hr.isChecked()
        opts_dict['merge_comments'] = "%s:%s:%s" % \
            (self.merge_source_field_name, checked, include_hr)

        opts_dict['header_note_source_field'] = self.header_note_source_field_name

        # Append the output profile
        try:
            opts_dict['output_profile'] = [load_defaults('page_setup')['output_profile']]
        except:
            opts_dict['output_profile'] = ['default']
        if False:
            print "opts_dict"
            for opt in sorted(opts_dict.keys()):
                print " %s: %s" % (opt, repr(opts_dict[opt]))
        return opts_dict
Esempio n. 9
0
    def closeEvent(self, *args):
        gprefs.set('preferences_window_geometry',
                bytearray(self.saveGeometry()))
        if self.committed:
            self.gui.must_restart_before_config = self.must_restart
            self.gui.tags_view.recount()
            self.gui.create_device_menu()
            self.gui.set_device_menu_items_state(bool(self.gui.device_connected))
            self.gui.bars_manager.apply_settings()
            self.gui.bars_manager.update_bars()
            self.gui.build_context_menus()

        return QMainWindow.closeEvent(self, *args)
Esempio n. 10
0
    def options(self):
        # Save the currently activated fields
        fields = []
        for x in range(self.db_fields.count()):
            item = self.db_fields.item(x)
            if item.isSelected():
                fields.append(unicode(item.text()))
        gprefs.set(self.name+'_db_fields', fields)

        # Return a dictionary with current options for this widget
        if len(self.db_fields.selectedItems()):
            return {'fields':[unicode(item.text()) for item in self.db_fields.selectedItems()]}
        else:
            return {'fields':['all']}
Esempio n. 11
0
    def options(self):
        # Save the currently activated fields
        fields, all_fields = [], []
        for x in xrange(self.db_fields.count()):
            item = self.db_fields.item(x)
            all_fields.append(unicode(item.data(Qt.UserRole)))
            if item.checkState() == Qt.Checked:
                fields.append(unicode(item.data(Qt.UserRole)))
        gprefs.set(self.name+'_db_fields', fields)
        gprefs.set(self.name + '_db_fields_sort_order', {x:i for i, x in enumerate(all_fields)})

        # Return a dictionary with current options for this widget
        if len(fields):
            return {'fields':fields}
        else:
            return {'fields':['all']}
Esempio n. 12
0
 def save_settings(self):
     if not self.something_selected:
         return error_dialog(self, _('No actions selected'),
             _('You must select at least one action before saving'),
                             show=True)
     name, ok = QInputDialog.getText(self, _('Choose name'),
             _('Choose a name for these settings'))
     if ok:
         name = unicode(name).strip()
         if name:
             settings = {ac:getattr(self, 'opt_'+ac).isChecked() for ac in
                         self.all_actions}
             saved = gprefs.get('polish_settings', {})
             saved[name] = settings
             gprefs.set('polish_settings', saved)
             self.setup_load_button()
Esempio n. 13
0
 def save_settings(self):
     xpaths = self.xpaths
     if not xpaths:
         return error_dialog(self, _('No XPaths'),
                             _('No XPaths have been entered'), show=True)
     if not self.check():
         return
     name, ok = QInputDialog.getText(self, _('Choose name'),
             _('Choose a name for these settings'))
     if ok:
         name = unicode(name).strip()
         if name:
             saved = gprefs.get('xpath_toc_settings', {})
             saved[name] = {i:x for i, x in enumerate(xpaths)}
             gprefs.set('xpath_toc_settings', saved)
             self.setup_load_button()
Esempio n. 14
0
    def setup_ui(self):
        self.vl = vl = QVBoxLayout(self)
        self.stack = l = QStackedLayout()
        self.pi = pi = ProgressIndicator(self, 256)
        vl.addLayout(l), vl.addWidget(self.bb)
        self.restore_defs_button = b = self.bb.addButton(_('Restore &default icons'), self.bb.ActionRole)
        b.clicked.connect(self.restore_defaults)
        b.setIcon(QIcon(I('view-refresh.png')))
        self.c = c = QWidget(self)
        self.c.v = v = QVBoxLayout(self.c)
        v.addStretch(), v.addWidget(pi, 0, Qt.AlignCenter)
        self.wait_msg = m = QLabel(self)
        v.addWidget(m, 0, Qt.AlignCenter), v.addStretch()
        f = m.font()
        f.setBold(True), f.setPointSize(28), m.setFont(f)
        self.start_spinner()

        l.addWidget(c)
        self.w = w = QWidget(self)
        l.addWidget(w)
        w.l = l = QGridLayout(w)

        def add_row(x, y=None):
            if isinstance(x, type('')):
                x = QLabel(x)
            row = l.rowCount()
            if y is None:
                if isinstance(x, QLabel):
                    x.setWordWrap(True)
                l.addWidget(x, row, 0, 1, 2)
            else:
                if isinstance(x, QLabel):
                    x.setBuddy(y)
                l.addWidget(x, row, 0), l.addWidget(y, row, 1)
        add_row(_(
            'Choose an icon theme below. You will need to restart'
            ' calibre to see the new icons.'))
        add_row(_('Current icon theme:') + '\xa0<b>' + (self.current_theme or 'None'))
        self.sort_by = sb = QComboBox(self)
        add_row(_('&Sort by:'), sb)
        sb.addItems([_('Number of icons'), _('Popularity'), _('Name'),])
        sb.setEditable(False), sb.setCurrentIndex(gprefs.get('choose_icon_theme_sort_by', 1))
        sb.currentIndexChanged[int].connect(self.re_sort)
        sb.currentIndexChanged[int].connect(lambda : gprefs.set('choose_icon_theme_sort_by', sb.currentIndex()))
        self.theme_list = tl = QListWidget(self)
        tl.setVerticalScrollMode(tl.ScrollPerPixel)
        self.delegate = Delegate(tl)
        tl.setItemDelegate(self.delegate)
        tl.itemDoubleClicked.connect(self.accept)
        add_row(tl)

        t = Thread(name='GetIconThemes', target=self.get_themes)
        t.daemon = True
        t.start()
Esempio n. 15
0
 def start_content_server(self, check_started=True):
     from calibre.srv.embedded import Server
     if not gprefs.get('server3_warning_done', False):
         gprefs.set('server3_warning_done', True)
         if os.path.exists(os.path.join(config_dir, 'server.py')):
             try:
                 os.remove(os.path.join(config_dir, 'server.py'))
             except EnvironmentError:
                 pass
             warning_dialog(self, _('Content server changed!'), _(
                 'calibre 3 comes with a completely re-written content server.'
                 ' As such any custom configuration you have for the content'
                 ' server no longer applies. You should check and refresh your'
                 ' settings in Preferences->Sharing->Sharing over the net'), show=True)
     self.content_server = Server(self.library_broker, Dispatcher(self.handle_changes_from_server))
     self.content_server.state_callback = Dispatcher(
             self.iactions['Connect Share'].content_server_state_changed)
     if check_started:
         self.content_server.start_failure_callback = \
             Dispatcher(self.content_server_start_failed)
     self.content_server.start()
Esempio n. 16
0
    def setup_ui(self):
        self.l = l = QGridLayout(self)
        self.items = i = QListWidget(self)
        i.setSelectionMode(i.SingleSelection)
        i.currentItemChanged.connect(self.current_changed)
        l.addWidget(i)
        self.v = v = QVBoxLayout()
        l.addLayout(v, 0, 1)
        self.sort_alphabetically = sa = QCheckBox(_('&Sort libraries alphabetically'))
        v.addWidget(sa)
        sa.setChecked(bool(gprefs.get('copy_to_library_choose_library_sort_alphabetically', True)))
        sa.stateChanged.connect(self.resort)

        connect_lambda(sa.stateChanged, self, lambda self:
                gprefs.set('copy_to_library_choose_library_sort_alphabetically',
                bool(self.sort_alphabetically.isChecked())))
        la = self.la = QLabel(_('Library &path:'))
        v.addWidget(la)
        le = self.le = QLineEdit(self)
        la.setBuddy(le)
        b = self.b = QToolButton(self)
        b.setIcon(QIcon(I('document_open.png')))
        b.setToolTip(_('Browse for library'))
        b.clicked.connect(self.browse)
        h = QHBoxLayout()
        h.addWidget(le), h.addWidget(b)
        v.addLayout(h)
        v.addStretch(10)
        bb = self.bb
        bb.setStandardButtons(QDialogButtonBox.Cancel)
        self.delete_after_copy = False
        b = bb.addButton(_('&Copy'), bb.AcceptRole)
        b.setIcon(QIcon(I('edit-copy.png')))
        b.setToolTip(_('Copy to the specified library'))
        b2 = bb.addButton(_('&Move'), bb.AcceptRole)
        connect_lambda(b2.clicked, self, lambda self: setattr(self, 'delete_after_copy', True))
        b2.setIcon(QIcon(I('edit-cut.png')))
        b2.setToolTip(_('Copy to the specified library and delete from the current library'))
        b.setDefault(True)
        l.addWidget(bb, 1, 0, 1, 2)
        self.items.setFocus(Qt.OtherFocusReason)
Esempio n. 17
0
 def __init__(self, formats, parent=None):
     QDialog.__init__(self, parent)
     self.setWindowTitle(_('Choose format to edit'))
     self.setWindowIcon(QIcon(I('dialog_question.png')))
     l = self.l = QGridLayout()
     self.setLayout(l)
     la = self.la = QLabel(_('Choose which format you want to edit:'))
     formats = sorted(formats)
     l.addWidget(la, 0, 0, 1, -1)
     self.buttons = []
     for i, f in enumerate(formats):
         b = QCheckBox('&' + f, self)
         l.addWidget(b, 1, i)
         self.buttons.append(b)
     self.formats = gprefs.get('edit_toc_last_selected_formats', ['EPUB',])
     bb = self.bb = QDialogButtonBox(
         QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
     bb.addButton(_('&All formats'),
                  bb.ActionRole).clicked.connect(self.do_all)
     bb.accepted.connect(self.accept)
     bb.rejected.connect(self.reject)
     l.addWidget(bb, l.rowCount(), 0, 1, -1)
     self.resize(self.sizeHint())
     connect_lambda(self.finished, self, lambda self, code:gprefs.set('edit_toc_last_selected_formats', list(self.formats)))
Esempio n. 18
0
 def clear_settings(self):
     gprefs.set('xpath_toc_settings', {})
     self.setup_load_button()
Esempio n. 19
0
 def accept(self):
     gprefs.set('diff_dialog_geom', bytearray(self.saveGeometry()))
     self.compare_widget.save_comments_controls_state()
     super().accept()
Esempio n. 20
0
 def save_geometry(self):
     gprefs.set('comments_dialog_geom', bytearray(self.saveGeometry()))
Esempio n. 21
0
 def reject(self):
     gprefs.set('single-cover-fetch-dialog-geometry',
                bytearray(self.saveGeometry()))
     self.covers_widget.cancel()
     return QDialog.reject(self)
Esempio n. 22
0
 def save_geometry(self):
     gprefs.set('authors-edit-geometry', bytearray(self.saveGeometry()))
Esempio n. 23
0
 def accept(self, *args):
     gprefs.set('single-cover-fetch-dialog-geometry',
                bytearray(self.saveGeometry()))
     self.cover_pixmap = self.covers_widget.cover_pixmap()
     QDialog.accept(self)
Esempio n. 24
0
 def _save_settings(self):
     gprefs.set('cover_generation_save_settings_for_future',
                self.save_settings.isChecked())
     gprefs.set('cover_settings_dialog_geom',
                bytearray(self.saveGeometry()))
     self.settings.save_state()
Esempio n. 25
0
    def __init__(self, ids, get_metadata, field_metadata, parent=None,
                 window_title=None,
                 reject_button_tooltip=None,
                 accept_all_tooltip=None,
                 reject_all_tooltip=None,
                 revert_tooltip=None,
                 intro_msg=None,
                 action_button=None,
                 **kwargs):
        QDialog.__init__(self, parent)
        self.l = l = QVBoxLayout()
        self.setLayout(l)
        self.setWindowIcon(QIcon(I('auto_author_sort.png')))
        self.get_metadata = get_metadata
        self.ids = list(ids)
        self.total = len(self.ids)
        self.accepted = OrderedDict()
        self.rejected_ids = set()
        self.window_title = window_title or _('Compare metadata')

        if intro_msg:
            self.la = la = QLabel(intro_msg)
            la.setWordWrap(True)
            l.addWidget(la)

        self.compare_widget = CompareSingle(field_metadata, parent=parent, revert_tooltip=revert_tooltip, **kwargs)
        self.sa = sa = QScrollArea()
        l.addWidget(sa)
        sa.setWidget(self.compare_widget)
        sa.setWidgetResizable(True)

        self.bb = bb = QDialogButtonBox(QDialogButtonBox.Cancel)
        bb.button(bb.Cancel).setAutoDefault(False)
        bb.rejected.connect(self.reject)
        if self.total > 1:
            self.aarb = b = bb.addButton(_('&Accept all remaining'), bb.YesRole)
            b.setIcon(QIcon(I('ok.png'))), b.setAutoDefault(False)
            if accept_all_tooltip:
                b.setToolTip(accept_all_tooltip)
            b.clicked.connect(self.accept_all_remaining)
            self.rarb = b = bb.addButton(_('Re&ject all remaining'), bb.NoRole)
            b.setIcon(QIcon(I('minus.png'))), b.setAutoDefault(False)
            if reject_all_tooltip:
                b.setToolTip(reject_all_tooltip)
            b.clicked.connect(self.reject_all_remaining)
            self.sb = b = bb.addButton(_('&Reject'), bb.ActionRole)
            b.clicked.connect(partial(self.next_item, False))
            b.setIcon(QIcon(I('minus.png'))), b.setAutoDefault(False)
            if reject_button_tooltip:
                b.setToolTip(reject_button_tooltip)
            self.next_action = ac = QAction(self)
            ac.setShortcut(QKeySequence(Qt.ALT | Qt.Key_Right))
            self.addAction(ac)
        if action_button is not None:
            self.acb = b = bb.addButton(action_button[0], bb.ActionRole)
            b.setIcon(QIcon(action_button[1]))
            self.action_button_action = action_button[2]
            b.clicked.connect(self.action_button_clicked)
        self.nb = b = bb.addButton(_('&Next') if self.total > 1 else _('&OK'), bb.ActionRole)
        if self.total > 1:
            b.setToolTip(_('Move to next [%s]') % self.next_action.shortcut().toString(QKeySequence.NativeText))
            self.next_action.triggered.connect(b.click)
        b.setIcon(QIcon(I('forward.png' if self.total > 1 else 'ok.png')))
        b.clicked.connect(partial(self.next_item, True))
        b.setDefault(True), b.setAutoDefault(True)
        self.bbh = h = QHBoxLayout()
        h.setContentsMargins(0, 0, 0, 0)
        l.addLayout(h)
        self.markq = m = QCheckBox(_('&Mark rejected books'))
        m.setChecked(gprefs['metadata_diff_mark_rejected'])
        m.stateChanged[int].connect(lambda : gprefs.set('metadata_diff_mark_rejected', m.isChecked()))
        m.setToolTip(_('Mark rejected books in the book list after this dialog is closed'))
        h.addWidget(m), h.addWidget(bb)

        self.next_item(True)

        desktop = QApplication.instance().desktop()
        geom = desktop.availableGeometry(parent or self)
        width = max(700, min(950, geom.width()-50))
        height = max(650, min(1000, geom.height()-100))
        self.resize(QSize(width, height))
        geom = gprefs.get('diff_dialog_geom', None)
        if geom is not None:
            self.restoreGeometry(geom)
        b.setFocus(Qt.OtherFocusReason)
Esempio n. 26
0
 def clear_settings(self):
     gprefs.set('xpath_toc_settings', {})
     self.setup_load_button()
Esempio n. 27
0
 def cleanup(self):
     self.canvas.break_cycles()
     gprefs.set('image-trim-dialog-geometry', bytearray(self.saveGeometry()))
Esempio n. 28
0
    def __init__(self, parent, db, author, series=None, title=None, dup_title=None):
        QDialog.__init__(self, parent)
        self.db = db

        self.setWindowTitle(_('How many empty books?'))

        self._layout = QGridLayout(self)
        self.setLayout(self._layout)

        self.qty_label = QLabel(_('How many empty books should be added?'))
        self._layout.addWidget(self.qty_label, 0, 0, 1, 2)

        self.qty_spinbox = QSpinBox(self)
        self.qty_spinbox.setRange(1, 10000)
        self.qty_spinbox.setValue(1)
        self._layout.addWidget(self.qty_spinbox, 1, 0, 1, 2)

        self.author_label = QLabel(_('Set the author of the new books to:'))
        self._layout.addWidget(self.author_label, 2, 0, 1, 2)

        self.authors_combo = EditWithComplete(self)
        self.authors_combo.setSizeAdjustPolicy(
                self.authors_combo.AdjustToMinimumContentsLengthWithIcon)
        self.authors_combo.setEditable(True)
        self._layout.addWidget(self.authors_combo, 3, 0, 1, 1)
        self.initialize_authors(db, author)

        self.clear_button = QToolButton(self)
        self.clear_button.setIcon(QIcon(I('trash.png')))
        self.clear_button.setToolTip(_('Reset author to Unknown'))
        self.clear_button.clicked.connect(self.reset_author)
        self._layout.addWidget(self.clear_button, 3, 1, 1, 1)

        self.series_label = QLabel(_('Set the series of the new books to:'))
        self._layout.addWidget(self.series_label, 4, 0, 1, 2)

        self.series_combo = EditWithComplete(self)
        self.series_combo.setSizeAdjustPolicy(
                self.authors_combo.AdjustToMinimumContentsLengthWithIcon)
        self.series_combo.setEditable(True)
        self._layout.addWidget(self.series_combo, 5, 0, 1, 1)
        self.initialize_series(db, series)

        self.sclear_button = QToolButton(self)
        self.sclear_button.setIcon(QIcon(I('trash.png')))
        self.sclear_button.setToolTip(_('Reset series'))
        self.sclear_button.clicked.connect(self.reset_series)
        self._layout.addWidget(self.sclear_button, 5, 1, 1, 1)

        self.title_label = QLabel(_('Set the title of the new books to:'))
        self._layout.addWidget(self.title_label, 6, 0, 1, 2)

        self.title_edit = QLineEdit(self)
        self.title_edit.setText(title or '')
        self._layout.addWidget(self.title_edit, 7, 0, 1, 1)

        self.tclear_button = QToolButton(self)
        self.tclear_button.setIcon(QIcon(I('trash.png')))
        self.tclear_button.setToolTip(_('Reset title'))
        self.tclear_button.clicked.connect(self.title_edit.clear)
        self._layout.addWidget(self.tclear_button, 7, 1, 1, 1)

        self.format_label = QLabel(_('Also create an empty e-book in format:'))
        self._layout.addWidget(self.format_label, 8, 0, 1, 2)
        c = self.format_value = QComboBox(self)
        from calibre.ebooks.oeb.polish.create import valid_empty_formats
        possible_formats = [''] + sorted(x.upper() for x in valid_empty_formats)
        c.addItems(possible_formats)
        c.setToolTip(_('Also create an empty book format file that you can subsequently edit'))
        if gprefs.get('create_empty_epub_file', False):
            # Migration of the check box
            gprefs.set('create_empty_format_file', 'epub')
            del gprefs['create_empty_epub_file']
        use_format = gprefs.get('create_empty_format_file', '').upper()
        try:
            c.setCurrentIndex(possible_formats.index(use_format))
        except Exception:
            pass
        self._layout.addWidget(c, 9, 0, 1, 1)

        self.copy_formats = cf = QCheckBox(_('Also copy book &formats when duplicating a book'), self)
        cf.setToolTip(_(
            'Also copy all e-book files into the newly created duplicate'
            ' books.'))
        cf.setChecked(gprefs.get('create_empty_copy_dup_formats', False))
        self._layout.addWidget(cf, 10, 0, 1, -1)

        button_box = self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        button_box.accepted.connect(self.accept)
        button_box.rejected.connect(self.reject)
        self._layout.addWidget(button_box, 11, 0, 1, -1)
        if dup_title:
            self.dup_button = b = button_box.addButton(_('&Duplicate current book'), button_box.ActionRole)
            b.clicked.connect(self.do_duplicate_book)
            b.setIcon(QIcon(I('edit-copy.png')))
            b.setToolTip(_(
                'Make the new empty book records exact duplicates\n'
                'of the current book "%s", with all metadata identical'
            ) % dup_title)
        self.resize(self.sizeHint())
        self.duplicate_current_book = False
Esempio n. 29
0
 def _save_settings(self):
     gprefs.set('cover_generation_save_settings_for_future',
                self.save_settings.isChecked())
     gprefs.set('cover_settings_dialog_geom',
                bytearray(self.saveGeometry()))
     self.settings.save_state()
 def explode(self):
     self.show_msg(_('Exploding, please wait...'))
     if len(self.fmt_choice_buttons) > 1:
         gprefs.set('last_tweak_format', self.current_format.upper())
     QTimer.singleShot(5, self.do_explode)
Esempio n. 31
0
 def save_geometry(self):
     gprefs.set('enum-values-edit-geometry', bytearray(self.saveGeometry()))
Esempio n. 32
0
 def show_again_changed(self):
     gprefs.set('show_get_books_download_info',
                self.toggle_checkbox.isChecked())
Esempio n. 33
0
 def cleanup(self):
     self.canvas.break_cycles()
     gprefs.set('image-trim-dialog-geometry', bytearray(self.saveGeometry()))
Esempio n. 34
0
 def toggle_cover_fit(self, state):
     gprefs.set('book_info_dialog_fit_cover', self.fit_cover.isChecked())
     self.resize_cover()
Esempio n. 35
0
 def closeEvent(self, e):
     gprefs.set('store_dialog_main_window_geometry', bytearray(self.saveGeometry()))
     MainWindow.closeEvent(self, e)
Esempio n. 36
0
def set_saved_field_data(name, fields, sort_order):
    db = get_gui().current_db
    db.new_api.set_pref('catalog-field-data-for-' + name, {'fields': fields, 'sort_order': sort_order})
    gprefs.set(name+'_db_fields', fields)
    gprefs.set(name + '_db_fields_sort_order', sort_order)
Esempio n. 37
0
 def write_stats(self):
     locs = list(self.stats.keys())
     locs.sort(key=lambda x: self.stats[x], reverse=True)
     for key in locs[500:]:
         self.stats.pop(key)
     gprefs.set('library_usage_stats', self.stats)
Esempio n. 38
0
 def save_geometry(self):
     gprefs.set('duplicates-question-dialog-geometry',
                bytearray(self.saveGeometry()))
Esempio n. 39
0
 def save_comments_controls_state(self):
     if 'comments' in self.widgets:
         vis = self.widgets['comments'].new.toolbars_visible
         if vis != gprefs.get('diff_widget_show_comments_controls', True):
             gprefs.set('diff_widget_show_comments_controls', vis)
Esempio n. 40
0
 def save_geometry(self):
     gprefs.set('comments_dialog_geom', bytearray(self.saveGeometry()))
Esempio n. 41
0
 def save_geometry(self):
     gprefs.set('scheduler_dialog_geometry', bytearray(self.saveGeometry()))
Esempio n. 42
0
 def toggle_toolbars(self):
     visible = self.toolbars_visible
     getattr(self, ('hide' if visible else 'show') + '_toolbars')()
     if self.toolbar_prefs_name is not None:
         gprefs.set(self.toolbar_prefs_name, visible)
Esempio n. 43
0
 def toggle_cover_fit(self, state):
     gprefs.set('book_info_dialog_fit_cover', self.fit_cover.isChecked())
     self.resize_cover()
Esempio n. 44
0
    def __init__(self,
                 ids,
                 get_metadata,
                 field_metadata,
                 parent=None,
                 window_title=None,
                 reject_button_tooltip=None,
                 accept_all_tooltip=None,
                 reject_all_tooltip=None,
                 revert_tooltip=None,
                 intro_msg=None,
                 action_button=None,
                 **kwargs):
        QDialog.__init__(self, parent)
        self.l = l = QVBoxLayout()
        self.setLayout(l)
        self.setWindowIcon(QIcon(I('auto_author_sort.png')))
        self.get_metadata = get_metadata
        self.ids = list(ids)
        self.total = len(self.ids)
        self.accepted = OrderedDict()
        self.rejected_ids = set()
        self.window_title = window_title or _('Compare metadata')

        if intro_msg:
            self.la = la = QLabel(intro_msg)
            la.setWordWrap(True)
            l.addWidget(la)

        self.compare_widget = CompareSingle(field_metadata,
                                            parent=parent,
                                            revert_tooltip=revert_tooltip,
                                            **kwargs)
        self.sa = sa = QScrollArea()
        l.addWidget(sa)
        sa.setWidget(self.compare_widget)
        sa.setWidgetResizable(True)

        self.bb = bb = QDialogButtonBox(QDialogButtonBox.Cancel)
        bb.button(bb.Cancel).setAutoDefault(False)
        bb.rejected.connect(self.reject)
        if self.total > 1:
            self.aarb = b = bb.addButton(_('&Accept all remaining'),
                                         bb.YesRole)
            b.setIcon(QIcon(I('ok.png'))), b.setAutoDefault(False)
            if accept_all_tooltip:
                b.setToolTip(accept_all_tooltip)
            b.clicked.connect(self.accept_all_remaining)
            self.rarb = b = bb.addButton(_('Re&ject all remaining'), bb.NoRole)
            b.setIcon(QIcon(I('minus.png'))), b.setAutoDefault(False)
            if reject_all_tooltip:
                b.setToolTip(reject_all_tooltip)
            b.clicked.connect(self.reject_all_remaining)
            self.sb = b = bb.addButton(_('&Reject'), bb.ActionRole)
            b.clicked.connect(partial(self.next_item, False))
            b.setIcon(QIcon(I('minus.png'))), b.setAutoDefault(False)
            if reject_button_tooltip:
                b.setToolTip(reject_button_tooltip)
            self.next_action = ac = QAction(self)
            ac.setShortcut(QKeySequence(Qt.ALT | Qt.Key_Right))
            self.addAction(ac)
        if action_button is not None:
            self.acb = b = bb.addButton(action_button[0], bb.ActionRole)
            b.setIcon(QIcon(action_button[1]))
            self.action_button_action = action_button[2]
            b.clicked.connect(self.action_button_clicked)
        self.nb = b = bb.addButton(
            _('&Next') if self.total > 1 else _('&OK'), bb.ActionRole)
        if self.total > 1:
            b.setToolTip(
                _('Move to next [%s]') %
                self.next_action.shortcut().toString(QKeySequence.NativeText))
            self.next_action.triggered.connect(b.click)
        b.setIcon(QIcon(I('forward.png' if self.total > 1 else 'ok.png')))
        b.clicked.connect(partial(self.next_item, True))
        b.setDefault(True), b.setAutoDefault(True)
        self.bbh = h = QHBoxLayout()
        h.setContentsMargins(0, 0, 0, 0)
        l.addLayout(h)
        self.markq = m = QCheckBox(_('&Mark rejected books'))
        m.setChecked(gprefs['metadata_diff_mark_rejected'])
        m.stateChanged[int].connect(
            lambda: gprefs.set('metadata_diff_mark_rejected', m.isChecked()))
        m.setToolTip(
            _('Mark rejected books in the book list after this dialog is closed'
              ))
        h.addWidget(m), h.addWidget(bb)

        self.next_item(True)

        desktop = QApplication.instance().desktop()
        geom = desktop.availableGeometry(parent or self)
        width = max(700, min(950, geom.width() - 50))
        height = max(650, min(1000, geom.height() - 100))
        self.resize(QSize(width, height))
        geom = gprefs.get('diff_dialog_geom', None)
        if geom is not None:
            self.restoreGeometry(geom)
        b.setFocus(Qt.OtherFocusReason)
Esempio n. 45
0
 def write_state(self, state):
     name = unicode(self.objectName())
     if name:
         gprefs.set(name + ' books view state', state)
Esempio n. 46
0
 def save_comments_controls_state(self):
     if 'comments' in self.widgets:
         vis = self.widgets['comments'].new.toolbars_visible
         if vis != gprefs.get('diff_widget_show_comments_controls', True):
             gprefs.set('diff_widget_show_comments_controls', vis)
Esempio n. 47
0
 def reject(self):
     gprefs.set('diff_dialog_geom', bytearray(self.saveGeometry()))
     self.compare_widget.save_comments_controls_state()
     super(CompareMany, self).reject()
Esempio n. 48
0
 def reject(self):
     gprefs.set('diff_dialog_geom', bytearray(self.saveGeometry()))
     self.compare_widget.save_comments_controls_state()
     super(CompareMany, self).reject()
Esempio n. 49
0
    def setup_ui(self):
        self.vl = vl = QVBoxLayout(self)
        self.stack = l = QStackedLayout()
        self.pi = pi = ProgressIndicator(self, 256)
        vl.addLayout(l), vl.addWidget(self.bb)
        self.restore_defs_button = b = self.bb.addButton(
            _('Restore &default icons'), self.bb.ActionRole)
        b.clicked.connect(self.restore_defaults)
        b.setIcon(QIcon(I('view-refresh.png')))
        self.c = c = QWidget(self)
        self.c.v = v = QVBoxLayout(self.c)
        v.addStretch(), v.addWidget(pi, 0, Qt.AlignCenter)
        self.wait_msg = m = QLabel(self)
        v.addWidget(m, 0, Qt.AlignCenter), v.addStretch()
        f = m.font()
        f.setBold(True), f.setPointSize(28), m.setFont(f)
        self.start_spinner()

        l.addWidget(c)
        self.w = w = QWidget(self)
        l.addWidget(w)
        w.l = l = QGridLayout(w)

        def add_row(x, y=None):
            if isinstance(x, type('')):
                x = QLabel(x)
            row = l.rowCount()
            if y is None:
                if isinstance(x, QLabel):
                    x.setWordWrap(True)
                l.addWidget(x, row, 0, 1, 2)
            else:
                if isinstance(x, QLabel):
                    x.setBuddy(y)
                l.addWidget(x, row, 0), l.addWidget(y, row, 1)

        add_row(
            _('Choose an icon theme below. You will need to restart'
              ' calibre to see the new icons.'))
        add_row(
            _('Current icon theme:') + '\xa0<b>' +
            (self.current_theme or 'None'))
        self.sort_by = sb = QComboBox(self)
        add_row(_('&Sort by:'), sb)
        sb.addItems([
            _('Number of icons'),
            _('Popularity'),
            _('Name'),
        ])
        sb.setEditable(False), sb.setCurrentIndex(
            gprefs.get('choose_icon_theme_sort_by', 1))
        sb.currentIndexChanged[int].connect(self.re_sort)
        sb.currentIndexChanged[int].connect(
            lambda: gprefs.set('choose_icon_theme_sort_by', sb.currentIndex()))
        self.theme_list = tl = QListWidget(self)
        tl.setVerticalScrollMode(tl.ScrollPerPixel)
        self.delegate = Delegate(tl)
        tl.setItemDelegate(self.delegate)
        tl.itemDoubleClicked.connect(self.accept)
        add_row(tl)

        t = Thread(name='GetIconThemes', target=self.get_themes)
        t.daemon = True
        t.start()
Esempio n. 50
0
 def explode(self):
     self.show_msg(_('Exploding, please wait...'))
     if len(self.fmt_choice_buttons) > 1:
         gprefs.set('last_tweak_format', self.current_format.upper())
     QTimer.singleShot(5, self.do_explode)
Esempio n. 51
0
 def toggle_toolbars(self):
     visible = self.toolbars_visible
     getattr(self, ('hide' if visible else 'show') + '_toolbars')()
     if self.toolbar_prefs_name is not None:
         gprefs.set(self.toolbar_prefs_name, visible)
Esempio n. 52
0
 def save_geometry(self):
     gprefs.set('duplicates-question-dialog-geometry', bytearray(self.saveGeometry()))
Esempio n. 53
0
    def __init__(self,
                 ids,
                 get_metadata,
                 field_metadata,
                 parent=None,
                 window_title=None,
                 reject_button_tooltip=None,
                 accept_all_tooltip=None,
                 reject_all_tooltip=None,
                 revert_tooltip=None,
                 intro_msg=None,
                 action_button=None,
                 **kwargs):
        QDialog.__init__(self, parent)
        self.stack = s = QStackedLayout(self)
        self.w = w = QWidget(self)
        self.l = l = QVBoxLayout(w)
        s.addWidget(w)
        self.next_called = False
        self.setWindowIcon(QIcon(I('auto_author_sort.png')))
        self.get_metadata = get_metadata
        self.ids = list(ids)
        self.total = len(self.ids)
        self.accepted = OrderedDict()
        self.rejected_ids = set()
        self.window_title = window_title or _('Compare metadata')

        if intro_msg:
            self.la = la = QLabel(intro_msg)
            la.setWordWrap(True)
            l.addWidget(la)

        self.compare_widget = CompareSingle(field_metadata,
                                            parent=parent,
                                            revert_tooltip=revert_tooltip,
                                            **kwargs)
        self.sa = sa = QScrollArea()
        l.addWidget(sa)
        sa.setWidget(self.compare_widget)
        sa.setWidgetResizable(True)
        self.cover_zoom = cz = CoverZoom(self)
        cz.bb.rejected.connect(self.reject)
        s.addWidget(cz)
        self.compare_widget.zoom_requested.connect(self.show_zoomed_cover)

        self.bb = bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Cancel)
        bb.button(QDialogButtonBox.StandardButton.Cancel).setAutoDefault(False)
        bb.rejected.connect(self.reject)
        if self.total > 1:
            self.aarb = b = bb.addButton(_('&Accept all remaining'),
                                         QDialogButtonBox.ButtonRole.YesRole)
            b.setIcon(QIcon(I('ok.png'))), b.setAutoDefault(False)
            if accept_all_tooltip:
                b.setToolTip(accept_all_tooltip)
            b.clicked.connect(self.accept_all_remaining)
            self.rarb = b = bb.addButton(
                _('Re&ject all remaining'),
                QDialogButtonBox.ButtonRole.ActionRole)
            b.setIcon(QIcon(I('minus.png'))), b.setAutoDefault(False)
            if reject_all_tooltip:
                b.setToolTip(reject_all_tooltip)
            b.clicked.connect(self.reject_all_remaining)
            self.sb = b = bb.addButton(_('R&eject'),
                                       QDialogButtonBox.ButtonRole.ActionRole)
            ac = QAction(self)
            ac.setShortcut(
                QKeySequence(Qt.KeyboardModifier.AltModifier
                             | Qt.KeyboardModifier.ShiftModifier
                             | Qt.Key.Key_Right))
            ac.triggered.connect(b.click)
            self.addAction(ac)
            b.setToolTip(
                _('Reject changes and move to next [{}]').format(
                    ac.shortcut().toString(
                        QKeySequence.SequenceFormat.NativeText)))
            connect_lambda(b.clicked, self, lambda self: self.next_item(False))
            b.setIcon(QIcon(I('minus.png'))), b.setAutoDefault(False)
            if reject_button_tooltip:
                b.setToolTip(reject_button_tooltip)
            self.next_action = ac = QAction(self)
            ac.setShortcut(
                QKeySequence(Qt.KeyboardModifier.AltModifier
                             | Qt.Key.Key_Right))
            self.addAction(ac)
        if action_button is not None:
            self.acb = b = bb.addButton(action_button[0],
                                        QDialogButtonBox.ButtonRole.ActionRole)
            b.setIcon(QIcon(action_button[1]))
            self.action_button_action = action_button[2]
            b.clicked.connect(self.action_button_clicked)
        self.nb = b = bb.addButton(
            _('&Next') if self.total > 1 else _('&OK'),
            QDialogButtonBox.ButtonRole.ActionRole)
        if self.total > 1:
            b.setToolTip(
                _('Move to next [%s]') % self.next_action.shortcut().toString(
                    QKeySequence.SequenceFormat.NativeText))
            self.next_action.triggered.connect(b.click)
        b.setIcon(QIcon(I('forward.png' if self.total > 1 else 'ok.png')))
        connect_lambda(b.clicked, self, lambda self: self.next_item(True))
        b.setDefault(True), b.setAutoDefault(True)
        self.bbh = h = QHBoxLayout()
        h.setContentsMargins(0, 0, 0, 0)
        l.addLayout(h)
        self.markq = m = QCheckBox(_('&Mark rejected books'))
        m.setChecked(gprefs['metadata_diff_mark_rejected'])
        connect_lambda(
            m.stateChanged[int], self, lambda self: gprefs.set(
                'metadata_diff_mark_rejected', self.markq.isChecked()))
        m.setToolTip(
            _('Mark rejected books in the book list after this dialog is closed'
              ))
        h.addWidget(m), h.addWidget(bb)

        self.next_item(True)

        geom = (parent or self).screen().availableSize()
        width = max(700, min(950, geom.width() - 50))
        height = max(650, min(1000, geom.height() - 100))
        self.resize(QSize(width, height))
        geom = gprefs.get('diff_dialog_geom', None)
        if geom is not None:
            QApplication.instance().safe_restore_geometry(self, geom)
        b.setFocus(Qt.FocusReason.OtherFocusReason)
        self.next_called = False
Esempio n. 54
0
 def clear_settings(self):
     gprefs.set('polish_settings', {})
     self.setup_load_button()
Esempio n. 55
0
def set_saved_field_data(name, fields, sort_order):
    db = get_gui().current_db
    db.new_api.set_pref('catalog-field-data-for-' + name, {'fields': fields, 'sort_order': sort_order})
    gprefs.set(name+'_db_fields', fields)
    gprefs.set(name + '_db_fields_sort_order', sort_order)
Esempio n. 56
0
 def write_state(self, state):
     name = unicode(self.objectName())
     if name:
         gprefs.set(name + ' books view state', state)
Esempio n. 57
0
 def save_state(self):
     gprefs.set('tag browser search box visible',
                self.toggle_search_button.isChecked())