<s> """<STR_LIT>""" <EOL> from math import log10 , floor <EOL> import string <EOL> import wx <EOL> class EmbeddedPylab ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , canvas ) : <EOL> from matplotlib . backend_bases import FigureManagerBase <EOL> self . fm = FigureManagerBase ( canvas , - <NUM_LIT:1> ) <EOL> def __enter__ ( self ) : <EOL> import pylab <EOL> from matplotlib . _pylab_helpers import Gcf <EOL> Gcf . set_active ( self . fm ) <EOL> return pylab <EOL> def __exit__ ( self , * args , ** kw ) : <EOL> from matplotlib . _pylab_helpers import Gcf <EOL> Gcf . _activeQue = [ f for f in Gcf . _activeQue if f is not self . fm ] <EOL> try : <EOL> del Gcf . figs [ - <NUM_LIT:1> ] <EOL> except KeyError : <EOL> pass <EOL> class Validator ( wx . PyValidator ) : <EOL> def __init__ ( self , flag ) : <EOL> wx . PyValidator . __init__ ( self ) <EOL> self . flag = flag <EOL> self . Bind ( wx . EVT_CHAR , self . OnChar ) <EOL> def Clone ( self ) : <EOL> return Validator ( self . flag ) <EOL> def Validate ( self , win ) : <EOL> return True <EOL> def TransferToWindow ( self ) : <EOL> return True <EOL> def TransferFromWindow ( self ) : <EOL> return True <EOL> def OnChar ( self , evt ) : <EOL> key = chr ( evt . GetKeyCode ( ) ) <EOL> if self . flag == "<STR_LIT>" and key in string . letters : <EOL> return <EOL> if self . flag == "<STR_LIT>" and key in string . digits : <EOL> return <EOL> evt . Skip ( ) <EOL> def nice ( v , digits = <NUM_LIT:4> ) : <EOL> """<STR_LIT>""" <EOL> if v == <NUM_LIT:0.> : <EOL> return v <EOL> else : <EOL> sign = v / abs ( v ) <EOL> place = floor ( log10 ( abs ( v ) ) ) <EOL> scale = <NUM_LIT:10> ** ( place - ( digits - <NUM_LIT:1> ) ) <EOL> return sign * floor ( abs ( v ) / scale + <NUM_LIT:0.5> ) * scale </s>
