<s> import wx <EOL> from . wx_control import WxControl <EOL> from matplotlib . backends . backend_wxagg import FigureCanvasWxAgg <EOL> from matplotlib . backends . backend_wx import NavigationToolbar2Wx <EOL> class WxMPLCanvas ( WxControl ) : <EOL> """<STR_LIT>""" <EOL> _figure = None <EOL> _toolbar_visible = False <EOL> def create_widget ( self , parent , tree ) : <EOL> """<STR_LIT>""" <EOL> widget = wx . Panel ( parent ) <EOL> sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> widget . SetSizer ( sizer ) <EOL> return widget <EOL> def create ( self , tree ) : <EOL> """<STR_LIT>""" <EOL> super ( WxMPLCanvas , self ) . create ( tree ) <EOL> self . _figure = tree [ '<STR_LIT>' ] <EOL> self . _toolbar_visible = tree [ '<STR_LIT>' ] <EOL> def init_layout ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( WxMPLCanvas , self ) . init_layout ( ) <EOL> self . refresh_mpl_widget ( notify = False ) <EOL> def on_action_set_figure ( self , content ) : <EOL> """<STR_LIT>""" <EOL> self . _figure = content [ '<STR_LIT>' ] <EOL> self . refresh_mpl_widget ( ) <EOL> def on_action_set_toolbar_visible ( self , content ) : <EOL> """<STR_LIT>""" <EOL> visible = content [ '<STR_LIT>' ] <EOL> self . _toolbar_visible = visible <EOL> widget = self . widget ( ) <EOL> sizer = widget . GetSizer ( ) <EOL> children = sizer . GetChildren ( ) <EOL> if len ( children ) == <NUM_LIT:2> : <EOL> widget . Freeze ( ) <EOL> old_hint = widget . GetBestSize ( ) <EOL> toolbar = children [ <NUM_LIT:0> ] <EOL> toolbar . Show ( visible ) <EOL> new_hint = widget . GetBestSize ( ) <EOL> if old_hint != new_hint : <EOL> self . size_hint_updated ( ) <EOL> sizer . Layout ( ) <EOL> widget . Thaw ( ) <EOL> def refresh_mpl_widget ( self , notify = True ) : <EOL> """<STR_LIT>""" <EOL> widget = self . widget ( ) <EOL> widget . Freeze ( ) <EOL> if notify : <EOL> old_hint = widget . GetBestSize ( ) <EOL> sizer = widget . GetSizer ( ) <EOL> sizer . Clear ( True ) <EOL> figure = self . _figure <EOL> if figure is not None : <EOL> canvas = FigureCanvasWxAgg ( widget , - <NUM_LIT:1> , figure ) <EOL> toolbar = NavigationToolbar2Wx ( canvas ) <EOL> toolbar . Show ( self . _toolbar_visible ) <EOL> sizer . Add ( toolbar , <NUM_LIT:0> , wx . EXPAND ) <EOL> sizer . Add ( canvas , <NUM_LIT:1> , wx . EXPAND ) <EOL> if notify : <EOL> new_hint = widget . GetBestSize ( ) <EOL> if old_hint != new_hint : <EOL> self . size_hint_updated ( ) <EOL> sizer . Layout ( ) <EOL> widget . Thaw ( ) </s>
