def oApply(fldbk): '''this will convert orthographies in the database''' mapping = fldbk.oOrder.toPlainText() pairList = mapping.split(';') if fldbk.oTransformBox.currentIndex() == 0: '''if you set a new pohnetic value for a grapheme''' for child in dataIndex.root.iter('Lex'): string = child.find('Orth').text string = Orthographies.doTransform(string, pairList) try: child.find('IPA').text = string except AttributeError: elemList = list(child) elemList.reverse() for i, item in enumerate(elemList): if item.tag == 'POS': break elif item.tag == 'Orth': break i = len(elemList) - i child.insert(i, etree.Element('IPA')) child.find('IPA').text = string else: '''if you have changed practical orthographies, goes from IPA to new ortho''' for child in dataIndex.root.iter('Lex'): try: string = child.find('IPA').text string = Orthographies.doReverseTransform(string, pairList) child.find('Orth').text = string except AttributeError: pass dataIndex.unsavedEdit = 1
def copyLine(node, outputLanguage='L1'): '''copy example to clipboard''' fldbk = dataIndex.fldbk L2Flag = 1 entryRow0 = node.findtext('Line') if fldbk.eOrthography.currentText() == 'Phonetic': baseOrthography = dataIndex.root.get('Orth') mapping = dataIndex.root.find('Orthography[@Name="%s"]' % baseOrthography).text pairList = mapping.split(';') entryRow0 = Orthographies.doTransform(entryRow0, pairList) if len(entryRow0) == 0: return exampleP = entryRow0 try: entryRow1 = node.findtext('Mrph') if fldbk.eOrthography.currentText() == 'Phonetic': #TODO: set up output of examples in IPA entryRow1 = Orthographies.doTransform(entryRow1, pairList) exampleP += "\r" + entryRow1 entryRow2 = node.findtext('ILEG') exampleP += "\r" + entryRow2 except AttributeError: pass try: entryRow3 = node.findtext('L2Gloss') except AttributeError: L2Flag = 0 if outputLanguage == 'L2' and L2Flag != 0: entryRow3 = node.findtext('L2Gloss') elif len(node.findtext('L1Gloss')) == 0: entryRow3 = node.findtext('L2Gloss') else: entryRow3 = node.findtext('L1Gloss') exampleP += "\r‘" + entryRow3 + "’" exampleP = formattingHandlers.XMLtoPlainText( exampleP) + " (" + node.attrib.get('Spkr') + ")" clipboard = QtWidgets.QApplication.clipboard() clipboard.setText(exampleP) return exampleP
def oRandomTest(fldbk, n): '''select random forms to test''' for i in range(0, n): lexList = dataIndex.lexDict node = choice(list(lexList.keys())) string = dataIndex.lexDict[node].findtext('Orth') if i == 0: inPut = string else: inPut += "\n" + string IPA = Orthographies.testTransform(fldbk, string) if i == 0: output = IPA else: output += "\n" + IPA fldbk.oInput.setPlainText(inPut) fldbk.oOutput.setPlainText(output)
def textTableBuilder(node, j, spokenBy, lineNode): '''builds tables for presenting lines on the text card''' aFlag = 1 entryRow0 = node.findtext('Line') entryRow0 = formattingHandlers.XMLtoRTF(entryRow0) try: if len(node.findtext('Mrph')) == 0: aFlag = 0 else: entryRow1 = node.findtext('Mrph').split('\t') entryRow2 = node.findtext('ILEG').split('\t') except AttributeError: aFlag = 0 if node.find('L2Gloss') != None: if dataIndex.glossingLanguage == 'L2Gloss' and len(node.findtext('L2Gloss')) != 0: entryRow3 = node.findtext('L2Gloss') dataIndex.glossingLanguage = 'L2Gloss' elif len(node.findtext('L1Gloss')) == 0 and len(node.findtext('L2Gloss')) !=0: entryRow3 = node.findtext('L2Gloss') dataIndex.glossingLanguage = 'L2Gloss' else: entryRow3 = node.findtext('L1Gloss') dataIndex.glossingLanguage = 'L1Gloss' else: entryRow3 = node.findtext('L1Gloss') dataIndex.glossingLanguage = 'L1Gloss' '''code to normalize glossing''' entryRow3, spokenBy, timeCode, endTime = update.fixGlosses(entryRow3) node.find(dataIndex.glossingLanguage).text = entryRow3 if timeCode != None: lineNode.set('Time', timeCode) if endTime != None: lineNode.set('EndTime', endTime) if spokenBy != None: lineNode.set('SpokenBy', spokenBy) '''end code for normalizing''' entryRow3 = formattingHandlers.XMLtoRTF(entryRow3) entryRow3 = "‘" + entryRow3 + "’" if lineNode.attrib.get('Time') != None: timeCode = lineNode.attrib.get('Time') entryRow3 += ' [' + timeCode if lineNode.attrib.get('EndTime') != None: endTime = lineNode.attrib.get('EndTime') entryRow3 += ' – ' + endTime + ']' else: entryRow3 += ']' if lineNode.attrib.get('SpokenBy') != None: spokenBy = lineNode.attrib.get('SpokenBy') entryRow3 = spokenBy + ": " + entryRow3 if lineNode.attrib.get('SpokenBy') != node.attrib.get('Spkr'): for speaker in dataIndex.root.iter("Speaker"): if speaker.attrib.get('SCode') == spokenBy: node.set('Spkr', spokenBy) break newTable = textTable.textTable(parent=None) newTable.setGeometry(0, 0, 200, 58) newTable.setSizePolicy(QtWidgets.QSizePolicy.Minimum,QtWidgets.QSizePolicy.Minimum) if aFlag == 1: newTable.setRowCount(4) newTable.setColumnCount(len(entryRow1)) newTable.setRowHeight(0,20) newTable.setRowHeight(1,20) newTable.setRowHeight(2,20) newTable.setRowHeight(3,20) newTable.setMinimumHeight(100) newTable.setMaximumHeight(100) newTable.setVerticalHeaderLabels(["", "", "", ""]) else: newTable.setRowCount(2) newTable.setColumnCount(1) newTable.setRowHeight(0,20) newTable.setRowHeight(1,20) newTable.setMinimumHeight(50) newTable.setMaximumHeight(50) newTable.setVerticalHeaderLabels(["", ""]) tableCellLine = QtWidgets.QTableWidgetItem(10001) tableCellLine.setText(entryRow0) tableCellGloss = QtWidgets.QTableWidgetItem(10001) tableCellGloss.setText(entryRow3) if len(entryRow0) > len(entryRow3): newTable.setItem(0, 0, tableCellLine) else: newTable.setItem(0, 0, tableCellGloss) newTable.resizeColumnToContents(0) minWidth = newTable.columnWidth(0) sumWidth = 0 newTable.takeItem(0, 0) if aFlag == 1: if len(entryRow1) != len(entryRow2): missingDataBox = QtWidgets.QMessageBox() missingDataBox.setIcon(QtWidgets.QMessageBox.Warning) missingDataBox.setStandardButtons(QtWidgets.QMessageBox.Ok) missingDataBox.setDefaultButton(QtWidgets.QMessageBox.Ok) missingDataBox.setText('Mismatched lines.') missingDataBox.setInformativeText('You must have the same number of words ' 'on the analysis and the interlinear gloss lines.\n' 'Line number %s' %str(j+1)) missingDataBox.exec_() return sumWidth = 0 for i in range(0,len(entryRow1)): parse = entryRow2[i] parse = parse.replace(' ', '') newContent, parse = formattingHandlers.smallCapsConverter(parse) tableCellTop = QtWidgets.QTableWidgetItem(10001) tableCellTop.setText(entryRow1[i]) tableCellBottom = QtWidgets.QTableWidgetItem(10001) tableCellBottom.setText(parse + " ") tableCellBottom.setTextAlignment(QtCore.Qt.AlignBottom) newTable.setItem(1,i,tableCellTop) newTable.setItem(2,i,tableCellBottom) newTable.resizeColumnToContents(i) sumWidth += newTable.columnWidth(i) if sumWidth < minWidth: tDiff = minWidth - sumWidth + 5 newTable.setColumnWidth(i, newTable.columnWidth(i) + tDiff) if aFlag == 1: newTable.setItem(0,0,tableCellLine) newTable.setItem(3,0,tableCellGloss) if newTable.columnCount() > 1: newTable.setSpan(0,0,1,newTable.columnCount()) newTable.setSpan(3,0,1,newTable.columnCount()) else: newTable.setItem(0,0,tableCellLine) newTable.setItem(1,0,tableCellGloss) newTable.resizeColumnToContents(0) tableCellNumber = QtWidgets.QTableWidgetItem(1001) tableCellNumber.setText(str(j+1)) tableCellNumber.setData(35,node) tableCellNumber.setFlags(QtCore.Qt.ItemIsEnabled) newTable.setVerticalHeaderItem(0,tableCellNumber) # newTable.setObjectName(eg) newTable.setToolTip(QtWidgets.QApplication.translate("Fieldbook", "click on line number to view \n" "example in the Examples tab.\n" "Sideways scroll long examples with mouse.",None)) if dataIndex.displayOrthography == "Phonetic": mapping = dataIndex.root.find('Orthography[@Name="%s"]'%dataIndex.root.get('Orth')).text pairList = mapping.split(';') Orthographies.changeTextDisplay(dataIndex.fldbk, pairList, newTable) dataIndex.fldbk.tOrthography.setCurrentIndex(dataIndex.fldbk.tOrthography.findText("Phonetic")) return newTable
def loadExCard(egRoot, navBtn=False): fldbk = dataIndex.fldbk targetCard = egRoot.attrib.get('ExID') dataIndex.currentCard = targetCard dataIndex.lastEx = egRoot.attrib.get('ExID') dataIndex.root.set('lastEx',dataIndex.lastEx) if navBtn == False: if len(fldbk.eNavBar.stack) == 0: fldbk.eNavBar.stack.append(targetCard) fldbk.eNavBar.index = fldbk.eNavBar.index + 1 elif fldbk.eNavBar.stack[-1] != targetCard: fldbk.eNavBar.stack.append(targetCard) fldbk.eNavBar.index = fldbk.eNavBar.index + 1 fldbk.eExampleNumber.clear() IDRef = egRoot.get('ExID') fldbk.eExampleNumber.setPlainText(IDRef) fldbk.eKeywords.clear() entry = egRoot.attrib.get('Kywd') if entry: fldbk.eKeywords.setPlainText(entry) '''get data from text <Ln> elements if example is textual''' fldbk.eSourceText.clear() fldbk.eTimeCode.clear() fldbk.eSpokenBy.clear() sourceID = egRoot.attrib.get('SourceText') if sourceID: sourceText = dataIndex.textDict[sourceID] title = sourceText.find('Title').text fldbk.eSourceText.setPlainText(title) lineList = sourceText.findall('Ln') for i in range(0,len(lineList)): if lineList[i].attrib.get('LnRef') == targetCard: fldbk.eLineNumber.setPlainText('line ' + str(i + 1)) if lineList[i].attrib.get('SpokenBy') != None: fldbk.eSpokenBy.setPlainText(lineList[i].attrib.get('SpokenBy')) elif egRoot.attrib.get('SpokenBy') != None: spokenBy = egRoot.attrib.get('SpokenBy') lineList[i].set('SpokenBy', spokenBy) for speaker in dataIndex.root.iter("Speaker"): if speaker.attrib.get('SCode') == spokenBy: egRoot.set('Spkr', spokenBy) break del egRoot.attrib['SpokenBy'] if lineList[i].attrib.get('Time') != None: timeCode = lineList[i].attrib.get('Time') if lineList[i].attrib.get('EndTime') != None: endTime = lineList[i].attrib.get('EndTime') timeCode += ' – ' + endTime fldbk.eTimeCode.setPlainText(timeCode) elif egRoot.attrib.get('Time') != None: lineList[i].set('Time', egRoot.attrib.get('Time')) del egRoot.attrib['Time'] break fldbk.eLinksList.clear() entry = egRoot.attrib.get('Links') if entry: linksList = entry.split(', ') for item in linksList: fldbk.eLinksList.insertItem(-1, item) fldbk.eLinksList.setCurrentIndex(0) fldbk.eSource.clear() entry = egRoot.attrib.get('Spkr') if entry: fldbk.eSource.setPlainText(entry) fldbk.eResearcher.clear() entry = egRoot.attrib.get('Rschr') if entry: fldbk.eResearcher.setPlainText(entry) fldbk.eDate.clear() entry = egRoot.attrib.get('Date') if entry: fldbk.eDate.setPlainText(entry) fldbk.eUpdated.clear() entry = egRoot.attrib.get('Update') if entry: fldbk.eUpdated.setPlainText(entry) fldbk.eLine.clear() entry = egRoot.findtext('Line') if entry: entry = formattingHandlers.XMLtoRTF(entry) fldbk.eLine.setHtml(entry) else: fldbk.eLine.setFontItalic(0) fldbk.eLine.setFontUnderline(0) fldbk.eLine.setFontWeight(50) fldbk.eL1Gloss.clear() entry = egRoot.findtext('L1Gloss') if entry: entry = formattingHandlers.XMLtoRTF(entry) fldbk.eL1Gloss.setHtml(entry) else: fldbk.eL1Gloss.setFontItalic(0) fldbk.eL1Gloss.setFontUnderline(0) fldbk.eL1Gloss.setFontWeight(50) fldbk.eL2Gloss.clear() entry = egRoot.findtext('L2Gloss') if entry: entry = formattingHandlers.XMLtoRTF(entry) fldbk.eL2Gloss.setHtml(entry) else: fldbk.eL2Gloss.setFontItalic(0) fldbk.eL2Gloss.setFontUnderline(0) fldbk.eL2Gloss.setFontWeight(50) fldbk.eExScrollArea.horizontalScrollBar().setValue(0) fldbk.eAnalysis.clear() fldbk.eAnalysis.setColumnCount(0) if egRoot.findtext('Mrph') != None and len(egRoot.findtext('Mrph')) != 0: entryRow1 = egRoot.findtext('Mrph').split('\t') entryRow2 = egRoot.findtext('ILEG').split('\t') #need to handle case where the two lines have different numbers of cells (BAD!) if len(entryRow1) > len(entryRow2): while len(entryRow1) > len(entryRow2): entryRow2.append('[—]') elif len(entryRow1) < len(entryRow2): while len(entryRow1) < len(entryRow2): entryRow1.append('[—]') fldbk.eAnalysis.setRowCount(2) fldbk.eAnalysis.setColumnCount(len(entryRow1)) fldbk.eAnalysis.setRowHeight(0,20) fldbk.eAnalysis.setRowHeight(1,20) for i in range(len(entryRow1)): morphs = entryRow1[i] morphs = morphs.replace(' ', '') if morphs == '': morphs = '[—]' parse = entryRow2[i] parse = parse.replace(' ','') if parse == '': parse = '[—]' newContent, parse = formattingHandlers.smallCapsConverter(parse) tableCellTop = QtWidgets.QTableWidgetItem(1001) tableCellTop.setText(morphs) fldbk.eAnalysis.setItem(0,i,tableCellTop) tableCellBottom = QtWidgets.QTableWidgetItem(1001) tableCellBottom.setText(parse) tableCellBottom.setTextAlignment(QtCore.Qt.AlignBottom) fldbk.eAnalysis.setItem(1,i,tableCellBottom) fldbk.eAnalysis.resizeColumnToContents(i) lastColumn = fldbk.eAnalysis.columnCount() fldbk.eAnalysis.insertColumn(lastColumn) lastHeadWidget = QtWidgets.QTableWidgetItem(1001) lastHeadWidget.setText('+') fldbk.eAnalysis.setHorizontalHeaderItem(lastColumn,lastHeadWidget) fldbk.eAnalysis.resizeColumnToContents(lastColumn) rowHeader = QtWidgets.QTableWidgetItem(1001) rowHeader.setText('Morph') fldbk.eAnalysis.setVerticalHeaderItem(0, rowHeader) rowHeader = QtWidgets.QTableWidgetItem(1001) rowHeader.setText('ILEG') fldbk.eAnalysis.setVerticalHeaderItem(1, rowHeader) if egRoot.findtext('Synt') != None: syntList = egRoot.findall('Synt') for item in syntList: rowHeader = QtWidgets.QTableWidgetItem(1001) rowHeader.setText(item.attrib.get('Tier')) lastRow = fldbk.eAnalysis.rowCount() fldbk.eAnalysis.insertRow(lastRow) fldbk.eAnalysis.setVerticalHeaderItem(lastRow, rowHeader) tagsList = item.text.split("\t") for t, tag in enumerate(tagsList): itemWidget = QtWidgets.QTableWidgetItem(1001) itemWidget.setText(tag) fldbk.eAnalysis.setItem(fldbk.eAnalysis.rowCount()-1,t,itemWidget) for i in range(0,fldbk.eAnalysis.rowCount()): inertWidget = QtWidgets.QTableWidgetItem(1001) inertWidget.setFlags(QtCore.Qt.NoItemFlags) fldbk.eAnalysis.setItem(1,lastColumn,inertWidget) lastCol = fldbk.eAnalysis.columnCount()-1 for i in range(0, fldbk.eAnalysis.rowCount()): newItem = QtWidgets.QTableWidgetItem(1001) flags = QtCore.Qt.ItemFlags() flags != QtCore.Qt.ItemIsEnabled newItem.setFlags(flags) fldbk.eAnalysis.setItem(i, lastCol, newItem) if dataIndex.displayOrthography == "Phonetic": mapping = dataIndex.root.find('Orthography[@Name="%s"]'%dataIndex.root.get('Orth')).text pairList = mapping.split(';') Orthographies.changeExDisplay(fldbk, pairList) fldbk.eOrthography.setCurrentIndex(fldbk.eOrthography.findText("Phonetic")) else: fldbk.eOrthography.setCurrentIndex(fldbk.eOrthography.findText(dataIndex.root.get('Orth'))) try: for c in range(0, fldbk.eAnalysis.columnCount()-1): fldbk.eAnalysis.delegate.boundaryChecker(1, c) except AttributeError: pass fldbk.eNotes.clear() entry = egRoot.findtext('Comments') if entry: entry = formattingHandlers.XMLtoRTF(entry) fldbk.eNotes.setHtml(entry) else: fldbk.eNotes.setFontItalic(0) fldbk.eNotes.setFontUnderline(0) fldbk.eNotes.setFontWeight(50) '''''Recordings''' # fldbk.eRecordings.setItemData(0, dataIndex.lastEx, 33) fldbk.eSound.loadMedia(egRoot)
def loadTextCard(textRoot, navBtn=False): fldbk = dataIndex.fldbk if dataIndex.currentText == textRoot: if dataIndex.displayOrthography != fldbk.tOrthography.currentText(): Orthographies.changeDisplayOrthography(fldbk, -1, 'Txt') return dataIndex.currentText = textRoot dataIndex.newText = False if dataIndex.currentTextTable != None: dataIndex.currentTextTable.setStyleSheet("QTableWidget QHeaderView::section {border-bottom: 0px;" "border-left: 0px; border-top: 0px; border-right: 0px;" "padding: 5px; outline: 0px; background: white;}") dataIndex.currentTextTable = None targetCard = textRoot.attrib.get('TextID') dataIndex.currentCard = targetCard dataIndex.lastText = textRoot.attrib.get('TextID') dataIndex.root.set('LastText',dataIndex.lastText) if navBtn == False: if len(fldbk.tNavBar.stack) == 0: fldbk.tNavBar.stack.append(targetCard) fldbk.tNavBar.index = fldbk.tNavBar.index + 1 elif fldbk.tNavBar.stack[-1] != targetCard: fldbk.tNavBar.stack.append(targetCard) fldbk.tNavBar.index = fldbk.tNavBar.index + 1 fldbk.tSource.clear() entry = textRoot.attrib.get('Spkr') if entry: fldbk.tSource.setPlainText(entry) fldbk.tResearcher.clear() entry = textRoot.attrib.get('Rschr') if entry: fldbk.tResearcher.setPlainText(entry) fldbk.tDate.clear() entry = textRoot.attrib.get('Date') if entry: fldbk.tDate.setPlainText(entry) fldbk.tUpdated.clear() entry = textRoot.attrib.get('Update') if entry: fldbk.tUpdated.setPlainText(entry) fldbk.tTranscriber.clear() entry = textRoot.attrib.get('Trns') if entry: fldbk.tTranscriber.setPlainText(entry) fldbk.tTitle.clear() entry = textRoot.findtext('Title') if entry: entry = formattingHandlers.XMLtoRTF(entry) fldbk.tTitle.setHtml(entry) fldbk.tNotes.clear() entry = textRoot.findtext('Comments') if entry: entry = formattingHandlers.XMLtoRTF(entry) fldbk.tNotes.setHtml(entry) else: fldbk.tNotes.setFontItalic(0) fldbk.tNotes.setFontUnderline(0) fldbk.tNotes.setFontWeight(50) '''text table build''' addTextWidget(fldbk, textRoot) '''Recordings''' fldbk.tSound.loadMedia(textRoot) L1 = dataIndex.root.attrib.get('L1Choice') L2 = dataIndex.root.attrib.get('L2Choice') if dataIndex.glossingLanguage == 'L1Gloss' and L2 != None: label = L1 + " ➔ " + L2 elif dataIndex.glossingLanguage == 'L2Gloss' and L2 != None: label = L2 + " ➔ " + L1 else: label = "—" if len(label) < 10: fldbk.tLanguageBtn.setText(label) resetNavBars(fldbk.tTextNav, dataIndex.currentCard)
def setContents(fldbk, fieldname): update = SessionDate.dateFinder() # print('updating %s' %fieldname) '''update XML for edited fields''' # if dataIndex.updateEnabled == 'off': # return if fieldname[0] == "l": fldbk.lUpdated.setPlainText(update) newContent = fldbk.lUpdated.toPlainText() child = dataIndex.lexDict[dataIndex.currentCard] child.set('Update', newContent) elif fieldname[0] == "t": fldbk.tUpdated.setPlainText(update) newContent = fldbk.tUpdated.toPlainText() child = dataIndex.textDict[dataIndex.currentCard] child.set('Update', newContent) elif fieldname[0] == "e": fldbk.eUpdated.setPlainText(update) newContent = fldbk.eUpdated.toPlainText() child = dataIndex.exDict[dataIndex.currentCard] child.set('Update', newContent) elif fieldname[0] == "d": fldbk.dUpdated.setPlainText(update) newContent = fldbk.dUpdated.toPlainText() child = dataIndex.dataDict[dataIndex.currentCard] child.set('Update', newContent) #Home tab if fieldname == 'hTitle': html = fldbk.hTitle.toHtml() newHtml = formattingHandlers.textStyleHandler(html) fldbk.hTitle.setText(newHtml) newContent = fldbk.hTitle.toPlainText() dataIndex.root.set('Dbase', newContent) fldbk.hTitle.setText(html) elif fieldname == 'hLanguage': newContent = fldbk.hLanguage.toPlainText() dataIndex.root.set('Language', newContent) elif fieldname == 'hFamily': newContent = fldbk.hFamily.toPlainText() dataIndex.root.set('Family', newContent) elif fieldname == 'hPopulation': newContent = fldbk.hPopulation.toPlainText() dataIndex.root.set('Population', newContent) elif fieldname == 'hLocation': newContent = fldbk.hLocation.toPlainText() dataIndex.root.set('Location', newContent) elif fieldname == 'hISO': newContent = fldbk.hISO.toPlainText() dataIndex.root.set('ISO', newContent) #Lexicon elif fieldname == 'lOrthography': newContent = fldbk.lOrthography.text() oldListText = child.find('Orth').text entryID = child.attrib.get('LexID') if newContent != oldListText: child.find('Orth').text = newContent currentProxyIndex = fldbk.lLexNav.currentIndex() currentSourceIndex = fldbk.lLexNav.model().mapToSource( currentProxyIndex) fldbk.lLexNav.model().sourceModel().itemFromIndex( currentSourceIndex).setText(newContent) cardLoader.resetNavBars(fldbk.lLexNav, dataIndex.currentCard) '''if this was a homonym and now isn't in the same set, delink it''' if child.attrib.get('Hom') != None: syn = child.attrib.get('Hom') synList = syn.split(', ') if len(synList) != 0: for card in synList: del dataIndex.lexDict[card].attrib['Hom'] try: synList.remove(entryID) except ValueError: pass if len(synList) != 1: manageHomonyms(synList) '''check to see if you've created homonymy''' homList = [entryID] for node in dataIndex.root.iter('Lex'): '''create list of all homophonous entries''' if node.find('Orth').text == newContent and node.attrib.get( 'LexID') != entryID: homList.append(node.attrib.get('LexID')) if len(homList) > 1: manageHomonyms(homList) '''autoconversion''' if fldbk.lAutoBtn.isChecked(): IPA = Orthographies.toIPA(newContent) fldbk.lIPA.setText(IPA) ipaNode = child.find('IPA') if ipaNode != None: child.remove(ipaNode) if len(newContent) != 0: elemList = list(child) elemList.reverse() for i, item in enumerate(elemList): if item.tag == 'POS': break elif item.tag == 'Orth': break i = len(elemList) - i child.insert(i, etree.Element('IPA')) child.find('IPA').text = IPA elif fieldname == 'lPOS': newContent = fldbk.lPOS.toPlainText() posNode = child.find('POS') if posNode != None: child.remove(posNode) if len(newContent) != 0: child.insert(1, etree.Element('POS')) child.find('POS').text = newContent elif fieldname == 'lIPA': newContent = fldbk.lIPA.text() ipaNode = child.find('IPA') if ipaNode != None: child.remove(ipaNode) if len(newContent) != 0: elemList = list(child) elemList.reverse() for i, item in enumerate(elemList): if item.tag == 'POS': break elif item.tag == 'Orth': break i = len(elemList) - i child.insert(i, etree.Element('IPA')) child.find('IPA').text = newContent elif fieldname == 'lLiteral': newContent = fldbk.lLiteral.toPlainText() if len(newContent) != 0: newContent, newText = formattingHandlers.smallCapsConverter( newContent) fldbk.lLiteral.setText(newText) else: newContent = '' litNode = child.find('Lit') if litNode != None: child.remove(litNode) if len(newContent) != 0: elemList = list(child) for i, item in enumerate(elemList): if item.tag == 'Def': break child.insert(i, etree.Element('Lit')) child.find('Lit').text = newContent elif fieldname == 'lRegister': newContent = fldbk.lRegister.toPlainText() regNode = child.find('Reg') if regNode != None: child.remove(regNode) if len(newContent) != 0: elemList = list(child) elemList.reverse() for i, item in enumerate(elemList): if item.tag == 'Cf.': break elif item.tag == 'C2': break elif item.tag == 'Grm': break elif item.tag == 'IPA': break elif item.tag == 'POS': break elif item.tag == 'Orth': break i = len(elemList) - i child.insert(i, etree.Element('Reg')) child.find('Reg').text = newContent elif fieldname == 'lDialect': newContent = fldbk.lDialect.toPlainText() alternate = '' if newContent: dialectList = newContent.split(None, 1) dialect = dialectList[0] diaText = dialect altList = None if len(dialectList) > 1: alternate = dialectList[1] alternate = re.sub("\(", "", alternate) alternate = re.sub("\)", "", alternate) altList = alternate.split("; ") for i in range(0, len(altList)): alternative = altList[i].split(None, 1) variant = alternative[0] try: alternate = alternative[1] except IndexError: fldbk.dialectBox = QtWidgets.QMessageBox() fldbk.dialectBox.setIcon(QtWidgets.QMessageBox.Warning) fldbk.dialectBox.setStandardButtons( QtWidgets.QMessageBox.Cancel) fldbk.dialectBox.setStandardButtons( QtWidgets.QMessageBox.Ok) fldbk.dialectBox.setDefaultButton( QtWidgets.QMessageBox.Ok) fldbk.dialectBox.setText('Formatting error.') fldbk.dialectBox.setInformativeText( 'Format dialect information as' '<blockquote><big>Cdn. (US. soda; UK fizzy drink)</big></blockquote>' 'For expressions known for only one dialect, simply<br /> ' 'give the dialect name without an alternative.<br />' ) fldbk.dialectBox.exec_() return if i == 0 and len(altList) - 1 == 0: dialect = dialect + " (" + variant + " " + alternate + ")" elif i == 0: dialect = dialect + " (" + variant + " " + alternate elif i == len(altList) - 1: dialect = dialect + "; " + variant + " " + alternate + ")" else: dialect = dialect + "; " + variant + " " + alternate fldbk.lDialect.setText(dialect) crossRef = None oldCrossRef = None if child.find('Dia') != None: oldAlt = child.findall('Dia/Alternative') oldCrossRef = [] if oldAlt != None: for item in oldAlt: oldRef = item.attrib.get('CrossRef') oldCrossRef.append(oldRef) child.remove(child.find('Dia')) if newContent: elemList = list(child) elemList.reverse() for i, item in enumerate(elemList): if item.tag == 'Reg': break elif item.tag == 'Cf': break elif item.tag == 'C2': break elif item.tag == 'Grm': break elif item.tag == 'IPA': break elif item.tag == 'POS': break elif item.tag == 'Orth': break i = len(elemList) - i child.insert(i, etree.Element('Dia', {'Dialect': diaText})) if altList != None and len(altList) != 0: crossRefList = [] alterList = [] for j in range(0, len(altList)): altParts = altList[j].split(None, 1) variant = altParts[0] alternate = altParts[1] newAltNode = etree.SubElement(child.find('Dia'), 'Alternative', {'Variant': variant}) newAltNode.text = alternate for entry in dataIndex.root.iter('Lex'): lexeme = entry.find('Orth').text if lexeme == alternate and entry.attrib.get( 'Hom') != None: #TODO: fix so you can see defs as well as forms? for oldRef in oldCrossRef: if entry.attrib.get('LexID') == oldRef: crossRef = oldRef newAltNode.set('CrossRef', crossRef) break else: synList = entry.attrib.get('Hom').split( ", ") for syn in synList: if entry.attrib.get( 'LexID') == oldCrossRef: crossRef = oldRef newAltNode.set( 'CrossRef', crossRef) break synList.append(entry.attrib.get('LexID')) newCf = CrossRefManager.Dialog(fldbk) newCf.setRefs(synList) if newCf.exec_(): crossRef = newCf.getRef() else: crossRef = None break elif lexeme == alternate: crossRef = entry.attrib.get('LexID') newAltNode.set('CrossRef', crossRef) break if crossRef != None: crossRefList.append(crossRef) alterList.append(alternate) if crossRefList != None: contextMenus.updateContextMenu(fldbk, fieldname, crossRefList, alterList) if crossRefList == None: contextMenus.clearContextMenu(fldbk, fieldname) elif fieldname == 'lBrrw': newContent = fldbk.lBrrw.toPlainText() if newContent: borrowing = newContent.split(None, 1) source = borrowing[0] cognate = borrowing[1] cognate = re.sub('"', '', cognate) cognate = re.sub('“', '', cognate) cognate = re.sub('”', '', cognate) newText = source + ' “' + cognate + '”' fldbk.lBrrw.setPlainText(newText) borrowNode = child.find('Brrw') if borrowNode != None: child.remove(borrowNode) if newContent: elemList = list(child) elemList.reverse() for i, item in enumerate(elemList): if item.tag == 'Dia': break elif item.tag == 'Reg': break elif item.tag == 'Cf.': break elif item.tag == 'C2': break elif item.tag == 'Grm': break elif item.tag == 'IPA': break elif item.tag == 'POS': break elif item.tag == 'Orth': break i = len(elemList) - i child.insert(i, etree.Element('Brrw')) child.find('Brrw').text = cognate child.find('Brrw').set('Source', source) elif fieldname == 'lSource': newContent = fldbk.lSource.toPlainText() child.set('Spkr', newContent) elif fieldname == 'lResearcher': newContent = fldbk.lResearcher.toPlainText() child.set('Rschr', newContent) elif fieldname == 'lDate': newContent = fldbk.lDate.toPlainText() child.set('Date', newContent) elif fieldname == 'lUpdated': newContent = fldbk.lUpdated.toPlainText() child.set('Update', newContent) elif fieldname == 'lConfirmed': newContent = fldbk.lConfirmed.toPlainText() child.set('Confirmed', newContent) elif fieldname == 'lNotes': html = fldbk.lNotes.toHtml() newHtml = formattingHandlers.textStyleHandler(html) fldbk.lNotes.setHtml(newHtml) newContent = fldbk.lNotes.toPlainText().strip() fldbk.lNotes.setHtml(html) comNode = child.find('Comments') if comNode != None: child.remove(comNode) if len(newContent) != 0: elemList = list(child) elemList.reverse() for i, item in enumerate(elemList): if item.tag == 'Root': break elif item.tag == 'Drvn': break elif item.tag == 'Def': break i = len(elemList) - i newCommentNode = etree.Element('Comments') newCommentNode.text = newContent child.insert(i, newCommentNode) elif fieldname == 'lPrimaryIndex': newContent = fldbk.lPrimaryIndex.toPlainText() child.set('L1Index', newContent) elif fieldname == 'lSecondaryIndex': newContent = fldbk.lSecondaryIndex.toPlainText() child.set('L2Index', newContent) elif fieldname == 'lKeywordIndex': newContent = fldbk.lKeywordIndex.toPlainText() child.set('Kywd', newContent) #Examples elif fieldname == 'eLine': html = fldbk.eLine.toHtml() while ' ' in html: html = html.replace(' ', ' ') newHtml = formattingHandlers.textStyleHandler(html) fldbk.eLine.setHtml(newHtml) child.find('Line').text = fldbk.eLine.toPlainText().strip() fldbk.eLine.setHtml(html) ExNode = dataIndex.exDict[dataIndex.currentCard] if dataIndex.currentText != None and ExNode.attrib.get( 'SourceText') != None: prepareTextUpdate(fldbk, ExNode) elif fieldname == 'eL1Gloss': html = fldbk.eL1Gloss.toHtml() while ' ' in html: html = html.replace(' ', ' ') newHtml = formattingHandlers.textStyleHandler(html) fldbk.eL1Gloss.setHtml(newHtml) child.find('L1Gloss').text = fldbk.eL1Gloss.toPlainText().strip() fldbk.eL1Gloss.setHtml(html) ExNode = dataIndex.exDict[dataIndex.currentCard] if dataIndex.currentText != None and ExNode.attrib.get( 'SourceText') != None: prepareTextUpdate(fldbk, ExNode) elif fieldname == 'eL2Gloss': html = fldbk.eL2Gloss.toHtml() while ' ' in html: html = html.replace(' ', ' ') newHtml = formattingHandlers.textStyleHandler(html) fldbk.eL2Gloss.setHtml(newHtml) newGloss = fldbk.eL2Gloss.toPlainText().strip() fldbk.eL2Gloss.setHtml(html) l2Node = child.find('L2Gloss') if l2Node != None: child.remove(l2Node) if len(newContent) != 0: elemList = list(child) elemList.reverse() for i, item in enumerate(elemList): if item.tag == 'L1Gloss': break i = len(elemList) - i child.insert(i, etree.Element('L2Gloss')) child.find('L2Gloss').text = newGloss ExNode = dataIndex.exDict[dataIndex.currentCard] if dataIndex.currentText != None and ExNode.attrib.get( 'SourceText') != None: prepareTextUpdate(fldbk, ExNode) elif fieldname == 'eNotes': if len(fldbk.eNotes.toPlainText()) != 0: html = fldbk.eNotes.toHtml() newHtml = formattingHandlers.textStyleHandler(html) fldbk.eNotes.setHtml(newHtml) newContent = fldbk.eNotes.toPlainText().strip() fldbk.eNotes.setHtml(html) comNode = child.find('Comments') if comNode != None: child.remove(comNode) if len(newContent) != 0: elemList = list(child) elemList.reverse() for i, item in enumerate(elemList): if item.tag == 'L2Gloss': break elif item.tag == 'L1Gloss': break i = len(elemList) - i child.insert(i, etree.Element('Comments')) child.find('Comments').text = newContent elif fieldname == 'eKeywords': newContent = fldbk.eKeywords.toPlainText() child.set('Kywd', newContent) elif fieldname == 'eSource': newContent = fldbk.eSource.toPlainText() child.set('Spkr', newContent) elif fieldname == 'eResearcher': newContent = fldbk.eResearcher.toPlainText() child.set('Rschr', newContent) elif fieldname == 'eDate': newContent = fldbk.eDate.toPlainText() child.set('Date', newContent) elif fieldname == 'eTimeCode': newContent = fldbk.eTimeCode.toPlainText() child.set('Time', newContent) elif fieldname == 'eSpokenBy': newContent = fldbk.eSpokenBy.toPlainText() if child.attrib.get("SourceText") != None: for line in dataIndex.textDict[child.attrib.get( "SourceText")].iter('Ln'): if line.attrib.get('LnRef') == child.attrib.get('ExID'): if len(newContent ) == 0 and line.attrib.get("SpokenBy") != None: del line.attrib['SpokenBy'] elif len(newContent) != 0: line.set('SpokenBy', newContent) for speaker in dataIndex.root.iter('Speaker'): if speaker.attrib.get('SCode') == newContent: child.attrib['Spkr'] = newContent fldbk.eSource.setPlainText(newContent) break break #TEXTS elif fieldname == 'tNotes': if len(fldbk.tNotes.toPlainText()) != 0: html = fldbk.tNotes.toHtml() newHtml = formattingHandlers.textStyleHandler(html) fldbk.tNotes.setHtml(newHtml) newContent = fldbk.tNotes.toPlainText().strip() fldbk.tNotes.setHtml(html) comNode = child.find('Comments') if comNode != None: child.remove(comNode) if len(newContent) != 0: elemList = list(child) elemList.reverse() for i, item in enumerate(elemList): if item.tag == 'Ln': break i = len(elemList) - i child.insert(i, etree.Element('Comments')) child.find('Comments').text = newContent elif fieldname == 'tTranscriber': newContent = fldbk.tTranscriber.toPlainText() child.set('Trns', newContent) elif fieldname == 'tSource': newContent = fldbk.tSource.toPlainText() child.set('Spkr', newContent) elif fieldname == 'tResearcher': newContent = fldbk.tResearcher.toPlainText() child.set('Rschr', newContent) elif fieldname == 'tDate': newContent = fldbk.tDate.toPlainText() child.set('Date', newContent) elif fieldname == 'tTitle': plainTextTitle = fldbk.tTitle.toPlainText() html = fldbk.tTitle.toHtml() newHtml = formattingHandlers.textStyleHandler(html) fldbk.tTitle.setHtml(newHtml) newContent = fldbk.tTitle.toPlainText() fldbk.tTitle.setHtml(html) child.find('Title').text = newContent currentProxyIndex = fldbk.tTextNav.currentIndex() currentSourceIndex = fldbk.tTextNav.model().mapToSource( currentProxyIndex) fldbk.tTextNav.model().sourceModel().itemFromIndex( currentSourceIndex).setText(plainTextTitle) fldbk.tTextNav.model().setSortCaseSensitivity(0) fldbk.tTextNav.model().sort(0, QtCore.Qt.AscendingOrder) fldbk.tTextNav.scrollTo(fldbk.tTextNav.currentIndex(), QtWidgets.QAbstractItemView.EnsureVisible) #DATASETS elif fieldname == 'dSource': newContent = fldbk.dSource.toPlainText() child.set('Spkr', newContent) elif fieldname == 'dResearcher': newContent = fldbk.dResearcher.toPlainText() child.set('Rschr', newContent) elif fieldname == 'dDate': newContent = fldbk.dDate.toPlainText() elif fieldname == 'dKeywords': newContent = fldbk.dKeywords.toPlainText() child.set('Kywd', newContent) elif fieldname == 'dNotes': if len(fldbk.dNotes.toPlainText()) != 0: html = fldbk.dNotes.toHtml() newHtml = formattingHandlers.textStyleHandler(html) fldbk.dNotes.setHtml(newHtml) newContent = fldbk.dNotes.toPlainText().strip() fldbk.dNotes.setHtml(html) comNode = child.find('Comments') if comNode != None: child.remove(comNode) if len(newContent) != 0: elemList = list(child) elemList.reverse() for i, item in enumerate(elemList): if item.tag == 'Data': break elif item.tag == 'Ln': break i = len(elemList) - i child.insert(i, etree.Element('Comments')) child.find('Comments').text = newContent elif fieldname == 'dData': html = fldbk.dData.toHtml() newHtml = formattingHandlers.textStyleHandler(html) fldbk.dData.setHtml(newHtml) newContent = fldbk.dData.toPlainText() fldbk.dData.setHtml(html) child.find('Data').text = newContent elif fieldname == 'dTitle': html = fldbk.dTitle.toHtml() plainTextTitle = fldbk.dTitle.toPlainText() newHtml = formattingHandlers.textStyleHandler(html) fldbk.dTitle.setHtml(newHtml) newContent = fldbk.dTitle.toPlainText() fldbk.dTitle.setHtml(html) child.find('Title').text = newContent currentProxyIndex = fldbk.dDataNav.currentIndex() currentSourceIndex = fldbk.dDataNav.model().mapToSource( currentProxyIndex) fldbk.dDataNav.model().sourceModel().itemFromIndex( currentSourceIndex).setText(plainTextTitle) fldbk.dDataNav.model().setSortCaseSensitivity(0) fldbk.dDataNav.model().sort(0, QtCore.Qt.AscendingOrder) fldbk.dDataNav.scrollTo(fldbk.dDataNav.currentIndex(), QtWidgets.QAbstractItemView.EnsureVisible) #METADATA fields # elif fieldname == 'oOrder' or fieldname == 'oDiacriticsField': # alert = '!Orthography has been edited. Use “Update” to save permanent changes.' # fldbk.oOrthChangedLabel.setText(alert) # fldbk.oOrthChangedLabel.setToolTip('This warning indicates that changes have been made to the\n' # 'Mapping or Diacritics field. These will not be saved unless\n' # 'you click the "Update" button. The original orthography can\n' # 'be restored by clicking on its name in the list below.') elif fieldname == 'sOrder' or fieldname == 'sExclusions': alert = '!Sorting order has been edited. Use “Update” to save permanent changes.' fldbk.sOrderChangedLabel.setText(alert) fldbk.sOrderChangedLabel.setToolTip( 'This warning indicates that changes have been made to the\n' 'Sorting order or Exclusions field. These will not be saved\n' 'unless you click the "Update" button. The original order can\n' 'be restored by clicking on its name in the list below.')
def newCard(fldbk): today = SessionDate.dateFinder() tDate = setSessionDate() dataIndex.unsavedEdit = 1 if fldbk.tabWidget.currentIndex() == 1: #lexicon card newID = idGenerator.generateID('LX', dataIndex.lexDict) newCdWindow = NewLexDialog.NewLexDialog(fldbk) navBar = fldbk.lNavBar if newCdWindow.exec_(): clearCard(fldbk) fldbk.lL1Definition.clear() fldbk.lL2Definition.clear() fldbk.lDerivatives.clear() fldbk.lSound.Recordings.clear() fldbk.lSound.SoundFileMeta.clear() fldbk.lDoneBtn.setChecked(0) data = newCdWindow.getData() '''returns a list [speaker,researcher,entry word,gloss]''' newNode = etree.Element('Lex', {"LexID": newID}) newNode.set('Date', tDate) newNode.set('Update', today) newNode.set('Spkr', data[0]) newNode.set('Rschr', data[1]) newNode.set('Done', '0') newOrth = etree.SubElement(newNode, 'Orth') newOrth.text = data[2] '''generate IPA node if Auto checked''' if fldbk.lAutoBtn.isChecked() == True: IPA = Orthographies.toIPA(data[2]) newIPA = etree.SubElement(newNode, 'IPA') newIPA.text = IPA fldbk.lIPA.setText(IPA) newDef = etree.SubElement(newNode, 'Def', {'Index': '1'}) newL1 = etree.SubElement(newDef, 'L1') newL1.text = data[3] fldbk.lSource.setPlainText(data[0]) fldbk.lResearcher.setPlainText(data[1]) fldbk.lDate.setPlainText(tDate) fldbk.lUpdated.setPlainText(tDate) fldbk.lOrthography.setText(data[2]) '''if new word in data[2] is homophonous with another entry''' homList = fldbk.lLexNav.findChildren(QtGui.QStandardItem, data[2]) if homList != None: homList.append(newID) update.manageHomonyms(homList) cardLoader.loadDefinitions(fldbk, newNode) if len(dataIndex.lexDict.keys()) == 1: badNode = dataIndex.root.find('Lex') badID = badNode.attrib.get('LexID') if badID == 'LX00': dataIndex.root.remove(badNode) del dataIndex.lexDict[badID] dataIndex.root.insert(1, newNode) dataIndex.lexDict[newID] = newNode navLists.navListBuilderLex(fldbk) cardLoader.resetNavBars(fldbk.lLexNav, newID) dataIndex.currentCard = newID dataIndex.lastLex = newID dataIndex.lexDict[newID] = newNode dataIndex.root.set('LastLex', newID) if fldbk.tabWidget.currentIndex() == 2: # text card textOnlyBtns.enterNewText(fldbk) navBar = fldbk.tNavBar if fldbk.tabWidget.currentIndex() == 3: # example card navBar = fldbk.eNavBar fldbk.eAnalysis.clear() fldbk.eAnalysis.setColumnCount(2) fldbk.eAnalysis.setRowCount(2) lastHeadWidget = QtWidgets.QTableWidgetItem(1001) lastHeadWidget.setText('+') fldbk.eAnalysis.setHorizontalHeaderItem(1, lastHeadWidget) fldbk.eAnalysis.resizeColumnToContents(1) rowHeader = QtWidgets.QTableWidgetItem(1001) rowHeader.setText('Morph') fldbk.eAnalysis.setVerticalHeaderItem(0, rowHeader) rowHeader = QtWidgets.QTableWidgetItem(1001) rowHeader.setText('ILEG') fldbk.eAnalysis.setVerticalHeaderItem(1, rowHeader) clearCard(fldbk) fldbk.eLinksList.clear() newID = idGenerator.generateID('EX', dataIndex.exDict) newNode = etree.Element('Ex', {"ExID": newID}) newNode.set('Date', tDate) newNode.set('Update', today) if dataIndex.lastRschr != None and len(dataIndex.lastRschr) != 0: newNode.set('Rschr', dataIndex.lastRschr) else: newNode.set('Rschr', 'YYY') if dataIndex.lastSpeaker != None and len(dataIndex.lastSpeaker) != 0: newNode.set('Spkr', dataIndex.lastSpeaker) else: newNode.set('Spkr', 'XX') etree.SubElement(newNode, 'Line') etree.SubElement(newNode, 'Mrph') etree.SubElement(newNode, 'ILEG') etree.SubElement(newNode, 'L1Gloss') egList = list(dataIndex.exDict.keys()) lastExCard = dataIndex.exDict[egList[len(dataIndex.exDict) - 1]] i = list(dataIndex.root).index(lastExCard) if len(dataIndex.exDict.keys()) == 1: badNode = dataIndex.root.find('Ex') badID = badNode.attrib.get('ExID') if badID == 'EX00': dataIndex.root.remove(badNode) del dataIndex.exDict[badID] dataIndex.root.insert(i, newNode) dataIndex.currentCard = newID dataIndex.exDict[newID] = newNode dataIndex.lastEx = newID dataIndex.root.set('lastEx', newID) cardLoader.loadExCard(newNode) if fldbk.tabWidget.currentIndex() == 4: # dataset card nameBox = StyledInputDialog.StyledInputDialog(fldbk) nameBox.setWindowTitle('New dataset.') nameBox.inputLabel.setText('Give the dataset a name.') navBar = fldbk.dNavBar if nameBox.exec_(): title = nameBox.returnInput() newNode = newDataset(fldbk, title) clearCard(fldbk) cardLoader.loadDataCard(newNode) navBar.stack.append(dataIndex.currentCard) navBar.index = navBar.index + 1
def oTest(fldbk): '''test transformations on a string''' string = fldbk.oInput.toPlainText() IPA = Orthographies.testTransform(fldbk, string) fldbk.oOutput.setPlainText(IPA)