Example #1
0
def eSplitEg(fldbk):
    '''splits example between two cards'''
    oldID = dataIndex.currentCard
    tSplitter = LineSplitter.LineSplitter(fldbk)
    tSplitter.fillForm(oldID)
    tSplitter.exec_()
    if tSplitter.result() == 0:
        return
    else:
        idList = tSplitter.newData(oldID)
    oldRoot = dataIndex.exDict[idList[0]]
    try:
        source = dataIndex.textDict[oldRoot.get('SourceText')]
    except KeyError:
        source = None
    ##update XML if this is from a text
    if source != None:
        lineList = source.findall('Ln')
        i = 2
        for line in lineList:
            if line.attrib.get('LnRef') == oldID:
                newNode = etree.Element('Ln', {'LnRef': idList[1]})
                source.insert(i, newNode)
            else:
                i += 1
        ##update Text card if that text is open
        if oldRoot.get('SourceText'
                       ) == dataIndex.lastText and fldbk.tText.findChildren(
                           textTable) != None:
            cardLoader.loadTextCard(source)
    cardLoader.loadExCard(oldRoot)
    dataIndex.unsavedEdit = 1
Example #2
0
def eLocateEg(fldbk):
    '''goes to example in context (text or, eventually, dataset)'''
    #TODO: link up with datasets
    egNode = dataIndex.exDict[dataIndex.currentCard]
    lineLabel = fldbk.eLineNumber.toPlainText()
    lineNo = int(lineLabel[5:])
    text = egNode.attrib.get('SourceText')
    if text == None:
        return
    try:
        if text == dataIndex.currentText.attrib.get('TextID'):
            fldbk.tabWidget.setCurrentIndex(2)
        else:
            cardLoader.loadTextCard(dataIndex.textDict[text])
            fldbk.tabWidget.setCurrentIndex(2)
    except AttributeError:
        cardLoader.loadTextCard(dataIndex.textDict[text])
        fldbk.tabWidget.setCurrentIndex(2)
    textWidget = fldbk.textLayout.itemAt(lineNo - 1)
    textTable = textWidget.widget()
    dataIndex.currentTextTable = textTable
    textTable.setStyleSheet(
        "QTableWidget QHeaderView::section {border-bottom: 0px;"
        "border-left: 0px; border-top: 0px; border-right: 0px;"
        "padding: 5px; outline: 0px; background: #E6E6E6;}")
    fldbk.tFullText.ensureWidgetVisible(textTable)
    fldbk.tFullText.horizontalScrollBar().setValue(0)
Example #3
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)
Example #4
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()
Example #5
0
def goPrevTxt(fldbk):
    navBar = fldbk.tTextNav
    dct = dataIndex.textDict
    targetCard = goPrev(navBar,dct)
    cardLoader.loadTextCard(targetCard)
Example #6
0
def firstTxtCard(fldbk):
    navBar = fldbk.tTextNav
    dct = dataIndex.textDict
    targetCard = firstCard(navBar,dct)
    cardLoader.loadTextCard(targetCard)
Example #7
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()