<s> import hTools2 . dialogs . misc <EOL> reload ( hTools2 . dialogs . misc ) <EOL> try : <EOL> from mojo . roboFont import AllFonts <EOL> from mojo . events import addObserver , removeObserver <EOL> except ImportError : <EOL> from robofab . world import AllFonts <EOL> from vanilla import * <EOL> from hTools2 import hDialog <EOL> from hTools2 . dialogs . misc import Spinner <EOL> from hTools2 . modules . fontutils import get_full_name , get_glyphs <EOL> from hTools2 . modules . messages import no_glyph_selected , no_font_open <EOL> class interpolateGlyphsDialog ( hDialog ) : <EOL> """<STR_LIT>""" <EOL> all_fonts = [ ] <EOL> all_fonts_names = [ ] <EOL> factor_x = <NUM_LIT> <EOL> factor_y = <NUM_LIT> <EOL> def __init__ ( self ) : <EOL> self . _get_fonts ( ) <EOL> self . title = '<STR_LIT>' <EOL> self . height = ( self . nudge_button * <NUM_LIT:4> ) + ( self . text_height * <NUM_LIT:6> ) + self . progress_bar + ( self . padding_y * <NUM_LIT:8> ) + ( self . button_height ) - <NUM_LIT:10> <EOL> self . value_box = <NUM_LIT> <EOL> self . column_2 = self . value_box + ( self . nudge_button * <NUM_LIT:7> ) - <NUM_LIT:6> <EOL> self . w = FloatingWindow ( ( self . width , self . height ) , self . title ) <EOL> x = self . padding_x <EOL> y = self . padding_y - <NUM_LIT:8> <EOL> self . w . _f1_label = TextBox ( <EOL> ( x , y + <NUM_LIT:3> , <EOL> - self . padding_x , <EOL> self . text_height ) , <EOL> "<STR_LIT>" , <EOL> sizeStyle = self . size_style ) <EOL> y += self . text_height <EOL> self . w . _f1_font = PopUpButton ( <EOL> ( x , y , <EOL> - self . padding_x , <EOL> self . text_height ) , <EOL> self . all_fonts_names , <EOL> sizeStyle = self . size_style ) <EOL> y += self . text_height <EOL> self . w . _f2_label = TextBox ( <EOL> ( x , y + <NUM_LIT:3> , <EOL> - self . padding_x , <EOL> self . text_height ) , <EOL> "<STR_LIT>" , <EOL> sizeStyle = self . size_style ) <EOL> y += self . text_height <EOL> self . w . _f2_font = PopUpButton ( <EOL> ( x , y , <EOL> - self . padding_x , <EOL> self . text_height ) , <EOL> self . all_fonts_names , <EOL> sizeStyle = self . size_style ) <EOL> y += self . text_height <EOL> self . w . _f3_label = TextBox ( <EOL> ( x , y + <NUM_LIT:3> , <EOL> - self . padding_x , <EOL> self . text_height ) , <EOL> "<STR_LIT>" , <EOL> sizeStyle = self . size_style ) <EOL> y += self . text_height <EOL> self . w . _f3_font = PopUpButton ( <EOL> ( x , y , <EOL> - self . padding_x , <EOL> self . text_height ) , <EOL> self . all_fonts_names , <EOL> sizeStyle = self . size_style ) <EOL> x = <NUM_LIT:0> <EOL> y += ( self . text_height + self . padding_y ) <EOL> self . w . _factor_x = Spinner ( <EOL> ( x , y ) , <EOL> default = '<STR_LIT>' , <EOL> scale = <NUM_LIT> , <EOL> integer = False , <EOL> label = '<STR_LIT>' ) <EOL> y += self . w . _factor_x . getPosSize ( ) [ <NUM_LIT:3> ] <EOL> self . w . _factor_y = Spinner ( <EOL> ( x , y ) , <EOL> default = '<STR_LIT>' , <EOL> scale = <NUM_LIT> , <EOL> integer = False , <EOL> label = '<STR_LIT>' ) <EOL> y += self . w . _factor_y . getPosSize ( ) [ <NUM_LIT:3> ] <EOL> x = self . padding_x <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> y += ( self . button_height + self . padding_y ) <EOL> self . w . bar = ProgressBar ( <EOL> ( x , y , <EOL> - self . padding_x , <EOL> self . progress_bar ) , <EOL> isIndeterminate = True , <EOL> sizeStyle = self . size_style ) <EOL> self . w . bind ( "<STR_LIT>" , self . update_callback ) <EOL> self . w . bind ( "<STR_LIT>" , self . on_close_window ) <EOL> addObserver ( self , "<STR_LIT>" , "<STR_LIT>" ) <EOL> addObserver ( self , "<STR_LIT>" , "<STR_LIT>" ) <EOL> addObserver ( self , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . w . open ( ) <EOL> def _get_fonts ( self ) : <EOL> self . all_fonts = AllFonts ( ) <EOL> self . all_fonts_names = [ ] <EOL> if len ( self . all_fonts ) > <NUM_LIT:0> : <EOL> for font in self . all_fonts : <EOL> self . all_fonts_names . append ( get_full_name ( font ) ) <EOL> def update_callback ( self , sender ) : <EOL> self . _get_fonts ( ) <EOL> self . w . _f1_font . setItems ( self . all_fonts_names ) <EOL> self . w . _f2_font . setItems ( self . all_fonts_names ) <EOL> self . w . _f3_font . setItems ( self . all_fonts_names ) <EOL> def apply_callback ( self , sender ) : <EOL> try : <EOL> f1 = self . all_fonts [ self . w . _f1_font . get ( ) ] <EOL> f2 = self . all_fonts [ self . w . _f2_font . get ( ) ] <EOL> f3 = self . all_fonts [ self . w . _f3_font . get ( ) ] <EOL> glyph_names = get_glyphs ( f1 ) <EOL> if len ( glyph_names ) > <NUM_LIT:0> : <EOL> x = float ( self . w . _factor_x . value . get ( ) ) <EOL> y = float ( self . w . _factor_y . value . get ( ) ) <EOL> print '<STR_LIT>' <EOL> boolstring = ( False , True ) <EOL> print '<STR_LIT>' % get_full_name ( f1 ) <EOL> print '<STR_LIT>' % get_full_name ( f2 ) <EOL> print '<STR_LIT>' % get_full_name ( f3 ) <EOL> print <EOL> print '<STR_LIT>' % x <EOL> print '<STR_LIT>' % y <EOL> print <EOL> print '<STR_LIT:\t>' , <EOL> self . w . bar . start ( ) <EOL> for glyph_name in glyph_names : <EOL> if f2 . has_key ( glyph_name ) : <EOL> f3 . newGlyph ( glyph_name , clear = True ) <EOL> f3 [ glyph_name ] . prepareUndo ( '<STR_LIT>' ) <EOL> print glyph_name , <EOL> f3 [ glyph_name ] . interpolate ( ( x , y ) , f1 [ glyph_name ] , f2 [ glyph_name ] ) <EOL> f3 [ glyph_name ] . update ( ) <EOL> f3 [ glyph_name ] . performUndo ( ) <EOL> else : <EOL> print '<STR_LIT>' % glyph_name <EOL> f3 . update ( ) <EOL> self . w . bar . stop ( ) <EOL> print <EOL> print '<STR_LIT>' <EOL> else : <EOL> print no_glyph_selected <EOL> except : <EOL> print no_font_open <EOL> def on_close_window ( self , sender ) : <EOL> removeObserver ( self , "<STR_LIT>" ) <EOL> removeObserver ( self , "<STR_LIT>" ) <EOL> removeObserver ( self , "<STR_LIT>" ) </s>
