コード例 #1
0
    def fillTable(self, child):
        '''updates table with list of subentries'''
        subentry = child.findall('Def')
        howMany = len(subentry)
        self.table.setRowCount(howMany)
        for i in range(0, len(subentry)):
            entry = ''
            dialect = ''
            variant = ''
            alternative = ''
            POS = subentry[i].findtext('POS')
            if POS:
                entry = "(" + POS + ") "
            dNode = subentry[i].find('Dia')
            if dNode != None:
                dialect = dNode.attrib.get('Dialect')
                entry = entry + " <i>" + dialect + "</i> "
                aNodeList = dNode.findall('Alternative')
                if len(aNodeList) != 0:
                    j = 0
                    for aNode in aNodeList:
                        variant = aNode.attrib.get('Variant')
                        alternative = aNode.text
                        if j == 0 and len(aNodeList) - 1 == 0:
                            entry = entry + "[" + variant + " " + alternative + "] "
                        elif j == 0:
                            entry = entry + "[" + variant + " " + alternative
                        elif j == len(aNodeList) - 1:
                            entry = entry + "; " + variant + " " + alternative + "] "
                        else:
                            entry = entry + "; " + variant + " " + alternative
                        j += 1

            Reg = subentry[i].findtext('Reg')
            if Reg:
                entry = entry + "<i>" + Reg + "</i> "
            entry = entry + subentry[i].findtext('L1')
            entry = formattingHandlers.XMLtoRTF(entry)

            tableCell = QtWidgets.QTableWidgetItem(1002)
            tableCell.setData(35, subentry[i])
            tableCell.setText(entry)
            tableCell.setFlags(QtCore.Qt.ItemIsEnabled)
            self.table.setItem(i, 0, tableCell)
            self.table.resizeRowToContents(i)
コード例 #2
0
 def listEntries(self):
     proxyModel = self.fldbk.lLexNav.model()
     for i in range(0, proxyModel.rowCount()):
         derID = proxyModel.index(i, 0).data(32)
         child = dataIndex.lexDict[derID]
         lexeme = '<b>' + child.findtext('Orth') + '</b>'
         POS = child.findtext('POS')
         L1List = child.findall('Def/L1')
         item = QtWidgets.QTreeWidgetItem()
         item.setData(0,32,derID)
         for i in range(0,len(L1List)):
             L1 = L1List[i].text
             L1 = formattingHandlers.XMLtoRTF(L1)
             if len(L1List) != 1:
                 indexNo = str(i+1) + ") "
             else:
                 indexNo= None
             if indexNo == None:
                 try:
                     txt1 = lexeme + " (" + POS + ") " + L1
                 except TypeError:
                     txt1 = lexeme + " " + L1                           
                 item.setText(0,txt1)
                 item.setData(0,33,1)
             else:
                 if i ==0:
                     try:
                         txt1 = lexeme + " (" + POS + ") "
                     except TypeError:
                         txt1 = lexeme + " "                           
                     item.setText(0,txt1)
                     item.setData(0,33,i+1)
                 txt = indexNo + L1
                 defItem = QtWidgets.QTreeWidgetItem(item)
                 defItem.setText(0,txt)
                 defItem.setData(0,32,derID)
                 defItem.setData(0,33,i+1)
         self.lexList.addTopLevelItem(item)
         item.setExpanded(1)
     self.setWindowTitle(QtWidgets.QApplication.translate("EntryManager", "Select lexical entry", None))
