Exemplo n.º 1
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'))

    def label(text):
        la = QLabel(text)
        la.setWordWrap(True), l.addWidget(la), la.setMinimumWidth(450)
        l.addWidget(la)
        return la

    d.la = label(
        _('This will remove all CSS rules that do not match any actual content.'
          ' There are a couple of additional cleanups you can enable, below:'))
    d.c = c = QCheckBox(_('Remove unused &class attributes'))
    c.setChecked(tprefs['remove_unused_classes'])
    l.addWidget(c)
    d.la2 = label('<span style="font-size:small; font-style: italic">' + _(
        'Remove all class attributes from the HTML that do not match any existing CSS rules'
    ))
    d.m = m = QCheckBox(_('Merge CSS rules with identical selectors'))
    m.setChecked(tprefs['merge_identical_selectors'])
    l.addWidget(m)
    d.la3 = label('<span style="font-size:small; font-style: italic">' + _(
        'Merge CSS rules in the same stylesheet that have identical selectors.'
        ' Note that in rare cases merging can result in a change to the effective styling'
        ' of the book, so use with care.'))
    d.p = p = QCheckBox(_('Merge CSS rules with identical properties'))
    p.setChecked(tprefs['merge_rules_with_identical_properties'])
    l.addWidget(p)
    d.la4 = label('<span style="font-size:small; font-style: italic">' + _(
        'Merge CSS rules in the same stylesheet that have identical properties.'
        ' Note that in rare cases merging can result in a change to the effective styling'
        ' of the book, so use with care.'))

    d.bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok
                            | QDialogButtonBox.StandardButton.Cancel)
    d.l.addWidget(d.bb)
    d.bb.rejected.connect(d.reject)
    d.bb.accepted.connect(d.accept)
    if d.exec_() != QDialog.DialogCode.Accepted:
        raise Abort()
    ans['remove_unused_classes'] = tprefs[
        'remove_unused_classes'] = c.isChecked()
    ans['merge_identical_selectors'] = tprefs[
        'merge_identical_selectors'] = m.isChecked()
    ans['merge_rules_with_identical_properties'] = tprefs[
        'merge_rules_with_identical_properties'] = p.isChecked()