示例#1
0
    def _create_libdmtx(self, settings):
        radio = QRadioButton('My objects are labelled with Data Matrix barcodes')
        radio.setChecked('libdmtx' == settings['engine'])
        radio.setEnabled(libdmtx_available())
        self._layout.addWidget(radio)

        prompt = QLabel(
            'Barcodes will be decoded using the open-source '
            '<a href="http://www.libdmtx.org/">libdmtx</a> library')
        prompt.setOpenExternalLinks(True)
        prompt.setStyleSheet(self.STYLESHEET)
        self._layout.addWidget(prompt)

        self._layout.addWidget(HorizontalLine())
        return radio
示例#2
0
    def _create_zbar(self, settings):
        radio = QRadioButton(
            'My objects are labelled with either 1D barcodes or QR codes')
        radio.setChecked('zbar' == settings['engine'])
        radio.setEnabled(zbar_available())
        self._layout.addWidget(radio)

        prompt = QLabel('Barcodes will be decoded using the open-source '
                        '<a href="http://zbar.sourceforge.net/">ZBar</a> library')
        prompt.setOpenExternalLinks(True)
        prompt.setStyleSheet(self.STYLESHEET)
        self._layout.addWidget(prompt)

        self._layout.addWidget(HorizontalLine())
        return radio
示例#3
0
    def _create_inlite(self, settings):
        radio = QRadioButton(
            'Either my objects are labelled with a barcode not listed above '
            'or I would like the performance and reliability of a commercial '
            'library')
        radio.setChecked('inlite' == settings['engine'])
        radio.setEnabled(inlite_available())
        self._layout.addWidget(radio)

        prompt = QLabel(
            'Only available on Windows. '
            'Visit <a href="http://www.inliteresearch.com/">Inlite Research</a> '
            'to download and install Inlite Research\'s ClearImage library.'
        )
        prompt.setWordWrap(True)
        prompt.setOpenExternalLinks(True)
        prompt.setStyleSheet(self.STYLESHEET)
        self._layout.addWidget(prompt)

        prompt = QLabel('My objects are labelled with:')
        format = settings['inlite-format']
        radio_1d = QRadioButton('1D barcodes')
        radio_1d.setChecked('1d' == format)
        radio_datamatrix = QRadioButton('Data Matrix barcodes')
        radio_datamatrix.setChecked('datamatrix' == format)
        radio_pdf417 = QRadioButton('PDF 417 barcodes')
        radio_pdf417.setChecked('pdf417' == format)
        radio_qr = QRadioButton('QR codes')
        radio_qr.setChecked('qrcode' == format)

        layout = QVBoxLayout()
        layout.addWidget(prompt)
        layout.addWidget(radio_1d)
        layout.addWidget(radio_datamatrix)
        layout.addWidget(radio_pdf417)
        layout.addWidget(radio_qr)

        group = QWidget()
        group.setLayout(layout)
        group.setStyleSheet(self.STYLESHEET)
        radio.toggled.connect(group.setEnabled)
        group.setEnabled(inlite_available() and 'inlite' == settings['engine'])

        self._layout.addWidget(group)

        return radio, radio_1d, radio_datamatrix, radio_pdf417, radio_qr
