<s> try : <EOL> from mojo . roboFont import CurrentFont <EOL> except ImportError : <EOL> from robofab . world import CurrentFont <EOL> from vanilla import * <EOL> from hTools2 import hDialog <EOL> from hTools2 . modules . fontutils import get_glyphs <EOL> from hTools2 . modules . glyphutils import has_suffix , change_suffix <EOL> from hTools2 . modules . messages import no_font_open , no_glyph_selected <EOL> class changeSuffixDialog ( hDialog ) : <EOL> """<STR_LIT>""" <EOL> old_suffix = '<STR_LIT>' <EOL> new_suffix = '<STR_LIT>' <EOL> overwrite = True <EOL> def __init__ ( self ) : <EOL> self . title = '<STR_LIT>' <EOL> self . height = ( self . text_height * <NUM_LIT:3> ) + ( self . padding_y * <NUM_LIT:5> ) + self . button_height <EOL> self . column_1 = <NUM_LIT> <EOL> self . column_2 = <NUM_LIT> <EOL> self . w = FloatingWindow ( ( self . width , self . height ) , self . title , ) <EOL> x = self . padding_x <EOL> y = self . padding_y <EOL> self . w . old_suffix_label = TextBox ( <EOL> ( x , y , <EOL> self . column_1 , <EOL> self . text_height ) , <EOL> "<STR_LIT>" , <EOL> sizeStyle = self . size_style ) <EOL> x += self . column_1 <EOL> self . w . old_suffix_value = EditText ( <EOL> ( x , y , <EOL> self . column_2 , <EOL> self . text_height ) , <EOL> text = self . old_suffix , <EOL> placeholder = '<STR_LIT>' , <EOL> sizeStyle = self . size_style ) <EOL> x = self . padding_x <EOL> y += ( self . text_height + self . padding_y ) <EOL> self . w . new_suffix_label = TextBox ( <EOL> ( x , y , <EOL> self . column_1 , <EOL> self . text_height ) , <EOL> "<STR_LIT>" , <EOL> sizeStyle = self . size_style ) <EOL> x += self . column_1 <EOL> self . w . new_suffix_value = EditText ( <EOL> ( x , y , <EOL> self . column_2 , <EOL> self . text_height ) , <EOL> text = self . new_suffix , <EOL> placeholder = '<STR_LIT>' , <EOL> sizeStyle = self . size_style ) <EOL> y += ( self . text_height + self . padding_y ) <EOL> self . w . overwrite_checkbox = CheckBox ( <EOL> ( x , y , <EOL> - self . padding_x , <EOL> self . text_height ) , <EOL> "<STR_LIT>" , <EOL> value = self . overwrite , <EOL> sizeStyle = self . size_style ) <EOL> x = self . padding_x <EOL> y += ( self . text_height + self . padding_y ) <EOL> self . w . button_apply = SquareButton ( <EOL> ( x , y , <EOL> - self . padding_x , <EOL> self . button_height ) , <EOL> "<STR_LIT>" , <EOL> callback = self . apply_callback , <EOL> sizeStyle = self . size_style ) <EOL> self . w . open ( ) <EOL> def apply_callback ( self , sender ) : <EOL> f = CurrentFont ( ) <EOL> if f is not None : <EOL> glyph_names = get_glyphs ( f ) <EOL> if len ( glyph_names ) > <NUM_LIT:0> : <EOL> boolstring = [ False , True ] <EOL> self . old_suffix = self . w . old_suffix_value . get ( ) <EOL> self . new_suffix = self . w . new_suffix_value . get ( ) <EOL> self . overwrite = self . w . overwrite_checkbox . get ( ) <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' % ( self . old_suffix ) <EOL> print '<STR_LIT>' % ( self . new_suffix ) <EOL> print '<STR_LIT>' % boolstring [ self . overwrite ] <EOL> print <EOL> for glyph_name in glyph_names : <EOL> g = f [ glyph_name ] <EOL> if has_suffix ( g , self . old_suffix ) : <EOL> if len ( self . old_suffix ) > <NUM_LIT:0> and len ( self . new_suffix ) > <NUM_LIT:0> : <EOL> new_name = change_suffix ( g , self . old_suffix , self . new_suffix ) <EOL> elif len ( self . old_suffix ) > <NUM_LIT:0> and len ( self . new_suffix ) == <NUM_LIT:0> : <EOL> new_name = change_suffix ( g , self . old_suffix , None ) <EOL> elif len ( self . old_suffix ) == <NUM_LIT:0> and len ( self . new_suffix ) > <NUM_LIT:0> : <EOL> new_name = '<STR_LIT>' % ( glyph_name , self . new_suffix ) <EOL> else : <EOL> new_name = glyph_name <EOL> if new_name != glyph_name : <EOL> if not f . has_key ( new_name ) : <EOL> print '<STR_LIT>' % ( glyph_name , new_name ) <EOL> g . name = new_name <EOL> else : <EOL> if self . _overwrite : <EOL> print "<STR_LIT>" % ( new_name , glyph_name ) <EOL> f . removeGlyph ( _new_name ) <EOL> f . update ( ) <EOL> g . name = new_name <EOL> g . update ( ) <EOL> else : <EOL> print "<STR_LIT>" % ( new_name , glyph_name ) <EOL> else : <EOL> pass <EOL> f . update ( ) <EOL> print <EOL> print '<STR_LIT>' <EOL> else : <EOL> print no_glyph_selected <EOL> else : <EOL> print no_font_open <EOL> pass </s>
