This is a read-only mirror of pymolwiki.org

Difference between revisions of "Plugindirectory"

From PyMOL Wiki
Jump to navigation Jump to search
m (moved PluginDirectory to Plugindirectory: Small letters)
m (1 revision)
 
(23 intermediate revisions by 4 users not shown)
Line 1: Line 1:
This page describes how to set up a personal plugin directory. It supports single python files as well as directories which contain a __init__.py file.
+
<div style="padding: 10px; border: 4px solid red; text-align: center; background-color: #fcc">
 
+
This script was superseded by the [[Plugin Manager]] which was introduced in PyMOL 1.5.0.5
1) Create a directory '''$HOME/.pymol/pymolplugins''', this will be your personal plugin directory. Copy plugins here instead of using the "Plugin > Manage Plugins > Install..." menu.
+
</div>
 
 
2) Create a file '''$HOME/.pymol/pymolplugins/__init__.py''' with the folling content:
 
 
 
<source lang="python">
 
'''
 
PyMOL personal plugin directory
 
Recommended location of this file: ~/.pymol/pymolplugins/__init__.py
 
'''
 
 
 
import os, sys, traceback
 
 
 
# import pymolplugins (allow different name)
 
pymolplugins = sys.modules[__name__]
 
 
 
import pmg_tk.PMGApp
 
x__initializePlugins = pmg_tk.PMGApp.initializePlugins
 
 
 
def initializePlugins(self):
 
    '''
 
    Overloaded version of pmg_tk.PMGApp.initializePlugins
 
    See pmg_tk/PMGApp.py
 
    '''
 
    # load global plugins
 
    x__initializePlugins(self)
 
 
 
    # load user plugins
 
    modules = set()
 
    for path in pymolplugins.__path__:
 
        for filename in os.listdir(path):
 
            name, _, ext = filename.partition('.')
 
            if ext not in ['py', 'pyc', 'pyo']:
 
                if os.path.isdir(os.path.join(path, filename)):
 
                    modules.add(filename)
 
            elif name != '__init__':
 
                modules.add(name)
 
    for name in modules:
 
        mod_name = pymolplugins.__name__ + '.' + name
 
        try:
 
            __import__(mod_name, level=0)
 
            mod = sys.modules[mod_name]
 
            if hasattr(mod,'__init_plugin__'):
 
                mod.__init_plugin__(self)
 
            elif hasattr(mod,'__init__'):
 
                mod.__init__(self)
 
        except:
 
            print "Exception in plugin '%s' -- Traceback follows..."%name
 
            traceback.print_exc()
 
            print "Error: unable to initialize plugin '%s'."%name
 
 
 
# overload method
 
pmg_tk.PMGApp.initializePlugins = initializePlugins
 
</source>
 
 
 
3) We need to import '''pymolplugins''' before the GUI launches, so insert into your [[pymolrc|$HOME/.pymolrc]] file:
 
 
 
<source lang="python">
 
python
 
import sys, os
 
sys.path.append(os.path.expanduser('~/.pymol'))
 
import pymolplugins
 
python end
 
</source>
 
 
 
[[Category:Plugins]]
 

Latest revision as of 03:24, 10 December 2018

This script was superseded by the Plugin Manager which was introduced in PyMOL 1.5.0.5