示例#4
0
class Form(QDialog):
    def __init__(self, state, parent=None):
        super().__init__(parent)
        Lib.prepareModalDialog(self)
        self.state = state
        self.setWindowTitle("Copy Entry — {}".format(
            QApplication.applicationName()))
        self.createWidgets()
        self.layoutWidgets()
        self.createConnections()
        self.updateUi()
        settings = QSettings()
        self.updateToolTips(
            bool(
                int(
                    settings.value(Gopt.Key.ShowDialogToolTips,
                                   Gopt.Default.ShowDialogToolTips))))

    def createWidgets(self):
        selectedEid = self.state.viewAllPanel.view.selectedEid
        self.selectedEntry = self.state.model.entry(selectedEid)
        self.entryLabel = QLabel("Copy ")
        termText = Lib.elidePatchHtml(self.selectedEntry.term, self.state)
        self.termLabel = Widgets.Label.HtmlLabel("“{}”".format(termText))

        self.eidGroup = QGroupBox()

        self.copyToTopRadioButton = QRadioButton("to be a &Main Entry")
        self.tooltips.append((self.copyToTopRadioButton, """\
<p><b>to be a Main Entry</b></p>
<p>Copy the original entry to be a Main Entry (even if it is
already).</p>"""))
        self.subentryRadioButton = QRadioButton("to be a &Subentry of itself")
        self.tooltips.append((self.subentryRadioButton, """\
<p><b>to be a Subentry of itself</b></p>
<p>Copy the original entry to be a subentry of the original entry.</p>"""))
        self.siblingRadioButton = QRadioButton("to be a Si&bling of itself")
        self.tooltips.append((self.subentryRadioButton, """\
<p><b>to be a Sibling of itself</b></p>
<p>Copy the original entry to be a sibling of itself, i.e., to be a
subentry of the original entry's parent.</p>"""))

        self.filteredEntry = self.circledEntry = None
        filteredEid = self.state.viewFilteredPanel.view.selectedEid
        if filteredEid is not None:
            self.filteredEntry = self.state.model.entry(filteredEid)
        circledEid = self.state.viewAllPanel.view.circledEid
        if circledEid is not None:
            self.circledEntry = self.state.model.entry(circledEid)

        self.filteredRadioButton = QRadioButton("under &Filtered")
        self.circledRadioButton = QRadioButton("under C&ircled")
        self.recentRadioButton = QRadioButton("under &Recent")
        self.tooltips.append(
            (self.recentRadioButton, """<p><b>under Recent</b></p>
<p>Copy the current entry under a recently visited entry.</p>"""))

        self.filteredLabel = Widgets.Label.HtmlLabel()
        self.circledLabel = Widgets.Label.HtmlLabel()

        self.copyToTopRadioButton.setChecked(True)
        seen = {selectedEid}
        self.buttons = (self.copyToTopRadioButton, self.subentryRadioButton,
                        self.filteredRadioButton, self.circledRadioButton,
                        self.recentRadioButton)
        Forms.Util.setUpRadioButton(
            self, self.filteredEntry, self.filteredRadioButton,
            self.filteredLabel, self.buttons, seen,
            """<p><b>under Filtered</b></p>
<p>Copy the current entry under the filtered entry “{}”.</p>""")
        Forms.Util.setUpRadioButton(
            self, self.circledEntry, self.circledRadioButton,
            self.circledLabel, self.buttons, seen,
            """<p><b>under Circled</b></p>
<p>Copy the current entry under the circled entry “{}”.</p>""")
        self.recentComboBox = Forms.Util.createTermsComboBox(
            self.state, self.state.gotoEids, ignore=seen, maximum=MAX_RECENT)

        self.optionsGroup = QGroupBox()
        self.copyAllCheckBox = QCheckBox("Copy &All:")
        self.tooltips.append((self.copyAllCheckBox, """\
<p><b>Copy All</b></p>
<p>If you check this checkbox, the other Copy checkboxes are checked in
one go.</p>"""))
        self.copyXrefsCheckBox = QCheckBox("Cross-r&eferences")
        self.tooltips.append((self.copyXrefsCheckBox, """\
<p><b>Cross-references</b></p>
<p>Copy cross-references from the original entry(ies) to the copied
entry(ies).</p>"""))
        self.copyGroupsCheckBox = QCheckBox("&Groups")
        self.tooltips.append((self.copyGroupsCheckBox, """\
<p><b>Groups</b></p>
<p>Copy groups from the original entry(ies) to the copied
entry(ies).</p>
<p>If you check the <b>Link Pages...</b> checkbox, this checkbox will be
both checked and disabled, since linking is achieved by copying a linked
group (creating one if necessary).</p>"""))
        self.copySubentriesCheckBox = QCheckBox("S&ubentries")
        self.tooltips.append((self.copySubentriesCheckBox, """\
<p><b>Subentries</b></p>
<p>Copy the copied entry's subentries, subsubentries, and so on.</p>"""))
        self.linkPagesCheckBox = QCheckBox("&Link Pages between")
        self.linkLabel = Widgets.Label.HtmlLabel(
            "“{}” and its copy".format(termText))
        self.tooltips.append((self.linkPagesCheckBox, """\
<p><b>Link Pages</b></p>
<p>If the original entry belongs to a linked group, its copy is added to
that linked group. If the original doesn't belong to a linked group, a
new linked group is created with the name of the original's term, and
both the original and its copy are added to this new linked group.</p>
<p>If you check the this checkbox, the <b>Copy Groups</b> checkbox will be
both checked and disabled, since linking is achieved by copying a linked
group (creating one if necessary).</p>"""))
        self.withSeeCheckBox = QCheckBox("A&dd a")
        self.withSeeLabel1 = Widgets.Label.HtmlLabel(
            "<i>see</i> cross-reference from the copy to “{}”".format(
                termText))
        self.withSeeLabel2 = Widgets.Label.HtmlLabel(
            "and <i>don't</i> copy the pages")
        self.withSeeLabel2.setIndent(self.fontMetrics().width("WW"))

        self.buttonBox = QDialogButtonBox()
        self.copyButton = QPushButton(QIcon(":/copy.svg"), "C&opy")
        self.tooltips.append((self.copyButton, """<p><b>Copy</b></p>
<p>Copy the “{}” entry.</p>""".format(self.termLabel.text())))
        self.buttonBox.addButton(self.copyButton, QDialogButtonBox.AcceptRole)
        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 Copy Entry dialog"))
        self.buttonBox.addButton(self.helpButton, QDialogButtonBox.HelpRole)

    def layoutWidgets(self):
        layout = QVBoxLayout()
        entryLayout = QHBoxLayout()
        entryLayout.setSpacing(0)
        entryLayout.addWidget(self.entryLabel)
        entryLayout.addWidget(self.termLabel)
        entryLayout.addStretch()
        layout.addLayout(entryLayout)
        eidLayout = QVBoxLayout()
        eidLayout.addWidget(self.copyToTopRadioButton)
        eidLayout.addWidget(self.subentryRadioButton)
        eidLayout.addWidget(self.siblingRadioButton)
        hbox = QHBoxLayout()
        hbox.setSpacing(0)
        hbox.addWidget(self.filteredRadioButton)
        hbox.addWidget(self.filteredLabel, 1)
        eidLayout.addLayout(hbox)
        hbox = QHBoxLayout()
        hbox.setSpacing(0)
        hbox.addWidget(self.circledRadioButton)
        hbox.addWidget(self.circledLabel, 1)
        eidLayout.addLayout(hbox)
        hbox = QHBoxLayout()
        hbox.setSpacing(0)
        hbox.addWidget(self.recentRadioButton)
        hbox.addWidget(self.recentComboBox, 1)
        eidLayout.addLayout(hbox)
        eidLayout.addStretch()
        self.eidGroup.setLayout(eidLayout)
        layout.addWidget(self.eidGroup)
        vbox = QVBoxLayout()
        hbox = QHBoxLayout()
        hbox.addWidget(self.copyAllCheckBox)
        hbox.addWidget(self.copyXrefsCheckBox)
        hbox.addWidget(self.copyGroupsCheckBox)
        hbox.addWidget(self.copySubentriesCheckBox)
        hbox.addStretch()
        vbox.addLayout(hbox)
        hbox = QHBoxLayout()
        hbox.setSpacing(0)
        hbox.addWidget(self.linkPagesCheckBox)
        hbox.addWidget(self.linkLabel)
        hbox.addStretch()
        vbox.addLayout(hbox)
        hbox = QHBoxLayout()
        hbox.setSpacing(0)
        hbox.addWidget(self.withSeeCheckBox)
        hbox.addWidget(self.withSeeLabel1)
        hbox.addStretch()
        vbox.addLayout(hbox)
        vbox.addWidget(self.withSeeLabel2)
        self.optionsGroup.setLayout(vbox)
        layout.addWidget(self.optionsGroup)
        layout.addWidget(self.buttonBox)
        self.setLayout(layout)

    def createConnections(self):
        self.buttonBox.accepted.connect(self.copy)
        self.buttonBox.rejected.connect(self.reject)
        self.helpButton.clicked.connect(self.help)
        self.copyXrefsCheckBox.toggled.connect(self.updateUi)
        self.copyGroupsCheckBox.toggled.connect(self.updateUi)
        self.copySubentriesCheckBox.toggled.connect(self.updateUi)
        self.linkPagesCheckBox.toggled.connect(self.updateUi)
        self.withSeeCheckBox.toggled.connect(self.updateUi)
        self.copyAllCheckBox.toggled.connect(self.copyAll)
        self.recentRadioButton.toggled.connect(self.moveFocus)
        self.recentComboBox.currentIndexChanged[int].connect(
            self.recentChanged)

    def recentChanged(self):
        self.recentRadioButton.setChecked(True)
        self.updateUi()

    def moveFocus(self):
        if self.recentRadioButton.isChecked():
            self.recentComboBox.setFocus()

    def updateUi(self):
        self.recentRadioButton.setEnabled(self.recentComboBox.count())
        self.recentComboBox.setEnabled(self.recentComboBox.count())
        enable = not self.withSeeCheckBox.isChecked()
        for widget in (self.copyAllCheckBox, self.copyXrefsCheckBox,
                       self.copyGroupsCheckBox, self.copySubentriesCheckBox,
                       self.linkPagesCheckBox):
            if not enable:
                widget.setChecked(False)
            widget.setEnabled(enable)
        self.linkLabel.setEnabled(enable)
        if enable:
            if self.linkPagesCheckBox.isChecked():
                self.copyGroupsCheckBox.setChecked(True)
                self.copyGroupsCheckBox.setEnabled(False)
            else:
                self.copyGroupsCheckBox.setEnabled(True)
            self.copyAllCheckBox.setChecked(
                all(widget.isChecked()
                    for widget in (self.copyXrefsCheckBox,
                                   self.copyGroupsCheckBox,
                                   self.copySubentriesCheckBox)))

    def copyAll(self, checked):
        if checked:
            for widget in (self.copyXrefsCheckBox, self.copyGroupsCheckBox,
                           self.copySubentriesCheckBox):
                widget.setChecked(True)

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

    def copy(self):
        self.state.maybeSave()
        eid = self.selectedEntry.eid
        peid = None
        if self.copyToTopRadioButton.isChecked():
            peid = ROOT
            description = "copy “{}” to be main entry"
        elif self.subentryRadioButton.isChecked():
            peid = eid
            description = "copy “{}” to be subentry of itself"
        elif self.siblingRadioButton.isChecked():
            peid = self.selectedEntry.peid
            description = "copy “{}” to be sibling of itself"
        elif self.filteredRadioButton.isChecked():
            peid = self.filteredEntry.eid
            description = "copy “{}” under filtered"
        elif self.circledRadioButton.isChecked():
            peid = self.circledEntry.eid
            description = "copy “{}” under circled"
        elif self.recentRadioButton.isChecked():
            peid = self.recentComboBox.itemData(
                self.recentComboBox.currentIndex())
            description = "copy “{}” under recently visited"
        if peid is not None:  # Should always be True
            description = description.format(
                Lib.elidePatchHtml(self.selectedEntry.term, self.state))
            self.state.model.copyEntry(
                Lib.CopyInfo(eid, peid, self.copyXrefsCheckBox.isChecked(),
                             self.copyGroupsCheckBox.isChecked(),
                             self.copySubentriesCheckBox.isChecked(),
                             self.linkPagesCheckBox.isChecked(),
                             self.withSeeCheckBox.isChecked(), description))
            say(re.sub(r"^copy", "Copied", Lib.htmlToPlainText(description)),
                SAY_TIMEOUT)
        self.accept()