コード例 #3
0
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
コード例 #4
0
def loadLexCard(lexRoot, navBtn=False):
    fldbk = dataIndex.fldbk
    targetCard = lexRoot.attrib.get('LexID')
    dataIndex.currentCard = targetCard
    dataIndex.lastLex = lexRoot.attrib.get('LexID')   
    dataIndex.root.set('LastLex',dataIndex.lastLex)
    if navBtn == False:
        if len(fldbk.lNavBar.stack) == 0:
            fldbk.lNavBar.stack.append(targetCard)
            fldbk.lNavBar.index = fldbk.lNavBar.index + 1
        elif fldbk.lNavBar.stack[-1] != targetCard:
            fldbk.lNavBar.stack.append(targetCard)
            fldbk.lNavBar.index = fldbk.lNavBar.index + 1
    try:
          del(fldbk.lGrammar.crossrefMenu)
    except AttributeError:
        pass
          
    try:
        del(fldbk.lDialect.dialectMenu)
    except AttributeError:
        pass
    
    try:
        del(fldbk.lL1Definition.L1DefinitionMenu)
    except AttributeError:
        pass
    
    try:
        del(fldbk.lL2Definition.L2DefinitionMenu)
    except AttributeError:
        pass
    
    try:
        if lexRoot.attrib.get('Done') == '1':
            fldbk.lDoneBtn.setChecked(1)
        else:
            fldbk.lDoneBtn.setChecked(0)
    except (KeyError, AttributeError):
        fldbk.lDoneBtn.setChecked(0)
    
    fldbk.lOrthography.clear()
    entry = lexRoot.findtext('Orth')
    if entry:
      fldbk.lOrthography.setText(entry)

    fldbk.lPOS.clear()
    entry = lexRoot.findtext('POS')
    if entry:
      fldbk.lPOS.setPlainText(entry)

    fldbk.lRegister.clear()
    entry = lexRoot.findtext('Reg')
    if entry:
      fldbk.lRegister.setPlainText(entry)

    fldbk.lIPA.clear()
    entry = lexRoot.findtext('IPA')
    if entry:
      if "̰" in entry:
        entry = entry.replace("(̰)", "")
        lexRoot.find('IPA').text = entry
      fldbk.lIPA.setText(entry)

    fldbk.lLiteral.clear()
    entry = lexRoot.findtext('Lit')
    if entry:
        newContent,  entry = formattingHandlers.smallCapsConverter(entry)
        fldbk.lLiteral.setText(entry)

    '''Grammar'''
    fldbk.lGrammar.clear()
    subentry = lexRoot.findall('Grm')
    grmList = ''
    entryList = []
    refList = []
    mediaRefs = []
    if len(subentry) != 0:
      for i in range(0,len(subentry)):
          if subentry[i].attrib.get('Prefix'):
              entry = "<i>" + subentry[i].attrib.get('Prefix') + ".</i> " + subentry[i].text
          else:
              entry = subentry[i].text
          if subentry[i].attrib.get('Variant'):
              entry += ' (' + subentry[i].attrib.get('Variant') + ')'
          if entry == None:
                 continue
        #TODO: the above is a hack in case we have a <Grm />, need to delete instead
          entry += "<br/>"
          grmList += entry
          if subentry[i].attrib.get('MediaRef'):
            entryList.append(subentry[i].text)
            refList.append(subentry[i].attrib.get('MediaRef'))
            mediaRefs.append(subentry[i].attrib.get('MediaRef'))
      fldbk.lGrammar.insertHtml(grmList)
        
    subentry = lexRoot.findall('C2')
    if subentry:
      c2List = '<i>also</i> '
      for i in range(0,len(subentry)):
          entry = subentry[i].text
          if subentry[i].attrib.get('Variant'):
              entry += " (" + subentry[i].attrib.get('Variant') + ")"
          if subentry[i].attrib.get('MediaRef'):
            entryList.append(entry)
            refList.append(subentry[i].attrib.get('MediaRef'))
            mediaRefs.append(subentry[i].attrib.get('MediaRef'))
          c2List = c2List + entry
          if i != len(subentry)-1:
              c2List = c2List + ', '
      if len(fldbk.lGrammar.toPlainText()) != 0:
          c2List = "<br />" + c2List
      fldbk.lGrammar.insertHtml(c2List)
      
    subentry = lexRoot.findall('Cf')
    if subentry:
      cfList = '<i>cf.</i> '
      for i in range(0,len(subentry)):
          entry = subentry[i].text
          if subentry[i].attrib.get('CrossRef'):
             entryList.append(entry)
             refList.append(subentry[i].attrib.get('CrossRef'))
             cfList = cfList + entry
          else:
              cfList = cfList + '<span style="color:blue">' + entry + '</span>'               
          if i != len(subentry)-1:
              cfList = cfList + ', '
      if len(fldbk.lGrammar.toPlainText()) != 0:
          cfList = "<br />" + cfList
      fldbk.lGrammar.insertHtml(cfList)
    if refList:
        field = 'lGrammar'
        contextMenus.buildContextMenu(field,refList,entryList)

    '''Indices'''
    fldbk.lPrimaryIndex.clear()
    entry = lexRoot.attrib.get('L1Index')
    if entry:
        fldbk.lPrimaryIndex.setPlainText(entry)

    fldbk.lSecondaryIndex.clear()
    entry = lexRoot.attrib.get('L2Index')
    if entry:
        fldbk.lSecondaryIndex.setPlainText(entry)

    '''Comments'''
    fldbk.lNotes.clear()
    entry = lexRoot.findtext('Comments')
    if entry:
        entry = formattingHandlers.XMLtoRTF(entry)
        fldbk.lNotes.setHtml(entry)
    else:
        fldbk.lNotes.setFontItalic(0)
        fldbk.lNotes.setFontUnderline(0)
        fldbk.lNotes.setFontWeight(50)
    
    fldbk.lKeywordIndex.clear()
    entry = lexRoot.attrib.get('Kywd')
    if entry:
        fldbk.lKeywordIndex.setPlainText(entry)

    '''Dialect'''
    fldbk.lDialect.clear()
    ##dia = ''
    entry = ''
    subentry = lexRoot.find('Dia')
    if subentry != None:
        dialect = subentry.attrib.get('Dialect')
        entry = entry + " <i>" + dialect + "</i> "
        aNodeList = subentry.findall('Alternative')
        if len(aNodeList) != 0:
            crossRefList = []
            altList = []
            j = 0
            for item in aNodeList:
                alternative = item.text
                variant = item.attrib.get('Variant')
                crossref = item.attrib.get('CrossRef')
                if j == 0 and j == len(aNodeList) - 1:
                    entry = entry + " (" + variant + " " + alternative + ")"
                elif j == 0:
                    entry = entry + " (" + variant + " " + alternative
                elif j == len(aNodeList) - 1:
                    entry = entry + "; " + variant + " " + alternative + ")"
                else:
                    entry = entry + "; " + variant + " " + alternative
                j += 1
                if crossref:
                    crossRefList.append(crossref)
                    altList.append(alternative)
                if len(crossRefList) != 0:
                    field = 'lDialect'
                    contextMenus.buildContextMenu(fldbk,field,crossRefList,altList)
        fldbk.lDialect.insertHtml(entry)
           
    fldbk.lBrrw.clear()
    subentry = lexRoot.find('Brrw')
    if subentry != None:
        source = subentry.attrib.get('Source')
        cognate = lexRoot.findtext('Brrw')
        cognate = '“' + cognate + '”'
        borrowing = source + ' ' + cognate
        fldbk.lBrrw.setPlainText(borrowing)

    '''Metadata'''
    fldbk.lSource.clear()
    fldbk.lResearcher.clear()
    fldbk.lDate.clear()
    fldbk.lUpdated.clear()
    fldbk.lConfirmed.clear()
    entry = lexRoot.attrib.get('Spkr')
    if entry:
      fldbk.lSource.setPlainText(entry)
 
    entry = lexRoot.attrib.get('Rschr')
    if entry:
      fldbk.lResearcher.setPlainText(entry)
      
    entry = lexRoot.attrib.get('Date')
    if entry:
      fldbk.lDate.setPlainText(entry)

    entry = lexRoot.attrib.get('Update')
    if entry:
      fldbk.lUpdated.setPlainText(entry)

    entry = lexRoot.attrib.get('Confirmed')
    if entry:
      fldbk.lConfirmed.setPlainText(entry)

    '''Definitions and examples'''
    loadDefinitions(fldbk, lexRoot)
    
    '''Derivations'''
    fldbk.lDerivatives.clear()
    fldbk.lRemoveDerBtn.setEnabled(0)
    derivatives = lexRoot.findall('Drvn')
    parent = None
    if derivatives:
        fldbk.lDerivatives.setAlternatingRowColors(True)
        for i in range(0,len(derivatives)):
            text = ''
            derID = derivatives[i].attrib.get('LexIDREF')
            der = dataIndex.lexDict[derID]
            word = der.findtext('Orth')
            POS = der.findtext('POS')
            L1 = der.findtext('Def/L1')
            if POS:
                text = word + " (" + POS + ") " + L1
            item = QtWidgets.QListWidgetItem(parent, QtWidgets.QListWidgetItem.UserType)
            item.setData(32, derID)
            item.setText(text)
            fldbk.lDerivatives.addItem(item)
        fldbk.lRemoveDerBtn.setEnabled(1)
        try:
            fldbk.lDerivatives.sortItems(QtCore.Qt.AscendingOrder)
        except AttributeError:
            pass

    '''Bases'''
    fldbk.lBase.clear()
    fldbk.lBreakLnkBtn.setEnabled(0)
    base = lexRoot.find('Root')
    if base != None:
        baseID = base.attrib.get('LexIDREF')
        baseElement = dataIndex.lexDict[baseID]
        baseName = baseElement.findtext('Orth')
        item = QtWidgets.QListWidgetItem(parent, QtWidgets.QListWidgetItem.UserType)
        item.setData(32, baseID)
        item.setText(baseName)
        fldbk.lBase.addItem(item)
        fldbk.lBreakLnkBtn.setEnabled(1)

    '''Recordings'''
    fldbk.lSound.loadMedia(lexRoot, mediaRefs)
    resetNavBars(fldbk.lLexNav, dataIndex.currentCard)
