Beispiel #1
0
def findByID(fldbk):
    inputBox = StyledInputDialog.StyledInputDialog(fldbk)
    inputBox.setWindowTitle('Find by ID')
    inputBox.inputLabel.setText('Enter unique ID for entry.')
    if inputBox.exec_():
        ID = inputBox.returnInput()
    if ID[0] == 'L':
        try:
            target = dataIndex.lexDict[ID]
            cardLoader.loadLexCard(target)
            fldbk.tabWidget.setCurrentIndex(1)
        except KeyError:
            QtWidgets.QApplication.beep()
    elif ID[0] == 'E':
        try:
            target = dataIndex.exDict[ID]
            cardLoader.loadExCard(target)
            fldbk.tabWidget.setCurrentIndex(3)
        except KeyError:
            QtWidgets.QApplication.beep()
    elif ID[0] == 'D':
        try:
            target = dataIndex.dataDict[ID]
            cardLoader.loadDataCard(target)
            fldbk.tabWidget.setCurrentIndex(4)
        except KeyError:
            QtWidgets.QApplication.beep()
    else:
        QtWidgets.QApplication.beep()
Beispiel #2
0
def goToCard(fldbk, direction):
    ##move through cards on buttonclicks, called by buttons
    if direction == -1:
        targetID = cardStackVar.theQueue[cardStackVar.theCounter - 1]
        cardStackVar.theCounter = cardStackVar.theCounter - 1
        fldbk.lFwdBtn.setEnabled(1)
        fldbk.tFwdBtn.setEnabled(1)
        fldbk.eFwdBtn.setEnabled(1)
        fldbk.dFwdBtn.setEnabled(1)
    else:
        targetID = cardStackVar.theQueue[cardStackVar.theCounter + 1]
        cardStackVar.theCounter += 1
        fldbk.lRtnBtn.setEnabled(1)
        fldbk.tRtnBtn.setEnabled(1)
        fldbk.eRtnBtn.setEnabled(1)
        fldbk.dRtnBtn.setEnabled(1)
    if len(cardStackVar.theQueue) - 1 == cardStackVar.theCounter:
        fldbk.lFwdBtn.setEnabled(0)
        fldbk.tFwdBtn.setEnabled(0)
        fldbk.eFwdBtn.setEnabled(0)
        fldbk.dFwdBtn.setEnabled(0)
    if cardStackVar.theCounter == 0:
        fldbk.lRtnBtn.setEnabled(0)
        fldbk.tRtnBtn.setEnabled(0)
        fldbk.eRtnBtn.setEnabled(0)
        fldbk.dRtnBtn.setEnabled(0)
    if targetID[0] == "L":
        navBar = fldbk.lLexNav
        targetCard = dataIndex.lexDict[targetID]
        cardLoader.loadLexCard(targetCard, navBtn=True)
        fldbk.tabWidget.setCurrentIndex(1)
    elif targetID[0] == "T":
        navBar = fldbk.tTextNav
        targetCard = dataIndex.textDict[targetID]
        cardLoader.loadTextCard(targetCard, navBtn=True)
        fldbk.tabWidget.setCurrentIndex(2)
    elif targetID[0] == "E":
        targetCard = dataIndex.exDict[targetID]
        if dataIndex.unsavedEdit == 1:
            pendingChange = 1
        else:
            pendingChange = 0
        cardLoader.loadExCard(targetCard, navBtn=True)
        dataIndex.unsavedEdit = 0
        if pendingChange == 1:
            dataIndex.unsavedEdit = 1
        fldbk.tabWidget.setCurrentIndex(3)
    elif targetID[0] == "D":
        navBar = fldbk.dDataNav
        targetCard = dataIndex.dataDict[targetID]
        cardLoader.loadDataCard(targetCard, navBtn=True)
        fldbk.tabWidget.setCurrentIndex(4)
    elif targetID[0] == "H":
        fldbk.tabWidget.setCurrentIndex(0)

    try:
        cardLoader.resetNavBars(navBar, targetID)
    except UnboundLocalError:
        fldbk.tabWidget.setCurrentIndex(0)
Beispiel #3
0
def fuzzyAgain(fldbk):
    if dataIndex.fuzzyResults != None:
        dataIndex.fuzzyPointer += 1
        if dataIndex.fuzzyPointer > len(dataIndex.fuzzyResults):
            dataIndex.fuzzyPointer = 1
        tCard = dataIndex.fuzzyResults[dataIndex.fuzzyPointer]
        if tCard[0] == 'L':
            cardLoader.loadLexCard(dataIndex.lexDict[tCard])
        elif tCard[0] == 'D':
            cardLoader.loadDataCard(dataIndex.dataDict[tCard])
        elif tCard[0] == 'E':
            cardLoader.loadExCard(dataIndex.exDict[tCard])
