def operationCallback(self, sender):
        value = sender.get()
        roundCoordinates = self.w.roundCoordinates.get()
        backToFront = self.w.reverseContourOrder.get()

        if roundCoordinates is None:
            roundCoordinates = 0

        robofabGlyph = CurrentGlyph()

        if robofabGlyph is None:
            return

        glyph = robofabGlyph.naked()

        selectedContours = glyph.selection.getAllSelectedContours()
        if not selectedContours:
            return

        if backToFront:
            selectedContours.reverse()

        subjectContours = selectedContours[:1]
        clipContours = selectedContours[1:]

        glyph.prepareUndo("Path Operations")

        if value == 0:
            # union
            removeOverlap(glyph, selectedContours, roundCoordinates)

        elif value == 1:
            # difference
            difference(glyph, subjectContours, clipContours, roundCoordinates)

        elif value == 2:
            # intersection
            intersection(glyph, subjectContours, clipContours,
                         roundCoordinates)

        elif value == 3:
            # Xor
            xor(glyph, subjectContours, clipContours, roundCoordinates)

        glyph.performUndo()
        glyph.selection.resetSelection()
    def operationCallback(self, sender):
        value = sender.get()
        roundCoordinates = self.w.roundCoordinates.get()
        backToFront = self.w.reverseContourOrder.get()
        
        if roundCoordinates is None:
            roundCoordinates = 0
            
        robofabGlyph = CurrentGlyph()
        
        if robofabGlyph is None:
            return
            
        glyph = robofabGlyph.naked()
        
        selectedContours = glyph.selection.getAllSelectedContours()
        if not selectedContours:
            return 
        
        if backToFront:
            selectedContours.reverse()
        
        subjectContours = selectedContours[:1]
        clipContours = selectedContours[1:]
        
        glyph.prepareUndo("Path Operations")
        
        if value == 0:
            # union
            removeOverlap(glyph, selectedContours, roundCoordinates)
        
        elif value == 1:
            # difference
            difference(glyph, subjectContours, clipContours, roundCoordinates)
                
        elif value == 2:
            # intersection
            intersection(glyph, subjectContours, clipContours, roundCoordinates)

        elif value == 3:
            # Xor
            xor(glyph, subjectContours, clipContours, roundCoordinates)
        
        glyph.performUndo()
        glyph.selection.resetSelection()