コード例 #5
0
def loadDataCard(dataRoot, navBtn=False):
    fldbk = dataIndex.fldbk
    targetCard = dataRoot.attrib.get('DsetID')
    dataIndex.currentCard = targetCard
    dataIndex.lastDset = dataRoot.attrib.get('DsetID')   
    dataIndex.root.set('LastDset',dataIndex.lastDset)
    if navBtn == False:
        if len(fldbk.dNavBar.stack) == 0:
            fldbk.dNavBar.stack.append(targetCard)
            fldbk.dNavBar.index = fldbk.dNavBar.index + 1
        elif fldbk.dNavBar.stack[-1] != targetCard:
            fldbk.dNavBar.stack.append(targetCard)       
            fldbk.dNavBar.index = fldbk.dNavBar.index + 1
    fldbk.dSource.clear()
    entry = dataRoot.attrib.get('Spkr')
    if entry:
      fldbk.dSource.setPlainText(entry)
      
    fldbk.dResearcher.clear()
    entry = dataRoot.attrib.get('Rschr')
    if entry:
      fldbk.dResearcher.setPlainText(entry)
      
    fldbk.dDate.clear()
    entry = dataRoot.attrib.get('Date')
    if entry:
      fldbk.dDate.setPlainText(entry)
      
    fldbk.dUpdated.clear()
    entry = dataRoot.attrib.get('Update')
    if entry:
      fldbk.dUpdated.setPlainText(entry)
      
    fldbk.dKeywords.clear()
    entry = dataRoot.attrib.get('Kywd')
    if entry:
      fldbk.dKeywords.setPlainText(entry)
      
    fldbk.dNotes.clear()
    entry = dataRoot.findtext('Comments')
    if entry:
        entry = formattingHandlers.XMLtoRTF(entry)
        fldbk.dNotes.setHtml(entry)
    else:
        fldbk.dNotes.setFontItalic(0)
        fldbk.dNotes.setFontUnderline(0)
        fldbk.dNotes.setFontWeight(50)
        
    fldbk.dTitle.clear()
    entry = dataRoot.findtext('Title')
    if entry:
        entry = formattingHandlers.XMLtoRTF(entry)
        fldbk.dTitle.setHtml(entry)
      
    fldbk.dData.clear()
    fldbk.dData.setAcceptRichText(1)
    fldbk.dData.setFontItalic(0)
    fldbk.dData.setFontUnderline(0)
    fldbk.dData.setFontWeight(50)
