home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 May / maximum-cd-2009-05.iso / DiscContents / gimp-2.6.5-i686-setup.exe / {app} / lib / gimp / 2.0 / python / gimpfu,2.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-02-15  |  26.2 KB  |  747 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. '''Simple interface to writing GIMP plug-ins in Python.
  5.  
  6. Instead of worrying about all the user interaction, saving last used values
  7. and everything, the gimpfu module can take care of it for you.  It provides
  8. a simple register() function that will register your plug-in if needed, and
  9. cause your plug-in function to be called when needed.
  10.  
  11. Gimpfu will also handle showing a user interface for editing plug-in parameters
  12. if the plug-in is called interactively, and will also save the last used
  13. parameters, so the RUN_WITH_LAST_VALUES run_type will work correctly.  It
  14. will also make sure that the displays are flushed on completion if the plug-in
  15. was run interactively.
  16.  
  17. When registering the plug-in, you do not need to worry about specifying
  18. the run_type parameter.
  19.  
  20. A typical gimpfu plug-in would look like this:
  21.   from gimpfu import *
  22.  
  23.   def plugin_func(image, drawable, args):
  24.               #do what plugins do best
  25.   register(
  26.               "plugin_func",
  27.               "blurb",
  28.               "help message",
  29.               "author",
  30.               "copyright",
  31.               "year",
  32.               "My plug-in",
  33.               "*",
  34.               [
  35.                   (PF_IMAGE, "image", "Input image"),
  36.                   (PF_DRAWABLE, "drawable", "Input drawable"),
  37.                   (PF_STRING, "arg", "The argument", "default-value")
  38.               ],
  39.               [],
  40.               plugin_func, menu="<Image>/Somewhere")
  41.   main()
  42.  
  43. The call to "from gimpfu import *" will import all the gimp constants into
  44. the plug-in namespace, and also import the symbols gimp, pdb, register and
  45. main.  This should be just about all any plug-in needs.
  46.  
  47. You can use any of the PF_* constants below as parameter types, and an
  48. appropriate user interface element will be displayed when the plug-in is
  49. run in interactive mode.  Note that the the PF_SPINNER and PF_SLIDER types
  50. expect a fifth element in their description tuple -- a 3-tuple of the form
  51. (lower,upper,step), which defines the limits for the slider or spinner.
  52.  
  53. If want to localize your plug-in, add an optional domain parameter to the
  54. register call. It can be the name of the translation domain or a tuple that
  55. consists of the translation domain and the directory where the translations
  56. are installed.
  57. '''
  58. import string as _string
  59. import math
  60. import gimp
  61. import gimpcolor
  62. from gimpenums import *
  63. pdb = gimp.pdb
  64. import gettext
  65. t = gettext.translation('gimp20-python', gimp.locale_directory, fallback = True)
  66. _ = t.ugettext
  67.  
  68. class error(RuntimeError):
  69.     pass
  70.  
  71.  
  72. class CancelError(RuntimeError):
  73.     pass
  74.  
  75. PF_INT8 = PDB_INT8
  76. PF_INT16 = PDB_INT16
  77. PF_INT32 = PDB_INT32
  78. PF_INT = PF_INT32
  79. PF_FLOAT = PDB_FLOAT
  80. PF_STRING = PDB_STRING
  81. PF_VALUE = PF_STRING
  82. PF_COLOR = PDB_COLOR
  83. PF_COLOUR = PF_COLOR
  84. PF_REGION = PDB_REGION
  85. PF_DISPLAY = PDB_DISPLAY
  86. PF_IMAGE = PDB_IMAGE
  87. PF_LAYER = PDB_LAYER
  88. PF_CHANNEL = PDB_CHANNEL
  89. PF_DRAWABLE = PDB_DRAWABLE
  90. PF_VECTORS = PDB_VECTORS
  91. PF_TOGGLE = 1000
  92. PF_BOOL = PF_TOGGLE
  93. PF_SLIDER = 1001
  94. PF_SPINNER = 1002
  95. PF_ADJUSTMENT = PF_SPINNER
  96. PF_FONT = 1003
  97. PF_FILE = 1004
  98. PF_BRUSH = 1005
  99. PF_PATTERN = 1006
  100. PF_GRADIENT = 1007
  101. PF_RADIO = 1008
  102. PF_TEXT = 1009
  103. PF_PALETTE = 1010
  104. PF_FILENAME = 1011
  105. PF_DIRNAME = 1012
  106. PF_OPTION = 1013
  107. _type_mapping = {
  108.     PF_INT8: PDB_INT8,
  109.     PF_INT16: PDB_INT16,
  110.     PF_INT32: PDB_INT32,
  111.     PF_FLOAT: PDB_FLOAT,
  112.     PF_STRING: PDB_STRING,
  113.     PF_COLOR: PDB_COLOR,
  114.     PF_REGION: PDB_REGION,
  115.     PF_DISPLAY: PDB_DISPLAY,
  116.     PF_IMAGE: PDB_IMAGE,
  117.     PF_LAYER: PDB_LAYER,
  118.     PF_CHANNEL: PDB_CHANNEL,
  119.     PF_DRAWABLE: PDB_DRAWABLE,
  120.     PF_VECTORS: PDB_VECTORS,
  121.     PF_TOGGLE: PDB_INT32,
  122.     PF_SLIDER: PDB_FLOAT,
  123.     PF_SPINNER: PDB_INT32,
  124.     PF_FONT: PDB_STRING,
  125.     PF_FILE: PDB_STRING,
  126.     PF_BRUSH: PDB_STRING,
  127.     PF_PATTERN: PDB_STRING,
  128.     PF_GRADIENT: PDB_STRING,
  129.     PF_RADIO: PDB_STRING,
  130.     PF_TEXT: PDB_STRING,
  131.     PF_PALETTE: PDB_STRING,
  132.     PF_FILENAME: PDB_STRING,
  133.     PF_DIRNAME: PDB_STRING,
  134.     PF_OPTION: PDB_INT32 }
  135. _obj_mapping = {
  136.     PF_INT8: int,
  137.     PF_INT16: int,
  138.     PF_INT32: int,
  139.     PF_FLOAT: float,
  140.     PF_STRING: str,
  141.     PF_COLOR: gimpcolor.RGB,
  142.     PF_REGION: int,
  143.     PF_DISPLAY: gimp.Display,
  144.     PF_IMAGE: gimp.Image,
  145.     PF_LAYER: gimp.Layer,
  146.     PF_CHANNEL: gimp.Channel,
  147.     PF_DRAWABLE: gimp.Drawable,
  148.     PF_VECTORS: gimp.Vectors,
  149.     PF_TOGGLE: bool,
  150.     PF_SLIDER: float,
  151.     PF_SPINNER: int,
  152.     PF_FONT: str,
  153.     PF_FILE: str,
  154.     PF_BRUSH: str,
  155.     PF_PATTERN: str,
  156.     PF_GRADIENT: str,
  157.     PF_RADIO: str,
  158.     PF_TEXT: str,
  159.     PF_PALETTE: str,
  160.     PF_FILENAME: str,
  161.     PF_DIRNAME: str,
  162.     PF_OPTION: int }
  163. _registered_plugins_ = { }
  164.  
  165. def register(proc_name, blurb, help, author, copyright, date, label, imagetypes, params, results, function, menu = None, domain = None, on_query = None, on_run = None):
  166.     '''This is called to register a new plug-in.'''
  167.     
  168.     def letterCheck(str):
  169.         allowed = _string.letters + _string.digits + '_' + '-'
  170.         for ch in str:
  171.             if ch not in allowed:
  172.                 return 0
  173.                 continue
  174.         else:
  175.             return 1
  176.  
  177.     if not letterCheck(proc_name):
  178.         raise error, 'procedure name contains illegal characters'
  179.     
  180.     for ent in params:
  181.         if len(ent) < 4:
  182.             raise error, 'parameter definition must contain at least 4 elements (%s given: %s)' % (len(ent), ent)
  183.         
  184.         if type(ent[0]) != int:
  185.             raise error, 'parameter types must be integers'
  186.         
  187.         if not letterCheck(ent[1]):
  188.             raise error, 'parameter name contains illegal characters'
  189.             continue
  190.     
  191.     for ent in results:
  192.         if len(ent) < 3:
  193.             raise error, 'result definition must contain at least 3 elements (%s given: %s)' % (len(ent), ent)
  194.         
  195.         if type(ent[0]) != type(42):
  196.             raise error, 'result types must be integers'
  197.         
  198.         if not letterCheck(ent[1]):
  199.             raise error, 'result name contains illegal characters'
  200.             continue
  201.     
  202.     plugin_type = PLUGIN
  203.     if not (proc_name[:7] == 'python-') and not (proc_name[:7] == 'python_') and not (proc_name[:10] == 'extension-') and not (proc_name[:10] == 'extension_') and not (proc_name[:8] == 'plug-in-') and not (proc_name[:8] == 'plug_in_') and not (proc_name[:5] == 'file-') and not (proc_name[:5] == 'file_'):
  204.         proc_name = 'python-fu-' + proc_name
  205.     
  206.     need_compat_params = False
  207.     if menu is None and label:
  208.         fields = label.split('/')
  209.         if fields:
  210.             label = fields.pop()
  211.             menu = '/'.join(fields)
  212.             need_compat_params = True
  213.         
  214.         if need_compat_params and plugin_type == PLUGIN:
  215.             file_params = [
  216.                 (PDB_STRING, 'filename', 'The name of the file', ''),
  217.                 (PDB_STRING, 'raw-filename', 'The name of the file', '')]
  218.             if menu is None:
  219.                 pass
  220.             elif menu[:6] == '<Load>':
  221.                 params[0:0] = file_params
  222.             elif menu[:7] == '<Image>' or menu[:6] == '<Save>':
  223.                 params.insert(0, (PDB_IMAGE, 'image', 'Input image', None))
  224.                 params.insert(1, (PDB_DRAWABLE, 'drawable', 'Input drawable', None))
  225.                 if menu[:6] == '<Save>':
  226.                     params[2:2] = file_params
  227.                 
  228.             
  229.         
  230.     
  231.     _registered_plugins_[proc_name] = (blurb, help, author, copyright, date, label, imagetypes, plugin_type, params, results, function, menu, domain, on_query, on_run)
  232.  
  233.  
  234. def _query():
  235.     for plugin in _registered_plugins_.keys():
  236.         (blurb, help, author, copyright, date, label, imagetypes, plugin_type, params, results, function, menu, domain, on_query, on_run) = _registered_plugins_[plugin]
  237.         
  238.         def make_params(params):
  239.             return [ (_type_mapping[x[0]], x[1], _string.replace(x[2], '_', '')) for x in params ]
  240.  
  241.         params = make_params(params)
  242.         params.insert(0, (PDB_INT32, 'run-mode', 'Interactive, Non-Interactive'))
  243.         results = make_params(results)
  244.         if domain:
  245.             
  246.             try:
  247.                 (domain, locale_dir) = domain
  248.                 gimp.domain_register(domain, locale_dir)
  249.             except ValueError:
  250.                 gimp.domain_register(domain)
  251.             except:
  252.                 None<EXCEPTION MATCH>ValueError
  253.             
  254.  
  255.         None<EXCEPTION MATCH>ValueError
  256.         gimp.install_procedure(plugin, blurb, help, author, copyright, date, label, imagetypes, plugin_type, params, results)
  257.         if menu:
  258.             gimp.menu_register(plugin, menu)
  259.         
  260.         if on_query:
  261.             on_query()
  262.             continue
  263.     
  264.  
  265.  
  266. def _get_defaults(proc_name):
  267.     import gimpshelf
  268.     (blurb, help, author, copyright, date, label, imagetypes, plugin_type, params, results, function, menu, domain, on_query, on_run) = _registered_plugins_[proc_name]
  269.     key = 'python-fu-save--' + proc_name
  270.  
  271.  
  272. def _set_defaults(proc_name, defaults):
  273.     import gimpshelf
  274.     key = 'python-fu-save--' + proc_name
  275.     gimpshelf.shelf[key] = defaults
  276.  
  277.  
  278. def _interact(proc_name, start_params):
  279.     (blurb, help, author, copyright, date, label, imagetypes, plugin_type, params, results, function, menu, domain, on_query, on_run) = _registered_plugins_[proc_name]
  280.     
  281.     def run_script(run_params):
  282.         params = start_params + tuple(run_params)
  283.         _set_defaults(proc_name, params)
  284.         return apply(function, params)
  285.  
  286.     params = params[len(start_params):]
  287.     if len(params) == 0:
  288.         return run_script([])
  289.     
  290.     import pygtk
  291.     pygtk.require('2.0')
  292.     import gimpui
  293.     import gtk
  294.     defaults = _get_defaults(proc_name)
  295.     defaults = defaults[len(start_params):]
  296.     
  297.     class EntryValueError(Exception):
  298.         pass
  299.  
  300.     
  301.     def warning_dialog(parent, primary, secondary = (None,)):
  302.         dlg = gtk.MessageDialog(parent, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_WARNING, gtk.BUTTONS_CLOSE, primary)
  303.         if secondary:
  304.             dlg.format_secondary_text(secondary)
  305.         
  306.         dlg.run()
  307.         dlg.destroy()
  308.  
  309.     
  310.     def error_dialog(parent, proc_name):
  311.         import sys
  312.         import traceback
  313.         exc_str = exc_only_str = _('Missing exception information')
  314.         
  315.         try:
  316.             (etype, value, tb) = sys.exc_info()
  317.             exc_str = ''.join(traceback.format_exception(etype, value, tb))
  318.             exc_only_str = ''.join(traceback.format_exception_only(etype, value))
  319.         finally:
  320.             etype = None
  321.             value = None
  322.             tb = None
  323.  
  324.         title = _('An error occured running %s') % proc_name
  325.         dlg = gtk.MessageDialog(parent, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, title)
  326.         dlg.format_secondary_text(exc_only_str)
  327.         alignment = gtk.Alignment(0, 0, 1, 1)
  328.         alignment.set_padding(0, 0, 12, 12)
  329.         dlg.vbox.pack_start(alignment)
  330.         alignment.show()
  331.         expander = gtk.Expander(_('_More Information'))
  332.         expander.set_use_underline(True)
  333.         expander.set_spacing(6)
  334.         alignment.add(expander)
  335.         expander.show()
  336.         scrolled = gtk.ScrolledWindow()
  337.         scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
  338.         scrolled.set_size_request(-1, 200)
  339.         expander.add(scrolled)
  340.         scrolled.show()
  341.         label = gtk.Label(exc_str)
  342.         label.set_alignment(0, 0)
  343.         label.set_padding(6, 6)
  344.         label.set_selectable(True)
  345.         scrolled.add_with_viewport(label)
  346.         label.show()
  347.         
  348.         def response(widget, id):
  349.             widget.destroy()
  350.  
  351.         dlg.connect('response', response)
  352.         dlg.set_resizable(True)
  353.         dlg.show()
  354.  
  355.     
  356.     class StringEntry((gtk.Entry,)):
  357.         
  358.         def __init__(self, default = ('',)):
  359.             gtk.Entry.__init__(self)
  360.             self.set_text(str(default))
  361.  
  362.         
  363.         def get_value(self):
  364.             return self.get_text()
  365.  
  366.  
  367.     
  368.     class TextEntry((gtk.ScrolledWindow,)):
  369.         
  370.         def __init__(self, default = ('',)):
  371.             gtk.ScrolledWindow.__init__(self)
  372.             self.set_shadow_type(gtk.SHADOW_IN)
  373.             self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
  374.             self.set_size_request(100, -1)
  375.             self.view = gtk.TextView()
  376.             self.add(self.view)
  377.             self.view.show()
  378.             self.buffer = self.view.get_buffer()
  379.             self.set_value(str(default))
  380.  
  381.         
  382.         def set_value(self, text):
  383.             self.buffer.set_text(text)
  384.  
  385.         
  386.         def get_value(self):
  387.             return self.buffer.get_text(self.buffer.get_start_iter(), self.buffer.get_end_iter())
  388.  
  389.  
  390.     
  391.     class IntEntry((StringEntry,)):
  392.         
  393.         def get_value(self):
  394.             
  395.             try:
  396.                 return int(self.get_text())
  397.             except ValueError:
  398.                 e = None
  399.                 raise EntryValueError, e.args
  400.  
  401.  
  402.  
  403.     
  404.     class FloatEntry((StringEntry,)):
  405.         
  406.         def get_value(self):
  407.             
  408.             try:
  409.                 return float(self.get_text())
  410.             except ValueError:
  411.                 e = None
  412.                 raise EntryValueError, e.args
  413.  
  414.  
  415.  
  416.     
  417.     def precision(step):
  418.         if math.fabs(step) >= 1 or step == 0:
  419.             digits = 0
  420.         else:
  421.             digits = abs(math.floor(math.log10(math.fabs(step))))
  422.         if digits > 20:
  423.             digits = 20
  424.         
  425.         return int(digits)
  426.  
  427.     
  428.     class SliderEntry('SliderEntry', (gtk.HScale,)):
  429.         
  430.         def __init__(self, default = None, bounds = (0, (0, 100, 5))):
  431.             step = bounds[2]
  432.             self.adj = gtk.Adjustment(default, bounds[0], bounds[1], step, 10 * step, 0)
  433.             gtk.HScale.__init__(self, self.adj)
  434.             self.set_digits(precision(step))
  435.  
  436.         
  437.         def get_value(self):
  438.             return self.adj.value
  439.  
  440.  
  441.     
  442.     class SpinnerEntry('SpinnerEntry', (gtk.SpinButton,)):
  443.         
  444.         def __init__(self, default = None, bounds = (0, (0, 100, 5))):
  445.             step = bounds[2]
  446.             self.adj = gtk.Adjustment(default, bounds[0], bounds[1], step, 10 * step, 0)
  447.             gtk.SpinButton.__init__(self, self.adj, step, precision(step))
  448.  
  449.  
  450.     
  451.     class ToggleEntry((gtk.ToggleButton,)):
  452.         
  453.         def __init__(self, default = (0,)):
  454.             gtk.ToggleButton.__init__(self)
  455.             self.label = gtk.Label(_('No'))
  456.             self.add(self.label)
  457.             self.label.show()
  458.             self.connect('toggled', self.changed)
  459.             self.set_active(default)
  460.  
  461.         
  462.         def changed(self, tog):
  463.             if tog.get_active():
  464.                 self.label.set_text(_('Yes'))
  465.             else:
  466.                 self.label.set_text(_('No'))
  467.  
  468.         
  469.         def get_value(self):
  470.             return self.get_active()
  471.  
  472.  
  473.     
  474.     class RadioEntry((gtk.VBox,)):
  475.         
  476.         def __init__(self, default = 0, items = (((_('Yes'), 1), (_('No'), 0)),)):
  477.             gtk.VBox.__init__(self, homogeneous = False, spacing = 2)
  478.             button = None
  479.             for label, value in items:
  480.                 button = gtk.RadioButton(button, label)
  481.                 self.pack_start(button)
  482.                 button.show()
  483.                 button.connect('toggled', self.changed, value)
  484.                 if value == default:
  485.                     button.set_active(True)
  486.                     self.active_value = value
  487.                     continue
  488.             
  489.  
  490.         
  491.         def changed(self, radio, value):
  492.             if radio.get_active():
  493.                 self.active_value = value
  494.             
  495.  
  496.         
  497.         def get_value(self):
  498.             return self.active_value
  499.  
  500.  
  501.     
  502.     class ComboEntry((gtk.ComboBox,)):
  503.         
  504.         def __init__(self, default = 0, items = ((),)):
  505.             store = gtk.ListStore(str)
  506.             for item in items:
  507.                 store.append([
  508.                     item])
  509.             
  510.             gtk.ComboBox.__init__(self, model = store)
  511.             cell = gtk.CellRendererText()
  512.             self.pack_start(cell)
  513.             self.set_attributes(cell, text = 0)
  514.             self.set_active(default)
  515.  
  516.         
  517.         def get_value(self):
  518.             return self.get_active()
  519.  
  520.  
  521.     
  522.     def FileSelector(default = (None, '')):
  523.         if default and default.endswith('/'):
  524.             selector = DirnameSelector
  525.             if default == '/':
  526.                 default = ''
  527.             
  528.         else:
  529.             selector = FilenameSelector
  530.         return selector(default)
  531.  
  532.     
  533.     class FilenameSelector((gtk.FileChooserButton,)):
  534.         
  535.         def __init__(self, default = '', save_mode = (False,)):
  536.             gtk.FileChooserButton.__init__(self, _('Python-Fu File Selection'))
  537.             self.set_action(gtk.FILE_CHOOSER_ACTION_OPEN)
  538.             if default:
  539.                 self.set_filename(default)
  540.             
  541.  
  542.         
  543.         def get_value(self):
  544.             return self.get_filename()
  545.  
  546.  
  547.     
  548.     class DirnameSelector((gtk.FileChooserButton,)):
  549.         
  550.         def __init__(self, default = ('',)):
  551.             gtk.FileChooserButton.__init__(self, _('Python-Fu Folder Selection'))
  552.             self.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
  553.             if default:
  554.                 self.set_filename(default)
  555.             
  556.  
  557.         
  558.         def get_value(self):
  559.             return self.get_filename()
  560.  
  561.  
  562.     _edit_mapping = {
  563.         PF_INT8: IntEntry,
  564.         PF_INT16: IntEntry,
  565.         PF_INT32: IntEntry,
  566.         PF_FLOAT: FloatEntry,
  567.         PF_STRING: StringEntry,
  568.         PF_COLOR: gimpui.ColorSelector,
  569.         PF_REGION: IntEntry,
  570.         PF_IMAGE: gimpui.ImageSelector,
  571.         PF_LAYER: gimpui.LayerSelector,
  572.         PF_CHANNEL: gimpui.ChannelSelector,
  573.         PF_DRAWABLE: gimpui.DrawableSelector,
  574.         PF_VECTORS: gimpui.VectorsSelector,
  575.         PF_TOGGLE: ToggleEntry,
  576.         PF_SLIDER: SliderEntry,
  577.         PF_SPINNER: SpinnerEntry,
  578.         PF_RADIO: RadioEntry,
  579.         PF_OPTION: ComboEntry,
  580.         PF_FONT: gimpui.FontSelector,
  581.         PF_FILE: FileSelector,
  582.         PF_FILENAME: FilenameSelector,
  583.         PF_DIRNAME: DirnameSelector,
  584.         PF_BRUSH: gimpui.BrushSelector,
  585.         PF_PATTERN: gimpui.PatternSelector,
  586.         PF_GRADIENT: gimpui.GradientSelector,
  587.         PF_PALETTE: gimpui.PaletteSelector,
  588.         PF_TEXT: TextEntry }
  589.     if on_run:
  590.         on_run()
  591.     
  592.     tooltips = gtk.Tooltips()
  593.     dialog = gimpui.Dialog(proc_name, 'python-fu', None, 0, None, proc_name, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
  594.     dialog.set_alternative_button_order((gtk.RESPONSE_OK, gtk.RESPONSE_CANCEL))
  595.     dialog.set_transient()
  596.     vbox = gtk.VBox(False, 12)
  597.     vbox.set_border_width(12)
  598.     dialog.vbox.pack_start(vbox)
  599.     vbox.show()
  600.     if blurb:
  601.         if domain:
  602.             
  603.             try:
  604.                 (domain, locale_dir) = domain
  605.                 trans = gettext.translation(domain, locale_dir, fallback = True)
  606.             except ValueError:
  607.                 trans = gettext.translation(domain, fallback = True)
  608.  
  609.             blurb = trans.ugettext(blurb)
  610.         
  611.         box = gimpui.HintBox(blurb)
  612.         vbox.pack_start(box, expand = False)
  613.         box.show()
  614.     
  615.     table = gtk.Table(len(params), 2, False)
  616.     table.set_row_spacings(6)
  617.     table.set_col_spacings(6)
  618.     vbox.pack_start(table, expand = False)
  619.     table.show()
  620.     
  621.     def response(dlg, id):
  622.         if id == gtk.RESPONSE_OK:
  623.             dlg.set_response_sensitive(gtk.RESPONSE_OK, False)
  624.             dlg.set_response_sensitive(gtk.RESPONSE_CANCEL, False)
  625.             params = []
  626.             
  627.             try:
  628.                 for wid in edit_wids:
  629.                     params.append(wid.get_value())
  630.             except EntryValueError:
  631.                 warning_dialog(dialog, _("Invalid input for '%s'") % wid.desc)
  632.  
  633.             
  634.             try:
  635.                 dialog.res = run_script(params)
  636.             except Exception:
  637.                 dlg.set_response_sensitive(gtk.RESPONSE_CANCEL, True)
  638.                 error_dialog(dialog, proc_name)
  639.                 raise 
  640.             except:
  641.                 None<EXCEPTION MATCH>Exception
  642.             
  643.  
  644.         None<EXCEPTION MATCH>Exception
  645.         gtk.main_quit()
  646.  
  647.     dialog.connect('response', response)
  648.     edit_wids = []
  649.     for i in range(len(params)):
  650.         pf_type = params[i][0]
  651.         name = params[i][1]
  652.         desc = params[i][2]
  653.         def_val = defaults[i]
  654.         label = gtk.Label(desc)
  655.         label.set_use_underline(True)
  656.         label.set_alignment(0, 0.5)
  657.         table.attach(label, 1, 2, i, i + 1, xoptions = gtk.FILL)
  658.         label.show()
  659.         if pf_type in (PF_SPINNER, PF_SLIDER, PF_RADIO, PF_OPTION):
  660.             wid = _edit_mapping[pf_type](def_val, params[i][4])
  661.         else:
  662.             wid = _edit_mapping[pf_type](def_val)
  663.         label.set_mnemonic_widget(wid)
  664.         table.attach(wid, 2, 3, i, i + 1, yoptions = 0)
  665.         if pf_type != PF_TEXT:
  666.             tooltips.set_tip(wid, desc, None)
  667.         else:
  668.             tooltips.set_tip(wid.view, desc, None)
  669.         wid.show()
  670.         wid.desc = desc
  671.         edit_wids.append(wid)
  672.     
  673.     progress_vbox = gtk.VBox(False, 6)
  674.     vbox.pack_end(progress_vbox, expand = False)
  675.     progress_vbox.show()
  676.     progress = gimpui.ProgressBar()
  677.     progress_vbox.pack_start(progress)
  678.     progress.show()
  679.     tooltips.enable()
  680.     dialog.show()
  681.     gtk.main()
  682.     if hasattr(dialog, 'res'):
  683.         res = dialog.res
  684.         dialog.destroy()
  685.         return res
  686.     else:
  687.         dialog.destroy()
  688.         raise CancelError
  689.  
  690.  
  691. def _run(proc_name, params):
  692.     run_mode = params[0]
  693.     func = _registered_plugins_[proc_name][10]
  694.     if run_mode == RUN_NONINTERACTIVE:
  695.         return apply(func, params[1:])
  696.     
  697.     script_params = _registered_plugins_[proc_name][8]
  698.     min_args = 0
  699.     if len(params) > 1:
  700.         for i in range(1, len(params)):
  701.             param_type = _obj_mapping[script_params[i - 1][0]]
  702.             if not isinstance(params[i], param_type):
  703.                 break
  704.                 continue
  705.         
  706.         min_args = i
  707.     
  708.     if len(script_params) > min_args:
  709.         start_params = params[:min_args + 1]
  710.         if run_mode == RUN_WITH_LAST_VALS:
  711.             default_params = _get_defaults(proc_name)
  712.             params = start_params + default_params[min_args:]
  713.         else:
  714.             params = start_params
  715.     else:
  716.         run_mode = RUN_NONINTERACTIVE
  717.     if run_mode == RUN_INTERACTIVE:
  718.         
  719.         try:
  720.             res = _interact(proc_name, params[1:])
  721.         except CancelError:
  722.             return None
  723.         except:
  724.             None<EXCEPTION MATCH>CancelError
  725.         
  726.  
  727.     None<EXCEPTION MATCH>CancelError
  728.     res = apply(func, params[1:])
  729.     gimp.displays_flush()
  730.     return res
  731.  
  732.  
  733. def main():
  734.     '''This should be called after registering the plug-in.'''
  735.     gimp.main(None, None, _query, _run)
  736.  
  737.  
  738. def fail(msg):
  739.     '''Display and error message and quit'''
  740.     gimp.message(msg)
  741.     raise error, msg
  742.  
  743.  
  744. def N_(message):
  745.     return message
  746.  
  747.