Exemplo n.º 1
0
    def resetCallback(self, sender=None):
        """
        Resets the view to the currently opened fonts.

        """
        self.fonts = AllFonts()
        self.w.fontList.set(self._getFontItems())
Exemplo n.º 2
0
 def loadFontsOrder(self):
     if self.fontsOrder is None:
         fontsOrder = [f for f in AllFonts() if f.path is not None]
         self.fontsOrder = sorted(fontsOrder,
                                  key=lambda f: os.path.basename(f.path))
     else:
         newFontsOrder = [f for f in AllFonts() if f in self.fontsOrder] + [
             f for f in AllFonts() if f not in self.fontsOrder
         ]
         self.fontsOrder = newFontsOrder
Exemplo n.º 3
0
    def italicizeCallback(self, sender=None):
        italicAngle = self.getItalicAngle()
        italicSlantOffset = self.getItalicSlantOffset()
        if self.w.fontSelection.get() == 0:
            if CurrentFont() is not None:
                fonts = [CurrentFont()]
            else:
                fonts = []
        else:
            fonts = AllFonts()

        if self.w.glyphSelection.get() == 0 and CurrentGlyph() is not None:
            glyphs = [CurrentGlyph()]
        elif self.w.glyphSelection.get() == 1:
            glyphs = []
            for f in fonts:
                for gname in CurrentFont().selection:
                    if gname in f:
                        glyphs.append(f[gname])
        else:
            glyphs = []
            for f in fonts:
                for g in f:
                    glyphs.append(g.name)

        for glyph in glyphs:
            italicize(glyph,
                      italicAngle,
                      offset=italicSlantOffset,
                      shouldMakeReferenceLayer=self.w.makeReferenceLayer.get())
Exemplo n.º 4
0
def getOtherMaster(nextFont=True, shuffleFont=False):
    cf = CurrentFont()
    orderedFonts = []
    fonts = {}
    for f in AllFonts():
        if f.path is None:
            continue
        fonts[f.path] = f
    sortedPaths = list(fonts.keys())
    sortedPaths.sort()
    #
    if shuffleFont:
        shufflePaths = sortedPaths[:]
        shufflePaths.remove(cf.path)
        shuffledPath = random.choice(shufflePaths)
        return fonts[shuffledPath]

    for i in range(len(sortedPaths)):
        if cf.path == fonts[sortedPaths[i]].path:
            prev = fonts[sortedPaths[i - 1]]
            nxt = fonts[sortedPaths[(i + 1) % len(sortedPaths)]]
            if nextFont:
                return nxt
            else:
                return prev
Exemplo n.º 5
0
 def _fontWillClose(self, info):
     """
     Close the window when the last font is closed
     """
     if len(AllFonts()) < 2:
         self.windowClose(self)
         self.w.close()
