Posts: 5
Threads: 1
Joined: Feb 2019
Reputation:
0
Operating system(s):
- Windows (Vista and later)
- Linux
Gimp version: 2.10
I'm new to gimp and pretty much a novice at using it. But, I have done quite a bit of work with CNC routers and am dabbling with laser engraving. This led me to create a gimp plug-in that converts images to g-code for laser engraving. I have versions for 2.8 and 2.10 on Windows and a separate version for linux. I haven't tried it on a mac but am pretty sure I can get that going as well.
If there is interest, I'd be happy to make it public.
What do you think?
Posts: 6,350
Threads: 274
Joined: Oct 2016
Reputation:
565
Operating system(s):
Gimp version: 2.10
I would go the other way.. make it public, and see if there is interest
Posts: 5
Threads: 1
Joined: Feb 2019
Reputation:
0
Operating system(s):
- Windows (Vista and later)
- Linux
Gimp version: 2.10
OK, thanks for the suggestion. It's available for on github at:
https://github.com/buildbotics/gimp-laser-plugin
I'd be interested to see what people think and open to implementing improvements that are suggested.
Posts: 6,350
Threads: 274
Joined: Oct 2016
Reputation:
565
Operating system(s):
Gimp version: 2.10
02-07-2019, 04:39 PM
(This post was last modified: 02-07-2019, 04:45 PM by Ofnuts.)
I don't really understand why you import gtk just to open a FileChooser.
If you want to create a file from the current image, then you define a file-export plugin. Gimp will then handle the file picker for you. Registration is a bit more complicated that your regular plugin but there are examples (for instance the file-openraster.py plugin that comes in Gimp 2.10).
Otherwise you can just as well make it an independent application and remove the dependency on Gimp. There are Python libraries to load images (PIL or its "pillow" derivative, among others).
Posts: 5
Threads: 1
Joined: Feb 2019
Reputation:
0
Operating system(s):
- Windows (Vista and later)
- Linux
Gimp version: 2.10
02-07-2019, 09:17 PM
(This post was last modified: 02-07-2019, 09:23 PM by DougCoffland.)
(02-07-2019, 04:39 PM)Ofnuts Wrote: I don't really understand why you import gtk just to open a FileChooser.
If you want to create a file from the current image, then you define a file-export plugin. Gimp will then handle the file picker for you. Registration is a bit more complicated that your regular plugin but there are examples (for instance the file-openraster.py plugin that comes in Gimp 2.10).
Otherwise you can just as well make it an independent application and remove the dependency on Gimp. There are Python libraries to load images (PIL or its "pillow" derivative, among others).
(02-07-2019, 09:17 PM)DougCoffland Wrote: (02-07-2019, 04:39 PM)Ofnuts Wrote: I don't really understand why you import gtk just to open a FileChooser.
If you want to create a file from the current image, then you define a file-export plugin. Gimp will then handle the file picker for you. Registration is a bit more complicated that your regular plugin but there are examples (for instance the file-openraster.py plugin that comes in Gimp 2.10).
Otherwise you can just as well make it an independent application and remove the dependency on Gimp. There are Python libraries to load images (PIL or its "pillow" derivative, among others).
I used gtk because I couldn't figure out how to get the standard file chooser to warn the user that the file that was selected already exists and to ask the user if they want to replace it. If there is a way to configure the standard file chooser to do this, it would certainly make things simpler.
Do you have any suggestions on how to do this?
Posts: 6,350
Threads: 274
Joined: Oct 2016
Reputation:
565
Operating system(s):
Gimp version: 2.10
(02-07-2019, 09:17 PM)DougCoffland Wrote: I used gtk because I couldn't figure out how to get the standard file chooser to warn the user that the file that was selected already exists and to ask the user if they want to replace it. If there is a way to configure the standard file chooser to do this, it would certainly make things simpler.
Do you have any suggestions on how to do this?
As far as I can see, the file chooser that Gimp use when you do File>Export already cover this. So if you change your plugin to register as a proper export plugin, when you will be called the file overwrite check will have been already performed by Gimp.
Posts: 5
Threads: 1
Joined: Feb 2019
Reputation:
0
Operating system(s):
- Windows (Vista and later)
- Linux
Gimp version: 2.10
(02-07-2019, 11:50 PM)Ofnuts Wrote: (02-07-2019, 09:17 PM)DougCoffland Wrote: I used gtk because I couldn't figure out how to get the standard file chooser to warn the user that the file that was selected already exists and to ask the user if they want to replace it. If there is a way to configure the standard file chooser to do this, it would certainly make things simpler.
Do you have any suggestions on how to do this?
As far as I can see, the file chooser that Gimp use when you do File>Export already cover this. So if you change your plugin to register as a proper export plugin, when you will be called the file overwrite check will have been already performed by Gimp.
Yes, File>Export seems to work correctly. But my plug-in does not work the way I want it to when I use the standard file interface. If I can make it work like File>Export, that would be great.
I have attached a version of my script that does not use 'gtk'. It's called "no-gtk.py" and runs under Gim 2.10 on Windows 10.
The dialog comes up with the Output file field empty. Click the button to select a file. The select a file that already exists that you don't mind overwriting. Then, click OK to run the program. The selected file gets overwritten and you don't get warned.
I must be doing something wrong. Do you have any suggestions? Thanks...
Posts: 6,350
Threads: 274
Joined: Oct 2016
Reputation:
565
Operating system(s):
Gimp version: 2.10
02-10-2019, 08:43 PM
(This post was last modified: 02-10-2019, 09:35 PM by Ofnuts.)
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.
Posts: 5
Threads: 1
Joined: Feb 2019
Reputation:
0
Operating system(s):
- Windows (Vista and later)
- Linux
Gimp version: 2.10
Sorry, I did not get the skeleton script. Can you provide a link to it?
Posts: 6,350
Threads: 274
Joined: Oct 2016
Reputation:
565
Operating system(s):
Gimp version: 2.10
(02-10-2019, 09:26 PM)DougCoffland Wrote: Sorry, I did not get the skeleton script. Can you provide a link to it?
Just figured out I forgot to include it : Fixed.
|