<s> from . . util import SimpleBunch <EOL> import time <EOL> from timeit import default_timer <EOL> class BaseApplicationBackend ( object ) : <EOL> """<STR_LIT>""" <EOL> def _vispy_get_backend_name ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def _vispy_process_events ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def _vispy_run ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def _vispy_reuse ( self ) : <EOL> pass <EOL> def _vispy_quit ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def _vispy_get_native_app ( self ) : <EOL> return self <EOL> def _vispy_sleep ( self , duration_sec ) : <EOL> time . sleep ( duration_sec ) <EOL> class BaseCanvasBackend ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , vispy_canvas ) : <EOL> from . canvas import Canvas <EOL> assert isinstance ( vispy_canvas , Canvas ) <EOL> self . _vispy_canvas = vispy_canvas <EOL> self . _last_time = <NUM_LIT:0> <EOL> vispy_canvas . _backend = self <EOL> self . _vispy_mouse_data = { <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> } <EOL> def _process_backend_kwargs ( self , kwargs ) : <EOL> """<STR_LIT>""" <EOL> app = self . _vispy_canvas . app <EOL> capability = app . backend_module . capability <EOL> if kwargs [ '<STR_LIT>' ] . shared . name : <EOL> if not capability [ '<STR_LIT>' ] : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> for key in [ key for ( key , val ) in capability . items ( ) if not val ] : <EOL> if key in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> continue <EOL> invert = key in [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if bool ( kwargs [ key ] ) - invert : <EOL> raise RuntimeError ( '<STR_LIT>' <EOL> % ( key , app . backend_name ) ) <EOL> out = SimpleBunch ( ) <EOL> keys = [ '<STR_LIT:title>' , '<STR_LIT:size>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> ] <EOL> for key in keys : <EOL> out [ key ] = kwargs [ key ] <EOL> return out <EOL> def _vispy_set_current ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def _vispy_swap_buffers ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def _vispy_set_title ( self , title ) : <EOL> raise NotImplementedError ( ) <EOL> def _vispy_set_size ( self , w , h ) : <EOL> raise NotImplementedError ( ) <EOL> def _vispy_set_position ( self , x , y ) : <EOL> raise NotImplementedError ( ) <EOL> def _vispy_set_visible ( self , visible ) : <EOL> raise NotImplementedError ( ) <EOL> def _vispy_set_fullscreen ( self , fullscreen ) : <EOL> raise NotImplementedError ( ) <EOL> def _vispy_update ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def _vispy_close ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def _vispy_get_size ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def _vispy_get_physical_size ( self ) : <EOL> return self . _vispy_get_size ( ) <EOL> def _vispy_get_position ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def _vispy_get_fullscreen ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def _vispy_get_geometry ( self ) : <EOL> x , y = self . _vispy_get_position ( ) <EOL> w , h = self . _vispy_get_size ( ) <EOL> return x , y , w , h <EOL> def _vispy_get_native_canvas ( self ) : <EOL> return self <EOL> def _vispy_mouse_press ( self , ** kwargs ) : <EOL> kwargs . update ( self . _vispy_mouse_data ) <EOL> ev = self . _vispy_canvas . events . mouse_press ( ** kwargs ) <EOL> if self . _vispy_mouse_data [ '<STR_LIT>' ] is None : <EOL> self . _vispy_mouse_data [ '<STR_LIT>' ] = ev <EOL> self . _vispy_mouse_data [ '<STR_LIT>' ] . append ( ev . button ) <EOL> self . _vispy_mouse_data [ '<STR_LIT>' ] = ev <EOL> if not getattr ( self , '<STR_LIT>' , False ) : <EOL> self . _vispy_detect_double_click ( ev ) <EOL> return ev <EOL> def _vispy_mouse_move ( self , ** kwargs ) : <EOL> if default_timer ( ) - self . _last_time < <NUM_LIT> : <EOL> return <EOL> self . _last_time = default_timer ( ) <EOL> kwargs . update ( self . _vispy_mouse_data ) <EOL> if self . _vispy_mouse_data [ '<STR_LIT>' ] is None : <EOL> last_event = self . _vispy_mouse_data [ '<STR_LIT>' ] <EOL> if last_event is not None : <EOL> last_event . _forget_last_event ( ) <EOL> else : <EOL> kwargs [ '<STR_LIT>' ] = self . _vispy_mouse_data [ '<STR_LIT>' ] . button <EOL> ev = self . _vispy_canvas . events . mouse_move ( ** kwargs ) <EOL> self . _vispy_mouse_data [ '<STR_LIT>' ] = ev <EOL> return ev <EOL> def _vispy_mouse_release ( self , ** kwargs ) : <EOL> kwargs . update ( self . _vispy_mouse_data ) <EOL> ev = self . _vispy_canvas . events . mouse_release ( ** kwargs ) <EOL> if ( self . _vispy_mouse_data [ '<STR_LIT>' ] <EOL> and self . _vispy_mouse_data [ '<STR_LIT>' ] . button == ev . button ) : <EOL> self . _vispy_mouse_data [ '<STR_LIT>' ] = None <EOL> if ev . button in self . _vispy_mouse_data [ '<STR_LIT>' ] : <EOL> self . _vispy_mouse_data [ '<STR_LIT>' ] . remove ( ev . button ) <EOL> self . _vispy_mouse_data [ '<STR_LIT>' ] = ev <EOL> return ev <EOL> def _vispy_mouse_double_click ( self , ** kwargs ) : <EOL> kwargs . update ( self . _vispy_mouse_data ) <EOL> ev = self . _vispy_canvas . events . mouse_double_click ( ** kwargs ) <EOL> self . _vispy_mouse_data [ '<STR_LIT>' ] = ev <EOL> return ev <EOL> def _vispy_detect_double_click ( self , ev , ** kwargs ) : <EOL> dt_max = <NUM_LIT> <EOL> lastev = self . _vispy_mouse_data [ '<STR_LIT>' ] <EOL> if lastev is None : <EOL> self . _vispy_mouse_data [ '<STR_LIT>' ] = ev <EOL> return <EOL> assert lastev . type == '<STR_LIT>' <EOL> assert ev . type == '<STR_LIT>' <EOL> if ( ( ev . time - lastev . time <= dt_max ) & <EOL> ( lastev . pos [ <NUM_LIT:0> ] - ev . pos [ <NUM_LIT:0> ] == <NUM_LIT:0> ) & <EOL> ( lastev . pos [ <NUM_LIT:1> ] - ev . pos [ <NUM_LIT:1> ] == <NUM_LIT:0> ) & <EOL> ( lastev . button == ev . button ) ) : <EOL> self . _vispy_mouse_double_click ( ** kwargs ) <EOL> self . _vispy_mouse_data [ '<STR_LIT>' ] = ev <EOL> class BaseTimerBackend ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , vispy_timer ) : <EOL> self . _vispy_timer = vispy_timer <EOL> def _vispy_start ( self , interval ) : <EOL> raise NotImplementedError <EOL> def _vispy_stop ( self ) : <EOL> raise NotImplementedError <EOL> def _vispy_get_native_timer ( self ) : <EOL> return self </s>