#    html = fldbk.dData.toHtml()
    entry = dataRoot.findtext('Data')
    if entry:
        fldbk.dData.setPlainText(entry)
#        html = fldbk.dData.toHtml()
#        newHtml = formattingHandlers.XMLtoRTF(html)
#        fldbk.dData.setHtml(newHtml)
      
    '''Recordings'''
    fldbk.dSound.loadMedia(dataRoot)
    resetNavBars(fldbk.dDataNav, dataIndex.currentCard)
コード例 #6
0
def loadDefinitions(fldbk, lexRoot):
    fldbk.lL1Definition.clear()
    fldbk.lL1Definition.verticalScrollBar().setValue(0)
    fldbk.lL1Definition.horizontalScrollBar().setValue(0)
    fldbk.lL2Definition.clear()
    fldbk.lL2Definition.verticalScrollBar().setValue(0)
    fldbk.lL2Definition.horizontalScrollBar().setValue(0)
    subentry = lexRoot.findall('Def')
    L1DefList = []
    L2DefList = []
    for i in range(0,len(subentry)):
        #L1
        entry = ''
        dialect = ''
        variant = ''
        alternative = ''
        POS = subentry[i].findtext('POS')
        index = subentry[i].attrib.get('Index')
        try:
            if subentry[i].attrib.get('L1Index') != None:
                L1Index = subentry[i].attrib.get('L1Index') #check to see if there are index words for the subentry
                if len(fldbk.lPrimaryIndex.toPlainText()) == 0: 
                    #if there are no indices from other subentries in the field on the card
                    L1Index += '(' + index + ')'
                    fldbk.lPrimaryIndex.setPlainText(L1Index)
                else:
                    #otherwise add new indices to old with semi-colons as separators
                    newIndex = fldbk.lPrimaryIndex.toPlainText().strip() + '; ' + L1Index + '(' + index + ')'
                    fldbk.lPrimaryIndex.setPlainText(newIndex)
        except AttributeError:
            pass
        try:
            if subentry[i].attrib.get('L2Index') != None:
                L2Index = subentry[i].attrib.get('L2Index') #same as above for L1Index
                if len(fldbk.lSecondaryIndex.toPlainText()) == 0:
                    L2Index += '(' + index + ')'
                    fldbk.lSecondaryIndex.setPlainText(L2Index)
                else:
                    newIndex = fldbk.lSecondaryIndex.toPlainText().strip() + '; ' + L2Index + '(' + index + ')'
                    fldbk.lSecondaryIndex.setPlainText(newIndex)
        except AttributeError:
            pass
        if POS:
            entry = "(" + POS + ") "
        Reg = subentry[i].findtext('Reg')
        dNode = subentry[i].find('Dia')
        if dNode != None:
            dialect = dNode.attrib.get('Dialect')
            entry = entry + " <i>" + dialect + "</i> "
            aNodeList = dNode.findall('Alternative')
            if len(aNodeList) != 0:
                crossRefList = []
                altList = []
                j = 0
                for item in aNodeList:
                    variant = item.attrib.get('Variant')
                    crossref = item.attrib.get('CrossRef')
                    alternative = item.text
                    if j == 0 and j == len(aNodeList) - 1:
                        entry = entry + "[" + variant + " " + alternative + "] "
                    elif j == 0:
                        entry = entry + "[" + variant + " " + alternative
                    elif j == len(aNodeList) - 1:
                        entry = entry + "; " + variant + " " + alternative + "] "
                    else:
                        entry = entry + "; " + variant + " " + alternative
                    if crossref:
                        crossRefList.append(crossref)
                        altList.append(alternative)
                    if len(crossRefList) != 0:
                        field = 'lL1Definition'
                        contextMenus.buildContextMenu(field,crossRefList,altList)
                    j += 1
                  
        if Reg:
            entry = entry + "<i>" + Reg + "</i> "
        entry2 = entry
        entry = entry + subentry[i].findtext('L1')
        try:
            entry = entry + ' [' + subentry[i].findtext('Cxt').strip() + ']'
        except AttributeError:
            pass
        entry = formattingHandlers.XMLtoRTF(entry)
        exampleList = []
        exampleList2 = []
        examples = subentry[i].findall('Ln')
        if examples:
            for j in range(0,len(examples)):
                egID = examples[j].attrib.get('LnRef')
                egElement = dataIndex.exDict[egID]
                eg = '<i>' + egElement.findtext('Line') + '</i>'
                try:
                    if len(egElement.findtext('L1Gloss')) != 0:
                        eg = eg + " ‘" + egElement.findtext('L1Gloss') + "’ (" 
                except TypeError:
                    eg = eg + " ‘" + egElement.findtext('L2Gloss') + "’ ("
                eg = eg + egElement.attrib.get('Spkr') + ")"
                eg = re.sub('{i}','',eg)
                eg = re.sub('{/i}','',eg)
                eg += "@" + egID
                exampleList.append(eg)

                eg2 = '<i>' + egElement.findtext('Line') + '</i>'
                try: 
                    if len(egElement.findtext('L2Gloss')) != 0:
                        eg2 = eg2 + " ‘" + egElement.findtext('L2Gloss') + "’ (" 
                except TypeError:
                    eg2 = eg2 + " ‘" + egElement.findtext('L1Gloss') + "’ ("
                eg2 = eg2 + egElement.attrib.get('Spkr') + ")"
                eg2 = re.sub('{i}','',eg2)
                eg2 = re.sub('{/i}','',eg2)
                eg2 += "@" + egID
                exampleList2.append(eg2)

        L1DefList.append([index,entry,exampleList])

        '''L2'''
        try:
            entry2 = entry2 + subentry[i].findtext('L2')
            entry2 = formattingHandlers.XMLtoRTF(entry2)
            L2DefList.append([index,entry2,exampleList2])
        except TypeError:
            pass
          
    if len(subentry) == 1:
        i = 0
        cWidth = 681
        fldbk.lL1Definition.setColumnCount(1)
        fldbk.lL2Definition.setColumnCount(1)
        fldbk.lL1Definition.setColumnWidth(0,cWidth)
        fldbk.lL2Definition.setColumnWidth(0,cWidth)
    else:
        i = 1
        cWidth = 645
        fldbk.lL1Definition.setColumnCount(2)
        fldbk.lL1Definition.setColumnWidth(0,25)
        fldbk.lL1Definition.setColumnWidth(1,cWidth)
        fldbk.lL2Definition.setColumnCount(2)
        fldbk.lL2Definition.setColumnWidth(0,25)
        fldbk.lL2Definition.setColumnWidth(1,cWidth)