Exemplo n.º 6
0
    def __init__(self):
        super(VisualReporter, self).__init__()

        self.allFonts = AllFonts()
        self.sortAllFonts()
        self.collectFontNames()

        self.w = Window((0, 0, PLUGIN_WIDTH, 1), PLUGIN_TITLE)

        jumpingY = UI_MARGIN
        self.w.fontsPopUp = PopUpButton(
            (UI_MARGIN, jumpingY, NET_WIDTH,
             vanillaControlsSize['PopUpButtonRegularHeight']),
            self.fontNames,
            callback=None)

        jumpingY += vanillaControlsSize['PopUpButtonRegularHeight'] + UI_MARGIN
        self.w.reportButton = SquareButton(
            (UI_MARGIN, jumpingY, NET_WIDTH,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Generate PDF Report',
            callback=self.reportButtonCallback)
        jumpingY += vanillaControlsSize['ButtonRegularHeight'] * 1.5 + UI_MARGIN

        self.setUpBaseWindowBehavior()
        addObserver(self, 'updateFontOptions', "newFontDidOpen")
        addObserver(self, 'updateFontOptions', "fontDidOpen")
        addObserver(self, 'updateFontOptions', "fontWillClose")
        self.w.bind("close", self.windowCloseCallback)
        self.w.resize(PLUGIN_WIDTH, jumpingY)
        self.w.open()
Exemplo n.º 7
0
 def updateFontOptions(self, notification):
     self.allFonts = AllFonts()
     self.sortAllFonts()
     self.collectFontNames()
     previousFontName = self.w.fontsPopUp.get()
     self.w.fontsPopUp.setItems(self.fontNames)
     if previousFontName in self.fontNames:
         self.w.fontsPopUp.set(self.fontNames.index(previousFontName))
Exemplo n.º 8
0
 def get_fonts(self):
     # get all fonts
     self.all_fonts = AllFonts()
     # get font names
     self.all_fonts_names = []
     if len(self.all_fonts) > 0:
         for font in self.all_fonts:
             self.all_fonts_names.append(get_full_name(font))
Exemplo n.º 9
0
    def initFontsOrder(self):
        if self.fontsOrder is None:
            fontsOrder = [f for f in AllFonts() if f.path is not None]
            self.fontsOrder = sorted(fontsOrder,
                                     key=lambda f: os.path.basename(f.path))
        else:
            newFontsOrder = [f for f in AllFonts() if f in self.fontsOrder] + [
                f for f in AllFonts() if f not in self.fontsOrder
            ]
            self.fontsOrder = newFontsOrder

        for eachFont in self.fontsOrder:
            status, report = checkGroupConflicts(eachFont)
            if status is False:
                self.kerningLogger.error('groups conflict in {}'.format(
                    eachFont.path))
                self.kerningLogger.error(report)
Exemplo n.º 10
0
 def prepareFontsToAction(self):
     if self.whichFont == 'All Fonts':
         fontsToProcess = AllFonts()
     elif self.whichFont == 'Current Font':
         fontsToProcess = [CurrentFont()]
     else:
         fontsToProcess = [self.whichFont]
     return fontsToProcess
Exemplo n.º 11
0
 def updateGlyphList(self):
     if self.activeFontPath == CURRENT_FONT_REPR:
         activeFont = CurrentFont()
     else:
         activeFont = getOpenedFontFromPath(AllFonts(), self.activeFontPath)
     activeGlyphOrder = makeGlyphList(activeFont)
     self.glyphPop.setItems(activeGlyphOrder)
     self.glyphPop.set(activeGlyphOrder.index(self.activeGlyphName))
Exemplo n.º 12
0
    def cleanButtonCallback(self, sender):
        if self.target == 'All Fonts':
            fontsToProcess = AllFonts()
        else:
            fontsToProcess = [CurrentFont()]

        for eachFont in fontsToProcess:
            for eachTargetName, _ in self.transferList:
                if eachTargetName in eachFont:
                    eachFont[eachTargetName].clear()
Exemplo n.º 13
0
    def __init__(self):
        super(AccentedMaker, self).__init__()
        self.initLogger()

        self.fontOptions = ['All Fonts', 'Current Font'] + AllFonts()
        self.whichFont = self.fontOptions[0]
        self.pluginHeight = PLUGIN_HEIGHT

        self.loadAccentedData()
        self.parseGlyphListsFromAccentedData()

        firstKey = self.glyphLists[self.whichAction].keys()[0]
        self.whichGlyphList = self.glyphLists[self.whichAction][firstKey]

        self.w = FloatingWindow((0, 0, PLUGIN_WIDTH, self.pluginHeight),
                                PLUGIN_TITLE)

        self.w.sharedCtrls = SharedCtrls(
            (MARGIN_HOR, MARGIN_VER, NET_WIDTH, 104),
            fontOptions=self.fontOptions,
            whichFont=self.whichFont,
            actions=self.actions,
            whichAction=self.whichAction,
            glyphLists=self.glyphLists,
            whichGlyphList=self.whichGlyphList,
            markColor=self.markColor,
            markEditedGlyphs=self.markEditedGlyphs,
            callback=self.sharedCtrlsCallback)
        self.w.separationLine = HorizontalLine(
            (MARGIN_HOR, self.w.sharedCtrls.getPosSize()[3] + MARGIN_ROW,
             NET_WIDTH, vanillaControlsSize['HorizontalLineThickness']))

        dependantCtrlsHgt = MARGIN_VER + self.w.sharedCtrls.getPosSize(
        )[3] + MARGIN_ROW
        self.w.anchorsCtrls = AnchorsCtrls(
            (MARGIN_HOR, dependantCtrlsHgt, NET_WIDTH, 76),
            callbackAttrs=self.anchorsVarsCallback,
            placeCallback=self.anchorsPlaceCallback,
            deleteCallback=self.anchorsDeleteCallback)

        self.w.buildingCtrls = BuildingCtrls(
            (MARGIN_HOR, dependantCtrlsHgt, NET_WIDTH, 50),
            self.uppercaseAccents,
            callbackAttrs=self.buildingVarsCallback,
            callbackCheck=self.checkAccentedCallback,
            callbackBuild=self.buildAccentedCallback)
        self.w.buildingCtrls.show(False)

        addObserver(self, 'updateFontOptions', "newFontDidOpen")
        addObserver(self, 'updateFontOptions', "fontDidOpen")
        addObserver(self, 'updateFontOptions', "fontWillClose")
        self.w.bind("close", self.windowCloseCallback)
        self.setUpBaseWindowBehavior()
        self.adjustPluginHeight()
        self.w.open()
Exemplo n.º 14
0
    def updateFontList(self, sender):
        self.fontOptions = AllFonts()
        self.w.targetPopUp.setItems([
            '{} {}'.format(font.info.familyName, font.info.styleName)
            for font in self.fontOptions
        ])

        if self.fontOptions:
            self.chosenFont = self.fontOptions[0]
        else:
            self.chosenFont = None
 def get_fonts(self):
     self.all_fonts = AllFonts()
     if len(self.all_fonts) > 0:
         self.all_fonts_names = []
         for f in self.all_fonts:
             font_name = get_full_name(f)
             self.all_fonts_names.append(font_name)
         self.w.source_value.setItems(self.all_fonts_names)
         self.w.target_value.setItems(self.all_fonts_names)
     # no font open
     else:
         print no_font_open
Exemplo n.º 16
0
    def destroy(self):
        CurrentGlyphSubscriber.controller = None
        unregisterCurrentGlyphSubscriber(CurrentGlyphSubscriber)

        GlyphEditorSubscriber.controller = None
        unregisterGlyphEditorSubscriber(GlyphEditorSubscriber)

        FontListManager.controller = None
        unregisterRoboFontSubscriber(FontListManager)

        if DEBUG_MODE:
            for eachFont in AllFonts():
                eachFont.close()
Exemplo n.º 17
0
    def __init__(self):
        self.doMarkGlyphs = 0
        self.doOverwrite = 1
        self.sourceFontList = AllFonts()
        self.destinationFontList = AllFonts()
        self.source_font = self.sourceFontList[0]
        self.destination_fonts = None
        self.glyphs = None
        self.mark = NSColor.redColor()

        sl = []
        for f in self.sourceFontList:
            if f.info.familyName != None:
                fn = f.info.familyName
            else:
                fn = "None"
            if f.info.styleName != None:
                fs = f.info.styleName
            else:
                fs = "None"
            sl.append(fn+" "+fs)

        ## create a window
        self.w = Window((700, 500), "Copy Glyphs", minSize=(700, 500))
        self.w.sourceTitle = TextBox((15, 20, 200, 20), "Source Font:")
        self.w.sourceFont = PopUpButton((15, 42, -410, 20), sl, callback=self.sourceCallback)
        self.w.glyphs = GlyphCollectionView((16, 70, -410, -65), initialMode="list", enableDelete=False, allowDrag=False, selectionCallback=self.glyphCallback)
        self._sortGlyphs(self.source_font)
        self.w.desTitle = TextBox((-400, 20, 200, 20), "Destination Fonts:")
        self.w.destinationFonts = FontList((-400, 42, -15, -115), self.destinationFontList, selectionCallback=self.desCallback)
        self.w.overwrite = CheckBox((-395, -105, 130, 22), "Overwrite glyphs", callback=self.overwriteCallback, value=self.doOverwrite)
        self.w.markGlyphs = CheckBox((-395, -84, 100, 22), "Mark Glyphs", callback=self.markCallback, value=self.doMarkGlyphs)
        self.w.copyButton = Button((-115, -40, 100, 20), 'Copy Glyphs', callback=self.copyCallback)
        self.w.line = HorizontalLine((10, -50, -10, 1))
        self._checkSelection()
        self._updateDest()
        ## open the window
        self.w.open()
Exemplo n.º 18
0
 def button_apply_callback(self, sender):
     all_fonts = AllFonts()
     if len(all_fonts) > 0:
         # get settings
         _decompose = self.w._decompose.get()
         _overlaps = self.w._overlaps.get()
         _autohint = self.w._autohint.get()
         _release_mode = self.w._release_mode.get()
         # print settings
         boolstring = ("False", "True")
         print('generating .otfs for all open fonts...\n')
         print('\totfs folder: %s' % self._otfs_folder)
         print('\tremove overlaps: %s' % boolstring[_overlaps])
         print('\tdecompose: %s' % boolstring[_decompose])
         print('\tautohint: %s' % boolstring[_autohint])
         print('\trelease mode: %s' % boolstring[_release_mode])
         print()
         # batch generate
         self.w.bar.start()
         _undo_name = 'generate all open fonts'
         for font in all_fonts:
             if font.path is not None:
                 _font_path = font.path
                 print('\tgenerating .otf for %s...' %
                       os.path.split(get_full_name(font))[1])
                 # generate otf
                 otf_file = os.path.splitext(os.path.split(
                     font.path)[1])[0] + '.otf'
                 otf_path = os.path.join(self._otfs_folder, otf_file)
                 font.generate(otf_path,
                               'otf',
                               decompose=_decompose,
                               autohint=_autohint,
                               checkOutlines=_overlaps,
                               releaseMode=_release_mode,
                               glyphOrder=[])
                 print('\t\totf path: %s' % otf_path)
                 print('\t\tgeneration sucessful? %s\n' %
                       os.path.exists(otf_path))
             # skip unsaved open fonts
             else:
                 print(
                     '\tskipping "%s", please save this font to file first.\n'
                     % os.path.split(get_full_name(font))[1])
         # done all
         self.w.bar.stop()
         print('...done.\n')
     # no font open
     else:
         print(no_font_open)
Exemplo n.º 19
0
    def glyphPopCallback(self, sender):
        if self.activeFontPath == CURRENT_FONT_REPR:
            activeFont = CurrentFont()
        else:
            activeFont = getOpenedFontFromPath(AllFonts(), self.activeFontPath)

        if sender.get() == 0:
            self.activeGlyphName = CurrentGlyph().name
        elif sender.get() == 1:
            self.activeGlyphName = None
        else:
            self.activeGlyphName = self.glyphPop.getItems()[sender.get()]

        self.callback(self)
Exemplo n.º 20
0
def openFont(nameOrPath, showUI=False):
    """
    Open a font defined by the name of path. If the font is already open
    in RoboFont, then answer.
    """
    if isRoboFont():
        from mojo.roboFont import AllFonts, OpenFont
        for f in AllFonts():
            if nameOrPath == f.info.familyName or f.path.endswith(nameOrPath):
                return f
        assert os.path.exists(nameOrPath)
        return OpenFont(nameOrPath, showUI=showUI)
    # Else not in RoboFont, use plain fontParts instead
    from fontParts.fontshell.font import RFont
    #print('RFONT', nameOrPath)
    return RFont(nameOrPath, showInterface=showUI)
Exemplo n.º 21
0
 def get_fonts(self):
     # get all fonts
     self.all_fonts = AllFonts()
     if len(self.all_fonts) > 0:
         # get font names
         self.all_fonts_names = []
         if len(self.all_fonts) > 0:
             for font in self.all_fonts:
                 self.all_fonts_names.append(get_full_name(font))
         self.all_fonts_names.sort()
         # update UI
         self.w.source_value.setItems(self.all_fonts_names)
         self.w.dest_value.setItems(self.all_fonts_names)
     # no font open
     else:
         print(no_font_open)
Exemplo n.º 22
0
    def fontPopCallback(self, sender):
        if sender.get() > 1:
            self.activeFontPath = self.openedFontPaths[sender.get() - 2]
            activeFont = getOpenedFontFromPath(AllFonts(), self.activeFontPath)
        else:
            self.fontPop.set(0)
            self.activeFontPath = CURRENT_FONT_REPR
            activeFont = CurrentFont()

        activeGlyphOrder = makeGlyphList(activeFont)
        self.glyphPop.setItems(activeGlyphOrder)

        if not activeFont.has_key(self.activeGlyphName):
            self.activeGlyphName = activeGlyphOrder[0]

        self.glyphPop.set(activeGlyphOrder.index(self.activeGlyphName))
        self.callback(self)
Exemplo n.º 23
0
 def toolbarAddOpenFonts(self, sender):
     fonts = AllFonts()
     existingPaths = [item.path() for item in self.paths.get()]
     paths = []
     unSaved = []
     for font in fonts:
         if font.path in existingPaths:
             continue
         if font.path:
             paths.append(font.path)
         else:
             unSaved.append("%s %s" % (font.info.familyName, font.info.styleName))
     if unSaved:
         self.showMessage("Cannot import unsaved fonts.", "\n".join(unSaved))
     items = self._wrapItems(paths)
     items = self.paths.get() + self._wrapItems(paths)
     self.paths.set(items)
Exemplo n.º 24
0
def chooseRightGlyph(aFontPath, aGlyphName):
    if aGlyphName == CURRENT_GLYPH_REPR:
        absGlyphName = CurrentGlyph().name
    else:
        absGlyphName = aGlyphName

    if aFontPath == CURRENT_FONT_REPR:
        absFontPath = CurrentFont().path
    else:
        absFontPath = aFontPath

    for eachFont in AllFonts():
        if eachFont.path == absFontPath:
            if eachFont.has_key(absGlyphName):
                return eachFont[absGlyphName]
    else:
        return None
Exemplo n.º 25
0
 def setInFontCallback(self, sender):
     if self.w.fontSelection.get() == 0:
         if CurrentFont() is not None:
             fonts = [CurrentFont()]
         else:
             fonts = []
     else:
         fonts = AllFonts()
     for f in fonts:
         with f.undo('italicBowtie'):
             f.info.italicAngle = self.getItalicAngle()
             f.lib[self.italicSlantOffsetKey] = self.getItalicSlantOffset()
     try:
         window = CurrentGlyphWindow()
         window.setGlyph(CurrentGlyph().naked())
     except Exception:
         print(self.DEFAULTKEY, 'error resetting window, please refresh it')
     self.updateBowtie()
Exemplo n.º 26
0
    def fontDidCloseCallback(self, notification):
        self.allFonts = AllFonts()

        if self.selectedFont is None and self.allFonts != []:
            self.selectedFont = self.allFonts[0]
            links = loadLinksFromFont(self.selectedFont)
            self.w.linksList.set(links)

        currentFontName = self.w.fontPopUp.getItems()[self.w.fontPopUp.get()]
        newNames = getNamesFrom(self.allFonts)
        self.w.fontPopUp.setItems(newNames)

        if self.allFonts != []:
            if currentName in newNames:
                self.w.fontPopUp.set(newNames.index(currentName))
            else:
                self.w.fontPopUp.set(
                    newNames.index(os.path.basename(self.selectedFont)))
Exemplo n.º 27
0
def getOtherMaster(nextFont=True):
    cf = CurrentFont()
    orderedFonts = []
    fonts = {}
    for f in AllFonts():
        if f.path is None:
            continue
        fonts[f.path]=f
    sortedPaths = list(fonts.keys())
    sortedPaths.sort()

    for i in range(len(sortedPaths)):
        if cf.path == fonts[sortedPaths[i]].path:
            prev = fonts[sortedPaths[i-1]]
            nxt = fonts[sortedPaths[(i+1)%len(sortedPaths)]]
            if nextFont:
                return nxt
            else:
                return prev
Exemplo n.º 28
0
    def fitButtonCallback(self, sender):
        if self.fontTarget == 'All Fonts':
            fontsToProcess = AllFonts()
        else:
            fontsToProcess = [CurrentFont()]

        for eachFont in fontsToProcess:
            if self.glyphTarget == 'All Glyphs':
                glyphNamesToProcess = eachFont.glyphOrder
            elif self.glyphTarget == 'Selection':
                glyphNamesToProcess = CurrentFont().selection
            else:
                glyphNamesToProcess = [CurrentGlyph().name]

            for eachName in glyphNamesToProcess:
                eachGlyph = eachFont[eachName]
                gridFit(eachGlyph,
                        self.gridSize,
                        bcpHandlesFit=self.bcpHandlesFit)
Exemplo n.º 29
0
 def apply_callback(self, sender):
     # batch perform actions
     all_fonts = AllFonts()
     if len(all_fonts) > 0:
         print('transforming all open fonts...\n')
         self.w.bar.start()
         for font in all_fonts:
             print('\ttransforming %s...' % get_full_name(font))
             if self.round:
                 print('\t\trounding...')
                 font.round()
             if self.decompose:
                 print('\t\tdecomposing...')
                 decompose(font)
             if self.overlaps:
                 print('\t\tremoving overlaps...')
                 font.removeOverlap()
             if self.order:
                 print('\t\tauto contour order...')
                 auto_contour_order(font)
             if self.direction:
                 print('\t\tauto contour direction...')
                 auto_contour_direction(font)
             if self.extremes:
                 print('\t\tadding extreme points...')
                 add_extremes(font)
             if self.save:
                 print('\t\tsaving font...')
                 font.save()
             if self.close:
                 print('\t\tclosing font...')
                 font.close()
                 print()
             print('\t...done.\n')
         self.w.bar.stop()
         print('...done.\n')
     # no font open
     else:
         print(no_font_open)
Exemplo n.º 30
0
    def fontDidOpenCallback(self, notification):
        self.allFonts = AllFonts()

        if self.selectedFont is not None:
            previousFontName = self.w.fontPopUp.getItems()[
                self.w.fontPopUp.get()]
        else:
            self.selectedFont = self.allFonts[0]
            previousFontName = None

        newNames = getNamesFrom(self.allFonts)
        self.w.fontPopUp.setItems(newNames)

        if previousFontName is not None:
            self.w.fontPopUp.set(newNames.index(previousFontName))

        links = loadLinksFromFont(self.selectedFont)
        self.w.linksList.set(links)
        self.w.linksList.setSelection([0])
        self.currentRow = self.w.linksList[self.w.linksList.getSelection()[0]]
        self.matchSubscriptions()
        self.matchDisplayedSubscriptions()
Exemplo n.º 31
0
class switchGlyphDialog(object):

    _title = "switch"
    _padding_top = 8
    _padding = 10
    _button_1 = 30
    _button_2 = 18
    _line_height = 18
    _box_height = 23
    _width = 320
    _height = (_button_1 * 3) + (_padding_top * 2)

    _move_default = 70

    def __init__(self):
        # get fonts
        self.all_fonts = AllFonts()
        if len(self.all_fonts) > 0:
            self.w = FloatingWindow(
                        (self._width,
                        self._height),
                        self._title)
            # move buttons
            p = self._padding
            b1 = self._button_1
            b2 = self._button_2
            box = self._box_height
            x = self._padding
            y = self._padding_top
            x1 = x + b1 - 1
            x2 = x + (b1 * 2) - 2
            # buttons
            self.w._up = SquareButton(
                        (x1, y,
                        b1, b1),
                        unichr(8673),
                        callback=self._up_callback)
            self.w._up_right = SquareButton(
                        (x2 + 8, y,
                        b1 - 8, b1 - 8),
                        unichr(8599),
                        callback=self._up_right_callback,
                        sizeStyle='small')
            y += b1 - 1
            self.w._left = SquareButton(
                        (x, y,
                        b1, b1),
                        unichr(8672),
                        callback=self._left_callback)
            self.w._right = SquareButton(
                        (x2, y,
                        b1, b1),
                        unichr(8674),
                        callback=self._right_callback)
            y += b1 - 1
            self.w._down = SquareButton(
                        (x1, y,
                        b1, b1),
                        unichr(8675),
                        callback=self._down_callback)
            self.w._down_left = SquareButton(
                        (x, y + 8,
                        b1 - 8, b1 - 8),
                        unichr(8601),
                        callback=self._down_left_callback,
                        sizeStyle='small')
            # location
            y = p
            x3 = x2 + b1 + 16
            self.w.box_font = Box(
                        (x3, y,
                        -self._padding,
                        self._box_height))
            self.w.box_font.text = TextBox(
                        (5, 0,
                        -self._padding,
                        -0),
                        '',
                        sizeStyle='small')
            y += self._box_height + self._padding_top
            self.w.box_glyph = Box(
                        (x3, y,
                        -self._padding,
                        self._box_height))
            self.w.box_glyph.text = TextBox(
                        (5, 0,
                        -self._padding,
                        -0),
                        '',
                        sizeStyle='small')
            y += self._box_height + self._padding_top
            self.w.box_layer = Box(
                        (x3, y,
                        -self._padding,
                        self._box_height))
            self.w.box_layer.text = TextBox(
                        (5, 0,
                        -self._padding,
                        -0),
                        '',
                        sizeStyle='small')
            # open
            if self.update():
                self.w.open()
        else:
            print 'please open at least one font first.\n'

    # methods

    def next_glyph(self):
        next = next_glyph(self.font, self.glyph_index)
        try:
            self.glyph_window.setGlyphByName(next)
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.setGlyphByName(next)
        self.update()

    def previous_glyph(self):
        prev = previous_glyph(self.font, self.glyph_index)
        try:
            self.glyph_window.setGlyphByName(prev)
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.setGlyphByName(prev)
        self.update()

    def layer_down(self):
        try:
            self.glyph_window.layerDown()
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.layerDown()
        self.update()

    def layer_up(self):
        try:
            self.glyph_window.layerUp()
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.layerUp()
        self.update()

    def _update_text_box(self):
        self.w.box_font.text.set('%s [%s]' % (get_full_name(self.font), self.font_index))
        self.w.box_glyph.text.set('%s [%s]' % (self.glyph.name, self.glyph_index))
        self.w.box_layer.text.set(self.glyph.layerName)

    def update(self):
        self.glyph_window = CurrentGlyphWindow()
        if self.glyph_window is not None:
            self.glyph = CurrentGlyph()
            self.font = self.glyph.getParent()
            self.glyph_index = self.font.glyphOrder.index(self.glyph.name)
            self.font_index = self.all_fonts.index(self.font)
            self._update_text_box()
            return True
        else:
            f = CurrentFont()
            if f is not None:
                self.font = f
                self.font_index = self.all_fonts.index(self.font)
                glyph_names = get_glyphs(f)
                if len(glyph_names) > 0:
                    self.glyph = self.font[glyph_names[0]]
                    self.glyph_index = self.font.glyphOrder.index(self.glyph.name)
                    self.glyph_window = OpenGlyphWindow(self.glyph, newWindow=False)
                    self._update_text_box()
                    return True
                else:
                    print 'please select a glyph first.\n'
                    return False
            else:
                print 'please open a font first.\n'
                return False

    # callbacks

    def _left_callback(self, sender):
        self.previous_glyph()

    def _right_callback(self, sender):
        self.next_glyph()

    def _up_callback(self, sender):
        self.layer_up()

    def _down_callback(self, sender):
        self.layer_down()

    def _up_right_callback(self, sender):
        if len(self.all_fonts) > 1:
            # get next font
            f = CurrentFont()
            i = self.all_fonts.index(f)
            try:
                next_i = i + 1
                next_font = self.all_fonts[next_i]
            except IndexError:
                next_i = 0
                next_font = self.all_fonts[next_i]
            # get glyph
            g_current = CurrentGlyph()
            if g_current is not None:
                if next_font.has_key(g_current.name):
                    next_glyph = next_font[g_current.name]
                else:
                    next_glyph = next_font[next_font.glyphOrder[0]]
                # switch to glyph window
                G = OpenGlyphWindow(next_glyph, newWindow=False)
                # update UI
                self.update()

    def _down_left_callback(self, sender):
        if len(self.all_fonts) > 1:
            # get next font
            f = CurrentFont()
            i = self.all_fonts.index(f)
            try:
                prev_i = i - 1
                prev_font = self.all_fonts[prev_i]
            except IndexError:
                prev_i = -1
                prev_font = self.all_fonts[prev_i]
            # get glyph
            g_current = CurrentGlyph()
            if g_current is not None:
                if prev_font.has_key(g_current.name):
                    prev_glyph = prev_font[g_current.name]
                else:
                    prev_glyph = prev_font[prev_font.glyphOrder[0]]
                # switch to glyph window
                G = OpenGlyphWindow(prev_glyph, newWindow=False)
                # update UI
                self.update()
Exemplo n.º 32
0
class switchGlyphDialog(hDialog):

    """A dialog to navigate through glyphs, fonts and layers of all open fonts.

    .. image:: imgs/glyph/switch.png

    """

    # methods

    def __init__(self):
        # get fonts
        self.get_fonts()
        if len(self.all_fonts) > 0:
            self.title = "switch"
            self.text_height += 3
            self.square_button -= 4
            self.height = (self.square_button * 3) + (self.padding_y * 2)
            self.width = 320
            self.w = HUDFloatingWindow((self.width, self.height), self.title)
            # move buttons
            x = self.padding_x
            y = self.padding_y
            x1 = x + (self.square_button * 1) - 1
            x2 = x + (self.square_button * 2) - 2
            self.w._up = SquareButton(
                        (x1, y,
                        self.square_button,
                        self.square_button),
                        unichr(8673),
                        callback=self._up_callback)
            self.w._up_right = SquareButton(
                        (x2 + 8, y,
                        self.square_button - 8,
                        self.square_button - 8),
                        unichr(8599),
                        callback=self._up_right_callback,
                        sizeStyle=self.size_style)
            y += self.square_button - 1
            self.w._left = SquareButton(
                        (x, y,
                        self.square_button,
                        self.square_button),
                        unichr(8672),
                        callback=self._left_callback)
            self.w._right = SquareButton(
                        (x2, y,
                        self.square_button,
                        self.square_button),
                        unichr(8674),
                        callback=self._right_callback)
            y += self.square_button - 1
            self.w._down_left = SquareButton(
                        (x, y + 8,
                        self.square_button - 8,
                        self.square_button - 8),
                        unichr(8601),
                        callback=self._down_left_callback,
                        sizeStyle=self.size_style)
            self.w._down = SquareButton(
                        (x1, y,
                        self.square_button,
                        self.square_button),
                        unichr(8675),
                        callback=self._down_callback)
            # location
            y = self.padding_y
            x3 = x2 + self.square_button + 16
            self.w.box_font = Box(
                        (x3, y,
                        -self.padding_x,
                        self.text_height))
            self.w.box_font.text = TextBox(
                        (5, 0,
                        -self.padding_x,
                        -0),
                        '',
                        sizeStyle=self.size_style)
            y += self.text_height + self.padding_y
            self.w.box_glyph = Box(
                        (x3, y,
                        -self.padding_x,
                        self.text_height))
            self.w.box_glyph.text = TextBox(
                        (5, 0,
                        -self.padding_x,
                        -0),
                        '',
                        sizeStyle=self.size_style)
            y += self.text_height + self.padding_y
            self.w.box_layer = Box(
                        (x3, y,
                        -self.padding_x,
                        self.text_height))
            self.w.box_layer.text = TextBox(
                        (5, 0,
                        -self.padding_x,
                        -0),
                        '',
                        sizeStyle=self.size_style)
            # open
            if self.update():
                # bind
                # self.w.bind("became key", self.update_callback)
                self.w.bind("close", self.on_close_window)
                # observers
                addObserver(self, "update_callback", "newFontDidOpen")
                addObserver(self, "update_callback", "fontDidOpen")
                addObserver(self, "update_callback", "fontDidClose")
                # open window
                self.w.open()
        else:
            print no_font_open

    # methods

    def get_fonts(self):
        self.all_fonts = AllFonts()

    def next_glyph(self):
        next = next_glyph(self.font, self.glyph_index)
        try:
            self.glyph_window.setGlyphByName(next)
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.setGlyphByName(next)
        self.update()

    def previous_glyph(self):
        prev = previous_glyph(self.font, self.glyph_index)
        try:
            self.glyph_window.setGlyphByName(prev)
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.setGlyphByName(prev)
        self.update()

    def layer_down(self):
        try:
            self.glyph_window.layerDown()
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.layerDown()
        self.update()

    def layer_up(self):
        try:
            self.glyph_window.layerUp()
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.layerUp()
        self.update()

    def _update_text_box(self):
        self.w.box_font.text.set(get_full_name(self.font))
        self.w.box_glyph.text.set(self.glyph.name)
        self.w.box_layer.text.set(self.glyph.layerName)

    def update(self):
        self.glyph_window = CurrentGlyphWindow()
        if self.glyph_window is not None:
            self.glyph = CurrentGlyph()
            self.font = self.glyph.getParent()
            self.glyph_index = self.font.glyphOrder.index(self.glyph.name)
            self.font_index = self.all_fonts.index(self.font)
            self._update_text_box()
            return True
        else:
            f = CurrentFont()
            if f is not None:
                self.font = f
                self.font_index = self.all_fonts.index(self.font)
                glyph_names = get_glyphs(f)
                if len(glyph_names) > 0:
                    self.glyph = self.font[glyph_names[0]]
                    self.glyph_index = self.font.glyphOrder.index(self.glyph.name)
                    self.glyph_window = OpenGlyphWindow(self.glyph, newWindow=False)
                    self._update_text_box()
                    return True
                else:
                    print no_glyph_selected
                    return False
            else:
                print no_font_open
                return False

    # callbacks

    def _left_callback(self, sender):
        self.previous_glyph()

    def _right_callback(self, sender):
        self.next_glyph()

    def _up_callback(self, sender):
        self.layer_up()

    def _down_callback(self, sender):
        self.layer_down()

    def _up_right_callback(self, sender):
        if len(self.all_fonts) > 1:
            # get next font
            f = CurrentFont()
            i = self.all_fonts.index(f)
            try:
                next_i = i + 1
                next_font = self.all_fonts[next_i]
            except IndexError:
                next_i = 0
                next_font = self.all_fonts[next_i]
            # get glyph
            g_current = CurrentGlyph()
            if g_current is not None:
                if next_font.has_key(g_current.name):
                    next_glyph = next_font[g_current.name]
                else:
                    next_glyph = next_font[next_font.glyphOrder[0]]
                # switch to glyph window
                G = OpenGlyphWindow(next_glyph, newWindow=False)
                # update UI
                self.update()

    def _down_left_callback(self, sender):
        if len(self.all_fonts) > 1:
            # get next font
            f = CurrentFont()
            i = self.all_fonts.index(f)
            try:
                prev_i = i - 1
                prev_font = self.all_fonts[prev_i]
            except IndexError:
                prev_i = -1
                prev_font = self.all_fonts[prev_i]
            # get glyph
            g_current = CurrentGlyph()
            if g_current is not None:
                if prev_font.has_key(g_current.name):
                    prev_glyph = prev_font[g_current.name]
                else:
                    prev_glyph = prev_font[prev_font.glyphOrder[0]]
                # switch to glyph window
                G = OpenGlyphWindow(prev_glyph, newWindow=False)
                # update UI
                self.update()

    def update_callback(self, sender):
        self.get_fonts()
        self.update()

    def on_close_window(self, sender):
            removeObserver(self, "newFontDidOpen")
            removeObserver(self, "fontDidOpen")
            removeObserver(self, "fontDidClose")
Exemplo n.º 33
0
 def get_fonts(self):
     self.all_fonts = AllFonts()
Exemplo n.º 34
0
 def __init__(self):
     # get fonts
     self.all_fonts = AllFonts()
     if len(self.all_fonts) > 0:
         self.w = FloatingWindow(
                     (self._width,
                     self._height),
                     self._title)
         # move buttons
         p = self._padding
         b1 = self._button_1
         b2 = self._button_2
         box = self._box_height
         x = self._padding
         y = self._padding_top
         x1 = x + b1 - 1
         x2 = x + (b1 * 2) - 2
         # buttons
         self.w._up = SquareButton(
                     (x1, y,
                     b1, b1),
                     unichr(8673),
                     callback=self._up_callback)
         self.w._up_right = SquareButton(
                     (x2 + 8, y,
                     b1 - 8, b1 - 8),
                     unichr(8599),
                     callback=self._up_right_callback,
                     sizeStyle='small')
         y += b1 - 1
         self.w._left = SquareButton(
                     (x, y,
                     b1, b1),
                     unichr(8672),
                     callback=self._left_callback)
         self.w._right = SquareButton(
                     (x2, y,
                     b1, b1),
                     unichr(8674),
                     callback=self._right_callback)
         y += b1 - 1
         self.w._down = SquareButton(
                     (x1, y,
                     b1, b1),
                     unichr(8675),
                     callback=self._down_callback)
         self.w._down_left = SquareButton(
                     (x, y + 8,
                     b1 - 8, b1 - 8),
                     unichr(8601),
                     callback=self._down_left_callback,
                     sizeStyle='small')
         # location
         y = p
         x3 = x2 + b1 + 16
         self.w.box_font = Box(
                     (x3, y,
                     -self._padding,
                     self._box_height))
         self.w.box_font.text = TextBox(
                     (5, 0,
                     -self._padding,
                     -0),
                     '',
                     sizeStyle='small')
         y += self._box_height + self._padding_top
         self.w.box_glyph = Box(
                     (x3, y,
                     -self._padding,
                     self._box_height))
         self.w.box_glyph.text = TextBox(
                     (5, 0,
                     -self._padding,
                     -0),
                     '',
                     sizeStyle='small')
         y += self._box_height + self._padding_top
         self.w.box_layer = Box(
                     (x3, y,
                     -self._padding,
                     self._box_height))
         self.w.box_layer.text = TextBox(
                     (5, 0,
                     -self._padding,
                     -0),
                     '',
                     sizeStyle='small')
         # open
         if self.update():
             self.w.open()
     else:
         print 'please open at least one font first.\n'