carol.gimp.org

gimp2

Python:restore tools

python

These few lines when added to the beginning and ending of your scripts, will leave TheGIMP the way your script found it. The colors in the tool box, the last used gradient, brush, and whatever else fits there.

*et-tools

File   Edit   Search   Preferences


def get_tools():
    version = pdb.gimp_version()
    old_settings = (gimp.get_foreground(),
                    gimp.get_background(),
                    pdb.gimp_context_get_brush(),
                    pdb.gimp_context_get_font(),
                    pdb.gimp_context_get_gradient(),
                    pdb.gimp_context_get_palette(),
                    pdb.gimp_context_get_pattern())
    return old_settings, version



def reset_tools(old_settings):
    old_fg,old_bg,old_brush,old_font,old_gradient,old_palette,old_pattern = old_settings
    pdb.gimp_context_set_background(old_bg)
    pdb.gimp_context_set_foreground(old_fg)
    pdb.gimp_context_set_brush(old_brush)
    pdb.gimp_context_set_font(old_font)
    pdb.gimp_context_set_gradient(old_gradient)
    pdb.gimp_context_set_palette(old_palette)
    pdb.gimp_context_get_pattern(old_pattern)
    pdb.gimp_context_set_foreground(old_fg)    
    pdb.gimp_context_set_background(old_bg)
    pdb.gimp_context_set_gradient(old_gradient)
    pdb.gimp_context_set_palette(old_palette)

# at the beginning of your script 
    old_settings, version = get_tools()


# at the end of your script
    reset_tools(old_settings)


  

another-gnu-type

Most all of my software is gnu. thanks!

Valid XHTML 1.1!

CC-GNU GPL
This software is licensed under the CC-GNU GPL.