#    L1DefList = sorted(L1DefList, key = lambda x: int(x[0][0]))
#    L2DefList = sorted(L2DefList, key = lambda x: int(x[0][0]))
    j = 0
    for item in L1DefList:
        fldbk.lL1Definition.insertRow(j)
        if i == 1:
            indexTag = item[0] + ")"
            tableCell = QtWidgets.QTableWidgetItem()
            tableCell.setText(indexTag)
            tableCell.setFlags(QtCore.Qt.ItemIsEnabled)
            fldbk.lL1Definition.setItem(j,0,tableCell)
        tableCell = QtWidgets.QTableWidgetItem()
        tableCell.setFlags(QtCore.Qt.ItemIsEnabled)
        tableCell.setTextAlignment(QtCore.Qt.TextWordWrap)
        text = breakLines(item[1], 100)
        tableCell.setText(text)
        tableCell.setSizeHint(QtCore.QSize(cWidth,16))
        fldbk.lL1Definition.setItem(j,i,tableCell)
        if len(item[2]) !=0:
            for eg in item[2]:
                j += 1
                fldbk.lL1Definition.insertRow(j)
                tableCell = QtWidgets.QTableWidgetItem()
                egIndex = eg.split("@")
                text = breakLines(egIndex[0], 120,'&nbsp;&nbsp;&nbsp;')
                tableCell.setText(text)
                tableCell.setData(35,egIndex[1])
                tableCell.setTextAlignment(QtCore.Qt.TextWordWrap)
                tableCell.setFlags(QtCore.Qt.ItemIsEnabled)
                fldbk.lL1Definition.setItem(j,i,tableCell)
        j += 1
    fldbk.lL1Definition.resizeRowsToContents()
    j = 0
    for item in L2DefList:
        fldbk.lL2Definition.insertRow(j)
        if i == 1:
            indexTag = item[0] + ")"
            tableCell = QtWidgets.QTableWidgetItem()
            tableCell.setText(indexTag)
            tableCell.setFlags(QtCore.Qt.ItemIsEnabled)
            fldbk.lL2Definition.setItem(j,0,tableCell)
        tableCell = QtWidgets.QTableWidgetItem()
        text = breakLines(item[1], 100)
        tableCell.setText(text)
        tableCell.setFlags(QtCore.Qt.ItemIsEnabled)
        tableCell.setTextAlignment(QtCore.Qt.TextWordWrap)
        fldbk.lL2Definition.setItem(j,i,tableCell)
        if len(item[2]) !=0:
            for eg in item[2]:
                j += 1
                fldbk.lL2Definition.insertRow(j)
                tableCell = QtWidgets.QTableWidgetItem()
                egIndex = eg.split("@")
                text = breakLines(egIndex[0], 120,'&nbsp;&nbsp;&nbsp;')
                tableCell.setText(text)
                tableCell.setData(35,egIndex[1])
                tableCell.setFlags(QtCore.Qt.ItemIsEnabled)
                tableCell.setTextAlignment(QtCore.Qt.TextWordWrap)
                fldbk.lL2Definition.setItem(j,i,tableCell)
        j += 1
    fldbk.lL2Definition.resizeRowsToContents()
