def initialize(pmgapp=-1):
    '''
    Searches for plugins and registers them.

    pmgapp == -2: No Autoloading
    pmgapp == -1: Autoloading but no legacyinit
    else:         Autoloading and legacyinit
    '''
    if os.path.exists(PYMOLPLUGINSRC):
        from pymol import parsing
        try:
            parsing.run_file(PYMOLPLUGINSRC, {'__script__': PYMOLPLUGINSRC},
                             {})
        except SyntaxError as e:
            colorprinting.warning(str(e))

    autoload = (pmgapp != -2)
    for parent in [startup]:
        modules = findPlugins(parent.__path__)

        for name, filename in modules.items():
            mod_name = parent.__name__ + '.' + name
            info = PluginInfo(name, filename, mod_name)
            if autoload and info.autoload:
                info.load(pmgapp)
def initialize(pmgapp=-1):
    '''
    Searches for plugins and registers them.

    pmgapp == -2: No Autoloading
    pmgapp == -1: Autoloading but no legacyinit
    else:         Autoloading and legacyinit
    '''

    # check for obsolete development version of pymolplugins
    if 'pymolplugins' in sys.modules:
        from .legacysupport import tkMessageBox
        tkMessageBox.showwarning(
            'WARNING',
            '"pymolplugins" now integrated into PyMOL as "pymol.plugins"! '
            'Please remove the old pymolplugins module and delete ~/.pymolrc_plugins.py'
        )

    if os.path.exists(PYMOLPLUGINSRC):
        from pymol import parsing
        try:
            parsing.run_file(PYMOLPLUGINSRC, {'__script__': PYMOLPLUGINSRC},
                             {})
        except SyntaxError as e:
            colorprinting.warning(str(e))

    autoload = (pmgapp != -2)
    for parent in [startup]:
        modules = findPlugins(parent.__path__)

        for name, filename in modules.items():
            mod_name = parent.__name__ + '.' + name
            info = PluginInfo(name, filename, mod_name)
            if autoload and info.autoload:
                info.load(pmgapp)
    def load(self, pmgapp=None, force=0):
        '''
        Load and initialize plugin.

        If pmgapp == -1, do not initialize.
        '''
        import time

        assert not self.is_temporary

        starttime = time.time()
        if pmgapp is None:
            pmgapp = get_pmgapp()

        verbose = pref_get('verbose', False)

        try:
            # overload cmd.extend to register commands
            extend_orig = cmd.extend

            def extend_overload(a, b=None):
                self.commands.append(a if b else a.__name__)
                return extend_orig(a, b)

            cmd.extend = extend_overload

            # do not use self.loaded here
            if force and self.module is not None:
                from importlib import reload
                reload(self.module)
            else:
                __import__(self.mod_name, level=0)

            if pmgapp != -1:
                self.legacyinit(pmgapp)

            cmd.extend = extend_orig

            self.loadtime = time.time() - starttime
            if verbose and pymol.invocation.options.show_splash:
                print(' Plugin "%s" loaded in %.2f seconds' %
                      (self.name, self.loadtime))
        except QtNotAvailableError:
            colorprinting.warning("Plugin '%s' only available with PyQt GUI." %
                                  (self.name, ))
        except:
            e = sys.exc_info()[1]
            if verbose:
                colorprinting.print_exc([__file__])
            elif 'libX11' in str(e) and sys.platform == 'darwin':
                colorprinting.error(
                    'Please install XQuartz (https://www.xquartz.org/)')
            else:
                colorprinting.error(e)
            colorprinting.warning("Unable to initialize plugin '%s' (%s)." %
                                  (self.name, self.mod_name))
            return False

        return True
Beispiel #4
0
    def load(self, pmgapp=None, force=0):
        '''
        Load and initialize plugin.

        If pmgapp == -1, do not initialize.
        '''
        import time

        assert not self.is_temporary

        starttime = time.time()
        if pmgapp is None:
            pmgapp = get_pmgapp()

        verbose = pref_get('verbose', False)

        try:
            # overload cmd.extend to register commands
            extend_orig = cmd.extend
            def extend_overload(a, b=None):
                self.commands.append(a if b else a.__name__)
                return extend_orig(a, b)
            cmd.extend = extend_overload

            # do not use self.loaded here
            if force and self.module is not None:
                if sys.version_info[0] > 2:
                    from importlib import reload
                else:
                    from __builtin__ import reload
                reload(self.module)
            else:
                __import__(self.mod_name, level=0)

            if pmgapp != -1:
                self.legacyinit(pmgapp)

            cmd.extend = extend_orig

            self.loadtime = time.time() - starttime
            if verbose and pymol.invocation.options.show_splash:
                print(' Plugin "%s" loaded in %.2f seconds' % (self.name, self.loadtime))
        except QtNotAvailableError:
            colorprinting.warning("Plugin '%s' only available with PyQt GUI." % (self.name,))
        except:
            e = sys.exc_info()[1]
            if verbose:
                colorprinting.print_exc([__file__])
            elif 'libX11' in str(e) and sys.platform == 'darwin':
                colorprinting.error('Please install XQuartz (https://www.xquartz.org/)')
            else:
                colorprinting.error(e)
            colorprinting.warning("Unable to initialize plugin '%s' (%s)." % (self.name, self.mod_name))
            return False

        return True