简体   繁体   English

GIMP Python,切换所有可见或不可见的路径,如何?

[英]GIMP Python, toggle all paths visible or invisible, how?

I'm trying to create a GIMP Python plug-in to toggle visibility of all paths in the image on or off. 我正在尝试创建GIMP Python插件,以打开或关闭图像中所有路径的可见性。 This is to more easily process images with lots of paths (>100+) instead of endless clicking in the paths dialog. 这是为了更轻松地处理具有很多路径(> 100+)的图像,而不是在路径对话框中无休止的单击。

The GIMP Python documentation is not very helpful and I could only find the function set_component_visible. GIMP Python文档不是很有帮助,我只能找到函数set_component_visible。 But when I try img.set_component_visible(v, False) or img.set_component_visible(v, 0) is gives this error: 但是当我尝试img.set_component_visible(v, False)img.set_component_visible(v, 0)此错误:

TypeError: an integer is required

Here is the code I have got so far: 这是到目前为止我得到的代码:

from gimpfu import *
import os

def select_paths_visible(img, layer, tog, apl, wc):

    # iterate all paths (internally called "vectors")
    for v in img.vectors:
        img.set_component_visible(v, 0) # <== TypeError on this line

# tell gimp about our plugin
register(
    "python_fu_select_paths_visible",
    "Toggle paths visible",
    "Toggle paths visible",
    "BdR",
    "BdR",
    "2017",
    "<Image>/Tools/Toggle paths visible", # menu path
    "",
    [
        (PF_RADIO, "p1", "Toggle paths:", 1, (("Invisible", 0), ("Visible", 1))),
        (PF_RADIO, "p2", "Apply to paths:", 1, (("All", 0), ("With name", 1))),
        (PF_TEXT, "p3", "Pathname contains:", "test")
    ],
    [],
    select_paths_visible
)

main()

My question is 我的问题是
1. should I use set_component_visible differently 1.我应该不同地使用set_component_visible吗
2. is there a different function to toggle paths visibility on/off? 2.是否有其他功能可以打开/关闭路径可见性?
3. What is a good source for documentation on the GIMP Python functions 3. GIMP Python函数的文档的最佳来源是什么

Simply: 只是:

for v in image.vectors:
    v.visible = False
  1. set_component_visible() is about RGB channels and not paths (it seems to be the equivalent of clicking he visibility of the RGB channels in the Channels dialog) set_component_visible()与RGB通道有关,而不是路径(似乎等效于在“通道”对话框中单击RGB通道的可见性)
  2. gimp_vectors_set_visible() or change the attribute of the vector directly as done above gimp_vectors_set_visible()或如上所述直接更改矢量的属性
  3. The Procedure Browser ( Browse... button in the Python-fu console) is quite efficient IMHO. 程序浏览器(Python-fu控制台中的Browse...按钮)非常有效,恕我直言。 In Python, the more often used calls have equivalents as object methods and attributes. 在Python中,更常用的调用与对象方法和属性等效。 Use dir(object) to list methods and attributes. 使用dir(object)列出方法和属性。 You will find many things that have obvious equivalents as PDB functions. 您会发现许多与PDB函数具有明显等效的事物。 Attributes may be be R/W (as visible above) or just R/O (and should then be changed with a method or a PDB function). 属性可以是被R / W(如visible上文)或只是R / O(然后应使用方法或PDB功能改变)。

If you need sample code, see these two scripts repositories: general scripts and paths-related scripts 如果需要示例代码,请参见以下两个脚本存储库: 常规脚本和与路径相关的脚本

PS: for you name criterion: PS:为您命名标准:

for v in image.vectors:
    if string in v.name:
        v.visible = False

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM