Initializing resources for dialog in Python plugins

Issue #1:

When the code of the plugin is first run (which is sort of when the data is initialized) it seems that the Gimp context isn’t complete, so calls such as Gimp.Brush.get_by_name('confetti') return nothing. So if you want to separate data initialization from the code, well, tough luck.

Issue #2:

I have spent most of the day fighting the use of the noneOK and defaultToContext flags. It appears that defaultToContext is really willBeClobberedByContextEvenIfDefined but I don’t get the purpose of noneOK since If the resource is not defined Gimp also uses the resource from the context. So how are these really supposed to work?

In addition it seems that something somewhere remembers settings (I have scoured plug-in-settings/ between Gimp restarts of course). It went like this:

  • I start all my tests with a resource argument called 'brush' that was by default set to the Confetti brush with defaultToContext=True.
  • So in the dialog I get that brush displayed with the context brush despite it being expected to be Confetti
  • I want to investigate the effect of defaultToContext so set it to False: the brush is still the context brush
  • I define 4 brush args called brush1 to brush4 to which I assign each of the combos of noneOK and defaultToContext. At last, two of them show the Confetti brush (the ones with the defaultToContext=False.
  • I add a fifth brush brush5 where the flags assume the defaults in my code (also defaultToContext=False). It displays as Confetti as expected.
  • I just change the name back to brush and now the brush displays as the context brush.
  • Acid test: I only change the procedure identifier in the .py and the brush brush is back to Confetti
  • I change back to the original procedure name and the context brush reappears
  • Plot twist: if I then use “Reset to factory defaults” the Confetti brush reappears… (but not if I use “Reset to initial values”)

Or is it just because the name brush is used somewhere? (after all I can’t use image as an argument name already).