コード例 #7
0
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)
コード例 #8
0
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)
コード例 #9
0
    def fillForm(self, row, column):
        '''fills in the fields with data from the subentry selected in the table list'''
        self.POS.clear()
        self.Reg.clear()
        self.Dia.clear()
        self.Alternative.clear()
        self.L1.clear()
        self.L2.clear()
        self.Ln.clear()
        self.Context.clear()
        thisRow = self.table.item(row, column)
        self.currentCell = thisRow
        L1Text = thisRow.data(35).findtext('L1')
        L1Text = formattingHandlers.XMLtoRTF(L1Text)
        self.L1.setHtml(L1Text)
        if thisRow.data(35).findtext('L2'):
            L2Text = thisRow.data(35).findtext('L2')
            L2Text = formattingHandlers.XMLtoRTF(L2Text)
            self.L2.setHtml(L2Text)
        if thisRow.data(35).findtext('Cxt'):
            CxtText = thisRow.data(35).findtext('Cxt')
            CxtText = formattingHandlers.XMLtoRTF(CxtText)
            self.Context.setHtml(CxtText)
        n = self.table.rowCount()
        self.orderEntries.setMaximum(n)
        self.orderEntries.setMinimum(1)
        self.orderEntries.setEnabled(1)
        self.currentSubentry = int(thisRow.data(35).attrib.get('Index'))
        self.orderEntries.setValue(int(thisRow.data(35).attrib.get('Index')))
        try:
            L1Index = thisRow.data(35).attrib.get('L1Index')
            self.L1Index.setHtml(L1Index)
        except AttributeError:
            self.L1Index.clear()
        try:
            L2Index = thisRow.data(35).attrib.get('L2Index')
            self.L2Index.setHtml(L2Index)
        except AttributeError:
            self.L2Index.clear()
        self.currentSubentry = self.orderEntries.value()
        if thisRow.data(35).findtext('POS'):
            self.POS.setHtml(thisRow.data(35).findtext('POS'))
        else:
            self.POS.clear()
        if thisRow.data(35).findtext('Reg'):
            self.Reg.setHtml(thisRow.data(35).findtext('Reg'))
        else:
            self.Reg.clear()
        dNode = thisRow.data(35).find('Dia')
        try:
            dialect = dNode.attrib.get('Dialect')
            self.Dia.setHtml(dialect)
            if dNode.find('Alternative') != None:
                aNodeList = dNode.findall('Alternative')
                j = 0
                for aNode in aNodeList:
                    variant = " " + aNode.attrib.get('Variant')
                    alternative = " " + aNode.text
                    if j == 0:
                        entry = variant + alternative
                    else:
                        entry = entry + "; " + variant + alternative
                    j += 1
                self.Alternative.setHtml(entry)
        except AttributeError:
            self.Dia.clear()
            self.Alternative.clear()

        examples = thisRow.data(35).findall('Ln')
        if examples:
            self.Ln.setRowCount(len(examples))
            for j in range(0, len(examples)):
                egID = examples[j].attrib.get('LnRef')
                egElement = dataIndex.exDict[egID]
                eg = '<i>' + egElement.findtext('Line') + '</i>'
                if len(egElement.findtext('L1Gloss')) != 0:
                    eg = eg + " ‘" + egElement.findtext('L1Gloss') + "’ ("
                else:
                    eg = eg + " ‘" + egElement.findtext('L2Gloss') + "’ ("
                eg = eg + egElement.attrib.get('Spkr') + ")"
                eg = re.sub('{i}', '', eg)
                eg = re.sub('{/i}', '', eg)
                tableCell = QtWidgets.QTableWidgetItem(1002)
                tableCell.setTextAlignment(QtCore.Qt.TextWordWrap)
                tableCell.setText(eg)
                tableCell.setData(36, egID)
                self.Ln.setItem(j, 0, tableCell)
                self.Ln.resizeRowToContents(j)
        else:
            self.Ln.clear()

        a = self.Ln.selectedRanges()
        if len(a) != 0:
            self.Ln.setRangeSelected(a[0], 0)

        self.Kill.setEnabled(1)
        self.Update.setEnabled(1)
        self.Clear.setEnabled(1)
        self.addEgBtn.setEnabled(1)
        self.minusEgBtn.setDisabled(1)
        self.switchEgBtn.setDisabled(1)
