def __init__(self, devs, blacklist):
        QWidget.__init__(self)
        self.l = l = QVBoxLayout()
        self.setLayout(l)
        self.la = la = QLabel('<p>'+_(
            '''Select the devices to be <b>ignored</b>. calibre <b>will not</b>
            connect to devices with a checkmark next to their names.'''))
        la.setWordWrap(True)
        l.addWidget(la)
        self.f = f = QListWidget(self)
        l.addWidget(f)

        devs = [(snum, (x[0], parse_date(x[1]))) for snum, x in
                iteritems(devs)]
        for dev, x in sorted(devs, key=lambda x:x[1][1], reverse=True):
            name = x[0]
            name = '%s [%s]'%(name, dev)
            item = QListWidgetItem(name, f)
            item.setData(Qt.ItemDataRole.UserRole, dev)
            item.setFlags(Qt.ItemFlag.ItemIsEnabled|Qt.ItemFlag.ItemIsUserCheckable|Qt.ItemFlag.ItemIsSelectable)
            item.setCheckState(Qt.CheckState.Checked if dev in blacklist else Qt.CheckState.Unchecked)
Exemple #2
0
    def setup_ui(self):
        self.setWindowIcon(QIcon(I('modified.png')))
        self.l = l = QVBoxLayout(self)
        self.stack = s = QStackedLayout()
        l.addLayout(s), l.addWidget(self.bb)
        self.listc = c = QWidget(self)
        s.addWidget(c)
        c.l = l = QVBoxLayout(c)
        c.h = h = QHBoxLayout()
        l.addLayout(h)

        self.search_bar = sb = QLineEdit(self)
        sb.setPlaceholderText(_('Search for a snippet'))
        h.addWidget(sb)
        self.next_button = b = QPushButton(_('&Next'))
        b.clicked.connect(self.find_next)
        h.addWidget(b)

        c.h2 = h = QHBoxLayout()
        l.addLayout(h)
        self.snip_list = sl = QListWidget(self)
        sl.doubleClicked.connect(self.edit_snippet)
        h.addWidget(sl)

        c.l2 = l = QVBoxLayout()
        h.addLayout(l)
        self.add_button = b = QToolButton(self)
        b.setIcon(QIcon(I('plus.png'))), b.setText(_('&Add snippet')), b.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextUnderIcon)
        b.clicked.connect(self.add_snippet)
        l.addWidget(b)

        self.edit_button = b = QToolButton(self)
        b.setIcon(QIcon(I('modified.png'))), b.setText(_('&Edit snippet')), b.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextUnderIcon)
        b.clicked.connect(self.edit_snippet)
        l.addWidget(b)

        self.add_button = b = QToolButton(self)
        b.setIcon(QIcon(I('minus.png'))), b.setText(_('&Remove snippet')), b.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextUnderIcon)
        b.clicked.connect(self.remove_snippet)
        l.addWidget(b)

        self.add_button = b = QToolButton(self)
        b.setIcon(QIcon(I('config.png'))), b.setText(_('Change &built-in')), b.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextUnderIcon)
        b.clicked.connect(self.change_builtin)
        l.addWidget(b)

        for i, snip in enumerate(sorted(user_snippets.get('snippets', []), key=itemgetter('trigger'))):
            item = self.snip_to_item(snip)
            if i == 0:
                self.snip_list.setCurrentItem(item)

        self.edit_snip = es = EditSnippet(self)
        self.stack.addWidget(es)
Exemple #3
0
 def __init__(self, as_dict, parent=None):
     QWidget.__init__(self, parent)
     self.changed_signal.connect(parent.changed_signal)
     self.l = l = QFormLayout(self)
     self.type_widget = t = QComboBox(self)
     l.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.ExpandingFieldsGrow)
     t.addItems([_('Book'), _('Author')])
     l.addRow(_('URL type:'), t)
     self.name_widget = n = QLineEdit(self)
     n.setClearButtonEnabled(True)
     l.addRow(_('Name:'), n)
     self.url_widget = w = QLineEdit(self)
     w.setClearButtonEnabled(True)
     l.addRow(_('URL:'), w)
     if as_dict:
         self.name = as_dict['name']
         self.url = as_dict['url']
         self.url_type = as_dict['type']
     self.type_widget.currentIndexChanged.connect(self.changed_signal)
     self.name_widget.textChanged.connect(self.changed_signal)
     self.url_widget.textChanged.connect(self.changed_signal)
Exemple #4
0
 def __init__(self, parent=None):
     QWidget.__init__(self, parent)
     self.l = l = QHBoxLayout()
     l.setContentsMargins(0, 0, 0, 0)
     self.setLayout(l)
     self.button = QPushButton(self)
     self.button.setIcon(QIcon(I('font.png')))
     self.button.setSizePolicy(QSizePolicy.Policy.Fixed,
                               QSizePolicy.Policy.Fixed)
     l.addWidget(self.button)
     self.default_text = _('Choose &font family')
     self.font_family = None
     self.button.clicked.connect(self.show_chooser)
     self.clear_button = QToolButton(self)
     self.clear_button.setIcon(QIcon(I('clear_left.png')))
     self.clear_button.clicked.connect(self.clear_family)
     l.addWidget(self.clear_button)
     self.setToolTip = self.button.setToolTip
     self.toolTip = self.button.toolTip
     self.clear_button.setToolTip(_('Clear the font family'))
     l.addStretch(1)
Exemple #5
0
    def __init__(self, vertical, parent=None):
        QWidget.__init__(self, parent)
        self._current_pixmap_size = QSize(120, 120)
        self.vertical = vertical

        self.animation = QPropertyAnimation(self, b'current_pixmap_size', self)
        self.animation.setEasingCurve(QEasingCurve(QEasingCurve.Type.OutExpo))
        self.animation.setDuration(1000)
        self.animation.setStartValue(QSize(0, 0))
        self.animation.valueChanged.connect(self.value_changed)

        self.setSizePolicy(
                QSizePolicy.Policy.Expanding if vertical else QSizePolicy.Policy.Minimum,
                QSizePolicy.Policy.Expanding)

        self.default_pixmap = QPixmap(I('default_cover.png'))
        self.pixmap = self.default_pixmap
        self.pwidth = self.pheight = None
        self.data = {}

        self.do_layout()
Exemple #6
0
 def paintEvent(self, ev):
     br = ev.region().boundingRect()
     p = QPainter(self)
     p.setOpacity(0.2)
     p.fillRect(br, QBrush(self.palette().text()))
     p.end()
     QWidget.paintEvent(self, ev)
     p = QPainter(self)
     p.setClipRect(br)
     f = p.font()
     f.setBold(True)
     f.setPointSize(20)
     p.setFont(f)
     p.setPen(Qt.PenStyle.SolidLine)
     r = QRect(0,
               self.dummy.geometry().top() + 10,
               self.geometry().width(), 150)
     p.drawText(
         r, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignTop
         | Qt.TextFlag.TextSingleLine, self.text)
     p.end()
