def reload_components(self, doReload=True, errors=None): """Load changes made to project components""" get_package_classes( 'components', pug.component.Component, #@UndefinedVariable doReload=doReload, errors=errors)
def get_available_scenes(doReload=False, useWorking=False, errors=None): """get_available_scenes( doReload=False, useWorking=False, errors=None)>dict Get all Scenes available in modules in Scenes folder. Return dict of available Scene sub-classes {"sceneName":sceneClass}. Scene is automatically included. doReload: if True, don't just import scene modules, but reload them useWorking: if True, and the class in the __Working__.py file is in the class list, use the __Working__ scene to replace the one in the list. errors: if a dict is passed in, it will be filled with the results of sys.exc_info() for each module that had a problem being imported. Indexed by module """ if type(errors) != type({}): errors = None global availableScenes if availableScenes is not None and not doReload: return availableScenes.copy() sceneList = get_package_classes('scenes', Opioid2D.Scene, doReload, errors=errors) # use __Working__ scene as override workingModule = 'scenes.__Working__' needsReload = workingModule in sys.modules sceneDict = {} try: module = __import__(workingModule) except ImportError: pass except: if getattr(Opioid2D.Director, "editorMode", False): if errors: errors[workingModule] = sys.exc_info() else: print "Exception while loading working module." print traceback.format_exc() else: if doReload and needsReload: sys.modules.pop(workingModule) module = __import__(workingModule) #reload(module.__Working__) classes = find_classes_in_module(module.__Working__, Opioid2D.Scene) if classes: workingScene = classes[0] if useWorking: for idx in range(len(sceneList)): if sceneList[idx].__name__ == workingScene.__name__: global _revertScene _revertScene = sceneList[idx] sceneList[idx] = workingScene break else: sceneDict['__Working__'] = workingScene else: print "No scene in working module.", \ "Using committed module instead." for item in sceneList: sceneDict[item.__name__] = item availableScenes = sceneDict.copy() return sceneDict
def get_available_scenes( doReload=False, useWorking=False, errors=None): """get_available_scenes( doReload=False, useWorking=False, errors=None)>dict Get all Scenes available in modules in Scenes folder. Return dict of available Scene sub-classes {"sceneName":sceneClass}. Scene is automatically included. doReload: if True, don't just import scene modules, but reload them useWorking: if True, and the class in the __Working__.py file is in the class list, use the __Working__ scene to replace the one in the list. errors: if a dict is passed in, it will be filled with the results of sys.exc_info() for each module that had a problem being imported. Indexed by module """ if type(errors) != type({}): errors=None global availableScenes if availableScenes is not None and not doReload: return availableScenes.copy() sceneList = get_package_classes('scenes', Opioid2D.Scene, doReload, errors=errors) # use __Working__ scene as override workingModule = 'scenes.__Working__' needsReload = workingModule in sys.modules sceneDict = {} try: module = __import__(workingModule) except ImportError: pass except: if getattr(Opioid2D.Director,"editorMode",False): if errors: errors[workingModule] = sys.exc_info() else: print "Exception while loading working module." print traceback.format_exc() else: if doReload and needsReload: sys.modules.pop(workingModule) module = __import__(workingModule) #reload(module.__Working__) classes = find_classes_in_module(module.__Working__, Opioid2D.Scene) if classes: workingScene = classes[0] if useWorking: for idx in range(len(sceneList)): if sceneList[idx].__name__ == workingScene.__name__: global _revertScene _revertScene = sceneList[idx] sceneList[idx] = workingScene break else: sceneDict['__Working__'] = workingScene else: print "No scene in working module.", \ "Using committed module instead." for item in sceneList: sceneDict[item.__name__]=item availableScenes = sceneDict.copy() return sceneDict
def get_available_objects(doReload=False, errors=None): """get_available_objects( doReload=False, errors=None)->dict of objects Get all Nodes available in modules in Objects folder. Return a dict of available 'name':class. Sprite is automatically included. doReload: if True reload all object modules from disk errors: if a dict is passed in, it will be filled with the results of sys.exc_info() for each module that had a problem being imported. Indexed by module """ global availableObjects if availableObjects is not None and not doReload: return availableObjects.copy() objectList = get_package_classes('objects', Node, doReload, errors=errors) objectDict = {} for item in objectList: objectDict[item.__name__] = item availableObjects = objectDict.copy() return objectDict
def get_available_objects( doReload=False, errors=None): """get_available_objects( doReload=False, errors=None)->dict of objects Get all Nodes available in modules in Objects folder. Return a dict of available 'name':class. Sprite is automatically included. doReload: if True reload all object modules from disk errors: if a dict is passed in, it will be filled with the results of sys.exc_info() for each module that had a problem being imported. Indexed by module """ global availableObjects if availableObjects is not None and not doReload: return availableObjects.copy() objectList = get_package_classes('objects', Node, doReload, errors=errors) objectDict = {} for item in objectList: objectDict[item.__name__]=item availableObjects = objectDict.copy() return objectDict
def reload_components(self, doReload=True, errors=None): """Load changes made to project components""" get_package_classes('components', pug.component.Component, #@UndefinedVariable doReload=doReload, errors=errors)
def run_pig_scene(projectPath, scenename=None, position=None, resolution=None, title=None, fullscreen=None, icon=None, units=None, useWorking=False): """run_pig_scene( ...) Run a pig scene in a new window args: ( scenename, projectPath, position=None, resolution=None, title=None, fullscreen=None, icon=None, units=None, use_working=False) All arguments with None defaults will default to info found in the _project_settings file unless otherwise noted. projectPath: the root path of this project. If projectPath is a file path, just the folder will be used. If that folder is the 'scenes' folder, the parent of that folder will be used. scenename: the name of the scene to run ('scenename'.py in scenes folder). If '__Editor__', use the scenename in _pug_settings.py position: (x, y) the topleft corner of the window. resolution: (x,y) the width and height of the window title: the title to appear on the window fullscreen: True displays window in fullscreen mode icon: icon graphic to use for the window units: viewport size in project units. Defaults to resolution useWorking: if True, use the __working__.py file when running the scene of the same name """ skip_deprecated_warnings() projectPath = fix_project_path(projectPath) if os.path.isfile(projectPath): projectPath = os.path.dirname(projectPath) if os.path.basename == 'scenes': projectPath = os.path.dirname(projectPath) set_project_path(projectPath) try: from _project_settings import project_settings #@UnresolvedImport except: raise ValueError( "No scenes have been created yet. Run edit_project.py") # settings if position is None: try: position = project_settings.rect_opioid_window[0:2] except: position = [0, 0] if resolution is None: try: resolution = project_settings.rect_opioid_window[2:4] except: resolution = [800, 600] if title is None: try: title = project_settings.title except: title = "Scene" if fullscreen is None: try: fullscreen = project_settings.fullscreen except: fullscreen = False if fullscreen: position = [0, 0] if scenename is None: try: scenename = project_settings.initial_scene except: scenename = 'Scene' if icon is None: try: icon = project_settings.icon except: icon = '' # get scene import pig.components get_package_classes('components', pug.component.Component) scenedict = get_available_scenes( useWorking=useWorking) # use __Working__.py from pig.Scene import Scene if scenename == 'Scene': initial_scene = Scene elif scenename == '__Editor__': from _pug_settings import pug_settings editor_scene = pug_settings.initial_scene initial_scene = scenedict[editor_scene] else: try: initial_scene = scenedict[scenename] except: if useWorking: module = __import__('scenes.__Working__') workingClasses = find_classes_in_module( module.__Working__, Opioid2D.Scene) for cls in workingClasses: if cls.__name__ == scenename: exec('from scenes.__Working__ import ' + scenename) break exec('from scenes.' + scenename + ' import ' + scenename) raise ValueError("Problem with scene: " + scenename) Opioid2D.Display.init(resolution, units, title, fullscreen, icon) set_opioid_window_position(position) Opioid2D.Director.start_project = True # Import Psyco if available try: import psyco psyco.full() except ImportError: pass Opioid2D.Director.run(initial_scene)
def run_pig_scene( projectPath, scenename=None, position=None, resolution=None, title=None, fullscreen=None, icon=None, units=None, useWorking=False): """run_pig_scene( ...) Run a pig scene in a new window args: ( scenename, projectPath, position=None, resolution=None, title=None, fullscreen=None, icon=None, units=None, use_working=False) All arguments with None defaults will default to info found in the _project_settings file unless otherwise noted. projectPath: the root path of this project. If projectPath is a file path, just the folder will be used. If that folder is the 'scenes' folder, the parent of that folder will be used. scenename: the name of the scene to run ('scenename'.py in scenes folder). If '__Editor__', use the scenename in _pug_settings.py position: (x, y) the topleft corner of the window. resolution: (x,y) the width and height of the window title: the title to appear on the window fullscreen: True displays window in fullscreen mode icon: icon graphic to use for the window units: viewport size in project units. Defaults to resolution useWorking: if True, use the __working__.py file when running the scene of the same name """ skip_deprecated_warnings() projectPath = fix_project_path(projectPath) if os.path.isfile(projectPath): projectPath = os.path.dirname(projectPath) if os.path.basename == 'scenes': projectPath = os.path.dirname(projectPath) set_project_path (projectPath) try: from _project_settings import project_settings #@UnresolvedImport except: raise ValueError("No scenes have been created yet. Run edit_project.py") # settings if position is None: try: position = project_settings.rect_opioid_window[0:2] except: position = [0,0] if resolution is None: try: resolution = project_settings.rect_opioid_window[2:4] except: resolution = [800,600] if title is None: try: title = project_settings.title except: title = "Scene" if fullscreen is None: try: fullscreen = project_settings.fullscreen except: fullscreen = False if fullscreen: position = [0,0] if scenename is None: try: scenename = project_settings.initial_scene except: scenename = 'Scene' if icon is None: try: icon = project_settings.icon except: icon = '' # get scene import pig.components get_package_classes('components', pug.component.Component) scenedict = get_available_scenes( useWorking=useWorking)# use __Working__.py from pig.Scene import Scene if scenename == 'Scene': initial_scene = Scene elif scenename == '__Editor__': from _pug_settings import pug_settings editor_scene = pug_settings.initial_scene initial_scene = scenedict[editor_scene] else: try: initial_scene = scenedict[scenename] except: if useWorking: module = __import__('scenes.__Working__') workingClasses = find_classes_in_module(module.__Working__, Opioid2D.Scene) for cls in workingClasses: if cls.__name__ == scenename: exec('from scenes.__Working__ import ' + scenename) break exec('from scenes.' + scenename + ' import ' + scenename) raise ValueError("Problem with scene: "+scenename) Opioid2D.Display.init(resolution, units, title, fullscreen, icon) set_opioid_window_position( position) Opioid2D.Director.start_project = True # Import Psyco if available try: import psyco psyco.full() except ImportError: pass Opioid2D.Director.run(initial_scene)