gimpplugin.py 2.06 KB
Newer Older
1 2 3
#   Gimp-Python - allows the writing of Gimp plugins in Python.
#   Copyright (C) 1997  James Henstridge <james@daa.com.au>
#
4
#    This program is free software: you can redistribute it and/or modify
5
#   it under the terms of the GNU General Public License as published by
6
#   the Free Software Foundation; either version 3 of the License, or
7 8 9 10 11 12 13 14
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
15
#   along with this program.  If not, see <https://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23 24 25 26 27

#   plugin.py -- helper for writing gimp plugins
#     Copyright (C) 1997, James Henstridge.
#
# This is a small wrapper that makes plugins look like an object class that
# you can derive to create your plugin.  With this wrapper, you are pretty
# much responsible for doing everything (checking run_mode, gui, etc).  If
# you want to write a quick plugin, you probably want the gimpfu module.
#
# A plugin using this module would look something like this:
#
#   import gimp, gimpplugin
28
#
29
#   pdb = gimp.pdb
30
#
31
#   class myplugin(gimpplugin.plugin):
32 33
#       def query(self):
#           gimp.install_procedure("plug_in_mine", ...)
34
#
35 36 37 38 39
#       def plug_in_mine(self, par1, par2, par3,...):
#           do_something()
#
#   if __name__ == '__main__':
#       myplugin().start()
40 41 42 43

import gimp

class plugin:
James Henstridge's avatar
James Henstridge committed
44
    def start(self):
45
        gimp.main(self.init, self.quit, self.query, self._run)
46

James Henstridge's avatar
James Henstridge committed
47
    def init(self):
48
        pass
49

James Henstridge's avatar
James Henstridge committed
50
    def quit(self):
51
        pass
52

James Henstridge's avatar
James Henstridge committed
53
    def query(self):
54
        pass
55

James Henstridge's avatar
James Henstridge committed
56
    def _run(self, name, params):
57 58 59 60
        import sys
        if "gimpui" in sys.modules.keys():
            sys.modules["gimpui"].gimp_ui_init ()

61
        if hasattr(self, name):
62
            return apply(getattr(self, name), params)
63 64
        else:
            raise AttributeError, name
65

66 67
if __name__ == '__main__':
    plugin().start()