Commit f8861444 authored by Manish Singh's avatar Manish Singh Committed by Manish Singh
Browse files

use dialog.run() for sub dialogs, since the main dialog is also doing

2003-02-08  Manish Singh  <yosh@gimp.org>

        * gimpui.py: use dialog.run() for sub dialogs, since the main dialog
        is also doing that. This does break consistency with the rest of
        gimp, but will do for now. I wish there was a similar API that didn't
        set the dialog modal. Fixed brush and pattern list to use the new
        PDB names. Also make the filesel really have a title of "Files"

        * gimpshelf.py: minor clean up, use cStringIO if available

        * gimpfu.py: add support for Load/Save plug-ins. Use GtkImage
        instead of deprecated GtkPixmap.

        * gimpenums.py: regenerated

        * plug-ins/Makefile.am
        * plug-ins/colorhtml.py: the return of colorhtml to 1.3
parent b72a6a87
2003-02-08 Manish Singh <yosh@gimp.org>
* gimpui.py: use dialog.run() for sub dialogs, since the main dialog
is also doing that. This does break consistency with the rest of
gimp, but will do for now. I wish there was a similar API that didn't
set the dialog modal. Fixed brush and pattern list to use the new
PDB names. Also make the filesel really have a title of "Files"
* gimpshelf.py: minor clean up, use cStringIO if available
* gimpfu.py: add support for Load/Save plug-ins. Use GtkImage
instead of deprecated GtkPixmap.
* gimpenums.py: regenerated
* plug-ins/Makefile.am
* plug-ins/colorhtml.py: the return of colorhtml to 1.3
2003-01-08 Manish Singh <yosh@gimp.org>
* plug-ins/gimpcons.py: import gtkcons only when we're about to use
......
......@@ -23,21 +23,28 @@
# NOTE: This file is autogenerated by enumcode-py.pl.
TRUE = 1
FALSE = 0
# TRUE and FALSE constants ...
import __builtin__
if not hasattr(__builtin__, 'True'):
__builtin__.True = (1 == 1)
__builtin__.False = (1 != 1)
del __builtin__
FALSE = False
TRUE = True
# GimpAddMaskType
ADD_WHITE_MASK = 0
ADD_BLACK_MASK = 1
ADD_ALPHA_MASK = 2
ADD_SELECTION_MASK = 3
ADD_WHITE_MASK = 0
ADD_BLACK_MASK = 1
ADD_ALPHA_MASK = 2
ADD_SELECTION_MASK = 3
ADD_INVERSE_SELECTION_MASK = 4
ADD_COPY_MASK = 5
ADD_INVERSE_COPY_MASK = 6
ADD_COPY_MASK = 5
ADD_INVERSE_COPY_MASK = 6
# GimpBlendMode
FG_BG_RGB_MODE = 0
FG_BG_HSV_MODE = 1
FG_BG_RGB_MODE = 0
FG_BG_HSV_MODE = 1
FG_TRANSPARENT_MODE = 2
CUSTOM_MODE = 3
......@@ -46,208 +53,229 @@ BRUSH_HARD = 0
BRUSH_SOFT = 1
# GimpBucketFillMode
FG_BUCKET_FILL = 0
BG_BUCKET_FILL = 1
FG_BUCKET_FILL = 0
BG_BUCKET_FILL = 1
PATTERN_BUCKET_FILL = 2
# GimpChannelLutType
VALUE_LUT = 0
RED_LUT = 1
RED_LUT = 1
GREEN_LUT = 2
BLUE_LUT = 3
BLUE_LUT = 3
ALPHA_LUT = 4
# GimpChannelOps
CHANNEL_OP_ADD = 0
CHANNEL_OP_SUB = 1
CHANNEL_OP_REPLACE = 2
CHANNEL_OP_ADD = 0
CHANNEL_OP_SUBTRACT = 1
CHANNEL_OP_REPLACE = 2
CHANNEL_OP_INTERSECT = 3
# GimpChannelType
RED_CHANNEL = 0
GREEN_CHANNEL = 1
BLUE_CHANNEL = 2
GRAY_CHANNEL = 3
INDEXED_CHANNEL = 4
AUXILLARY_CHANNEL = 5
RED_CHANNEL = 0
GREEN_CHANNEL = 1
BLUE_CHANNEL = 2
GRAY_CHANNEL = 3
INDEXED_CHANNEL = 4
ALPHA_CHANNEL = 5
# GimpCloneType
IMAGE_CLONE = 0
IMAGE_CLONE = 0
PATTERN_CLONE = 1
# GimpConvertDitherType
NO_DITHER = 0
FS_DITHER = 1
NO_DITHER = 0
FS_DITHER = 1
FSLOWBLEED_DITHER = 2
FIXED_DITHER = 3
FIXED_DITHER = 3
# GimpConvertPaletteType
MAKE_PALETTE = 0
REUSE_PALETTE = 1
WEB_PALETTE = 2
MONO_PALETTE = 3
MAKE_PALETTE = 0
REUSE_PALETTE = 1
WEB_PALETTE = 2
MONO_PALETTE = 3
CUSTOM_PALETTE = 4
# GimpConvolutionType
NORMAL_CONVOL = 0
NORMAL_CONVOL = 0
ABSOLUTE_CONVOL = 1
NEGATIVE_CONVOL = 2
# GimpConvolveType
BLUR_CONVOLVE = 0
BLUR_CONVOLVE = 0
SHARPEN_CONVOLVE = 1
# GimpDodgeBurnType
DODGE = 0
BURN = 1
BURN = 1
# GimpFillType
FOREGROUND_FILL = 0
BACKGROUND_FILL = 1
WHITE_FILL = 2
FOREGROUND_FILL = 0
BACKGROUND_FILL = 1
WHITE_FILL = 2
TRANSPARENT_FILL = 3
NO_FILL = 4
NO_FILL = 4
# GimpGradientPaintMode
GRADIENT_ONCE_FORWARD = 0
GRADIENT_ONCE_BACKWARDS = 1
GRADIENT_LOOP_SAWTOOTH = 2
GRADIENT_LOOP_TRIANGLE = 3
GRADIENT_ONCE_FORWARD = 0
GRADIENT_ONCE_BACKWARD = 1
GRADIENT_LOOP_SAWTOOTH = 2
GRADIENT_LOOP_TRIANGLE = 3
# GimpGradientType
LINEAR = 0
BILINEAR = 1
RADIAL = 2
SQUARE = 3
CONICAL_SYMMETRIC = 4
CONICAL_ASYMMETRIC = 5
SHAPEBURST_ANGULAR = 6
LINEAR = 0
BILINEAR = 1
RADIAL = 2
SQUARE = 3
CONICAL_SYMMETRIC = 4
CONICAL_ASYMMETRIC = 5
SHAPEBURST_ANGULAR = 6
SHAPEBURST_SPHERICAL = 7
SHAPEBURST_DIMPLED = 8
SPIRAL_CLOCKWISE = 9
SHAPEBURST_DIMPLED = 8
SPIRAL_CLOCKWISE = 9
SPIRAL_ANTICLOCKWISE = 10
# GimpHueRange
ALL_HUES = 0
RED_HUES = 1
YELLOW_HUES = 2
GREEN_HUES = 3
CYAN_HUES = 4
BLUE_HUES = 5
ALL_HUES = 0
RED_HUES = 1
YELLOW_HUES = 2
GREEN_HUES = 3
CYAN_HUES = 4
BLUE_HUES = 5
MAGENTA_HUES = 6
# GimpImageBaseType
RGB = 0
GRAY = 1
RGB = 0
GRAY = 1
INDEXED = 2
# GimpImageType
RGB_IMAGE = 0
RGBA_IMAGE = 1
GRAY_IMAGE = 2
GRAYA_IMAGE = 3
INDEXED_IMAGE = 4
RGB_IMAGE = 0
RGBA_IMAGE = 1
GRAY_IMAGE = 2
GRAYA_IMAGE = 3
INDEXED_IMAGE = 4
INDEXEDA_IMAGE = 5
# GimpLayerModeEffects
NORMAL_MODE = 0
DISSOLVE_MODE = 1
BEHIND_MODE = 2
MULTIPLY_MODE = 3
SCREEN_MODE = 4
OVERLAY_MODE = 5
DIFFERENCE_MODE = 6
ADDITION_MODE = 7
SUBTRACT_MODE = 8
DARKEN_ONLY_MODE = 9
NORMAL_MODE = 0
DISSOLVE_MODE = 1
BEHIND_MODE = 2
MULTIPLY_MODE = 3
SCREEN_MODE = 4
OVERLAY_MODE = 5
DIFFERENCE_MODE = 6
ADDITION_MODE = 7
SUBTRACT_MODE = 8
DARKEN_ONLY_MODE = 9
LIGHTEN_ONLY_MODE = 10
HUE_MODE = 11
SATURATION_MODE = 12
COLOR_MODE = 13
VALUE_MODE = 14
DIVIDE_MODE = 15
DODGE_MODE = 16
BURN_MODE = 17
HARDLIGHT_MODE = 18
COLOR_ERASE_MODE = 19
HUE_MODE = 11
SATURATION_MODE = 12
COLOR_MODE = 13
VALUE_MODE = 14
DIVIDE_MODE = 15
DODGE_MODE = 16
BURN_MODE = 17
HARDLIGHT_MODE = 18
SOFTLIGHT_MODE = 19
GRAIN_EXTRACT_MODE = 20
GRAIN_MERGE_MODE = 21
COLOR_ERASE_MODE = 22
# GimpMaskApplyMode
MASK_APPLY = 0
MASK_APPLY = 0
MASK_DISCARD = 1
# GimpMergeType
EXPAND_AS_NECESSARY = 0
CLIP_TO_IMAGE = 1
EXPAND_AS_NECESSARY = 0
CLIP_TO_IMAGE = 1
CLIP_TO_BOTTOM_LAYER = 2
FLATTEN_IMAGE = 3
FLATTEN_IMAGE = 3
# GimpMessageHandlerType
MESSAGE_BOX = 0
CONSOLE = 1
ERROR_CONSOLE = 2
# GimpOffsetType
OFFSET_BACKGROUND = 0
OFFSET_BACKGROUND = 0
OFFSET_TRANSPARENT = 1
# GimpOrientationType
HORIZONTAL = 0
VERTICAL = 1
UNKNOWN = 2
VERTICAL = 1
UNKNOWN = 2
# GimpPDBArgType
PDB_INT32 = 0
PDB_INT16 = 1
PDB_INT8 = 2
PDB_FLOAT = 3
PDB_STRING = 4
PDB_INT32ARRAY = 5
PDB_INT16ARRAY = 6
PDB_INT8ARRAY = 7
PDB_FLOATARRAY = 8
PDB_INT32 = 0
PDB_INT16 = 1
PDB_INT8 = 2
PDB_FLOAT = 3
PDB_STRING = 4
PDB_INT32ARRAY = 5
PDB_INT16ARRAY = 6
PDB_INT8ARRAY = 7
PDB_FLOATARRAY = 8
PDB_STRINGARRAY = 9
PDB_COLOR = 10
PDB_REGION = 11
PDB_DISPLAY = 12
PDB_IMAGE = 13
PDB_LAYER = 14
PDB_CHANNEL = 15
PDB_DRAWABLE = 16
PDB_SELECTION = 17
PDB_BOUNDARY = 18
PDB_PATH = 19
PDB_PARASITE = 20
PDB_STATUS = 21
PDB_END = 22
PDB_COLOR = 10
PDB_REGION = 11
PDB_DISPLAY = 12
PDB_IMAGE = 13
PDB_LAYER = 14
PDB_CHANNEL = 15
PDB_DRAWABLE = 16
PDB_SELECTION = 17
PDB_BOUNDARY = 18
PDB_PATH = 19
PDB_PARASITE = 20
PDB_STATUS = 21
PDB_END = 22
# GimpPDBProcType
INTERNAL = 0
PLUGIN = 1
INTERNAL = 0
PLUGIN = 1
EXTENSION = 2
TEMPORARY = 3
# GimpPDBStatusType
PDB_EXECUTION_ERROR = 0
PDB_CALLING_ERROR = 1
PDB_PASS_THROUGH = 2
PDB_SUCCESS = 3
PDB_CANCEL = 4
PDB_CALLING_ERROR = 1
PDB_PASS_THROUGH = 2
PDB_SUCCESS = 3
PDB_CANCEL = 4
# GimpPaintApplicationMode
PAINT_CONSTANT = 0
PAINT_CONSTANT = 0
PAINT_INCREMENTAL = 1
# GimpRepeatMode
REPEAT_NONE = 0
REPEAT_SAWTOOTH = 1
REPEAT_NONE = 0
REPEAT_SAWTOOTH = 1
REPEAT_TRIANGULAR = 2
# GimpRunModeType
RUN_INTERACTIVE = 0
# GimpRunMode
RUN_INTERACTIVE = 0
RUN_NONINTERACTIVE = 1
RUN_WITH_LAST_VALS = 2
# GimpSizeType
PIXELS = 0
POINTS = 1
# GimpStackTraceMode
STACK_TRACE_NEVER = 0
STACK_TRACE_QUERY = 1
STACK_TRACE_ALWAYS = 2
# GimpTransferMode
SHADOWS = 0
MIDTONES = 1
SHADOWS = 0
MIDTONES = 1
HIGHLIGHTS = 2
# GimpUnit
UNIT_PIXEL = 0
UNIT_INCH = 1
UNIT_MM = 2
UNIT_POINT = 3
UNIT_PICA = 4
UNIT_END = 5
# GimpSizeType
PIXELS = 0
POINTS = 1
......@@ -123,7 +123,8 @@ _type_mapping = {
_registered_plugins_ = {}
def register(func_name, blurb, help, author, copyright, date, menupath,
imagetypes, params, results, function):
imagetypes, params, results, function,
on_query=None, on_run=None):
'''This is called to register a new plugin.'''
# First perform some sanity checks on the data
def letterCheck(str):
......@@ -149,7 +150,9 @@ def register(func_name, blurb, help, author, copyright, date, menupath,
raise error, "result types must be integers"
if not letterCheck(ent[1]):
raise error,"result name contains ilegal characters"
if menupath[:8] == '<Image>/':
if menupath[:8] == '<Image>/' or \
menupath[:7] == '<Load>/' or \
menupath[:7] == '<Save>/':
plugin_type = PLUGIN
elif menupath[:10] == '<Toolbox>/':
plugin_type = EXTENSION
......@@ -158,19 +161,24 @@ def register(func_name, blurb, help, author, copyright, date, menupath,
if not func_name[:7] == 'python_' and \
not func_name[:10] == 'extension_' and \
not func_name[:8] == 'plug_in_':
not func_name[:8] == 'plug_in_' and \
not func_name[:5] == 'file_':
func_name = 'python_fu_' + func_name
_registered_plugins_[func_name] = (blurb, help, author, copyright,
date, menupath, imagetypes,
plugin_type, params, results,
function)
function, on_query, on_run)
file_params = [(PDB_STRING, "filename", "The name of the file"),
(PDB_STRING, "raw_filename", "The name of the file")]
def _query():
for plugin in _registered_plugins_.keys():
(blurb, help, author, copyright, date,
menupath, imagetypes, plugin_type,
params, results, function) = _registered_plugins_[plugin]
params, results, function,
on_query, on_run) = _registered_plugins_[plugin]
fn = lambda x: (_type_mapping[x[0]], x[1], x[2])
params = map(fn, params)
......@@ -178,20 +186,30 @@ def _query():
params.insert(0, (PDB_INT32, "run_mode",
"Interactive, Non-Interactive"))
if plugin_type == PLUGIN:
params.insert(1, (PDB_IMAGE, "image",
"The image to work on"))
params.insert(2, (PDB_DRAWABLE, "drawable",
"The drawable to work on"))
if menupath[:7] == '<Load>/':
params[1:1] = file_params
else:
params.insert(1, (PDB_IMAGE, "image",
"The image to work on"))
params.insert(2, (PDB_DRAWABLE, "drawable",
"The drawable to work on"))
if menupath[:7] == '<Save>/':
params[3:3] = file_params
results = map(fn, results)
gimp.install_procedure(plugin, blurb, help, author, copyright,
date, menupath, imagetypes, plugin_type,
params, results)
if on_query:
on_query()
def _get_defaults(func_name):
import gimpshelf
(blurb, help, author, copyright, date,
menupath, imagetypes, plugin_type,
params, results, function) = _registered_plugins_[func_name]
params, results, function,
on_query, on_run) = _registered_plugins_[func_name]
key = "python-fu-save--" + func_name
if gimpshelf.shelf.has_key(key):
......@@ -209,7 +227,8 @@ def _set_defaults(func_name, defaults):
def _interact(func_name):
(blurb, help, author, copyright, date,
menupath, imagetypes, plugin_type,
params, results, function) = _registered_plugins_[func_name]
params, results, function,
on_query, on_run) = _registered_plugins_[func_name]
# short circuit for no parameters ...
if len(params) == 0: return []
......@@ -276,7 +295,7 @@ def _interact(func_name):
def get_value(self):
return self.get_active()
class RadioEntry(gtk.Frame):
def __init__(self, default=0, items=[("Yes", 1), ("No", 0)]):
def __init__(self, default=0, items=(("Yes", 1), ("No", 0))):
import gtk
gtk.Frame.__init__(self)
box = gtk.HBox(gtk.FALSE, 5)
......@@ -327,6 +346,9 @@ def _interact(func_name):
PF_GRADIENT : gimpui.GradientSelector,
}
if on_run:
on_run()
tooltips = gtk.Tooltips()
dialog = gtk.Dialog(func_name, None, 0,
......@@ -389,11 +411,17 @@ def _interact(func_name):
def _run(func_name, params):
run_mode = params[0]
plugin_type = _registered_plugins_[func_name][7]
menupath = _registered_plugins_[func_name][5]
func = _registered_plugins_[func_name][10]
if plugin_type == PLUGIN:
start_params = params[1:3]
extra_params = params[3:]
if menupath[:7] == '<Save>/':
end = 5
else:
end = 3
start_params = params[1:end]
extra_params = params[end:]
else:
start_params = ()
extra_params = params[1:]
......@@ -492,4 +520,6 @@ def _get_logo(colormap):
import gtk
pix, mask = gtk.gdk.pixmap_colormap_create_from_xpm_d(None, colormap,
None, _python_image)
return gtk.Pixmap(pix, mask)
image = gtk.Image()
image.set_from_pixmap(pix, mask)
return image
......@@ -26,14 +26,18 @@
# making it dificult to work out what to save. This module gives an interface
# to the gimp module's primitive interface, which resembles the shelve module.
# use cPickle and cStringIO if available
try:
# use cPickle instead of pickle if it is available.
import cPickle
pickle = cPickle
del cPickle
import cPickle as pickle
except ImportError:
import pickle
import StringIO
try:
import cStringIO as StringIO
except ImportError:
import StringIO
import gimp
import copy_reg
......
......@@ -182,21 +182,13 @@ class _Selector(gtk.HBox):
self.pack_start(self.button, expand=gtk.FALSE)
self.button.show()
self.dialog = gtk.Dialog()
self.dialog.set_title(self.get_title())
def delete_event(win, event):
win.hide()
return gtk.TRUE
self.dialog.connect("delete_event", delete_event)
box = gtk.VBox()
box.set_border_width(5)
self.dialog.vbox.pack_start(box)
box.show()
self.dialog = gtk.Dialog(self.get_title(), None, 0,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OK, gtk.RESPONSE_OK))
swin = gtk.ScrolledWindow()
swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
box.pack_start(swin)
dialog.vbox.pack_start(swin)
swin.show()
items = map(None, self.get_list())
......@@ -214,31 +206,18 @@ class _Selector(gtk.HBox):
swin.add_with_viewport(list)
list.show()
b = gtk.Button("OK")
self.dialog.action_area.pack_start(b)
b.set_flags(gtk.CAN_DEFAULT)
b.grab_default()
b.show()
b.connect("clicked", self.selection_ok, list)
b = gtk.Button("Cancel")
self.dialog.action_area.pack_start(b)
b.set_flags(gtk.CAN_DEFAULT)
b.show()
b.connect("clicked", self.dialog.hide)
self.dialog.set_usize(300, 225)
self.dialog.set_size_request(300, 225)
def show_dialog(self, button):
self.dialog.show()
def selection_ok(self, button, list):
response = self.dialog.run()