def dumpspecs(outstream = None, skip_volatiles = False): """ Dump various flags, settings, values to the terminal. This is not to be used internal to this module - it must wait until the module is fully imported for all the values to be finalized. If outstream is not given, this will simply dump to sys.stdout. """ pyrver = 'unknown' try: from pyraf import __version__ as pyrver except: pass out = "python exec = "+str(sys.executable) if skip_volatiles: out += "\npython ver = "+'.'.join([str(v) for v in sys.version_info[0:2]]) else: out += "\npython ver = "+'.'.join([str(v) for v in sys.version_info[0:3]]) out += "\nplatform = "+str(sys.platform) if not skip_volatiles: out += "\nPyRAF ver = "+pyrver out += "\nPY3K = "+str(capable.PY3K) out += "\nc.OF_GRAPHICS = "+str(capable.OF_GRAPHICS) dco = 'not yet known' if hasattr(capable, 'get_dc_owner'): # rm hasattr at/after v2.2 if skip_volatiles: out +="\n/dev/console owner = <skipped>" else: dco = capable.get_dc_owner(False, True) out +="\n/dev/console owner = "+str(dco) if not capable.OF_GRAPHICS: if hasattr(capable, 'TKINTER_IMPORT_FAILED'): out += "\ntkinter import failed." else: out += "\ntkinter use unattempted." else: out += "\nTclVersion = "+str(capable.TKNTR.TclVersion) out += "\nTkVersion = "+str(capable.TKNTR.TkVersion) out += "\nWUTIL_ON_MAC = "+str(WUTIL_ON_MAC) out += "\nWUTIL_ON_WIN = "+str(WUTIL_ON_WIN) out += "\nWUTIL_USING_X = "+str(WUTIL_USING_X) try: # the try/except handling here will be unneccessary after stsci.tools 3.4.2 out += "\nis_darwin_and_x = "+str(capable.is_darwin_and_x()) if WUTIL_ON_MAC: out += "\nwhich_darwin_linkage = "+str(capable.which_darwin_linkage()) out += "\nwhich_darwin_linkage2 = "+str(capable.which_darwin_linkage(force_otool_check=True)) else: out += "\nwhich_darwin_linkage = (not darwin)" except Exception: out += "\ndarwin linkage check threw exception" out += "\nskip display = "+str(_skipDisplay) out += "\nhas graphics = "+str(hasGraphics) out += "\nimported aqutil = "+str(bool(_has_aqutil)) out += "\nimported xutil = "+str(bool(_has_xutil)) # Case of WUTIL_USING_X and not _has_xutil means either they don't have # xutil library installed, or they do but they can't draw to screen if WUTIL_USING_X and capable.OF_GRAPHICS and \ not _skipDisplay and not bool(_has_xutil): # quick debug help here for case where xutil didn't build out += '\n\tWARNING! PyRAF may be missing the "xutil" library. See PyRAF FAQ 1.9' if 'PYRAFGRAPHICS' in os.environ: val = os.environ['PYRAFGRAPHICS'] out += "\nPYRAFGRAPHICS = "+val if val == "matplotlib": mpl_ok = False try: import matplotlib as mpl mpl_ok = True except: out += "\nCannot import matplotlib" if mpl_ok: if hasattr(mpl, 'tk_window_focus'): out += "\nmpl.tk_window_focus = "+str(mpl.tk_window_focus()) else: out += "\nmpl.tk_window_focus = function not supported" mpldir = os.path.split(mpl.__file__)[0] import glob flist = glob.glob(mpldir+os.path.sep+'backends'+os.path.sep+'*.so') flist = [os.path.split(f)[1] for f in flist] out += "\nmpl backends = "+str(flist) tkaggbknd = mpldir+'/backends/_tkagg.so' if os.path.exists(tkaggbknd): out += "\ntry: /usr/bin/otool -L "+tkaggbknd else: out += "\nPYRAFGRAPHICS not set" if outstream: outstream.write(out+'\n') else: print out
if 'PYRAF_NO_DISPLAY' in os.environ: print "No graphics/display intended for this session." else: print "No graphics/display possible for this session." if hasattr(capable, 'TKINTER_IMPORT_FAILED'): print "tkinter import failed." else: if _has_xutil or _has_aqutil: hasGraphics = focusController.hasGraphics elif WUTIL_ON_MAC: # on a Mac but loaded no graphcs libs (aqutil/xutil) # Handle case where we are on the Mac with no X and no PyObjc. We can # still run, albeit without automatic mouse moving and focus jumping. hasGraphics = focusController.hasGraphics if hasGraphics: try: # the try/except handling here will be unneccessary after stsci.tools 3.4.2 if capable.which_darwin_linkage() == 'aqua': print "\nLimited graphics available on OSX (aqutil not loaded)\n" else: print "\nLimited graphics available on OSX (xutil not loaded)\n" except Exception: print "\nLimited graphics available on OSX (library not loaded)\n" elif WUTIL_ON_WIN: hasGraphics = 1 # try this, tho VERY limited (epar only I guess) print "\nLimited graphics available on win32 platform\n" if not hasGraphics: print "" print "No graphics display available for this session." print "Graphics tasks that attempt to plot to an interactive " + \ "screen will fail." print 'For help, search "PyRAF FAQ 5.13" or visit the STScI help site, ' \
if 'PYRAF_NO_DISPLAY' in os.environ: print "No graphics/display intended for this session." else: print "No graphics/display possible for this session." if hasattr(capable, 'TKINTER_IMPORT_FAILED'): print "tkinter import failed." else: if _has_xutil or _has_aqutil: hasGraphics = focusController.hasGraphics elif WUTIL_ON_MAC: # on a Mac but loaded no graphcs libs (aqutil/xutil) # Handle case where we are on the Mac with no X and no PyObjc. We can # still run, albeit without automatic mouse moving and focus jumping. hasGraphics = focusController.hasGraphics if hasGraphics: try: # the try/except handling here will be unneccessary after stsci.tools 3.4.2 if capable.which_darwin_linkage() == 'aqua': print "\nLimited graphics available on OSX (aqutil not loaded)\n" else: print "\nLimited graphics available on OSX (xutil not loaded)\n" except Exception: print "\nLimited graphics available on OSX (library not loaded)\n" elif WUTIL_ON_WIN: hasGraphics = 1 # try this, tho VERY limited (epar only I guess) print "\nLimited graphics available on win32 platform\n" if not hasGraphics: print "" print "No graphics display available for this session." print "Graphics tasks that attempt to plot to an interactive " + \ "screen will fail." print 'For help, search "PyRAF FAQ 5.13" or contact "*****@*****.**".'
def dumpspecs(outstream=None, skip_volatiles=False): """ Dump various flags, settings, values to the terminal. This is not to be used internal to this module - it must wait until the module is fully imported for all the values to be finalized. If outstream is not given, this will simply dump to sys.stdout. """ pyrver = 'unknown' try: from pyraf import __version__ as pyrver except: pass out = "python exec = " + str(sys.executable) if skip_volatiles: out += "\npython ver = " + '.'.join( [str(v) for v in sys.version_info[0:2]]) else: out += "\npython ver = " + '.'.join( [str(v) for v in sys.version_info[0:3]]) out += "\nplatform = " + str(sys.platform) if not skip_volatiles: out += "\nPyRAF ver = " + pyrver out += "\nPY3K = " + str(capable.PY3K) out += "\nc.OF_GRAPHICS = " + str(capable.OF_GRAPHICS) dco = 'not yet known' if hasattr(capable, 'get_dc_owner'): # rm hasattr at/after v2.2 if skip_volatiles: out += "\n/dev/console owner = <skipped>" else: dco = capable.get_dc_owner(False, True) out += "\n/dev/console owner = " + str(dco) if not capable.OF_GRAPHICS: if hasattr(capable, 'TKINTER_IMPORT_FAILED'): out += "\ntkinter import failed." else: out += "\ntkinter use unattempted." else: out += "\nTclVersion = " + str(capable.TKNTR.TclVersion) out += "\nTkVersion = " + str(capable.TKNTR.TkVersion) out += "\nWUTIL_ON_MAC = " + str(WUTIL_ON_MAC) out += "\nWUTIL_ON_WIN = " + str(WUTIL_ON_WIN) out += "\nWUTIL_USING_X = " + str(WUTIL_USING_X) try: # the try/except handling here will be unneccessary after stsci.tools 3.4.2 out += "\nis_darwin_and_x = " + str(capable.is_darwin_and_x()) if WUTIL_ON_MAC: out += "\nwhich_darwin_linkage = " + str( capable.which_darwin_linkage()) out += "\nwhich_darwin_linkage2 = " + str( capable.which_darwin_linkage(force_otool_check=True)) else: out += "\nwhich_darwin_linkage = (not darwin)" except Exception: out += "\ndarwin linkage check threw exception" out += "\nskip display = " + str(_skipDisplay) out += "\nhas graphics = " + str(hasGraphics) out += "\nimported aqutil = " + str(bool(_has_aqutil)) out += "\nimported xutil = " + str(bool(_has_xutil)) # Case of WUTIL_USING_X and not _has_xutil means either they don't have # xutil library installed, or they do but they can't draw to screen if WUTIL_USING_X and capable.OF_GRAPHICS and \ not _skipDisplay and not bool(_has_xutil): # quick debug help here for case where xutil didn't build out += '\n\tWARNING! PyRAF may be missing the "xutil" library. See PyRAF FAQ 1.9' if 'PYRAFGRAPHICS' in os.environ: val = os.environ['PYRAFGRAPHICS'] out += "\nPYRAFGRAPHICS = " + val if val == "matplotlib": mpl_ok = False try: import matplotlib as mpl mpl_ok = True except: out += "\nCannot import matplotlib" if mpl_ok: if hasattr(mpl, 'tk_window_focus'): out += "\nmpl.tk_window_focus = " + str( mpl.tk_window_focus()) else: out += "\nmpl.tk_window_focus = function not supported" mpldir = os.path.split(mpl.__file__)[0] import glob flist = glob.glob(mpldir + os.path.sep + 'backends' + os.path.sep + '*.so') flist = [os.path.split(f)[1] for f in flist] out += "\nmpl backends = " + str(flist) tkaggbknd = mpldir + '/backends/_tkagg.so' if os.path.exists(tkaggbknd): out += "\ntry: /usr/bin/otool -L " + tkaggbknd else: out += "\nPYRAFGRAPHICS not set" if outstream: outstream.write(out + '\n') else: print out
_skipDisplay = not capable.OF_GRAPHICS # Are we on MacOS X ? Windows ? WUTIL_ON_MAC = sys.platform == 'darwin' WUTIL_ON_WIN = sys.platform.startswith('win') # WUTIL_USING_X: default to using X on most platforms, tho surely not on windows WUTIL_USING_X = not WUTIL_ON_WIN # More on WUTIL_USING_X: for now we support both versions (X or Aqua) on OSX if WUTIL_ON_MAC and not _skipDisplay: if 'PYRAF_WUTIL_USING_AQUA' in os.environ: WUTIL_USING_X = False else: # Do this check for them; look at the python binaries - are they X11-linked? WUTIL_USING_X = capable.which_darwin_linkage() == "x11" # Experimental new (2012) mode some have requested (OSX mostly) where all # graphics windows drawn are popped to the foreground and left there with # the focus (focus not placed back onto terminal). Except the splash win. GRAPHICS_ALWAYS_ON_TOP = 'PYRAF_GRAPHICS_ALWAYS_ON_TOP' in os.environ # attempt to override with xutil or aqua versions _has_aqutil = 0 _has_xutil = 0 try: if WUTIL_USING_X and not _skipDisplay: # set an env var before importing xutil (see PyRAF FAQ on this) os.environ['XLIB_SKIP_ARGB_VISUALS'] = '1' from . import xutil #initGraphics = initXGraphics