Exemple #1
0
 def loadOldTests(self, e):
     l = self.addGroup('main')
     for t in e.iterfind('test'):
         feats = {}
         f = t.get('feats')
         if f:
             for ft in f.split(" "):
                 (k, v) = ft.split('=')
                 feats[k] = int(v)
         txt = t.text
         if not txt:
             y = t.find('text')
             txt = y.text
         y = t.find('comment')
         if y is not None:
             c = y.text
         else:
             c = ""
         te = Test(txt,
                   feats,
                   rtl=t.get('rtl'),
                   name=t.get('name'),
                   comment=c)
         b = t.get('background')
         if b:
             res = QtGui.QColor(b)
             if res.isValid(): te.background = res
         self.appendTest(te, l)
Exemple #2
0
 def addTestClicked(self, t=None):
     groupIndex = self.liststack.currentIndex()
     if not t:
         t = Test('',
                  self.app.feats[None].fval,
                  rtl=configintval(self.app.config, 'main', 'defaultrtl'))
     self.appendTest(t)
     res = self.editTest(len(self.testGroups[groupIndex]) - 1)
     if not t.name or not res:
         self.testGroups[groupIndex].pop()
         self.liststack.widget(groupIndex).takeItem(len(self.testGroups))
Exemple #3
0
 def loadOldTests(self, e) :
     l = self.addGroup('main')
     for t in e.iterfind('test') :
         feats = {}
         f = t.get('feats')
         if f :
             for ft in f.split(" ") :
                 (k, v) = ft.split('=')
                 feats[k] = int(v)
         txt = t.text
         if not txt :
             y = t.find('text')
             txt = y.text
         y = t.find('comment')
         if y is not None :
             c = y.text
         else :
             c = ""
         te = Test(txt, feats, rtl = t.get('rtl'), name = t.get('name'), comment = c)
         b = t.get('background')
         if b :
             res = QtGui.QColor(b)
             if res.isValid() : te.background = res
         self.appendTest(te, l)
Exemple #4
0
    def searchClicked(self):
        pattern = self.patternEdit.toPlainText()

        if pattern != "":
            # Populate the MatchList with the results.
            self.matchList.clearTests()

            patternMatcher = GlyphPatternMatcher(self.app, self)
            patternMatcher.setUpPattern(pattern, self.font)
            targetFile = self.matchList.selectedFile()
            matchResults = patternMatcher.search(self.fontFileName, targetFile,
                                                 self.matchList)

            ##print matchResults

            if matchResults == False:
                print "Search canceled"
            elif matchResults == True:
                # Results have already been put in the control
                pass  # do nothing
            else:
                for data in matchResults:
                    matchKey = data[0]
                    matchText = data[1]
                    matchRtl = data[2]
                    matchComment = data[3]
                    matchFeats = data[4]
                    matchLang = data[5]

                    te = Test(text=matchText,
                              feats=matchFeats,
                              lang=matchLang,
                              rtl=matchRtl,
                              name=matchKey,
                              comment=matchComment)
                    self.matchList.appendTest(te)
Exemple #5
0
 def loadTests(self, fname):
     #print "TestList::loadTests(" + fname + ")"
     
     # Assumes the file has been added to the UI.
     self.testGroups = []
     self.gcombo.clear()
     for i in range(self.liststack.count()-1, -1, -1) :
         self.liststack.removeWidget(self.liststack.widget(i))
     if not fname or not os.path.exists(fname) :
         # Create a new set of tests - these will be stored in a new file.
         self.initTests(fname)
         return
         
     try :
         e = et.parse(fname)
     except Exception as err:
         reportError("TestsFile %s: %s" % (fname, str(err)))
         return
     if e.getroot().tag == 'tests' :
         print "Can't find tests file " + fname
         self.loadOldTests(e)
         return
         
     styles = {}
     langs = {}
     self.header = e.find('.//head') 
     if self.header is None : self.header = e.find('.//header')
     for s in e.iterfind('.//style') :
         styleName = s.get('name')
         featDescrip = s.get('feats') or ""
         langCode = s.get('lang') or ""
         fset = featDescrip + "\n" + langCode
         if fset not in self.fsets : self.fsets[fset] = styleName
         styles[styleName] = {}
         if langCode : langs[styleName] = langCode
         for ft in featDescrip.split(" ") :
             if '=' in ft :
                 (fname, value) = ft.split('=')
                 if value and value != "None" :  # under buggy circumstances value can be 'None'; test for it just in case
                     styles[styleName][fname] = int(value)
         m = re.match(r'fset([0-9]+)', styleName)
         if m :
             i = int(m.group(1)) ## number of the fset, eg 'fset2' -> 2
             if i > self.fcount : self.fcount = i
                 
     for g in e.iterfind('testgroup') :
         listwidget = self.addGroup(g.get('label'))
         y = g.find('comment')
         self.comments.append(y.text if y else '')
         for t in g.iterfind('test') :
             y = t.find('string')
             if y is None : y = t.find('text')
             txt = y.text if y is not None else ""
             y = t.find('comment')
             c = y.text if y is not None else ""
             y = t.get('class')
             if y and y in styles :
                 feats = styles[y]
                 lng = langs.get(y)
             else :
                 feats = {}
                 lng = None
             te = Test(txt, feats, lang = lng, rtl = asBool(t.get('rtl')), name = t.get('label'), comment = c)
             b = t.get('background')
             if b :
                 res = QtGui.QColor(b)
                 if res.isValid() : te.background = res
             w = t.get('expand')
             if w :
                 te.setWidth(int(w))
             self.appendTest(te, listwidget)
