Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Plugin for converting images to g-code for laser engraving
#8
Here the skeleton of a basic "save" handler. When you use that, the registered extensions (".ofn" here) is add to the possible choices in the File>Export menus and if the filename has the right extensions your plugin is called when saving the file. Gimp will have already handled the "overwrite existing", including not checking it when you export again (Ctrl-E).

Code:
#!/usr/bin/env python2

# Sample file export plugin

import os, sys, tempfile
from gimpfu import *

handlerName='file-ofn-sample-export'

def exportExample(*args):
    print 'Called export plugin: %s %s %s %s' % args
    img, drawable, filename, raw_filename=args
    with open(filename,'w') as out:
        out.write('Saved file')
    
def register_save_handlers():
    gimp.register_save_handler('file-ofn-sample-export', 'ofn', '')

register(
    handlerName,'Export sample (.ofn)','Export sample (.ofn)',
    'me', 'me', '2019',
    'OFN-Example',
    '*',
    [   
        (PF_IMAGE, "image", "Input image", None),
        (PF_DRAWABLE, "drawable", "Input drawable", None),
        (PF_STRING, "filename", "The name of the file", None),
        (PF_STRING, "raw-filename", "The name of the file", None),
    ],
    [],
    exportExample,
    on_query = register_save_handlers,
    menu = '<Save>'
)

main()

However as far as I can tell you won't get an auto-generated dialog if you add more parameters, so you have to build a GTK dialog for this, unless you consider that you can replace "interactive" settings with some config file   to ensure repeatability.
Reply


Messages In This Thread
RE: Plugin for converting images to g-code for laser engraving - by Ofnuts - 02-10-2019, 08:43 PM

Forum Jump: