Tue Feb 02, 2016 10:03 pm
Wed Feb 03, 2016 2:51 am
#!/usr/bin/env python
from gimpfu import *
def idiosync(inImage, inDrawable, inSwitch):
pdb.gimp_context_set_foreground((0,0,0))
pdb.gimp_context_set_background((255, 255, 255))
if inSwitch == True:
pdb.gimp_drawable_fill(inDrawable, BACKGROUND_FILL)
else:
pdb.gimp_drawable_fill(inDrawable, FOREGROUND_FILL)
return
def idiosync_call(inImage, inDrawable, inSwitch):
idiosync(inImage, inDrawable, inSwitch)
return
register(
"idiosync_call",
"Alter an images background color based on a switch.",
"Alter an images background color based on a switch.",
"Jazzon",
"C. Jason B.",
"January 2016",
"idiosync_call",
"",
[
(PF_IMAGE, "image", "Input Image", None),
(PF_DRAWABLE, "drawable", "Input Drawable", None),
(PF_TOGGLE, "switch", "No is black\nYes is White", False),
],
[],
idiosync_call,
menu="<Image>/DiegoTest/",
)
main()
Wed Feb 03, 2016 3:42 am
#!/usr/bin/env python
from gimpfu import *
def idiosync(inImage, inDrawable, inSwitch):
pdb.gimp_context_set_foreground((0,0,0))
pdb.gimp_context_set_background((255, 255, 255))
if inSwitch == True:
pdb.gimp_drawable_fill(inDrawable, BACKGROUND_FILL)
else:
pdb.gimp_drawable_fill(inDrawable, FOREGROUND_FILL)
return
def idiosync_call2(inImage, inDrawable, inSwitch):
if inSwitch == True:
idiosync(inImage, inDrawable, 1)
else:
idiosync(inImage, inDrawable, 0)
return
register(
"idiosync_call2",
"Alter an images background color based on a switch.",
"Alter an images background color based on a switch.",
"Jazzon",
"C. Jason B.",
"January 2016",
"idiosync_call2",
"",
[
(PF_IMAGE, "image", "Input Image", None),
(PF_DRAWABLE, "drawable", "Input Drawable", None),
(PF_TOGGLE, "switch", "No is black\nYes is White", False),
],
[],
idiosync_call2,
menu="<Image>/DiegoTest/",
)
main()
Wed Feb 03, 2016 4:53 am
jazzon wrote:So to all of the True Gimp Gods, and Python Deities around here I ask this. I assume something this major is a known issue. But I cannot seem to find a bug report for it anywhere. Perhaps one of You can find one? And if not please let me know and I'll fire one off.
Wed Feb 03, 2016 6:56 am
saulgoode wrote:It is not a GIMP bug. It is a "feature" of the Python programming language.
#!/usr/bin/env python
from gimpfu import *
def truth_test(truth):
if truth is True:
msg = "Received true"
else:
msg = "Received False"
pdb.gimp_message(msg)
return
def truth_test2(truth):
pdb.python_fu_jaz_truth_test_interactive(truth)
return
register(
"jaz_truth_test_interactive",
"Simple truth test",
"Simple truth test called interactively.",
"Jazzon",
"Jazzon",
"January 2016",
"Succeeds",
"",
[
(PF_TOGGLE, "truth", "True or False?", True),
],
[],
truth_test,
menu="<Image>/Demo")
register(
"jaz_truth_test_noninteractive",
"Simple truth test",
"Simple truth test called noninteractively.",
"Jazzon",
"Jazzon",
"January 2016",
"Fails",
"",
[
(PF_TOGGLE, "truth", "True or False?", True),
],
[],
truth_test2,
menu="<Image>/Demo")
main()
dinasset wrote:<snip>
In effects, I tried your script #1 and something failed.
Then, because I'm simple-minded, I rewrote your #1 in my own simple python style.
Here it is:<snip>
it seems to work both with Yes and No.
Did I miss something from your comments?
Wed Feb 03, 2016 8:21 am
Wed Feb 03, 2016 10:05 am
Wed Feb 03, 2016 11:34 am
if bool(inSwitch) == True:
inDrawable.fill(BACKGROUND_FILL)
else:
inDrawable.fill(FOREGROUND_FILL)
Wed Feb 03, 2016 12:05 pm
# First plugin
def truth_test(truth):
if truth is True:
msg = "Received true"
else:
msg = "Received false"
pdb.gimp_message(msg)
return
# Second plugin
def truth_test2(truth):
# This calls plugin one
pdb.python_fu_jaz_truth_test_interactive(truth)
return
Wed Feb 03, 2016 1:04 pm
Wed Feb 03, 2016 3:31 pm
jazzon wrote:Wow, I must have really been unclear. The problem isn't how to code this. The problem is it's broken.
Take this example:
A plugin takes only one parameter, a boolean value.
It uses pdb.gimp_message to display "recienved XXX" (Where xxx is a string true or false)
call the plugin from the menu.
supply true
plugin prints out "Received True"
Wed Feb 03, 2016 5:53 pm
Python.org documentation of bool() (empahasis mine) wrote:Return a Boolean value, i.e. one of True or False. x is converted using the standard truth testing procedure. If x is false or omitted, this returns False; otherwise it returns True. bool is also a class, which is a subclass of int. Class bool cannot be subclassed further. Its only instances are False and True.
Python documentation section 5.9 wrote:The operators is and is not test for object identity: x is y is true if and only if x and y are the same object. x is not y yields the inverse truth value.
Wed Feb 03, 2016 6:28 pm
Wed Feb 03, 2016 6:42 pm
gimp --verbose -c
Terminal window copy paste wrote:loading menu '/usr/share/gimp/2.0/menus/image-menu.xml' for /image-menubar
Loading module '/usr/lib/gimp/2.0/modules/libdisplay-filter-lcms.so'
idiosync-Warning: Received True
idiosync-Warning: Received False
idiosync-Warning: Received True
Should Succeed-Warning: Received false
Should Succeed-Warning: Received false
Should Succeed-Warning: Received True
Sending: True
Should Succeed-Warning: Received false
Sending: False
Should Succeed-Warning: Received false
Sending: True
Should Succeed-Warning: Received false
Sending: True
Should Succeed-Warning: Received false
Sending: True
Should Succeed-Warning: Received false
Command line output wrote:loading menu '/usr/share/gimp/2.0/menus/image-menu.xml' for /image-menubar
Loading module '/usr/lib/gimp/2.0/modules/libdisplay-filter-lcms.so'
I added this blank to the paste for clarity
Plugin one Received: False Type(): <type 'bool'> repr(): False
Plugin one Received: True Type(): <type 'bool'> repr(): True
I added this blank for clarity
Plug in 2 Sending: False <type 'bool'> False
Plugin one Received: 0 Type(): <type 'int'> repr(): 0
Plug in 2 received 0 as a return from 1
type() and repr() for return: <type 'int'> 0
Plug in 2 Sending: True <type 'bool'> True
Plugin one Received: 1 Type(): <type 'int'> repr(): 1
Plug in 2 received 1 as a return from 1
type() and repr() for return: <type 'int'> 1
def truth_test(truth):
print "Plugin one Received:" , truth, "Type(): ",type(truth), "repr(): ", repr(truth)
return truth
def truth_test2(truth):
print "Plug in 2 Sending: ", truth, type(truth), repr(truth)
truth = pdb.python_fu_jaz_truth_test_interactive(truth)
print "Plug in 2 received ", truth, "as a return from 1"
print "type() and repr() for return: ",type(truth), repr(truth),"\n"
return
Command line copy paste wrote:loading menu '/usr/share/gimp/2.0/menus/image-menu.xml' for /image-menubar
Loading module '/usr/lib/gimp/2.0/modules/libdisplay-filter-lcms.so'
Plugin one Received: True Type(): <type 'bool'> repr(): True
test of 'truth is True': True
test of 'truth == True': True
Plugin one Received: False Type(): <type 'bool'> repr(): False
test of 'truth is True': False
test of 'truth == True': False
Plug in 2 Sending: False <type 'bool'> False
Plugin one Received: 0 Type(): <type 'int'> repr(): 0
test of 'truth is True': False
test of 'truth == True': False
Plug in 2 received 0 as a return from 1
type() and repr() for return: <type 'int'> 0
Plug in 2 Sending: True <type 'bool'> True
Plugin one Received: 1 Type(): <type 'int'> repr(): 1
test of 'truth is True': False
test of 'truth == True': True
Plug in 2 received 1 as a return from 1
type() and repr() for return: <type 'int'> 1
Wed Feb 03, 2016 9:16 pm
jazzon wrote:I concur, it received an int type, but it was sent a bool type. Therein lies the issue. SOmehow the type is being changed between caller and receiver, thus standard truth tests (like: x is True) can fail.
Wed Feb 03, 2016 11:48 pm
Thu Feb 04, 2016 12:50 pm
inDrawable.fill([FOREGROUND_FILL,BACKGROUND_FILL][bool(inSwitch)])
inDrawable.fill(BACKGROUND_FILL if inSwitch else FOREGROUND_FILL)
Thu Feb 04, 2016 1:33 pm
Thu Feb 04, 2016 6:08 pm
if someFlag:
if not someFlag:
Fri Feb 05, 2016 2:47 am