saulgoode wrote:
It is not a GIMP bug. It is a "feature" of the Python programming language.
That part I understand. In most
Python code I have written True or 1 and False, 0, or -1 work as expected. But unless I am way off base here, all 7 of the scripts I originally attached should get the same results. The calls are identical, but the results are not. The only difference is one is called interactively, and one non-interactivly. (I only coded one example variant for each, not all of the possibilities.)
So why then does this fail?
#!/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()
That is what started me digging into this.
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?
dinasset Simple Minded? HA! I've seen Your work! I'll never believe that.
No You are hitting the nail on the head actually. The point I am trying to illustrate is the fact that unless I am seriously off in my understanding of something, all 7 of my scripts SHOULD WORK SYSTEM AGNOSTICALLY, but on my machine 1, A, and Work all work flawlessly. But on Yours 1 failed. Why? To my knowledge I have nothing installed which alters
Python's or The GIMP's handling of it's parameters, or considering of Truth.
Python is from standard repositories for Linux Mint (granted that means a binary build and I do not know of modifications with out a lot of research on the issue), and ditto for The GIMP. No scripts or plugins that alter anything as far as I know. So why do they work on my end and not yours? That very question is the heart of what I was getting at ... There is no consistant handling of Truth and parameters AT RUN TIME.
Unless I am missing something, all 7 of these should succeed, but when I run it on my machine I get the following results:
Script 1: Changes to black or white;
Script 2: Changes from white to black, but will not under any circumstances change it to white.
Script A: Changes to black or white;
Script B: Again can change to black, but not to white.
Script Works: Changes to black or top white
Script int: Changes to black or to white
Script bool: Changes to black or to white.
But all 7 scripts are valid and
should achieve the same successful results. Bu they do not. Something different between our machines altered Your results as compared to mine (or mine compared to Yours, same thing really).
Slightly off topic:
As for the difference in code (Yours to mine), I simply used PyGimps class interface to the drawable, while You are using PyGimp's pdb interface. They both do the same thing, just different means of accessing them (great thing about
Python). Some time ago (well over a year since I found the article was I think for The GIMP 2.4 or maybe 2.6) I read that the class interface methods ran quicker. The same article also posted some stats on the run times. The differences exist, but if I recall, are not huge. Anyway, I try to use the class interface because of what I read. They are both the same thing.
I am not trying to criticise here, or in any of my other posts, Your code is great! Just style differences between You and I, and most people don't like my style anyway. ( I tend to try to super simplify things, and in the end result I often over complicate matters. If that makes any sense.)