Is it possible to use win32com in python script for GIMP

时间:2019-01-15 18:06:40

标签: python win32com gimp gimpfu

I try to use win32com in GIMP python script. Script should appear under tab: /Grzegorz. I noticed that "IMPORT FROM EXCEL..." shortcut appears on tab only when I delete import declaration "import win32com.client as win32". So I assume win32com causes problem.

Win32com works when I try it outside gimp as a python file so win32com is ok.

#!/usr/bin/env python

from gimpfu import *
import win32com.client as win32


def import_text_my(img):
    Excel = win32.gencache.EnsureDispatch("Excel.Application")
    Excel.Visible = True

    title = Excel.ActiveSheet.Cells(Excel.Selection.Row, 1).Value
    description = Excel.ActiveSheet.Cells(Excel.Selection.Row, 1).Value

    param = pdb.gimp_image_get_active_layer(img)
    ret = param.Split(" ")

    if len(ret) == 1:
        ret = [title, title, 'textZwyklyLeft']

    output = param.replace(ret[1], title)
    layerMy = img.active_layer
    layerMy.Name = output

    pdb.gimp_text_layer_set_text(layerMy, description)


register(
    "python_import_excel",
    "IMPORT FROM EXCEL",
    "import_text",
    "Grzegorz Mackiewicz",
    "Grzegorz Mackiewicz",
    "2019",
    "IMPORT FROM EXCEL...",
    "",
    [
        (PF_IMAGE, "img", "Input image", None)
    ],
    [],
    import_text_my, menu="<Image>/Grzegorz")

main()

Does anyone know if there is possiblility to use win32com in gimp script?

1 个答案:

答案 0 :(得分:1)

pypiwin32是的,但是您必须将win32com模块添加到Gimp使用的python运行时中。

一些指示可以安装here(这是numpy的东西,但适用于随PIP安装的任何东西)。

This post提示您应使用PIP安装pypiwin32