Exemple #7
0
    def __init__(self, tts_client, initial_backend_settings=None, parent=None):
        QWidget.__init__(self, parent)
        self.l = l = QFormLayout(self)
        self.tts_client = tts_client

        with BusyCursor():
            self.voice_data = self.tts_client.get_voice_data()
            self.default_system_rate = self.tts_client.default_system_rate
            self.all_sound_outputs = self.tts_client.get_sound_outputs()

        self.speed = s = QSlider(Qt.Orientation.Horizontal, self)
        s.setMinimumWidth(200)
        l.addRow(_('&Speed of speech (words per minute):'), s)
        s.setRange(self.tts_client.min_rate, self.tts_client.max_rate)
        s.setSingleStep(1)
        s.setPageStep(2)

        self.voices = v = QTableView(self)
        self.voices_model = VoicesModel(self.voice_data, parent=v)
        self.proxy_model = p = QSortFilterProxyModel(self)
        p.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
        p.setSourceModel(self.voices_model)
        v.setModel(p)
        v.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
        v.setSortingEnabled(True)
        v.horizontalHeader().resizeSection(0, QFontMetrics(self.font()).averageCharWidth() * 25)
        v.horizontalHeader().resizeSection(1, QFontMetrics(self.font()).averageCharWidth() * 30)
        v.verticalHeader().close()
        v.verticalHeader().close()
        v.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection)
        v.sortByColumn(0, Qt.SortOrder.AscendingOrder)
        l.addRow(v)

        self.sound_outputs = so = QComboBox(self)
        so.addItem(_('System default'), '')
        for x in self.all_sound_outputs:
            so.addItem(x.get('description') or x['id'], x['id'])
        l.addRow(_('Sound output:'), so)

        self.backend_settings = initial_backend_settings or {}
    def __init__(self, device, rule=None):
        QWidget.__init__(self)
        self._device = weakref.ref(device)

        self.l = l = QHBoxLayout()
        self.setLayout(l)

        p, s = _('Send the %s format to the folder:').partition('%s')[0::2]
        self.l1 = l1 = QLabel(p)
        l.addWidget(l1)
        self.fmt = f = QComboBox(self)
        l.addWidget(f)
        self.l2 = l2 = QLabel(s)
        l.addWidget(l2)
        self.folder = f = QLineEdit(self)
        f.setPlaceholderText(_('Folder on the device'))
        l.addWidget(f)
        self.b = b = QToolButton()
        l.addWidget(b)
        b.setIcon(QIcon(I('document_open.png')))
        b.clicked.connect(self.browse)
        b.setToolTip(_('Browse for a folder on the device'))
        self.rb = rb = QPushButton(QIcon(I('list_remove.png')),
                _('&Remove rule'), self)
        l.addWidget(rb)
        rb.clicked.connect(self.removed)

        for fmt in sorted(BOOK_EXTENSIONS):
            self.fmt.addItem(fmt.upper(), fmt.lower())

        self.fmt.setCurrentIndex(0)

        if rule is not None:
            fmt, folder = rule
            idx = self.fmt.findText(fmt.upper())
            if idx > -1:
                self.fmt.setCurrentIndex(idx)
            self.folder.setText(folder)

        self.ignore = False
    def __init__(self, tts_client, initial_backend_settings=None, parent=None):
        QWidget.__init__(self, parent)
        self.l = l = QFormLayout(self)
        self.tts_client = tts_client

        self.speed = s = QSlider(Qt.Orientation.Horizontal, self)
        s.setTickPosition(QSlider.TickPosition.TicksAbove)
        s.setMinimumWidth(200)
        l.addRow(_('&Speed of speech:'), s)
        s.setRange(self.tts_client.min_rate, self.tts_client.max_rate)
        s.setSingleStep(10)
        s.setTickInterval((s.maximum() - s.minimum()) // 2)

        self.output_modules = om = QComboBox(self)
        with BusyCursor():
            self.voice_data = self.tts_client.get_voice_data()
            self.system_default_output_module = self.tts_client.system_default_output_module
        om.addItem(_('System default'), self.system_default_output_module)
        for x in self.voice_data:
            om.addItem(x, x)
        l.addRow(_('Speech s&ynthesizer:'), om)

        self.voices = v = QTableView(self)
        self.voices_model = VoicesModel(self.voice_data, self.system_default_output_module, parent=v)
        self.proxy_model = p = QSortFilterProxyModel(self)
        p.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
        p.setSourceModel(self.voices_model)
        v.setModel(p)
        v.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
        v.setSortingEnabled(True)
        h = v.horizontalHeader()
        h.resizeSection(0, QFontMetrics(self.font()).averageCharWidth() * 30)
        v.verticalHeader().close()
        v.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection)
        v.sortByColumn(0, Qt.SortOrder.AscendingOrder)
        om.currentIndexChanged.connect(self.output_module_changed)
        l.addRow(v)

        self.backend_settings = initial_backend_settings or {}
Exemple #10
0
    def key_press_event(self, ev, which=0):
        if self.capture == 0:
            return QWidget.keyPressEvent(self, ev)
        sequence = keysequence_from_event(ev)
        if sequence is None:
            return QWidget.keyPressEvent(self, ev)
        ev.accept()

        button = getattr(self, 'button%d' % which)
        button.setStyleSheet('QPushButton { font-weight: normal}')
        button.setText(
            sequence.toString(QKeySequence.SequenceFormat.NativeText))
        self.capture = 0
        dup_desc = self.dup_check(sequence)
        if dup_desc is not None:
            error_dialog(
                self,
                _('Already assigned'),
                str(sequence.toString(QKeySequence.SequenceFormat.NativeText))
                + ' ' + _('already assigned to') + ' ' + dup_desc,
                show=True)
            self.clear_clicked(which=which)
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.l = l = QVBoxLayout(self)
        self.h = h = QHBoxLayout()

        self.la = la = QLabel(self.MSG)
        la.setWordWrap(True)
        l.addWidget(la)
        l.addLayout(h)
        english_sentence = '{preamble} {match_type}'
        sentence = _('{preamble} {match_type}')
        if set(sentence.split()) != set(english_sentence.split()):
            sentence = english_sentence
        parts = sentence.split()
        for clause in parts:
            if clause == '{preamble}':
                self.preamble = w = QLabel(_('If the tag'))
            elif clause == '{match_type}':
                self.match_type = w = QComboBox(self)
                for action, m in MATCH_TYPE_MAP.items():
                    w.addItem(m.text, action)
                w.currentIndexChanged.connect(self.update_state)
            h.addWidget(w)
            if clause is not parts[-1]:
                h.addWidget(QLabel('\xa0'))
        h.addStretch(1)
        self.generic_query = gq = GenericEdit(self)
        self.css_query = cq = CSSEdit(self)
        self.xpath_query = xq = XPathEdit(self, object_name='html_transform_rules_xpath', show_msg=False)
        l.addWidget(gq), l.addWidget(cq), l.addWidget(xq)

        self.thenl = QLabel(_('Then:'))
        l.addWidget(self.thenl)
        self.actions = a = ActionsContainer(self)
        l.addWidget(a)
        self.add_button = b = QPushButton(QIcon(I('plus.png')), _('Add another action'))
        b.clicked.connect(self.actions.new_action)
        l.addWidget(b)
        self.update_state()
Exemple #12
0
    def __init__(self, log, parent=None):
        QWidget.__init__(self, parent)
        self.log = log
        self.abort = Event()
        self.caches = {}

        self.l = l = QVBoxLayout(self)

        names = ['<b>'+p.name+'</b>' for p in metadata_plugins(['identify']) if
                p.is_configured()]
        self.top = QLabel('<p>'+_('calibre is downloading metadata from: ') +
            ', '.join(names))
        self.top.setWordWrap(True)
        l.addWidget(self.top)

        self.splitter = s = QSplitter(self)
        s.setChildrenCollapsible(False)
        l.addWidget(s, 100)
        self.results_view = ResultsView(self)
        self.results_view.book_selected.connect(self.emit_book_selected)
        self.get_result = self.results_view.get_result
        s.addWidget(self.results_view)

        self.comments_view = Comments(self)
        s.addWidget(self.comments_view)
        s.setStretchFactor(0, 2)
        s.setStretchFactor(1, 1)

        self.results_view.show_details_signal.connect(self.comments_view.show_data)

        self.query = QLabel('download starting...')
        self.query.setWordWrap(True)
        l.addWidget(self.query)

        self.comments_view.show_wait()
        state = gprefs.get('metadata-download-identify-widget-splitter-state')
        if state is not None:
            s.restoreState(state)
Exemple #13
0
 def __init__(self, parent):
     QWidget.__init__(self, parent)
     l = QVBoxLayout(parent)
     l.addWidget(self)
     l.setContentsMargins(0, 0, 0, 0)
     l = QFormLayout(self)
     l.setContentsMargins(0, 0, 0, 0)
     l.setFieldGrowthPolicy(
         QFormLayout.FieldGrowthPolicy.AllNonFixedFieldsGrow)
     self.choices = c = QComboBox()
     c.setMinimumContentsLength(30)
     for text, data in [
         (_('Search for the author on Goodreads'), 'search-goodreads'),
         (_('Search for the author on Amazon'), 'search-amzn'),
         (_('Search for the author in your calibre library'),
          'search-calibre'),
         (_('Search for the author on Wikipedia'), 'search-wikipedia'),
         (_('Search for the author on Google Books'), 'search-google'),
         (_('Search for the book on Goodreads'), 'search-goodreads-book'),
         (_('Search for the book on Amazon'), 'search-amzn-book'),
         (_('Search for the book on Google Books'), 'search-google-book'),
         (_('Use a custom search URL'), 'url'),
     ]:
         c.addItem(text, data)
     l.addRow(_('Clicking on &author names should:'), c)
     self.custom_url = u = QLineEdit(self)
     u.setToolTip(
         _('Enter the URL to search. It should contain the string {0}'
           '\nwhich will be replaced by the author name. For example,'
           '\n{1}').format(
               '{author}',
               'https://en.wikipedia.org/w/index.php?search={author}'))
     u.textChanged.connect(self.changed_signal)
     u.setPlaceholderText(_('Enter the URL'))
     c.currentIndexChanged.connect(self.current_changed)
     l.addRow(u)
     self.current_changed()
     c.currentIndexChanged.connect(self.changed_signal)
Exemple #14
0
 def keyPressEvent(self, ev):
     k = ev.key()
     if k in (Qt.Key.Key_Left, Qt.Key.Key_Right, Qt.Key.Key_Up, Qt.Key.Key_Down) and self.selection_state.rect is not None and self.has_selection:
         ev.accept()
         delta = 10 if ev.modifiers() & Qt.KeyboardModifier.ShiftModifier else 1
         x = y = 0
         if k in (Qt.Key.Key_Left, Qt.Key.Key_Right):
             x = delta * (-1 if k == Qt.Key.Key_Left else 1)
         else:
             y = delta * (-1 if k == Qt.Key.Key_Up else 1)
         self.move_selection_rect(x, y)
         self.update()
     else:
         return QWidget.keyPressEvent(self, ev)
Exemple #15
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.setAcceptDrops(True)
        self.setMouseTracking(True)
        self.setFocusPolicy(Qt.FocusPolicy.ClickFocus)
        self.selection_state = SelectionState()
        self.undo_stack = u = QUndoStack()
        u.setUndoLimit(10)
        u.canUndoChanged.connect(self.emit_undo_redo_state)
        u.canRedoChanged.connect(self.emit_undo_redo_state)

        self.original_image_data = None
        self.is_valid = False
        self.original_image_format = None
        self.current_image = None
        self.current_scaled_pixmap = None
        self.last_canvas_size = None
        self.target = QRectF(0, 0, 0, 0)

        self.undo_action = a = self.undo_stack.createUndoAction(self, _('Undo') + ' ')
        a.setIcon(QIcon(I('edit-undo.png')))
        self.redo_action = a = self.undo_stack.createRedoAction(self, _('Redo') + ' ')
        a.setIcon(QIcon(I('edit-redo.png')))
Exemple #16
0
    def __init__(self, model, parent=None):
        QWidget.__init__(self, parent)
        self.l = l = QGridLayout(self)
        self.setLayout(l)
        self.setContentsMargins(0, 0, 0, 0)

        self.view = v = QListView(self)
        self.d = SpacedDelegate(v)
        v.doubleClicked.connect(self.double_clicked)
        v.setItemDelegate(self.d)
        v.setModel(model)
        l.addWidget(v, 0, 0, 1, -1)
        model.dataChanged.connect(self.data_changed)

        self.rb = b = QPushButton(QIcon(I('edit-undo.png')), _('&Revert to'), self)
        b.setToolTip(_('Revert the book to the selected checkpoint'))
        b.clicked.connect(self.revert_clicked)
        l.addWidget(b, 1, 1)

        self.cb = b = QPushButton(QIcon(I('diff.png')), _('&Compare'), self)
        b.setToolTip(_('Compare the state of the book at the selected checkpoint with the current state'))
        b.clicked.connect(self.compare_clicked)
        l.addWidget(b, 1, 0)
    def __init__(self, all_formats, format_map):
        QWidget.__init__(self)
        self.l = l = QGridLayout()
        self.setLayout(l)

        self.f = f = QListWidget(self)
        l.addWidget(f, 0, 0, 3, 1)
        unchecked_formats = sorted(all_formats - set(format_map))
        for fmt in format_map + unchecked_formats:
            item = QListWidgetItem(fmt, f)
            item.setData(Qt.ItemDataRole.UserRole, fmt)
            item.setFlags(Qt.ItemFlag.ItemIsEnabled|Qt.ItemFlag.ItemIsUserCheckable|Qt.ItemFlag.ItemIsSelectable)
            item.setCheckState(Qt.CheckState.Checked if fmt in format_map else Qt.CheckState.Unchecked)

        self.button_up = b = QToolButton(self)
        b.setIcon(QIcon(I('arrow-up.png')))
        l.addWidget(b, 0, 1)
        b.clicked.connect(self.up)

        self.button_down = b = QToolButton(self)
        b.setIcon(QIcon(I('arrow-down.png')))
        l.addWidget(b, 2, 1)
        b.clicked.connect(self.down)
    def __init__(self, tts_client, initial_backend_settings=None, parent=None):
        QWidget.__init__(self, parent)
        self.l = l = QFormLayout(self)
        self.tts_client = tts_client

        with BusyCursor():
            self.voice_data = self.tts_client.get_voice_data()
            self.default_system_rate = self.tts_client.default_system_rate

        self.speed = s = QSlider(Qt.Orientation.Horizontal, self)
        s.setMinimumWidth(200)
        l.addRow(_('&Speed of speech (words per minute):'), s)
        s.setRange(self.tts_client.min_rate, self.tts_client.max_rate)
        s.setTickPosition(QSlider.TickPosition.TicksAbove)
        s.setTickInterval((s.maximum() - s.minimum()) // 2)
        s.setSingleStep(10)

        self.voices = v = QTableView(self)
        self.voices_model = VoicesModel(self.voice_data, parent=v)
        self.proxy_model = p = QSortFilterProxyModel(self)
        p.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
        p.setSourceModel(self.voices_model)
        v.setModel(p)
        v.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
        v.setSortingEnabled(True)
        v.horizontalHeader().resizeSection(
            0,
            QFontMetrics(self.font()).averageCharWidth() * 20)
        v.horizontalHeader().resizeSection(
            1,
            QFontMetrics(self.font()).averageCharWidth() * 30)
        v.verticalHeader().close()
        v.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection)
        v.sortByColumn(0, Qt.SortOrder.AscendingOrder)
        l.addRow(v)

        self.backend_settings = initial_backend_settings or {}
Exemple #19
0
 def __init__(self, parent):
     self.restrict_to_book_ids = frozenset()
     QWidget.__init__(self, parent)
     v = QVBoxLayout(self)
     v.setContentsMargins(0, 0, 0, 0)
     h = QHBoxLayout()
     h.setContentsMargins(0, 0, 0, 0)
     v.addLayout(h)
     self.rla = QLabel(_('Restrict to') + ': ')
     h.addWidget(self.rla)
     la = QLabel(_('Type:'))
     h.addWidget(la)
     self.types_box = tb = QComboBox(self)
     tb.la = la
     tb.currentIndexChanged.connect(self.restrictions_changed)
     connect_lambda(tb.currentIndexChanged, tb, lambda tb: gprefs.set('browse_annots_restrict_to_type', tb.currentData()))
     la.setBuddy(tb)
     tb.setToolTip(_('Show only annotations of the specified type'))
     h.addWidget(tb)
     la = QLabel(_('User:'******'browse_annots_restrict_to_user', ub.currentData()))
     la.setBuddy(ub)
     ub.setToolTip(_('Show only annotations created by the specified user'))
     h.addWidget(ub)
     h.addStretch(10)
     h = QHBoxLayout()
     self.restrict_to_books_cb = cb = QCheckBox('')
     self.update_book_restrictions_text()
     cb.setToolTip(_('Only show annotations from books that have been selected in the calibre library'))
     cb.setChecked(bool(gprefs.get('show_annots_from_selected_books_only', False)))
     cb.stateChanged.connect(self.show_only_selected_changed)
     h.addWidget(cb)
     v.addLayout(h)
Exemple #20
0
    def __init__(self, name, plugins, gui_name, parent=None):
        QWidget.__init__(self, parent)
        self._layout = QVBoxLayout()
        self.setLayout(self._layout)
        self.label = QLabel(gui_name)
        self.sep = QFrame(self)
        self.bf = QFont()
        self.bf.setBold(True)
        self.label.setFont(self.bf)
        self.sep.setFrameShape(QFrame.Shape.HLine)
        self._layout.addWidget(self.label)
        self._layout.addWidget(self.sep)

        self.plugins = plugins

        self.bar = QToolBar(self)
        self.bar.setStyleSheet('QToolBar { border: none; background: none }')
        lh = QApplication.instance().line_height
        self.bar.setIconSize(QSize(2 * lh, 2 * lh))
        self.bar.setMovable(False)
        self.bar.setFloatable(False)
        self.bar.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextUnderIcon)
        self._layout.addWidget(self.bar)
        self.actions = []
        for p in plugins:
            target = partial(self.triggered, p)
            ac = self.bar.addAction(QIcon(p.icon),
                                    p.gui_name.replace('&', '&&'), target)
            ac.setToolTip(textwrap.fill(p.description))
            ac.setWhatsThis(textwrap.fill(p.description))
            ac.setStatusTip(p.description)
            self.actions.append(ac)
            w = self.bar.widgetForAction(ac)
            w.setCursor(Qt.CursorShape.PointingHandCursor)
            if hasattr(w, 'setAutoRaise'):
                w.setAutoRaise(True)
            w.setMinimumWidth(100)
Exemple #21
0
 def mouseMoveEvent(self, ev):
     if hasattr(self, 'hyperlink_rect'):
         pos = ev.pos()
         hovering = self.hyperlink_rect.contains(pos)
         self.update_hover(hovering)
         cursor = Qt.CursorShape.ArrowCursor
         for r, row in enumerate(self.rows):
             for cell in row:
                 if cell.rect.contains(pos):
                     cursor = Qt.CursorShape.PointingHandCursor if cell.rect is self.hyperlink_rect else Qt.CursorShape.IBeamCursor
                 if r == 0:
                     break
             if cursor != Qt.CursorShape.ArrowCursor:
                 break
         self.setCursor(cursor)
     return QWidget.mouseMoveEvent(self, ev)
Exemple #22
0
 def key_press_event(self, ev, which=0):
     code = ev.key()
     if self.capture == 0 or code in (0, Qt.Key.Key_unknown,
             Qt.Key.Key_Shift, Qt.Key.Key_Control, Qt.Key.Key_Alt, Qt.Key.Key_Meta,
             Qt.Key.Key_AltGr, Qt.Key.Key_CapsLock, Qt.Key.Key_NumLock, Qt.Key.Key_ScrollLock):
         return QWidget.keyPressEvent(self, ev)
     sequence = QKeySequence(code|(int(ev.modifiers()) & (~Qt.KeyboardModifier.KeypadModifier)))
     setattr(self, 'shortcut%d'%which, sequence)
     self.clear_button(which)
     self.capture = 0
     dup_desc = self.dup_check(sequence, self.key)
     if dup_desc is not None:
         error_dialog(self, _('Already assigned'),
                 str(sequence.toString(QKeySequence.SequenceFormat.NativeText)) + ' ' +
                 _('already assigned to') + ' ' + dup_desc, show=True)
         self.clear_clicked(which=which)
Exemple #23
0
    def color_override(self, name):
        w = QWidget(self)
        l = QHBoxLayout(w)

        def b(name, text, tt):
            ans = QRadioButton(text, w)
            l.addWidget(ans)
            ans.setToolTip(tt)
            setattr(w, name, ans)
            ans.setObjectName(name)
            return ans

        b(
            'unset', _('No change'),
            _('Use the colors from the book styles, defaulting to black-on-white'
              ))
        b(
            'auto', _('Theme based'),
            _('When using a dark theme force dark colors, otherwise same as "No change"'
              ))
        b('manual', _('Custom'), _('Choose a custom color'))

        c = w.color_button = ColorButton(parent=w)
        l.addWidget(c)
        connect_lambda(c.clicked, w, lambda w: w.manual.setChecked(True))

        def getter(w):
            if w.unset.isChecked():
                return 'unset'
            if w.auto.isChecked():
                return 'auto'
            return w.color_button.color or 'auto'

        def setter(w, val):
            val = val or 'auto'
            if val == 'unset':
                w.unset.setChecked(True)
            elif val == 'auto':
                w.auto.setChecked(True)
            else:
                w.manual.setChecked(True)
                w.color_button.color = val

        self(name, widget=w, getter=getter, setter=setter)
        l.setContentsMargins(0, 0, 0, 0)
        return w
    def init_main_window_mixin(self, db):
        self.setObjectName('MainWindow')
        self.setWindowIcon(QIcon(I('lt.png')))
        self.setWindowTitle(__appname__)

        self.setContextMenuPolicy(Qt.ContextMenuPolicy.NoContextMenu)
        self.centralwidget = QWidget(self)
        self.setCentralWidget(self.centralwidget)
        self._central_widget_layout = l = QVBoxLayout(self.centralwidget)
        l.setContentsMargins(0, 0, 0, 0)
        l.setSpacing(0)
        self.resize(1012, 740)
        self.location_manager = LocationManager(self)

        self.iactions['Fetch News'].init_scheduler(db)

        self.search_bar = SearchBar(self)
        self.bars_manager = BarsManager(self.donate_action,
                                        self.location_manager, self)
        for bar in self.bars_manager.main_bars:
            self.addToolBar(Qt.ToolBarArea.TopToolBarArea, bar)
            bar.setStyleSheet('QToolBar { border: 0px }')
        for bar in self.bars_manager.child_bars:
            self.addToolBar(Qt.ToolBarArea.BottomToolBarArea, bar)
            bar.setStyleSheet('QToolBar { border: 0px }')
        self.bars_manager.update_bars()
        # This is disabled because it introduces various toolbar related bugs
        # The width of the toolbar becomes the sum of both toolbars
        if tweaks['unified_title_toolbar_on_osx']:
            try:
                self.setUnifiedTitleAndToolBarOnMac(True)
            except AttributeError:
                pass  # PyQt seems to be missing this property

        # And now, start adding the real widgets
        l.addWidget(self.search_bar)

        # Add in the widget for the shutdown messages. It is invisible until a
        # message is shown
        smw = self.shutdown_message_widget = QLabel(self)
        smw.setAlignment(Qt.AlignmentFlag.AlignCenter)
        smw.setVisible(False)
        smw.setAutoFillBackground(True)
        smw.setStyleSheet(
            'QLabel { background-color: rgba(200, 200, 200, 200); color: black }'
        )
Exemple #25
0
    def setup_ui(self):
        self.l = l = QVBoxLayout(self)
        self.splitter = s = QSplitter(self)
        s.setChildrenCollapsible(False)
        l.addWidget(s), l.addWidget(self.bb)
        self.bb.setStandardButtons(QDialogButtonBox.StandardButton.Yes
                                   | QDialogButtonBox.StandardButton.No)
        self.left = w = QWidget(self)
        s.addWidget(w)
        w.l = l = QVBoxLayout(w)
        l.setContentsMargins(0, 0, 0, 0)

        def cb(name, text, tt=''):
            ans = QCheckBox(text)
            l.addWidget(ans)
            prefs_key = ans.prefs_key = 'choose-merge-cb-' + name
            ans.setChecked(gprefs.get(prefs_key, True))
            connect_lambda(ans.stateChanged,
                           self,
                           lambda self, state: self.state_changed(
                               getattr(self, name), state),
                           type=Qt.ConnectionType.QueuedConnection)
            if tt:
                ans.setToolTip(tt)
            setattr(self, name, ans)
            return ans

        cb('merge_metadata', _('Merge metadata'),
           _('Merge the metadata of the selected books into the target book'))
        cb(
            'merge_formats', _('Merge formats'),
            _('Merge the book files of the selected books into the target book'
              ))
        cb('delete_books', _('Delete merged books'),
           _('Delete the selected books after merging'))
        l.addStretch(10)
        self.msg = la = QLabel(self)
        la.setWordWrap(True)
        l.addWidget(la)
        self.update_msg()

        self.right = r = Target(self.mi, self)
        s.addWidget(r)
Exemple #26
0
    def __init__(self, username, restriction, parent=None):
        QDialog.__init__(self, parent)
        self.setWindowTitle(_('Change library access permissions for {}').format(username))
        self.username = username
        self._items = []
        self.l = l = QFormLayout(self)
        l.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.AllNonFixedFieldsGrow)

        self.libraries = t = QWidget(self)
        t.setObjectName('libraries')
        t.l = QVBoxLayout(self.libraries)
        self.atype = a = QComboBox(self)
        a.addItems([_('All libraries'), _('Only the specified libraries'), _('All except the specified libraries')])
        self.library_restrictions = restriction['library_restrictions'].copy()
        if restriction['allowed_library_names']:
            a.setCurrentIndex(1)
            self.items = restriction['allowed_library_names']
        elif restriction['blocked_library_names']:
            a.setCurrentIndex(2)
            self.items = restriction['blocked_library_names']
        else:
            a.setCurrentIndex(0)
        a.currentIndexChanged.connect(self.atype_changed)
        l.addRow(_('Allow access to:'), a)

        self.msg = la = QLabel(self)
        la.setWordWrap(True)
        l.addRow(la)
        self.la = la = QLabel(_('Specify the libraries below:'))
        la.setWordWrap(True)
        self.sa = sa = QScrollArea(self)
        sa.setWidget(t), sa.setWidgetResizable(True)
        l.addRow(la), l.addRow(sa)
        self.atype_changed()

        self.bb = bb = QDialogButtonBox(
            QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
        )
        bb.accepted.connect(self.accept), bb.rejected.connect(self.reject)
        l.addWidget(bb)
        self.items = self.items
Exemple #27
0
    def setup_ui(self):
        self.l = l = QVBoxLayout(self)
        self.splitter = s = QSplitter(self)
        s.setChildrenCollapsible(False)
        l.addWidget(s), l.addWidget(self.bb)
        self.bb.setStandardButtons(QDialogButtonBox.StandardButton.Yes
                                   | QDialogButtonBox.StandardButton.No)

        self.left = w = QWidget(self)
        s.addWidget(w)
        w.l = l = QVBoxLayout(w)
        l.setContentsMargins(0, 0, 0, 0)
        self.la = la = QLabel(self.msg)
        la.setWordWrap(True)
        l.addWidget(la)
        self.confirm = c = QCheckBox(_('Show this confirmation again'), self)
        c.setChecked(True)
        c.stateChanged.connect(self.toggle)
        l.addWidget(c)

        self.right = r = Target(self.mi, self)
        s.addWidget(r)
Exemple #28
0
    def setup_ui(self):
        from calibre.gui2.convert.look_and_feel_ui import Ui_Form
        f, w = Ui_Form(), QWidget()
        f.setupUi(w)
        self.l = l = QFormLayout(self)
        self.setLayout(l)

        l.addRow(
            QLabel(
                _('Select what style information you want completely removed:')
            ))
        self.h = h = QHBoxLayout()

        for name, text in (
            ('fonts', _('&Fonts')),
            ('margins', _('&Margins')),
            ('padding', _('&Padding')),
            ('floats', _('Flo&ats')),
            ('colors', _('&Colors')),
        ):
            c = QCheckBox(text)
            setattr(self, 'opt_' + name, c)
            h.addWidget(c)
            c.setToolTip(getattr(f, 'filter_css_' + name).toolTip())
        l.addRow(h)

        self.others = o = QLineEdit(self)
        l.addRow(_('&Other CSS properties:'), o)
        o.setToolTip(f.filter_css_others.toolTip())

        if self.current_name is not None:
            self.filter_current = c = QCheckBox(
                _('Only filter CSS in the current file (%s)') %
                self.current_name)
            l.addRow(c)

        l.addRow(self.bb)
Exemple #29
0
 def __init__(self, parent=None):
     QWidget.__init__(self, parent)
     if hasattr(self, 'setupUi'):
         self.setupUi(self)
     self.settings = {}
Exemple #30
0
 def __init__(self, parent=None):
     QWidget.__init__(self, parent)
     self.setVisible(False)
     self.l = QVBoxLayout(self)
     self.items = {}