コード例 #10
0
ファイル: menus.py プロジェクト: davidjamesbeck/eFieldbook
def openDb(fldbk, fname=None):
    fldbk.tabWidget.setCurrentIndex(0)
    currentFile = dataIndex.sourceFile
    if currentFile:
        if not okToContinue(fldbk):
            return
        else:
            closeDb(fldbk)
    if fname == None:
        openFileDialog = QtWidgets.QFileDialog(fldbk)
        filePath = path.dirname(openFileDialog.directory().currentPath())
        fileDir = path.split(filePath)
        if fileDir[1] == 'com.UNTProject.eFieldbook':
            openFileDialog.setDirectory(dataIndex.homePath)
        fname = openFileDialog.getOpenFileName(fldbk, "Open...")
        fname = fname[0]
    if fname:
        xmlFile = QtCore.QFile(fname)
        xmlFile.open(QtCore.QIODevice.ReadOnly | QtCore.QIODevice.Text)
        xmlString = xmlFile.readAll()
        xmlFile.close()
        dataIndex.root = etree.XML(xmlString)
        #rebuild the window contents using the new file
        fldbk.tabWidget.setTabEnabled(1, 1)
        fldbk.tabWidget.setTabEnabled(2, 1)
        fldbk.tabWidget.setTabEnabled(3, 1)
        fldbk.tabWidget.setTabEnabled(4, 1)
        fldbk.tabWidget.setTabEnabled(5, 1)
        fldbk.tabWidget.setTabEnabled(6, 1)
        fldbk.tabWidget.setTabEnabled(7, 1)
        fldbk.tabWidget.setTabEnabled(8, 1)
        dbTitle = dataIndex.root.attrib.get('Dbase')
        dbTitle = formattingHandlers.XMLtoRTF(dbTitle)
        fldbk.hTitle.setText(dbTitle)
        fldbk.hTitle.setAlignment(QtCore.Qt.AlignHCenter)
        lang = dataIndex.root.attrib.get('Language')
        fldbk.hLanguage.setPlainText(lang)
        family = dataIndex.root.attrib.get('Family')
        fldbk.hFamily.setPlainText(family)
        population = dataIndex.root.attrib.get('Population')
        fldbk.hPopulation.setPlainText(population)
        location = dataIndex.root.attrib.get('Location')
        fldbk.hLocation.setPlainText(location)
        iso = dataIndex.root.attrib.get('ISO')
        fldbk.hISO.setPlainText(iso)
        if dataIndex.sourceFile not in dataIndex.recentFile and dataIndex.sourceFile != None:
            dataIndex.recentFile.insert(0, dataIndex.sourceFile)
        dataIndex.sourceFile = fname[len(dataIndex.homePath):]
        if fname[len(dataIndex.homePath):] in dataIndex.recentFile:
            del dataIndex.recentFile[dataIndex.recentFile.index(
                fname[len(dataIndex.homePath):])]
        fldbk.settings.setValue('LastFile', dataIndex.sourceFile)
        dataIndex.recentFile.insert(0, fname[len(dataIndex.homePath):])
        dataIndex.recentFile = dataIndex.recentFile[:6]
        dataIndex.unsavedEdit = 1
        fldbk.giveWindowTitle()
        navLists.navListBuilderLex(fldbk)
        navLists.navListBuilderText(fldbk)
        navLists.navListBuilderData(fldbk)
        dictBuilder.exDictBuilder(fldbk)
        dictBuilder.mediaDictBuilder(fldbk)
        dictBuilder.speakerDictBuilder(fldbk)
        dictBuilder.rschrDictBuilder(fldbk)
        metaDataTableFillers.fillRTable(fldbk)
        metaDataTableFillers.fillConsultantTable(fldbk)
        metaDataTableFillers.fillMediaTable(fldbk)
        metaDataTableFillers.fillOrth(fldbk)
        metaDataTableFillers.fillAbbrevTables(fldbk)
        dataIndex.lastText = dataIndex.root.attrib.get('LastText')
        dataIndex.lastLex = dataIndex.root.attrib.get('LastLex')
        dataIndex.lastEx = dataIndex.root.attrib.get('lastEx')
        dataIndex.lastDset = dataIndex.root.attrib.get('LastDset')
        try:
            if dataIndex.root.attrib.get('lAuto') == 'on':
                fldbk.lAutoBtn.setChecked(1)
            else:
                fldbk.lAutoBtn.setChecked(0)
        except AttributeError:
            fldbk.lAutoBtn.setChecked(0)