<s> import sys , os <EOL> import logging <EOL> from ginga import AstroImage <EOL> from ginga . qtw . QtHelp import QtGui , QtCore <EOL> from ginga . qtw . ImageViewCanvasQt import ImageViewCanvas <EOL> STD_FORMAT = '<STR_LIT>' <EOL> class FitsViewer ( QtGui . QMainWindow ) : <EOL> def __init__ ( self , logger ) : <EOL> super ( FitsViewer , self ) . __init__ ( ) <EOL> self . logger = logger <EOL> fi = ImageViewCanvas ( self . logger , render = '<STR_LIT>' ) <EOL> fi . enable_autocuts ( '<STR_LIT>' ) <EOL> fi . set_autocut_params ( '<STR_LIT>' ) <EOL> fi . enable_autozoom ( '<STR_LIT>' ) <EOL> fi . set_callback ( '<STR_LIT>' , self . drop_file ) <EOL> fi . set_bg ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> fi . ui_setActive ( True ) <EOL> fi . enable_draw ( False ) <EOL> self . fitsimage = fi <EOL> bd = fi . get_bindings ( ) <EOL> bd . enable_pan ( True ) <EOL> bd . enable_zoom ( True ) <EOL> bd . enable_cuts ( True ) <EOL> bd . enable_flip ( True ) <EOL> w = fi . get_widget ( ) <EOL> w . resize ( <NUM_LIT> , <NUM_LIT> ) <EOL> vbox = QtGui . QVBoxLayout ( ) <EOL> vbox . setContentsMargins ( QtCore . QMargins ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> vbox . setSpacing ( <NUM_LIT:1> ) <EOL> vbox . addWidget ( w , stretch = <NUM_LIT:1> ) <EOL> hbox = QtGui . QHBoxLayout ( ) <EOL> hbox . setContentsMargins ( QtCore . QMargins ( <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:2> ) ) <EOL> wopen = QtGui . QPushButton ( "<STR_LIT>" ) <EOL> wopen . clicked . connect ( self . open_file ) <EOL> wquit = QtGui . QPushButton ( "<STR_LIT>" ) <EOL> wquit . clicked . connect ( self . quit ) <EOL> hbox . addStretch ( <NUM_LIT:1> ) <EOL> for w in ( wopen , wquit ) : <EOL> hbox . addWidget ( w , stretch = <NUM_LIT:0> ) <EOL> hw = QtGui . QWidget ( ) <EOL> hw . setLayout ( hbox ) <EOL> vbox . addWidget ( hw , stretch = <NUM_LIT:0> ) <EOL> vw = QtGui . QWidget ( ) <EOL> self . setCentralWidget ( vw ) <EOL> vw . setLayout ( vbox ) <EOL> def load_file ( self , filepath ) : <EOL> image = AstroImage . AstroImage ( logger = self . logger ) <EOL> image . load_file ( filepath ) <EOL> self . fitsimage . set_image ( image ) <EOL> self . setWindowTitle ( filepath ) <EOL> def open_file ( self ) : <EOL> res = QtGui . QFileDialog . getOpenFileName ( self , "<STR_LIT>" , <EOL> "<STR_LIT:.>" , "<STR_LIT>" ) <EOL> if isinstance ( res , tuple ) : <EOL> fileName = res [ <NUM_LIT:0> ] <EOL> else : <EOL> fileName = str ( res ) <EOL> if len ( fileName ) != <NUM_LIT:0> : <EOL> self . load_file ( fileName ) <EOL> def drop_file ( self , fitsimage , paths ) : <EOL> fileName = paths [ <NUM_LIT:0> ] <EOL> self . load_file ( fileName ) <EOL> def quit ( self , * args ) : <EOL> self . logger . info ( "<STR_LIT>" ) <EOL> self . deleteLater ( ) <EOL> def main ( options , args ) : <EOL> app = QtGui . QApplication ( sys . argv ) <EOL> logger = logging . getLogger ( "<STR_LIT>" ) <EOL> logger . setLevel ( logging . INFO ) <EOL> fmt = logging . Formatter ( STD_FORMAT ) <EOL> stderrHdlr = logging . StreamHandler ( ) <EOL> stderrHdlr . setFormatter ( fmt ) <EOL> logger . addHandler ( stderrHdlr ) <EOL> w = FitsViewer ( logger ) <EOL> w . resize ( <NUM_LIT> , <NUM_LIT> ) <EOL> w . show ( ) <EOL> app . setActiveWindow ( w ) <EOL> w . raise_ ( ) <EOL> w . activateWindow ( ) <EOL> if len ( args ) > <NUM_LIT:0> : <EOL> w . load_file ( args [ <NUM_LIT:0> ] ) <EOL> app . exec_ ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( None , sys . argv [ <NUM_LIT:1> : ] ) </s>
