Пример #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()
Пример #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)
Пример #3
0
 def linkSelected(self):
     sender = self.sender()
     link = sender.data()
     fldbk = dataIndex.fldbk
     if 'M' in link:
         i = fldbk.lSound.Recordings.findData(link, 35)
         fldbk.lSound.Recordings.setCurrentIndex(i)
         fldbk.lSound.playSound()
     else:
         lexRoot = dataIndex.lexDict[link]
         cardLoader.loadLexCard(lexRoot)        
Пример #4
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])
Пример #5
0
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
Пример #6
0
def restoreLexCard(textRoot=None):
    fldbk = dataIndex.fldbk
    if textRoot == False:
        textRoot = dataIndex.lexDict[dataIndex.currentCard]
    cardLoader.loadLexCard(textRoot)
    fldbk.lSearchHeader.setVisible(0)
    fldbk.lL1Search.setVisible(0)
    fldbk.lL2Search.setVisible(0)
    fldbk.lSearchControlBar.setVisible(0)
    fldbk.lSearchUpdate.setVisible(0)
    fldbk.searchParam.setVisible(0)
    fldbk.sDoneBtn.setVisible(0)
    fldbk.instructionBox.setVisible(0)
    fldbk.searchParam.deleteLater()
    fldbk.lL1Search.deleteLater()
    fldbk.lL2Search.deleteLater()
    fldbk.lSearchHeader.deleteLater()
    fldbk.lSearchControlBar.deleteLater()
    fldbk.lSearchUpdate.deleteLater()
    fldbk.sDoneBtn.deleteLater()
    fldbk.instructionBox.deleteLater()
    fldbk.lDerivationBox.setVisible(1)
    fldbk.lLexNav.setVisible(1)
    fldbk.lHeader.setVisible(1)
    fldbk.lL1Definition.setVisible(1)
    fldbk.lL2Definition.setVisible(1)
    fldbk.lSoundBox.setVisible(1)
    fldbk.lControlBar.setVisible(1)
    fldbk.lUpdated.setVisible(1)
    fldbk.lAutoBtn.setVisible(1)
    try:
        if dataIndex.autoTransform == 1:
            fldbk.lAutoBtn.setChecked(1)
        else:
            fldbk.lAutoBtn.setChecked(0)
        dataIndex.autoTransform = None
    except AttributeError:
        pass
    fldbk.lDoneBtn.setVisible(1)
    fldbk.lNewBtn.setVisible(1)
    fldbk.lClipBtn.setVisible(1)
    dataIndex.updateEnabled = 'on'
    dataIndex.activeSearch = None
Пример #7
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()
Пример #8
0
def eAdd2Lex(fldbk):
    '''adds example to a lexical entry'''
    eManager = LinkToLexicon.EntryManager(fldbk)
    eManager.listEntries()
    if eManager.exec_():
        data = eManager.setData()
        node = dataIndex.lexDict[data[0]]
        definition = node.find('Def[@Index="%s"]' % str(data[1]))
        etree.SubElement(definition, 'Ln', {'LnRef': dataIndex.currentCard})
        fldbk.eLinksList.insertItem(-1, data[0])
        fldbk.eLinksList.setCurrentIndex(fldbk.eLinksList.findText(data[0]))
        example = dataIndex.root.find('Ex[@ExID="%s"]' % dataIndex.currentCard)
        if example.attrib.get('Links'):
            linksList = example.attrib.get('Links')
            linksList = linksList + ", " + data[0]
        else:
            linksList = data[0]
        example.set("Links", linksList)
        #        print(etree.tostring(definition, encoding='unicode'))
        cardLoader.loadLexCard(node)
        fldbk.tabWidget.setCurrentIndex(1)
        dataIndex.unsavedEdit = 1