示例#5
0
class _DelimitedDetectorWidget(_DetectorWidget):

    def _initUI(self):
        # Widgets
        self._rb_delimited = QRadioButton('Delimited')
        self._rb_delimited.setChecked(False)

        self._lbl_elevation = QLabel("Elevation")
        self._lbl_elevation.setStyleSheet("color: blue")
        self._txt_elevation = _AngleRangeWidget(_DelimitedDetector.elevation_rad)
        self._txt_elevation.setEnabled(False)
        self._txt_elevation.setRequired(False)

        self._lbl_azimuth = QLabel('Azimuth')
        self._lbl_azimuth.setStyleSheet("color: blue")
        self._txt_azimuth = _AngleRangeWidget(_DelimitedDetector.azimuth_rad)
        self._txt_azimuth.setEnabled(False)
        self._txt_azimuth.setRequired(False)

        self._rb_annular = QRadioButton('Annular')
        self._rb_annular.setChecked(True)

        self._lbl_takeoffangle = QLabel('Take-off angle')
        self._lbl_takeoffangle.setStyleSheet("color: blue")
        param_takeoffangle = \
            AngleParameter(validators=range_validator(0.0, HALFPI),
                           doc='Take-off angle from the x-y plane')
        param_takeoffangle._name = 'takeoffangle'
        self._txt_takeoffangle = AngleParameterWidget(param_takeoffangle)

        self._lbl_opening = QLabel('Opening')
        self._lbl_opening.setStyleSheet("color: blue")
        param_opening = \
            AngleParameter(validators=range_validator(0.0, HALFPI, False),
                           doc='Opening angle from the take-off angle (above and below)')
        param_opening._name = 'opening'
        self._txt_opening = AngleParameterWidget(param_opening)

        # Layouts
        layout = _DetectorWidget._initUI(self)

        layout.addRow(self._rb_delimited)

        sublayout = QFormLayout()
        sublayout.setContentsMargins(10, 0, 0, 0)
        if sys.platform == 'darwin': # Fix for Mac OS
            sublayout.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.ExpandingFieldsGrow)
        sublayout.addRow(self._lbl_elevation, self._txt_elevation)
        sublayout.addRow(self._lbl_azimuth, self._txt_azimuth)
        layout.addRow(sublayout)

        layout.addRow(self._rb_annular)

        sublayout = QFormLayout()
        sublayout.setContentsMargins(10, 0, 0, 0)
        if sys.platform == 'darwin': # Fix for Mac OS
            sublayout.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.ExpandingFieldsGrow)
        sublayout.addRow(self._lbl_takeoffangle, self._txt_takeoffangle)
        sublayout.addRow(self._lbl_opening, self._txt_opening)
        layout.addRow(sublayout)

        # Signals
        self._rb_delimited.toggled.connect(self._onToggle)
        self._rb_annular.toggled.connect(self._onToggle)

        return layout

    def _onToggle(self):
        state = self._rb_delimited.isChecked()
        self._txt_elevation.setEnabled(state)
        self._txt_azimuth.setEnabled(state)
        self._txt_elevation.setRequired(state)
        self._txt_azimuth.setRequired(state)
        self._txt_takeoffangle.setEnabled(not state)
        self._txt_opening.setEnabled(not state)
        self._txt_takeoffangle.setRequired(not state)
        self._txt_opening.setRequired(not state)

    def _getElevationValues(self):
        if self._rb_delimited.isChecked():
            return self._txt_elevation.values()
        else:
            takeoffangles = self._txt_takeoffangle.values()
            openings = self._txt_opening.values()

            elevations = []
            for takeoffangle, opening in product(takeoffangles, openings):
                elevation = (takeoffangle - opening, takeoffangle + opening)
                elevations.append(elevation)

            return elevations

    def _getAzimuthValues(self):
        if self._rb_delimited.isChecked():
            return self._txt_azimuth.values()
        else:
            return [(0.0, TWOPI)]

    def setValue(self, value):
        self._rb_delimited.setChecked(True)
        self._txt_elevation.setValues(value.elevation_rad)
        self._txt_azimuth.setValues(value.azimuth_rad)
        self._txt_takeoffangle.setValues([])
        self._txt_opening.setValues([])

    def setReadOnly(self, state):
        _DetectorWidget.setReadOnly(self, state)
        style = 'color: none' if state else 'color: blue'
        self._rb_delimited.setEnabled(not state)
        self._rb_annular.setEnabled(not state)
        self._lbl_elevation.setStyleSheet(style)
        self._txt_elevation.setReadOnly(state)
        self._lbl_azimuth.setStyleSheet(style)
        self._txt_azimuth.setReadOnly(state)
        self._lbl_takeoffangle.setStyleSheet(style)
        self._txt_takeoffangle.setReadOnly(state)
        self._lbl_opening.setStyleSheet(style)
        self._txt_opening.setReadOnly(state)
