Exemplo n.º 1
0
 def addRun(self, font, run, label, num, tooltip = "", highlight = False, collision = False) :
     if num >= len(self.runViews) :
         v = RunView(font, run, self, collision = collision)
         self.runViews.append(v)
         self.setCellWidget(num, 1, v.gview)
         self.setCellWidget(num, 2, v.tview)
         l = QtGui.QTableWidgetItem(label)
         l.setFlags(QtCore.Qt.ItemIsEnabled)
         self.setItem(num, 0, l)
         try :
             v.slotSelected.connect(self.changeSlot)
             v.glyphSelected.connect(self.changeGlyph)
         except :
             print "Passes connection failed"
     else :
         v = self.runViews[num]
         v.loadRun(run, font)
         l = self.item(num, 0)
     if tooltip : l.setToolTip(tooltip)
     if highlight == "active" :
         l.setBackground(Layout.activePassColour)
     elif highlight == "semi-active" :
         l.setBackground(Layout.semiActivePassColour)
     else :
         l.setBackground(QtGui.QColor(255, 255, 255))
     l.highlight = highlight
     self.verticalHeader().setDefaultSectionSize(v.gview.size().height())
     return (v.gview.width(), v.tview.width())
Exemplo n.º 2
0
    def initializeLayout(self, xmlFile) :
        vsplitter = QtGui.QSplitter()  # allows sizing of results view
        vsplitter.setOrientation(QtCore.Qt.Vertical)
        vsplitter.setContentsMargins(0, 0, 0, 0)
        vsplitter.setHandleWidth(4)
        self.layout.addWidget(vsplitter)
        
        self.widget = QtGui.QWidget(vsplitter)
        vbox = QtGui.QVBoxLayout(self.widget) # MatchList + input control
        vbox.setContentsMargins(*Layout.buttonMargins)
        vbox.setSpacing(Layout.buttonSpacing)
        
        hbox = QtGui.QHBoxLayout()  # just in case we want to add more buttons here
        vbox.addLayout(hbox)
        plabel = QtGui.QLabel("Search pattern:")
        hbox.addWidget(plabel)        
        hbox.addStretch()
        hbox.setContentsMargins(*Layout.buttonMargins)
        hbox.setSpacing(Layout.buttonSpacing)
        searchGo = QtGui.QToolButton(self.widget)
        searchGo.setDefaultAction(self.aSearchGo)
        hbox.addWidget(searchGo)
    
        self.patternEdit = TextEditReturn(self.widget, self)
        self.patternEdit.setMaximumHeight(Layout.runEditHeight)
        vbox.addWidget(self.patternEdit)
        vbox.addSpacing(5)
        
        self.matchList = MatchList(self.app, self.font, xmlFile, self)
        #self.matchList.itemClicked.connect(self.itemClicked)
        vbox.addWidget(self.matchList)

        # line below MatchList
        line = QtGui.QFrame(self.widget)
        line.setFrameStyle(QtGui.QFrame.HLine | QtGui.QFrame.Raised)
        line.setLineWidth(2)
        vbox.addWidget(line)
        vbox.addSpacing(2)
        
        # input control
        self.runEdit = QtGui.QPlainTextEdit(self.widget)
        self.runEdit.setMaximumHeight(Layout.runEditHeight)
        vbox.addWidget(self.runEdit)
        
        # control buttons
        hbox = QtGui.QHBoxLayout()
        vbox.addLayout(hbox)
        hbox.setContentsMargins(*Layout.buttonMargins)
        hbox.setSpacing(Layout.buttonSpacing)
        runGo = QtGui.QToolButton(self.widget)
        runGo.setDefaultAction(self.aRunGo)
        hbox.addWidget(runGo)
        hbox.addStretch()
        self.runRtl = QtGui.QCheckBox("RTL", self.widget)
        self.runRtl.setChecked(True if configintval(self.app.config, 'main', 'defaultrtl') else False)
        self.runRtl.setToolTip("Process text right to left")
        hbox.addWidget(self.runRtl)
        self.runFeats = QtGui.QToolButton(self.widget)
        #self.runFeats.setDefaultAction(self.aRunFeats)
        hbox.addWidget(self.runFeats)
        #runAdd = QtGui.QToolButton(self.widget)
        #runAdd.setDefaultAction(self.aRunAdd)
        #hbox.addWidget(runAdd)
    
        # test output
        self.run = Run(self.font, self.runRtl.isChecked())
        self.runView = RunView(self.font)
        self.runView.gview.resize(self.runView.gview.width(), self.font.pixrect.height() + 5)
        vsplitter.addWidget(self.runView.gview)
Exemplo n.º 3
0
class Matcher(QtGui.QTabWidget) :
    
    def __init__(self, fontFileName, font, parent = None, xmlFile = None) :   # parent = app
        super(Matcher, self).__init__(parent)
        self.fontFileName = fontFileName
        self.font = font
        self.app = parent
        self.xmlFile = xmlFile
        self.layout = QtGui.QVBoxLayout(self)
        
        # Default test settings
        self.currFeats = {}
        self.currLang = ""
        self.currWidth = 100
        
        self.runLoaded = False
        
        self.unsavedMods = False

        self.setActions(self.app)
        self.initializeLayout(xmlFile)
        
    # end of __init__
        
        
    def setActions(self, app) :
        self.aSearchGo = QtGui.QAction(QtGui.QIcon.fromTheme('edit-find', QtGui.QIcon(":/images/find-normal.png")), "", self)
        self.aSearchGo.setToolTip("Search for pattern in specified test file")
        self.aSearchGo.triggered.connect(self.searchClicked)

        self.aRunGo = QtGui.QAction(QtGui.QIcon.fromTheme("media-playback-start", QtGui.QIcon(":/images/media-playback-start.png")), "&Run Test", self)
        self.aRunGo.setToolTip("Run text string")
        self.aRunGo.triggered.connect(self.runClicked)
        
    # end of setActions
    
    
    def initializeLayout(self, xmlFile) :
        vsplitter = QtGui.QSplitter()  # allows sizing of results view
        vsplitter.setOrientation(QtCore.Qt.Vertical)
        vsplitter.setContentsMargins(0, 0, 0, 0)
        vsplitter.setHandleWidth(4)
        self.layout.addWidget(vsplitter)
        
        self.widget = QtGui.QWidget(vsplitter)
        vbox = QtGui.QVBoxLayout(self.widget) # MatchList + input control
        vbox.setContentsMargins(*Layout.buttonMargins)
        vbox.setSpacing(Layout.buttonSpacing)
        
        hbox = QtGui.QHBoxLayout()  # just in case we want to add more buttons here
        vbox.addLayout(hbox)
        plabel = QtGui.QLabel("Search pattern:")
        hbox.addWidget(plabel)        
        hbox.addStretch()
        hbox.setContentsMargins(*Layout.buttonMargins)
        hbox.setSpacing(Layout.buttonSpacing)
        searchGo = QtGui.QToolButton(self.widget)
        searchGo.setDefaultAction(self.aSearchGo)
        hbox.addWidget(searchGo)
    
        self.patternEdit = TextEditReturn(self.widget, self)
        self.patternEdit.setMaximumHeight(Layout.runEditHeight)
        vbox.addWidget(self.patternEdit)
        vbox.addSpacing(5)
        
        self.matchList = MatchList(self.app, self.font, xmlFile, self)
        #self.matchList.itemClicked.connect(self.itemClicked)
        vbox.addWidget(self.matchList)

        # line below MatchList
        line = QtGui.QFrame(self.widget)
        line.setFrameStyle(QtGui.QFrame.HLine | QtGui.QFrame.Raised)
        line.setLineWidth(2)
        vbox.addWidget(line)
        vbox.addSpacing(2)
        
        # input control
        self.runEdit = QtGui.QPlainTextEdit(self.widget)
        self.runEdit.setMaximumHeight(Layout.runEditHeight)
        vbox.addWidget(self.runEdit)
        
        # control buttons
        hbox = QtGui.QHBoxLayout()
        vbox.addLayout(hbox)
        hbox.setContentsMargins(*Layout.buttonMargins)
        hbox.setSpacing(Layout.buttonSpacing)
        runGo = QtGui.QToolButton(self.widget)
        runGo.setDefaultAction(self.aRunGo)
        hbox.addWidget(runGo)
        hbox.addStretch()
        self.runRtl = QtGui.QCheckBox("RTL", self.widget)
        self.runRtl.setChecked(True if configintval(self.app.config, 'main', 'defaultrtl') else False)
        self.runRtl.setToolTip("Process text right to left")
        hbox.addWidget(self.runRtl)
        self.runFeats = QtGui.QToolButton(self.widget)
        #self.runFeats.setDefaultAction(self.aRunFeats)
        hbox.addWidget(self.runFeats)
        #runAdd = QtGui.QToolButton(self.widget)
        #runAdd.setDefaultAction(self.aRunAdd)
        #hbox.addWidget(runAdd)
    
        # test output
        self.run = Run(self.font, self.runRtl.isChecked())
        self.runView = RunView(self.font)
        self.runView.gview.resize(self.runView.gview.width(), self.font.pixrect.height() + 5)
        vsplitter.addWidget(self.runView.gview)
        
    # end of initializeLayout
    

    def setRun(self, test) :

        self.runRtl.setChecked(True if test.rtl else False)
        if configintval(self.app.config, 'ui', 'entities') :
            t = as_entities(test.text)
        else :
            t = test.text
        self.runEdit.setPlainText(t)
        self.currFeats = dict(test.feats)
        self.currLang = test.lang
        self.currWidth = test.width
        self.runView.clear()

    # end of setRun
    

    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)
        
    # end of searchClicked
    

    def runClicked(self) :

        jsonResult = self.app.runGraphiteOverString(self.fontFileName, None, self.runEdit.toPlainText(),
            self.font.size, self.runRtl.isChecked(), 
            #self.currFeats or self.app.feats[self.currLang].fval,
            self.currFeats,
            self.currLang, self.currWidth)
        if jsonResult != False :
            self.json = jsonResult
        else :
            print "No Graphite result" ###
            self.json = [ {'passes' : [], 'output' : [] } ]
                
        self.run = self.app.loadRunViewAndPasses(self, self.json, 
            # In the Matcher we are generally interested in the output of the final pass, so scroll it into view:
            'to-end')
        
        
        
    # end of runClicked
    
    
    def pasteAsPattern(self, glyphList) :
        string = ""
        sep = ""
        for glyph in glyphList :
            string += sep + glyph
            sep = " "
        self.patternEdit.setPlainText(string)
    
    
    def updateFromConfigSettings(self, fontFileName, config) :
        self.fontFileName = fontFileName
        if config.has_option('main', 'testsfile') :
            self.matchList.addFile(config.get('main', 'testsfile'))
            
        
       
    
# end of class Matcher
Exemplo n.º 4
0
    def initializeLayout(self, xmlFile):
        vsplitter = QtGui.QSplitter()  # allows sizing of results view
        vsplitter.setOrientation(QtCore.Qt.Vertical)
        vsplitter.setContentsMargins(0, 0, 0, 0)
        vsplitter.setHandleWidth(4)
        self.layout.addWidget(vsplitter)

        self.widget = QtGui.QWidget(vsplitter)
        vbox = QtGui.QVBoxLayout(self.widget)  # MatchList + input control
        vbox.setContentsMargins(*Layout.buttonMargins)
        vbox.setSpacing(Layout.buttonSpacing)

        hbox = QtGui.QHBoxLayout(
        )  # just in case we want to add more buttons here
        vbox.addLayout(hbox)
        plabel = QtGui.QLabel("Search pattern:")
        hbox.addWidget(plabel)
        hbox.addStretch()
        hbox.setContentsMargins(*Layout.buttonMargins)
        hbox.setSpacing(Layout.buttonSpacing)
        searchGo = QtGui.QToolButton(self.widget)
        searchGo.setDefaultAction(self.aSearchGo)
        hbox.addWidget(searchGo)

        self.patternEdit = TextEditReturn(self.widget, self)
        self.patternEdit.setMaximumHeight(Layout.runEditHeight)
        vbox.addWidget(self.patternEdit)
        vbox.addSpacing(5)

        self.matchList = MatchList(self.app, self.font, xmlFile, self)
        #self.matchList.itemClicked.connect(self.itemClicked)
        vbox.addWidget(self.matchList)

        # line below MatchList
        line = QtGui.QFrame(self.widget)
        line.setFrameStyle(QtGui.QFrame.HLine | QtGui.QFrame.Raised)
        line.setLineWidth(2)
        vbox.addWidget(line)
        vbox.addSpacing(2)

        # input control
        self.runEdit = QtGui.QPlainTextEdit(self.widget)
        self.runEdit.setMaximumHeight(Layout.runEditHeight)
        vbox.addWidget(self.runEdit)

        # control buttons
        hbox = QtGui.QHBoxLayout()
        vbox.addLayout(hbox)
        hbox.setContentsMargins(*Layout.buttonMargins)
        hbox.setSpacing(Layout.buttonSpacing)
        runGo = QtGui.QToolButton(self.widget)
        runGo.setDefaultAction(self.aRunGo)
        hbox.addWidget(runGo)
        hbox.addStretch()
        self.runRtl = QtGui.QCheckBox("RTL", self.widget)
        self.runRtl.setChecked(True if configintval(self.app.config, 'main',
                                                    'defaultrtl') else False)
        self.runRtl.setToolTip("Process text right to left")
        hbox.addWidget(self.runRtl)
        self.runFeats = QtGui.QToolButton(self.widget)
        #self.runFeats.setDefaultAction(self.aRunFeats)
        hbox.addWidget(self.runFeats)
        #runAdd = QtGui.QToolButton(self.widget)
        #runAdd.setDefaultAction(self.aRunAdd)
        #hbox.addWidget(runAdd)

        # test output
        self.run = Run(self.font, self.runRtl.isChecked())
        self.runView = RunView(self.font)
        self.runView.gview.resize(self.runView.gview.width(),
                                  self.font.pixrect.height() + 5)
        vsplitter.addWidget(self.runView.gview)
Exemplo n.º 5
0
class Matcher(QtGui.QTabWidget):
    def __init__(self,
                 fontFileName,
                 font,
                 parent=None,
                 xmlFile=None):  # parent = app
        super(Matcher, self).__init__(parent)
        self.fontFileName = fontFileName
        self.font = font
        self.app = parent
        self.xmlFile = xmlFile
        self.layout = QtGui.QVBoxLayout(self)

        # Default test settings
        self.currFeats = {}
        self.currLang = ""
        self.currWidth = 100

        self.runLoaded = False

        self.unsavedMods = False

        self.setActions(self.app)
        self.initializeLayout(xmlFile)

    # end of __init__

    def setActions(self, app):
        self.aSearchGo = QtGui.QAction(
            QtGui.QIcon.fromTheme('edit-find',
                                  QtGui.QIcon(":/images/find-normal.png")), "",
            self)
        self.aSearchGo.setToolTip("Search for pattern in specified test file")
        self.aSearchGo.triggered.connect(self.searchClicked)

        self.aRunGo = QtGui.QAction(
            QtGui.QIcon.fromTheme(
                "media-playback-start",
                QtGui.QIcon(":/images/media-playback-start.png")), "&Run Test",
            self)
        self.aRunGo.setToolTip("Run text string")
        self.aRunGo.triggered.connect(self.runClicked)

    # end of setActions

    def initializeLayout(self, xmlFile):
        vsplitter = QtGui.QSplitter()  # allows sizing of results view
        vsplitter.setOrientation(QtCore.Qt.Vertical)
        vsplitter.setContentsMargins(0, 0, 0, 0)
        vsplitter.setHandleWidth(4)
        self.layout.addWidget(vsplitter)

        self.widget = QtGui.QWidget(vsplitter)
        vbox = QtGui.QVBoxLayout(self.widget)  # MatchList + input control
        vbox.setContentsMargins(*Layout.buttonMargins)
        vbox.setSpacing(Layout.buttonSpacing)

        hbox = QtGui.QHBoxLayout(
        )  # just in case we want to add more buttons here
        vbox.addLayout(hbox)
        plabel = QtGui.QLabel("Search pattern:")
        hbox.addWidget(plabel)
        hbox.addStretch()
        hbox.setContentsMargins(*Layout.buttonMargins)
        hbox.setSpacing(Layout.buttonSpacing)
        searchGo = QtGui.QToolButton(self.widget)
        searchGo.setDefaultAction(self.aSearchGo)
        hbox.addWidget(searchGo)

        self.patternEdit = TextEditReturn(self.widget, self)
        self.patternEdit.setMaximumHeight(Layout.runEditHeight)
        vbox.addWidget(self.patternEdit)
        vbox.addSpacing(5)

        self.matchList = MatchList(self.app, self.font, xmlFile, self)
        #self.matchList.itemClicked.connect(self.itemClicked)
        vbox.addWidget(self.matchList)

        # line below MatchList
        line = QtGui.QFrame(self.widget)
        line.setFrameStyle(QtGui.QFrame.HLine | QtGui.QFrame.Raised)
        line.setLineWidth(2)
        vbox.addWidget(line)
        vbox.addSpacing(2)

        # input control
        self.runEdit = QtGui.QPlainTextEdit(self.widget)
        self.runEdit.setMaximumHeight(Layout.runEditHeight)
        vbox.addWidget(self.runEdit)

        # control buttons
        hbox = QtGui.QHBoxLayout()
        vbox.addLayout(hbox)
        hbox.setContentsMargins(*Layout.buttonMargins)
        hbox.setSpacing(Layout.buttonSpacing)
        runGo = QtGui.QToolButton(self.widget)
        runGo.setDefaultAction(self.aRunGo)
        hbox.addWidget(runGo)
        hbox.addStretch()
        self.runRtl = QtGui.QCheckBox("RTL", self.widget)
        self.runRtl.setChecked(True if configintval(self.app.config, 'main',
                                                    'defaultrtl') else False)
        self.runRtl.setToolTip("Process text right to left")
        hbox.addWidget(self.runRtl)
        self.runFeats = QtGui.QToolButton(self.widget)
        #self.runFeats.setDefaultAction(self.aRunFeats)
        hbox.addWidget(self.runFeats)
        #runAdd = QtGui.QToolButton(self.widget)
        #runAdd.setDefaultAction(self.aRunAdd)
        #hbox.addWidget(runAdd)

        # test output
        self.run = Run(self.font, self.runRtl.isChecked())
        self.runView = RunView(self.font)
        self.runView.gview.resize(self.runView.gview.width(),
                                  self.font.pixrect.height() + 5)
        vsplitter.addWidget(self.runView.gview)

    # end of initializeLayout

    def setRun(self, test):

        self.runRtl.setChecked(True if test.rtl else False)
        if configintval(self.app.config, 'ui', 'entities'):
            t = as_entities(test.text)
        else:
            t = test.text
        self.runEdit.setPlainText(t)
        self.currFeats = dict(test.feats)
        self.currLang = test.lang
        self.currWidth = test.width
        self.runView.clear()

    # end of setRun

    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)

    # end of searchClicked

    def runClicked(self):

        jsonResult = self.app.runGraphiteOverString(
            self.fontFileName,
            None,
            self.runEdit.toPlainText(),
            self.font.size,
            self.runRtl.isChecked(),
            #self.currFeats or self.app.feats[self.currLang].fval,
            self.currFeats,
            self.currLang,
            self.currWidth)
        if jsonResult != False:
            self.json = jsonResult
        else:
            print "No Graphite result"  ###
            self.json = [{'passes': [], 'output': []}]

        self.run = self.app.loadRunViewAndPasses(
            self,
            self.json,
            # In the Matcher we are generally interested in the output of the final pass, so scroll it into view:
            'to-end')

    # end of runClicked

    def pasteAsPattern(self, glyphList):
        string = ""
        sep = ""
        for glyph in glyphList:
            string += sep + glyph
            sep = " "
        self.patternEdit.setPlainText(string)

    def updateFromConfigSettings(self, fontFileName, config):
        self.fontFileName = fontFileName
        if config.has_option('main', 'testsfile'):
            self.matchList.addFile(config.get('main', 'testsfile'))


# end of class Matcher