Exemple #6
0
    def loadTests(self, fname):
        #print "TestList::loadTests(" + fname + ")"

        # Assumes the file has been added to the UI.
        self.testGroups = []
        self.gcombo.clear()
        for i in range(self.liststack.count() - 1, -1, -1):
            self.liststack.removeWidget(self.liststack.widget(i))
        if not fname or not os.path.exists(fname):
            # Create a new set of tests - these will be stored in a new file.
            self.initTests(fname)
            return

        try:
            e = et.parse(fname)
        except Exception as err:
            reportError("TestsFile %s: %s" % (fname, str(err)))
            return
        if e.getroot().tag == 'tests':
            print "Can't find tests file " + fname
            self.loadOldTests(e)
            return

        styles = {}
        langs = {}
        self.header = e.find('.//head')
        if self.header is None: self.header = e.find('.//header')
        for s in e.iterfind('.//style'):
            styleName = s.get('name')
            featDescrip = s.get('feats') or ""
            langCode = s.get('lang') or ""
            fset = featDescrip + "\n" + langCode
            if fset not in self.fsets: self.fsets[fset] = styleName
            styles[styleName] = {}
            if langCode: langs[styleName] = langCode
            for ft in featDescrip.split(" "):
                if '=' in ft:
                    (fname, value) = ft.split('=')
                    if value and value != "None":  # under buggy circumstances value can be 'None'; test for it just in case
                        styles[styleName][fname] = int(value)
            m = re.match(r'fset([0-9]+)', styleName)
            if m:
                i = int(m.group(1))  ## number of the fset, eg 'fset2' -> 2
                if i > self.fcount: self.fcount = i

        for g in e.iterfind('testgroup'):
            listwidget = self.addGroup(g.get('label'))
            y = g.find('comment')
            self.comments.append(y.text if y else '')
            for t in g.iterfind('test'):
                y = t.find('string')
                if y is None: y = t.find('text')
                txt = y.text if y is not None else ""
                y = t.find('comment')
                c = y.text if y is not None else ""
                y = t.get('class')
                if y and y in styles:
                    feats = styles[y]
                    lng = langs.get(y)
                else:
                    feats = {}
                    lng = None
                te = Test(txt,
                          feats,
                          lang=lng,
                          rtl=asBool(t.get('rtl')),
                          name=t.get('label'),
                          comment=c)
                b = t.get('background')
                if b:
                    res = QtGui.QColor(b)
                    if res.isValid(): te.background = res
                w = t.get('expand')
                if w:
                    te.setWidth(int(w))
                self.appendTest(te, listwidget)
Exemple #7
0
    def search(self, fontFileName, targetFile, matchList=None):

        matchResults = []

        if self.pattern == "":
            print "No valid search pattern"
            return matchResults

        print "Searching " + targetFile + " for '" + self.pattern + "'..."

        cpat = re.compile(self.pattern)  # compiled pattern

        totalTests = self._countTests(targetFile)
        showProgress = (totalTests > 25)

        # Read and parse the target file.
        try:
            e = et.parse(targetFile)
        except Exception as err:
            reportError("Could not search %s: %s" % (targetFile, str(err)))
            print "could not search " + targetFile  ####
            return matchResults

        faceAndFont = makeFontAndFace(fontFileName, 12)

        if showProgress:
            print "Total tests=", totalTests
            progressDialog = QtGui.QProgressDialog("Searching...0 matches",
                                                   "Cancel", 0, totalTests,
                                                   self.matcher)
            progressDialog.setWindowModality(QtCore.Qt.WindowModal)

        cntTested = 0
        cntMatched = 0
        canceled = False
        for g in e.iterfind('testgroup'):
            groupLabel = g.get('label')
            for t in g.iterfind('test'):
                testLabel = t.get('label')
                r = t.get('rtl')
                testRtl = True if r == 'True' else False
                d = t.find('string')
                if d is None: d = t.find('text')
                testString = d.text if d is not None else ""
                testComment = t.find('comment') or ""
                featDescrip = t.get('feats') or ""
                langCode = t.get('lang') or ""

                jsonOutput = self.app.runGraphiteOverString(
                    fontFileName, faceAndFont, testString, 12, testRtl, {}, {},
                    100)
                if jsonOutput != False:
                    glyphOutput = self._dataFromGlyphs(jsonOutput)
                    match = cpat.search(glyphOutput)
                else:
                    match = False

                if match:
                    key = "[" + groupLabel + "] " + testLabel

                    if matchList == None:
                        # Return a list of the results.
                        matchResults.append(
                            (key, testString, testRtl, testComment,
                             featDescrip, langCode))
                    else:
                        # Put a match right into the control.
                        te = Test(text=testString,
                                  feats=featDescrip,
                                  lang=langCode,
                                  rtl=testRtl,
                                  name=key,
                                  comment=testComment)
                        matchList.appendTest(te)
                        matchResults = True
                        cntMatched = cntMatched + 1
                        if showProgress:
                            progressDialog.setLabelText("Searching..." +
                                                        str(cntMatched) +
                                                        " matches")
                ###else :
                ###    print testLabel + " did not match"

                cntTested = cntTested + 1
                #if cntTested >= 1 : canceled = True

                if showProgress:
                    if progressDialog.wasCanceled():
                        canceled = True
                    progressDialog.setValue(cntTested)
                    progressDialog.forceShow()

                if canceled: break
            # end of for t loop

            if canceled: break
        # end of for g loop

        if showProgress:
            progressDialog.hide()  # to counteract forceShow()

        if canceled:
            return False
        else:
            return matchResults