<s> from ginga . web . pgw . ImageViewPg import CanvasView , ImageViewCanvas <EOL> from ginga . web . pgw import Widgets <EOL> from ginga . misc import Bunch <EOL> class GingaViewerWidget ( Widgets . Canvas ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , viewer = None , width = <NUM_LIT> , height = <NUM_LIT> ) : <EOL> super ( GingaViewerWidget , self ) . __init__ ( width = <NUM_LIT> , height = <NUM_LIT> ) <EOL> if viewer is None : <EOL> viewer = CanvasView ( logger ) <EOL> self . logger = viewer . logger <EOL> self . _configured = False <EOL> self . refresh_delay = <NUM_LIT> <EOL> self . set_viewer ( viewer ) <EOL> def set_viewer ( self , viewer ) : <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> self . viewer = viewer <EOL> self . _dispatch_event_table = { <EOL> "<STR_LIT>" : self . ignore_event , <EOL> "<STR_LIT>" : self . map_event_cb , <EOL> "<STR_LIT>" : viewer . button_press_event , <EOL> "<STR_LIT>" : viewer . button_release_event , <EOL> "<STR_LIT>" : viewer . motion_notify_event , <EOL> "<STR_LIT>" : viewer . leave_notify_event , <EOL> "<STR_LIT>" : viewer . enter_notify_event , <EOL> "<STR_LIT>" : viewer . scroll_event , <EOL> "<STR_LIT>" : viewer . scroll_event , <EOL> "<STR_LIT>" : self . ignore_event , <EOL> "<STR_LIT>" : self . ignore_event , <EOL> "<STR_LIT>" : viewer . key_down_event , <EOL> "<STR_LIT>" : viewer . key_up_event , <EOL> "<STR_LIT>" : viewer . key_press_event , <EOL> "<STR_LIT>" : viewer . resize_event , <EOL> "<STR_LIT>" : lambda event : viewer . focus_event ( event , True ) , <EOL> "<STR_LIT>" : lambda event : viewer . focus_event ( event , False ) , <EOL> "<STR_LIT>" : lambda event : viewer . focus_event ( event , False ) , <EOL> "<STR_LIT>" : viewer . drop_event , <EOL> "<STR_LIT>" : self . ignore_event , <EOL> "<STR_LIT>" : viewer . pinch_event , <EOL> "<STR_LIT>" : viewer . pinch_event , <EOL> "<STR_LIT>" : viewer . pinch_event , <EOL> "<STR_LIT>" : viewer . rotate_event , <EOL> "<STR_LIT>" : viewer . rotate_event , <EOL> "<STR_LIT>" : viewer . rotate_event , <EOL> "<STR_LIT>" : viewer . tap_event , <EOL> "<STR_LIT>" : viewer . pan_event , <EOL> "<STR_LIT>" : viewer . pan_event , <EOL> "<STR_LIT>" : viewer . pan_event , <EOL> "<STR_LIT>" : viewer . swipe_event , <EOL> } <EOL> self . add_timer ( '<STR_LIT>' , self . refresh_cb ) <EOL> self . add_timer ( '<STR_LIT>' , self . viewer . delayed_redraw ) <EOL> self . add_timer ( '<STR_LIT>' , self . viewer . clear_onscreen_message ) <EOL> self . viewer . set_widget ( self ) <EOL> def get_viewer ( self ) : <EOL> return self . viewer <EOL> def ignore_event ( self , event ) : <EOL> pass <EOL> def map_event_cb ( self , event ) : <EOL> self . viewer . map_event ( event ) <EOL> self . reset_timer ( '<STR_LIT>' , self . refresh_delay ) <EOL> def refresh_cb ( self , * args ) : <EOL> app = self . get_app ( ) <EOL> app . do_operation ( '<STR_LIT>' , id = self . id ) <EOL> self . reset_timer ( '<STR_LIT>' , self . refresh_delay ) <EOL> def do_update ( self , buf ) : <EOL> self . clear_rect ( <NUM_LIT:0> , <NUM_LIT:0> , self . width , self . height ) <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> self . draw_image ( buf , <NUM_LIT:0> , <NUM_LIT:0> , self . width , self . height ) <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> def _cb_redirect ( self , event ) : <EOL> method = self . _dispatch_event_table [ event . type ] <EOL> try : <EOL> method ( event ) <EOL> except Exception as e : <EOL> self . logger . error ( "<STR_LIT>" % ( <EOL> event . type , str ( e ) ) ) </s>