示例#6
0
class Form(QDialog):
    def __init__(self, state, parent=None):
        super().__init__(parent)
        Lib.prepareModalDialog(self)
        self.state = state
        self.setWindowTitle("Move Entry — {}".format(
            QApplication.applicationName()))
        self.message = None
        self.createWidgets()
        self.layoutWidgets()
        self.createConnections()
        self.updateUi()
        settings = QSettings()
        self.updateToolTips(
            bool(
                int(
                    settings.value(Gopt.Key.ShowDialogToolTips,
                                   Gopt.Default.ShowDialogToolTips))))

    def createWidgets(self):
        selectedEid = self.state.viewAllPanel.view.selectedEid
        self.selectedEntry = self.state.model.entry(selectedEid)
        self.entryLabel = QLabel("Move ")
        self.termLabel = Widgets.Label.HtmlLabel("“{}”".format(
            Lib.elidePatchHtml(self.selectedEntry.term, self.state)))

        self.eidGroup = QGroupBox()

        parentEid = self.selectedEntry.peid
        self.moveToTopRadioButton = QRadioButton("to be a &Main Entry")
        self.grandParentEntry = None
        grandParentEid = None
        if parentEid != ROOT:
            grandParentEid = self.state.model.parentOf(parentEid)
            if grandParentEid != ROOT:
                self.grandParentEntry = self.state.model.entry(grandParentEid)
        self.grandParentRadioButton = QRadioButton("up under &Grandparent")

        self.filteredEntry = self.circledEntry = None
        filteredEid = self.state.viewFilteredPanel.view.selectedEid
        if filteredEid is not None:
            self.filteredEntry = self.state.model.entry(filteredEid)
        circledEid = self.state.viewAllPanel.view.circledEid
        if circledEid is not None:
            self.circledEntry = self.state.model.entry(circledEid)
        self.filteredRadioButton = QRadioButton("under &Filtered")
        self.circledRadioButton = QRadioButton("under C&ircled")
        self.recentRadioButton = QRadioButton("under &Recent")
        self.tooltips.append(
            (self.recentRadioButton, """<p><b>under Recent</b></p>
<p>Move the current entry under a recently visited entry.</p>"""))

        self.grandParentLabel = Widgets.Label.HtmlLabel()
        self.filteredLabel = Widgets.Label.HtmlLabel()
        self.circledLabel = Widgets.Label.HtmlLabel()

        self.moveToTopRadioButton.setEnabled(parentEid != ROOT)
        self.moveToTopRadioButton.setChecked(parentEid != ROOT)
        seen = {selectedEid, self.selectedEntry.peid}
        self.buttons = (self.moveToTopRadioButton, self.grandParentRadioButton,
                        self.filteredRadioButton, self.circledRadioButton,
                        self.recentRadioButton)
        Forms.Util.setUpRadioButton(
            self, self.grandParentEntry, self.grandParentRadioButton,
            self.grandParentLabel, self.buttons, seen,
            """<p><b>under Grandparent</b></p>
<p>Move the current entry up under its grandparent “{}”.</p>""")
        Forms.Util.setUpRadioButton(
            self, self.filteredEntry, self.filteredRadioButton,
            self.filteredLabel, self.buttons, seen,
            """<p><b>under Filtered</b></p>
<p>Move the current entry under the filtered entry “{}”.</p>""")
        Forms.Util.setUpRadioButton(
            self, self.circledEntry, self.circledRadioButton,
            self.circledLabel, self.buttons, seen,
            """<p><b>under Circled</b></p>
<p>Move the current entry under the circled entry “{}”.</p>""")
        self.recentComboBox = Forms.Util.createTermsComboBox(
            self.state, self.state.gotoEids, ignore=seen, maximum=MAX_RECENT)
        if self.recentComboBox.count() and all(not radio.isChecked()
                                               for radio in self.buttons):
            self.recentRadioButton.setChecked(True)
            self.recentComboBox.setFocus()

        self.buttonBox = QDialogButtonBox()
        self.moveButton = QPushButton(QIcon(":/move.svg"), "M&ove")
        self.tooltips.append((self.moveButton, """<p><b>Move</b></p>
<p>Move the “{}” entry.</p>""".format(self.termLabel.text())))
        self.buttonBox.addButton(self.moveButton, QDialogButtonBox.AcceptRole)
        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 Move Entry dialog"))
        self.buttonBox.addButton(self.helpButton, QDialogButtonBox.HelpRole)

    def layoutWidgets(self):
        layout = QVBoxLayout()
        entryLayout = QHBoxLayout()
        entryLayout.setSpacing(0)
        entryLayout.addWidget(self.entryLabel)
        entryLayout.addWidget(self.termLabel)
        entryLayout.addStretch()
        layout.addLayout(entryLayout)
        eidLayout = QVBoxLayout()
        eidLayout.addWidget(self.moveToTopRadioButton)
        hbox = QHBoxLayout()
        hbox.setSpacing(0)
        hbox.addWidget(self.grandParentRadioButton)
        hbox.addWidget(self.grandParentLabel, 1)
        eidLayout.addLayout(hbox)
        hbox = QHBoxLayout()
        hbox.setSpacing(0)
        hbox.addWidget(self.filteredRadioButton)
        hbox.addWidget(self.filteredLabel, 1)
        eidLayout.addLayout(hbox)
        hbox = QHBoxLayout()
        hbox.setSpacing(0)
        hbox.addWidget(self.circledRadioButton)
        hbox.addWidget(self.circledLabel, 1)
        eidLayout.addLayout(hbox)
        hbox = QHBoxLayout()
        hbox.setSpacing(0)
        hbox.addWidget(self.recentRadioButton)
        hbox.addWidget(self.recentComboBox, 1)
        eidLayout.addLayout(hbox)
        eidLayout.addStretch()
        self.eidGroup.setLayout(eidLayout)
        layout.addWidget(self.eidGroup)
        layout.addWidget(self.buttonBox)
        self.setLayout(layout)

    def createConnections(self):
        self.buttonBox.accepted.connect(self.move)
        self.buttonBox.rejected.connect(self.reject)
        self.helpButton.clicked.connect(self.help)
        self.recentRadioButton.toggled.connect(self.moveFocus)
        self.recentComboBox.currentIndexChanged[int].connect(
            self.recentChanged)

    def recentChanged(self):
        self.recentRadioButton.setChecked(True)
        self.updateUi()

    def moveFocus(self):
        if self.recentRadioButton.isChecked():
            self.recentComboBox.setFocus()

    def updateUi(self):
        self.recentRadioButton.setEnabled(self.recentComboBox.count())
        self.recentComboBox.setEnabled(self.recentComboBox.count())
        self.moveButton.setEnabled(
            any(button.isChecked() for button in self.buttons))

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

    def move(self):
        self.state.maybeSave()
        eid = self.selectedEntry.eid
        if self.moveToTopRadioButton.isChecked():
            self.state.model.moveToTop(eid)
        else:
            peid = None
            if self.grandParentRadioButton.isChecked():
                peid = self.grandParentEntry.eid
                message = "move up"
            elif self.filteredRadioButton.isChecked():
                peid = self.filteredEntry.eid
                message = "move under filtered"
            elif self.circledRadioButton.isChecked():
                peid = self.circledEntry.eid
                message = "move under circled"
            elif self.recentRadioButton.isChecked():
                peid = self.recentComboBox.itemData(
                    self.recentComboBox.currentIndex())
                message = "move under recently visited"
            if peid is not None:  # Should always be True
                self.state.model.moveUnder(eid, peid, message)
                term = Lib.htmlToPlainText(self.state.model.term(eid))
                if peid == ROOT:
                    message = "Moved “{}” to be a main entry".format(term)
                else:
                    message = "Moved “{}” under “{}”".format(
                        term, Lib.htmlToPlainText(self.state.model.term(peid)))
                say(message, SAY_TIMEOUT)
        self.accept()