Пример #9
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
Пример #10
0
    def updateXML(self):
        '''updates XML and grammar field on lex card'''
        self.grammar.sortItems(1, 0)
        self.grammar.sortItems(0, 0)
        #        fieldContents = ''
        '''build a new set of <Grm>, <C2>, and <Cf> nodes'''
        child = dataIndex.lexDict[dataIndex.currentCard]
        '''remove old elments'''
        killList = []
        for node in child.iter('Grm'):
            killList.append(node)
        for item in killList:
            child.remove(item)
        killList = []
        for node in child.iter('C2'):
            killList.append(node)
        for item in killList:
            child.remove(item)
        killList = []
        for node in child.iter('Cf'):
            killList.append(node)
        for item in killList:
            child.remove(item)
        '''build the new nodes'''
        if child.find('IPA') != None:
            k = child.find('IPA')
            index = list(child).index(k) + 1
        elif child.find('POS') != None:
            k = child.find('POS')
            index = list(child).index(k) + 1
        else:
            k = child.find('Orth')
            index = list(child).index(k) + 1
        refList = []
        altList = []
        '''add grm nodes'''
        for i in range(0, self.grammar.rowCount()):
            if self.grammar.item(i, 0) == None:
                break
            if not self.grammar.item(i, 1):
                break
            if self.grammar.item(i, 1).text() == 'new item':
                break
            newGrm = etree.Element('Grm')
            newGrm.text = self.grammar.item(i, 1).text()
            '''get a prefix/grammatical category'''
            if len(self.grammar.item(i, 0).text()) != 0:
                if len(self.grammar.item(i, 1).text()) == 0:
                    self.grammar.item(i, 1).setText(' ')
                prefix = self.grammar.item(i, 0).text()
                if prefix[-1] == ".":
                    prefix = prefix[:-1]
                newGrm.set("Prefix", prefix)
#                fieldContents += "<i>" + prefix + ".</i> "
            if self.grammar.item(i, 0).data(35) != None:
                newGrm.set("MediaRef", self.grammar.item(i, 0).data(35))
                refList.append(self.grammar.item(i, 0).data(35))
                altList.append(self.grammar.item(i, 1).text())
            '''get a dialect designation'''
            try:
                if len(self.grammar.item(i, 2).text()) != 0:
                    dialect = self.grammar.item(i, 2).text()
                    newGrm.set("Variant", dialect)
            except AttributeError:
                pass
#                fieldContents += " (" + dialect + ")"
            child.insert(index, newGrm)
            index += 1
        '''add C2 nodes'''
        for i in range(0, self.C2.rowCount()):
            if self.C2.item(i, 0) == None:
                break
            if not self.C2.item(i, 0):
                break
            if self.C2.item(i, 0).text() == 'new item':
                break
            if len(self.C2.item(i, 0).text()) == 0:
                break
            try:
                if len(self.C2.item(i, 1).text()) != 0:
                    dialect = self.C2.item(i, 1).text()
                else:
                    dialect = None
            except AttributeError:
                dialect = None
            newC2 = etree.Element('C2')
            newC2.text = self.C2.item(i, 0).text()
            if self.C2.item(i, 0).data(35) != None:
                newC2.set("MediaRef", self.C2.item(i, 0).data(35))
                refList.append(self.C2.item(i, 0).data(35))
                altList.append(self.C2.item(i, 0).text())
            if dialect != None:
                newC2.set("Variant", dialect)
            child.insert(index, newC2)
            index += 1
        '''add Cf Nodes'''
        if len(self.cf.toPlainText()) != 0:
            CfInfo = self.cf.toPlainText()
            CfElems = CfInfo.split(', ')
            for item in CfElems:
                newCross = etree.Element('Cf')
                newCross.text = item
                crossRef = None
                for entry in dataIndex.root.findall('Lex'):
                    lexeme = entry.find('Orth').text
                    if lexeme == item and entry.attrib.get('Hom') != None:
                        #TODO: fix so you see definitions with alternatives
                        synList = entry.attrib.get('Hom').split(", ")
                        newCf = CrossRefManager.Dialog(self)
                        newCf.setRefs(synList)
                        if newCf.exec_():
                            crossRef = newCf.getRef()
                        else:
                            crossRef = None
                        break
                    elif lexeme == item:
                        crossRef = entry.attrib.get('LexID')
                        break
                if crossRef != None:
                    newCross.set("CrossRef", crossRef)
                    refList.append(crossRef)
                    altList.append(item)
                child.insert(index, newCross)
                index += 1
        cardLoader.loadLexCard(child)
        if len(refList) != 0:
            field = 'lGrammar'
            contextMenus.buildContextMenu(self.fldbk, field, refList, altList)
        else:
            try:
                del (self.fldbk.lGrammar.crossrefMenu)
            except AttributeError:
                pass
Пример #11
0
def goPrevLx(fldbk):
    navBar = fldbk.lLexNav
    dct = dataIndex.lexDict
    targetCard = goPrev(navBar,dct)
    cardLoader.loadLexCard(targetCard)
Пример #12
0
def firstLxCard(fldbk):
    navBar = fldbk.lLexNav
    dct = dataIndex.lexDict
    targetCard = firstCard(navBar,dct)
    cardLoader.loadLexCard(targetCard)
Пример #13
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()