コード例 #1
0
def run():
    if not len(AllFonts()) > 0:
        print('you must have a font open')
        return

    try:
        p = metricsMachine.GetCurrentPair()

    except:
        print('you must have Metrics Machine open first')
        return

    p = metricsMachine.GetCurrentPair()

    font = metricsMachine.CurrentFont()

    ## old support for custom word path, add back later via UI?
    # wordlistPath_rel = 'resources/ukacd.txt'

    # #wordlistPath_abs = None

    # if wordlistPath_rel:
    #     pathname = os.path.dirname(sys.argv[0])
    #     cwd = os.path.abspath(pathname)
    #     wordlistPath_abs = os.path.join(cwd ,wordlistPath_rel)

    #     p = MM2SpaceCenter(wordlistPath=wordlistPath_abs)

    # else:
    #     p = MM2SpaceCenter()
    p = MM2SpaceCenter()
コード例 #2
0
    def __init__(self, ):
        self.font = metricsMachine.CurrentFont()
        self.pair = metricsMachine.GetCurrentPair()
        #self.wordlistPath = wordlistPath

        leftMargin = 10
        topMargin = 5
        yPos = 0
        lineHeight = 20

        yPos += topMargin

        self.messageText = 'MM2SpaceCenter activated 😎'

        self.wordCount = 20
        self.minLength = 3
        self.maxLength = 15

        self.activateModule()
        self.w = Window((250, 155), "MM2SpaceCenter")

        self.w.myTextBox = TextBox((leftMargin, yPos, -10, 17),
                                   self.messageText,
                                   sizeStyle="regular")

        yPos += (lineHeight * 1.2)

        topLineFields = {
            "wordCount": [0 + leftMargin, self.wordCount, 20],
            #"minLength": [108+leftMargin, self.minLength, 3],
            #"maxLength": [145+leftMargin, self.maxLength, 10],
        }
        topLineLabels = {
            "wcText": [31 + leftMargin, 78, 'words', 'left'],

            #"wcText": [31+leftMargin, 78, 'words with', 'left'],

            # "lenTextTwo": [133+leftMargin, 10, u'–', 'center'],
            #"lenTextThree": [176+leftMargin, -0, 'letters', 'left'],
        }

        # for label, values in topLineFields.items():
        #     setattr(self.w, label, EditText((values[0], 0+yPos, 28, 22), text=values[1], placeholder=str(values[2])))

        self.w.wordCount = EditText((0 + leftMargin, 0 + yPos, 28, 22),
                                    text=self.wordCount,
                                    placeholder=self.wordCount,
                                    callback=self.wordCountCallback)

        for label, values in topLineLabels.items():
            setattr(
                self.w, label,
                TextBox((values[0], 3 + yPos, values[1], 22),
                        text=values[2],
                        alignment=values[3]))

        yPos += lineHeight * 1.3

        self.loadDictionaries()

        # language selection
        languageOptions = list(self.languageNames)

        self.w.source = PopUpButton((leftMargin, yPos, 85, 20), [],
                                    sizeStyle="small",
                                    callback=self.changeSourceCallback)
        self.w.source.setItems(languageOptions)

        self.w.source.set(4)  #default to English for now
        self.source = None
        self.source = self.w.source.get(
        )  #get value, to use for other functions

        yPos += lineHeight * 1.2

        checkBoxSize = 18
        self.w.listOutput = CheckBox(
            (leftMargin, yPos, checkBoxSize, checkBoxSize),
            "",
            sizeStyle="small",
            callback=self.sortedCallback)
        self.w.listLabel = TextBox(
            (checkBoxSize + 5, yPos + 2, -leftMargin, checkBoxSize),
            "Output as list sorted by width",
            sizeStyle="small")

        yPos += lineHeight * 1.2

        checkBoxSize = 18
        self.w.openCloseContext = CheckBox(
            (leftMargin, yPos, checkBoxSize, checkBoxSize),
            "",
            sizeStyle="small",
            callback=self.sortedCallback)
        self.w.openCloseContextLabel = TextBox(
            (checkBoxSize + 5, yPos + 2, -leftMargin, checkBoxSize),
            "Show open+close context {n}",
            sizeStyle="small")

        yPos += lineHeight * 1.2

        self.w.mirroredPair = CheckBox(
            (leftMargin, yPos, checkBoxSize, checkBoxSize),
            "",
            sizeStyle="small",
            callback=self.sortedCallback)
        self.w.mirroredPairLabel = TextBox(
            (checkBoxSize + 5, yPos + 2, -leftMargin, checkBoxSize),
            "Show mirrored pair (LRL)",
            sizeStyle="small")

        self.sorted = self.w.listOutput.get()

        self.w.bind("close", self.deactivateModule)
        self.w.open()
コード例 #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":
        # if version >= "3.3":
        #     w = CurrentSpaceCenterWindow()
        #     print('w', w.font.path)
        #     c = w.getSpaceCenter()
        #     c.setFont(nextMaster)
        #     c.setLayerName(nextLayer)
        #     print("setting font to spacecenter", time.time(), nextMaster)
        # else:
        setSpaceCenterWindowPosSize(nextMaster, nextLayer)
    elif windowType == "GlyphWindow":
        if nextMaster is None:
            print("geen next XX 1")
            switch(direction)
            return
        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()
                    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)
    elif windowType == "MetricsMachineMainWindow":
        # this handles any metricsMachine windows that might be open.
        # copy the pairlist and the current pair to the next window
        # maybe also adjust the window position?
        # thanks to Tal and Frederik
        currentPair = metricsMachine.GetCurrentPair(font=f)
        currentList = metricsMachine.GetPairList(font=f)
        MMcontroller = focusOnMetricsMachine(nextMaster)
        MMcontroller.w.show()
        metricsMachine.SetPairList(currentList, font=nextMaster)
        metricsMachine.SetCurrentPair(currentPair, font=nextMaster)