Beispiel #1
0
    def __startIfReady(self):
        """ Called internally to start the application. """
        if self.started:
            return

        if self.gotWindow and self.gotP3DFilename:
            self.started = True

            # Now we can ignore future calls to startIfReady().
            self.ignore('AppRunner_startIfReady')

            # Hang a hook so we know when the window is actually opened.
            self.acceptOnce('window-event', self.__windowEvent)

            # Look for the startup Python file.  This might be a magic
            # filename (like "__main__", or any filename that contains
            # invalid module characters), so we can't just import it
            # directly; instead, we go through the low-level importer.

            # If there's no p3d_info.xml file, we look for "main".
            moduleName = 'main'
            if self.p3dPackage:
                mainName = self.p3dPackage.Attribute('main_module')
                if mainName:
                    moduleName = mainName

            # Temporarily set this flag while we import the app, so
            # that if the app calls run() within its own main.py, it
            # will properly get ignored by ShowBase.
            self.initialAppImport = True

            # Python won't let us import a module named __main__.  So,
            # we have to do that manually, via the VFSImporter.
            if moduleName == '__main__':
                dirName = Filename(self.multifileRoot).toOsSpecific()
                importer = VFSImporter.VFSImporter(dirName)
                loader = importer.find_module('__main__')
                if loader is None:
                    raise ImportError('No module named __main__')

                mainModule = loader.load_module('__main__')
            else:
                __import__(moduleName)
                mainModule = sys.modules[moduleName]

            # Check if it has a main() function.  If so, call it.
            if hasattr(mainModule, 'main') and hasattr(mainModule.main,
                                                       '__call__'):
                mainModule.main(self)

            # Now clear this flag.
            self.initialAppImport = False

            if self.interactiveConsole:
                # At this point, we have successfully loaded the app.
                # If the interactive_console flag is enabled, stop the
                # main loop now and give the user a Python prompt.
                taskMgr.stop()
Beispiel #2
0
getModelPath().appendDirectory(multifileRoot)
trueFileIO = False
if not trueFileIO:
    # Replace the builtin open and file symbols so user code will get
    # our versions by default, which can open and read files out of
    # the multifile.
    builtins.open = file.open
    if sys.version_info < (3, 0):
        builtins.file = file.open
        builtins.execfile = file.execfile
    os.listdir = file.listdir
    os.walk = file.walk
    os.path.join = file.join
    os.path.isfile = file.isfile
    os.path.isdir = file.isdir
    os.path.exists = file.exists
    os.path.lexists = file.lexists
    os.path.getmtime = file.getmtime
    os.path.getsize = file.getsize
    sys.modules['glob'] = glob
vfs = VirtualFileSystem.getGlobalPtr()
vfs.mount(Filename("app.p3d"), multifileRoot, VirtualFileSystem.MFReadOnly)
VFSImporter.register()
VFSImporter.reloadSharedPackages()
loadPrcFileData('', 'default-model-extension .bam')
dirName = Filename(multifileRoot).toOsSpecific()
importer = VFSImporter.VFSImporter(dirName)
loaderr = importer.find_module('__main__')
mainModule = loaderr.load_module('__main__')
#import Pinball