home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / gimp / 2.0 / plug-ins / gimpcons.py < prev    next >
Encoding:
Python Source  |  2006-07-10  |  2.9 KB  |  110 lines

  1. #!/usr/bin/env python
  2.  
  3. #   Gimp-Python - allows the writing of Gimp plugins in Python.
  4. #   Copyright (C) 1997  James Henstridge <james@daa.com.au>
  5. #
  6. #   This program is free software; you can redistribute it and/or modify
  7. #   it under the terms of the GNU General Public License as published by
  8. #   the Free Software Foundation; either version 2 of the License, or
  9. #   (at your option) any later version.
  10. #
  11. #   This program is distributed in the hope that it will be useful,
  12. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #   GNU General Public License for more details.
  15. #
  16. #   You should have received a copy of the GNU General Public License
  17. #   along with this program; if not, write to the Free Software
  18. #   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19.  
  20. from gimpfu import *
  21.  
  22. def plug_in_python_fu_console():
  23.     import pygtk
  24.     pygtk.require('2.0')
  25.  
  26.     import gtk, gimpenums, gimpshelf
  27.  
  28.     gtk.rc_parse(gimp.gtkrc())
  29.  
  30.     namespace = {'__builtins__': __builtins__,
  31.                  '__name__': '__main__', '__doc__': None,
  32.                  'gimp': gimp, 'pdb': gimp.pdb,
  33.                  'shelf': gimpshelf.shelf}
  34.  
  35.     for s in gimpenums.__dict__.keys():
  36.         if s[0] != '_':
  37.             namespace[s] = getattr(gimpenums, s)
  38.  
  39.     def bye(*args):
  40.         gtk.main_quit()
  41.  
  42.     win = gtk.Window()
  43.     win.connect("destroy", bye)
  44.     win.set_title("Gimp-Python Console")
  45.  
  46.     import gtkcons
  47.     cons = gtkcons.Console(namespace=namespace, quit_cb=bye)
  48.  
  49.     def browse(button, cons):
  50.         import gimpprocbrowser
  51.  
  52.         def on_apply(proc): 
  53.             cmd = ''
  54.  
  55.             if len(proc.return_vals) > 0:
  56.                 cmd = ', '.join([x[1] for x in proc.return_vals]) + ' = '
  57.  
  58.             if '-' in proc.proc_name:
  59.                 cmd = cmd + "pdb['%s']" % proc.proc_name
  60.             else:
  61.                 cmd = cmd + "pdb.%s" % proc.proc_name
  62.  
  63.             if len(proc.params) > 0 and proc.params[0][1] == 'run_mode':
  64.                 params = proc.params[1:]
  65.             else:
  66.                 params = proc.params
  67.  
  68.             cmd = cmd + "(%s)" % ', '.join([x[1] for x in params])
  69.  
  70.             cons.line.set_text(cmd)
  71.     
  72.         dlg = gimpprocbrowser.dialog_new(on_apply)
  73.  
  74.     button = gtk.Button("Browse")
  75.     button.connect("clicked", browse, cons)
  76.  
  77.     cons.inputbox.pack_end(button, expand=FALSE)
  78.     button.show()
  79.  
  80.     win.add(cons)
  81.     cons.show()
  82.  
  83.     win.set_default_size(475, 300)
  84.     win.show()
  85.  
  86.     cons.init()
  87.  
  88.     # flush the displays every half second
  89.     def timeout():
  90.         gimp.displays_flush()
  91.         return TRUE
  92.  
  93.     gtk.timeout_add(500, timeout)
  94.     gtk.main()
  95.  
  96. register(
  97.     "python_fu_console",
  98.     "Python interactive interpreter with gimp extensions",
  99.     "Type in commands and see results",
  100.     "James Henstridge",
  101.     "James Henstridge",
  102.     "1997-1999",
  103.     "<Toolbox>/Xtns/Python-Fu/_Console",
  104.     "",
  105.     [],
  106.     [],
  107.     plug_in_python_fu_console)
  108.  
  109. main()
  110.