Esempio n. 3
0
def switch(direction=1, shuffle=False):
    currentPath, windowType = getCurrentFontAndWindowFlavor()
    # maybe here
    nextMaster = None
    nextLayer = None
    currentLayerName = None
    try:
        app = AppKit.NSApp()
        if hasattr(app, "getNextSkateboardMasterCallback"):
            callback = app.getNextSkateboardMasterCallback
            if callback:
                r = callback(direction, windowType)
                if r is not None:
                    nextMaster, nextLayer = r
    except:
        print("EditNext: problem calling Skateboard")
    if nextMaster is None:
        nextMaster = getOtherMaster(direction == 1, shuffle == True)
    f = CurrentFont()
    if windowType == "FontWindow":
        fontWindow = CurrentFontWindow()
        selectedGlyphs = f.selectedGlyphNames if version >= '3.2' else f.selection
        currentFontWindowQuery = fontWindow.getGlyphCollection().getQuery()
        selectedSmartList = fontWindow.fontOverview.views.smartList.getSelection(
        )
        posSize = fontWindow.window().getPosSize()
        nextWindow = nextMaster.document().getMainWindow()
        nextSelectedGlyphs = [s for s in selectedGlyphs if s in nextMaster]
        if version >= '3.2':
            nextMaster.selectedGlyphNames = nextSelectedGlyphs
        else:
            nextMaster.selection = nextSelectedGlyphs
        nextWindow.setPosSize(posSize)
        nextWindow.show()
        # set the selected smartlist
        fontWindow = CurrentFontWindow()
        try:
            fontWindow.fontOverview.views.smartList.setSelection(
                selectedSmartList)
            fontWindow.getGlyphCollection().setQuery(
                currentFontWindowQuery
            )  # sorts but does not fill it in the form
        except:
            pass
    elif windowType == "SpaceCenter":
        setSpaceCenterWindowPosSize(nextMaster, nextLayer)
    elif windowType == "GlyphWindow":
        g = CurrentGlyph()
        selectedPoints, selectedComps, selectedAnchors = copySelection(g)
        currentMeasurements = g.naked().measurements
        if g is not None:
            # wrap possible UFO3 / fontparts objects
            if version >= "3.0":
                # RF 3.x
                if nextLayer is not None:
                    # wait nextlayer can be None
                    # if we're jumping from a source with a layername
                    # to a source without one
                    currentLayerName = nextLayer
                else:
                    currentLayerName = g.layer.name
            else:
                # RF 1.8.x
                currentLayerName = g.layerName
            if not g.name in nextMaster:
                # Frank suggests:
                #nextMaster = getOtherMaster(direction==1, shuffle==True)
                #OpenWindow(AddSomeGlyphsWindow, f, nextMaster, g.name)
                #AppKit.NSBeep()
                return None
            nextGlyph = nextMaster[g.name]
            applySelection(nextGlyph, selectedPoints, selectedComps,
                           selectedAnchors)
            nextGlyph.naked().measurements = currentMeasurements
            if nextGlyph is not None:
                if version >= "3.3":
                    # use the 3.3 new window.setGlyph so we don't have to create a new window
                    w = CurrentGlyphWindow()
                    print("glyphwindow recycle! 3.3b", time.time(), w)
                    view = w.getGlyphView()
                    viewFrame = view.visibleRect()  #    necessary?
                    viewScale = w.getGlyphViewScale()  #    necessary?
                    w.setGlyph(nextGlyph)
                    w.setGlyphViewScale(viewScale)  #    necessary?
                    view.scrollRectToVisible_(viewFrame)  #    necessary?
                    if currentLayerName is not None:
                        w.setLayer(currentLayerName, toToolbar=True)
                else:
                    # can't set a new glyph to the same window
                    # then make a new window and copy the state
                    rr = getGlyphWindowPosSize()
                    if rr is not None:
                        p, s, settings, viewFrame, viewScale = rr
                        setGlyphWindowPosSize(nextGlyph,
                                              p,
                                              s,
                                              settings=settings,
                                              viewFrame=viewFrame,
                                              viewScale=viewScale,
                                              layerName=currentLayerName)
    elif windowType == "SingleFontWindow":
        selectedPoints = None
        selectedComps = None
        currentMeasurements = None
        nextGlyph = None
        fontWindow = CurrentFontWindow()
        selectedGlyphs = f.selectedGlyphNames if version >= "3.2" else f.selection
        nextWindow = nextMaster.document().getMainWindow()
        nextWindow = nextWindow.vanillaWrapper()
        g = CurrentGlyph()
        if g is not None:
            selectedPoints, selectedComps, selectedAnchors = copySelection(g)
            currentMeasurements = g.naked().measurements
            nextGlyph = nextMaster[g.name]
        # copy the posSize
        posSize = fontWindow.window().getPosSize()
        nextWindow.window().setPosSize(posSize)
        nextWindow.window().show()
        # set the new current glyph
        nextWindow.setGlyphByName(g.name)
        # set the viewscale
        currentView = fontWindow.getGlyphView()
        viewFrame = currentView.visibleRect()
        viewScale = currentView.getGlyphViewScale()
        nextView = nextWindow.getGlyphView()
        nextWindow.setGlyphViewScale(1 / viewScale)
        nextView.scrollRectToVisible_(viewFrame)
        # maybe the viewframe needs to be seen as a factor of the rect

        nextSelectedGlyphs = [s for s in selectedGlyphs if s in nextMaster]
        if version >= "3.0":
            nextMaster.selectedGlyphNames = nextSelectedGlyphs
        else:
            nextMaster.selection = nextSelectedGlyphs

        if nextGlyph is not None:
            applySelection(nextGlyph, selectedPoints, selectedComps,
                           selectedAnchors)
            nextGlyph.naked().measurements = currentMeasurements

        rawText = fontWindow.spaceCenter.getRaw()
        prefix = fontWindow.spaceCenter.getPre()
        suffix = fontWindow.spaceCenter.getAfter()
        gnameSuffix = fontWindow.spaceCenter.getSuffix()
        size = fontWindow.spaceCenter.getPointSize()

        nextWindow.spaceCenter.setRaw(rawText)
        nextWindow.spaceCenter.setPre(prefix)
        nextWindow.spaceCenter.setAfter(suffix)
        nextWindow.spaceCenter.setSuffix(gnameSuffix)
        nextWindow.spaceCenter.setPointSize(size)
Esempio n. 4
0
def switch(direction=1):
    currentPath, windowType = getCurrentFontAndWindowFlavor()
    nextMaster = getOtherMaster(direction==1)
    f = CurrentFont()
    if windowType == "FontWindow":
        fontWindow = CurrentFontWindow()
        selectedGlyphs = f.selection
        currentFontWindowQuery =  fontWindow.getGlyphCollection().getQuery()
        selectedSmartList = fontWindow.fontOverview.views.smartList.getSelection()
        posSize = fontWindow.window().getPosSize()
        nextWindow = nextMaster.document().getMainWindow()
        nextMaster.selection = [s for s in selectedGlyphs if s in nextMaster]
        nextWindow.setPosSize(posSize)
        nextWindow.show()
        # set the selected smartlist
        fontWindow = CurrentFontWindow()
        try:
            fontWindow.fontOverview.views.smartList.setSelection(selectedSmartList)
            fontWindow.getGlyphCollection().setQuery(currentFontWindowQuery)    # sorts but does not fill it in the form
        except:
            pass
    elif windowType == "SpaceCenter":
        setSpaceCenterWindowPosSize(nextMaster)
    elif windowType == "GlyphWindow":
        g = CurrentGlyph()
        selectedPoints, selectedComps = copySelection(g)
        currentMeasurements = g.naked().measurements
        if g is not None:
            # wrap possible UFO3 / fontparts objects
            if version >= "3.0":
                # RF 3.x
                currentLayerName = g.layer.name
            else:
                # RF 1.8.x
                currentLayerName = g.layerName
            if not g.name in nextMaster:
                #OpenWindow(AddSomeGlyphsWindow, f, nextMaster, g.name)
                AppKit.NSBeep()
                return None
            nextGlyph = nextMaster[g.name]
            applySelection(nextGlyph, selectedPoints, selectedComps)
            nextGlyph.naked().measurements = currentMeasurements
            if nextGlyph is not None:
                rr = getGlyphWindowPosSize()
                if rr is not None:
                    p, s, settings, viewFrame, viewScale = rr
                    setGlyphWindowPosSize(nextGlyph, p, s, settings=settings, viewFrame=viewFrame, viewScale=viewScale, layerName=currentLayerName)
    elif windowType == "SingleFontWindow":
        selectedPoints = None
        selectedComps = None
        currentMeasurements = None
        nextGlyph = None
        fontWindow = CurrentFontWindow()
        selectedGlyphs = f.selection
        nextWindow = nextMaster.document().getMainWindow()
        nextWindow = nextWindow.vanillaWrapper()
        g = CurrentGlyph()
        if g is not None:
            selectedPoints, selectedComps = copySelection(g)
            currentMeasurements = g.naked().measurements
            nextGlyph = nextMaster[g.name]
            #print("SingleFontWindow", fontWindow, selectedGlyphs, g, selectedPoints, currentMeasurements)
        # copy the posSize
        posSize = fontWindow.window().getPosSize()
        nextWindow.window().setPosSize(posSize)
        nextWindow.window().show()
        # set the new current glyph
        nextWindow.setGlyphByName(g.name)
        # set the viewscale
        currentView = fontWindow.getGlyphView()
        viewFrame = currentView.visibleRect()
        viewScale = currentView.getGlyphViewScale()
        nextView = nextWindow.getGlyphView()
        nextWindow.setGlyphViewScale(viewScale)
        nextView.scrollRectToVisible_(viewFrame)
        # maybe the viewframe needs to be seen as a factor of the rect
        
        nextMaster.selection = [s for s in selectedGlyphs if s in nextMaster]
        if nextGlyph is not None:
            applySelection(nextGlyph, selectedPoints, selectedComps)
            nextGlyph.naked().measurements = currentMeasurements

        rawText = fontWindow.spaceCenter.getRaw()
        prefix = fontWindow.spaceCenter.getPre()
        suffix = fontWindow.spaceCenter.getAfter()
        size = fontWindow.spaceCenter.getPointSize()

        nextWindow.spaceCenter.setRaw(rawText)
        nextWindow.spaceCenter.setPre(prefix)
        nextWindow.spaceCenter.setAfter(suffix)
        nextWindow.spaceCenter.setPointSize(size)

        for n in dir(nextWindow):
           print(n)