def apply_callback(self, sender): boolstring = [ False, True ] f = CurrentFont() if f is not None: if len(f.selection) > 0: # print info print 'changing glyph name suffixes...\n' print '\told suffix: %s' % self._old_suffix print '\tnew suffix: %s' % self._new_suffix print '\toverwrite: %s' % boolstring[self._overwrite] print # batch change glyph names for glyph_name in get_glyphs(f): g = f[glyph_name] # get glyphs with matching suffix if has_suffix(g, self._old_suffix): # make new name if len(self._new_suffix) > 0: _new_name = change_suffix(g, self._old_suffix, self._new_suffix) else: _new_name = change_suffix(g, self._old_suffix, None) # if new name not in font, rename if not f.has_key(_new_name): print '\trenaming %s to %s...' % (glyph_name, _new_name) g.name = _new_name # new name in font else: # overwrite existing if self._overwrite: print "\toverwriting '%s' with '%s'" % (_new_name, glyph_name) f.removeGlyph(_new_name) f.update() g.name = _new_name g.update() # do not overwrite else: print "\t'%s' already exists in font, skipping '%s'" % (_new_name, glyph_name) # glyph name does not have suffix else: pass # done glyph # done font f.update() print print '...done.\n' # no glyph selected else: print 'please select one or more glyphs before running the script.\n' # no glyph selected else: print 'please open a font first.\n' pass
def set_element_callback(self, sender): font = CurrentFont() if font is not None: # get parameters shape = self.shapes[self.w.shape.get()] scale = float(self.w.spinner_size.value.get()) magic = float(self.w.spinner_magic.value.get()) # create element glyph if not font.has_key(self.element_glyph): font.newGlyph(self.element_glyph) # draw element shape font[self.element_glyph].prepareUndo('set element') set_element(font, scale, type=shape, magic=magic, element_=self.element_glyph) font[self.element_glyph].performUndo() # no font open else: print no_font_open
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)
def set_element_callback(self, sender): font = CurrentFont() if font is not None: # get parameters shape = self.shapes[self.w.shape.get()] scale = float(self.w.spinner_size.value.get()) magic = float(self.w.spinner_magic.value.get()) # create element glyph if not font.has_key(self.element_glyph): font.newGlyph(self.element_glyph) # draw element shape font[self.element_glyph].prepareUndo('set element') set_element(font, scale, type=shape, magic=magic, element_src=self.element_glyph) font[self.element_glyph].performUndo() # no font open else: print no_font_open
def apply_callback(self, sender): # get font f = CurrentFont() if f is not None: glyph_names = get_glyphs(f) if len(glyph_names) > 0: boolstring = [ False, True ] # get parameters self.old_suffix = self.w.old_suffix_value.get() self.new_suffix = self.w.new_suffix_value.get() self.overwrite = self.w.overwrite_checkbox.get() # print info print 'changing glyph name suffixes...\n' print '\told suffix: %s' % (self.old_suffix) print '\tnew suffix: %s' % (self.new_suffix) print '\toverwrite: %s' % boolstring[self.overwrite] print # batch change glyph names for glyph_name in glyph_names: g = f[glyph_name] # get glyphs with matching suffix if has_suffix(g, self.old_suffix): # switch suffixes : one.osf -> one.onum if len(self.old_suffix) > 0 and len(self.new_suffix) > 0: new_name = change_suffix(g, self.old_suffix, self.new_suffix) # remove suffix : one.osf -> one elif len(self.old_suffix) > 0 and len(self.new_suffix) == 0: new_name = change_suffix(g, self.old_suffix, None) # add suffix : one -> one.onum elif len(self.old_suffix) == 0 and len(self.new_suffix) > 0: new_name = '%s.%s' % (glyph_name, self.new_suffix) else: new_name = glyph_name # new name not in font (rename) if new_name != glyph_name: if not f.has_key(new_name): print '\trenaming %s to %s...' % (glyph_name, new_name) g.name = new_name # new name in font else: # overwrite if self._overwrite: print "\toverwriting '%s' with '%s'" % (new_name, glyph_name) f.removeGlyph(_new_name) f.update() g.name = new_name g.update() # do not overwrite else: print "\t'%s' already exists in font, skipping '%s'" % (new_name, glyph_name) # glyph does not have suffix else: pass # done glyph # done font f.update() print print '...done.\n' # no glyph selected else: print no_glyph_selected # no font open else: print no_font_open pass
def apply_callback(self, sender): # get font f = CurrentFont() if f is not None: glyph_names = get_glyphs(f) if len(glyph_names) > 0: boolstring = [False, True] # get parameters self.old_suffix = self.w.old_suffix_value.get() self.new_suffix = self.w.new_suffix_value.get() self.overwrite = self.w.overwrite_checkbox.get() # print info print 'changing glyph name suffixes...\n' print '\told suffix: %s' % (self.old_suffix) print '\tnew suffix: %s' % (self.new_suffix) print '\toverwrite: %s' % boolstring[self.overwrite] print # batch change glyph names for glyph_name in glyph_names: g = f[glyph_name] # get glyphs with matching suffix if has_suffix(g, self.old_suffix): # switch suffixes : one.osf -> one.onum if len(self.old_suffix) > 0 and len( self.new_suffix) > 0: new_name = change_suffix(g, self.old_suffix, self.new_suffix) # remove suffix : one.osf -> one elif len(self.old_suffix) > 0 and len( self.new_suffix) == 0: new_name = change_suffix(g, self.old_suffix, None) # add suffix : one -> one.onum elif len(self.old_suffix) == 0 and len( self.new_suffix) > 0: new_name = '%s.%s' % (glyph_name, self.new_suffix) else: new_name = glyph_name # new name not in font (rename) if new_name != glyph_name: if not f.has_key(new_name): print '\trenaming %s to %s...' % (glyph_name, new_name) g.name = new_name # new name in font else: # overwrite if self._overwrite: print "\toverwriting '%s' with '%s'" % ( new_name, glyph_name) f.removeGlyph(_new_name) f.update() g.name = new_name g.update() # do not overwrite else: print "\t'%s' already exists in font, skipping '%s'" % ( new_name, glyph_name) # glyph does not have suffix else: pass # done glyph # done font f.update() print print '...done.\n' # no glyph selected else: print no_glyph_selected # no font open else: print no_font_open pass