def goToLink(fldbk):
    if len(fldbk.eLinksList.currentText()) == 0:
        return
    else:
        link = fldbk.eLinksList.currentText()
    if link[0:2] == "LX":
        linkedCard = dataIndex.root.find('Lex[@LexID="%s"]' % link)
        cardLoader.loadLexCard(linkedCard)
        fldbk.tabWidget.setCurrentIndex(1)
    elif link[0:2] == "DS":
        linkedCard = dataIndex.root.find('Dset[@DsetID="%s"]' % link)
        cardLoader.loadDataCard(linkedCard)
        fldbk.tabWidget.setCurrentIndex(4)
    else:
        return
Beispiel #5
0
def lookUp(fldbk):
    inputBox = QtWidgets.QInputDialog()
    result = inputBox.getText(fldbk, 'Look up … ?',
                              'Type search term in the box.')
    if result[1] == True:
        tTerm = result[0]
    else:
        return
    regex = re.compile('^[LTED][XS]\d')
    if regex.match(tTerm):
        try:
            if tTerm[0] == "L":
                tEntry = dataIndex.lexDict[tTerm]
                cardLoader.loadLexCard(tEntry)
                fldbk.tabWidget.setCurrentIndex(1)
            elif tTerm[0] == "T":
                tEntry = dataIndex.textDict[tTerm]
                cardLoader.loadTextCard(tEntry)
                fldbk.tabWidget.setCurrentIndex(2)
            elif tTerm[0] == "E":
                tEntry = dataIndex.exDict[tTerm]
                cardLoader.loadExCard(tEntry)
                fldbk.tabWidget.setCurrentIndex(3)
            elif tTerm[0] == "D":
                tEntry = dataIndex.dataDict[tTerm]
                cardLoader.loadDataCard(tEntry)
                fldbk.tabWidget.setCurrentIndex(4)
        except (IndexError, KeyError):
            tEntry = None
    else:
        tEntry = None
        for child in dataIndex.root.iter('Lex'):
            if child.findtext('Orth') == tTerm:
                tEntry = child
                break
        if tEntry != None:
            cardLoader.loadLexCard(tEntry)
            fldbk.tabWidget.setCurrentIndex(1)

    if tEntry == None:
        QtWidgets.QApplication.beep()
Beispiel #6
0
def searchXML(fldbk, regExp):
    resultsDict = {}
    matchObject = QtCore.QRegularExpressionMatch()
    if dataIndex.currentCard[0] == "L":
        cardType = "Lex"
        ID = 'LexID'
    elif dataIndex.currentCard[0] == "T":
        return
    elif dataIndex.currentCard[0] == "D":
        cardType = "Dset"
        ID = 'DsetID'
    elif dataIndex.currentCard[0] == "E":
        cardType = "Ex"
        ID = 'ExID'
    else:
        return
    i = 0
    for node in dataIndex.root.iter(cardType):
        for item in node.itertext():
            matchObject = regExp.match(item)
            if matchObject.hasMatch():
                i += 1
                resultsDict[i] = node.get(ID)
    if len(resultsDict) != 0:
        tCard = resultsDict[1]
        if cardType == 'Lex':
            cardLoader.loadLexCard(dataIndex.lexDict[tCard])
        elif cardType == 'Dset':
            cardLoader.loadDataCard(dataIndex.dataDict[tCard])
        elif cardType == 'Ex':
            cardLoader.loadExCard(dataIndex.exDict[tCard])
        return resultsDict
    else:
        notFoundBox = QtWidgets.QMessageBox()
        notFoundBox.setText('Text not found.')
        notFoundBox.exec_()
        return False
Beispiel #7
0
def goPrevDset(fldbk):
    navBar = fldbk.dDataNav
    dct = dataIndex.dataDict
    targetCard = goPrev(navBar,dct)
    cardLoader.loadDataCard(targetCard)
Beispiel #8
0
def firstDsetCard(fldbk):
    navBar = fldbk.dDataNav
    dct = dataIndex.dataDict
    targetCard = firstCard(navBar,dct)
    cardLoader.loadDataCard(targetCard)
