I am currently trying to write my own plugin for Gimp.It's my first time and also my first lines in python so be gentle with me. The code is used to make my live easier creating Liveries for DCS. For that it needs to be able to find a layer by name and make it visible/invisible (In my case countrty flags). Also, not implemented yet, I want to change text from text layers.
*added afterwards
Detailed Description:
The end Goal ist to change the paint scheme for a plane in a Filght Simulator called "DCS".
The developer gave us access to texture templates.
These come with different base layers and layer-groups which need no changing.
in there I added my own layer-group which contains all my layers and layer-groups.
The script should make it easy to switch between a High-Visibility and a Low-Visibility paint scheme.
(Not implemented yet) This should be easier to achieve by hiding respective "Low Vis", "High Vis" layer-groups.
Also I wanted to make it possible to personalize the paint scheme with a Name, Callsign and a choosen Flag.
Name and Callsign have no textlayers yet and aren't implemeted.
There will be a flag on each side of the aircraft canopy (left, right).
Each flag has their own layer and there are 200+ of them.
Their layer-group structure would be "WA"/"Flag + Callsign"/"Flags Right", "Flags Left".
In their layer-group I want to make only the by input choosen Flag visible.
#!/usr/bin/env python
from gimpfu import *
def ui_callsign(image, drawable, flag_var, vis_var, name_var, callsign_var):
pdb.gimp_message("main function call")
flag_list = ["ad", "ae", "af", "ag", "ai", "al", "am", "ao", "aq", "ar", "as", "at", "au", "aw", "ax", "az", "ba", "bb", "bd", "be", "bf", "bg", "bh", "bi", "bj", "bl", "bm", "bn", "bo", "bq", "br", "bs", "bt", "bv", "bw", "by", "bz", "ca", "cc", "cd", "cf", "cg", "ch", "ci", "ck", "cl", "cm", "cn", "co", "cr", "cu", "cv", "cw", "cx", "cy", "cz", "de", "dj", "dk", "dm", "do", "dz", "ec", "ee", "eg", "eh", "er", "es", "et", "fi", "fj", "fk", "fm", "fo", "fr", "ga", "gb", "gb-eng", "gb-nir", "gb-sct", "gb-wls", "gd", "ge", "gf", "gg", "gh", "gi", "gl", "gm", "gn", "gp", "gq", "gr", "gt", "gu", "gw", "gy", "hk", "hm", "hn", "hr", "ht", "hu", "id", "ie", "il", "im", "in", "io", "iq", "ir", "is", "it", "je", "jm", "jo", "jp", "ke", "kg", "kh", "ki", "km", "kn", "kp", "kr", "kw", "ky", "kz", "la", "lb", "lc", "li", "lk", "lr", "ls", "lt", "lu", "lv", "ly", "ma", "mc", "md", "me", "mf", "mg", "mh", "mk", "ml", "mm", "mn", "mo", "mp", "mq", "mr", "ms", "mt", "mu", "mv", "mw", "mx", "my", "mz", "na", "nc", "ne", "nf", "ng", "ni", "nl", "no", "np", "nr", "nu", "nz", "om", "pa", "pe", "pf", "pg", "ph", "pk", "pl", "pm", "pn", "pr", "ps", "pt", "pt", "pw", "py", "qa", "re", "ro", "rs", "ru", "rw", "sa", "sb", "sc", "sd", "se", "sg", "sh", "si", "sj", "sk", "sl", "sm", "sn", "so", "sr", "ss", "st", "sv", "sx", "sy", "sz", "tc", "td", "tf", "tg", "th", "tj", "tk", "tl", "tm", "tn", "to", "tr", "tt", "tv", "tw", "tz", "ua", " ug", "um", "us", "uy", "uz", "va", "vc", "ve", "vg", "vi", "vn", "vu", "wf", "ws", "xk", "ye", "yt", "za", "zm", "zw"
] #List of all flags
pdb.gimp_message("created list")
for x in flag_list: #go through list one by one
pdb.gimp_message(x)
if x == flag_var: #if at by user choosen flag:
layer_name_right = x + ".png #1" #add ending to get right layer name
layer_name_left = x + ".png"
layer_right = pdb.gimp_image_get_layer_by_name(image, layer_name_right) #find right layer by layer name
layer_left = pdb.gimp_image_get_layer_by_name(image, layer_name_left)
pdb.gimp_item_set_visible(layer_right, TRUE) #set right layer to visible
pdb.gimp_item_set_visible(layer_left, TRUE)
else: #all other flag layers same procedure as above but set to invisible
layer_name_right = x + ".png #1"
layer_name_left = x + ".png"
layer_right = pdb.gimp_image_get_layer_by_name(image, layer_name_right)
layer_left = pdb.gimp_image_get_layer_by_name(image, layer_name_left)
pdb.gimp_item_set_visible(layer_right, FALSE)
pdb.gimp_item_set_visible(layer_left, FALSE)
pdb.gimp_message("end loop")
return
register(
"python_fu_ui_callsign",
"Enter Name, Callsign and Flag selection",
"Let's you easily change Name, Callsign and Flag on DCS Livery"
"David Buergel", "David Buergel", "2022",
"Ui Callsign",
"Ui Callsign",
"",
[
(PF_IMAGE, "image", "takes current image", None),
(PF_DRAWABLE, "drawable", "Input layer", None),
(PF_OPTION, "flag_var", "Flag", 0,
["ad", "ae", "af", "ag", "ai", "al", "am", "ao", "aq", "ar", "as", "at", "au", "aw", "ax", "az", "ba", "bb", "bd", "be", "bf", "bg", "bh", "bi", "bj", "bl", "bm", "bn", "bo", "bq", "br", "bs", "bt", "bv", "bw", "by", "bz", "ca", "cc", "cd", "cf", "cg", "ch", "ci", "ck", "cl", "cm", "cn", "co", "cr", "cu", "cv", "cw", "cx", "cy", "cz", "de", "dj", "dk", "dm", "do", "dz", "ec", "ee", "eg", "eh", "er", "es", "et", "fi", "fj", "fk", "fm", "fo", "fr", "ga", "gb", "gb-eng", "gb-nir", "gb-sct", "gb-wls", "gd", "ge", "gf", "gg", "gh", "gi", "gl", "gm", "gn", "gp", "gq", "gr", "gt", "gu", "gw", "gy", "hk", "hm", "hn", "hr", "ht", "hu", "id", "ie", "il", "im", "in", "io", "iq", "ir", "is", "it", "je", "jm", "jo", "jp", "ke", "kg", "kh", "ki", "km", "kn", "kp", "kr", "kw", "ky", "kz", "la", "lb", "lc", "li", "lk", "lr", "ls", "lt", "lu", "lv", "ly", "ma", "mc", "md", "me", "mf", "mg", "mh", "mk", "ml", "mm", "mn", "mo", "mp", "mq", "mr", "ms", "mt", "mu", "mv", "mw", "mx", "my", "mz", "na", "nc", "ne", "nf", "ng", "ni", "nl", "no", "np", "nr", "nu", "nz", "om", "pa", "pe", "pf", "pg", "ph", "pk", "pl", "pm", "pn", "pr", "ps", "pt", "pt", "pw", "py", "qa", "re", "ro", "rs", "ru", "rw", "sa", "sb", "sc", "sd", "se", "sg", "sh", "si", "sj", "sk", "sl", "sm", "sn", "so", "sr", "ss", "st", "sv", "sx", "sy", "sz", "tc", "td", "tf", "tg", "th", "tj", "tk", "tl", "tm", "tn", "to", "tr", "tt", "tv", "tw", "tz", "ua", " ug", "um", "us", "uy", "uz", "va", "vc", "ve", "vg", "vi", "vn", "vu", "wf", "ws", "xk", "ye", "yt", "za", "zm", "zw"
]
),
(PF_RADIO, "vis_var", "Vis", "vis_value",
(
("High Vis", "high_vis_value"),
("Low Vis", "low_vis_value")
)
),
(PF_TEXT, "name_var", "Name", "enter Name"),
(PF_TEXT, "callsign_var", "Callsign", "enter Callsign")
],
[],
ui_callsign, menu="<Image>/Filters")
main()
Plugin shows up in Gimp and gives me all the right options. After clicking ok it grey's out ok and cancle and nothing happens. No messages in the error console.
I'd be happy with all the help I can get
Since you are in Ubuntu, you can start Gimp in a terminal to check for errors (this is also doable on OSX, on Windows you have to use
gimp-console
). When you do so you see this when you run your script:Since you have a single radio button widget the reason isn't hard to find, your code is:
... where the third argument is supposed to be the value set by default. But since
"vis_value"
isn't one of the two possible values this doesn't work. Change it to"high_vis_value"
or"low_vis_value"
.Some more remarks:
print
statements in your Python code are printed to the console, this is more efficient than usinggimp_message()
pdb.gimp_text_layer_set_text(layer, text)
. But this assumes that the layer is still a pure text layer. If not in some cases the text info can be recovered and you can recreate a new layer using the font information of the previous layer. In all cases this can be tricky since you can have to reposition the layer if its size changed.You code with the first four suggestions: