def populateConditionalPage(self): layout = QVBoxLayout() for c in MasterConstraintList: if c[1].constraint_type == 'conditional': checkBox = QCheckBox(c[1].explanation) setattr(self, c[0], checkBox) if self.constraints[c[0]]: checkBox.setChecked(True) layout.addWidget(checkBox) self.conditionalPage.setLayout(layout)
class AdvancedFingerTab(QWidget): def __init__(self): super().__init__() self.fingerConfigPanel = ExtendedFingerPanel() self.fingerNumberPanel = NumExtendedFingerPanel() self.relationlogicPanel = LogicRadioButtonGroup('vertical', 'a', title='Relation between finger configuration and ' 'number of extended fingers', a='Apply both', o='Apply either', fg='Apply only the finger configuration', nf='Apply only the number of extended fingers') self.modePanel = LogicRadioButtonGroup('vertical', 'p', title='Search mode', p='Positive', n='Negative') self.includeIbutton = QCheckBox('Treat "i" as extended') self.includeIbutton.setChecked(False) self.default = QPushButton('Return to default') self.default.clicked.connect(self.setToDefault) mainLayout = QGridLayout() self.setLayout(mainLayout) mainLayout.addWidget(self.fingerConfigPanel, 0, 0, 1, 3) mainLayout.addWidget(self.fingerNumberPanel, 1, 0, 1, 3) mainLayout.addWidget(self.relationlogicPanel, 2, 0, 2, 1) mainLayout.addWidget(self.modePanel, 2, 1, 2, 1) mainLayout.addWidget(self.includeIbutton, 2, 2, 1, 1) mainLayout.addWidget(self.default, 3, 2, 1, 1) def setToDefault(self): self.fingerConfigPanel.setToDefault() self.fingerNumberPanel.setToDefault() self.relationlogicPanel.setToDefault('Apply both') self.modePanel.setToDefault('Positive') self.includeIbutton.setChecked(False) def value(self): return { 'fingerConfigRegExps': self.fingerConfigPanel.generateRegExp(self.includeIbutton.isChecked()), 'fingerNumberRegExps': self.fingerNumberPanel.generateRegExp(self.includeIbutton.isChecked()), 'relationLogic': self.relationlogicPanel.value(), 'searchMode': self.modePanel.value() }
class HandshapeSearchDialog(FunctionDialog): header = ['Corpus', 'Sign', 'Token frequency', 'Note'] about = 'Handshape search' name = 'handshape search' def __init__(self, corpus, parent, settings, recent): super().__init__(parent, settings, HSWorker()) self.corpus = corpus self.recent = recent # container widget for scroll container = QWidget() scroll = QScrollArea() scroll.setWidgetResizable(True) scroll.setWidget(container) globalFrame = QGroupBox('Global options') globalLayout = QHBoxLayout() globalFrame.setLayout(globalLayout) self.forearmLogic = LogicRadioButtonGroup('vertical', 'e', title='Forearm', y='Yes', n='No', e='Either') self.estimateLogic = LogicRadioButtonGroup('vertical', 'e', title='Estimated', y='Yes', n='No', e='Either') self.uncertainLogic = LogicRadioButtonGroup('vertical', 'e', title='Uncertain', y='Yes', n='No', e='Either') self.incompleteLogic = LogicRadioButtonGroup('vertical', 'e', title='Incomplete', y='Yes', n='No', e='Either') globalLayout.addWidget(self.forearmLogic) globalLayout.addWidget(self.estimateLogic) globalLayout.addWidget(self.uncertainLogic) globalLayout.addWidget(self.incompleteLogic) self.configLogic = LogicRadioButtonGroup('vertical', 'e', title='Configuration', one='One-config signs', two='Two-config signs', e='Either') self.configLogic.chosen.connect(self.handleConfigChange) #self.handLogic = LogicRadioButtonGroup('vertical', 'e', # title='Hand', # one='One-hand signs', two='Two-hand signs', e='Either') #self.handLogic.chosen.connect(self.handleHandChange) self.handCheckboxGroup = QGroupBox('Hand') self.box1 = QCheckBox('One-hand signs') self.box2 = QCheckBox('Two-hand signs (H1 == H2)') self.box3 = QCheckBox('Two-hand signs (H1 != H2)') self.box1.setChecked(True) self.box2.setChecked(True) self.box3.setChecked(True) self.box1.stateChanged.connect(self.handCheckboxGroupChange) self.box2.stateChanged.connect(self.handCheckboxGroupChange) self.box3.stateChanged.connect(self.handCheckboxGroupChange) vBox = QVBoxLayout() vBox.addWidget(self.box1) vBox.addWidget(self.box2) vBox.addWidget(self.box3) self.handCheckboxGroup.setLayout(vBox) self.createConfigHand() self.createHandshapes() self.logicPanel = LogicRadioButtonGroup('vertical', 'all', title='Signs should contain...', all='All of the above configurations', any='Any of the above configurations') self.searchModePanel = LogicRadioButtonGroup('vertical', 'pos', 'Global search mode', pos='Positive search', neg='Negative search') self.notePanel = QLineEdit() self.notePanel.setPlaceholderText('Enter notes here...') mainLayout = QGridLayout() mainLayout.addWidget(globalFrame, 0, 0, 1, 2) mainLayout.addWidget(self.configLogic, 0, 2, 1, 1) #mainLayout.addWidget(self.handLogic, 0, 3, 1, 1) mainLayout.addWidget(self.handCheckboxGroup, 0, 3, 1, 1) mainLayout.addWidget(self.c1h1Group, 1, 0, 1, 1) mainLayout.addWidget(self.c1h2Group, 1, 1, 1, 1) mainLayout.addWidget(self.c2h1Group, 1, 2, 1, 1) mainLayout.addWidget(self.c2h2Group, 1, 3, 1, 1) mainLayout.addWidget(self.logicPanel, 2, 0, 1, 1) mainLayout.addWidget(self.searchModePanel, 2, 1, 1, 1) mainLayout.addWidget(self.otherGroup, 2, 2, 1, 2) mainLayout.addWidget(self.unmarkedGroup, 3, 0, 1, 4) mainLayout.addWidget(self.markedGroup, 4, 0, 1, 4) mainLayout.addWidget(self.notePanel, 5, 0, 1, 4) container.setLayout(mainLayout) #####This part should be removed later##### #self.testButton = QPushButton('test') #mainLayout.addWidget(self.testButton, 6, 0, 1, 1) #self.testButton.clicked.connect(self.test) #####This part should be removed later##### self.layout().insertWidget(0, scroll) def handCheckboxGroupChange(self): # TODO: implement function to handle the hand widget print('==========') print(self.box1.isChecked()) print(self.box2.isChecked()) print(self.box3.isChecked()) def handleConfigChange(self, option): if option == 'One-config signs': self.c2h1Group.selectionList.setToSpecified('empty') self.c2h2Group.selectionList.setToSpecified('empty') #self.c2h1Group.selectionList.setEnabled(False) #self.c2h2Group.selectionList.setEnabled(False) self.c2h1Group.setEnabled(False) self.c2h2Group.setEnabled(False) else: if self.handLogic.value() == 'One-hand signs': #self.c2h1Group.selectionList.setEnabled(True) self.c2h1Group.setEnabled(True) else: #self.c2h1Group.selectionList.setEnabled(True) #self.c2h2Group.selectionList.setEnabled(True) self.c2h1Group.setEnabled(True) self.c2h2Group.setEnabled(True) def handleHandChange(self, option): if option == 'One-hand signs': self.c1h2Group.selectionList.setToSpecified('empty') self.c2h2Group.selectionList.setToSpecified('empty') #self.c1h2Group.selectionList.setEnabled(False) #self.c2h2Group.selectionList.setEnabled(False) self.c1h2Group.setEnabled(False) self.c2h2Group.setEnabled(False) else: if self.configLogic.value() == 'One-config signs': #self.c1h2Group.selectionList.setEnabled(True) self.c1h2Group.setEnabled(True) else: #self.c1h2Group.selectionList.setEnabled(True) #self.c2h2Group.selectionList.setEnabled(True) self.c1h2Group.setEnabled(True) self.c2h2Group.setEnabled(True) #def test(self): # res = self.generateKwargs() #ret = extended_finger_search(self.corpus, res['c1h1'], res['c1h2'], res['c2h1'], res['c2h2'], res['logic']) # pprint(res) def createConfigHand(self): self.c1h1Group = ConfigHandPanel('Config1Hand1') self.c1h2Group = ConfigHandPanel('Config1Hand2') self.c2h1Group = ConfigHandPanel('Config2Hand1') self.c2h2Group = ConfigHandPanel('Config2Hand2') def createHandshapes(self): # unmarked handshapes self.unmarkedGroup = HandshapePanel('Unmarked handshapes') self.unmarkedGroup.addHandshape('A') self.unmarkedGroup.addHandshape('B1') self.unmarkedGroup.addHandshape('B2') self.unmarkedGroup.addHandshape('C') self.unmarkedGroup.addHandshape('O') self.unmarkedGroup.addHandshape('S') self.unmarkedGroup.addHandshape('1') self.unmarkedGroup.addHandshape('5') # marked handshapes self.markedGroup = HandshapePanel('Marked handshapes') self.markedGroup.addHandshape('g') self.markedGroup.addHandshape('7') # other self.otherGroup = HandshapePanel('Others') self.otherGroup.addHandshape('any') self.otherGroup.addHandshape('empty') def generateKwargs(self): kwargs = dict() kwargs['corpus'] = self.corpus kwargs['forearm'] = self.forearmLogic.value() kwargs['estimated'] = self.estimateLogic.value() kwargs['uncertain'] = self.uncertainLogic.value() kwargs['incomplete'] = self.incompleteLogic.value() kwargs['configuration'] = self.configLogic.value() kwargs['hand'] = self.handLogic.value() kwargs['logic'] = self.logicPanel.value() kwargs['config1hand1'] = self.c1h1Group.value() kwargs['config1hand2'] = self.c1h2Group.value() kwargs['config2hand1'] = self.c2h1Group.value() kwargs['config2hand2'] = self.c2h2Group.value() self.note = self.notePanel.text() return kwargs @Slot(object) def setResults(self, results): #TODO: need to modify token frequency when implemented (right not there is not frquency info) #TODO: double check thread method to properly place accept() self.results = list() for sign in results: self.results.append({'Corpus': self.corpus.name, 'Sign': sign.gloss, 'Token frequency': 1, 'Note': self.notePanel.text()}) self.accept() #app = QApplication(sys.argv) #main = HandshapeSearchDialog(None, None, None, None) #main.show() #sys.exit(app.exec_())
class TranscriptionSearchDialog(FunctionDialog): header = [ 'Corpus', 'Sign', 'Coder', 'Last updated', 'Token frequency', 'Note' ] about = 'Transcription search' name = 'transcription search' def __init__(self, corpus, parent, settings, recent): super().__init__(parent, settings, TSWorker()) self.corpus = corpus self.recent = recent globalFrame = QGroupBox('Global options') globalFrame.setFixedWidth(500) globalLayout = QHBoxLayout() globalFrame.setLayout(globalLayout) self.forearmLogic = LogicRadioButtonGroup('vertical', 'e', title='Forearm', y='Yes', n='No', e='Either') self.estimateLogic = LogicRadioButtonGroup('vertical', 'e', title='Estimated', y='Yes', n='No', e='Either') self.uncertainLogic = LogicRadioButtonGroup('vertical', 'e', title='Uncertain', y='Yes', n='No', e='Either') self.incompleteLogic = LogicRadioButtonGroup('vertical', 'e', title='Incomplete', y='Yes', n='No', e='Either') self.configLogic = LogicRadioButtonGroup('vertical', 'e', title='Configuration', one='One-config signs', two='Two-config signs', e='Either') #self.configLogic.setFixedWidth(150) self.handCheckboxGroup = QGroupBox('Hand') self.box1 = QCheckBox('One-hand signs') self.box2 = QCheckBox('Two-hand signs (H1 == H2)') self.box3 = QCheckBox('Two-hand signs (H1 != H2)') self.box1.setChecked(True) self.box2.setChecked(True) self.box3.setChecked(True) vBox = QVBoxLayout() vBox.addWidget(self.box1) vBox.addWidget(self.box2) vBox.addWidget(self.box3) self.handCheckboxGroup.setLayout(vBox) # TODO: implement function to handle the hand widget #self.handCheckboxGroup.setFixedWidth(150) #self.handLogic = LogicRadioButtonGroup('vertical', 'e', title='Hand', one='One-hand signs', two='Two-hand signs', e='Either') #self.handLogic.setFixedWidth(150) frequencyGroup = QGroupBox('Frequency') frequencyGroup.setFixedWidth(100) freqeuncyLayout = QVBoxLayout() frequencyGroup.setLayout(freqeuncyLayout) self.minLineEdit = QLineEdit(str(self.corpus.getFrequencyRange()[0])) self.maxLineEdit = QLineEdit(str(self.corpus.getFrequencyRange()[1])) freqeuncyLayout.addWidget(QLabel('From:')) freqeuncyLayout.addWidget(self.minLineEdit) freqeuncyLayout.addWidget(QLabel('To:')) freqeuncyLayout.addWidget(self.maxLineEdit) globalLayout.addWidget(self.forearmLogic) globalLayout.addWidget(self.estimateLogic) globalLayout.addWidget(self.uncertainLogic) globalLayout.addWidget(self.incompleteLogic) config1Frame = QGroupBox('Config 1') config1Layout = QVBoxLayout() config1Frame.setLayout(config1Layout) self.config1 = TransConfigTab() self.config1.setFixedWidth(1250) config1Layout.addWidget(self.config1) config2Frame = QGroupBox('Config 2') config2Layout = QVBoxLayout() config2Frame.setLayout(config2Layout) self.config2 = TransConfigTab() self.config2.setFixedWidth(1250) config2Layout.addWidget(self.config2) self.notePanel = QLineEdit() self.notePanel.setPlaceholderText('Enter notes here...') metaInfoGroup = QGroupBox() metaInfoLayout = QHBoxLayout() metaInfoGroup.setLayout(metaInfoLayout) self.coderSlot = CoderSlot(self.corpus) self.lastUpdatedSlot = LastUpdateSlot(self.corpus) metaInfoLayout.addWidget(QLabel('Coder:')) metaInfoLayout.addWidget(self.coderSlot) metaInfoLayout.addWidget(QLabel('Last updated:')) metaInfoLayout.addWidget(self.lastUpdatedSlot) mainLayout = QGridLayout() #self.setLayout(mainLayout) mainLayout.addWidget(globalFrame, 0, 0, 1, 1) mainLayout.addWidget(frequencyGroup, 0, 1, 1, 1) mainLayout.addWidget(self.configLogic, 0, 2, 1, 1) #mainLayout.addWidget(self.handLogic, 0, 3, 1, 1) mainLayout.addWidget(self.handCheckboxGroup, 0, 3, 1, 1) mainLayout.addWidget(config1Frame, 1, 0, 1, 4) mainLayout.addWidget(config2Frame, 2, 0, 1, 4) mainLayout.addWidget(metaInfoGroup, 3, 0, 1, 2) mainLayout.addWidget(self.notePanel, 3, 2, 1, 2) #self.testButton = QPushButton('test') #mainLayout.addWidget(self.testButton, 4, 0) #self.testButton.clicked.connect(self.test) self.layout().insertLayout(0, mainLayout) #def test(self): # pprint(self.lastUpdatedSlot.value()) # results = {'forearmLogic': self.forearmLogic.value(), # 'estimated': self.estimateLogic.value(), # 'uncertain': self.uncertainLogic.value(), # 'incomplete': self.incompleteLogic.value(), # 'configuration': self.configLogic.value(), # 'hand': self.handLogic.value(), # 'config1': self.config1.value(), # 'config2': self.config2.value()} # pprint(results) # # return results def generateKwargs(self): kwargs = dict() kwargs['corpus'] = self.corpus kwargs['forearm'] = self.forearmLogic.value() kwargs['estimated'] = self.estimateLogic.value() kwargs['uncertain'] = self.uncertainLogic.value() kwargs['incomplete'] = self.incompleteLogic.value() kwargs['configuration'] = self.configLogic.value() kwargs['hand'] = self.handLogic.value() kwargs['config1'] = self.config1.value() kwargs['config2'] = self.config2.value() kwargs['frequency_range'] = (float(self.minLineEdit.text()), float(self.maxLineEdit.text())) kwargs['coder'] = self.coderSlot.value() kwargs['lastUpdated'] = self.lastUpdatedSlot.value() self.note = self.notePanel.text() return kwargs @Slot(object) def setResults(self, results): #TODO: need to modify token frequency when implemented (right not there is not frquency info) #TODO: double check thread method to properly place accept() self.results = list() for sign in results: self.results.append({ 'Corpus': self.corpus.name, 'Sign': sign.gloss, 'Coder': sign.coder, 'Last updated': str(sign.lastUpdated), 'Token frequency': sign.frequency, 'Note': self.note }) self.accept()
class BasicSearchTab(QWidget): def __init__(self): super().__init__() self.handPanel = LogicRadioButtonGroup('horizontal', 'c1h1', title='Configuration/Hand', c1h1='Config1Hand1', c1h2='Config1Hand2', c2h1='Config2Hand1', c2h2='Config2Hand2', ) self.includeIbutton = QCheckBox('Treat "i" as extended') self.includeIbutton.setChecked(False) self.fingerConfigPanel = ExtendedFingerPanel() self.fingerNumberPanel = NumExtendedFingerPanel() self.relationlogicPanel = LogicRadioButtonGroup('vertical', 'a', title='Relation between finger configuration and ' 'number of extended fingers', a='Apply both', o='Apply either', fg='Apply only the finger configuration', nf='Apply only the number of extended fingers') #self.signTypePanel = LogicRadioButtonGroup('vertical', # 'e', # title='Sign type', # sg='Only one-hand signs', # db='Only two-hand signs', # e='Either') self.handCheckboxGroup = QGroupBox('Hand') self.box1 = QCheckBox('One-hand signs') self.box2 = QCheckBox('Two-hand signs (H1 == H2)') self.box3 = QCheckBox('Two-hand signs (H1 != H2)') self.box1.setChecked(True) self.box2.setChecked(True) self.box3.setChecked(True) vBox = QVBoxLayout() vBox.addWidget(self.box1) vBox.addWidget(self.box2) vBox.addWidget(self.box3) self.handCheckboxGroup.setLayout(vBox) self.modePanel = LogicRadioButtonGroup('vertical', 'p', title='Search mode', p='Positive', n='Negative') self.notePanel = QLineEdit() self.notePanel.setPlaceholderText('Enter notes here...') mainLayout = QGridLayout() self.setLayout(mainLayout) mainLayout.addWidget(self.handPanel, 0, 0, 1, 2) mainLayout.addWidget(self.includeIbutton, 0, 2, 1, 1) mainLayout.addWidget(self.fingerConfigPanel, 1, 0, 1, 3) mainLayout.addWidget(self.fingerNumberPanel, 2, 0, 1, 3) mainLayout.addWidget(self.relationlogicPanel, 3, 0, 1, 1) #mainLayout.addWidget(self.signTypePanel, 3, 1, 1, 1) mainLayout.addWidget(self.handCheckboxGroup, 3, 1, 1, 1) mainLayout.addWidget(self.modePanel, 3, 2, 1, 1) mainLayout.addWidget(self.notePanel, 4, 0, 1, 3) def value(self): handconfig = self.handPanel.value() fingerConfigRegExps = self.fingerConfigPanel.generateRegExp(self.includeIbutton.isChecked()) fingerNumberRegExps = self.fingerNumberPanel.generateRegExp(self.includeIbutton.isChecked()) reltionLogic = self.relationlogicPanel.value() searchMode = self.modePanel.value() handconfigvalue = { 'fingerConfigRegExps': fingerConfigRegExps, 'fingerNumberRegExps': fingerNumberRegExps, 'relationLogic': reltionLogic, 'searchMode': searchMode } neutralhandRegExp = re.compile('(?P<thumb>_....)..\u2205/......' \ '(?P<index>1...)' \ '(?P<middle>.2...)' \ '(?P<ring>.3...)' \ '(?P<pinky>.4...)') neutralhandRegExps = set() neutralhandRegExps.add(neutralhandRegExp) neutralvalue = { 'fingerConfigRegExps': neutralhandRegExps, 'fingerNumberRegExps': neutralhandRegExps, 'relationLogic': 'Apply both', 'searchMode': 'Positive' } if handconfig == 'Configuration 1 Hand 1': c1h1 = handconfigvalue c1h2 = neutralvalue c2h1 = neutralvalue c2h2 = neutralvalue elif handconfig == 'Configuration 1 Hand 2': c1h1 = neutralvalue c1h2 = handconfigvalue c2h1 = neutralvalue c2h2 = neutralvalue elif handconfig == 'Configuration 2 Hand 1': c1h1 = neutralvalue c1h2 = neutralvalue c2h1 = handconfigvalue c2h2 = neutralvalue else: c1h1 = neutralvalue c1h2 = neutralvalue c2h1 = neutralvalue c2h2 = handconfigvalue signType = set() for typ, check in (('one', self.box1.isChecked()), ('two-same', self.box2.isChecked()), ('two-diff', self.box3.isChecked())): if check: signType.add(typ) return { 'c1h1': c1h1, 'c1h2': c1h2, 'c2h1': c2h1, 'c2h2': c2h2, 'logic': 'All four hand/configuration specifications', 'signType': signType, 'note': self.notePanel.text() }
class NumExtendedFingerPanel(QGroupBox): fingers = ['thumb', 'index', 'middle', 'ring', 'pinky'] fingerConfigDict_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>.)..)'} } fingerConfigDict_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): super().__init__('Number of extended fingers') groupLayout = QVBoxLayout() self.setLayout(groupLayout) logicComment = QLabel('Returned signs will contain ANY of the specificed numbers:') groupLayout.addWidget(logicComment) buttonLayout = QHBoxLayout() groupLayout.addLayout(buttonLayout) self.zero = QCheckBox('0') self.one = QCheckBox('1') self.two = QCheckBox('2') self.three = QCheckBox('3') self.four = QCheckBox('4') self.five = QCheckBox('5') self.zero.setChecked(True) self.one.setChecked(True) self.two.setChecked(True) self.three.setChecked(True) self.four.setChecked(True) self.five.setChecked(True) buttonLayout.addWidget(self.zero) buttonLayout.addWidget(self.one) buttonLayout.addWidget(self.two) buttonLayout.addWidget(self.three) buttonLayout.addWidget(self.four) buttonLayout.addWidget(self.five) def setToDefault(self): self.zero.setChecked(True) self.one.setChecked(True) self.two.setChecked(True) self.three.setChecked(True) self.four.setChecked(True) self.five.setChecked(True) def generateRegExp(self, includeI): def generate_subset(s, n): """ Helper function for calculating "from s take n" """ return list(combinations(s, n)) regExps = set() # First, find the numbers that are checked numFingers = self.value() for num in numFingers: # Second, find the fingers that corresponding to a num combs = generate_subset(self.fingers, num) for comb in combs: fingers_reg = r'' for finger in self.fingers: if includeI: if finger in comb: reg = self.fingerConfigDict_with_i[finger]['Extended'] fingers_reg += reg else: reg = self.fingerConfigDict_with_i[finger]['Not extended'] fingers_reg += reg else: if finger in comb: reg = self.fingerConfigDict_without_i[finger]['Extended'] fingers_reg += reg else: reg = self.fingerConfigDict_without_i[finger]['Not extended'] fingers_reg += reg regExps.add(fingers_reg) return regExps def value(self): checkedNum = list() for button in [self.zero, self.one, self.two, self.three, self.four, self.five]: if button.isChecked(): checkedNum.append(int(button.text())) return checkedNum
class AdvancedSearchTab(QWidget): def __init__(self): super().__init__() style = 'QTabWidget::pane { /* The tab widget frame */' \ 'border: 5px solid #9B9B9B;' \ 'top: -0.75em;}' self.c1h1Tab = AdvancedFingerTab() self.c1h2Tab = AdvancedFingerTab() self.c2h1Tab = AdvancedFingerTab() self.c2h2Tab = AdvancedFingerTab() handTab = QTabWidget() handTab.setStyleSheet(style) handTab.addTab(self.c1h1Tab, 'Config1Hand1') handTab.addTab(self.c1h2Tab, 'Config1Hand2') handTab.addTab(self.c2h1Tab, 'Config2Hand1') handTab.addTab(self.c2h2Tab, 'Config2Hand2') self.logicPanel = LogicRadioButtonGroup('horizontal', 'all', 'Signs should contain', all='All four hand/configuration specifications', any='Any of the four hand/configuration specifications') self.searchModePanel = LogicRadioButtonGroup('horizontal', 'pos', 'Global search mode', pos='Positive search', neg='Negative search') #self.signTypePanel = LogicRadioButtonGroup('horizontal', # 'e', # title='Sign type', # sg='Only one-hand signs', # db='Only two-hand signs', # e='Either') self.handCheckboxGroup = QGroupBox('Hand') self.box1 = QCheckBox('One-hand signs') self.box2 = QCheckBox('Two-hand signs (H1 == H2)') self.box3 = QCheckBox('Two-hand signs (H1 != H2)') self.box1.setChecked(True) self.box2.setChecked(True) self.box3.setChecked(True) hBox = QHBoxLayout() hBox.addWidget(self.box1) hBox.addWidget(self.box2) hBox.addWidget(self.box3) self.handCheckboxGroup.setLayout(hBox) self.notePanel = QLineEdit() self.notePanel.setPlaceholderText('Enter notes here...') mainLayout = QVBoxLayout() self.setLayout(mainLayout) mainLayout.addWidget(handTab) mainLayout.addWidget(self.logicPanel) mainLayout.addWidget(self.searchModePanel) #mainLayout.addWidget(self.signTypePanel) mainLayout.addWidget(self.handCheckboxGroup) mainLayout.addWidget(self.notePanel) def value(self): signType = set() for typ, check in (('one', self.box1.isChecked()), ('two-same', self.box2.isChecked()), ('two-diff', self.box3.isChecked())): if check: signType.add(typ) return { 'c1h1': self.c1h1Tab.value(), 'c1h2': self.c1h2Tab.value(), 'c2h1': self.c2h1Tab.value(), 'c2h2': self.c2h2Tab.value(), 'logic': self.logicPanel.value(), 'signType': signType, 'note': self.notePanel.text() }