Python 从外部模块调用gimp fu函数

Python 从外部模块调用gimp fu函数,python,wrapper,gimp,gimpfu,Python,Wrapper,Gimp,Gimpfu,我正试图为GIMP编写一种包装器库,以使我的生成性艺术项目更容易,但我在从我的包装器模块与gimpfu接口时遇到了一个问题。以下插件代码运行良好,并显示一个带有横线的图像: from gimpfu import * from basicObjects import * def newFilt() : img = gimp.Image(500, 500, RGB) background = gimp.Layer(img, "Background", 500, 500,RGB_IM

我正试图为GIMP编写一种包装器库,以使我的生成性艺术项目更容易,但我在从我的包装器模块与gimpfu接口时遇到了一个问题。以下插件代码运行良好,并显示一个带有横线的图像:

from gimpfu import *
from basicObjects import *

def newFilt() :
    img = gimp.Image(500, 500, RGB)
    background = gimp.Layer(img, "Background", 500, 500,RGB_IMAGE, 100, NORMAL_MODE)
    img.add_layer(background, 1)
    background.fill(BACKGROUND_FILL)
    pdb.gimp_context_set_brush('1. Pixel')
    pdb.gimp_context_set_brush_size(2)
    for i in range(100):
        Line= line([(0,5*i),(500,5*i)])
        pdb.gimp_pencil(background,Line.pointcount,Line.printpoints())
    gimp.Display(img)
    gimp.displays_flush()

register(
    "python_fu_render",
    "new Image",
    "Filters",
    "Brendan",
    "Brendan",
    "2016",
    "Render",
    "",
    [],
    [],
    newFilt, menu="<Image>/File/Create")

main()
图像未呈现,并且gimp错误控制台中没有显示任何消息。如何从外部文件进行pdb调用?让包装器成为一个独立的插件会有帮助吗?

首先: gimp和gimp fu模块仅在Python脚本作为插件从gimp中运行时工作。我不知道您称之为“外部文件”是什么,但入口点总是一个插件脚本。它可以像任何普通程序一样导入其他Python模块

第二:GIMP插件运行的是Python2.x(现在是2.7版)——因此任何声明的类都应该继承自
对象
——声明一个类而不继承对象只会给您带来意想不到的问题——尽管现在这可能不是您的问题


类声明看起来不错,但是您调用它的示例并不-
Line.draw(background)
似乎表明您试图在类本身上调用该方法,而不是在
Line
类的实例上

是的,正如已经指出的,gimpfu和gimp模块只能在gimp应用程序中工作,或者通过大量的黑客攻击来创建一个重复的环境,从一个脚本中运行gimp扩展和插件而不需要gimp应用程序开销是非常酷的,但这基本上就是能够同时拥有和享用蛋糕。如果你不需要从GIMP中获得的所有过滤器和效果,你可以考虑PIL/枕头模块。它们没有达到gimp的功能,但具有图形图像处理的所有基本功能。它们在python2或3中运行良好,比gimp快得多。

是的,可以执行存储在磁盘上任何位置的python fu脚本,可能使用PYTHONPATH和DYLD_LIBRARY_PATH

from gimfu import *
class line:
    """creates a line object and defines functions specific to lines """
    def __init__(self, points):
        self.points = points
        self.pointcount = len(points)*2
    def printpoints(self):
        """converts point array in form [(x1,y1),(x2,y1)] to [x1,y1,x2,y2] as nessecary for gimp pdb calls"""
        output=[]
        for point in self.points:
            output.append(point[0])
            output.append(point[1])
        return output
    def draw(self,layer):
        pdb.gimp_pencil(layer,self.pointcount,self.printpoints())