mirror of https://github.com/GNOME/gimp.git
Do some simple validation on the GUI input. Arrays are still kinda hokey
2004-02-20 Manish Singh <yosh@gimp.org> * plug-ins/common/pygimp/gimpfu.py: Do some simple validation on the GUI input. Arrays are still kinda hokey though. Based on Dave Neary's patch, addresses bug #122049. * plug-ins/common/pygimp/plug-ins/sphere.py: Make sure radius is at least 1. Thanks to Florian Traverse for noticing. (Also in #122049)
This commit is contained in:
parent
e80060a1e7
commit
843e4a30ba
|
@ -1,3 +1,12 @@
|
||||||
|
2004-02-20 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
|
* plug-ins/common/pygimp/gimpfu.py: Do some simple validation on the
|
||||||
|
GUI input. Arrays are still kinda hokey though. Based on Dave Neary's
|
||||||
|
patch, addresses bug #122049.
|
||||||
|
|
||||||
|
* plug-ins/common/pygimp/plug-ins/sphere.py: Make sure radius is at
|
||||||
|
least 1. Thanks to Florian Traverse for noticing. (Also in #122049)
|
||||||
|
|
||||||
2004-02-20 Simon Budig <simon@gimp.org>
|
2004-02-20 Simon Budig <simon@gimp.org>
|
||||||
|
|
||||||
* plug-ins/common/lic.c: fixed crash when the effect image
|
* plug-ins/common/lic.c: fixed crash when the effect image
|
||||||
|
|
|
@ -239,8 +239,19 @@ def _interact(func_name):
|
||||||
import gimpui
|
import gimpui
|
||||||
|
|
||||||
gtk.rc_parse(gimp.gtkrc())
|
gtk.rc_parse(gimp.gtkrc())
|
||||||
|
|
||||||
defaults = _get_defaults(func_name)
|
defaults = _get_defaults(func_name)
|
||||||
|
|
||||||
|
class EntryValueError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def error_dialog(parent, msg):
|
||||||
|
dlg = gtk.MessageDialog(parent, gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||||
|
gtk.MESSAGE_WARNING, gtk.BUTTONS_CLOSE,
|
||||||
|
msg)
|
||||||
|
dlg.run()
|
||||||
|
dlg.destroy()
|
||||||
|
|
||||||
# define a mapping of param types to edit objects ...
|
# define a mapping of param types to edit objects ...
|
||||||
class StringEntry(gtk.Entry):
|
class StringEntry(gtk.Entry):
|
||||||
def __init__(self, default=''):
|
def __init__(self, default=''):
|
||||||
|
@ -250,15 +261,19 @@ def _interact(func_name):
|
||||||
return self.get_text()
|
return self.get_text()
|
||||||
class IntEntry(StringEntry):
|
class IntEntry(StringEntry):
|
||||||
def get_value(self):
|
def get_value(self):
|
||||||
import string
|
try:
|
||||||
return string.atoi(self.get_text())
|
return int(self.get_text())
|
||||||
|
except ValueError, e:
|
||||||
|
raise EntryValueError, e.args
|
||||||
class FloatEntry(StringEntry):
|
class FloatEntry(StringEntry):
|
||||||
def get_value(self):
|
def get_value(self):
|
||||||
import string
|
try:
|
||||||
return string.atof(self.get_text())
|
return float(self.get_text())
|
||||||
|
except ValueError, e:
|
||||||
|
raise EntryValueError, e.args
|
||||||
class ArrayEntry(StringEntry):
|
class ArrayEntry(StringEntry):
|
||||||
def get_value(self):
|
def get_value(self):
|
||||||
return eval(self.get_text())
|
return eval(self.get_text(), {}, {})
|
||||||
class SliderEntry(gtk.HScale):
|
class SliderEntry(gtk.HScale):
|
||||||
# bounds is (upper, lower, step)
|
# bounds is (upper, lower, step)
|
||||||
def __init__(self, default=0, bounds=(0, 100, 5)):
|
def __init__(self, default=0, bounds=(0, 100, 5)):
|
||||||
|
@ -276,7 +291,10 @@ def _interact(func_name):
|
||||||
bounds[2], bounds[2])
|
bounds[2], bounds[2])
|
||||||
gtk.SpinButton.__init__(self, self.adj, 1, 0)
|
gtk.SpinButton.__init__(self, self.adj, 1, 0)
|
||||||
def get_value(self):
|
def get_value(self):
|
||||||
return int(self.adj.value)
|
try:
|
||||||
|
return int(self.get_text())
|
||||||
|
except ValueError, e:
|
||||||
|
raise EntryValueError, e.args
|
||||||
class ToggleEntry(gtk.ToggleButton):
|
class ToggleEntry(gtk.ToggleButton):
|
||||||
def __init__(self, default=0):
|
def __init__(self, default=0):
|
||||||
gtk.ToggleButton.__init__(self)
|
gtk.ToggleButton.__init__(self)
|
||||||
|
@ -388,20 +406,38 @@ def _interact(func_name):
|
||||||
wid = _edit_mapping[type](def_val, params[i][4])
|
wid = _edit_mapping[type](def_val, params[i][4])
|
||||||
else:
|
else:
|
||||||
wid = _edit_mapping[type](def_val)
|
wid = _edit_mapping[type](def_val)
|
||||||
|
|
||||||
table.attach(wid, 2,3, i,i+1)
|
table.attach(wid, 2,3, i,i+1)
|
||||||
tooltips.set_tip(wid, desc, None)
|
tooltips.set_tip(wid, desc, None)
|
||||||
wid.show()
|
wid.show()
|
||||||
|
|
||||||
|
wid.desc = desc
|
||||||
edit_wids.append(wid)
|
edit_wids.append(wid)
|
||||||
|
|
||||||
tooltips.enable()
|
tooltips.enable()
|
||||||
dialog.show()
|
dialog.show()
|
||||||
response = dialog.run()
|
|
||||||
dialog.hide()
|
|
||||||
ret = None
|
ret = None
|
||||||
if response == gtk.RESPONSE_OK:
|
while 1:
|
||||||
# OK was clicked
|
ret = None
|
||||||
ret = map(lambda wid: wid.get_value(), edit_wids)
|
|
||||||
_set_defaults(func_name, ret)
|
response = dialog.run()
|
||||||
|
if response == gtk.RESPONSE_OK:
|
||||||
|
# OK was clicked
|
||||||
|
ret = []
|
||||||
|
msg = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
for wid in edit_wids:
|
||||||
|
ret.append(wid.get_value())
|
||||||
|
except EntryValueError:
|
||||||
|
error_dialog(dialog, 'Invalid input for "%s"' % wid.desc)
|
||||||
|
else:
|
||||||
|
_set_defaults(func_name, ret)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@ import math
|
||||||
from gimpfu import *
|
from gimpfu import *
|
||||||
|
|
||||||
def python_sphere(radius, light, shadow, bg_colour, sphere_colour):
|
def python_sphere(radius, light, shadow, bg_colour, sphere_colour):
|
||||||
|
if radius < 1:
|
||||||
|
radius = 1
|
||||||
width = int(radius * 3.75)
|
width = int(radius * 3.75)
|
||||||
height = int(radius * 2.5)
|
height = int(radius * 2.5)
|
||||||
img = gimp.Image(width, height, RGB)
|
img = gimp.Image(width, height, RGB)
|
||||||
|
|
Loading…
Reference in New Issue