<s> import logging <EOL> import wx <EOL> from matplotlib . backends . backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar <EOL> from matplotlib . widgets import Lasso <EOL> from matplotlib import path <EOL> from matplotlib import dates <EOL> from odmtools . common . logger import LoggerTool <EOL> from odmtools . common . icons . plotToolbar import back , filesave , select , scroll_right , scroll_left , zoom_data , zoom_to_rect , subplots , forward , home , move <EOL> tools = LoggerTool ( ) <EOL> logger = tools . setupLogger ( __name__ , __name__ + '<STR_LIT>' , '<STR_LIT:w>' , logging . DEBUG ) <EOL> def bind ( actor , event , action , id = None ) : <EOL> if id is not None : <EOL> event ( actor , id , action ) <EOL> else : <EOL> event ( actor , action ) <EOL> class MyCustomToolbar ( NavigationToolbar ) : <EOL> '''<STR_LIT>''' <EOL> toolitems = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' , home , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , zoom_data , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , back , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , forward , '<STR_LIT>' ) , <EOL> ( None , None , None , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , move , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , zoom_to_rect , '<STR_LIT>' ) , <EOL> ( None , None , None , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , subplots , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , scroll_left , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , scroll_right , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , filesave , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , select , '<STR_LIT>' ) , <EOL> ) <EOL> def _init_toolbar ( self ) : <EOL> self . _parent = self . canvas . GetParent ( ) <EOL> self . wx_ids = { } <EOL> for text , tooltip_text , image_file , callback in self . toolitems : <EOL> if text is None : <EOL> self . AddSeparator ( ) <EOL> continue <EOL> self . wx_ids [ text ] = wx . NewId ( ) <EOL> if text in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> self . AddCheckTool ( self . wx_ids [ text ] , image_file . GetBitmap ( ) , <EOL> shortHelp = text , longHelp = tooltip_text ) <EOL> else : <EOL> self . AddSimpleTool ( self . wx_ids [ text ] , image_file . GetBitmap ( ) , <EOL> text , tooltip_text ) <EOL> bind ( self , wx . EVT_TOOL , getattr ( self , callback ) , id = self . wx_ids [ text ] ) <EOL> self . Realize ( ) <EOL> def __init__ ( self , plotCanvas , multPlots = False , allowselect = False ) : <EOL> NavigationToolbar . __init__ ( self , plotCanvas ) <EOL> if ( not multPlots ) : <EOL> CONFIGURE_SUBPLOTS_TOOLBAR_BTN_POSITION = <NUM_LIT:8> <EOL> self . DeleteToolByPos ( CONFIGURE_SUBPLOTS_TOOLBAR_BTN_POSITION ) <EOL> if allowselect : <EOL> """<STR_LIT>""" <EOL> self . pan_tool = self . FindById ( self . wx_ids [ '<STR_LIT>' ] ) <EOL> self . zoom_tool = self . FindById ( self . wx_ids [ '<STR_LIT>' ] ) <EOL> self . select_tool = self . FindById ( self . wx_ids [ '<STR_LIT>' ] ) <EOL> self . zoom_to_data = self . FindById ( self . wx_ids [ '<STR_LIT>' ] ) <EOL> wx . EVT_TOOL ( self , self . zoom_tool . Id , self . on_toggle_pan_zoom ) <EOL> wx . EVT_TOOL ( self , self . pan_tool . Id , self . on_toggle_pan_zoom ) <EOL> self . lassoAction = None <EOL> self . select_tool . Enable ( False ) <EOL> self . zoom_to_data . Enable ( False ) <EOL> else : <EOL> ZOOM_DATA_BTN_POSITION = <NUM_LIT:1> <EOL> SELECT_DATA_BTN_POSTITION = self . ToolsCount - <NUM_LIT:1> <EOL> self . DeleteToolByPos ( SELECT_DATA_BTN_POSTITION ) <EOL> self . DeleteToolByPos ( ZOOM_DATA_BTN_POSITION ) <EOL> self . SetToolBitmapSize ( wx . Size ( <NUM_LIT:16> , <NUM_LIT:16> ) ) <EOL> self . AddSeparator ( ) <EOL> self . msg = wx . StaticText ( self , - <NUM_LIT:1> , "<STR_LIT>" ) <EOL> self . AddControl ( self . msg ) <EOL> self . Realize ( ) <EOL> def editSeries ( self , xys , edit ) : <EOL> self . xys = xys <EOL> self . editCurve = edit <EOL> self . select_tool . Enable ( True ) <EOL> self . zoom_to_data . Enable ( True ) <EOL> self . Realize ( ) <EOL> def stopEdit ( self ) : <EOL> self . canvas . mpl_disconnect ( self . lassoAction ) <EOL> self . xys = None <EOL> self . editCurve = None <EOL> self . lassoAction = None <EOL> self . select_tool . Enable ( False ) <EOL> self . zoom_to_data . Enable ( False ) <EOL> self . Realize ( ) <EOL> def _on_custom_pan_left ( self , evt ) : <EOL> ONE_SCREEN = <NUM_LIT:7> <EOL> axes = self . canvas . figure . axes [ <NUM_LIT:0> ] <EOL> x1 , x2 = axes . get_xlim ( ) <EOL> ONE_SCREEN = ( x2 - x1 ) / <NUM_LIT:2> <EOL> axes . set_xlim ( x1 - ONE_SCREEN , x2 - ONE_SCREEN ) <EOL> self . canvas . draw ( ) <EOL> def _on_custom_pan_right ( self , evt ) : <EOL> ONE_SCREEN = <NUM_LIT:7> <EOL> axes = self . canvas . figure . axes [ <NUM_LIT:0> ] <EOL> x1 , x2 = axes . get_xlim ( ) <EOL> ONE_SCREEN = ( x2 - x1 ) / <NUM_LIT:2> <EOL> axes . set_xlim ( x1 + ONE_SCREEN , x2 + ONE_SCREEN ) <EOL> self . canvas . draw ( ) <EOL> def _onPress ( self , event ) : <EOL> self . myEvent = event <EOL> if event . inaxes is None : <EOL> return <EOL> self . lasso = Lasso ( event . inaxes , ( event . xdata , event . ydata ) , self . callback ) <EOL> def callback ( self , verts ) : <EOL> p = path . Path ( verts ) <EOL> ind = p . contains_points ( self . xys ) <EOL> df = self . editCurve . dataTable <EOL> filtered_datetime_dataframe = df [ ind ] <EOL> self . _parent . lassoChangeSelection ( filtered_datetime = filtered_datetime_dataframe ) <EOL> self . canvas . draw_idle ( ) <EOL> del self . lasso <EOL> def untoggle_mpl_tools ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . pan_tool . IsToggled ( ) : <EOL> wx . PostEvent ( self . GetEventHandler ( ) , wx . CommandEvent ( wx . EVT_TOOL . typeId , self . pan_tool . Id ) ) <EOL> self . ToggleTool ( self . pan_tool . Id , False ) <EOL> elif self . zoom_tool . IsToggled ( ) : <EOL> wx . PostEvent ( self . GetEventHandler ( ) , wx . CommandEvent ( wx . EVT_TOOL . typeId , self . zoom_tool . Id ) ) <EOL> self . ToggleTool ( self . zoom_tool . Id , False ) <EOL> def on_toggle_lasso_tool ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if event . Checked ( ) : <EOL> self . untoggle_mpl_tools ( ) <EOL> self . lassoAction = self . canvas . mpl_connect ( '<STR_LIT>' , self . _onPress ) <EOL> else : <EOL> self . canvas . mpl_disconnect ( self . lassoAction ) <EOL> self . lassoAction = None <EOL> def on_toggle_pan_zoom ( self , event ) : <EOL> if event . Checked ( ) : <EOL> self . ToggleTool ( self . select_tool . Id , False ) <EOL> self . canvas . mpl_disconnect ( self . lassoAction ) <EOL> self . lassoAction = None <EOL> event . Skip ( ) <EOL> def on_toggle_zoom_data_tool ( self , event ) : <EOL> if self . _views . empty ( ) : <EOL> self . push_current ( ) <EOL> nodvvals = self . editCurve . dataTable [ self . editCurve . dataTable [ "<STR_LIT>" ] != self . editCurve . noDataValue ] <EOL> axes = self . canvas . figure . axes [ <NUM_LIT:0> ] <EOL> axes . set_ylim ( min ( nodvvals [ "<STR_LIT>" ] ) , max ( nodvvals [ "<STR_LIT>" ] ) ) <EOL> axes . set_xlim ( dates . date2num ( [ min ( nodvvals . index ) , max ( nodvvals . index ) ] ) ) <EOL> self . push_current ( ) <EOL> self . canvas . draw ( ) <EOL> def release_zoom ( self , event ) : <EOL> super ( self . __class__ , self ) . release_zoom ( event ) <EOL> self . canvas . draw ( ) <EOL> def press_pan ( self , event ) : <EOL> super ( self . __class__ , self ) . press_pan ( event ) <EOL> self . canvas . draw ( ) <EOL> def back ( self , event ) : <EOL> super ( self . __class__ , self ) . back ( event ) <EOL> self . canvas . draw ( ) <EOL> def forward ( self , event ) : <EOL> super ( self . __class__ , self ) . forward ( event ) <EOL> self . canvas . draw ( ) <EOL> def home ( self , event ) : <EOL> super ( self . __class__ , self ) . home ( event ) <EOL> self . canvas . draw ( ) </s>