示例#7
0
class Form(QDialog):
    def __init__(self, state, parent=None):
        super().__init__(parent)
        Lib.prepareModalDialog(self)
        self.state = state
        self.setWindowTitle("Add Cross-reference — {}".format(
            QApplication.applicationName()))
        self.createWidgets()
        self.layoutWidgets()
        self.createConnections()
        self.updateUi()
        settings = QSettings()
        self.updateToolTips(
            bool(
                int(
                    settings.value(Gopt.Key.ShowDialogToolTips,
                                   Gopt.Default.ShowDialogToolTips))))

    def createWidgets(self):
        selectedEid = self.state.viewAllPanel.view.selectedEid
        self.selectedEntry = self.state.model.entry(selectedEid)
        self.entry1Label = QLabel("cross-reference from ")
        self.termLabel = Widgets.Label.HtmlLabel("“{}”".format(
            Lib.elidePatchHtml(self.selectedEntry.term, self.state)))
        self.entry2Label = QLabel(" to")
        self.seeRadioButton = QRadioButton("&See")
        self.seeRadioButton.setChecked(True)
        self.tooltips.append((self.seeRadioButton, """<p><b>See</b></p>
<p>Check to create a <i>see</i> cross-reference.</p>"""))
        self.alsoRadioButton = QRadioButton("See &Also")
        self.tooltips.append((self.alsoRadioButton, """<p><b>See
Also</b></p>
<p>Check to create a <i>see also</i> cross-reference.</p>"""))
        self.whichGroup = QGroupBox("Add")
        self.filteredEntry = self.circledEntry = None
        filteredEid = self.state.viewFilteredPanel.view.selectedEid
        if filteredEid is not None:
            self.filteredEntry = self.state.model.entry(filteredEid)
        circledEid = self.state.viewAllPanel.view.circledEid
        if circledEid is not None:
            self.circledEntry = self.state.model.entry(circledEid)
        self.filteredRadioButton = QRadioButton("&Filtered")
        self.circledRadioButton = QRadioButton("C&ircled")
        self.recentRadioButton = QRadioButton("&Recent")
        self.tooltips.append((self.recentRadioButton, """<p><b>Recent</b></p>
<p>Create a cross-reference to a recently visited entry.</p>"""))
        self.filteredLabel = Widgets.Label.HtmlLabel()
        self.circledLabel = Widgets.Label.HtmlLabel()
        seen = {selectedEid}
        buttons = (self.filteredRadioButton, self.circledRadioButton,
                   self.recentRadioButton)
        Forms.Util.setUpRadioButton(
            self, self.filteredEntry, self.filteredRadioButton,
            self.filteredLabel, buttons, seen, """<p><b>Filtered</b></p>
<p>Create a cross-reference to the filtered entry “{}”.</p>""")
        Forms.Util.setUpRadioButton(
            self, self.circledEntry, self.circledRadioButton,
            self.circledLabel, buttons, seen, """<p><b>Circled</b></p>
<p>Create a cross-reference to the circled entry “{}”.</p>""")
        self.recentComboBox = Forms.Util.createTermsComboBox(
            self.state, self.state.gotoEids, ignore=seen, maximum=MAX_RECENT)
        self.groupRadioButton = QRadioButton("All in &Group")
        self.groupComboBox = QComboBox()
        for i, (gid, name, linked) in enumerate(self.state.model.allGroups()):
            self.groupComboBox.addItem(
                QIcon(":/grouplink.svg" if linked else ":/groups.svg"), name,
                gid)
        if not self.groupComboBox.count():
            self.groupRadioButton.setEnabled(False)
            self.groupComboBox.setEnabled(False)
        self.eidGroup = QGroupBox()
        self.genericTermRadioButton = QRadioButton("Generic &Term")
        self.tooltips.append((self.genericTermRadioButton, """\
<p><b>Generic Term</b></p>
<p>Create a cross-reference to the given generic term.</p>"""))
        self.genericTermLineEdit = EnableOnClickLineEdit(
            self.state, self.genericTermRadioButton, self)
        self.tooltips.append((self.genericTermLineEdit, """\
<p><b>Generic Term text</b></p>
<p>The generic term text styled (e.g., <b>bold</b>, <i>italic</i>), as
it should appear in the final index.</p>"""))
        self.formatPanel = Widgets.FormatPanel.Panel(self.state, self)
        self.formatPanel.state.editors = [self.genericTermLineEdit]
        self.formatActions = self.formatPanel.formatActions
        self.buttonBox = QDialogButtonBox()
        self.addButton = QPushButton(QIcon(":/xref-add.svg"), "A&dd")
        self.tooltips.append((self.addButton, """<p><b>Add</b></p>
<p>Add the specified cross-reference to the <b>Entry</b> {}.</p>""".format(
            self.termLabel.text())))
        self.buttonBox.addButton(self.addButton, QDialogButtonBox.AcceptRole)
        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 Add Cross-reference dialog"))
        self.buttonBox.addButton(self.helpButton, QDialogButtonBox.HelpRole)
        if (not self.filteredRadioButton.isChecked()
                and not self.circledRadioButton.isChecked()):
            if self.recentComboBox.count():
                self.recentRadioButton.setChecked(True)
            else:
                self.genericTermRadioButton.setChecked(True)
                self.genericTermLineEdit.setFocus()

    def layoutWidgets(self):
        layout = QVBoxLayout()
        whichLayout = QHBoxLayout()
        whichLayout.addWidget(self.seeRadioButton)
        whichLayout.addWidget(self.alsoRadioButton)
        whichLayout.addStretch()
        self.whichGroup.setLayout(whichLayout)
        layout.addWidget(self.whichGroup)
        entryLayout = QHBoxLayout()
        entryLayout.setSpacing(0)
        entryLayout.addWidget(self.entry1Label)
        entryLayout.addWidget(self.termLabel)
        entryLayout.addWidget(self.entry2Label)
        entryLayout.addStretch()
        layout.addLayout(entryLayout)
        eidLayout = QVBoxLayout()
        hbox = QHBoxLayout()
        hbox.setSpacing(0)
        hbox.addWidget(self.filteredRadioButton)
        hbox.addWidget(self.filteredLabel, 1)
        eidLayout.addLayout(hbox)
        hbox = QHBoxLayout()
        hbox.setSpacing(0)
        hbox.addWidget(self.circledRadioButton)
        hbox.addWidget(self.circledLabel, 1)
        eidLayout.addLayout(hbox)
        hbox = QHBoxLayout()
        hbox.setSpacing(0)
        hbox.addWidget(self.recentRadioButton)
        hbox.addWidget(self.recentComboBox, 1)
        eidLayout.addLayout(hbox)
        hbox = QHBoxLayout()
        hbox.addWidget(self.groupRadioButton)
        hbox.addWidget(self.groupComboBox, 1)
        eidLayout.addLayout(hbox)
        grid = QGridLayout()
        grid.addWidget(self.formatPanel, 0, 0, 1, 2, Qt.AlignRight)
        grid.addWidget(self.genericTermRadioButton, 1, 0)
        grid.addWidget(self.genericTermLineEdit, 1, 1)
        eidLayout.addLayout(grid)
        eidLayout.addStretch()
        self.eidGroup.setLayout(eidLayout)
        layout.addWidget(self.eidGroup)
        layout.addWidget(self.buttonBox)
        self.setLayout(layout)

    def createConnections(self):
        self.buttonBox.accepted.connect(self.addXRef)
        self.buttonBox.rejected.connect(self.reject)
        self.helpButton.clicked.connect(self.help)
        self.filteredRadioButton.clicked.connect(self.updateUi)
        self.circledRadioButton.clicked.connect(self.updateUi)
        self.recentRadioButton.clicked.connect(self.updateUi)
        self.recentRadioButton.toggled.connect(self.moveFocus)
        self.recentComboBox.currentIndexChanged[int].connect(
            self.recentChanged)
        self.groupRadioButton.clicked.connect(self.updateUi)
        self.groupRadioButton.toggled.connect(self.moveFocus)
        self.groupComboBox.currentIndexChanged[int].connect(self.groupChanged)
        self.genericTermRadioButton.clicked.connect(self.updateUi)
        self.genericTermRadioButton.clicked.connect(
            self.genericTermLineEdit.setFocus)
        self.genericTermLineEdit.textChanged.connect(self.updateUi)
        self.genericTermLineEdit.enterPressed.connect(self.maybeAdd)

    def recentChanged(self):
        self.recentRadioButton.setChecked(True)
        self.updateUi()

    def groupChanged(self):
        self.groupRadioButton.setChecked(True)
        self.updateUi()

    def moveFocus(self):
        if self.recentRadioButton.isChecked():
            self.recentComboBox.setFocus()
        elif self.groupRadioButton.isChecked():
            self.groupComboBox.setFocus()

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

    def updateUi(self):
        enable = (self.genericTermRadioButton.isChecked()
                  or (self.groupRadioButton.isChecked()
                      and self.groupComboBox.count()))
        for widget in (self.genericTermLineEdit, self.formatPanel):
            widget.setEnabled(enable)
        self.recentRadioButton.setEnabled(self.recentComboBox.count())
        self.recentComboBox.setEnabled(self.recentComboBox.count())
        enable = True
        if (self.filteredRadioButton.isChecked()
                and self.filteredEntry is None):
            enable = False
        if (self.circledRadioButton.isChecked() and self.circledEntry is None):
            enable = False
        if (self.recentRadioButton.isChecked()
                and self.recentComboBox.currentIndex() < 0):
            enable = False
        if (self.groupRadioButton.isChecked()
                and not self.groupComboBox.count()):
            enable = False
        if (self.genericTermRadioButton.isChecked()
                and self.genericTermLineEdit.isEmpty()):
            enable = False
        self.addButton.setEnabled(enable)

    def maybeAdd(self):
        if (self.genericTermRadioButton.isChecked()
                and not self.genericTermLineEdit.isEmpty()):
            self.addXRef()

    def addXRef(self):
        from_eid = self.selectedEntry.eid
        assert from_eid is not None
        kind = (XrefKind.SEE
                if self.seeRadioButton.isChecked() else XrefKind.SEE_ALSO)
        if self.groupRadioButton.isChecked():
            gid = int(
                self.groupComboBox.itemData(self.groupComboBox.currentIndex()))
            for to_eid in tuple(self.state.model.eidsForGid(gid)):
                self.state.model.addXRef(from_eid, to_eid, kind)
        elif not self.genericTermRadioButton.isChecked():
            to_eid = None
            if self.filteredRadioButton.isChecked():
                to_eid = self.filteredEntry.eid
            elif self.circledRadioButton.isChecked():
                to_eid = self.circledEntry.eid
            elif self.recentRadioButton.isChecked():
                to_eid = self.recentComboBox.itemData(
                    self.recentComboBox.currentIndex())
            assert to_eid is not None
            self.state.model.addXRef(from_eid, to_eid, kind)
        else:
            term = self.genericTermLineEdit.toHtml()
            kind = (XrefKind.SEE_GENERIC if self.seeRadioButton.isChecked()
                    else XrefKind.SEE_ALSO_GENERIC)
            self.state.model.addGenericXRef(from_eid, term, kind)
        say("Added cross-reference", SAY_TIMEOUT)
        self.accept()