class LogicRadioButtonGroup(QGroupBox):
    chosen = Signal(str)

    def __init__(self, direction, default, title='', **kwarg):
        super().__init__(title)

        if direction == 'vertical':
            buttonLayout = QVBoxLayout()
        else:  # direction == 'horizontal'
            buttonLayout = QHBoxLayout()

        self.buttonGroup = QButtonGroup()
        self.setLayout(buttonLayout)

        for short_name, text in kwarg.items():
            button = QRadioButton(text)
            button.clicked.connect(self.selected)
            if short_name == default:
                button.setChecked(True)
            self.buttonGroup.addButton(button)
            buttonLayout.addWidget(button)

    def setToDefault(self, default_option):
        for option in self.buttonGroup.buttons():
            if option.text() == default_option:
                option.setChecked(True)
            else:
                option.setChecked(False)

    def value(self):
        checked = self.buttonGroup.checkedButton()
        return checked.text()

    def selected(self):
        self.chosen.emit(self.buttonGroup.checkedButton().text())
Exemplo n.º 2
0
class TranscriptionsSearchOptionsDialog(QDialog):
    def __init__(self, blankOptionSelection=None, wildcard=None):
        super().__init__()

        self.blankOptionSelection = blankOptionSelection
        self.wildcard = wildcard

        self.setWindowTitle('Search Options')
        layout = QVBoxLayout()

        blankOptionsLabel = QLabel(
            'How should blank spaces be interpreted in your search?')
        layout.addWidget(blankOptionsLabel)

        blankOptionsLayout = QVBoxLayout()
        self.blankOptionsGroup = QButtonGroup()

        asBlankOption = QRadioButton(
            'Interpret as literal blanks, and only match blank slots')
        blankOptionsLayout.addWidget(asBlankOption)
        self.blankOptionsGroup.addButton(asBlankOption)
        self.blankOptionsGroup.setId(asBlankOption, 0)
        if self.blankOptionSelection == 'literal':
            asBlankOption.setChecked(True)

        asWildcardOption = QRadioButton(
            'Interpret as wildcards, and match anything')
        blankOptionsLayout.addWidget(asWildcardOption)
        self.blankOptionsGroup.addButton(asWildcardOption)
        self.blankOptionsGroup.setId(asWildcardOption, 1)
        if self.blankOptionSelection == 'wildcard' or self.blankOptionSelection is None:
            asWildcardOption.setChecked(True)

        miniLayout = QHBoxLayout()
        asBlankWithWildcard = QRadioButton(
            'Interpret as literal blanks, and use this character for wildcards: '
        )
        self.wildcardLineEdit = QLineEdit()
        self.wildcardLineEdit.setMaxLength(1)
        self.wildcardLineEdit.setMaximumWidth(30)
        self.blankOptionsGroup.addButton(asBlankWithWildcard)
        self.blankOptionsGroup.setId(asBlankWithWildcard, 2)
        if self.blankOptionSelection == 'both':
            asBlankWithWildcard.setChecked(True)
            self.wildcardLineEdit.setText(self.wildcard)
        miniLayout.addWidget(asBlankWithWildcard)
        miniLayout.addWidget(self.wildcardLineEdit)
        blankOptionsLayout.addLayout(miniLayout)

        layout.addLayout(blankOptionsLayout)

        buttonLayout = QHBoxLayout()
        ok = QPushButton('OK')
        ok.clicked.connect(self.accept)
        buttonLayout.addWidget(ok)
        cancel = QPushButton('Cancel')
        cancel.clicked.connect(self.reject)
        buttonLayout.addWidget(cancel)
        layout.addLayout(buttonLayout)

        self.setLayout(layout)

    def accept(self):
        selectedButton = self.blankOptionsGroup.checkedButton()
        id_ = self.blankOptionsGroup.id(selectedButton)
        if id_ == 0:
            self.blankOptionSelection = 'literal'
            self.wildcard = None
        elif id_ == 1:
            self.blankOptionSelection = 'wildcard'
            self.wildcard = '_'
        elif id_ == 2:
            self.blankOptionSelection = 'both'
            self.wildcard = self.wildcardLineEdit.text()
        super().accept()
