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 ConfigHandPanel(QGroupBox): def __init__(self, title): super().__init__(title) self.positive = QCheckBox('Set negative', parent=self) self.selectionList = ConfigHandList(parent=self) Layout = QVBoxLayout() Layout.addWidget(self.positive) Layout.addWidget(self.selectionList) self.setLayout(Layout) def value(self): labels = {self.selectionList.item(i).text() for i in range(self.selectionList.count())} if self.positive.isChecked(): # Set negative operator = lambda x: not x else: operator = lambda x: x #labels = set() #numItems = self.selectionList.count() #for i in range(numItems): # label = self.selectionList.item(i).text() # labels.add(label) return {'labels': labels, 'positive': operator}
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 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 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() }