Ejemplo n.º 1
0
 def setFont(self, size) :
     if self.fontname and self.fontname != "":
         fontfile = str(self.fontname)
         self.font = GraideFont()
         self.font.loadFont(fontfile, size)
         self.font.loadEmptyGlyphs()
Ejemplo n.º 2
0
class TweakView(QtGui.QWidget) :
    
    # tweaker => Tweaker

    # Communication with the Glyph and Slot tabs
    slotSelected = QtCore.Signal(DataObj, ModelSuper)
    glyphSelected = QtCore.Signal(DataObj, ModelSuper)


    @QtCore.Slot(DataObj, ModelSuper)
    def changeSlot(self, data, model) :
        self.slotSelected.emit(data, model)
        #self.tweaker.changeSlot(...)


    @QtCore.Slot(DataObj, ModelSuper)
    def changeGlyph(self, data, model) :
        self.glyphSelected.emit(data, model)
        if self.currsel and self.currsel != model :
            self.currsel.clearSelected()
        self.currsel = model


    def __init__(self, fontname, size, app = None, parent = None) :
        super(TweakView, self).__init__(parent)
        
        self.app = app
        self.runloaded = False
        self.tweaker = None # set later
        
        self.fontname = fontname
        self.setFont(size)

        if self.fontname and self.fontname != "":
            self._createRunView()
        
        self.currSlotIndex = -1
        self.updateable = True
        
    def _createRunView(self) :
        layout = QtGui.QVBoxLayout(self)
        self.runView = TweakableRunView(self.font, run = None, parent = self)
        self.runView.gview.resize(self.runView.gview.width(), (self.font.pixrect.height() + 5))
        layout.addWidget(self.runView.gview)
        # Ignore runView.tview - text view that shows the glyph names.
        
        
    def updateFromConfigSettings(self, fontname, config) :
        self.fontname = fontname
        self.setFont(configintval(config, 'ui', 'tweakglyphsize'))
        self._createRunView()
        

    def changeFontSize(self, size) :
        self.setFont(size)
        

    def setFont(self, size) :
        if self.fontname and self.fontname != "":
            fontfile = str(self.fontname)
            self.font = GraideFont()
            self.font.loadFont(fontfile, size)
            self.font.loadEmptyGlyphs()
        

    def setTweaker(self, tweaker) :
        # The Tweaker has all the data in it, which is needed to display the glyphs at their
        # adjusted offsets.
        self.tweaker = tweaker
        

    def setUpdateable(self, state) :
        self.updateable = state
        

    def updateDisplay(self, tweak, slotIndex = 0, highlight = False) :
        if not self.updateable :
            # In the middle of a mouse move - don't regenerate (ie, delete) anything.
            return
            
        jsonResult = self.app.runGraphiteOverString(self.app.fontFileName, None, tweak.text, 10, #self.font.size,
            tweak.rtl, tweak.feats, tweak.lang, tweak.width)
        
        if jsonResult != False :
            self.json = jsonResult
        else :
            print "No Graphite result"
            self.json = None

        self.run = Run(tweak.rtl)
        if self.json :
            self.run.addSlots(self.json[-1]['output'])
        self.runView.loadRun(self.run, self.font, resize = False)
        if not self.runloaded :
            try :
                # Don't switch to the Slot tab, but just update the contents.
                self.runView.slotSelected.connect(self.app.tab_slot.changeData)
                self.runView.glyphSelected.connect(self.app.glyphAttrib.changeData)
                self.runloaded = True
            except :
                print "Selection connection failed"

        # Bring the Tweak tab to the front
        self.app.tab_results.setCurrentWidget(self.app.tab_tweakview)
        
        if highlight :
            self.highlightSlot(slotIndex)
        # otherwise done in Tweaker::tweakChanged
    
    # end of updateDisplay
    
    
    def highlightSlot(self, slotIndex) :
        self.currSlotIndex = slotIndex
        self.runView.glyphClicked(None, slotIndex, False)


#    def snagKeyPress(self, event) :
#        self.runView.keyPressEvent(event)
#        self.runView.snagFocus()

#end of class TweakView