Exemplo n.º 3
0
class FingerOptionGroup(QGroupBox):
    fingerOptionDict_with_i = {
        'thumb': {'Extended': r'(?P<thumb>.(?P<thumb_opposition>[LU]).(?<thumb_mcp>[HEei]).).+.\u2205/.+.....',
                  'Not extended': r'(?P<thumb>.(?P<thumb_opposition_1>[^LU]).(?<thumb_mcp_1>[HEei]).|_(?P<thumb_opposition_2>[LU]).(?<thumb_mcp_2>[^HEei]).|_(?P<thumb_opposition_3>[^LU]).(?<thumb_mcp_3>[^HEei]).).+.\u2205/.+.....',
                  'Either': r'(?P<thumb>.(?P<thumb_opposition>.).(?<thumb_mcp>.).).+.\u2205/.+.....'},
        'index': {'Extended': r'(?P<index>1(?P<index_mcp>[HEei])..)',
                  'Not extended': r'(?P<index>1(?P<index_mcp>[^HEei])..)',
                  'Either': r'(?P<index>1(?P<index_mcp>.)..)'},
        'middle': {'Extended': r'(?P<middle>.+2(?P<middle_mcp>[HEei])..)',
                   'Not extended': r'(?P<middle>.+2(?P<middle_mcp>[^HEei])..)',
                   'Either': r'(?P<middle>.+2(?P<middle_mcp>.)..)'},
        'ring': {'Extended': r'(?P<ring>.+3(?P<ring_mcp>[HEei])..)',
                 'Not extended': r'(?P<ring>.+3(?P<ring_mcp>[^HEei])..)',
                 'Either': r'(?P<ring>.+3(?P<ring_mcp>.)..)'},
        'pinky': {'Extended': r'(?P<pinky>.+4(?P<pinky_mcp>[HEei])..)',
                  'Not extended': r'(?P<pinky>.+4(?P<pinky_mcp>[^HEei])..)',
                  'Either': r'(?P<pinky>.+4(?P<pinky_mcp>.)..)'}
    }

    fingerOptionDict_without_i = {
        'thumb': {'Extended': r'(?P<thumb>.(?P<thumb_opposition>[LU]).(?<thumb_mcp>[HEe]).).+.\u2205/.+.....',
                  'Not extended': r'(?P<thumb>.(?P<thumb_opposition_1>[^LU]).(?<thumb_mcp_1>[HEe]).|_(?P<thumb_opposition_2>[LU]).(?<thumb_mcp_2>[^HEe]).|_(?P<thumb_opposition_3>[^LU]).(?<thumb_mcp_3>[^HEe]).).+.\u2205/.+.....',
                  'Either': r'(?P<thumb>.(?P<thumb_opposition>.).(?<thumb_mcp>.).).+.\u2205/.+.....'},
        'index': {'Extended': r'(?P<index>1(?P<index_mcp>[HEe])..)',
                  'Not extended': r'(?P<index>1(?P<index_mcp>[^HEe])..)',
                  'Either': r'(?P<index>1(?P<index_mcp>.)..)'},
        'middle': {'Extended': r'(?P<middle>.+2(?P<middle_mcp>[HEe])..)',
                   'Not extended': r'(?P<middle>.+2(?P<middle_mcp>[^HEe])..)',
                   'Either': r'(?P<middle>.+2(?P<middle_mcp>.)..)'},
        'ring': {'Extended': r'(?P<ring>.+3(?P<ring_mcp>[HEe])..)',
                 'Not extended': r'(?P<ring>.+3(?P<ring_mcp>[^HEe])..)',
                 'Either': r'(?P<ring>.+3(?P<ring_mcp>.)..)'},
        'pinky': {'Extended': r'(?P<pinky>.+4(?P<pinky_mcp>[HEe])..)',
                  'Not extended': r'(?P<pinky>.+4(?P<pinky_mcp>[^HEe])..)',
                  'Either': r'(?P<pinky>.+4(?P<pinky_mcp>.)..)'}
    }

    def __init__(self, groupName):
        super().__init__(groupName)

        self.buttonGroup = QButtonGroup()
        self.extended = QRadioButton('Extended')
        self.notExtended = QRadioButton('Not extended')
        self.either = QRadioButton('Either')
        self.either.setChecked(True)

        self.buttonGroup.addButton(self.extended)
        self.buttonGroup.addButton(self.notExtended)
        self.buttonGroup.addButton(self.either)

        buttonLayout = QVBoxLayout()
        self.setLayout(buttonLayout)
        buttonLayout.addWidget(self.extended)
        buttonLayout.addWidget(self.notExtended)
        buttonLayout.addWidget(self.either)

    def setToDefault(self):
        self.extended.setChecked(False)
        self.notExtended.setChecked(False)
        self.either.setChecked(True)

    def getExtendedRegExp(self, includeI):
        finger = self.title().lower()
        if includeI:
            regExp = self.fingerOptionDict_with_i[finger]['Extended']
        else:
            regExp = self.fingerOptionDict_without_i[finger]['Extended']
        return regExp

    def getEitherRegExp(self, includeI):
        finger = self.title().lower()
        if includeI:
            regExp = self.fingerOptionDict_with_i[finger]['Either']
        else:
            regExp = self.fingerOptionDict_without_i[finger]['Either']
        return regExp

    def getNotExtendedRegExp(self, includeI):
        finger = self.title().lower()
        if includeI:
            regExp = self.fingerOptionDict_with_i[finger]['Not extended']
        else:
            regExp = self.fingerOptionDict_without_i[finger]['Not extended']
        return regExp

    def generateRegExp(self, includeI):
        finger = self.title()
        chosen = self.buttonGroup.checkedButton().text()

        if includeI:
            if finger == 'Thumb':
                regExp = self.fingerOptionDict_with_i['thumb'][chosen]
            elif finger == 'Index':
                regExp = self.fingerOptionDict_with_i['index'][chosen]
            elif finger == 'Middle':
                regExp = self.fingerOptionDict_with_i['middle'][chosen]
            elif finger == 'Ring':
                regExp = self.fingerOptionDict_with_i['ring'][chosen]
            else:
                regExp = self.fingerOptionDict_with_i['pinky'][chosen]
        else:
            if finger == 'Thumb':
                regExp = self.fingerOptionDict_without_i['thumb'][chosen]
            elif finger == 'Index':
                regExp = self.fingerOptionDict_without_i['index'][chosen]
            elif finger == 'Middle':
                regExp = self.fingerOptionDict_without_i['middle'][chosen]
            elif finger == 'Ring':
                regExp = self.fingerOptionDict_without_i['ring'][chosen]
            else:
                regExp = self.fingerOptionDict_without_i['pinky'][chosen]

        return regExp

    def value(self):
        checked = self.buttonGroup.checkedButton()
        return checked.text()