【发布时间】:2016-10-12 19:56:59
【问题描述】:
我有一组图像要尝试手动处理,因此我编写了一个简单的插件来尝试帮助减轻痛苦。图像按顺序编号。因此,当我完成一张图像的工作时,我可以点击一个组合键,它会以正确的名称保存文件并打开列表中的下一张。这一切都很好。
插件的问题是,对于新打开的图像,撤消重做历史记录不起作用。我不确定我是否没有正确加载它,或者我是否必须设置一些东西才能启用撤消历史记录。加载新图像时,撤消历史记录完全空白,并且当我对图像进行更改时,在我处理文件时没有添加任何新内容。这使得做任何事情都变得困难,因为错误意味着重新开始。我正在使用最新的 gimp 版本 2.8.18。
我在编写 gimp 插件方面是一个完全的新手,并从 web 示例中构建了它,因此任何帮助找出为什么会发生这种情况的帮助将不胜感激。这是我为插件编写的代码:
#!/usr/bin/python
from gimpfu import *
import os.path
def get_next_filename(filepath):
#Now figure out the next image to load
old_file = filepath.replace("\\", "/")
file_info = old_file.split('/')
#print file_info
name = file_info[len(file_info) - 1].replace(".JPG", "").replace("P", "")
print name
next_num = int(name) + 1
new_name = "P" + str(next_num) + ".JPG"
print new_name
file_info[len(file_info) - 1] = new_name
s = "/"
new_path = s.join(file_info)
print new_path
return new_path
def plugin_main(timg, tdrawable):
print "orig filename: ", timg.filename
new_filename = timg.filename.replace(".JPG", "_colored.JPG")
print "new filename: ", new_filename
layer = pdb.gimp_image_merge_visible_layers(timg, CLIP_TO_IMAGE)
if not os.path.isfile(new_filename):
pdb.gimp_file_save(timg, layer, new_filename, '?')
else:
pdb.gimp_message ("Failed to save segmented image. File " + new_filename + " already exists.")
print "Closing image"
#pdb.gimp_display_delete(gimp._id2display(0))
#Try to load one of the next 5 consecutive image numbers.
#If none found then quit plugin, else load it.
new_path = timg.filename
for i in range(0,5):
new_path = get_next_filename(new_path)
if os.path.isfile(new_path):
print new_path + " found. Loading it."
img = pdb.file_jpeg_load(new_path, new_path)
pdb.gimp_display_new(img)
return
pdb.gimp_message ("No more consecutive images were found in the folder.")
register(
"segmented_saver",
"Saves a segmented image with the correct name and opens next image.",
"Saves a segmented image with the correct name and opens next image.",
"DC",
"DC",
"2016",
"<Image>/Image/Save Segmented...",
"RGB*, GRAY*",
[],
[],
plugin_main)
main()
【问题讨论】:
-
This thread 建议插件可以打破撤销历史,但主要是如果他们自己处理历史。无论如何,你不是说你
if os.path.isfile(new_path)块在 5 元素for循环内吗? -
我什至不明白它是如何运行的,因为您的注册码没有声明任何参数,所以 plugin_main 必须为两个参数接收“无”。我有一个非常相似的插件(ofn-file-next)并且没有这样的问题......
-
你是对的。当我为帖子格式化时,如果块错误,我得到了缩进。
-
我在您提供的链接中没有看到 ofn-file-next.py 插件?