<s> import numpy <EOL> from ginga . gw import Widgets <EOL> from ginga . misc import Bunch <EOL> from ginga import GingaPlugin <EOL> class Info ( GingaPlugin . GlobalPlugin ) : <EOL> def __init__ ( self , fv ) : <EOL> super ( Info , self ) . __init__ ( fv ) <EOL> self . channel = { } <EOL> self . active = None <EOL> self . info = None <EOL> self . maxstr = <NUM_LIT> <EOL> fv . add_callback ( '<STR_LIT>' , self . add_channel ) <EOL> fv . add_callback ( '<STR_LIT>' , self . delete_channel ) <EOL> fv . add_callback ( '<STR_LIT>' , self . field_info ) <EOL> fv . add_callback ( '<STR_LIT>' , self . focus_cb ) <EOL> def build_gui ( self , container ) : <EOL> nb = Widgets . StackWidget ( ) <EOL> self . nb = nb <EOL> container . add_widget ( self . nb , stretch = <NUM_LIT:1> ) <EOL> def _create_info_window ( self ) : <EOL> sw = Widgets . ScrollArea ( ) <EOL> vbox = Widgets . VBox ( ) <EOL> sw . set_widget ( vbox ) <EOL> captions = ( ( '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT:Name>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT:X>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT:Y>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) <EOL> w , b = Widgets . build_info ( captions ) <EOL> col = Widgets . VBox ( ) <EOL> row = Widgets . HBox ( ) <EOL> row . set_spacing ( <NUM_LIT:0> ) <EOL> row . set_border_width ( <NUM_LIT:0> ) <EOL> row . add_widget ( w , stretch = <NUM_LIT:0> ) <EOL> row . add_widget ( Widgets . Label ( '<STR_LIT>' ) , stretch = <NUM_LIT:1> ) <EOL> col . add_widget ( row , stretch = <NUM_LIT:0> ) <EOL> sw2 = Widgets . ScrollArea ( ) <EOL> sw2 . set_widget ( col ) <EOL> vbox . add_widget ( sw2 , stretch = <NUM_LIT:2> ) <EOL> vbox . add_widget ( Widgets . Label ( '<STR_LIT>' ) , stretch = <NUM_LIT:1> ) <EOL> captions = ( ( '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) <EOL> w , b2 = Widgets . build_info ( captions ) <EOL> b . update ( b2 ) <EOL> b . cut_levels . set_tooltip ( "<STR_LIT>" ) <EOL> b . auto_levels . set_tooltip ( "<STR_LIT>" ) <EOL> b . cut_low . set_tooltip ( "<STR_LIT>" ) <EOL> b . cut_low_value . set_text ( '<STR_LIT>' ) <EOL> b . cut_high . set_tooltip ( "<STR_LIT>" ) <EOL> b . cut_high_value . set_text ( '<STR_LIT>' ) <EOL> b . cut_new . set_text ( '<STR_LIT>' ) <EOL> b . zoom_new . set_text ( '<STR_LIT>' ) <EOL> b . center_new . set_text ( '<STR_LIT>' ) <EOL> row = Widgets . HBox ( ) <EOL> row . set_spacing ( <NUM_LIT:0> ) <EOL> row . set_border_width ( <NUM_LIT:0> ) <EOL> row . add_widget ( w , stretch = <NUM_LIT:0> ) <EOL> vbox . add_widget ( row , stretch = <NUM_LIT:0> ) <EOL> return sw , b <EOL> def add_channel ( self , viewer , chinfo ) : <EOL> sw , winfo = self . _create_info_window ( ) <EOL> chname = chinfo . name <EOL> self . nb . add_widget ( sw , title = chname ) <EOL> index = self . nb . index_of ( sw ) <EOL> info = Bunch . Bunch ( widget = sw , winfo = winfo , <EOL> mode_w = None , <EOL> chinfo = chinfo ) <EOL> self . channel [ chname ] = info <EOL> winfo . cut_low . add_callback ( '<STR_LIT>' , self . cut_levels , <EOL> chinfo . fitsimage , info ) <EOL> winfo . cut_high . add_callback ( '<STR_LIT>' , self . cut_levels , <EOL> chinfo . fitsimage , info ) <EOL> winfo . cut_levels . add_callback ( '<STR_LIT>' , self . cut_levels , <EOL> chinfo . fitsimage , info ) <EOL> winfo . auto_levels . add_callback ( '<STR_LIT>' , self . auto_levels , <EOL> chinfo . fitsimage , info ) <EOL> fitsimage = chinfo . fitsimage <EOL> fitssettings = fitsimage . get_settings ( ) <EOL> fitsimage . add_callback ( '<STR_LIT>' , self . new_image_cb , info ) <EOL> for name in [ '<STR_LIT>' ] : <EOL> fitssettings . getSetting ( name ) . add_callback ( '<STR_LIT>' , <EOL> self . cutset_cb , fitsimage , info ) <EOL> for name in [ '<STR_LIT>' ] : <EOL> fitssettings . getSetting ( name ) . add_callback ( '<STR_LIT>' , <EOL> self . zoomset_cb , fitsimage , info ) <EOL> fitssettings . getSetting ( '<STR_LIT>' ) . add_callback ( '<STR_LIT>' , <EOL> self . autocuts_cb , fitsimage , info ) <EOL> fitssettings . getSetting ( '<STR_LIT>' ) . add_callback ( '<STR_LIT>' , <EOL> self . autozoom_cb , fitsimage , info ) <EOL> fitssettings . getSetting ( '<STR_LIT>' ) . add_callback ( '<STR_LIT>' , <EOL> self . autocenter_cb , fitsimage , info ) <EOL> def delete_channel ( self , viewer , chinfo ) : <EOL> chname = chinfo . name <EOL> self . logger . debug ( "<STR_LIT>" % ( chname ) ) <EOL> widget = self . channel [ chname ] . widget <EOL> self . nb . remove ( widget , delete = True ) <EOL> self . active = None <EOL> self . info = None <EOL> del self . channel [ chname ] <EOL> def new_image_cb ( self , fitsimage , image , info ) : <EOL> image . add_callback ( '<STR_LIT>' , self . image_update_cb , fitsimage , info ) <EOL> self . set_info ( info , fitsimage ) <EOL> return True <EOL> def image_update_cb ( self , image , fitsimage , info ) : <EOL> cur_img = fitsimage . get_image ( ) <EOL> if cur_img == image : <EOL> self . fv . gui_do ( self . set_info , info , fitsimage ) <EOL> return True <EOL> def focus_cb ( self , viewer , channel ) : <EOL> chname = channel . name <EOL> if self . active != chname : <EOL> if not chname in self . channel : <EOL> self . add_channel ( viewer , channel ) <EOL> widget = self . channel [ chname ] . widget <EOL> index = self . nb . index_of ( widget ) <EOL> self . nb . set_index ( index ) <EOL> self . active = chname <EOL> self . info = self . channel [ self . active ] <EOL> self . set_info ( self . info , channel . fitsimage ) <EOL> def zoomset_cb ( self , setting , value , fitsimage , info ) : <EOL> """<STR_LIT>""" <EOL> scale_x , scale_y = value <EOL> if scale_x == scale_y : <EOL> text = self . fv . scale2text ( scale_x ) <EOL> else : <EOL> textx = self . fv . scale2text ( scale_x ) <EOL> texty = self . fv . scale2text ( scale_y ) <EOL> text = "<STR_LIT>" % ( textx , texty ) <EOL> info . winfo . zoom . set_text ( text ) <EOL> def cutset_cb ( self , setting , value , fitsimage , info ) : <EOL> loval , hival = value <EOL> info . winfo . cut_low_value . set_text ( '<STR_LIT>' % ( loval ) ) <EOL> info . winfo . cut_high_value . set_text ( '<STR_LIT>' % ( hival ) ) <EOL> def autocuts_cb ( self , setting , option , fitsimage , info ) : <EOL> info . winfo . cut_new . set_text ( option ) <EOL> def autozoom_cb ( self , setting , option , fitsimage , info ) : <EOL> info . winfo . zoom_new . set_text ( option ) <EOL> def autocenter_cb ( self , setting , option , fitsimage , info ) : <EOL> if isinstance ( option , bool ) : <EOL> choice = { True : '<STR_LIT>' , False : '<STR_LIT>' } <EOL> option = choice [ option ] <EOL> info . winfo . center_new . set_text ( option ) <EOL> def trunc ( self , s ) : <EOL> if len ( s ) > self . maxstr : <EOL> return s [ : self . maxstr - <NUM_LIT:3> ] + '<STR_LIT>' <EOL> else : <EOL> return s <EOL> def set_info ( self , info , fitsimage ) : <EOL> image = fitsimage . get_image ( ) <EOL> if image is None : <EOL> return <EOL> header = image . get_header ( ) <EOL> name = self . trunc ( image . get ( '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> info . winfo . name . set_text ( name ) <EOL> objtext = self . trunc ( header . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> info . winfo . object . set_text ( objtext ) <EOL> equinox = header . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> info . winfo . equinox . set_text ( str ( equinox ) ) <EOL> width , height = fitsimage . get_data_size ( ) <EOL> minval , maxval = image . get_minmax ( noinf = False ) <EOL> info . winfo . max . set_text ( str ( maxval ) ) <EOL> info . winfo . min . set_text ( str ( minval ) ) <EOL> loval , hival = fitsimage . get_cut_levels ( ) <EOL> info . winfo . cut_low_value . set_text ( '<STR_LIT>' % ( loval ) ) <EOL> info . winfo . cut_high_value . set_text ( '<STR_LIT>' % ( hival ) ) <EOL> dim_txt = "<STR_LIT>" % ( width , height ) <EOL> info . winfo . dimensions . set_text ( dim_txt ) <EOL> scalefactor = fitsimage . get_scale ( ) <EOL> text = self . fv . scale2text ( scalefactor ) <EOL> info . winfo . zoom . set_text ( text ) <EOL> t_ = fitsimage . get_settings ( ) <EOL> info . winfo . cut_new . set_text ( t_ [ '<STR_LIT>' ] ) <EOL> info . winfo . zoom_new . set_text ( t_ [ '<STR_LIT>' ] ) <EOL> option = t_ [ '<STR_LIT>' ] <EOL> if isinstance ( option , bool ) : <EOL> choice = { True : '<STR_LIT>' , False : '<STR_LIT>' } <EOL> option = choice [ option ] <EOL> info . winfo . center_new . set_text ( option ) <EOL> def field_info ( self , viewer , fitsimage , info ) : <EOL> chname = self . fv . get_channelName ( fitsimage ) <EOL> chinfo = self . fv . get_channelInfo ( chname ) <EOL> chname = chinfo . name <EOL> if not chname in self . channel : <EOL> return <EOL> obj = self . channel [ chname ] <EOL> obj . winfo . x . set_text ( "<STR_LIT>" % info . x ) <EOL> obj . winfo . y . set_text ( "<STR_LIT>" % info . y ) <EOL> obj . winfo . value . set_text ( str ( info . value ) ) <EOL> if '<STR_LIT>' in info : <EOL> obj . winfo . ra . set_text ( info . ra_txt ) <EOL> obj . winfo . dec . set_text ( info . dec_txt ) <EOL> if '<STR_LIT>' in info : <EOL> obj . winfo . lbl_ra . set_text ( info . ra_lbl + '<STR_LIT::>' ) <EOL> obj . winfo . lbl_dec . set_text ( info . dec_lbl + '<STR_LIT::>' ) <EOL> def cut_levels ( self , w , fitsimage , info ) : <EOL> loval , hival = fitsimage . get_cut_levels ( ) <EOL> try : <EOL> lostr = info . winfo . cut_low . get_text ( ) . strip ( ) <EOL> if lostr != '<STR_LIT>' : <EOL> loval = float ( lostr ) <EOL> histr = info . winfo . cut_high . get_text ( ) . strip ( ) <EOL> if histr != '<STR_LIT>' : <EOL> hival = float ( histr ) <EOL> self . logger . debug ( "<STR_LIT>" % ( loval , hival ) ) <EOL> return fitsimage . cut_levels ( loval , hival ) <EOL> except Exception as e : <EOL> self . fv . show_error ( "<STR_LIT>" % ( str ( e ) ) ) <EOL> return True <EOL> def auto_levels ( self , w , fitsimage , info ) : <EOL> fitsimage . auto_levels ( ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT:info>' </s>