Beispiel #9
0
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
Beispiel #10
0
def copyCard(fldbk):
    tDate = setSessionDate()
    dataIndex.unsavedEdit = 1
    if fldbk.tabWidget.currentIndex() == 1:  #lexicon card
        cardType = 'LX'
        newID = idGenerator.generateID(cardType, dataIndex.lexDict)
        ID = 'LexID'
        elemListType = 'Lex[@LexID="%s"]' % dataIndex.currentCard
        dict = dataIndex.lexDict
    elif fldbk.tabWidget.currentIndex() == 2:  #text card
        cardType = 'TX'
        newID = idGenerator.generateID(cardType, dataIndex.lexDict)
        ID = 'TextID'
        elemListType = 'Text[@TextID="%s"]' % dataIndex.currentCard
        dict = dataIndex.textDict
    elif fldbk.tabWidget.currentIndex() == 3:  #example card
        cardType = 'EX'
        newID = idGenerator.generateID(cardType, dataIndex.lexDict)
        ID = 'ExID'
        elemListType = 'Ex[@ExID="%s"]' % dataIndex.currentCard
        dict = dataIndex.exDict
    elif fldbk.tabWidget.currentIndex() == 4:  #dataset card
        cardType = 'DS'
        newID = idGenerator.generateID(cardType, dataIndex.lexDict)
        ID = 'DsetID'
        elemListType = 'Dset[@DsetID="%s"]' % dataIndex.currentCard
        dict = dataIndex.dataDict
    newID = idGenerator.generateID(cardType, dict)
    sourceCard = dict[dataIndex.currentCard]
    newElem = copy.deepcopy(sourceCard)
    newElem.set(ID, newID)
    newElem.set('Date', tDate)
    newElem.set('Update', tDate)
    k = dataIndex.root.find(elemListType)
    i = list(dataIndex.root).index(k) + 1
    dataIndex.root.insert(i, newElem)
    ##delink sounds and media files##
    soundList = newElem.findall('Sound')
    if len(soundList) != 0:
        for sound in soundList:
            newElem.remove(sound)
    if cardType == 'LX':
        dataIndex.lexDict[newID] = newElem
        cardLoader.loadLexCard(newElem)
        navLists.navListBuilderLex(fldbk)
        cardLoader.resetNavBars(fldbk.lLexNav, newID)
        dataIndex.currentCard = newID
        dataIndex.lastLex = newID
        dataIndex.root.set('LastLex', newID)
        fldbk.lSound.Recordings.clear()
        fldbk.lSound.SoundFileMeta.clear()
        ##clear derivations##
        fldbk.lDerivatives.clear()
        drvnList = newElem.findall('Drvn')
        if len(drvnList) != 0:
            for drvn in drvnList:
                newElem.remove(drvn)
        ##clear root##
        root = newElem.find('Root')
        try:
            newElem.remove(root)
            fldbk.lBase.clear()
            fldbk.lBreakLnkBtn.setEnabled(0)
        except TypeError:
            pass
        ##deal with existing homonyms##
        if newElem.attrib.get('Hom') != None:
            syn = newElem.attrib.get('Hom')
            synList = syn.split(', ')
            synList.append(newID)
            try:
                synList.index(sourceCard.attrib.get('LexID'))
            except ValueError:
                synList.append(sourceCard.attrib.get('LexID'))
            update.manageHomonyms(synList)
    elif cardType == 'TX':
        dataIndex.textDict[newID] = newElem
        cardLoader.loadTextCard(newElem)
        navLists.navListBuilderText(fldbk)
        cardLoader.resetNavBars(fldbk.tTextNav, newID)
        dataIndex.currentCard = newID
        dataIndex.lastText = newID
        dataIndex.root.set('LastText', newID)
        fldbk.tRecordings.clear()
        fldbk.tSoundFileMeta.clear()
    elif cardType == 'EX':
        dataIndex.exDict[newID] = newElem
        cardLoader.loadExCard(newElem)
        dataIndex.currentCard = newID
        dataIndex.lastText = newID
        dataIndex.root.set('lastEx', newID)
        if newElem.attrib['Links'] != None:
            del newElem.attrib['Links']
            fldbk.eLinksList.clear()
        fldbk.eSound.Recordings.clear()
        fldbk.eSound.SoundFileMeta.clear()
    elif cardType == 'DS':
        dataIndex.dataDict[newID] = newElem
        cardLoader.loadDataCard(newElem)
        navLists.navListBuilderData(fldbk)
        cardLoader.resetNavBars(fldbk.dDataNav, newID)
        dataIndex.currentCard = newID
        dataIndex.lastText = newID
        dataIndex.root.set('LastDset', newID)
        fldbk.dSound.Recordings.clear()
        fldbk.dSound.SoundFileMeta.clear()