#NEWLINE# def main( self , options , args ) : #NEWLINE# #INDENT# '\n        Main routine for running the reference viewer.\n\n        `options` is a OptionParser object that has been populated with\n        values from parsing the command line.  It should at least include\n        the options from add_default_options()\n\n        `args` is a list of arguments to the viewer after parsing out\n        options.  It should contain a list of files or URLs to load.\n        ' #NEWLINE# logger = log . get_logger ( name = 'ginga' , options = options ) #NEWLINE# basedir = paths . ginga_home #NEWLINE# if ( not os . path . exists ( basedir ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# os . mkdir ( basedir ) #NEWLINE# #UNINDENT# except OSError as e : #NEWLINE# #INDENT# logger . warning ( ( "Couldn't create ginga settings area (%s): %s" % ( basedir , str ( e ) ) ) ) #NEWLINE# logger . warning ( 'Preferences will not be able to be saved' ) #NEWLINE# #UNINDENT# #UNINDENT# prefs = Settings . Preferences ( basefolder = basedir , logger = logger ) #NEWLINE# settings = prefs . createCategory ( 'general' ) #NEWLINE# settings . load ( onError = 'silent' ) #NEWLINE# settings . setDefaults ( useMatplotlibColormaps = False , widgetSet = 'choose' , WCSpkg = 'choose' , FITSpkg = 'choose' , recursion_limit = 2000 ) #NEWLINE# sys . setrecursionlimit ( settings . get ( 'recursion_limit' ) ) #NEWLINE# sys . path . insert ( 0 , basedir ) #NEWLINE# moduleHome = os . path . split ( sys . modules [ 'ginga.version' ] . __file__ ) [ 0 ] #NEWLINE# childDir = os . path . join ( moduleHome , 'misc' , 'plugins' ) #NEWLINE# sys . path . insert ( 0 , childDir ) #NEWLINE# pluginDir = os . path . join ( basedir , 'plugins' ) #NEWLINE# sys . path . insert ( 0 , pluginDir ) #NEWLINE# gc = os . path . join ( basedir , 'ginga_config.py' ) #NEWLINE# have_ginga_config = os . path . exists ( gc ) #NEWLINE# if have_ginga_config : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# import ginga_config #NEWLINE# if hasattr ( ginga_config , 'init_config' ) : #NEWLINE# #INDENT# ginga_config . init_config ( self ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( type , value , tb ) = sys . exc_info ( ) #NEWLINE# tb_str = '\n' . join ( traceback . format_tb ( tb ) ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# tb_str = 'Traceback information unavailable.' #NEWLINE# #UNINDENT# logger . error ( ( 'Error processing Ginga config file: %s' % str ( e ) ) ) #NEWLINE# logger . error ( ( 'Traceback:\n%s' % tb_str ) ) #NEWLINE# #UNINDENT# #UNINDENT# if options . toolkit : #NEWLINE# #INDENT# toolkit = options . toolkit #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# toolkit = settings . get ( 'widgetSet' , 'choose' ) #NEWLINE# #UNINDENT# if ( toolkit == 'choose' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# from ginga.qtw import QtHelp #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# from ginga.gtkw import GtkHelp #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# print ( 'You need python-gtk or python-qt to run Ginga!' ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# ginga_toolkit . use ( toolkit ) #NEWLINE# #UNINDENT# tkname = ginga_toolkit . get_family ( ) #NEWLINE# logger . info ( ( "Chosen toolkit (%s) family is '%s'" % ( ginga_toolkit . toolkit , tkname ) ) ) #NEWLINE# from ginga.gw.GingaGw import GingaView #NEWLINE# from ginga.Control import GingaControl , GuiLogHandler #NEWLINE# class GingaShell ( GingaControl , GingaView ) : #NEWLINE# #INDENT# def __init__( self , logger , thread_pool , module_manager , prefs , ev_quit = None ) : #NEWLINE# #INDENT# GingaView . __init__ ( self , logger , ev_quit , thread_pool ) #NEWLINE# GingaControl . __init__ ( self , logger , thread_pool , module_manager , prefs , ev_quit = ev_quit ) #NEWLINE# #UNINDENT# #UNINDENT# if settings . get ( 'useMatplotlibColormaps' , False ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# from ginga import cmap #NEWLINE# cmap . add_matplotlib_cmaps ( ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# logger . warning ( ( 'failed to load matplotlib colormaps: %s' % str ( e ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# if options . wcspkg : #NEWLINE# #INDENT# wcspkg = options . wcspkg #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# wcspkg = settings . get ( 'WCSpkg' , 'choose' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# from ginga.util import wcsmod #NEWLINE# assert ( wcsmod . use ( wcspkg ) == True ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# logger . warning ( ( 'failed to set WCS package preference: %s' % str ( e ) ) ) #NEWLINE# #UNINDENT# if options . fitspkg : #NEWLINE# #INDENT# fitspkg = options . fitspkg #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# fitspkg = settings . get ( 'FITSpkg' , 'choose' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# from ginga.util import io_fits #NEWLINE# assert ( io_fits . use ( fitspkg ) == True ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# logger . warning ( ( 'failed to set FITS package preference: %s' % str ( e ) ) ) #NEWLINE# #UNINDENT# use_opencv = settings . get ( 'use_opencv' , False ) #NEWLINE# if ( use_opencv or options . opencv ) : #NEWLINE# #INDENT# from ginga import trcalc #NEWLINE# try : #NEWLINE# #INDENT# trcalc . use ( 'opencv' ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# logger . warning ( ( 'failed to set OpenCv preference: %s' % str ( e ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# mm = ModuleManager . ModuleManager ( logger ) #NEWLINE# ev_quit = threading . Event ( ) #NEWLINE# thread_pool = Task . ThreadPool ( options . numthreads , logger , ev_quit = ev_quit ) #NEWLINE# thread_pool . startall ( ) #NEWLINE# ginga_shell = GingaShell ( logger , thread_pool , mm , prefs , ev_quit = ev_quit ) #NEWLINE# ginga_shell . set_layout ( self . layout ) #NEWLINE# if have_ginga_config : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if hasattr ( ginga_config , 'pre_gui_config' ) : #NEWLINE# #INDENT# ginga_config . pre_gui_config ( ginga_shell ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( type , value , tb ) = sys . exc_info ( ) #NEWLINE# tb_str = '\n' . join ( traceback . format_tb ( tb ) ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# tb_str = 'Traceback information unavailable.' #NEWLINE# #UNINDENT# logger . error ( ( 'Error importing Ginga config file: %s' % str ( e ) ) ) #NEWLINE# logger . error ( ( 'Traceback:\n%s' % tb_str ) ) #NEWLINE# #UNINDENT# #UNINDENT# ginga_shell . build_toplevel ( ) #NEWLINE# if options . geometry : #NEWLINE# #INDENT# ginga_shell . set_geometry ( options . geometry ) #NEWLINE# #UNINDENT# disabled_plugins = [ ] #NEWLINE# if ( not ( options . disable_plugins is None ) ) : #NEWLINE# #INDENT# disabled_plugins = options . disable_plugins . lower ( ) . split ( ',' ) #NEWLINE# #UNINDENT# for spec in self . global_plugins : #NEWLINE# #INDENT# if ( not ( spec . module . lower ( ) in disabled_plugins ) ) : #NEWLINE# #INDENT# ginga_shell . add_global_plugin ( spec ) #NEWLINE# #UNINDENT# #UNINDENT# guiHdlr = GuiLogHandler ( ginga_shell ) #NEWLINE# guiHdlr . setLevel ( options . loglevel ) #NEWLINE# fmt = logging . Formatter ( log . LOG_FORMAT ) #NEWLINE# guiHdlr . setFormatter ( fmt ) #NEWLINE# logger . addHandler ( guiHdlr ) #NEWLINE# if options . modules : #NEWLINE# #INDENT# modules = options . modules . split ( ',' ) #NEWLINE# for longPluginName in modules : #NEWLINE# #INDENT# if ( '.' in longPluginName ) : #NEWLINE# #INDENT# tmpstr = longPluginName . split ( '.' ) #NEWLINE# pluginName = tmpstr [ ( - 1 ) ] #NEWLINE# pfx = '.' . join ( tmpstr [ : ( - 1 ) ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pluginName = longPluginName #NEWLINE# pfx = None #NEWLINE# #UNINDENT# spec = Bunch ( name = pluginName , module = pluginName , tab = pluginName , ws = 'right' , pfx = pfx ) #NEWLINE# ginga_shell . add_global_plugin ( spec ) #NEWLINE# #UNINDENT# #UNINDENT# for spec in self . local_plugins : #NEWLINE# #INDENT# if ( not ( spec . module . lower ( ) in disabled_plugins ) ) : #NEWLINE# #INDENT# ginga_shell . add_local_plugin ( spec ) #NEWLINE# #UNINDENT# #UNINDENT# if options . plugins : #NEWLINE# #INDENT# plugins = options . plugins . split ( ',' ) #NEWLINE# for longPluginName in plugins : #NEWLINE# #INDENT# if ( '.' in longPluginName ) : #NEWLINE# #INDENT# tmpstr = longPluginName . split ( '.' ) #NEWLINE# pluginName = tmpstr [ ( - 1 ) ] #NEWLINE# pfx = '.' . join ( tmpstr [ : ( - 1 ) ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pluginName = longPluginName #NEWLINE# pfx = None #NEWLINE# #UNINDENT# spec = Bunch ( module = pluginName , ws = 'dialogs' , hidden = False , pfx = pfx ) #NEWLINE# ginga_shell . add_local_plugin ( spec ) #NEWLINE# #UNINDENT# #UNINDENT# ginga_shell . update_pending ( ) #NEWLINE# tab_names = list ( map ( ( lambda name : name . lower ( ) ) , ginga_shell . ds . get_tabnames ( group = None ) ) ) #NEWLINE# if ( 'info' in tab_names ) : #NEWLINE# #INDENT# ginga_shell . ds . raise_tab ( 'Info' ) #NEWLINE# #UNINDENT# if ( 'thumbs' in tab_names ) : #NEWLINE# #INDENT# ginga_shell . ds . raise_tab ( 'Thumbs' ) #NEWLINE# #UNINDENT# channels = options . channels . split ( ',' ) #NEWLINE# for chname in channels : #NEWLINE# #INDENT# ginga_shell . add_channel ( chname ) #NEWLINE# #UNINDENT# ginga_shell . change_channel ( channels [ 0 ] ) #NEWLINE# if have_ginga_config : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if hasattr ( ginga_config , 'post_gui_config' ) : #NEWLINE# #INDENT# ginga_config . post_gui_config ( ginga_shell ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( type , value , tb ) = sys . exc_info ( ) #NEWLINE# tb_str = '\n' . join ( traceback . format_tb ( tb ) ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# tb_str = 'Traceback information unavailable.' #NEWLINE# #UNINDENT# logger . error ( ( 'Error processing Ginga config file: %s' % str ( e ) ) ) #NEWLINE# logger . error ( ( 'Traceback:\n%s' % tb_str ) ) #NEWLINE# #UNINDENT# #UNINDENT# for hdlr in logger . handlers : #NEWLINE# #INDENT# logging . getLogger ( 'py.warnings' ) . addHandler ( hdlr ) #NEWLINE# #UNINDENT# showBanner = True #NEWLINE# try : #NEWLINE# #INDENT# showBanner = settings . get ( 'showBanner' ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# settings . set ( showBanner = False ) #NEWLINE# settings . save ( ) #NEWLINE# #UNINDENT# if ( ( not options . nosplash ) and ( len ( args ) == 0 ) and showBanner ) : #NEWLINE# #INDENT# ginga_shell . banner ( raiseTab = True ) #NEWLINE# #UNINDENT# for imgfile in args : #NEWLINE# #INDENT# ginga_shell . nongui_do ( ginga_shell . load_file , imgfile ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if hasattr ( ginga_shell , 'start' ) : #NEWLINE# #INDENT# task = Task . FuncTask2 ( ginga_shell . start ) #NEWLINE# thread_pool . addTask ( task ) #NEWLINE# #UNINDENT# logger . info ( 'Entering mainloop...' ) #NEWLINE# ginga_shell . mainloop ( timeout = 0.001 ) #NEWLINE# #UNINDENT# except KeyboardInterrupt : #NEWLINE# #INDENT# logger . error ( 'Received keyboard interrupt!' ) #NEWLINE# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# logger . info ( 'Shutting down...' ) #NEWLINE# ev_quit . set ( ) #NEWLINE# #UNINDENT# sys . exit ( 0 )