What you want to do is called string formatting. There are several forms in Python v2, and even more forms in Pythin v3. The simplest form uses the percent operator:
In Pythonv3 you could use an "f-string":
but so far in Gimp you have to stick to Python v2.
Code:
pdb.gimp_item_set_name(new_layer, "Blur %3.1f, contrast %2d" % (blur,contrast))
- The things after the % in the format string ("Blur %3.1f, contrast %2d") are format specifications:
- 3.1f means at least 3 characters wide, at least one decimal and expects a floating point value
- %2d means integer (base 10), at least 2 characters wide (%d would mean: just what is needed), and expects an integer
- You can also find %s for string (or whatever the __str__ method returns for an object.
- 3.1f means at least 3 characters wide, at least one decimal and expects a floating point value
- Format specs are replaced by the values at the same position in the tuple that follows the % operator ((blur,contrast)). If you have only one format value you can skip the tuple.
In Pythonv3 you could use an "f-string":
Code:
pdb.gimp_item_set_name(new_layer,f'Blur: {blur:3.4f}, contrast: {contrast:d}')