How can I use Pandas library on a Python-GIMP script?

For the last few days, I’been trying to make a dungeons and dragons spellcard making program.
What I’m trying to do is:

  • make a card template in GIMP containing all my layers (graphical and text layers)
  • take a .csv file with card info to fill into the text layers
  • transform the .csv file into a dataframe with pandas
  • iter through each row of the dataframe and edit the text layers with the corresponding data
  • save each iteration as a .png file

I’m working with VSCode IDE, Python 3.12.2 and GIMP 2.10

PD: It’s my first post and I’m not totally fluent with English so I apologize for anything that might be wrong with both my writing and my post formatting!

I’ve managed to get the code apparently working but when I try to open it on GIMP (by saving the script in the plugins folder) it doesn’t even show in the Filter>Custom section. So far I’ve would say it’s something related to GIMP not working with pandas library, but have no clue in how to fix it. Any idea on how to debug it or another approach to try?

The code:

from gimpfu import *

def modify_xcf(spell_file_name, class_name):
    import pandas as pd
    #Carga de DF
    df = pd.read_csv(spell_file_name, index_col=0)
    # Abre el archivo .xcf
    image = pdb.gimp_file_load('[my_path]/plantilla_gimp.xcf', '[my_path]/plantilla_gimp.xcf')
    
    spell_list = df.index.to_list()
    for spell in spell_list:
        image = pdb.gimp_file_load('[my_path]/plantilla_gimp.xcf', '[my_path]/plantilla_gimp.xcf')
    
        # Activa/desactiva capas según los datos del spell
        for layer in image.layers:
            match layer.name:
                case "Concentration":
                    layer.visible = df["Concentration"][spell]
                    
                #Si tiene o no casteo a mayor nivel
                case "WithHigherLevel":
                    layer.visible = df["Has Higher Levels"][spell]
                        
                case "WithoutHigherLevel":
                    layer.visible = not df["Has Higher Levels"][spell]
        
                # Reemplaza los textos
                case "Text":
                    for sublayer in layer:
                        match sublayer.name:
                            case "Source, Page":
                                pdb.gimp_text_layer_set_text(sublayer, f"{df["Source"][spell]}, p.{df["Page"][spell]}")
                            
                            case "Class":
                                pdb.gimp_text_layer_set_text(sublayer, class_name)
                            
                            case "Duration":
                                pdb.gimp_text_layer_set_text(sublayer, df["Duration"][spell])
                            
                            case "Materials":
                                pdb.gimp_text_layer_set_text(sublayer, df["Materials"][spell])
                                
                            case "Components":
                                pdb.gimp_text_layer_set_text(sublayer, df["Components"][spell])
                                
                            case "Range":
                                pdb.gimp_text_layer_set_text(sublayer, df["Range"][spell])
                                
                            case "Casting time":
                                pdb.gimp_text_layer_set_text(sublayer, df["Casting Time"][spell])
                                
                            case "Level - School":
                                pdb.gimp_text_layer_set_text(sublayer, f"{df["Level"][spell]} lvl - {df["School"][spell]}")
                                
                            case "Name":
                                pdb.gimp_text_layer_set_text(sublayer, spell)
        
            # Guarda la imagen modificada
            output_filepath = f"{class_name} Spellcards/Paladin Spellcards/{spell}.png"
            output_filename = f"{spell}.png"
            pdb.gimp_file_save(image, image.active_layer, output_filepath, output_filename)

def process_spells():
    modify_xcf("[my_path]/PaladinSpellsCleaned.csv", "Paladin")

register(
    "python_fu_process_spells",
    "Procesa los hechizos desde un CSV",
    "Activa capas y reemplaza textos en una plantilla .xcf según un CSV",
    "Tu Nombre",
    "Tu Nombre",
    "2024",
    "<Image>/Filters/Custom/Process Spells from CSV",
    "",
    [],
    [],
    process_spells)

main()

New contributor

capymate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật