示例#1
0
def createFontBoxesFor(parent,
                       name,
                       family,
                       size,
                       *,
                       mono=False,
                       tooltips=None,
                       which="Font"):
    font = QFont(family, size)
    fontComboBox = QFontComboBox(parent)
    if not mono:
        fontFilter = QFontComboBox.ScalableFonts
    else:
        fontFilter = (QFontComboBox.ScalableFonts
                      | QFontComboBox.MonospacedFonts)
    fontComboBox.setFontFilters(fontFilter)
    fontComboBox.setCurrentFont(font)
    fontSizeSpinBox = QSpinBox(parent)
    fontSizeSpinBox.setAlignment(Qt.AlignRight)
    fontSizeSpinBox.setRange(6, 36)
    fontSizeSpinBox.setSuffix(" pt")
    fontSizeSpinBox.setAlignment(Qt.AlignVCenter | Qt.AlignRight)
    fontSizeSpinBox.setValue(font.pointSize())
    if tooltips is not None:
        tooltips.append((fontComboBox, """\
<p><b>{0} Font</b></p><p>The font family to use for the {0} Font.</p>""".
                         format(which)))
        tooltips.append((fontSizeSpinBox, """\
<p><b>{0} Font Size</b></p><p>The font point size to use for the {0}
Font.</p>""".format(which)))
    setattr(parent, "{}FontComboBox".format(name.lower()), fontComboBox)
    setattr(parent, "{}FontSizeSpinBox".format(name.lower()), fontSizeSpinBox)
示例#2
0
class Panel(QToolBar):

    def __init__(self, state, parent=None, *, editableFontSize=False):
        super().__init__(parent)
        self.appState = state
        self.state = FormatState(self.appState, self)
        self.fontSizeSpinBox = None
        if editableFontSize:
            self.fontSizeSpinBox = QSpinBox()
            self.fontSizeSpinBox.setAlignment(Qt.AlignRight)
            self.fontSizeSpinBox.setFocusPolicy(Qt.NoFocus)
            self.fontSizeSpinBox.setRange(MIN_FONT_SIZE, MAX_FONT_SIZE)
            self.fontSizeSpinBox.setSuffix(" pt")
            self.fontSizeSpinBox.setValue(self.appState.stdFontSize)
            self.fontSizeSpinBox.setToolTip("""<p><b>Font Size</b></p>
<p>Set the font size in points.</p>""")
        self.formatActions = Actions.Format.Actions(
            self, self.fontSizeSpinBox)
        for action in self.formatActions.forToolbar():
            if action is not None:
                self.addAction(action)
            else:
                self.addSeparator()
        if editableFontSize:
            self.addWidget(self.fontSizeSpinBox)
示例#3
0
class Form(QDialog):
    def __init__(self, state, parent=None):
        super().__init__(parent)
        Lib.prepareModalDialog(self)
        self.state = state
        self.setWindowTitle("Renumber Pages — {}".format(
            QApplication.applicationName()))
        self.createWidgets()
        self.layoutWidgets()
        self.createConnections()
        self.romanStartSpinBox.setFocus()
        self.updateUi()
        settings = QSettings()
        self.updateToolTips(
            bool(
                int(
                    settings.value(Gopt.Key.ShowDialogToolTips,
                                   Gopt.Default.ShowDialogToolTips))))

    def createWidgets(self):
        self.romanStartLabel = QLabel("&Roman from")
        self.romanStartSpinBox = Widgets.RomanSpinBox.SpinBox()
        self.tooltips.append((self.romanStartSpinBox, """\
<p><b>Roman from</b></p>
<p>The first roman page number to change.</p>"""))
        self.romanStartLabel.setBuddy(self.romanStartSpinBox)
        self.romanEndLabel = QLabel("to")
        self.romanEndSpinBox = Widgets.RomanSpinBox.SpinBox()
        self.romanEndSpinBox.setValue(200)
        self.tooltips.append((self.romanEndSpinBox, """\
<p><b>Roman, to</b></p>
<p>The last roman page number to change.</p>"""))
        self.romanChangeLabel = QLabel("change")
        self.romanChangeSpinBox = Widgets.ChangeSpinBox.SpinBox()
        self.romanChangeSpinBox.setRange(-100, 100)
        self.romanChangeSpinBox.setValue(0)
        self.romanChangeSpinBox.setMinimumWidth(
            self.romanChangeSpinBox.fontMetrics().width("W(no change)W"))
        self.tooltips.append((self.romanChangeSpinBox, """\
<p><b>Roman, change</b></p>
<p>The amount to change the roman page numbers in the Roman from&ndash;to
range.</p>"""))
        self.decimalStartLabel = QLabel("&Decimal from")
        self.decimalStartSpinBox = QSpinBox()
        self.decimalStartSpinBox.setAlignment(Qt.AlignRight)
        self.decimalStartLabel.setBuddy(self.decimalStartSpinBox)
        self.decimalStartSpinBox.setRange(1, 10000)
        self.tooltips.append((self.decimalStartSpinBox, """\
<p><b>Decimal from</b></p>
<p>The first decimal page number to change.</p>"""))
        self.decimalEndLabel = QLabel("to")
        self.decimalEndSpinBox = QSpinBox()
        self.decimalEndSpinBox.setAlignment(Qt.AlignRight)
        self.decimalEndSpinBox.setRange(1, 10000)
        self.decimalEndSpinBox.setValue(2000)
        self.tooltips.append((self.decimalEndSpinBox, """\
<p><b>Decimal, to</b></p>
<p>The last decimal page number to change.</p>"""))
        self.decimalChangeLabel = QLabel("change")
        self.decimalChangeSpinBox = Widgets.ChangeSpinBox.SpinBox()
        self.decimalChangeSpinBox.setRange(-100, 100)
        self.decimalChangeSpinBox.setValue(0)
        self.tooltips.append((self.decimalChangeSpinBox, """\
<p><b>Decimal, change</b></p>
<p>The amount to change the decimal page numbers in the Decimal
from&ndash;to range.</p>"""))

        self.buttonBox = QDialogButtonBox()
        self.renumberButton = QPushButton(QIcon(":/renumberpages.svg"),
                                          "Re&number")
        self.tooltips.append((self.renumberButton, """\
<p><b>Renumber</b></p>
<p>Renumber roman and decimal page numbers within the given ranges by
the specified amounts of change throughout the entire index.</p>"""))
        self.buttonBox.addButton(self.renumberButton,
                                 QDialogButtonBox.ActionRole)
        self.closeButton = QPushButton(QIcon(":/dialog-close.svg"), "&Cancel")
        self.tooltips.append((self.closeButton, """<p><b>Cancel</b></p>
<p>Close the dialog without making any changes to the index.</p>"""))
        self.buttonBox.addButton(self.closeButton, QDialogButtonBox.RejectRole)
        self.helpButton = QPushButton(QIcon(":/help.svg"), "Help")
        self.tooltips.append(
            (self.helpButton, "Help on the Renumber Pages dialog"))
        self.buttonBox.addButton(self.helpButton, QDialogButtonBox.HelpRole)

    def layoutWidgets(self):
        grid = QGridLayout()
        grid.addWidget(self.romanStartLabel, 0, 0)
        grid.addWidget(self.romanStartSpinBox, 0, 1)
        grid.addWidget(self.romanEndLabel, 0, 2)
        grid.addWidget(self.romanEndSpinBox, 0, 3)
        grid.addWidget(self.romanChangeLabel, 0, 4)
        grid.addWidget(self.romanChangeSpinBox, 0, 5)
        grid.addWidget(self.decimalStartLabel, 1, 0)
        grid.addWidget(self.decimalStartSpinBox, 1, 1)
        grid.addWidget(self.decimalEndLabel, 1, 2)
        grid.addWidget(self.decimalEndSpinBox, 1, 3)
        grid.addWidget(self.decimalChangeLabel, 1, 4)
        grid.addWidget(self.decimalChangeSpinBox, 1, 5)
        hbox = QHBoxLayout()
        hbox.addLayout(grid)
        hbox.addStretch()
        layout = QVBoxLayout()
        layout.addLayout(hbox)
        layout.addStretch()
        layout.addWidget(self.buttonBox)
        self.setLayout(layout)

    def createConnections(self):
        self.buttonBox.rejected.connect(self.reject)
        self.renumberButton.clicked.connect(self.renumber)
        for spinbox in (self.romanStartSpinBox, self.romanEndSpinBox,
                        self.romanChangeSpinBox, self.decimalStartSpinBox,
                        self.decimalEndSpinBox, self.decimalChangeSpinBox):
            spinbox.valueChanged.connect(self.updateUi)
        self.helpButton.clicked.connect(self.help)

    def updateUi(self):
        self._synchronize(self.romanStartSpinBox, self.romanEndSpinBox)
        self._synchronize(self.decimalStartSpinBox, self.decimalEndSpinBox)
        changeRoman = (
            (self.romanStartSpinBox.value() != self.romanEndSpinBox.value())
            and self.romanChangeSpinBox.value() != 0)
        changeDecimal = ((self.decimalStartSpinBox.value() !=
                          self.decimalEndSpinBox.value())
                         and self.decimalChangeSpinBox.value() != 0)
        self.renumberButton.setEnabled(changeRoman or changeDecimal)
        self._setPrefix(self.romanChangeSpinBox)
        self._setPrefix(self.decimalChangeSpinBox)

    def _synchronize(self, startSpinBox, endSpinBox):
        value = startSpinBox.value()
        if endSpinBox.value() < value:
            endSpinBox.setValue(value)

    def _setPrefix(self, spinbox):
        spinbox.setPrefix("+" if spinbox.value() > 0 else "")

    def help(self):
        self.state.help("xix_ref_dlg_renumpages.html")

    def renumber(self):  # No need to restore focus widget
        options = RenumberOptions(self.romanStartSpinBox.value(),
                                  self.romanEndSpinBox.value(),
                                  self.romanChangeSpinBox.value(),
                                  self.decimalStartSpinBox.value(),
                                  self.decimalEndSpinBox.value(),
                                  self.decimalChangeSpinBox.value())
        with Lib.DisableUI(self):
            self.state.model.renumber(options,
                                      self.state.window.reportProgress)
        message = "Renumber pages"
        if self.state.model.canUndo:
            self.state.model.can_undo.emit(True, message)
        if self.state.model.canRedo:
            self.state.model.can_redo.emit(True, message)
        self.state.updateUi()
        say("Renumbered pages", SAY_TIMEOUT)
        self.accept()
示例#4
0
class Panel(QWidget):
    def __init__(self, state, config, parent):
        super().__init__(parent)
        self.state = state
        self.config = config
        self.form = parent
        self.createWidgets()
        self.layoutWidgets()
        self.createConnections()

    def createWidgets(self):
        settings = QSettings()
        creator = settings.value(Gopt.Key.Creator, self.state.user)
        self.creatorLineEdit = QLineEdit()
        self.creatorLineEdit.setText(creator)
        self.form.tooltips.append((self.creatorLineEdit, """\
<p><b>Creator</b></p>
<p>The indexer's name.</p>"""))
        initials = ""
        if creator:
            initials = Lib.initials(creator)
        initials = settings.value(Gopt.Key.Initials, initials)
        self.initialsLineEdit = QLineEdit()
        self.initialsLineEdit.setMaximumWidth(
            self.initialsLineEdit.fontMetrics().width("W") * 4)
        self.initialsLineEdit.setText(initials)
        self.form.tooltips.append((self.initialsLineEdit, """\
<p><b>Initials</b></p>
<p>The indexer's initials.</p>"""))

        self.languageGroupBox = QGroupBox("&Language")
        defaultLanguage = LanguageKind(
            settings.value(Gopt.Key.Language, Gopt.Default.Language))
        thisLanguage = self.config.get(Gconf.Key.Language, defaultLanguage)
        self.defaultLanguageComboBox = QComboBox()
        self.form.tooltips.append((self.defaultLanguageComboBox, """\
<p><b>Language, Default</b></p>
<p>The default setting for the <b>Language, For This Index</b> combobox
for new indexes.</p>"""))
        self.thisLanguageComboBox = QComboBox()
        self.form.tooltips.append((self.thisLanguageComboBox, """\
<p><b>Language, For This Index</b></p>
<p>The language to use for spellchecking and suggestions for this
index.</p>"""))
        self.populateLanguageComboBox(self.defaultLanguageComboBox,
                                      defaultLanguage)
        self.populateLanguageComboBox(self.thisLanguageComboBox, thisLanguage)

        self.limitsGroupBox = QGroupBox("Publisher's Limits for this Index")
        self.highestPageSpinBox = QSpinBox()
        self.highestPageSpinBox.setAlignment(Qt.AlignRight)
        self.highestPageSpinBox.setRange(10, 26000)
        self.highestPageSpinBox.setValue(
            self.config.get(Gconf.Key.HighestPageNumber,
                            Gconf.Default.HighestPageNumber))
        self.form.tooltips.append((self.highestPageSpinBox, """\
<p><b>Highest Page Number</b></p>
<p>Any entries which contain a page number greater than this one will be
shown in the Filtered view if you use the “Too High Page Number”
filter.</p>"""))
        self.largestPageRangeSpinBox = QSpinBox()
        self.largestPageRangeSpinBox.setAlignment(Qt.AlignRight)
        self.largestPageRangeSpinBox.setRange(2, 1000)
        self.largestPageRangeSpinBox.setValue(
            self.config.get(Gconf.Key.LargestPageRange,
                            Gconf.Default.LargestPageRange))
        self.form.tooltips.append((self.largestPageRangeSpinBox, """\
<p><b>Largest Page Range Span</b></p>
<p>Any entries which contain a page range that spans more pages than
this will be shown in the Filtered view if you use the “Too Large
Page Range” filter.</p>"""))
        self.mostPagesSpinBox = QSpinBox()
        self.mostPagesSpinBox.setAlignment(Qt.AlignRight)
        self.mostPagesSpinBox.setRange(2, 100)
        self.mostPagesSpinBox.setValue(
            self.config.get(Gconf.Key.MostPages, Gconf.Default.MostPages))
        self.form.tooltips.append((self.mostPagesSpinBox, """\
<p><b>Most Pages per Entry</b></p>
<p>Any entries which contain more pages and page ranges this will be
shown in the Filtered view if you use the “Too Many Pages”
filter.</p>"""))

    def layoutWidgets(self):
        layout = QVBoxLayout()

        form = QFormLayout()
        form.addRow("C&reator", self.creatorLineEdit)
        form.addRow("&Initials", self.initialsLineEdit)
        layout.addLayout(form)

        form = QFormLayout()
        form.addRow("For This Index", self.thisLanguageComboBox)
        form.addRow("Default", self.defaultLanguageComboBox)
        self.languageGroupBox.setLayout(form)
        layout.addWidget(self.languageGroupBox)

        form = QFormLayout()
        form.addRow("&Highest Page Number", self.highestPageSpinBox)
        form.addRow("Largest &Page Range Span", self.largestPageRangeSpinBox)
        form.addRow("&Most Pages per Entry", self.mostPagesSpinBox)
        self.limitsGroupBox.setLayout(form)
        hbox = QHBoxLayout()
        hbox.addWidget(self.limitsGroupBox)
        hbox.addStretch()
        layout.addLayout(hbox)

        layout.addStretch()
        self.setLayout(layout)

    def createConnections(self):
        self.creatorLineEdit.textChanged.connect(self.updateInitials)
        self.defaultLanguageComboBox.currentIndexChanged.connect(
            self.setDefaultLanguage)
        self.thisLanguageComboBox.currentIndexChanged.connect(
            self.setThisLanguage)

    def updateInitials(self):
        text = self.creatorLineEdit.text()
        if text:
            initials = Lib.initials(text)
            if initials:
                self.initialsLineEdit.setText(initials)

    def populateLanguageComboBox(self, combobox, theLanguage):
        index = -1
        for i, language in enumerate(LanguageKind):
            if language is theLanguage:
                index = i
            name = language.value
            combobox.addItem(QIcon(":/{}.svg".format(name.replace(" ", "_"))),
                             name, language)
        combobox.setCurrentIndex(index)

    def setDefaultLanguage(self, index):
        language = self.defaultLanguageComboBox.itemData(index)
        settings = QSettings()
        settings.setValue(Gopt.Key.Language, language.value)

    def setThisLanguage(self, index):
        language = self.defaultLanguageComboBox.itemData(index)
        self.state.model.setConfig(Gconf.Key.Language, language)
        self.state.entryPanel.spellHighlighter.rehighlight()
        self.state.window.updateLanguageIndicator()
示例#5
0
class Panel(QWidget):
    def __init__(self, state, config, parent):
        super().__init__(parent)
        self.state = state
        self.config = config
        self.form = parent
        self.createWidgets()
        self.layoutWidgets()
        self.createConnections()

    def createWidgets(self):
        self.formatPanel = Widgets.FormatPanel.Panel(self.state,
                                                     self,
                                                     editableFontSize=True)
        formatActions = self.formatPanel.formatActions

        self.titleLabel = QLabel("&Index Title")
        self.titleTextEdit = Widgets.LineEdit.HtmlLineEdit(
            self.state, formatActions=formatActions)
        self.titleLabel.setBuddy(self.titleTextEdit)
        self.titleTextEdit.setHtml(self.config.get(Gconf.Key.Title))
        self.form.tooltips.append((self.titleTextEdit, """\
<p><b>Index Title</b></p>
<p>The index's title. Leave blank if the title is to be added directly
in the output file.</p>"""))

        self.noteLabel = QLabel("Index &Note")
        self.noteTextEdit = Widgets.LineEdit.MultilineHtmlEdit(
            self.state, maxLines=8, formatActions=formatActions)
        self.noteLabel.setBuddy(self.noteTextEdit)
        self.noteTextEdit.setLineWrapMode(QTextEdit.FixedColumnWidth)
        self.noteTextEdit.setLineWrapColumnOrWidth(60)
        self.noteTextEdit.setWordWrapMode(QTextOption.WordWrap)
        self.noteTextEdit.setHtml(self.config.get(Gconf.Key.Note))
        self.form.tooltips.append((self.noteTextEdit, """\
<p><b>Index Note</b></p>
<p>The index's note. Leave blank if no note is required or if the note
is to be added directly in the output file.</p>"""))

        self.sectionsGroupBox = QGroupBox("Sections")
        self.blankBeforeLabel = QLabel("&Blank Lines Before")
        self.blankBeforeSpinBox = QSpinBox()
        self.blankBeforeSpinBox.setAlignment(Qt.AlignRight)
        self.blankBeforeLabel.setBuddy(self.blankBeforeSpinBox)
        self.blankBeforeSpinBox.setRange(0, 3)
        self.blankBeforeSpinBox.setValue(
            self.config.get(Gconf.Key.SectionPreLines))
        self.form.tooltips.append((self.blankBeforeSpinBox, """\
<p><b>Blank Lines Before</b></p>
<p>How many blank lines to output before a section. (A section is a
distinct part of the index, e.g., the ‘A’s.)</p>"""))
        self.blankAfterLabel = QLabel("Blank &Lines After")
        self.blankAfterSpinBox = QSpinBox()
        self.blankAfterSpinBox.setAlignment(Qt.AlignRight)
        self.blankAfterLabel.setBuddy(self.blankAfterSpinBox)
        self.blankAfterSpinBox.setRange(0, 3)
        self.blankAfterSpinBox.setValue(
            self.config.get(Gconf.Key.SectionPostLines))
        self.form.tooltips.append((self.blankAfterSpinBox, """\
<p><b>Blank Lines After</b></p>
<p>How many blank lines to output before after section's title. (A
section is a distinct part of the index, e.g., the ‘A’s.)</p>"""))
        self.sectionTitlesCheckBox = QCheckBox("&Output Titles")
        self.sectionTitlesCheckBox.setChecked(
            self.config.get(Gconf.Key.SectionTitles))
        self.form.tooltips.append((self.sectionTitlesCheckBox, """\
<p><b>Output Titles</b></p>
<p>If checked, section titles are output before each section, e.g., ‘A’,
before the As, ‘B’, before the Bs, and so on.</p>"""))
        self.sectionSpecialTitleLabel = QLabel("Special Section &Title")
        self.sectionSpecialTitleTextEdit = Widgets.LineEdit.HtmlLineEdit(
            self.state, formatActions=formatActions)
        self.sectionSpecialTitleLabel.setBuddy(
            self.sectionSpecialTitleTextEdit)
        self.sectionSpecialTitleTextEdit.setHtml(
            self.config.get(Gconf.Key.SectionSpecialTitle))
        self.form.tooltips.append((self.sectionSpecialTitleTextEdit, """\
<p><b>Special Section Title</b></p>
<p>If there are entries which precede the ‘A’ section, then this section
title will be used for them.</p>
<p>Note that even if this title isn't used, its font name and size will
be used for all the other section titles.</p>"""))

        size = self.font().pointSize() + (1 if WIN else 2)
        family = self.config.get(Gconf.Key.StdFont)
        size = self.config.get(Gconf.Key.StdFontSize, size)
        Lib.createFontBoxesFor(self,
                               "Std",
                               family,
                               size,
                               tooltips=self.form.tooltips,
                               which="Std.")
        self.onStdFontChange(False)
        family = self.config.get(Gconf.Key.AltFont)
        size = self.config.get(Gconf.Key.AltFontSize, size)
        Lib.createFontBoxesFor(self,
                               "Alt",
                               family,
                               size,
                               tooltips=self.form.tooltips,
                               which="Alt.")
        self.onAltFontChange(False)
        family = self.config.get(Gconf.Key.MonoFont)
        size = self.config.get(Gconf.Key.MonoFontSize, size)
        Lib.createFontBoxesFor(self,
                               "Mono",
                               family,
                               size,
                               mono=True,
                               tooltips=self.form.tooltips,
                               which="Mono.")
        self.onMonoFontChange(False)

        self.monoFontAsStrikeoutCheckbox = QCheckBox(
            "Output Mono. &Font as Strikeout")
        self.form.tooltips.append((self.monoFontAsStrikeoutCheckbox, """\
<p><b>Output Mono. Font as Strikeout</b></p>
<p>If checked, any text in the index that is styled as mono. font
family will be output using the std. font family&mdash;but with
<s>strikeout</s>.</p>"""))
        self.monoFontAsStrikeoutCheckbox.setChecked(
            self.config.get(Gconf.Key.MonoFontAsStrikeout))

        self.styleLabel = QLabel("St&yle")
        self.styleComboBox = QComboBox()
        self.styleLabel.setBuddy(self.styleComboBox)
        oldStyle = self.config.get(Gconf.Key.Style)
        index = -1
        for i, style in enumerate(StyleKind):
            self.styleComboBox.addItem(style.text, style.value)
            if style is oldStyle:
                index = i
        self.styleComboBox.setCurrentIndex(index)
        self.form.tooltips.append((self.styleComboBox, """\
<p><b>Style</b></p>
<p>The style of index to output.</p>"""))

        self.termPagesSepLabel = QLabel("T&erm-Pages Separator")
        self.termPagesSepTextEdit = Widgets.LineEdit.SpacesHtmlLineEdit(
            self.state, 3, formatActions=formatActions)
        self.termPagesSepLabel.setBuddy(self.termPagesSepTextEdit)
        self.termPagesSepTextEdit.setHtml(
            self.config.get(Gconf.Key.TermPagesSeparator))
        self.form.tooltips.append((self.termPagesSepTextEdit, """\
<p><b>Term-Pages Separator</b></p>
<p>The separator text to use between the end of an entry's term and its
pages.</p>{}""".format(BLANK_SPACE_HTML)))

        self.runInSepLabel = QLabel("&Run-in Separator")
        self.runInSepTextEdit = Widgets.LineEdit.SpacesHtmlLineEdit(
            self.state, 3, formatActions=formatActions)
        self.runInSepLabel.setBuddy(self.runInSepTextEdit)
        self.runInSepTextEdit.setHtml(self.config.get(
            Gconf.Key.RunInSeparator))
        self.form.tooltips.append((self.runInSepTextEdit, """\
<p><b>Run-in Separator</b></p>
<p>The separator text to use between run-in entries (for run-in style
index output).</p>{}""".format(BLANK_SPACE_HTML)))

        self.formatPanel.state.editors = [
            self.titleTextEdit, self.noteTextEdit,
            self.sectionSpecialTitleTextEdit, self.termPagesSepTextEdit,
            self.runInSepTextEdit
        ]

    def layoutWidgets(self):
        form = QFormLayout()
        hbox = QHBoxLayout()
        hbox.addStretch()
        hbox.addWidget(self.formatPanel)
        form.addRow(hbox)
        form.addRow(self.titleLabel, self.titleTextEdit)
        form.addRow(self.noteLabel, self.noteTextEdit)

        vbox = QVBoxLayout()
        hbox = QHBoxLayout()
        hbox.addWidget(self.blankBeforeLabel)
        hbox.addWidget(self.blankBeforeSpinBox)
        hbox.addWidget(self.blankAfterLabel)
        hbox.addWidget(self.blankAfterSpinBox)
        hbox.addStretch()
        vbox.addLayout(hbox)
        hbox = QHBoxLayout()
        hbox.addWidget(self.sectionTitlesCheckBox)
        hbox.addStretch()
        hbox.addWidget(self.sectionSpecialTitleLabel)
        hbox.addWidget(self.sectionSpecialTitleTextEdit)
        vbox.addLayout(hbox)
        self.sectionsGroupBox.setLayout(vbox)
        form.addRow(self.sectionsGroupBox)

        hbox = QHBoxLayout()
        hbox.addWidget(self.stdFontComboBox, 1)
        hbox.addWidget(self.stdFontSizeSpinBox)
        hbox.addStretch()
        label = QLabel("&Std. Font")
        label.setBuddy(self.stdFontComboBox)
        form.addRow(label, hbox)
        hbox = QHBoxLayout()
        hbox.addWidget(self.altFontComboBox, 1)
        hbox.addWidget(self.altFontSizeSpinBox)
        hbox.addStretch()
        label = QLabel("&Alt. Font")
        label.setBuddy(self.altFontComboBox)
        form.addRow(label, hbox)
        hbox = QHBoxLayout()
        hbox.addWidget(self.monoFontComboBox, 1)
        hbox.addWidget(self.monoFontSizeSpinBox)
        hbox.addStretch()
        label = QLabel("&Mono. Font")
        label.setBuddy(self.monoFontComboBox)
        form.addRow(label, hbox)

        grid = QGridLayout()
        grid.addWidget(self.monoFontAsStrikeoutCheckbox, 0, 0, 1, 2)
        grid.addWidget(self.termPagesSepLabel, 0, 2)
        grid.addWidget(self.termPagesSepTextEdit, 0, 3)
        grid.addWidget(self.styleLabel, 1, 0)
        grid.addWidget(self.styleComboBox, 1, 1)
        grid.addWidget(self.runInSepLabel, 1, 2)
        grid.addWidget(self.runInSepTextEdit, 1, 3)
        form.addRow(grid)
        self.setLayout(form)

    def createConnections(self):
        self.stdFontComboBox.currentFontChanged.connect(self.onStdFontChange)
        self.stdFontSizeSpinBox.valueChanged[int].connect(self.onStdFontChange)
        self.altFontComboBox.currentFontChanged.connect(self.onAltFontChange)
        self.altFontSizeSpinBox.valueChanged[int].connect(self.onAltFontChange)
        self.monoFontComboBox.currentFontChanged.connect(self.onMonoFontChange)
        self.monoFontSizeSpinBox.valueChanged[int].connect(
            self.onMonoFontChange)

    def onStdFontChange(self, propagate=True):
        font = QFont(self.stdFontComboBox.currentFont())
        font.setPointSize(self.stdFontSizeSpinBox.value())
        if propagate and bool(self.state.model):
            self.state.model.setConfig(Gconf.Key.StdFont, font.family())
            self.state.model.setConfig(Gconf.Key.StdFontSize, font.pointSize())

    def onAltFontChange(self, propagate=True):
        font = QFont(self.altFontComboBox.currentFont())
        font.setPointSize(self.altFontSizeSpinBox.value())
        if propagate and bool(self.state.model):
            self.state.model.setConfig(Gconf.Key.AltFont, font.family())
            self.state.model.setConfig(Gconf.Key.AltFontSize, font.pointSize())

    def onMonoFontChange(self, propagate=True):
        font = QFont(self.monoFontComboBox.currentFont())
        font.setPointSize(self.monoFontSizeSpinBox.value())
        if propagate and bool(self.state.model):
            self.state.model.setConfig(Gconf.Key.MonoFont, font.family())
            self.state.model.setConfig(Gconf.Key.MonoFontSize,
                                       font.pointSize())
示例#6
0
class Panel(QWidget):
    def __init__(self, state, config, parent):
        super().__init__(parent)
        self.state = state
        self.config = config
        self.form = parent
        self.createWidgets()
        self.layoutWidgets()
        self.createConnections()

    def createWidgets(self):
        settings = QSettings()
        self.sortRulesGroupBox = QGroupBox("Calculate &Sort As Rules")
        defaultSortAsRules = settings.value(Gconf.Key.SortAsRules,
                                            Gopt.Default.SortAsRules)
        self.thisSortAsRules = self.config.get(Gopt.Key.SortAsRules,
                                               defaultSortAsRules)
        self.defaultSortAsRulesBox = QComboBox()
        self.form.tooltips.append((self.defaultSortAsRulesBox, """\
<p><b>Calculate Sort As Rules, Default</b></p>
<p>The default setting for the <b>Calculate Sort As Rules, For This
Index</b> combobox for new indexes.</p>"""))
        self.thisSortAsRulesBox = QComboBox()
        self.form.tooltips.append((self.thisSortAsRulesBox, """\
<p><b>Calculate Sort As Rules, For This Index</b></p>
<p>The rules to use for calculating each entry's sort as text for this
index.</p>
<p>If the rules are changed, when the dialog is closed, the new rules
will be applied to every entry in the index.</p>"""))
        self.populateSortAsRulesBox(self.defaultSortAsRulesBox,
                                    defaultSortAsRules)
        self.populateSortAsRulesBox(self.thisSortAsRulesBox,
                                    self.thisSortAsRules)

        self.pageRangeRulesBox = QGroupBox("&Page Range Rules")
        defaultPageRangeRules = settings.value(Gconf.Key.PageRangeRules,
                                               Gopt.Default.PageRangeRules)
        self.thisPageRangeRules = self.config.get(Gopt.Key.PageRangeRules,
                                                  defaultPageRangeRules)
        self.defaultPageRangeRulesBox = QComboBox()
        self.form.tooltips.append((self.defaultPageRangeRulesBox, """\
<p><b>Page Range Rules, Default</b></p>
<p>The default setting for the <b>Page Range Rules, For This Index</b>
combobox for new indexes.</p>"""))
        self.thisPageRangeRulesBox = QComboBox()
        self.form.tooltips.append((self.thisPageRangeRulesBox, """\
<p><b>Page Range Rules, For This Index</b></p>
<p>The rules to use for handling page ranges, e.g., whether in full such
as 120&ndash;124, or somehow compressed, e.g., 120&ndash;4, for this
index.</p>
<p>If the rules are changed, when the dialog is closed, the new rules
will be applied to every entry in the index.</p>"""))
        self.populatePageRangeRulesBox(self.defaultPageRangeRulesBox,
                                       defaultPageRangeRules)
        self.populatePageRangeRulesBox(self.thisPageRangeRulesBox,
                                       self.thisPageRangeRules)
        self.padDigitsGroupBox = QGroupBox("Pad &Digits")
        defaultPadDigits = int(
            settings.value(Gconf.Key.PadDigits, Gopt.Default.PadDigits))
        self.thisPadDigits = int(
            self.config.get(Gopt.Key.PadDigits, defaultPadDigits))
        self.thisPadDigitsLabel = QLabel("For This Index")
        self.thisPadDigitsSpinBox = QSpinBox()
        self.thisPadDigitsSpinBox.setAlignment(Qt.AlignRight)
        self.thisPadDigitsSpinBox.setRange(0, 12)
        self.thisPadDigitsSpinBox.setValue(self.thisPadDigits)
        self.form.tooltips.append((self.thisPadDigitsSpinBox, """\
<p><b>Pad Digits, For This Index</b></p>
<p>Sort as texts are compared textually, so if a term contains a number
(or text which is converted to a number), the number must be padded by
leading zeros to ensure correct ordering. This is the number of digits
to pad for, for this index. For example, if set to 4, the numbers 1, 23,
and 400 would be set to 0001, 0023, and 0400, in the sort as text.</p>"""))
        self.defaultPadDigitsLabel = QLabel("Default")
        self.defaultPadDigitsSpinBox = QSpinBox()
        self.defaultPadDigitsSpinBox.setAlignment(Qt.AlignRight)
        self.defaultPadDigitsSpinBox.setRange(0, 12)
        self.defaultPadDigitsSpinBox.setValue(defaultPadDigits)
        self.form.tooltips.append((self.defaultPadDigitsSpinBox, """\
<p><b>Pad Digits, Default</b></p>
<p>The default setting for the <b>Pad Digits, For This Index</b> spinbox
for new indexes.</p>"""))
        self.ignoreSubFirstsGroupBox = QGroupBox(
            "&Ignore Subentry Function Words")
        defaultIgnoreSubFirsts = bool(
            int(
                settings.value(Gconf.Key.IgnoreSubFirsts,
                               Gopt.Default.IgnoreSubFirsts)))
        thisIgnoreSubFirsts = bool(
            int(
                self.config.get(Gopt.Key.IgnoreSubFirsts,
                                defaultIgnoreSubFirsts)))
        self.thisIgnoreSubFirstsCheckBox = QCheckBox("For This Index")
        self.thisIgnoreSubFirstsCheckBox.setChecked(thisIgnoreSubFirsts)
        self.form.tooltips.append((self.thisIgnoreSubFirstsCheckBox, """\
<p><b>Ignore Subentry Function Words, For This Index</b></p>
<p>This setting applies to this index.</p>
<p>If checked, words listed in the <b>Index→Ignore Subentry Function
Words</b> list are ignored for sorting purposes when the first word of a
subentry, i.e., ignored when the first word of an entry's sort as
text.</p> <p>This should normally be checked for Chicago Manual of Style
Sort As Rules, and unchecked for NISO Rules.</p>"""))
        self.defaultIgnoreSubFirstsCheckBox = QCheckBox("Default")
        self.defaultIgnoreSubFirstsCheckBox.setChecked(defaultIgnoreSubFirsts)
        self.form.tooltips.append((self.defaultIgnoreSubFirstsCheckBox, """\
<p><b>Ignore Subentry Function Words, Default</b></p>
<p>The default setting for the <b>Ignore Subentry Function Words, For
This Index</b> checkbox for new indexes</p>"""))
        self.suggestSpelledGroupBox = QGroupBox(
            "&Suggest Spelled Out Numbers when Appropriate")
        defaultSuggestSpelled = bool(
            int(
                settings.value(Gconf.Key.SuggestSpelled,
                               Gopt.Default.SuggestSpelled)))
        thisSuggestSpelled = bool(
            int(self.config.get(Gopt.Key.SuggestSpelled,
                                defaultSuggestSpelled)))
        self.thisSuggestSpelledCheckBox = QCheckBox("For This Index")
        self.thisSuggestSpelledCheckBox.setChecked(thisSuggestSpelled)
        self.form.tooltips.append((self.thisSuggestSpelledCheckBox, """\
<p><b>Suggest Spelled Out Numbers when Appropriate, For This Index</b></p>
<p>When checked (and providing the Sort As rules in force are not NISO
rules), when adding or editing a term when the <b>Automatically
Calculate Sort As</b> checkbox is checked, and when the term contains a
number, the choice of sort as texts will include the number spelled
out.</p>"""))
        self.defaultSuggestSpelledCheckBox = QCheckBox("Default")
        self.defaultSuggestSpelledCheckBox.setChecked(defaultSuggestSpelled)
        self.form.tooltips.append((self.defaultSuggestSpelledCheckBox, """\
<p><b>Suggest Spelled Out Numbers when Appropriate, Default</b></p>
<p>The default setting for the <b>Suggest Spelled Out Numbers when
Appropriate, For This Index</b> checkbox for new indexes.</p>"""))

    def layoutWidgets(self):
        layout = QVBoxLayout()

        form = QFormLayout()
        form.addRow("For This Index", self.thisSortAsRulesBox)
        form.addRow("Default", self.defaultSortAsRulesBox)
        self.sortRulesGroupBox.setLayout(form)
        layout.addWidget(self.sortRulesGroupBox)

        form = QFormLayout()
        form.addRow("For This Index", self.thisPageRangeRulesBox)
        form.addRow("Default", self.defaultPageRangeRulesBox)
        self.pageRangeRulesBox.setLayout(form)
        layout.addWidget(self.pageRangeRulesBox)

        hbox = QHBoxLayout()
        hbox.addWidget(self.thisPadDigitsLabel)
        hbox.addWidget(self.thisPadDigitsSpinBox)
        hbox.addStretch(1)
        hbox.addWidget(self.defaultPadDigitsLabel)
        hbox.addWidget(self.defaultPadDigitsSpinBox)
        hbox.addStretch(3)
        self.padDigitsGroupBox.setLayout(hbox)
        layout.addWidget(self.padDigitsGroupBox)

        hbox = QHBoxLayout()
        hbox.addWidget(self.thisIgnoreSubFirstsCheckBox)
        hbox.addWidget(self.defaultIgnoreSubFirstsCheckBox)
        hbox.addStretch()
        self.ignoreSubFirstsGroupBox.setLayout(hbox)
        layout.addWidget(self.ignoreSubFirstsGroupBox)

        hbox = QHBoxLayout()
        hbox.addWidget(self.thisSuggestSpelledCheckBox)
        hbox.addWidget(self.defaultSuggestSpelledCheckBox)
        hbox.addStretch()
        self.suggestSpelledGroupBox.setLayout(hbox)
        layout.addWidget(self.suggestSpelledGroupBox)

        layout.addStretch()
        self.setLayout(layout)

    def createConnections(self):
        self.defaultSortAsRulesBox.currentIndexChanged.connect(
            self.setDefaultSortAsRules)
        self.defaultPageRangeRulesBox.currentIndexChanged.connect(
            self.setDefaultPageRangeRules)
        self.defaultPadDigitsSpinBox.valueChanged.connect(
            self.setDefaultPadDigits)
        self.defaultIgnoreSubFirstsCheckBox.toggled.connect(
            self.setDefaultIgnoreSubFirsts)
        self.defaultSuggestSpelledCheckBox.toggled.connect(
            self.setDefaultSuggestSpelled)

    def populateSortAsRulesBox(self, combobox, rules):
        index = -1
        for i, name in enumerate(SortAs.RulesForName):
            displayName = SortAs.RulesForName[name].name
            combobox.addItem(displayName, name)
            if name == rules:
                index = i
        combobox.setCurrentIndex(index)

    def setDefaultSortAsRules(self, index):
        index = self.defaultSortAsRulesBox.currentIndex()
        name = self.defaultSortAsRulesBox.itemData(index)
        settings = QSettings()
        settings.setValue(Gopt.Key.SortAsRules, name)

    def populatePageRangeRulesBox(self, combobox, rules):
        index = -1
        for i, name in enumerate(Pages.RulesForName):
            displayName = Pages.RulesForName[name].name
            combobox.addItem(displayName, name)
            if name == rules:
                index = i
        combobox.setCurrentIndex(index)

    def setDefaultPageRangeRules(self, index):
        index = self.defaultPageRangeRulesBox.currentIndex()
        name = self.defaultPageRangeRulesBox.itemData(index)
        settings = QSettings()
        settings.setValue(Gopt.Key.PageRangeRules, name)

    def setDefaultPadDigits(self):
        value = self.defaultPadDigitsSpinBox.value()
        settings = QSettings()
        settings.setValue(Gopt.Key.PadDigits, value)

    def setDefaultIgnoreSubFirsts(self):
        value = int(self.defaultIgnoreSubFirstsCheckBox.isChecked())
        settings = QSettings()
        settings.setValue(Gopt.Key.IgnoreSubFirsts, value)

    def setDefaultSuggestSpelled(self):
        value = int(self.defaultSuggestSpelledCheckBox.isChecked())
        settings = QSettings()
        settings.setValue(Gopt.Key.SuggestSpelled, value)