def testLoaded(): """ Tests to see whether a backend is already loaded. Returns the name of the loaded backend, or an empty string if nothing is loaded. If visvis is part of a frozen app, returns "" always. """ if isFrozen(): return "" else: # see which backends we have path = __file__ path = os.path.dirname(path) files = os.listdir(path) for filename in files: if filename.startswith("__"): continue if not filename.endswith(".py"): continue be = filename[:-3] modNameFull = "visvis.backends." + be if sys.modules.has_key(modNameFull): i = be.find("_") return be[i + 1 :] # nothing found... return ""
def _loadBackend(name): """ Load the backend with the specified name. Returns True on success and False otherwise. """ # Get module names modName = "backend_" + name modNameFull = "visvis.backends.backend_" + name modFileName = os.path.join(os.path.dirname(__file__), modName + ".py") # Test whether to use the pyc version load_module = imp.load_source if not os.path.isfile(modFileName): modFileName += "c" # Probably a frozen app # Try importing the backend toolkit try: modNameTk = backendMap[name] __import__(modNameTk) except ImportError: return False # Try importing the visvis backend module try: if modFileName.endswith(".pyc"): module = __import__(modNameFull, fromlist=[modName]) else: module = imp.load_source(modNameFull, modFileName) globals()[modName] = module except Exception, why: if not isFrozen(): # Only show if not frozen. If frozen, it can easily happen that # the GUI toolkit is available, but the visvis backend is not. print "Error importing %s backend:" % name, why return False
def testLoaded(): """ Tests to see whether a backend is already loaded. Returns the name of the loaded backend, or an empty string if nothing is loaded. If visvis is part of a frozen app, returns "" always. """ if isFrozen(): return "" else: # see which backends we have path = __file__ path = os.path.dirname( path ) files = os.listdir(path) for filename in files: if not filename.startswith('backend_'): continue if not filename.endswith('.py'): continue be = filename[:-3] modNameFull = 'visvis.backends.' + be if modNameFull in sys.modules: i = be.find('_') return be[i+1:] # nothing found... return ''
def _loadBackend(name): """ Load the backend with the specified name. Returns True on success and False otherwise. """ # Get module names modName = 'backend_' + name modNameFull = 'visvis.backends.backend_' + name modFileName = os.path.join(os.path.dirname(__file__), modName + '.py') # Test whether to use the pyc version load_module = imp.load_source if not os.path.isfile(modFileName): modFileName += "c" # Probably a frozen app # Try importing the backend toolkit try: modNameTk = backendMap[name] __import__(modNameTk) except ImportError: return False # Try importing the visvis backend module try: if modFileName.endswith('.pyc'): module = __import__(modNameFull, fromlist=[modName]) else: module = imp.load_source(modNameFull, modFileName) globals()[modName] = module except Exception, why: if not isFrozen(): # Only show if not frozen. If frozen, it can easily happen that # the GUI toolkit is available, but the visvis backend is not. print 'Error importing %s backend:' % name, why return False
def _loadBackend(name): """ Load the backend with the specified name. Returns True on success and False otherwise. """ # Get module names modName = 'backend_' + name modNameFull = 'visvis.backends.backend_' + name modFileName = os.path.join(os.path.dirname(__file__), modName + '.py') # Test whether to use the pyc version load_module = imp.load_source if not os.path.isfile(modFileName): modFileName += "c" # Probably a frozen app # Try importing the backend toolkit try: modNameTk = backendMap[name] __import__(modNameTk) except ImportError: return False # Try importing the visvis backend module try: if modFileName.endswith('.pyc'): module = __import__(modNameFull, fromlist=[modName]) else: module = imp.load_source(modNameFull, modFileName) globals()[modName] = module except Exception: if not isFrozen(): # Only show if not frozen. If frozen, it can easily happen that # the GUI toolkit is available, but the visvis backend is not. why = str(getExceptionInstance()) print('Error importing %s backend: %s' % (name, why)) return False # Do some tests if not hasattr(module, 'newFigure'): raise Exception("Backend %s does not implement newFigure!" % be) elif not hasattr(module, 'Figure'): raise Exception("Backend %s does not implement Figure class!" % be) else: # All good (as far as I can tell). Update stuff if name does not match. module.app._backend = name if currentBackend.name != name: currentBackend.name = name currentBackend.newFigure = module.newFigure currentBackend.app = module.app return True
def _loadBackend(name): """ Load the backend with the specified name. Returns True on success and False otherwise. """ # Get module names modName = 'backend_' + name modNameFull = 'visvis.backends.backend_'+name modFileName = os.path.join(os.path.dirname(__file__), modName+'.py') # Test whether to use the pyc version load_module = imp.load_source if not os.path.isfile(modFileName): modFileName += "c" # Probably a frozen app # Try importing the backend toolkit try: modNameTk = backendMap[name] __import__(modNameTk) except ImportError: return False # Try importing the visvis backend module try: if modFileName.endswith('.pyc'): module = __import__(modNameFull, fromlist=[modName]) else: module = imp.load_source(modNameFull, modFileName) globals()[modName] = module except Exception: if not isFrozen(): # Only show if not frozen. If frozen, it can easily happen that # the GUI toolkit is available, but the visvis backend is not. why = str(getExceptionInstance()) print('Error importing %s backend: %s' % (name, why)) return False # Do some tests if not hasattr(module,'newFigure'): raise Exception("Backend %s does not implement newFigure!" % be) elif not hasattr(module,'Figure'): raise Exception("Backend %s does not implement Figure class!" % be) else: # All good (as far as I can tell). Update stuff if name does not match. module.app._backend = name if currentBackend.name != name: currentBackend.name = name currentBackend.newFigure = module.newFigure currentBackend.app = module.app return True